home *** CD-ROM | disk | FTP | other *** search
- /* ------------------------------------------------------ */
- /* VIEWERR.C */
- /* Compilieren: cl /AL viewerr.c */
- /* (c) 1991 V.Iuorno & TOOLBOX */
- /* ------------------------------------------------------ */
- #include <stdlib.h>
- #include <stdio.h>
- #include <conio.h>
- #include <string.h>
- #include <ctype.h>
-
- #define HOME 'G' /* Home bei getch() */
- #define END 'O' /* End bei getch() */
- #define CURSUP 'H' /* Cursor up bei getch() */
- #define CURSDN 'P' /* Cursor down bei getch() */
- #define ESCAPE 27
- /* Cursor-Positionieren */
- #define CURSOR(line, pos) printf("%c[%02d;%02df", \
- ESCAPE, line, pos)
- #define CURHOME printf("%c[0;0f", ESCAPE)
- #define CURPOS CURSOR(LAST_BILD_LINE, 80)
- #define INVERS_ON printf("%c[1;7m", ESCAPE)
- #define INVERS_OFF printf("%c[1;0m", ESCAPE)
- #define LAST_BILD_LINE 25
- #define LAST_SOURCE_LINE 19
- #define FIRST_ERROR_LINE 21
- #define LAST_ERROR_LINE 24
- #define ANZERROR 4
- #define MAX_LINE 100
- #define TRENNZEILE \
- "----------------------------------------\
- ----------------------------------------" /* 80 */
- #define ENDZEILE "ESCAPE = Programm beenden"
- #define START_NR "("
- /* String an dem die Fehler-Zeilen-Nr. anfängt */
-
- /* --- Globale Daten ------------------------------------ */
- struct C_Zeile
- {
- char zeile[MAX_LINE]; /* C-Source-Zeile */
- struct C_Zeile *next; /* Pointer auf nächste Zeile */
- } *c;
- struct C_Zeile *Start_C; /* Pointer auf 1. Source-Zeile */
- unsigned short iTotC = 0; /* Total Source-Zeilen */
-
- struct E_Zeile
- {
- char zeile[MAX_LINE]; /* Fehler-Zeile */
- struct E_Zeile *next; /* Pointer auf nächste Zeile */
- struct E_Zeile *prior; /* Pointer auf vorherige Zeile */
- } *e;
- struct E_Zeile *Start_E, *Ende_E, *First_Bild_E, *Akt_E;
- unsigned short iAktE = 0;
- /* Position der aktuellen Fehlerzeile */
- unsigned short iTotE = 0; /* Total Fehler-Zeilen */
-
- /* --- Funktions-Prototypen ----------------------------- */
- void DispSource (struct C_Zeile *);
- void DispError (struct E_Zeile *);
- void ZeigeFehler(struct E_Zeile *);
- struct C_Zeile * PositionC(short nr);
- void Invers(int line, int pos, char *str);
-
- /* --- Hauptprogramm ------------------------------------ */
- void main(int argc, char *argv[])
- {
- FILE *C_fp; /* Source-Datei */
- FILE *E_fp; /* Fehler-File */
- char ErrorZeile[80];
- /* String um eine Fehler-Zeile zu identifizieren */
- char zeile[MAX_LINE]; /* Puffer für Fehler-Zeilen */
- struct C_Zeile *C_Temp;
- struct E_Zeile *E_Temp;
- char ch;
- register i; /* allgemeine Laufvariable */
-
- /* --- Richtige Anzahl Argumente prüfen ----------------- */
- if(argc != 3)
- {
- fprintf(stderr, "\nAufruf: %s C_pgm.c errfile", argv[0]);
- exit(1);
- }
-
- /* --- C-Source und Fehler-File öffnen ------------------ */
- if(! (C_fp = fopen(argv[1], "r")))
- {
- fprintf(stderr, "Kann File %s nicht öffnen!", argv[1]);
- exit(1);
- }
- if(! (E_fp = fopen(argv[2], "r")))
- {
- fprintf(stderr, "\nKann File %s nicht öffnen!", argv[2]);
- exit(1);
- }
-
- /* String bilden, um eine Fehlerzeile zu identifizieren */
- /* String besteht aus C-Source-Namen und START_NR */
- for(i = strlen(argv[1]) - 1; *(argv[1]+i) != '\\'
- && *(argv[1]+i) != ':' && i; i--);
- if(i) i++;
- strcpy(ErrorZeile, argv[1]+i);
- strcat(ErrorZeile, START_NR);
-
- /* Fehler-Zeilen einlesen */
- /* Speicher für erste Zeile anfordern */
- if(! (Start_E = (struct E_Zeile *)
- malloc(sizeof(struct E_Zeile))))
- {
- fprintf(stderr,"\nNicht genug freier Speicher!");
- exit(1);
- }
- Start_E->next = 0; Start_E->prior = 0;
- e = E_Temp = Start_E;
-
- while(fgets(zeile, MAX_LINE, E_fp))
- {
- if(strlen(zeile) > 80) /* Zeile begrenzen */
- *(zeile+80) = '\0';
- if(strstr(zeile, ErrorZeile)) /* Fehlerzeile? */
- { /* ja */
- strcpy(e->zeile, zeile);
- /*** Speicher für nächste Zeile anfordern ***/
- if(! (e->next = (struct E_Zeile *)
- malloc(sizeof(struct E_Zeile))))
- {
- fprintf(stderr,"\nNicht genug freier Speicher!");
- exit(1);
- }
- e->prior = E_Temp;
- E_Temp = e;
- e = e->next;
- iTotE++;
- }
- }
- Ende_E = E_Temp; /* Letzte Zeile */
- E_Temp->next = NULL;
- fclose(E_fp);
- if(! iTotE)
- {
- fprintf(stderr, "\nKeine Fehler in %s ", argv[1]);
- exit(0);
- }
- First_Bild_E = Start_E;
-
- /* C-Source-Zeilen einlesen ----------------------------- */
- /* Speicher für erste Zeile anfordern */
- if(! (Start_C = (struct C_Zeile *)
- malloc(sizeof(struct C_Zeile))))
- {
- fprintf(stderr,"\nNicht genug freier Speicher!");
- exit(1);
- }
- Start_C->next = 0;
- c = C_Temp = Start_C;
-
- while(fgets(c->zeile, MAX_LINE, C_fp))
- {
- if(strlen(c->zeile) > 80) /* Zeile begrenzen */
- *(c->zeile+80) = '\0';
- /*** Speicher für nächste Zeile anfordern ***/
- if(! (c->next = (struct C_Zeile *)
- malloc(sizeof(struct C_Zeile))))
- {
- fprintf(stderr,"\nNicht genug freier Speicher!");
- exit(1);
- }
- C_Temp = c;
- c = c->next;
- iTotC++;
- }
- C_Temp->next = NULL; /* Letzte Zeile */
- fclose(C_fp);
-
- /* --- Trenn- und Endzeile anzeigen --------------------- */
- CURSOR(LAST_SOURCE_LINE+1, 0); printf("%-80s", TRENNZEILE);
- CURSOR(LAST_BILD_LINE, 0); printf("%-79s", ENDZEILE);
-
- /* --- Fehler-Zeilen anzeigen --------------------------- */
- DispError(Start_E);
-
- /* --- Erste Fehlerhafte Zeile anzeigen ----------------- */
- ZeigeFehler(Start_E);
- Akt_E = Start_E;
- iAktE = 1;
- Invers(FIRST_ERROR_LINE, 0, Akt_E->zeile);
-
- /* --- Main Loop ---------------------------------------- */
- while((ch = getch()) != ESCAPE) /* Abbruch mit ESCAPE */
- {
- if(ch == CURSDN && Akt_E->next)
- {
- if(iAktE == 4)
- {
- First_Bild_E = First_Bild_E->next;
- DispError(First_Bild_E);
- Invers(LAST_ERROR_LINE, 0, Akt_E->next->zeile);
- }
- else
- {
- iAktE++;
- DispError(First_Bild_E);
- Invers(FIRST_ERROR_LINE+iAktE-1,
- 0, Akt_E->next->zeile);
- }
- Akt_E = Akt_E->next;
- ZeigeFehler(Akt_E);
- }
- else if(ch == CURSUP && Akt_E->prior)
- {
- if(iAktE == 1)
- {
- First_Bild_E = First_Bild_E->prior;
- DispError(First_Bild_E);
- Invers(FIRST_ERROR_LINE, 0, Akt_E->prior->zeile);
- }
- else
- {
- iAktE--;
- DispError(First_Bild_E);
- Invers(FIRST_ERROR_LINE+iAktE-1,
- 0, Akt_E->prior->zeile);
- }
- Akt_E = Akt_E->prior;
- ZeigeFehler(Akt_E);
- }
- else if(ch == HOME && Akt_E->prior)
- {
- iAktE = 1;
- First_Bild_E = Akt_E = Start_E;
- DispError(First_Bild_E);
- Invers(FIRST_ERROR_LINE, 0, Akt_E->zeile);
- ZeigeFehler(Akt_E);
- }
- else if(ch == END && Akt_E->next)
- {
- iAktE = 1;
- First_Bild_E = Akt_E = Ende_E;
- DispError(First_Bild_E);
- Invers(FIRST_ERROR_LINE, 0, Akt_E->zeile);
- ZeigeFehler(Akt_E);
- }
- }
- }
-
- /* --- Source-Zeilen anzeigen --------------------------- */
- void DispSource(struct C_Zeile *Anzeigen)
- {
- struct C_Zeile *Disp;
- register i;
-
- CURHOME; for(i = 1; i <= LAST_SOURCE_LINE; i++)
- printf("%80s", "");
- CURHOME; for(Disp = Anzeigen, i = 1;
- Disp && i <= LAST_SOURCE_LINE; i++)
- {
- printf("%s", Disp->zeile);
- Disp = Disp->next;
- }
- }
-
- /* --- Fehler-Zeilen anzeigen --------------------------- */
- void DispError(struct E_Zeile *Anzeigen)
- {
- struct E_Zeile *Disp;
- register i;
-
- CURSOR(FIRST_ERROR_LINE, 0);
- for(i = FIRST_ERROR_LINE; i <= LAST_ERROR_LINE; i++)
- printf("%80s", "");
- CURSOR(FIRST_ERROR_LINE, 0);
- for(Disp = Anzeigen, i = FIRST_ERROR_LINE;
- Disp && i <= LAST_ERROR_LINE; i++)
- {
- printf("%s", Disp->zeile);
- Disp = Disp->next;
- }
- }
-
- /* --- Fehlerhafte Zeile anzeigen ----------------------- */
- void ZeigeFehler(struct E_Zeile *Anzeigen)
- {
- short first = 0, line;
- struct C_Zeile *AnzFirst, *AnzFehler;
- register i;
- char *p, str[20];
- int znr;
- static int oldnr = 0;
-
- p = strstr(Anzeigen->zeile, START_NR);
- p++;
- for(i = 0; isdigit(*p); p++, i++) *(str+i) = *p;
- /* Zeilen-Nr. speichern */
- str[i] = '\0';
- znr = atoi(str);
- if(oldnr != znr && znr <= iTotC + 1)
- {
- oldnr = znr;
- first = znr - LAST_SOURCE_LINE / 2;
- /* Fehlerhafte Zeile zentrieren */
- if(first < 1) first = 1;
- line = first > 1 ? LAST_SOURCE_LINE / 2 + 1 : znr;
- AnzFirst = PositionC(first);
- AnzFehler = PositionC(znr);
- DispSource(AnzFirst);
- Invers(line, 0, AnzFehler->zeile);
- }
- }
-
- /* --- Auf eine bestimmte Source-Zeile positionieren ---- */
- struct C_Zeile * PositionC(short nr)
- {
- struct C_Zeile *Find = Start_C;
- register i;
-
- for(i = 1; Find && i != nr; i++)
- Find = Find->next;
- return Find;
- }
-
- /* --- Einen String invers anzeigen --------------------- */
- void Invers(int line, int pos, char *str)
- {
- INVERS_ON;
- CURSOR(line, pos); printf("%-80s", "");
- CURSOR(line, pos); printf("%s", str);
- INVERS_OFF; CURPOS;
- }
- /* ------------------------------------------------------ */
- /* Ende von VIEWERR.C */
-
-