stdio.h not needed
[fw/sdcc] / support / cpp / cpplib.c
index 24dd0d06f4802251ef144ab9bd3f17f0652fb79d..5e65415fa603ac083bc68549bcad91b8850cdf03 100644 (file)
@@ -87,6 +87,9 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 #include <stdlib.h>
 #endif
 
+
+// PENDING: Straighten this out into configure
+#include <time.h> // all compilers need this
 #ifdef __MINGW32__
 #include <time.h>
 #else
@@ -96,6 +99,8 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 #ifndef VMS
 #ifndef USG
 #if !defined(_MSC_VER)
+// PENDING
+#include <time.h>
 #include <sys/time.h>   /* for __DATE__ and __TIME__ */
 #include <sys/resource.h>
 #else
@@ -276,30 +281,21 @@ struct cpp_pending {
 
 static void add_import ();
 static void append_include_chain ();
-static void make_undef ();
 static void make_assertion ();
 static void path_include ();
 static void initialize_builtins ();
 static void initialize_char_syntax ();
-static void dump_arg_n ();
-static void dump_defn_1 ();
 extern void delete_macro ();
-static void trigraph_pcp ();
 static int finclude ();
 static void validate_else ();
 static int comp_def_part ();
 extern void fancy_abort ();
-static void pipe_closed ();
-static void print_containing_files ();
 static int lookup_import ();
 static int redundant_include_p ();
-static is_system_include ();
+static int is_system_include (cpp_reader *, char *);
 static struct file_name_map *read_name_map ();
 static char *read_filename_string ();
 static int open_include_file ();
-static int check_preconditions ();
-static void pcfinclude ();
-static void pcstring_used ();
 static int check_macro_name ();
 static int compare_defs ();
 static int compare_token_lists ();
@@ -854,7 +850,7 @@ macro_cleanup (
   if (macro->type == T_DISABLED)
     macro->type = T_MACRO;
   if (macro->type != T_MACRO || pbuf->buf != macro->value.defn->expansion)
-    free (pbuf->buf);
+    Safe_free (pbuf->buf);
   return 0;
 }
 
@@ -865,46 +861,12 @@ file_cleanup (
 {
   if (pbuf->buf)
     {
-      free (pbuf->buf);
+      Safe_free (pbuf->buf);
       pbuf->buf = 0;
     }
   return 0;
 }
 
-static void
-newline_fix (
-     cpp_reader *pfile)
-{
-#if 1
-  NEWLINE_FIX;
-#else
-  register U_CHAR *p = bp;
-
-  /* First count the backslash-newline pairs here.  */
-
-  while (p[0] == '\\' && p[1] == '\n')
-    p += 2;
-
-  /* What follows the backslash-newlines is not embarrassing.  */
-
-  if (*p != '/' && *p != '*')
-    return;
-
-  /* Copy all potentially embarrassing characters
-     that follow the backslash-newline pairs
-     down to where the pairs originally started.  */
-
-  while (*p == '*' || *p == '/')
-    *bp++ = *p++;
-
-  /* Now write the same number of pairs after the embarrassing chars.  */
-  while (bp < p) {
-    *bp++ = '\\';
-    *bp++ = '\n';
-  }
-#endif
-}
-
 /* Assuming we have read '/'.
    If this is the start of a comment (followed by '*' or '/'),
    skip to the end of the comment, and return ' '.
@@ -916,7 +878,7 @@ skip_comment (
      cpp_reader *pfile,
      long *linep)
 {
-  int c;
+  int c = 0;
   while (PEEKC() == '\\' && PEEKN(1) == '\n')
     {
       if (linep)
@@ -1077,7 +1039,7 @@ handle_directive (
 { int c;
   register struct directive *kt;
   int ident_length;
-  long after_ident;
+  long after_ident = 0;
   U_CHAR *ident, *line_end;
   long old_written = CPP_WRITTEN (pfile);
 
@@ -1955,7 +1917,7 @@ cpp_pop_buffer (pfile)
   cpp_buffer *next_buf = CPP_PREV_BUFFER (buf);
   (*buf->cleanup) (buf, pfile);
   CPP_BUFFER (pfile) = next_buf;
-  free (buf);
+  Safe_free (buf);
   return next_buf;
 #endif
 }
@@ -2185,7 +2147,7 @@ output_line_command (
     CPP_PUTS_Q (pfile, sharp_line, sizeof(sharp_line)-1);
   }
 
-  sprintf (CPP_PWRITTEN (pfile), "%d ", line+2);
+  sprintf (CPP_PWRITTEN (pfile), "%ld ", line+2);
   CPP_ADJUST_WRITTEN (pfile, strlen (CPP_PWRITTEN (pfile)));
 
 // modification for SDC51
@@ -2225,8 +2187,8 @@ macarg (
      int rest_args)
 {
   int paren = 0;
-  enum cpp_token token;
-  long arg_start = CPP_WRITTEN (pfile);
+  enum cpp_token token = CPP_EOF;
+  /* long arg_start = CPP_WRITTEN (pfile); */
   char save_put_out_comments = CPP_OPTIONS (pfile)->put_out_comments;
   CPP_OPTIONS (pfile)->put_out_comments = 0;
 
@@ -2446,7 +2408,7 @@ special_symbol (
   adjust_position (CPP_LINE_BASE (ip), ip->cur, &line, &col);
 
   buf = (char *) alloca (10);
-  sprintf (buf, "%d", line);
+  sprintf (buf, "%ld", line);
       }
       break;
 
@@ -2475,7 +2437,7 @@ special_symbol (
 
       if (!is_idstart[*ip->cur])
   goto oops;
-      if (hp = cpp_lookup (pfile, ip->cur, -1, -1))
+      if ((hp = cpp_lookup (pfile, ip->cur, -1, -1)) != 0)
   {
 #if 0
     if (pcp_outfile && pcp_inside_if
@@ -2707,7 +2669,7 @@ macroexpand (
 
   if (nargs >= 0)
     {
-      enum cpp_token token;
+      enum cpp_token token = CPP_EOF;
 
       args = (struct argdata *) alloca ((nargs + 1) * sizeof (struct argdata));
 
@@ -3172,10 +3134,8 @@ do_include (
 
   int f;      /* file number */
 
-  int retried = 0;    /* Have already tried macro
-           expanding the include line*/
   int angle_brackets = 0; /* 0 for "...", 1 for <...> */
-  int pcf = -1;
+  /* int pcf = -1;  */
   char *pcfbuf;
 /*  char *pcfbuflimit;*/
   int pcfnum;
@@ -3700,7 +3660,7 @@ delete_assertion (
     {
       struct tokenlist_list *next = tail->next;
       free_token_list (tail->tokens);
-      free (tail);
+      Safe_free (tail);
       tail = next;
     }
 
@@ -3709,7 +3669,7 @@ delete_assertion (
   if (hp == *hp->bucket_hdr)
     *hp->bucket_hdr = hp->next;
 
-  free (hp);
+  Safe_free (hp);
 }
 \f
 /* Convert a character string literal into a nul-terminated string.
@@ -4333,7 +4293,6 @@ skip_if_group (
      int any)
 {
   int c;
-  int at_beg_of_line = 1;
   struct directive *kt;
   IF_STACK_FRAME *save_if_stack = pfile->if_stack; /* don't pop past here */
 #if 0
@@ -4431,7 +4390,7 @@ skip_if_group (
 
       temp = pfile->if_stack;
       pfile->if_stack = temp->next;
-      free (temp);
+      Safe_free (temp);
       break;
         default: ;
     }
@@ -4599,7 +4558,7 @@ FIXME!
     }
       }
         }
-      free (temp);
+      Safe_free (temp);
       output_line_command (pfile, 1, same_file);
     }
   return 0;
@@ -4631,7 +4590,7 @@ cpp_get_token (
      cpp_reader *pfile)
 {
   register int c, c2, c3;
-  long old_written;
+  long old_written = 0;
   long start_line, start_column;
   enum cpp_token token;
   struct cpp_options *opts = CPP_OPTIONS (pfile);
@@ -5515,7 +5474,7 @@ read_name_map (
         strcpy (ptr->map_to, dirname);
         ptr->map_to[dirlen] = '/';
         strcpy (ptr->map_to + dirlen + 1, to);
-        free (to);
+        Safe_free (to);
       }
 
     ptr->map_next = map_list_ptr->map_list_map;
@@ -5632,7 +5591,7 @@ finclude (
   long i;
   int length;
   cpp_buffer *fp;     /* For input stack frame */
-  int missing_newline = 0;
+  /* int missing_newline = 0; # KILL */
 
   if (file_size_and_mode (f, &st_mode, &st_size) < 0)
     {
@@ -5727,7 +5686,7 @@ finclude (
 
   indepth--;
   input_file_stack_tick++;
-  free (fp->buf);
+  Safe_free (fp->buf);
 #endif
   return 1;
 
@@ -5735,7 +5694,7 @@ finclude (
 
   cpp_perror_with_name (pfile, fname);
   close (f);
-  free (fp->buf);
+  Safe_free (fp->buf);
   return 1;
 }
 
@@ -6214,7 +6173,7 @@ push_parse_file (
   for (pend = opts->pending;  pend; )
     {
       struct cpp_pending *next = pend->next;
-      free (pend);
+      Safe_free (pend);
       pend = next;
     }
   opts->pending = NULL;
@@ -6633,11 +6592,17 @@ cpp_handle_options (
               char *p;
 
               if (argv[i][2] != 0)
+              {
                 p = argv[i] + 2;
-              else if (i + 1 == argc)
-                fatal ("Assertion missing after -A option");
-              else
-                p = argv[++i];
+              }
+              else 
+              {
+               if (++i == argc)
+               {
+                    fatal ("Assertion missing after -A option");
+                }
+                p = argv[i];
+              }
 
               if (!strcmp (p, "-")) {
                 struct cpp_pending **ptr;
@@ -6654,7 +6619,7 @@ cpp_handle_options (
                     && (pend->cmd[1] == 'D' || pend->cmd[1] == 'A'))
                   {
                     *ptr = pend->next;
-                    free (pend);
+                    Safe_free (pend);
                   }
                   else
                     ptr = &pend->next;
@@ -6796,13 +6761,13 @@ cpp_cleanup (
 
   if (pfile->token_buffer)
     {
-      free (pfile->token_buffer);
+      Safe_free (pfile->token_buffer);
       pfile->token_buffer = NULL;
     }
 
   if (pfile->deps_buffer)
     {
-      free (pfile->deps_buffer);
+      Safe_free (pfile->deps_buffer);
       pfile->deps_buffer = NULL;
       pfile->deps_allocated_size = 0;
     }
@@ -6811,23 +6776,23 @@ cpp_cleanup (
     {
       IF_STACK_FRAME *temp = pfile->if_stack;
       pfile->if_stack = temp->next;
-      free (temp);
+      Safe_free (temp);
     }
 
   while (pfile->dont_repeat_files)
     {
       struct file_name_list *temp = pfile->dont_repeat_files;
       pfile->dont_repeat_files = temp->next;
-      free (temp->fname);
-      free (temp);
+      Safe_free (temp->fname);
+      Safe_free (temp);
     }
 
   while (pfile->all_include_files)
     {
       struct file_name_list *temp = pfile->all_include_files;
       pfile->all_include_files = temp->next;
-      free (temp->fname);
-      free (temp);
+      Safe_free (temp->fname);
+      Safe_free (temp);
     }
 
   for (i = IMPORT_HASH_SIZE; --i >= 0; )
@@ -6836,8 +6801,8 @@ cpp_cleanup (
       while (imp)
   {
     struct import_file *next = imp->next;
-    free (imp->name);
-    free (imp);
+    Safe_free (imp->name);
+    Safe_free (imp);
     imp = next;
   }
       pfile->import_hash_table[i] = 0;
@@ -6997,7 +6962,7 @@ do_unassert (
     else
       hp->value = tail->next;
     free_token_list (tail->tokens);
-    free (tail);
+    Safe_free (tail);
   } else {
     prev = tail;
   }
@@ -7115,7 +7080,7 @@ read_token_list (
     {
       struct arglist *temp;
       long name_written = CPP_WRITTEN (pfile);
-      int eofp = 0;  int c;
+      int c;
 
       cpp_skip_hspace (pfile);
 
@@ -7184,8 +7149,8 @@ free_token_list (
 {
   while (tokens) {
     struct arglist *next = tokens->next;
-    free (tokens->name);
-    free (tokens);
+    Safe_free (tokens->name);
+    Safe_free (tokens);
     tokens = next;
   }
 }