]> git.refcnt.org Git - colorize.git/blobdiff - colorize.c
Omit declaration of optind/optarg
[colorize.git] / colorize.c
index 38b2350c768f0ee7ca07053fdceca66b4f5c0dbf..a1e13983bc24a6563cdc10927d048d8d4fc2da7f 100644 (file)
@@ -359,8 +359,6 @@ static void vfprintf_fail (const char *, ...);
 static void stack (struct var_list **, unsigned int *, unsigned int, void *, enum var_type);
 static void release (struct var_list *, unsigned int, void **);
 
-extern int optind;
-
 int
 main (int argc, char **argv)
 {
@@ -383,8 +381,12 @@ main (int argc, char **argv)
 
 #if DEBUG
     log = open_file (DEBUG_FILE, "w");
-    STACK_FILE (log);
     print_tstamp (log);
+    /* We're in debugging mode, hence we can't invoke STACK_FILE()
+       prior to print_tstamp(), because both cause text to be written
+       to the same logfile which is expected to have the timestamp
+       first.  */
+    STACK_FILE (log);
 #endif
 
     attr[0] = '\0';
@@ -451,7 +453,7 @@ main (int argc, char **argv)
       {
         if (arg_cnt == 0 || arg_cnt > 2)
           {
-            vfprintf_diag ("%u arguments provided, expected 1-2 arguments or clean option", arg_cnt);
+            vfprintf_diag ("%u arguments provided, expected 1-2 arguments or --clean[-all]", arg_cnt);
             print_hint ();
             exit (EXIT_FAILURE);
           }
@@ -509,8 +511,6 @@ print_tstamp (FILE *log)
     print_version ();        \
     exit (EXIT_SUCCESS);
 
-extern char *optarg;
-
 static void
 process_opts (int argc, char **argv, char **conf_file)
 {
@@ -584,6 +584,7 @@ conf_file_path (char **conf_file)
           perror ("getpwuid");
         exit (EXIT_FAILURE);
       }
+    /* getpwuid() leaks memory */
     size = strlen (passwd->pw_dir) + 1 + strlen (CONF_FILE) + 1;
     path = xmalloc (size);
     snprintf (path, size, "%s/%s", passwd->pw_dir, CONF_FILE);
@@ -609,10 +610,10 @@ process_opt_attr (const char *p, const bool is_opt)
     while (*p)
       {
         const char *s;
-        if (!isalnum (*p))
+        if (!isalnum ((unsigned char)*p))
           vfprintf_fail ("%s must be provided a string", desc_type[DESC_TYPE]);
         s = p;
-        while (isalnum (*p))
+        while (isalnum ((unsigned char)*p))
           p++;
         if (*p != '\0' && *p != ',')
           vfprintf_fail ("%s must have strings separated by ,", desc_type[DESC_TYPE]);
@@ -747,7 +748,7 @@ parse_conf (const char *conf_file, struct conf *config)
 /* NAME PARSING (end) */
 /* NAME VALIDATION (start) */
         for (p = opt; *p; p++)
-          if (!isalnum (*p) && *p != '-')
+          if (!isalnum ((unsigned char)*p) && *p != '-')
             vfprintf_fail (formats[FMT_CONF], conf_file, opt, "cannot be made of non-option characters");
 /* NAME VALIDATION (end) */
 /* VALUE PARSING (start) */
@@ -854,7 +855,7 @@ print_help (void)
         const char *code = entry->code;
         if (code)
           printf ("\t\t{\033[%s#\033[0m} [%c%c]%s%*s%s\n",
-                   code, toupper (*name), *name, name + 1, 10 - (int)strlen (name), " ", name);
+                   code, toupper ((unsigned char)*name), *name, name + 1, 10 - (int)strlen (name), " ", name);
         else
           printf ("\t\t{-} %s%*s%s\n", name, 13 - (int)strlen (name), " ", name);
       }
@@ -1202,17 +1203,17 @@ gather_color_names (const char *color_string, char *attr, struct color_name **co
         assert (p != NULL);
 
         for (ch = color; *ch; ch++)
-          if (!isalpha (*ch))
+          if (!isalpha ((unsigned char)*ch))
             vfprintf_fail (formats[FMT_COLOR], tables[index].desc, color, "cannot be made of non-alphabetic characters");
 
         for (ch = color + 1; *ch; ch++)
-          if (!islower (*ch))
+          if (!islower ((unsigned char)*ch))
             vfprintf_fail (formats[FMT_COLOR], tables[index].desc, color, "cannot be in mixed lower/upper case");
 
         if (streq (color, "None"))
           vfprintf_fail (formats[FMT_COLOR], tables[index].desc, color, "cannot be bold");
 
-        if (isupper (*color))
+        if (isupper ((unsigned char)*color))
           {
             switch (index)
               {
@@ -1234,7 +1235,7 @@ gather_color_names (const char *color_string, char *attr, struct color_name **co
         STACK_VAR (color_names[index]->orig);
 
         for (ch = color; *ch; ch++)
-          *ch = tolower (*ch);
+          *ch = tolower ((unsigned char)*ch);
 
         color_names[index]->name = xstrdup (color);
         STACK_VAR (color_names[index]->name);
@@ -1600,10 +1601,10 @@ gather_esc_offsets (const char *p, const char **start, const char **end)
             do {
               check_values = false;
               iter++;
-              if (!isdigit (*p))
+              if (!isdigit ((unsigned char)*p))
                 break;
               digit = p;
-              while (isdigit (*p))
+              while (isdigit ((unsigned char)*p))
                 p++;
               if (p - digit > 2)
                 break;
@@ -1636,7 +1637,7 @@ gather_esc_offsets (const char *p, const char **start, const char **end)
 static bool
 validate_esc_clean_all (const char **p)
 {
-    while (isdigit (**p) || **p == ';')
+    while (isdigit ((unsigned char)**p) || **p == ';')
       (*p)++;
     return (**p == 'm');
 }
@@ -1844,7 +1845,7 @@ has_color_name (const char *str, const char *name)
     assert (strlen (str) > 0);
     assert (strlen (name) > 0);
 
-    if (!(*str == *name || *str == toupper (*name)))
+    if (!(*str == *name || *str == toupper ((unsigned char)*name)))
       return false;
     else if (*(name + 1) != '\0'
      && !((p = strstr (str + 1, name + 1)) && p == str + 1))