home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Oakland CPM Archive
/
oakcpm.iso
/
sigm
/
vol179
/
trace.lbr
/
TRACE.CQ
/
TRACE.C
Wrap
Text File
|
1985-02-09
|
3KB
|
149 lines
#define VERSION "trace ver. 1.1"
/*
TRACE for Aztec CII
input: FILE.ASM from CII compiler with -t option
output: FILE.TRA with calls to TRACE1
GAE 09/04/83
*/
#include "libc.h"
#define CPMEOF 0x1a
#define MAX 200 /* maximum line length in files */
char werr[] = "Write error.\n";
main(argc,argv)
int argc;
char ** argv;
{
FILE *fopen(), *newf, *oldf;
char *fgets();
char buffer[MAX], oldn[30], newn[30];
printf(VERSION);
if (argc==1)
{
printf("\nUsage: TRACE FILE\n");
printf(" This will create FILE.TRA by inserting\n");
printf(" trace code in FILE.ASM .\n");
exit(0);
}
strcpy(oldn,argv[1]);
striptype(oldn);
strcpy(newn,oldn);
strcpy(oldn+strlen(oldn),".ASM");
strcpy(newn+strlen(newn),".TRA");
if((oldf = fopen(oldn,"r")) == NULL)
{
printf("\nCan't open %s",oldn);
exit(1);
}
if((newf = fopen(newn,"w")) == NULL)
{
printf("\nCan't open %s",newn);
exit(1);
}
printf(" %s --> %s\n",oldn,newn);
while(fgets(buffer,MAX,oldf) != NULL)
{
if(*buffer == CPMEOF)
break;
/* Aztec CII 1.05g has a bug in agets EOF recognition*/
if(*buffer != ';')
{
if(fputs(buffer,newf) < 0)
{
printf(werr);
exit(1);
}
}
else
{
if(fputs("\tCALL\tTRACE1##\n",newf) < 0)
{
printf(werr);
exit(1);
}
if(fputs("\tDB\t",newf) < 0)
{
printf(werr);
exit(1);
}
fputq(newf);
nonewl(buffer);
fputse(buffer,newf);
fputq(newf);
if(fputs(",0DH,0AH,0\n",newf) < 0)
{
printf(werr);
exit(1);
}
}
}
fclose(newf);
exit(0);
}
nonewl(s) /* strip newline character */
register char *s;
{
while (*s)
{
if (*s == '\n') *s = '\0';
else s++;
}
}
striptype(s) /* remove file type (if any) */
register char *s;
{
while (*s)
{
if (*s == '.') *s = '\0';
else s++;
}
}
fputq(fp)
FILE * fp;
{
if(aputc('\'',fp) < 0)
{
printf(werr);
exit(1);
}
}
fputse(s,p) /* output string, special for quote (') */
register char *s;
FILE *p;
{
while( *s )
{
if(*s == '\'')
{
fputq(p);
if(fputs(",27H,",p) < 0)
{
printf(werr);
exit(1);
}
fputq(p);
s++;
}
else if(aputc(*s++,p) < 0)
{
printf(werr);
exit(1);
}
}
return NULL;
}
utse(buffer,newf);