/[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.81 by akim, Tue Nov 12 08:05:59 2002 UTC revision 1.82 by eggert, Wed Dec 11 06:28:25 2002 UTC
# Line 21  Line 21 
21    
22    
23  #include "system.h"  #include "system.h"
24  #include "getargs.h"  
25    #include <error.h>
26    #include <get-errno.h>
27    
28    #include "complain.h"
29  #include "files.h"  #include "files.h"
30    #include "getargs.h"
31  #include "gram.h"  #include "gram.h"
 #include "error.h"  
 #include "complain.h"  
32    
33  /* From basename.c.  Almost a lie, as it returns a char *. */  /* From basename.c.  Almost a lie, as it returns a char *. */
34  const char *base_name (char const *name);  const char *base_name (char const *name);
# Line 50  char *spec_graph_file = NULL;   /* for - Line 53  char *spec_graph_file = NULL;   /* for -
53  char *spec_defines_file = NULL; /* for --defines. */  char *spec_defines_file = NULL; /* for --defines. */
54  char *parser_file_name = NULL;  char *parser_file_name = NULL;
55    
56  struniq_t grammar_file = NULL;  uniqstr grammar_file = NULL;
57  struniq_t current_file = NULL;  uniqstr current_file = NULL;
58    
59  static char *full_base_name = NULL;  static char *full_base_name = NULL;
60    
# Line 63  const char *src_extension = NULL; Line 66  const char *src_extension = NULL;
66  /* Header file extension (if option ``-d'' is specified).  */  /* Header file extension (if option ``-d'' is specified).  */
67  const char *header_extension = NULL;  const char *header_extension = NULL;
68    
   
 /*--------------------------.  
 | Is SUFFIX ending STRING?  |  
 `--------------------------*/  
   
 int  
 strsuffix (const char *string, const char *suffix)  
 {  
   size_t string_len = strlen (string);  
   size_t suffix_len = strlen (suffix);  
   if (suffix_len <= string_len)  
     return !strcmp (string + string_len - suffix_len, suffix);  
   else  
     return 0;  
 }  
   
   
69  /*-----------------------------------------------------------------.  /*-----------------------------------------------------------------.
70  | Return a newly allocated string composed of the concatenation of |  | Return a newly allocated string composed of the concatenation of |
71  | STRING1, and STRING2.                                            |  | STR1, and STR2.                                                  |
72  `-----------------------------------------------------------------*/  `-----------------------------------------------------------------*/
73    
74  char*  static char *
75  stringappend (const char *string1, const char *string2)  concat2 (char const *str1, char const *str2)
76  {  {
77    size_t len = strlen (string1) + strlen (string2);    size_t len = strlen (str1) + strlen (str2);
78    char *res = XMALLOC (char, len + 1);    char *res = XMALLOC (char, len + 1);
79    char *cp;    char *cp;
80    cp = stpcpy (res, string1);    cp = stpcpy (res, str1);
81    cp = stpcpy (cp, string2);    cp = stpcpy (cp, str2);
82    return res;    return res;
83  }  }
84    
# Line 108  xfopen (const char *name, const char *mo Line 94  xfopen (const char *name, const char *mo
94    
95    ptr = fopen (name, mode);    ptr = fopen (name, mode);
96    if (!ptr)    if (!ptr)
97      error (EXIT_FAILURE, errno, _("cannot open file `%s'"), name);      error (EXIT_FAILURE, get_errno (), _("cannot open file `%s'"), name);
98    
99    return ptr;    return ptr;
100  }  }
# Line 127  xfclose (FILE *ptr) Line 113  xfclose (FILE *ptr)
113      error (EXIT_FAILURE, 0, _("I/O error"));      error (EXIT_FAILURE, 0, _("I/O error"));
114    
115    if (fclose (ptr) != 0)    if (fclose (ptr) != 0)
116      error (EXIT_FAILURE, errno, _("cannot close file"));      error (EXIT_FAILURE, get_errno (), _("cannot close file"));
117  }  }
118    
119    
# Line 288  compute_base_names (void) Line 274  compute_base_names (void)
274    
275        full_base_name = XMALLOC (char,        full_base_name = XMALLOC (char,
276                                  strlen (short_base_name)                                  strlen (short_base_name)
277                                  + strlen (EXT_TAB) + 1);                                  + strlen (TAB_EXT) + 1);
278        stpcpy (stpcpy (full_base_name, short_base_name), EXT_TAB);        stpcpy (stpcpy (full_base_name, short_base_name), TAB_EXT);
279    
280        /* Computes the extensions from the grammar file name.  */        /* Computes the extensions from the grammar file name.  */
281        filename_split (grammar_file, &base, &tab, &ext);        filename_split (grammar_file, &base, &tab, &ext);
# Line 314  compute_output_file_names (void) Line 300  compute_output_file_names (void)
300      header_extension = ".h";      header_extension = ".h";
301    
302    parser_file_name =    parser_file_name =
303      spec_outfile ? spec_outfile : stringappend (full_base_name, src_extension);      spec_outfile ? spec_outfile : concat2 (full_base_name, src_extension);
304    
305    /* It the defines filename if not given, we create it.  */    /* It the defines filename if not given, we create it.  */
306    if (!spec_defines_file)    if (!spec_defines_file)
307      spec_defines_file = stringappend (full_base_name, header_extension);      spec_defines_file = concat2 (full_base_name, header_extension);
308    
309    /* It the graph filename if not given, we create it.  */    /* It the graph filename if not given, we create it.  */
310    if (!spec_graph_file)    if (!spec_graph_file)
311      spec_graph_file = stringappend (short_base_name, ".vcg");      spec_graph_file = concat2 (short_base_name, ".vcg");
312    
313    spec_verbose_file = stringappend (short_base_name, EXT_OUTPUT);    spec_verbose_file = concat2 (short_base_name, OUTPUT_EXT);
314  }  }

Legend:
Removed from v.1.81  
changed lines
  Added in v.1.82

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