m4-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Changes to m4/src/main.c,v


From: Eric Blake
Subject: Changes to m4/src/main.c,v
Date: Fri, 29 Sep 2006 12:26:10 +0000

CVSROOT:        /sources/m4
Module name:    m4
Changes by:     Eric Blake <ericb>      06/09/29 12:26:07

Index: src/main.c
===================================================================
RCS file: /sources/m4/m4/src/main.c,v
retrieving revision 1.88
retrieving revision 1.89
diff -u -b -r1.88 -r1.89
--- src/main.c  26 Sep 2006 21:21:50 -0000      1.88
+++ src/main.c  29 Sep 2006 12:26:07 -0000      1.89
@@ -25,6 +25,7 @@
 #include "version-etc.h"
 #include "gnu/progname.h"
 #include "pathconf.h"
+#include "xstrtol.h"
 
 #include <limits.h>
 
@@ -236,6 +237,22 @@
   INTERACTIVE_NO       /* -b specified last */
 };
 
+/* Convert OPT to size_t, reporting an error using MSGID if it does
+   not fit.  */
+static size_t
+size_opt (char const *opt, char const *msgid)
+{
+  unsigned long int size;
+  strtol_error status = xstrtoul (opt, NULL, 10, &size, "kKmMgGtTPEZY0");
+  if (SIZE_MAX < size && status == LONGINT_OK)
+    status = LONGINT_OVERFLOW;
+  if (status != LONGINT_OK)
+    STRTOL_FATAL_ERROR (opt, _(msgid), status);
+  return size;
+}
+
+
+/* Main entry point.  Parse arguments, load modules, then parse input.  */
 int
 main (int argc, char *const *argv, char *const *envp)
 {
@@ -243,6 +260,7 @@
   macro_definition *tail;
   macro_definition *defn;
   int optchar;                 /* option character */
+  size_t size;                 /* for parsing numeric option arguments */
 
   macro_definition *defines;
   FILE *fp;
@@ -370,7 +388,8 @@
        break;
 
       case 'L':
-       m4_set_nesting_limit_opt (context, atoi (optarg));
+       size = size_opt (optarg, N_("nesting limit"));
+       m4_set_nesting_limit_opt (context, size);
        break;
 
       case 'M':
@@ -430,9 +449,9 @@
        break;
 
       case 'l':
-       m4_set_max_debug_arg_length_opt (context, atoi (optarg));
-       if (m4_get_max_debug_arg_length_opt (context) <= 0)
-         m4_set_max_debug_arg_length_opt (context, 0);
+       size = size_opt (optarg,
+                        N_("debug argument length"));
+       m4_set_max_debug_arg_length_opt (context, size);
        break;
 
       case 'o':




reply via email to

[Prev in Thread] Current Thread [Next in Thread]