home *** CD-ROM | disk | FTP | other *** search
- /* Figure from Kaypro column in Micro Cornucopia Magazine Issue #41
- * NOCMNT vers. 6/30/87
- *
- * Removes comments, trailing white space, and blank
- * lines from assembly language source files.
- *
- * Written for Small-C compiler vers. 2.03 (ASM)
- *
- * Note: does not properly handle literal semicolons
- * such as in DB ';' or CPI ';' or MVI A,';'.
- */
-
- #include <stdioa.h>
- #include "iolib.asm"
- #include "call.asm"
-
- #define MAXLINE 127
- #define NOCCARGC
- #define NOTFOUND -1
-
- char line[MAXLINE + 1];
-
- main() {
-
- int len, i, j;
-
- fputs("NOCMNT -- strips comments from .ASM files.\n",stderr);
- fputs("Usage: nocmnt <fatfile.asm >slimfile.asm\n",stderr);
-
- while ((len = getline(line, MAXLINE, stdin)) != NULL) {
- i = index(line,';');
- if (i == NOTFOUND) i = len;
- while (--i >= 0) /* find last non-blank char */
- if ((line[i] != ' ')
- && (line[i] != '\t')
- && (line[i] != '\n'))
- break;
- if (i == -1) continue; /* line is blank, so ignore it */
- line[i+1] = '\0'; /* otherwise mark new end */
- fputs(line,stdout); /* and send string to output */
- fputc('\n',stdout); /* followed by newline char */
- }
- }
-
-
- /*
- * Return position (i.e., array index) of first occurrence
- * of c in str, else -1.
- */
-
- index(str, c) char *str, c; {
- int i;
- i = 0;
- while(*str) {
- if(*str == c) return (i);
- ++str;
- ++i;
- }
- return (-1);
- }
-
- /*
- * Fetch a line of input from fd and store it
- * (including any terminating newline) in s.
- * Return the length of the fetched line. From
- * Kernighan and Ritchie, The C Programming
- * Language, copyright 1978.
- */
-
- getline(s, lim, fd) char s[]; int lim, fd; {
-
- int c, i;
-
- i=0;
- while (--lim > 0
- && (c=fgetc(fd)) != EOF
- && c != '\n')
- s[i++] = c;
- if (c == '\n')
- s[i++] = c;
- s[i] = '\0';
- return(i);
- }