2017-04-22 18:39:52 +00:00
|
|
|
/*************************************
|
|
|
|
* C02 Common Definitions & Routines *
|
|
|
|
*************************************/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
|
|
|
|
/* Error - Print Input File name & position and exit */
|
|
|
|
void exterr(int errnum)
|
|
|
|
{
|
2018-02-09 03:39:20 +00:00
|
|
|
fprintf(stderr, "Line %d Column %d of File %s\n", curlin, curcol, inpnam);
|
2017-04-22 18:39:52 +00:00
|
|
|
exit(errnum);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Error - print "Expected" error message *
|
|
|
|
and exit with general failure code *
|
|
|
|
Args: expected - Description of what was expected */
|
|
|
|
void expctd(char *expstr)
|
|
|
|
{
|
2018-02-09 04:21:46 +00:00
|
|
|
fprintf(stderr, "Expected %s, but found '%c'\n", expstr, nxtchr);
|
2017-04-22 18:39:52 +00:00
|
|
|
exterr(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Print current position in file */
|
|
|
|
void prtpos()
|
|
|
|
{
|
|
|
|
printf("(%s: %d,%d) ", inpnam, curlin, curcol);
|
|
|
|
}
|
|
|
|
|
2018-02-13 22:25:57 +00:00
|
|
|
/* Set comment to string */
|
|
|
|
void setcmt(char *s)
|
|
|
|
{
|
|
|
|
strcpy(cmtasm, s);
|
|
|
|
}
|
2017-04-22 18:39:52 +00:00
|
|
|
|
2018-02-13 22:25:57 +00:00
|
|
|
/* Append string to comment */
|
|
|
|
void addcmt(char *s)
|
|
|
|
{
|
|
|
|
strcat(cmtasm, s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Append character to comment */
|
|
|
|
void chrcmt(char c)
|
|
|
|
{
|
|
|
|
if (cmtasm[0] == 0 && c == ' ') return;
|
|
|
|
int i = strlen(cmtasm);
|
|
|
|
cmtasm[i++] = c;
|
|
|
|
cmtasm[i] = 0;
|
|
|
|
}
|