C:/Users/Dennis/src/lang/russell.orig/src/extract_sig.c

Go to the documentation of this file.
00001 # include "parm.h"
00002 # include "stree/ststructs.mh"
00003 # include <a.out.h>
00004 # include <stdio.h>
00005 
00006 boolean Vflag = FALSE;
00007 boolean Gflag = TRUE;
00008 char * fn;
00009 FILE * obj_file;
00010 NODE * sig;
00011 extern FILE * unparse_file;
00012 
00013 /* Miscellaneous declarations to make this beast link correctly */
00014 char tokenbuf[1000];
00015 int avail_loc;
00016 
00017 typedef struct VrLine{
00018     int vr_vline,            /* virtual line number at which file */
00019                              /* change or line number jump occurred */
00020         vr_rline,            /* corresponding real line number */
00021         vr_fname;            /* string table index of filename */
00022     struct VrLine * vr_next; /* pointer to next record */  } vrline;
00023 
00024 vrline * vrtable = NIL,  /* pointers to first and last table entries */
00025        * vrtend  = NIL;
00026 
00027 int yyvline = 0;  /* curent virtual line number */
00028 
00029 yyperror(msg)
00030 char *msg;
00031 {  
00032     fprintf(stderr, "%s\n", msg);
00033     exit(1);
00034 }
00035 
00036 extern NODE * sig_in();
00037 
00038 main(argc,argv)
00039 int argc;
00040 char ** argv;
00041 {
00042     if (argc == 3) {
00043         if (strcmp(argv[1], "-V") != 0) {
00044             goto Usage;
00045         }
00046         Vflag = TRUE;
00047         fn = argv[2];
00048     } else if (argc != 2) {
00049         goto Usage;
00050     } else {
00051         fn = argv[1];
00052     }
00053 
00054     /* Fake vrtable, so it appears plausible */
00055         vrtable = vrtend = (vrline *) malloc(sizeof (vrline));
00056         vrtable -> vr_vline = vrtable -> vr_vline = 0;
00057         vrtable -> vr_fname = stt_enter(fn, strlen(fn)+1);
00058         vrtable -> vr_next = NIL;
00059 
00060     if ((obj_file = fopen(fn, "r")) == NULL) {
00061         fprintf(stderr, "Couldn't open %s\n", fn);
00062         exit(1);
00063     } else {
00064         long strsize;
00065         struct exec header;
00066         unsigned long optsize;
00067 
00068         /* seek past end of string table */
00069           fread(&header, sizeof (struct exec), 1, obj_file);
00070           fseek(obj_file, N_STROFF(header), 0);
00071           fread(&strsize, sizeof (long), 1, obj_file);
00072           fseek(obj_file, N_STROFF(header) + strsize, 0);
00073         printf("String table starts at 0x%X, compiler info starts at 0x%X\n",
00074                N_STROFF(header), N_STROFF(header) + strsize);
00075 #       if defined(SUN) && defined(EXTRA_MAGIC)
00076           /* Skip past secondary section header */
00077           {
00078             struct extra_sections es;
00079           
00080             fread(&es, sizeof (struct extra_sections), 1, obj_file);
00081             if (es.extra_magic != EXTRA_MAGIC) {
00082               printf("Bad secondary magic number %d\n",
00083                      es.extra_magic );
00084             }
00085             if (es.extra_nsects != 1) {
00086               printf("%d unrecognized extra section%s\n",
00087                      es.extra_nsects-1, (es.extra_nsects>2? "s" : ""));
00088             }
00089             /* Discard secondary section size */
00090               printf("Secondary section size = %d\n", getw(obj_file));
00091           }
00092 #       endif
00093 
00094         optsize = getw(obj_file);
00095         printf("Size of optimization info: %d; Object file list at 0x%X\n",
00096                 optsize, N_STROFF(header) + strsize + optsize + sizeof(int));
00097         fseek(obj_file, optsize, 1);
00098         
00099         printf("&etext = %d\n", getw(obj_file));
00100 
00101         /* Print list of embedded object files */
00102         {
00103             char str_buf[1000];  /* General purpose buffer */
00104             char *p;
00105             int c;  /* actually a character */
00106 
00107             if (Vflag) {
00108                 printf("Requires object files:\n");
00109             }
00110             do {
00111                 /* Read a line from obj_file */
00112                     p = str_buf;
00113                     do {
00114                         c = getc(obj_file);
00115                         if (c == '\n') {
00116                             *p = '\0';
00117                         } else if (c == EOF) {
00118                             fprintf(stderr, "%s has bad format\n",
00119                                     fn);
00120                                 exit(1);
00121                         } else {
00122                             *p++ = c;
00123                         }
00124                     } while (c != '\n');
00125                     if (Vflag && p != str_buf) {
00126                         printf("\t%s\n", str_buf);
00127                     }
00128             } while (p != str_buf);
00129             if (Vflag) {
00130                 printf("\n");
00131             }
00132         }
00133         printf("Signature starts at 0x%X\n", ftell(obj_file));
00134         /* Now read signature info */
00135             sig = sig_in(obj_file, fn);
00136             unparse_file = stdout;
00137             printf("Signature:\n\t");
00138             unparse(sig);
00139             printf("\n");
00140         printf("Signature ends at 0x%X\n", ftell(obj_file));
00141         if (Vflag) {
00142             printf("\n\nSignature in long form:\n");
00143             prtree(sig);
00144         }
00145         fclose(obj_file);
00146     }
00147     exit(0);
00148   Usage:
00149     fprintf(stderr, "Usage: %s [-V] filename.o\n", argv[0]);
00150     exit(1);
00151 }

Generated on Fri Jan 25 10:39:45 2008 for russell by  doxygen 1.5.4