Source Listing 31-MAR-2009 13:04:12 HP C V7.3-009-48GBT Page 1 12-APR-2006 12:45:38 _$1$DGA712:[LAISHEV.TOOLS.BISON-1_22]FILES.C;2 1 /* Open and close files for bison, 2 Copyright (C) 1984, 1986, 1989 Free Software Foundation, Inc. 3 4 This file is part of Bison, the GNU Compiler Compiler. 5 6 Bison is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 11 Bison is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with Bison; see the file COPYING. If not, write to 18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ 19 20 21 #ifdef VMS 22 #include 2173 #include 16147 #ifdef __DECC 16148 #define delete decc$delete 16149 #endif 16150 #include 18566 #define unlink delete 18567 #ifndef XPFILE 18568 #define XPFILE "sys$library:BISON.SIMPLE" 18569 #endif 18570 #ifndef XPFILE1 18571 #define XPFILE1 "sys$library:BISON.HAIRY" 18572 #endif 18573 #endif 18574 X 18575 #include 18576 #include "system.h" 21128 #include "files.h" 21181 #include "new.h" 21213 #include "gram.h" 21334 21335 #ifdef __DECC 21336 #define mktemp decc$mktemp 21337 #endif 21338 21339 FILE *finput = NULL; 21340 FILE *foutput = NULL; 21341 FILE *fdefines = NULL; 21342 FILE *ftable = NULL; 21343 FILE *fattrs = NULL; 21344 FILE *fguard = NULL; 21345 FILE *faction = NULL; 21346 FILE *fparser = NULL; 21347 21348 /* File name specified with -o for the output file, or 0 if no -o. */ 21349 char *spec_outfile; Source Listing 31-MAR-2009 13:04:12 HP C V7.3-009-48GBT Page 2 12-APR-2006 12:45:38 _$1$DGA712:[LAISHEV.TOOLS.BISON-1_22]FILES.C;2 21350 21351 char *infile; 21352 char *outfile; 21353 char *defsfile; 21354 char *tabfile; 21355 char *attrsfile; 21356 char *guardfile; 21357 char *actfile; 21358 char *tmpattrsfile; 21359 char *tmptabfile; 21360 char *tmpdefsfile; 21361 21362 extern char *mktemp(); /* So the compiler won't complain */ 21363 extern char *getenv(); 21364 extern void perror(); 21365 FILE *tryopen(); /* This might be a good idea */ 21366 void done(); 21367 21368 extern char *program_name; 21369 extern int verboseflag; 21370 extern int definesflag; 21371 int fixed_outfiles = 0; Source Listing 31-MAR-2009 13:04:12 HP C V7.3-009-48GBT Page 3 12-APR-2006 12:45:38 _$1$DGA712:[LAISHEV.TOOLS.BISON-1_22]FILES.C;2 21373 21374 char* 21375 stringappend(string1, end1, string2) 21376 char *string1; 21377 int end1; 21378 char *string2; 1 21379 { 1 21380 register char *ostring; 1 21381 register char *cp, *cp1; 1 21382 register int i; 1 21383 1 21384 cp = string2; i = 0; 1 21385 while (*cp++) i++; 1 21386 1 21387 ostring = NEW2(i+end1+1, char); 1 21388 1 21389 cp = ostring; 1 21390 cp1 = string1; 1 21391 for (i = 0; i < end1; i++) 1 21392 *cp++ = *cp1++; 1 21393 1 21394 cp1 = string2; 1 21395 while (*cp++ = *cp1++) ; 1 21396 1 21397 return ostring; 1 21398 } 21399 21400 21401 #ifdef VMS 21402 #include 21739 21740 char * 21741 strlwr (s) 21742 char *s; 1 21743 { 1 21744 char *s0 = s; 1 21745 if (s == 0) 1 21746 return 0; 1 21747 1 21748 for (; *s != '\0';) 2 21749 { 2 21750 /* VAX C Compiles this wrongly!!! s is advanced before tolower(*s) 2 21751 is executed. That's why we have to do this operation the other 2 21752 way... -- Richard Levitte */ 2X 21753 #if 0 2X 21754 *s++ = tolower (*s); 2X 21755 #else 2 21756 *s = tolower(*s); 2 21757 s++; 2 21758 #endif 1 21759 } 1 21760 1 21761 return s0; 1 21762 } 21763 #endif /* VMS */ 21764 21765 /* JF this has been hacked to death. Nowaday it sets up the file names for Source Listing 31-MAR-2009 13:04:12 HP C V7.3-009-48GBT Page 4 12-APR-2006 12:45:38 _$1$DGA712:[LAISHEV.TOOLS.BISON-1_22]FILES.C;2 21766 the output files, and opens the tmp files and the parser */ 21767 void 21768 openfiles() 1 21769 { 1 21770 char *name_base; 1 21771 register char *cp; 1 21772 char *filename; 1 21773 int base_length; 1 21774 int short_base_length; 1 21775 1 21776 #ifdef VMS 1 21777 char *tmp_base = "sys$scratch:b_"; 1X 21778 #else 1X 21779 char *tmp_base = "/tmp/b."; 1X 21780 #endif 1 21781 int tmp_len; 1 21782 1X 21783 #ifdef MSDOS 1X 21784 tmp_base = getenv ("TMP"); 1X 21785 if (tmp_base == 0) 1X 21786 tmp_base = ""; 1X 21787 #endif /* MSDOS */ 1 21788 #if defined(MSDOS) || defined(VMS) 1 21789 strlwr (infile); 1 21790 #endif /* MSDOS || VMS */ 1 21791 1 21792 1 21793 tmp_len = strlen (tmp_base); 1 21794 1 21795 if (spec_outfile) 2 21796 { 2 21797 /* -o was specified. The precise -o name will be used for ftable. 2 21798 For other output files, remove the ".c" or ".tab.c" suffix. */ 2 21799 name_base = spec_outfile; 2 21800 #if defined(MSDOS) || defined(VMS) 2 21801 strlwr (name_base); 2 21802 #endif /* MSDOS || VMS */ 2 21803 /* BASE_LENGTH includes ".tab" but not ".c". */ 2 21804 base_length = strlen (name_base); 2 21805 if (!strcmp (name_base + base_length - 2, ".c")) 2 21806 base_length -= 2; 2 21807 /* SHORT_BASE_LENGTH includes neither ".tab" nor ".c". */ 2 21808 short_base_length = base_length; 2 21809 if (!strncmp (name_base + short_base_length - 4, ".tab", 4)) 2 21810 short_base_length -= 4; 2 21811 else if (!strncmp (name_base + short_base_length - 4, "_tab", 4)) 2 21812 short_base_length -= 4; 1 21813 } 1 21814 else if (spec_file_prefix) 2 21815 { 2 21816 /* -b was specified. Construct names from it. */ 2 21817 /* SHORT_BASE_LENGTH includes neither ".tab" nor ".c". */ 2 21818 short_base_length = strlen (spec_file_prefix); 2 21819 /* Count room for `.tab'. */ 2 21820 base_length = short_base_length + 4; 2 21821 name_base = (char *) xmalloc (base_length + 1); 2 21822 /* Append `.tab'. */ Source Listing 31-MAR-2009 13:04:12 HP C V7.3-009-48GBT Page 5 12-APR-2006 12:45:38 _$1$DGA712:[LAISHEV.TOOLS.BISON-1_22]FILES.C;2 2 21823 strcpy (name_base, spec_file_prefix); 2 21824 #ifdef VMS 2 21825 strcat (name_base, "_tab"); 2X 21826 #else 2X 21827 strcat (name_base, ".tab"); 2X 21828 #endif 2 21829 #if defined(MSDOS) || defined(VMS) 2 21830 strlwr (name_base); 2 21831 #endif /* MSDOS || VMS */ 1 21832 } 1 21833 else 2 21834 { 2 21835 /* -o was not specified; compute output file name from input 2 21836 or use y.tab.c, etc., if -y was specified. */ 2 21837 2 21838 name_base = fixed_outfiles ? "y.y" : infile; 2 21839 2 21840 /* BASE_LENGTH gets length of NAME_BASE, sans ".y" suffix if any. */ 2 21841 2 21842 base_length = strlen (name_base); 2 21843 if (!strcmp (name_base + base_length - 2, ".y")) 2 21844 base_length -= 2; 2 21845 short_base_length = base_length; 2 21846 2 21847 #ifdef VMS 2 21848 name_base = stringappend(name_base, short_base_length, "_tab"); 2X 21849 #else 2X 21850 #ifdef MSDOS 2X 21851 name_base = stringappend(name_base, short_base_length, "_tab"); 2X 21852 #else 2X 21853 name_base = stringappend(name_base, short_base_length, ".tab"); 2X 21854 #endif /* not MSDOS */ 2X 21855 #endif 2 21856 base_length = short_base_length + 4; 1 21857 } 1 21858 1 21859 finput = tryopen(infile, "r"); 1 21860 1 21861 filename = getenv("BISON_SIMPLE"); 1X 21862 #ifdef MSDOS 1X 21863 /* File doesn't exist in current directory; try in INIT directory. */ 1X 21864 cp = getenv("INIT"); 1X 21865 if (filename == 0 && cp != NULL) 1X 21866 { 1X 21867 filename = xmalloc(strlen(cp) + strlen(PFILE) + 2); 1X 21868 strcpy(filename, cp); 1X 21869 cp = filename + strlen(filename); 1X 21870 *cp++ = '/'; 1X 21871 strcpy(cp, PFILE); 1X 21872 } 1X 21873 #endif /* MSDOS */ 1 21874 fparser = tryopen(filename ? filename : PFILE, "r"); 1 21875 1 21876 if (verboseflag) 2 21877 { 2X 21878 #ifdef MSDOS 2X 21879 outfile = stringappend(name_base, short_base_length, ".out"); Source Listing 31-MAR-2009 13:04:12 HP C V7.3-009-48GBT Page 6 12-APR-2006 12:45:38 _$1$DGA712:[LAISHEV.TOOLS.BISON-1_22]FILES.C;2 2X 21880 #else 2 21881 /* We used to use just .out if spec_name_prefix (-p) was used, 2 21882 but that conflicts with Posix. */ 2 21883 outfile = stringappend(name_base, short_base_length, ".output"); 2 21884 #endif 2 21885 foutput = tryopen(outfile, "w"); 1 21886 } 1 21887 1X 21888 #ifdef MSDOS 1X 21889 actfile = mktemp(stringappend(tmp_base, tmp_len, "acXXXXXX")); 1X 21890 tmpattrsfile = mktemp(stringappend(tmp_base, tmp_len, "atXXXXXX")); 1X 21891 tmptabfile = mktemp(stringappend(tmp_base, tmp_len, "taXXXXXX")); 1X 21892 tmpdefsfile = mktemp(stringappend(tmp_base, tmp_len, "deXXXXXX")); 1X 21893 #else 1 21894 actfile = mktemp(stringappend(tmp_base, tmp_len, "act.XXXXXX")); 1 21895 tmpattrsfile = mktemp(stringappend(tmp_base, tmp_len, "attrs.XXXXXX")); 1 21896 tmptabfile = mktemp(stringappend(tmp_base, tmp_len, "tab.XXXXXX")); 1 21897 tmpdefsfile = mktemp(stringappend(tmp_base, tmp_len, "defs.XXXXXX")); 1 21898 #endif /* not MSDOS */ 1 21899 1 21900 faction = tryopen(actfile, "w+"); 1 21901 fattrs = tryopen(tmpattrsfile,"w+"); 1 21902 ftable = tryopen(tmptabfile, "w+"); 1 21903 1 21904 if (definesflag) 2 21905 { 2 21906 defsfile = stringappend(name_base, base_length, ".h"); 2 21907 fdefines = tryopen(tmpdefsfile, "w+"); 1 21908 } 1 21909 1 21910 #ifndef MSDOS 1 21911 unlink(actfile); 1 21912 unlink(tmpattrsfile); 1 21913 unlink(tmptabfile); 1 21914 unlink(tmpdefsfile); 1 21915 #endif 1 21916 1 21917 /* These are opened by `done' or `open_extra_files', if at all */ 1 21918 if (spec_outfile) 1 21919 tabfile = spec_outfile; 1 21920 else 1 21921 tabfile = stringappend(name_base, base_length, ".c"); 1 21922 1 21923 #ifdef VMS 1 21924 attrsfile = stringappend(name_base, short_base_length, "_stype.h"); 1 21925 guardfile = stringappend(name_base, short_base_length, "_guard.c"); 1X 21926 #else 1X 21927 #ifdef MSDOS 1X 21928 attrsfile = stringappend(name_base, short_base_length, ".sth"); 1X 21929 guardfile = stringappend(name_base, short_base_length, ".guc"); 1X 21930 #else 1X 21931 attrsfile = stringappend(name_base, short_base_length, ".stype.h"); 1X 21932 guardfile = stringappend(name_base, short_base_length, ".guard.c"); 1X 21933 #endif /* not MSDOS */ 1X 21934 #endif /* not VMS */ 1 21935 } 21936 Source Listing 31-MAR-2009 13:04:12 HP C V7.3-009-48GBT Page 7 12-APR-2006 12:45:38 _$1$DGA712:[LAISHEV.TOOLS.BISON-1_22]FILES.C;2 21937 21938 21939 /* open the output files needed only for the semantic parser. 21940 This is done when %semantic_parser is seen in the declarations section. */ 21941 21942 void 21943 open_extra_files() 1 21944 { 1 21945 FILE *ftmp; 1 21946 int c; 1 21947 char *filename, *cp; 1 21948 1 21949 fclose(fparser); 1 21950 1 21951 filename = (char *) getenv ("BISON_HAIRY"); 1X 21952 #ifdef MSDOS 1X 21953 /* File doesn't exist in current directory; try in INIT directory. */ 1X 21954 cp = getenv("INIT"); 1X 21955 if (filename == 0 && cp != NULL) 1X 21956 { 1X 21957 filename = xmalloc(strlen(cp) + strlen(PFILE1) + 2); 1X 21958 strcpy(filename, cp); 1X 21959 cp = filename + strlen(filename); 1X 21960 *cp++ = '/'; 1X 21961 strcpy(cp, PFILE1); 1X 21962 } 1X 21963 #endif 1 21964 fparser= tryopen(filename ? filename : PFILE1, "r"); 1 21965 1 21966 /* JF change from inline attrs file to separate one */ 1 21967 ftmp = tryopen(attrsfile, "w"); 1 21968 rewind(fattrs); 1 21969 while((c=getc(fattrs))!=EOF) /* Thank god for buffering */ 1 21970 putc(c,ftmp); 1 21971 fclose(fattrs); 1 21972 fattrs=ftmp; 1 21973 1 21974 fguard = tryopen(guardfile, "w"); 1 21975 1 21976 } 21977 21978 /* JF to make file opening easier. This func tries to open file 21979 NAME with mode MODE, and prints an error message if it fails. */ 21980 FILE * 21981 tryopen(name, mode) 21982 char *name; 21983 char *mode; 1 21984 { 1 21985 FILE *ptr; 1 21986 1 21987 ptr = fopen(name, mode); 1 21988 if (ptr == NULL) 2 21989 { 2 21990 fprintf(stderr, "%s: ", program_name); 2 21991 perror(name); 2 21992 done(2); 1 21993 } Source Listing 31-MAR-2009 13:04:12 HP C V7.3-009-48GBT Page 8 12-APR-2006 12:45:38 _$1$DGA712:[LAISHEV.TOOLS.BISON-1_22]FILES.C;2 1 21994 return ptr; 1 21995 } 21996 21997 void 21998 done(k) 21999 int k; 1 22000 { 1 22001 if (faction) 1 22002 fclose(faction); 1 22003 1 22004 if (fattrs) 1 22005 fclose(fattrs); 1 22006 1 22007 if (fguard) 1 22008 fclose(fguard); 1 22009 1 22010 if (finput) 1 22011 fclose(finput); 1 22012 1 22013 if (fparser) 1 22014 fclose(fparser); 1 22015 1 22016 if (foutput) 1 22017 fclose(foutput); 1 22018 1 22019 /* JF write out the output file */ 1 22020 if (k == 0 && ftable) 2 22021 { 2 22022 FILE *ftmp; 2 22023 register int c; 2 22024 2 22025 ftmp=tryopen(tabfile, "w"); 2 22026 rewind(ftable); 2 22027 while((c=getc(ftable)) != EOF) 2 22028 putc(c,ftmp); 2 22029 fclose(ftmp); 2 22030 fclose(ftable); 2 22031 2 22032 if (definesflag) 3 22033 { 3 22034 ftmp = tryopen(defsfile, "w"); 3 22035 fflush(fdefines); 3 22036 rewind(fdefines); 3 22037 while((c=getc(fdefines)) != EOF) 3 22038 putc(c,ftmp); 3 22039 fclose(ftmp); 3 22040 fclose(fdefines); 2 22041 } 1 22042 } 1 22043 1 22044 #ifdef VMS 1 22045 if (faction) 1 22046 unlink(actfile); 1 22047 if (fattrs) 1 22048 unlink(tmpattrsfile); 1 22049 if (ftable) 1 22050 unlink(tmptabfile); Source Listing 31-MAR-2009 13:04:12 HP C V7.3-009-48GBT Page 9 12-APR-2006 12:45:38 _$1$DGA712:[LAISHEV.TOOLS.BISON-1_22]FILES.C;2 1 22051 if (k==0) sys$exit(SS$_NORMAL); 1 22052 sys$exit(SS$_ABORT); 1X 22053 #else 1X 22054 #ifdef MSDOS 1X 22055 if (actfile) unlink(actfile); 1X 22056 if (tmpattrsfile) unlink(tmpattrsfile); 1X 22057 if (tmptabfile) unlink(tmptabfile); 1X 22058 if (tmpdefsfile) unlink(tmpdefsfile); 1X 22059 #endif /* MSDOS */ 1X 22060 exit(k); 1X 22061 #endif /* not VMS */ 1 22062 } Command Line ------- ---- CC/INCLU=[]/LIS FILES.C Hardware: /ARCHITECTURE=GENERIC /OPTIMIZE=TUNE=GENERIC These macros are in effect at the start of the compilation. ----- ------ --- -- ------ -- --- ----- -- --- ------------ __G_FLOAT=1 __DECC=1 vms=1 VMS=1 __32BITS=1 __PRAGMA_ENVIRONMENT=1 __CRTL_VER=80300000 __vms_version="V8.3 " CC$gfloat=1 __X_FLOAT=1 vms_version="V8.3 " __DATE__="Mar 31 2009" __STDC_VERSION__=199901L __DECC_MODE_RELAXED=1 __DECC_VER=70390009 __VMS=1 __ALPHA=1 VMS_VERSION="V8.3 " __IEEE_FLOAT=0 __VMS_VERSION="V8.3 " __TIME__="13:04:12" __Alpha_AXP=1 __VMS_VER=80300022 __BIASED_FLT_ROUNDS=2 __INITIAL_POINTER_SIZE=0 __STDC__=2 __LANGUAGE_C__=1 __vms=1 __alpha=1 __D_FLOAT=0