make cpp -> bin/sdcppold
[fw/sdcc] / support / cpp / cpplib.c
index f1bac6ad49934874c5324534f078538a848560a9..d125709d867db8451d3cc2a9e3b63fa7418e2248 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 ();
@@ -631,23 +627,24 @@ make_assertion (
      U_CHAR *str)
 {
   cpp_buffer *ip;
-  struct directive *kt;
-  U_CHAR *buf, *p, *q;
+/*  struct directive *kt; */
+  U_CHAR *buf, *p  /*, *q */ ;
 
   /* Copy the entire option so we can modify it.  */
   buf = (U_CHAR *) alloca (strlen (str) + 1);
   strcpy ((char *) buf, str);
+
+#if 0
   /* Scan for any backslash-newline and remove it.  */
   p = q = buf;
   while (*p) {
-#if 0
     if (*p == '\\' && p[1] == '\n')
       p += 2;
     else
-#endif
       *q++ = *p++;
   }
   *q = 0;
+#endif
 
   p = buf;
   if (!is_idstart[*p]) {
@@ -870,40 +867,6 @@ file_cleanup (
   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 ' '.
@@ -915,7 +878,7 @@ skip_comment (
      cpp_reader *pfile,
      long *linep)
 {
-  int c;
+  int c = 0;
   while (PEEKC() == '\\' && PEEKN(1) == '\n')
     {
       if (linep)
@@ -1076,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);
 
@@ -1687,7 +1650,7 @@ create_definition (
   }
       }
     /* now everything from bp before limit is the definition. */
-    defn = collect_expansion (pfile, bp, limit, -1, NULL_PTR);
+    defn = collect_expansion (pfile, bp, limit, -1,(struct arglist *) NULL_PTR);
     defn->args.argnames = (U_CHAR *) "";
   }
 
@@ -1996,10 +1959,10 @@ cpp_expand_to_buffer (
      int length)
 {
   register cpp_buffer *ip;
-  cpp_buffer obuf;
   U_CHAR *limit = buf + length;
   U_CHAR *buf1;
 #if 0
+  cpp_buffer obuf;
   int odepth = indepth;
 #endif
 
@@ -2135,8 +2098,8 @@ output_line_command (
      int conditional,
      enum file_change_code file_change)
 {
-  int len;
-  char *line_cmd_buf, *line_end;
+/*  int len;*/
+/*  char *line_cmd_buf, *line_end;*/
   long line, col;
   cpp_buffer *ip = CPP_BUFFER (pfile);
 
@@ -2184,14 +2147,14 @@ 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
   if (*ip->nominal_fname == '\0')
-  quote_string (pfile,"standard input");
+               quote_string (pfile,"standard input");
   else
-  quote_string (pfile, ip->nominal_fname);
+               quote_string (pfile, ip->nominal_fname);
   if (file_change != same_file) {
     CPP_PUTC_Q (pfile, ' ');
     CPP_PUTC_Q (pfile, file_change == enter_file ? '1' : '2');
@@ -2224,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;
 
@@ -2343,7 +2306,7 @@ special_symbol (
      cpp_reader *pfile)
 {
   char *buf;
-  int i, len;
+  int /* i, */ len;
   int true_indepth;
   cpp_buffer *ip = NULL;
   struct tm *timebuf;
@@ -2445,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;
 
@@ -2474,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
@@ -2706,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));
 
@@ -3157,7 +3120,7 @@ do_include (
   int skip_dirs = (keyword->type == T_INCLUDE_NEXT);
   char *fname;    /* Dynamically allocated fname buffer */
   char *pcftry;
-  char *pcfname;
+/*  char *pcfname;*/
   U_CHAR *fbeg, *fend;    /* Beginning and end of fname */
   enum cpp_token token;
 
@@ -3171,12 +3134,10 @@ 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;
+/*  char *pcfbuflimit;*/
   int pcfnum;
   f= -1;      /* JF we iz paranoid! */
 
@@ -3772,7 +3733,7 @@ do_line (
   long old_written = CPP_WRITTEN (pfile);
   enum file_change_code file_change = same_file;
   enum cpp_token token;
-  int i;
+/*  int i;*/
 
   token = get_directive_token (pfile);
 
@@ -4014,7 +3975,7 @@ do_ident (
      U_CHAR *buf, U_CHAR *limit)
 {
 /*  long old_written = CPP_WRITTEN (pfile);*/
-  int len;
+/*  int len;*/
 
   /* Allow #ident in system headers, since that's not user's fault.  */
   if (CPP_PEDANTIC (pfile) && !CPP_BUFFER (pfile)->system_header_p)
@@ -4332,14 +4293,13 @@ 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
   U_CHAR *beg_of_line = bp;
 #endif
   register int ident_length;
-  U_CHAR *ident, *after_ident;
+  U_CHAR *ident /*, *after_ident */ ;
   struct parse_marker line_start_mark;
 
   parse_set_mark (&line_start_mark, pfile);
@@ -4630,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);
@@ -4698,7 +4658,7 @@ cpp_get_token (
     if (opts->put_out_comments)
       {
         cpp_buffer *pbuf = CPP_BUFFER (pfile);
-        long dummy;
+        /* long dummy; */
         U_CHAR *start = pbuf->buf + start_mark.position;
         int len = pbuf->cur - start;
         CPP_RESERVE(pfile, 1 + len);
@@ -5581,7 +5541,7 @@ open_include_file (
     p = filename;
   if (searchptr
       && searchptr->fname
-      && strlen (searchptr->fname) == p - filename
+      && (int) strlen (searchptr->fname) == p - filename
       && ! strncmp (searchptr->fname, filename, p - filename))
     {
       /* FILENAME is in SEARCHPTR, which we've already checked.  */
@@ -5631,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)
     {
@@ -6632,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;
@@ -6644,7 +6610,7 @@ cpp_handle_options (
                 Let's include also any that were specified earlier
                 on the command line.  That way we can get rid of any
                 that were passed automatically in from GCC.  */
-                int j;
+                /* int j; */
                 opts->inhibit_predefs = 1;
                 for (ptr = &opts->pending; *ptr != NULL; )
                 {
@@ -7114,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);
 
@@ -7323,7 +7289,7 @@ cpp_read_check_assertion (
   else
     result = check_assertion (pfile,
             pfile->token_buffer + name_start, name_length,
-            0, NULL_PTR);
+            0, (struct arglist *)NULL_PTR);
   CPP_ADJUST_WRITTEN (pfile, - name_length);  /* pop */
   return result;
 }
@@ -7394,7 +7360,6 @@ cpp_error_with_line (pfile, line, column, msg, arg1, arg2, arg3)
      char *msg;
      char *arg1, *arg2, *arg3;
 {
-  int i;
   cpp_buffer *ip = cpp_file_buffer (pfile);
 
   cpp_print_containing_files (pfile);
@@ -7412,7 +7377,6 @@ cpp_warning_with_line (pfile, line, column, msg, arg1, arg2, arg3)
      char *msg;
      char *arg1, *arg2, *arg3;
 {
-  int i;
   cpp_buffer *ip;
 
   if (CPP_OPTIONS (pfile)->inhibit_warnings)
@@ -7527,9 +7491,6 @@ cpp_error_from_errno (
      cpp_reader *pfile,
      char *name)
 {
-  int i;
-
-
   cpp_buffer *ip = cpp_file_buffer (pfile);
 
   cpp_print_containing_files (pfile);