summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwlemb <wlemb>2001-08-18 16:11:54 +0000
committerwlemb <wlemb>2001-08-18 16:11:54 +0000
commit553ad14abef58812d0b3c49b610dd82c54c30637 (patch)
treecd0a80ac8608da2ec0cf69629eb0e0e4c0af9816
parent0a474d60ad67afbf77b17ac6f57d28a948fb12e0 (diff)
downloadgroff-553ad14abef58812d0b3c49b610dd82c54c30637.tar.gz
* src/preproc/pic/pic.y (format_number): Use do_sprintf().
(do_sprintf): Use snprintf(). * src/libs/snprintf/*: Added an snprintf module written by Mark Martinec. * src/libs/libgroff/Makefile.sub: Updated. * configure.ac: Add test for snprintf(). * Makefile.in: Updated. * configure: Regenerated. * src/preproc/html/pre-html.cc (make_message): Reactivate code which uses snprintf().
-rw-r--r--ChangeLog17
-rw-r--r--Makefile.comm4
-rw-r--r--Makefile.in6
-rwxr-xr-xconfigure4
-rw-r--r--configure.ac4
-rw-r--r--src/libs/libgroff/Makefile.sub6
-rw-r--r--src/libs/snprintf/README8
-rw-r--r--src/preproc/html/pre-html.cc137
-rw-r--r--src/preproc/pic/pic.y26
9 files changed, 47 insertions, 165 deletions
diff --git a/ChangeLog b/ChangeLog
index c85fbcfb..686223ab 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2001-08-18 Sebastian Krahmer <krahmer@suse.de>
+
+ * src/preproc/pic/pic.y (format_number): Use do_sprintf().
+ (do_sprintf): Use snprintf().
+
+2001-08-18 Werner LEMBERG <wl@gnu.org>
+
+ * src/libs/snprintf/*: Added an snprintf module written by Mark
+ Martinec.
+ * src/libs/libgroff/Makefile.sub: Updated.
+ * configure.ac: Add test for snprintf().
+ * Makefile.in: Updated.
+ * configure: Regenerated.
+
+ * src/preproc/html/pre-html.cc (make_message): Reactivate code which
+ uses snprintf().
+
2001-08-14 Ruslan Ermilov <ru@FreeBSD.org>
* tmac/doc.tmac (Ex): New implementation.
diff --git a/Makefile.comm b/Makefile.comm
index b9c9c85b..94065ab6 100644
--- a/Makefile.comm
+++ b/Makefile.comm
@@ -25,7 +25,7 @@ INCLUDES=-I. -I$(srcdir) \
ALL_CCFLAGS=$(INCLUDES) $(CCDEFINES) $(CCFLAGS) $(CPPFLAGS)
COMPILE.cc=$(CCC) $(ALL_CCFLAGS) -c
ALL_CFLAGS=$(INCLUDES) $(CDEFINES) $(CFLAGS) $(CPPFLAGS)
-COMPILE.c=$(CC) $(ALL_CFLAGS) -c
+COMPILE.c=$(CC) $(ALL_CFLAGS) -c
LINK.cc=$(CCC) $(CCFLAGS) $(LDFLAGS)
LINK.c=$(CC) $(CFLAGS) $(LDFLAGS)
LIBGROFF=$(top_builddir)/src/libs/libgroff/libgroff.a
@@ -239,7 +239,7 @@ depend_src: depend.temp
depend.temp: FORCE
> depend.temp;
- test -z "$(CCSRCS)$(YTABC)" \
+ test -z "$(CCSRCS)$(YTABC)" \
|| $(CCC) $(ALL_CCFLAGS) -MM $(CCSRCS) $(YTABC) >>depend.temp
test -z "$(CSRCS)" \
|| $(CC) $(ALL_CFLAGS) -MM $(CSRCS) >>depend.temp
diff --git a/Makefile.in b/Makefile.in
index 6aad272a..821cd620 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -202,6 +202,7 @@ man7dir=$(manroot)/man$(man7ext)
# -DHAVE_MMAP if you have mmap()
# -DHAVE_PUTENV if you have putenv()
# -DHAVE_RENAME if you have rename()
+# -DHAVE_SNPRINTF if you have snprintf()
# -DHAVE_STRCASECMP if you have strcasecmp()
# -DHAVE_STRNCASECMP if you have strncasecmp()
# -DHAVE_STRERROR if you have strerror()
@@ -234,7 +235,10 @@ man7dir=$(manroot)/man$(man7ext)
# -DPAGEA4 if the the printer's page size is A4
DEFINES=@DEFS@
-# Include fmod.o, strtol.o, getcwd.o, strerror.o, putenv.o, mkstemp.o
+# Include
+#
+# fmod.o, getcwd.o, mkstemp.o, putenv.o, snprintf.o, strerror.o, strtol.o
+#
# in LIBOBJS if your C library is missing the corresponding function.
LIBOBJS=@LIBOBJS@
diff --git a/configure b/configure
index c8f1ecec..05f7ec41 100755
--- a/configure
+++ b/configure
@@ -4147,7 +4147,7 @@ rm -f conftest.mmap
saved_libs="$LIBS"
LIBS="$LIBS -lc $LIBM"
-for ac_func in fmod strtol getcwd strerror putenv
+for ac_func in fmod getcwd putenv snprintf strerror strtol
do
ac_ac_var=`echo "ac_cv_func_$ac_func" | $ac_tr_sh`
echo "$as_me:4153: checking for $ac_func" >&5
@@ -4220,7 +4220,7 @@ done
LIBS="$saved_libs"
-for ac_func in rename strcasecmp strncasecmp strsep gettimeofday
+for ac_func in gettimeofday rename strcasecmp strncasecmp strsep
do
ac_ac_var=`echo "ac_cv_func_$ac_func" | $ac_tr_sh`
echo "$as_me:4226: checking for $ac_func" >&5
diff --git a/configure.ac b/configure.ac
index 7b0c4740..d8ac6879 100644
--- a/configure.ac
+++ b/configure.ac
@@ -50,9 +50,9 @@ dnl checks for functions
AC_FUNC_MMAP
saved_libs="$LIBS"
LIBS="$LIBS -lc $LIBM"
-AC_REPLACE_FUNCS(fmod strtol getcwd strerror putenv)
+AC_REPLACE_FUNCS(fmod getcwd putenv snprintf strerror strtol)
LIBS="$saved_libs"
-AC_CHECK_FUNCS(rename strcasecmp strncasecmp strsep gettimeofday)
+AC_CHECK_FUNCS(gettimeofday rename strcasecmp strncasecmp strsep)
GROFF_MKSTEMP
AC_DECL_SYS_SIGLIST
dnl checks for compiler characteristics
diff --git a/src/libs/libgroff/Makefile.sub b/src/libs/libgroff/Makefile.sub
index 007102c7..b97a7784 100644
--- a/src/libs/libgroff/Makefile.sub
+++ b/src/libs/libgroff/Makefile.sub
@@ -76,7 +76,8 @@ CSRCS=\
$(srcdir)/matherr.c \
$(srcdir)/putenv.c \
$(srcdir)/strerror.c \
- $(srcdir)/strtol.c
+ $(srcdir)/strtol.c \
+ $(srcdir)/../snprintf/snprintf.c
GENSRCS=\
version.cc
@@ -89,3 +90,6 @@ version.cc: $(top_srcdir)/VERSION $(top_srcdir)/REVISION
@echo const char \*revision_string = \"$(revision)\"\; >>$@
@echo extern \"C\" const char \*Version_string = \"$(version).$(revision)\"\; | \
sed -e 's/\.0\"/\"/' >>$@
+
+snprintf.o: $(srcdir)/../snprintf/snprintf.c
+ $(COMPILE.c) $(srcdir)/../snprintf/snprintf.c
diff --git a/src/libs/snprintf/README b/src/libs/snprintf/README
new file mode 100644
index 00000000..6dd722d8
--- /dev/null
+++ b/src/libs/snprintf/README
@@ -0,0 +1,8 @@
+The file snprintf.c is not part of groff but is used by groff; it has been
+written by Mark Martinec <mark.martinec@ijs.si>.
+
+Please look into snprintf.c for the copyright message.
+
+The complete snprintf package together with documentation is available from
+
+ http://www.ijs.si/software/snprintf/
diff --git a/src/preproc/html/pre-html.cc b/src/preproc/html/pre-html.cc
index 199c3315..e4ee0ef3 100644
--- a/src/preproc/html/pre-html.cc
+++ b/src/preproc/html/pre-html.cc
@@ -160,14 +160,6 @@ void html_system(const char *s, int redirect_stdout)
fprintf(stderr, "Calling `%s' returned status %d\n", s, status);
}
-#if 0
-
-/*
- * if/when vsnprintf becomes available on all *NIX machines we can use this function,
- * until then we must use the more complex function below which performs hand built
- * %d, %s and %%.
- */
-
/*
* make_message - taken from man printf(3), creates a string via malloc
* and places the result of the va args into string.
@@ -210,135 +202,6 @@ make_message (const char *fmt, ...)
p = np; /* use realloc'ed, p */
}
}
-#else
-
-/*
- * lengthOfintToStr - returns the length of the proposed string value of i.
- * Hand built log10.
- */
-
-int
-lengthOfintToStr (int i)
-{
- int n=0;
-
- if (i < 0)
- sys_fatal("expecting positive integer value");
-
- do {
- i /= 10;
- n++;
- } while (i > 0);
- return n;
-}
-
-/*
- * intToStr - returns a string containing the positive value of i.
- * (int i is assumed to be positive).
- */
-
-char *
-intToStr (int i)
-{
- int n=lengthOfintToStr(i)+1;
- char *p = (char *)malloc(n);
-
- if (p == NULL)
- sys_fatal("malloc");
-
- if (i < 0)
- sys_fatal("expecting positive integer value");
-
- n--;
- p[n] = (char)0;
- do {
- n--;
- p[n] = (char)((i % 10) + (int)'0');
- i /= 10;
- } while (i > 0);
- return( p );
-}
-
-/*
- * make_message - returns a string built from a format specifier.
- * This function does not use vsnprintf; it only
- * understands primitive %%, %s, and %d specifiers.
- */
-
-char *
-make_message (const char *fmt, ...)
-{
- char *p = strsave(fmt); /* so we can splat a nul anywhere in the string */
- char *np;
- char *l;
- char *s;
- char *num;
- int search=0;
- va_list ap;
-
- va_start(ap, fmt);
- while (p) {
- int lenp=strlen(p);
- char *f = strchr(p+search, '%');
-
- search = f-p;
- np = p;
-
- if (f == NULL) {
- va_end(ap);
- return p;
- }
- switch (*(f+1)) {
-
- case 'd':
- l = strsave(f+2);
- *f = (char)0;
- num = intToStr(va_arg(ap, int));
- np = (char *)malloc(strlen(p)+strlen(num)+strlen(l)+1);
- if (np == NULL)
- sys_fatal("malloc");
- strcpy(np, p);
- strcat(np, num);
- strcat(np, l);
- search += strlen(np)-lenp;
- free(num);
- a_delete l;
- break;
- case 's':
- /* concat */
- l = f+2;
- s = va_arg(ap, char *);
- *f = (char)0;
- np = (char *)malloc(strlen(l)+1+strlen(p)+strlen(s));
- if (np == NULL)
- sys_fatal("malloc");
- strcpy(np, p);
- strcat(np, s);
- strcat(np, l);
- search += strlen(s);
- break;
- case '%':
- /* remove one of the two % that we have seen */
- *f = (char)0;
- l = f+1;
- np = (char *)malloc(strlen(l)+1+strlen(p));
- if (np == NULL)
- sys_fatal("malloc");
- strcpy(np, p);
- strcat(np, l);
- search++;
- break;
- default:
- sys_fatal("unexpected format specifier");
- return NULL;
- }
- a_delete p;
- p = np;
- }
- va_end(ap);
- return NULL;
-}
-#endif
/*
* the class and methods for retaining ascii text
diff --git a/src/preproc/pic/pic.y b/src/preproc/pic/pic.y
index c0a7315f..a02e7269 100644
--- a/src/preproc/pic/pic.y
+++ b/src/preproc/pic/pic.y
@@ -1754,23 +1754,7 @@ char *format_number(const char *form, double n)
{
if (form == 0)
form = "%g";
- else {
- // this is a fairly feeble attempt at validation of the format
- int nspecs = 0;
- for (const char *p = form; *p != '\0'; p++)
- if (*p == '%') {
- if (p[1] == '%')
- p++;
- else
- nspecs++;
- }
- if (nspecs > 1) {
- lex_error("bad format `%1'", form);
- return strsave(form);
- }
- }
- sprintf(sprintf_buf, form, n);
- return strsave(sprintf_buf);
+ return do_sprintf(form, &n, 1);
}
char *do_sprintf(const char *form, const double *v, int nv)
@@ -1792,18 +1776,20 @@ char *do_sprintf(const char *form, const double *v, int nv)
if (*form == '%') {
one_format += *form++;
one_format += '\0';
- sprintf(sprintf_buf, one_format.contents());
+ snprintf(sprintf_buf, sizeof(sprintf_buf),
+ "%s", one_format.contents());
}
else {
if (i >= nv) {
- lex_error("too few arguments to sprintf");
+ lex_error("too few arguments to snprintf");
result += one_format;
result += form;
break;
}
one_format += *form++;
one_format += '\0';
- sprintf(sprintf_buf, one_format.contents(), v[i++]);
+ snprintf(sprintf_buf, sizeof(sprintf_buf),
+ one_format.contents(), v[i++]);
}
one_format.clear();
result += sprintf_buf;