From 5e023263c09f29bc797e53584d60092a04b62e2d Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Thu, 29 May 2008 15:56:19 +0000 Subject: synctex portability patches git-svn-id: svn://tug.org/texlive/trunk@8406 c570f23f-e606-0410-a88d-b1316a301751 --- Build/source/texk/web2c/c-auto.in | 12 ++++++++++ Build/source/texk/web2c/configure | 8 +++++-- Build/source/texk/web2c/configure.in | 4 ++-- Build/source/texk/web2c/synctex/synctex.mk | 8 ++----- Build/source/texk/web2c/synctex/synctex_main.c | 11 +++++++++- Build/source/texk/web2c/synctex/synctex_parser.c | 28 ++++++++++++++++++++---- 6 files changed, 56 insertions(+), 15 deletions(-) diff --git a/Build/source/texk/web2c/c-auto.in b/Build/source/texk/web2c/c-auto.in index dad0a90f089..3813e384d16 100644 --- a/Build/source/texk/web2c/c-auto.in +++ b/Build/source/texk/web2c/c-auto.in @@ -52,6 +52,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H +/* Define to 1 if you have the header file. */ +#undef HAVE_LOCALE_H + /* Define if you have libfontconfig */ #undef HAVE_LIBFONTCONFIG @@ -82,6 +85,9 @@ /* Define if you have POSIX threads libraries and header files. */ #undef HAVE_PTHREAD +/* Define to 1 if you have the `setlocale' function. */ +#undef HAVE_SETLOCALE + /* Define to 1 if you have the header file. */ #undef HAVE_STDINT_H @@ -97,6 +103,12 @@ /* Define to 1 if you have the header file. */ #undef HAVE_STRING_H +/* Define to 1 if you have the `strlcat' function. */ +#undef HAVE_STRLCAT + +/* Define to 1 if you have the `strlcpy' function. */ +#undef HAVE_STRLCPY + /* Define to 1 if you have the header file. */ #undef HAVE_SYS_STAT_H diff --git a/Build/source/texk/web2c/configure b/Build/source/texk/web2c/configure index 6b552463e96..c1685cd3016 100755 --- a/Build/source/texk/web2c/configure +++ b/Build/source/texk/web2c/configure @@ -4078,7 +4078,8 @@ done -for ac_header in sys/time.h sys/timeb.h + +for ac_header in sys/time.h sys/timeb.h locale.h do as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then @@ -4227,7 +4228,10 @@ done -for ac_func in strerror gettimeofday ftime mkstemp mktemp + + + +for ac_func in strerror gettimeofday ftime mkstemp mktemp setlocale strlcat strlcpy do as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` { $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 diff --git a/Build/source/texk/web2c/configure.in b/Build/source/texk/web2c/configure.in index 7abfd68c0d1..030dfb3f3ae 100644 --- a/Build/source/texk/web2c/configure.in +++ b/Build/source/texk/web2c/configure.in @@ -40,8 +40,8 @@ case $LEX in *flex) $LEX --version >/dev/null 2>&1 && LEX="$LEX -l" ;; esac AC_PROG_RANLIB -AC_CHECK_HEADERS(sys/time.h sys/timeb.h) -AC_CHECK_FUNCS(strerror gettimeofday ftime mkstemp mktemp) +AC_CHECK_HEADERS(sys/time.h sys/timeb.h locale.h) +AC_CHECK_FUNCS(strerror gettimeofday ftime mkstemp mktemp setlocale strlcat strlcpy) AC_TYPE_SIGNAL diff --git a/Build/source/texk/web2c/synctex/synctex.mk b/Build/source/texk/web2c/synctex/synctex.mk index bd8fe448509..711c7cb50c1 100644 --- a/Build/source/texk/web2c/synctex/synctex.mk +++ b/Build/source/texk/web2c/synctex/synctex.mk @@ -37,10 +37,6 @@ synctex_dir = $(srcdir)/synctex -LIBOBSDCOMPATDIR=../../libs/obsdcompat -LIBOBSDCOMPATSRCDIR=$(srcdir)/$(LIBOBSDCOMPATDIR) -XCPPFLAGS=-I$(LIBOBSDCOMPATDIR) -I$(LIBOBSDCOMPATDIR)/.. -I$(LIBOBSDCOMPATSRCDIR) -I$(LIBOBSDCOMPATSRCDIR)/.. - Makefile: $(synctex_dir)/synctex.mk # for all the engines, this trick allows to enable or disable SyncTeX support from here. @@ -212,8 +208,8 @@ synctex_parser.o: $(synctex_dir)/synctex_parser.c $(synctex_dir)/synctex_parser. synctex_main.o: $(synctex_dir)/synctex_main.c $(synctex_dir)/synctex_parser.h $(compile) -c -I$(synctex_dir) $(ZLIBCPPFLAGS) -o $@ $< -synctex:synctex_main.o synctex_parser.o $(ZLIBDEPS) $(LIBOBSDDEP) - $(link_command) synctex_main.o synctex_parser.o $(LDZLIB) $(LDLIBOBSD) +synctex:synctex_main.o synctex_parser.o $(ZLIBDEPS) + $(link_command) synctex_main.o synctex_parser.o $(LDZLIB) # Cleaning up. clean:: synctex-clean diff --git a/Build/source/texk/web2c/synctex/synctex_main.c b/Build/source/texk/web2c/synctex/synctex_main.c index 3bab64cba08..9b19205cf9e 100644 --- a/Build/source/texk/web2c/synctex/synctex_main.c +++ b/Build/source/texk/web2c/synctex/synctex_main.c @@ -43,7 +43,16 @@ This is the command line interface to the synctex_parser.c. # include # include "synctex_parser.h" -# include "openbsd-compat.h" +/* The code below uses strlcat and strlcpy, which avoids security warnings with some compilers. + However, if these are not available we simply use the old, unchecked versions; + this is OK because all the uses in this code are working with a buffer that's been + allocated based on measuring the strings involved. */ +#ifndef HAVE_STRLCAT +#define strlcat(dst, src, size) strcat((dst), (src)) +#endif +#ifndef HAVE_STRLCPY +#define strlcpy(dst, src, size) strcpy((dst), (src)) +#endif int main(int argc, char *argv[]); diff --git a/Build/source/texk/web2c/synctex/synctex_parser.c b/Build/source/texk/web2c/synctex/synctex_parser.c index 39d67bb8fe5..dd2b57a3d88 100644 --- a/Build/source/texk/web2c/synctex/synctex_parser.c +++ b/Build/source/texk/web2c/synctex/synctex_parser.c @@ -42,6 +42,10 @@ authorization from the copyright holder. #include "math.h" #include "errno.h" +#ifdef HAVE_LOCALE_H +#include "locale.h" +#endif + /* This custom malloc functions initializes to 0 the newly allocated memory. */ void *_synctex_malloc(size_t size) { void * ptr = malloc(size); @@ -1402,11 +1406,13 @@ synctex_status_t _synctex_scan_preamble(synctex_scanner_t scanner) { } /* parse a float with a dimension */ -#include "xlocale.h" synctex_status_t _synctex_scan_float_and_dimension(synctex_scanner_t scanner, float * value_ref) { synctex_status_t status = 0; unsigned char * endptr = NULL; float f = 0; +#ifdef HAVE_SETLOCALE + char * loc = setlocale(LC_NUMERIC, NULL); +#endif size_t available = 0; if(NULL == scanner || NULL == value_ref) { return SYNCTEX_STATUS_BAD_ARGUMENT; @@ -1417,7 +1423,13 @@ synctex_status_t _synctex_scan_float_and_dimension(synctex_scanner_t scanner, fl _synctex_error("problem with float."); return status; } - f = strtof_l((char *)SYNCTEX_CUR,(char **)&endptr,NULL); +#ifdef HAVE_SETLOCALE + setlocale(LC_NUMERIC, "C"); +#endif + f = strtof((char *)SYNCTEX_CUR,(char **)&endptr); +#ifdef HAVE_SETLOCALE + setlocale(LC_NUMERIC, loc); +#endif if(endptr == SYNCTEX_CUR) { _synctex_error("a float was expected."); return SYNCTEX_STATUS_ERROR; @@ -1480,6 +1492,9 @@ report_unit_error: synctex_status_t _synctex_scan_post_scriptum(synctex_scanner_t scanner) { synctex_status_t status = 0; unsigned char * endptr = NULL; +#ifdef HAVE_SETLOCALE + char * loc = setlocale(LC_NUMERIC, NULL); +#endif if(NULL == scanner) { return SYNCTEX_STATUS_BAD_ARGUMENT; } @@ -1507,11 +1522,16 @@ next_line: return SYNCTEX_STATUS_OK;/* The EOF is found, we have properly scanned the file */ } /* Scanning the information */ - /* By default, all "*_l" functions are used with a C locale. */ /*next_record:*/ status = _synctex_match_string(scanner,"Magnification:"); if(status == SYNCTEX_STATUS_OK ) { - scanner->unit = strtof_l((char *)SYNCTEX_CUR,(char **)&endptr,NULL); +#ifdef HAVE_SETLOCALE + setlocale(LC_NUMERIC, "C"); +#endif + scanner->unit = strtof((char *)SYNCTEX_CUR,(char **)&endptr); +#ifdef HAVE_SETLOCALE + setlocale(LC_NUMERIC, loc); +#endif if(endptr == SYNCTEX_CUR) { _synctex_error("bad magnification in the post scriptum, a float was expected."); return SYNCTEX_STATUS_ERROR; -- cgit v1.2.3