/[bison]/bison/src/files.c
ViewVC logotype

Diff of /bison/src/files.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.51 by akim, Wed Aug 15 08:53:15 2001 UTC revision 1.52 by akim, Thu Oct 4 14:55:20 2001 UTC
# Line 22  Line 22 
22  #include "system.h"  #include "system.h"
23  #include "getargs.h"  #include "getargs.h"
24  #include "files.h"  #include "files.h"
 #include "xalloc.h"  
25  #include "gram.h"  #include "gram.h"
26  #include "complain.h"  #include "complain.h"
27    
# Line 34  struct obstack table_obstack; Line 33  struct obstack table_obstack;
33  struct obstack defines_obstack;  struct obstack defines_obstack;
34  struct obstack guard_obstack;  struct obstack guard_obstack;
35  struct obstack output_obstack;  struct obstack output_obstack;
 struct obstack graph_obstack;  
36    
37  char *spec_outfile = NULL;      /* for -o. */  char *spec_outfile = NULL;      /* for -o. */
38  char *spec_file_prefix = NULL;  /* for -b. */  char *spec_file_prefix = NULL;  /* for -b. */
39  char *spec_name_prefix = NULL;  /* for -p. */  char *spec_name_prefix = NULL;  /* for -p. */
40    char *spec_verbose_file = NULL;   /* for --verbose. */
41    char *spec_graph_file = NULL;   /* for -g. */
42    char *spec_defines_file = NULL; /* for --defines. */
43    
44  char *infile = NULL;  char *infile = NULL;
45  char *attrsfile = NULL;  char *attrsfile = NULL;
# Line 93  stringappend (const char *string1, const Line 94  stringappend (const char *string1, const
94  static char *  static char *
95  compute_header_macro (void)  compute_header_macro (void)
96  {  {
97    int ite;    char *macro_name, *cp;
98    char *macro_name;  
99      if (spec_defines_file)
100        macro_name = xstrdup (spec_defines_file);
101      else
102        {
103          macro_name = XMALLOC (char,
104                                strlen (base_name) +
105                                strlen (header_extension) + 1);
106    
107          stpcpy (macro_name, base_name);
108          strcat (macro_name, header_extension);
109        }
110    
111      for (cp = macro_name; *cp; ++cp)
112        if (islower (*cp))
113          *cp = toupper (*cp);
114        else if (!isalnum (*cp))
115          *cp = '_';
116    
   macro_name = XMALLOC (char,  
                         strlen (base_name) +  
                         strlen (header_extension) + 1);  
   
   stpcpy (macro_name, base_name);  
   strcat (macro_name, header_extension);  
   
   for (ite = 0; macro_name[ite]; ite++)  
     if (macro_name[ite] == '.')  
       macro_name[ite] = '_';  
     else  
       {  
         if (islower (macro_name[ite]))  
           macro_name[ite] -= ('a' - 'A');  
       }  
117    return macro_name;    return macro_name;
118  }  }
119    
# Line 194  skeleton_find (const char *envvar, const Line 197  skeleton_find (const char *envvar, const
197  {  {
198    const char *res = getenv (envvar);    const char *res = getenv (envvar);
199    
200  #ifdef MSDOS  #if defined (MSDOS) || defined (_WIN32)
201    const char *cp;    if (!res)
   
   /* File doesn't exist in current directory; try in INIT directory.  */  
   if (!res && (cp = getenv ("INIT")))  
202      {      {
203        res = XMALLOC (char, strlen (cp) + strlen (skeleton_name) + 2);        /* Skeleton file name without path */
204        sprintf (res, "%s%c%s", cp, '/', skeleton_name);        const char *skel_name = strrchr(skeleton_name, '/');
205          if (!skel_name)
206            skel_name = strrchr(skeleton_name, '\\');
207          if (!skel_name)
208            skel_name = skeleton_name;
209          else
210            ++skel_name;
211    
212          /* File doesn't exist in current directory; try in INIT directory.  */
213          const char *cp = getenv ("INIT");
214          if (cp)
215            {
216              res = XMALLOC (char, strlen (cp) + strlen (skel_name) + 2);
217              sprintf (res, "%s%c%s", cp, '\\', skel_name);
218            }
219          else if (access (skel_name, 4) == 0) /* Look in current dir. */
220            res = skel_name;
221          else
222            {
223              /* Look in program locations dir. */
224              extern char *program_name;
225              cp = strrchr(program_name, '\\');
226              if (!cp)
227                return skeleton_name;
228              else
229                ++cp;
230              res = XMALLOC (char, cp - program_name + strlen (skel_name) + 1);
231              strncpy (res, program_name, cp - program_name);
232              strcpy (res + (cp - program_name), skel_name);
233            }
234      }      }
235  #endif /* !MSDOS */  #endif /* defined (MSDOS) || defined (_WIN32) */
   
236    if (!res)    if (!res)
237      res = skeleton_name;      res = skeleton_name;
238    
# Line 260  get_extension_index (const char *filenam Line 288  get_extension_index (const char *filenam
288  static void  static void
289  compute_exts_from_gf (const char *ext)  compute_exts_from_gf (const char *ext)
290  {  {
291    /* Checks if SRC_EXTENSION is NULL. In the other case, %source_extension    src_extension = tr (ext, 'y', 'c');
292       was specified in the grammar file.  */    src_extension = tr (src_extension, 'Y', 'C');
293    if (src_extension == NULL)    header_extension = tr (ext, 'y', 'h');
294      {    header_extension = tr (header_extension, 'Y', 'H');
       src_extension = tr (ext, 'y', 'c');  
       src_extension = tr (src_extension, 'Y', 'C');  
     }  
   /* Checks if HEADER_EXTENSION is NULL. In the other case,  
      %header_extension was specified in the grammar file.  */  
   if (header_extension == NULL)  
     {  
       header_extension = tr (ext, 'y', 'h');  
       header_extension = tr (header_extension, 'Y', 'H');  
     }  
295  }  }
296    
297  /* Computes extensions from the given c source file extension. */  /* Computes extensions from the given c source file extension. */
# Line 395  compute_base_names (void) Line 413  compute_base_names (void)
413    }    }
414  }  }
415    
416    /*-------------------------------------------------------.
417    | Close the open files, compute the output files names.  |
418    `-------------------------------------------------------*/
419    
420    void
421    compute_output_file_names (void)
422    {
423      compute_base_names ();
424    
425      /* If not yet done. */
426      if (!src_extension)
427        src_extension = ".c";
428      if (!header_extension)
429        header_extension = ".h";
430    
431      /* It the defines filename if not given, we create it.  */
432      if (!spec_defines_file)
433        spec_defines_file = stringappend (base_name, header_extension);
434    
435      /* It the graph filename if not given, we create it.  */
436      if (!spec_graph_file)
437        spec_graph_file = stringappend (short_base_name, ".vcg");
438    
439      spec_verbose_file = stringappend (short_base_name, EXT_OUTPUT);
440    
441      attrsfile = stringappend (short_base_name, EXT_STYPE_H);
442    #ifndef MSDOS
443      attrsfile = stringappend (attrsfile, header_extension);
444    #endif /* MSDOS */
445    
446    }
447    
448  /*-----------------------------------------------------------------.  /*-----------------------------------------------------------------.
449  | Open the input file.  Look for the skeletons.  Find the names of |  | Open the input file.  Look for the skeletons.  Find the names of |
450  | the output files.  Prepare the obstacks.                         |  | the output files.  Prepare the obstacks.                         |
# Line 412  open_files (void) Line 462  open_files (void)
462    obstack_init (&defines_obstack);    obstack_init (&defines_obstack);
463    obstack_init (&guard_obstack);    obstack_init (&guard_obstack);
464    obstack_init (&output_obstack);    obstack_init (&output_obstack);
   obstack_init (&graph_obstack);  
465  }  }
466    
467    
468    
469  /*-----------------------------------------------------.  /*-----------------------.
470  | Close the open files, produce all the output files.  |  | Close the open file..  |
471  `-----------------------------------------------------*/  `-----------------------*/
472    
473  void  void
474  output_files (void)  close_files (void)
475  {  {
476    xfclose (finput);    xfclose (finput);
477    }
478    
479    compute_base_names ();  /*---------------------------.
480    | Produce the output files.  |
481    /* Set default extensions */  `---------------------------*/
   if (!src_extension)  
     src_extension = ".c";  
   if (!header_extension)  
     header_extension = ".h";  
   
   attrsfile = stringappend (short_base_name, EXT_STYPE_H);  
 #ifndef MSDOS  
   stringappend (attrsfile, header_extension);  
 #endif /* MSDOS */  
482    
483    void
484    output_files (void)
485    {
486    /* Output the main file.  */    /* Output the main file.  */
487    if (spec_outfile)    if (spec_outfile)
488      obstack_save (&table_obstack, spec_outfile);      obstack_save (&table_obstack, spec_outfile);
489    else    else
490      obstack_save (&table_obstack, stringappend (base_name, src_extension));      obstack_save (&table_obstack, stringappend (base_name, src_extension));
491      obstack_free (&table_obstack, NULL);
492    
493    /* Output the header file if wanted. */    /* Output the header file if wanted. */
494    if (defines_flag)    if (defines_flag)
495      defines_obstack_save (stringappend (base_name, header_extension));      defines_obstack_save (spec_defines_file);
496      obstack_free (&defines_obstack, NULL);
497    
498    #if 0
499      /* Seems to be invalid now --akim. */
500    
501    /* If we output only the table, dump the actions in ACTFILE. */    /* If we output only the table, dump the actions in ACTFILE. */
502    if (no_parser_flag)    if (no_parser_flag)
503      obstack_save (&action_obstack, stringappend (short_base_name, ".act"));      obstack_save (&action_obstack, stringappend (short_base_name, ".act"));
504      obstack_free (&action_obstack, NULL);
505    #endif
506    
507    /* If we produced a semantic parser ATTRS_OBSTACK must be dumped    /* If we produced a semantic parser ATTRS_OBSTACK must be dumped
508       into its own file, ATTTRSFILE.  */       into its own file, ATTTRSFILE.  */
# Line 460  output_files (void) Line 511  output_files (void)
511        char *temp_name;        char *temp_name;
512    
513        obstack_save (&attrs_obstack, attrsfile);        obstack_save (&attrs_obstack, attrsfile);
514          obstack_free (&attrs_obstack, NULL);
515        temp_name = stringappend (short_base_name, EXT_GUARD_C);        temp_name = stringappend (short_base_name, EXT_GUARD_C);
516  #ifndef MSDOS  #ifndef MSDOS
517        temp_name = stringappend (temp_name, src_extension);        temp_name = stringappend (temp_name, src_extension);
518  #endif /* MSDOS */  #endif /* MSDOS */
519        obstack_save (&guard_obstack, temp_name);        obstack_save (&guard_obstack, temp_name);
520          obstack_free (&guard_obstack, NULL);
521      }      }
   
   if (verbose_flag)  
     /* We used to use just .out if spec_name_prefix (-p) was used, but  
        that conflicts with Posix.  */  
     obstack_save (&output_obstack,  
                   stringappend (short_base_name, EXT_OUTPUT));  
   
   if (graph_flag)  
     obstack_save (&graph_obstack, stringappend (short_base_name, ".vcg"));  
522  }  }

Legend:
Removed from v.1.51  
changed lines
  Added in v.1.52

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26