home *** CD-ROM | disk | FTP | other *** search
- /* Copyright, 1990, Regents of the University of Colorado */
- #include <stdio.h>
- #include <string.h>
- #include <strings.h>
- #include <fcntl.h>
- #include "shell.h"
-
- BOOL warnings = TRUE; /* Display warning messages. */
- BOOL comments = FALSE; /* Display comment messages. */
- BOOL notes = FALSE; /* Display note messages. */
- BOOL aladin = FALSE; /* Display Attribute Grammar line numbers. */
- /*BOOL full = FALSE; /* Display complete source file. */
- BOOL lnumb = FALSE; /* Display source file line numbers. */
- BOOL order = TRUE; /*output messages in the order out of compiler*/
-
-
- int sourcefile;
- char sourcename[FILENAME] = "\0";
-
- enum level {note = 0,comment,warning,fatal,deadly};
- char *(msg_type[]) = {"NOTE", "COMMENT", "WARNING", "FATAL", "DEADLY"};
- enum level max_err = note;
-
- typedef struct segment{
- char file[FILENAME];
- int phys;
- int logical;
- } segment;
-
- typedef struct msg{
- int line;
- int col;
- int ala;
- enum level type;
- char mess[MESSLEN];
- char source[MESSLEN];
- struct msg *pt;
- segment *seg;
- } msg;
-
- msg *msgs, *cur;
-
- segment *seglist;
- int nsegs;
-
- char line_file_name[FILENAME];
-
- initsegs(){
- int line_file;
- char *line;
- char *pt, *q1, *q2;
- int i;
-
- if ((line_file = open(line_file_name, O_RDONLY)) == -1)
- {
- fprintf(stderr, "\nformat: Unable to open file %s\n\n",line_file_name);
- exit(1);
- }
- line = get_line(line_file);
- nsegs = strtol(line, &pt, 10);
- if((seglist = (segment*) malloc (sizeof(segment)*nsegs)) == NULL)
- {fprintf(stderr,"format:malloc segment\n"); exit(1);}
- for (i=0; i<nsegs; i++){
- line = get_line(line_file);
- seglist[i].phys = strtol(line, &pt, 10);
- seglist[i].logical = strtol(pt, &q2, 10);
- q1 = strchr(q2,'"');
- q2 = strchr(q1+1,'"');
- strncpy(seglist[i].file, q1, q2-q1+1);
- seglist[i].file[(q2-q1)+2] = '\0';
- }
- }
-
- #define MAX_ERROR 60
- msg error_list[MAX_ERROR];
- int next_error = 0;
-
- init(argc, argv)
- int argc;
- char *argv[];
- {
- int in;
-
- for (in = 1; in < argc; in++)
- if (argv[in][0] != '-'){
- strcpy(sourcename, argv[in]);
- }
- else switch(argv[in][1])
- {
- case 'F' : strcpy(line_file_name, &argv[in][2]); break;
- case 'a' : aladin = TRUE; break;
- case 'w' : warnings = FALSE; break;
- case 'c' : comments = TRUE; break;
- case 'n' : notes = TRUE; break;
- /* case 'f' : full = TRUE; break;*/
- case 'l' : lnumb = TRUE; break;
- case 'e' : order = FALSE;break;
- default : ;
- };
- /* if (full && !order){
- fprintf(stderr,"format: f and e flags not allowed together\n");
- order = TRUE;
- }*/
- msgs = error_list;
- next_error++;
- msgs -> line = 0;
- msgs -> col = 0;
- msgs -> ala = 0;
- msgs -> mess[0] = '\0';
- msgs -> pt = 0;
- msgs -> seg = 0;
- initsegs();
- };
-
- add_last()
- {
- msg *p;
- static msg end = {0,0,0,note};
- for (p=msgs; p->pt != NULL; p = p->pt);
- p->pt = &end;
- end.pt = NULL;
- };
-
- store(str)
- char *str;
- {
- char *comma = index(str, ',');
- int line, col, aladin;
- enum level type;
- char *pt1 = comma +7, *pt2 = comma + 7;
- msg *new, *search, *prev;
- BOOL found;
- char c;
- int i;
-
- if (next_error>=MAX_ERROR-2) return;
- if (comma == NULL) return;
- if (strncmp(comma,", line ",7) != 0) return;
-
- pt1 = pt2 = comma +7;
- line = strtol(pt1,&pt2,10);
- if (pt1 == pt2) return;
-
- pt1 = ++pt2;
- col = strtol(pt1,&pt2,10);
- if (pt1 == pt2) return;
-
- pt1 = ++ pt2;
- if (0== strncmp(pt1, "NOTE:",5)) {type = note; pt1 +=5;}
- else if (0== strncmp(pt1, "COMMENT:",8)) {type = comment; pt1 +=8;}
- else if (0== strncmp(pt1, "WARNING:",8)) {type = warning; pt1 +=8;}
- else if (0== strncmp(pt1, "FATAL:",6)) {type = fatal; pt1 +=6;}
- else if (0== strncmp(pt1, "DEADLY:",7)) {type = deadly; pt1 +=7;}
- else return;
-
- for (pt2 = pt1, c = *pt2;
- (c != '\0') && (c != '\n') && ((c < '0') || (c > '9'));
- pt2++, c = *pt2);
- if ((c == '\0') || (c == '\n')) aladin = 0;
- else {
- aladin = strtol(pt2, (char**)NULL,10);
- pt2 -=3;}
- *pt2 = '\0';
- if (max_err < type)
- max_err = type;
-
- new = &error_list[next_error++];
- new -> line = line;
- new -> col = col;
- new -> ala = aladin;
- new -> type = type;
- for (i=0; i<nsegs && line<=seglist[i].phys; i++);
- new -> seg = &seglist[i];
- strcpy(new ->mess, pt1); /* pt2-pt1*/
-
- if(order){
- for (prev = msgs, search = msgs->pt, found = FALSE;
- !(found || (search == NULL));
- )
- {
- if (line < search->line)
- found = TRUE;
- else if(line == search->line)
- if (col < search->col)
- found = TRUE;
- if (!found){
- prev = search;
- search = search->pt;
- }
- };
- new ->pt = search;
- prev ->pt = new;
- }
- else {
- new->pt = NULL;
- error_list[next_error-2].pt = new;
- }
- }
-
- dump_msgs(){
- int line = 0;
- msg *cur;
- char out[MESSLEN];
- BOOL print;
-
- for(cur=msgs->pt; cur->pt != NULL; cur = cur->pt){
- switch(cur->type){
- case note : print = notes; break;
- case comment : print = comments; break;
- case warning : print = warnings; break;
- case fatal :
- case deadly : print = TRUE;
- }
- if (print){
- int i,carat;
-
- if (!order || line != cur->line){
- if (lnumb) printf("%d\t",cur->line);
- printf("%s",cur->source);
- }
- line = cur->line;
- if (lnumb )
- carat = cur->col + 7;
- else carat = cur->col -1;
- for (i=0; i<carat; i++) out[i] = '-';
- out[i] = '^';
- out[i+1] = '\0';
- printf("%s\n%s %s %d %s\n",
- out,
- msg_type[cur->type],cur->seg->file,
- (cur->line) - (cur->seg->phys) + (cur->seg->logical),
- cur->mess);
- if (aladin && cur->ala >0)
- printf("\tLine %d in aladin file\n\n",cur->ala);
- }
- }
- }
-
- dump(str)
- char *str;
- {
- static int line = 1;
- BOOL print = FALSE;
- msg *grp;
- char out[MESSLEN];
-
- /* print = full;*/
- print = FALSE;
- if (order){
- for(grp = cur; (print == FALSE) && (grp->line == line); grp = grp ->pt)
- switch(grp->type){
- case note : print = notes; break;
- case comment : print = comments; break;
- case warning : print = warnings; break;
- case fatal :
- case deadly : print = TRUE;
- }
- if (print)
- strcpy(cur->source, str);
- for(; (cur->line == line) && (cur->pt != NULL); cur = cur ->pt);
- }
- else
- for( grp = msgs->pt; grp != NULL; grp = grp ->pt)
- if (grp->line == line)
- strcpy(grp->source, str);
- line++;
- }
-
- void main(argc, argv)
- int argc;
- char *argv[];
- {
- int done = FALSE;
- char *line;
-
- init(argc,argv);
- while (!done){
- line = get_line(0);
- if (*line != '\0')
- store(line);
- else done = TRUE;
- }
- add_last();
- if ((sourcefile = open(sourcename, O_RDONLY)) == -1)
- {
- fprintf(stderr, "\nformat: Unable to open file `%s' as source.\n\n",
- sourcename);
- exit(1);
- }
- cur = msgs->pt;
- done = FALSE;
- buf_count = 0;
- eof = 0;
- while (!done){
- line = get_line(sourcefile);
- if (*line != '\0')
- dump(line);
- else done = TRUE;
- }
- dump(" ");
- dump_msgs();
- exit(max_err+2);
- };
-