date and time created 83/08/11 20:49:31 by sam
[unix-history] / usr / src / old / as.vax / asmain.c
index 5a73720..53f692e 100644 (file)
@@ -2,7 +2,7 @@
  *     Copyright (c) 1982 Regents of the University of California
  */
 #ifndef lint
  *     Copyright (c) 1982 Regents of the University of California
  */
 #ifndef lint
-static char sccsid[] = "@(#)asmain.c 4.9 %G%";
+static char sccsid[] = "@(#)asmain.c 4.13 %G%";
 #endif not lint
 
 #include <stdio.h>
 #endif not lint
 
 #include <stdio.h>
@@ -14,14 +14,7 @@ static char sccsid[] = "@(#)asmain.c 4.9 %G%";
 #include "asscan.h"
 #include "asexpr.h"
 
 #include "asscan.h"
 #include "asexpr.h"
 
-#ifdef UNIX
-#define        unix_lang_name "VAX/UNIX Assembler V%G% 4.9"
-#endif
-
-#ifdef VMS
-#define vms_lang_name "VAX/VMS C Assembler V1.00"
-#endif VMS
-
+#define        unix_lang_name "VAX/UNIX Assembler V%G% 4.13"
 /*
  *     variables to manage reading the assembly source files
  */
 /*
  *     variables to manage reading the assembly source files
  */
@@ -51,13 +44,7 @@ int  debug = 0;
 int    toktrace = 0;
 #endif
 
 int    toktrace = 0;
 #endif
 
-int    useVM =         /*put the temp file in virtual memory*/
-#ifdef VMS
-       1;              /*VMS has virtual memory (duh)*/
-#endif VMS
-#ifdef UNIX
-       0;
-#endif
+int    useVM = 0;
 
 char   *endcore;       /*where to get more symbol space*/
 
 
 char   *endcore;       /*where to get more symbol space*/
 
@@ -82,11 +69,19 @@ u_long      drsize;         /* total data relocation size */
 struct exp     usedot[NLOC+NLOC];      /* info about all segments */
 struct exp     *dotp;                  /* data/text location pointer */
 /*
 struct exp     usedot[NLOC+NLOC];      /* info about all segments */
 struct exp     *dotp;                  /* data/text location pointer */
 /*
- *     The inter pass temporary file is opened and closed by stdio, but
+ *     The inter pass temporary token file is opened and closed by stdio, but
  *     is written to using direct read/write, as the temporary file
  *     is composed of buffers exactly BUFSIZ long.
  */
  *     is written to using direct read/write, as the temporary file
  *     is composed of buffers exactly BUFSIZ long.
  */
-FILE   *tmpfil;                        /* interpass communication file */
+FILE   *tokfile;                       /* interpass communication file */
+char   tokfilename[TNAMESIZE];
+/*
+ *     The string file is the string table
+ *     cat'ed to the end of the built up a.out file
+ */
+FILE   *strfile;                       /* interpass string file */
+char   strfilename[TNAMESIZE];
+int    strfilepos = 0;                 /* position within the string file */
 /*
  *     a.out is created during the second pass.
  *     It is opened by stdio, but is filled with the parallel
 /*
  *     a.out is created during the second pass.
  *     It is opened by stdio, but is filled with the parallel
@@ -163,17 +158,7 @@ BFILE      *relocfile;                     /* concatnated relocation info */
  *
  *     We use relfil to output the symbol table information.
  */
  *
  *     We use relfil to output the symbol table information.
  */
-
-char   *tmpdirprefix =
-#ifdef UNIX
-                       "/tmp/";
-#else VMS
-                       "/usr/tmp/";
-#endif
-
-#define                TMP_SUFFIX      "asXXXXXX"
-char           tmpn1[TNAMESIZE];
-
+char   *tmpdirprefix = "/tmp/";
 int delexit();
 
 main(argc, argv)
 int delexit();
 
 main(argc, argv)
@@ -182,7 +167,8 @@ main(argc, argv)
 {
        char    *sbrk();
 
 {
        char    *sbrk();
 
-       tmpn1[0] = 0;
+       tokfilename[0] = 0;
+       strfilename[0] = 0;
        endcore = sbrk(0);
 
        argprocess(argc, argv);         /* process argument lists */
        endcore = sbrk(0);
 
        argprocess(argc, argv);         /* process argument lists */
@@ -228,7 +214,7 @@ main(argc, argv)
                yywarning("These are not defined for all implementations of the VAX architecture.\n");
 
        exit(anyerrs != 0);
                yywarning("These are not defined for all implementations of the VAX architecture.\n");
 
        exit(anyerrs != 0);
-}      /*end of UNIX main*/
+}
 
 argprocess(argc, argv)
        int     argc;
 
 argprocess(argc, argv)
        int     argc;
@@ -259,6 +245,9 @@ argprocess(argc, argv)
                                        yyerror("Unknown flag: %c", *--cp);
                                        cp++;
                                        break;
                                        yyerror("Unknown flag: %c", *--cp);
                                        cp++;
                                        break;
+                                case 'v':
+                                       selfwhat(stdout);
+                                       exit(1);
                                 case 'd':
                                        d124 = *cp++ - '0';
                                        if ( (d124 != 1) && (d124 != 2) && 
                                 case 'd':
                                        d124 = *cp++ - '0';
                                        if ( (d124 != 1) && (d124 != 2) && 
@@ -317,6 +306,37 @@ argprocess(argc, argv)
        }
        /* innames[ninfiles] = 0; */
 }
        }
        /* innames[ninfiles] = 0; */
 }
+/*
+ *     poke through the data space and find all sccs identifiers.
+ *     We assume:
+ *     a) that extern char **environ; is the first thing in the bss
+ *     segment (true, if one is using the new version of cmgt.crt0.c)
+ *     b) that the sccsid's have not been put into text space.
+ */
+selfwhat(place)
+       FILE    *place;
+{
+       extern  char **environ;
+       register        char    *ub;
+       register        char *cp;
+       register        char    *pat;
+       char    *sbrk();
+
+       for (cp = (char *)&environ, ub = sbrk(0); cp < ub; cp++){
+               if (cp[0] != '@') continue;
+               if (cp[1] != '(') continue;
+               if (cp[2] != '#') continue;
+               if (cp[3] != ')') continue;
+               fputc('\t', place);
+               for (cp += 4; cp < ub; cp++){
+                       if (*cp == 0) break;
+                       if (*cp == '>') break;
+                       if (*cp == '\n') break;
+                       fputc(*cp, place);
+               }
+               fputc('\n', place);
+       }
+}
 
 initialize()
 {
 
 initialize()
 {
@@ -360,23 +380,40 @@ zerolocals()
 
 i_pass1()
 {
 
 i_pass1()
 {
-       if (useVM == 0){
-               strcat(tmpn1, tmpdirprefix);
-               if (tmpdirprefix[strlen(tmpdirprefix)-1] != '/')
-                       strcat(tmpn1, "/");
-               (void)strcat(tmpn1, TMP_SUFFIX);
-               (void)mktemp(tmpn1);
-               tmpfil = fopen(tmpn1, "w");
-               if (tmpfil==NULL) {
-                 yyerror("Bad pass 1 temporary file for writing %s", tmpn1);
-                 delexit();
-               }
-       }
+       FILE    *tempopen();
+       if (useVM == 0)
+               tokfile = tempopen(tokfilename, "T");
+       strfile = tempopen(strfilename, "S");
+       /*
+        *      write out the string length.
+        *      This will be overwritten when the
+        *      strings are tacked onto the growing a.out file
+        */
+       strfilepos = sizeof(int);
+       fwrite(&strfilepos, sizeof(int), 1, strfile);
 
 
-       inittmpfile();
+       inittokfile();
        initijxxx();
 }
 
        initijxxx();
 }
 
+FILE *tempopen(tname, part)
+       char    *tname;
+       char    *part;
+{
+       FILE    *file;
+       sprintf(tname, "%s%sas%s%05d",
+               tmpdirprefix,
+               (tmpdirprefix[strlen(tmpdirprefix)-1] != '/') ? "/" : 0,
+               part,
+               getpid());
+       file = fopen(tname, "w");
+       if (file == NULL) {
+               yyerror("Bad pass 1 temporary file for writing %s", tname);
+               delexit();
+       }
+       return(file);
+}
+
 pass1()
 {
        register        int     i;
 pass1()
 {
        register        int     i;
@@ -405,7 +442,7 @@ pass1()
                }
        }
 
                }
        }
 
-       closetmpfile();         /*kick out the last buffered intermediate text*/
+       closetokfile();         /*kick out the last buffered intermediate text*/
 }
 
 testlocals()
 }
 
 testlocals()
@@ -526,13 +563,15 @@ build_hdr()
 i_pass2()
 {
        if (useVM == 0) {
 i_pass2()
 {
        if (useVM == 0) {
-               fclose(tmpfil);
-               tmpfil = fopen(tmpn1, "r");
-               if (tmpfil==NULL) {
-                  yyerror("Bad pass 2 temporary file for reading %s", tmpn1);
+               fclose(tokfile);
+               tokfile = fopen(tokfilename, "r");
+               if (tokfile==NULL) {
+                  yyerror("Bad pass 2 temporary file for reading %s", tokfilename);
                   delexit();
                }
        }
                   delexit();
                }
        }
+       fclose(strfile);
+       strfile = fopen(strfilename, "r");
 }
 
 pass2()
 }
 
 pass2()
@@ -548,11 +587,11 @@ pass2()
        relfil = 0;             /* outrel takes care of the rest */
        initoutrel();
 
        relfil = 0;             /* outrel takes care of the rest */
        initoutrel();
 
-       inittmpfile();
+       inittokfile();
 
        yyparse();
 
 
        yyparse();
 
-       closetmpfile();
+       closetokfile();
 }
 
 fillsegments()
 }
 
 fillsegments()
@@ -592,9 +631,13 @@ reloc_syms()
                hdr.a_drsize = 0;
        }
        /*
                hdr.a_drsize = 0;
        }
        /*
-        *      Output the symbol table
-        *      and if FLEXNAMES is set, the string pool
+        *      Output the symbol table and the string pool
+        *
+        *      We must first rewind the string pool file to its beginning,
+        *      in case it was seek'ed into for fetching ascii and asciz
+        *      strings.
         */
         */
+       fseek(strfile, 0, 0);
        symwrite(relocfile);
 }
 
        symwrite(relocfile);
 }
 
@@ -617,8 +660,10 @@ delexit()
 
 delete()
 {
 
 delete()
 {
-       if (useVM == 0 || tmpn1[0])
-               unlink(tmpn1);
+       if (useVM == 0 || tokfilename[0])
+               unlink(tokfilename);
+       if (strfilename[0])
+               unlink(strfilename);
 }
 
 sawabort()
 }
 
 sawabort()