astrip.c
./driver3.2@242/hosts/amiga/astrip.c · 1.8 KB
From the archive driver3.2@242.tar.gz
Download the archive « Back to the archive contents
#include <stdio.h>
#include <string.h>
#define VERSION "0.5"
static char inbuf[10240], outbuf[10240];
static int result = 0;
static int nodebug = 0;
static void usage() {
printf ("astrip <asmfile> <new asmfile> [nodebug]\n\n");
printf ("astrip %s -- Copyleft by Lars Düning\n\n", VERSION);
printf ("Takes the assembler source produces by a compiler and strips\n");
printf ("off all empty and commenting lines (i.e. lines starting with\n");
printf ("a ';' or a '*').\n");
printf ("If 'nodebug' is given, also all 'debug' statements are omitted.\n");
exit (0);
}
int convert_file (char *in, char *out) {
FILE *fin, *fout;
char line[256];
int c;
if ((fin = fopen (in, "r")) == NULL) {
fprintf (stderr, "Can't open sourcefile '%s'\n", in);
result = 20;
return 0;
}
if ((fout = fopen (out, "w")) == NULL) {
fprintf (stderr, "Can't open new sourcefile '%s'\n", out);
fclose (fin);
result = 20;
return 0;
}
setvbuf (fin, inbuf, _IOFBF, sizeof(inbuf));
setvbuf (fout, outbuf, _IOFBF, sizeof(outbuf));
/* The skiping of the commenting lines must be done charwise
** because the preprocessor/compiler generates lines of
** arbitrary length.
** The generated assembler lines are of limited length.
*/
while ((c = getc(fin)) != EOF) {
if (c && c != '\n' && c != ';' && c != '*') {
line[0] = c; line[1] = '\0';
fgets (line+1, 254, fin);
if (!nodebug || strncmp (line, "\tdebug\t", 7))
fputs (line, fout);
}
else
while (c != '\n' && (c = getc(fin)) != EOF);
}
fclose (fout);
fclose (fin);
return 0;
}
int main (int argc, char **argv) {
if (argc < 3 || argc > 4) usage();
if (argc >= 4 && !stricmp (*(argv+3), "nodebug")) nodebug = 1;
if (!convert_file (*(argv+1), *(argv+2))) goto byebye;
byebye:
exit(result);
}