home *** CD-ROM | disk | FTP | other *** search
- #define kNoChanges 0
- #define kChanges 1
- #define kBadArgument 2
- #define kIOErr 3
-
- enum {FALSE, TRUE};
-
- #include <types.h>
- #include <CType.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <CursorCtl.h>
- #include <Files.h>
-
-
- // # 70: bra L#7
- // ### Warning 210 ### A short branch could be used here
- // File ":test.c.a"; line 70
- // # 80: bgt L#9
- // ### Warning 212 ### Short branch used
- // File ":test.c.a"; line 80
-
- char *progname;
- char *warning1 = "### Warning 210 ### A short branch could be used here";
- char *warning2 = "### Warning 212 ### Short branch used";
- char *semiLine = "; line ";
-
- FILE *errFile;
- FILE *asmFile;
- FILE *outFile;
-
-
- void ShowUsage(void);
- int ConvertToNumber(char *numString);
- FILE *mpw_fopen(char *name, char *mode);
-
-
- int main (int argc, char **argv)
- {
- register int i;
- char *errFileName = 0;
- char *asmFileName = 0;
- char *outFileName = 0;
- char errBuf[250];
- char asmBuf[250];
- char *numPtr;
- int beforeLine = 1;
- int lineToFind;
- int numberOfChanges = 0;
- Boolean progress = FALSE;
- Boolean doNextLine = FALSE;
-
- progname = argv[0];
-
- /* Prepare to spin the beach ball. */
- InitCursorCtl (nil);
-
- for (i = 1; i < argc; i++) {
- if (argv[i][0] == '-' && argv[i][1] != 0) {
- register char *str = argv[i] + 1;
- if (!strcmp (str, "e"))
- errFileName = argv[++i];
- else if (!strcmp (str, "a"))
- asmFileName = argv[++i];
- else if (!strcmp (str, "o"))
- outFileName = argv[++i];
- else if (!strcmp (str, "p"))
- progress = TRUE;
- else {
- fprintf(stderr, "Invalid option `%s'", argv[i]);
- ShowUsage();
- exit(kBadArgument);
- }
- }
- else {
- fprintf(stderr, "### Error: Invalid option `%s'", argv[i]);
- ShowUsage();
- exit(kBadArgument);
- }
- }
-
- if (errFileName == 0) {
- errFile = stdin;
- errFileName = "stdin";
- } else
- errFile = fopen(errFileName, "r");
- if (errFile == 0) {
- fprintf(stderr, "### Error: Could not open file: %s.\n", errFileName);
- exit(kIOErr);
- }
-
- if (asmFileName == 0) {
- fprintf(stderr, "### Error: must specify -a file for now.\n");
- exit(kBadArgument);
- } else
- asmFile = fopen(asmFileName, "r");
- if (asmFile == 0) {
- fprintf(stderr, "### Error: Could not open file: %s.\n", asmFileName);
- exit(kIOErr);
- }
-
- if (outFileName == 0) {
- outFile = stdout;
- outFileName = "stdout";
- } else
- outFile = mpw_fopen(outFileName, "w");
- if (outFile == 0) {
- fprintf(stderr, "### Error: Could not open file: %s.\n", outFileName);
- exit(kIOErr);
- }
-
- if (progress) {
- fprintf(stderr, "err file: %s.\n", errFileName);
- fprintf(stderr, "asm file: %s.\n", asmFileName);
- fprintf(stderr, "out file: %s.\n", outFileName);
- }
-
- do {
- SpinCursor(1);
-
- //
- // Get a line from the error message file
- //
- if (fgets(errBuf, 250, errFile)) {
- //
- // We got one. Now see if we are looking for a message
- // or a line number.
- //
- if (!doNextLine) {
- //
- // Looking for a message. Remove the carriage
- // return and compare the message against one of
- // the ones we are looking for. If we find a match,
- // set a flag that causes us to get the line number
- // from the next line.
- //
- if (errBuf[strlen(errBuf)-1] == '\n')
- errBuf[strlen(errBuf)-1] = 0;
- if (!strcmp(errBuf, warning1)) {
- doNextLine = TRUE;
- }
- } else {
- //
- // This is a line that follows one of the warning
- // messages we are looking for. Find the line number
- // that is printed on it.
- //
- numPtr = strstr(errBuf, semiLine);
- if (numPtr) {
- //
- // Found "; Line ". Next convert the number after
- // it into an integer, scoot to that line in the
- // asm file, modify it, and write it to the output
- // file. All other lines between the current one
- // and the one we are looking for are echoed
- // without being changed.
- //
- lineToFind = ConvertToNumber(numPtr + strlen(semiLine));
- do {
- fgets(asmBuf, 250, asmFile);
- if (beforeLine == lineToFind) {
- memmove(asmBuf+6, asmBuf+4, strlen(asmBuf)-4+1);
- asmBuf[4] = '.';
- asmBuf[5] = 's';
- numberOfChanges++;
- }
- fputs(asmBuf, outFile);
- beforeLine++;
- } while (beforeLine <= lineToFind);
- }
- doNextLine = FALSE;
- }
- }
- } while (!feof(errFile) && !ferror(errFile));
-
-
- //
- // Write out the rest of the file.
- //
- while (fgets(asmBuf, 250, asmFile)) {
- SpinCursor(1);
- fputs(asmBuf, outFile);
- }
-
- return (numberOfChanges > 0) ? kChanges : kNoChanges;
- }
-
-
- void ShowUsage(void)
- {
- }
-
- int ConvertToNumber(char *numString)
- {
- int numSoFar = 0;
-
- while (isdigit(*numString)) {
- numSoFar = numSoFar * 10 + (*numString - '0');
- numString++;
- }
-
- return numSoFar;
- }
-
- FILE *mpw_fopen(char *name, char *mode)
- {
- char *pname = (char *) malloc(strlen(name) + 2);
- OSErr e;
- FILE *fp;
- struct FInfo fi;
-
- pname[0] = strlen(name);
- strcpy(pname+1, name);
-
- fp = fopen(name, mode);
-
- e = GetFInfo(pname, 0, &fi);
- /* should do spiffier error handling */
- if (e != 0) printf("%d\n", e);
- fi.fdType = (OSType) 'TEXT';
- fi.fdCreator = (OSType) 'MPS ';
- e = SetFInfo(pname, 0, &fi);
- if (e != 0) printf("%d\n", e);
- return fp;
- }
-