clang-10: ignore fallthrough warning in generated code
[openafs.git] / src / comerr / error_table.y
index 88b38f6..6690c65 100644 (file)
@@ -1,8 +1,7 @@
 %{
-#include <afs/param.h>
 #include <afsconfig.h>
-
-RCSID("$Header$");
+#include <afs/param.h>
+#include <roken.h>
 
 /*
  *
@@ -22,7 +21,6 @@ RCSID("$Header$");
 #else
 #include <sys/time.h>
 #endif
-#include <sys/timeb.h>
 #include "error_table.h"
 #include "mit-sipb-cr.h"
 
@@ -46,10 +44,11 @@ RCSID("$Header$");
 
 #include "internal.h"
 
-char *current_token = (char *)NULL;
+int char_to_num(char c);
+char *gensym(const char *x);
+char *current_token = NULL;
 extern char *table_name;
 
-char *ds(const char *string);
 char *quote(const char *string);
 void set_table_1num(char *string);
 int char_to_1num(char c);
@@ -59,6 +58,8 @@ void put_ecs(void);
 void set_table_num(char *string);
 void set_table_fun(char *astring);
 
+extern int yylex (void);
+
 %}
 %union {
        char *dynstr;
@@ -73,7 +74,7 @@ void set_table_fun(char *astring);
 %%
 
 error_table    :       ERROR_TABLE header error_codes END
-                       { table_name = ds($2);
+                       { table_name = strdup($2);
                          current_token = table_name;
                          put_ecs(); }
                ;
@@ -83,7 +84,7 @@ header          :       table_fun table_id
                           $$ = $2; }
                 |       table_id
                         { current_token = $1;
-                          set_table_fun(ds("1"));
+                          set_table_fun(strdup("1"));
                           $$ = $1;
                         }
                 ;
@@ -118,19 +119,24 @@ ec_entry  :       ERROR_CODE_ENTRY ec_name ',' description
                ;
 
 ec_name                :       STRING
-                       { $$ = ds($1);
+                       { $$ = strdup($1);
                          current_token = $$; }
                ;
 
 description    :       QUOTED_STRING
-                       { $$ = ds($1);
+                       { $$ = strdup($1);
                          current_token = $$; }
                ;
 
 %%
 
-/* Copyright (C)  1998  Transarc Corporation.  All rights reserved.
- *
+/* 
+ * Copyright 2000, International Business Machines Corporation and others.
+ * All Rights Reserved.
+ * 
+ * This software has been released under the terms of the IBM Public
+ * License.  For details, see the LICENSE file in the top-level source
+ * directory or online at http://www.openafs.org/dl/license10.html
  */
 
 extern FILE *hfile, *cfile, *msfile;
@@ -146,26 +152,17 @@ char *gensym(const char *x)
                gettimeofday(&tv, (void *)0);
                gensym_n = (tv.tv_sec%10000)*100 + tv.tv_usec/10000;
        }
-       symbol = (char *)malloc(32 * sizeof(char));
+       symbol = malloc(32 * sizeof(char));
        gensym_n++;
        sprintf(symbol, "et%ld", (long int) gensym_n);
        return(symbol);
 }
 
 char *
-ds(const char *string)
-{
-       char *rv;
-       rv = (char *)malloc(strlen(string)+1);
-       strcpy(rv, string);
-       return(rv);
-}
-
-char *
 quote(const char *string)
 {
        char *rv;
-       rv = (char *)malloc(strlen(string)+3);
+       rv = malloc(strlen(string)+3);
        strcpy(rv, "\"");
        strcat(rv, string);
        strcat(rv, "\"");
@@ -174,7 +171,7 @@ quote(const char *string)
 
 afs_int32 table_number = 0;
 int current = 0;
-char **error_codes = (char **)NULL;
+char **error_codes = NULL;
 
 void add_ec(const char *name, const char *description)
 {
@@ -185,17 +182,17 @@ void add_ec(const char *name, const char *description)
 #else
                 fprintf(msfile, "%d %s\n", current, description);
 #endif /* !sun */
-        } else {
+        } else if (cfile){
            fprintf(cfile, "\t\"%s\",\n", description);
        }
-       if (error_codes == (char **)NULL) {
-               error_codes = (char **)malloc(sizeof(char *));
-               *error_codes = (char *)NULL;
+       if (error_codes == NULL) {
+               error_codes = malloc(sizeof(char *));
+               *error_codes = NULL;
        }
        error_codes = (char **)realloc((char *)error_codes,
                                       (current + 2)*sizeof(char *));
-       error_codes[current++] = ds(name);
-       error_codes[current] = (char *)NULL;
+       error_codes[current++] = strdup(name);
+       error_codes[current] = NULL;
 }
 
 void add_ec_val(const char *name, const char *val, const char *description)
@@ -208,8 +205,8 @@ void add_ec_val(const char *name, const char *val, const char *description)
        }
       
        while (ncurrent > current) {
-            if (!msfile)
-                fputs("\t(char *)NULL,\n", cfile);
+            if (cfile)
+                fputs("\tNULL,\n", cfile);
             current++;
         }
         if (msfile) {
@@ -219,24 +216,26 @@ void add_ec_val(const char *name, const char *val, const char *description)
 #else
                 fprintf(msfile, "%d %s\n", current, description);
 #endif /* ! sun */
-        } else {       
+        } else if (cfile) {
            fprintf(cfile, "\t\"%s\",\n", description);
        }
-       if (error_codes == (char **)NULL) {
-               error_codes = (char **)malloc(sizeof(char *));
-               *error_codes = (char *)NULL;
+       if (error_codes == NULL) {
+               error_codes = malloc(sizeof(char *));
+               *error_codes = NULL;
        }
        error_codes = (char **)realloc((char *)error_codes,
                                       (current + 2)*sizeof(char *));
-       error_codes[current++] = ds(name);
-       error_codes[current] = (char *)NULL;
+       error_codes[current++] = strdup(name);
+       error_codes[current] = NULL;
 } 
 
 void put_ecs(void)
 {
        int i;
+       if (!hfile)
+           return;
        for (i = 0; i < current; i++) {
-            if (error_codes[i] != (char *)NULL)
+            if (error_codes[i] != NULL)
                  fprintf(hfile, "#define %-40s (%ldL)\n",
                          error_codes[i], (long int) table_number + i);
        }
@@ -276,10 +275,8 @@ int char_to_num(char c)
 }
 
 void set_table_num(char *string)
-{       char ucname[6];                        /* I think 5 is enough but et_name.c used 6... */
-       extern char *ucstring();
-
-        if (msfile) {
+{
+        if (use_msf) {
            set_table_1num(string);
            return;
        }
@@ -289,7 +286,6 @@ void set_table_num(char *string)
                string[4] = '\0';
                fprintf(stderr, "to %s\n", string);
        }
-       string = ucstring (ucname, string, sizeof(ucname));
        if (char_to_num (string[0]) > char_to_num ('z')) {
                fprintf (stderr, "%s%s%s%s",
                         "First character of error table name must be ",
@@ -307,7 +303,7 @@ void set_table_num(char *string)
 
 void set_table_fun(char *astring)
 {
-    register char *tp;
+    char *tp;
     unsigned int tc;
 
     for(tp=astring; (tc = *tp) != 0; tp++) {
@@ -317,7 +313,7 @@ void set_table_fun(char *astring)
             exit(1);
         }
     }
-    if (msfile) 
+    if (use_msf)
        table_number += (atoi(astring)) << 28;
 }
 
@@ -393,6 +389,11 @@ int char_to_1num(char c)
         exit (1);
 }
 
+#if defined(IGNORE_SOME_GCC_WARNINGS) && defined(__clang__) && defined(HAVE_FUNC_ATTRIBUTE_FALLTHROUGH)
+/* flex generates fallthroughs in case blocks that get flagged by clang */
+# pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
+#endif
+
 #ifdef AFS_NT40_ENV
 #include "et_lex.lex_nt.c"
 #else