static void OptHelp (const char* Opt attribute ((unused)),
- const char* Arg attribute ((unused)))
+ const char* Arg attribute ((unused)))
/* Print usage information and exit */
{
Usage ();
static void OptTarget (const char* Opt attribute ((unused)), const char* Arg)
/* Set the target system */
{
- switch (FindTarget(Arg)) {
+ switch (FindTarget (Arg)) {
case TGT_GEOS_CBM:
apple = 0;
static void OptVersion (const char* Opt attribute ((unused)),
- const char* Arg attribute ((unused)))
+ const char* Arg attribute ((unused)))
/* Print the assembler version */
{
fprintf (stderr,
-void printCHeader(void) {
+static void printCHeader (void) {
- fprintf(outputCFile,
+ fprintf (outputCFile,
"//\n"
"//\tThis file was generated by the GEOS Resource Compiler\n"
"//\n"
}
-void printSHeader(void) {
+static void printSHeader (void) {
- fprintf(outputSFile,
+ fprintf (outputSFile,
";\n"
";\tThis file was generated by the GEOS Resource Compiler\n"
";\n"
}
-void openCFile(void) {
+static void openCFile (void) {
- if ((outputCFile = fopen(outputCName,outputCMode)) == 0) {
- AbEnd ("Can't open file %s for writing: %s", outputCName, strerror(errno));
+ if ((outputCFile = fopen (outputCName,outputCMode)) == 0) {
+ AbEnd ("Can't open file %s for writing: %s", outputCName, strerror (errno));
}
if (CFnum == 0) {
outputCMode[0] = 'a';
- printCHeader();
+ printCHeader ();
CFnum++;
}
}
-void openSFile(void) {
+static void openSFile (void) {
- if ((outputSFile = fopen(outputSName, outputSMode)) == 0) {
- AbEnd ("Can't open file %s for writing: %s", outputSName, strerror(errno));
+ if ((outputSFile = fopen (outputSName, outputSMode)) == 0) {
+ AbEnd ("Can't open file %s for writing: %s", outputSName, strerror (errno));
}
if (SFnum == 0) {
outputSMode[0] = 'a';
- printSHeader();
+ printSHeader ();
SFnum++;
}
}
-int findToken(const char **tokenTbl, const char *token) {
+static int findToken (const char **tokenTbl, const char *token) {
/* takes as input table of tokens and token, returns position in table or -1 if not found */
int a = 0;
- while (strlen(tokenTbl[a]) != 0) {
- if (strcmp(tokenTbl[a], token) == 0) break;
+ while (strlen (tokenTbl[a]) != 0) {
+ if (strcmp (tokenTbl[a], token) == 0) break;
a++;
}
- if (strlen(tokenTbl[a]) == 0) a = -1;
+ if (strlen (tokenTbl[a]) == 0) a = -1;
return a;
}
-char *nextPhrase() {
- return strtok(NULL, "\"");
+static char *nextPhrase (void) {
+ return strtok (NULL, "\"");
}
-char *nextWord() {
- return strtok(NULL, " ");
+static char *nextWord (void) {
+ return strtok (NULL, " ");
}
-void setLen(char *name, unsigned len) {
- if (strlen(name) > len)
+static void setLen (char *name, unsigned len) {
+ if (strlen (name) > len)
name[len] = '\0';
}
-void fillOut(char *name, int len, char *filler) {
+static void fillOut (char *name, int len, char *filler) {
int a;
setLen(name, len);
- fprintf(outputSFile, "\t.byte \"%s\"\n", name);
+ fprintf (outputSFile, "\t.byte \"%s\"\n", name);
- a = strlen(name);
+ a = strlen (name);
if (a < len) {
- fprintf(outputSFile, "\t.res (%i - %i), %s\n", len, a, filler);
+ fprintf (outputSFile, "\t.res (%i - %i), %s\n", len, a, filler);
}
}
-char *bintos(unsigned char a, char out[7]) {
+static char *bintos (unsigned char a, char out[7]) {
int i=0;
}
-int getNameSize(const char *word) {
+static int getNameSize (const char *word) {
/* count length of a word using BSW 9 font table */
int a = 0, i = 0;
}
-void DoMenu(void) {
+static void DoMenu (void) {
int a, size, tmpsize, item = 0;
char *token;
struct menu myMenu;
struct menuitem *curItem, *newItem;
- openCFile();
+ openCFile ();
- myMenu.name = nextWord();
- myMenu.left = atoi(nextWord());
- myMenu.top = atoi(nextWord());
- myMenu.type = nextWord();
+ myMenu.name = nextWord ();
+ myMenu.left = atoi (nextWord ());
+ myMenu.top = atoi (nextWord ());
+ myMenu.type = nextWord ();
- if (strcmp(nextWord(), "{") != 0) {
+ if (strcmp(nextWord (), "{") != 0) {
AbEnd ("Menu '%s' description has no opening bracket!", myMenu.name);
}
- curItem = xmalloc(sizeof(struct menuitem));
+ curItem = xmalloc (sizeof(struct menuitem));
myMenu.item = curItem;
do {
- token = nextWord();
- if (strcmp(token, "}") == 0) break;
+ token = nextWord ();
+ if (strcmp (token, "}") == 0) break;
if (token[strlen(token) - 1] != '"') {
- strcpy(namebuff, token);
+ strcpy (namebuff, token);
do {
- token = nextWord();
- strcat(namebuff, " ");
- strcat(namebuff, token);
+ token = nextWord ();
+ strcat (namebuff, " ");
+ strcat (namebuff, token);
} while (token[strlen(token) - 1] != '"');
- token = xmalloc(strlen(namebuff));
- strcpy(token, namebuff);
+ token = xmalloc (strlen(namebuff));
+ strcpy (token, namebuff);
}
curItem->name = token;
- curItem->type = nextWord();
- curItem->target = nextWord();
- newItem = xmalloc(sizeof(struct menuitem));
+ curItem->type = nextWord ();
+ curItem->target = nextWord ();
+ newItem = xmalloc (sizeof(struct menuitem));
curItem->next = newItem;
curItem = newItem;
item++;
- } while (strcmp(token, "}") != 0);
+ } while (strcmp (token, "}") != 0);
if (item == 0) AbEnd ("Menu '%s' has 0 items!", myMenu.name);
if (item > 31) AbEnd ("Menu '%s' has too many items!", myMenu.name);
/* count menu sizes */
size = 0;
curItem = myMenu.item;
- if (strstr(myMenu.type, "HORIZONTAL") != NULL) {
+ if (strstr (myMenu.type, "HORIZONTAL") != NULL) {
/* menu is HORIZONTAL, ysize=15, sum xsize of all items +~8?*/
myMenu.bot = myMenu.top + 15;
for (a = 0; a != item; a++) {
- size += getNameSize(curItem->name);
+ size += getNameSize (curItem->name);
curItem = curItem->next;
}
} else {
/* menu is VERTICAL, ysize=item*15, count largest xsize of all items +~8? */
myMenu.bot = myMenu.top + (14 * item);
for (a = 0; a != item; a++) {
- tmpsize = getNameSize(curItem->name);
+ tmpsize = getNameSize (curItem->name);
size = (size > tmpsize) ? size : tmpsize;
curItem = curItem->next;
}
curItem = myMenu.item;
for (a = 0; a != item; a++) {
/* print prototype only if MENU_ACTION or DYN_SUB_MENU are present in type */
- if ((strstr(curItem->type, "MENU_ACTION") != NULL) || (strstr(curItem->type, "DYN_SUB_MENU") != NULL)) {
- fprintf(outputCFile,
+ if ((strstr (curItem->type, "MENU_ACTION") != NULL) || (strstr (curItem->type, "DYN_SUB_MENU") != NULL)) {
+ fprintf (outputCFile,
"void %s (void);\n",
curItem->target);
}
curItem=curItem->next;
}
- fprintf(outputCFile,
+ fprintf (outputCFile,
"\n"
"const void %s = {\n"
"\t(char)%i, (char)%i,\n"
curItem = myMenu.item;
for (a = 0; a != item; a++) {
- fprintf(outputCFile,
+ fprintf (outputCFile,
"\t%s, (char)%s, (int)",
curItem->name, curItem->type);
- if ((strstr(curItem->type, "SUB_MENU") != NULL) && (strstr(curItem->type, "DYN_SUB_MENU") == NULL))
- fprintf(outputCFile,
+ if ((strstr (curItem->type, "SUB_MENU") != NULL) && (strstr (curItem->type, "DYN_SUB_MENU") == NULL))
+ fprintf (outputCFile,
"&");
- fprintf(outputCFile,
+ fprintf (outputCFile,
"%s,\n",
curItem->target);
curItem = curItem->next;
}
- fprintf(outputCFile,
+ fprintf (outputCFile,
"};\n\n");
- if (fclose(outputCFile) != 0)
+ if (fclose (outputCFile) != 0)
AbEnd ("Error closing %s: %s", outputCName, strerror(errno));
}
-void DoHeader(void) {
+static void DoHeader (void) {
time_t t;
struct tm *my_tm;
char i1[9], i2[9], i3[9];
int a, b;
- openSFile();
+ openSFile ();
- token = nextWord();
+ token = nextWord ();
a = findToken(hdrFTypes, token);
}
}
- myHead.dosname = nextPhrase();
- nextPhrase();
- myHead.classname = nextPhrase();
- nextPhrase();
- myHead.version = nextPhrase();
+ myHead.dosname = nextPhrase ();
+ nextPhrase ();
+ myHead.classname = nextPhrase ();
+ nextPhrase ();
+ myHead.version = nextPhrase ();
/* put default values into myHead here */
myHead.author = "cc65";
myHead.mode = 0;
myHead.icon = NULL;
- t = time(NULL);
- my_tm = localtime(&t);
+ t = time (NULL);
+ my_tm = localtime (&t);
myHead.year = my_tm->tm_year;
- myHead.month = my_tm->tm_mon+1;
+ myHead.month = my_tm->tm_mon + 1;
myHead.day = my_tm->tm_mday;
myHead.hour = my_tm->tm_hour;
myHead.min = my_tm->tm_min;
- if (strcmp(nextWord(), "{") != 0) {
+ if (strcmp (nextWord (), "{") != 0) {
AbEnd ("Header '%s' has no opening bracket!", myHead.dosname);
}
do {
- token = nextWord();
- if (strcmp(token, "}") == 0) break;
- switch (a = findToken(hdrFields, token)) {
+ token = nextWord ();
+ if (strcmp (token, "}") == 0) break;
+ switch (a = findToken (hdrFields, token)) {
case -1:
AbEnd ("Unknown field '%s' in header '%s'", token, myHead.dosname);
break;
case 0: /* author */
- myHead.author = nextPhrase();
+ myHead.author = nextPhrase ();
break;
case 1: /* info */
- myHead.info = nextPhrase();
+ myHead.info = nextPhrase ();
break;
case 2: /* date */
- myHead.year = atoi(nextWord());
- myHead.month = atoi(nextWord());
- myHead.day = atoi(nextWord());
- myHead.hour = atoi(nextWord());
- myHead.min = atoi(nextWord());
+ myHead.year = atoi (nextWord ());
+ myHead.month = atoi (nextWord ());
+ myHead.day = atoi (nextWord ());
+ myHead.hour = atoi (nextWord ());
+ myHead.min = atoi (nextWord ());
break;
case 3: /* dostype */
- switch (b = findToken(hdrDOSTp, nextWord())) {
+ switch (b = findToken (hdrDOSTp, nextWord ())) {
case -1:
AbEnd ("Unknown dostype in header '%s'", myHead.dosname);
break;
}
break;
case 4: /* mode */
- switch (b = findToken(hdrModes, nextWord())) {
+ switch (b = findToken (hdrModes, nextWord ())) {
case -1:
AbEnd ("Unknown mode in header '%s'", myHead.dosname);
case 0:
}
break;
case 5: /* structure */
- switch (b = findToken(hdrStructTp, nextWord())) {
+ switch (b = findToken (hdrStructTp, nextWord ())) {
case -1:
AbEnd ("unknown structure type in header '%s'", myHead.dosname);
case 0:
}
break;
case 6: /* icon */
- myHead.icon = nextPhrase();
+ myHead.icon = nextPhrase ();
break;
}
- } while (strcmp(token, "}") != 0);
+ } while (strcmp (token, "}") != 0);
/* OK, all information is gathered, do flushout */
- fprintf(outputSFile,
+ fprintf (outputSFile,
"\n"
"\t\t.segment \"DIRENTRY\"\n\n");
if (apple == 1) {
- fprintf(outputSFile,
+ fprintf (outputSFile,
"\t.byte %i << 4 | %u\n",
- myHead.structure + 2, (unsigned) strlen(myHead.dosname));
+ myHead.structure + 2, (unsigned)strlen (myHead.dosname));
- fillOut(myHead.dosname, 15, "0");
+ fillOut (myHead.dosname, 15, "0");
- fprintf(outputSFile,
+ fprintf (outputSFile,
"\t.byte $%02x\n"
"\t.word 0\n"
"\t.word 0\n"
} else {
- fprintf(outputSFile,
+ fprintf (outputSFile,
"\t.byte %i\n"
"\t.word 0\n",
myHead.dostype);
- fillOut(myHead.dosname, 16, "$a0");
+ fillOut (myHead.dosname, 16, "$a0");
- fprintf(outputSFile,
+ fprintf (outputSFile,
"\t.word 0\n"
"\t.byte %i\n"
"\t.byte %i\n"
myHead.year, myHead.month, myHead.day, myHead.hour, myHead.min);
}
- fprintf(outputSFile,
+ fprintf (outputSFile,
"\n"
"\t\t.segment \"FILEINFO\"\n\n"
"\t.import __VLIR0_START__, __STARTUP_RUN__\n\n"
"\t.byte 3, 21, 63 | $80\n");
if (myHead.icon != NULL) {
- fprintf(outputSFile,
+ fprintf (outputSFile,
"\t.incbin \"%s\", 0, 63\n",
myHead.icon);
} else {
for (a = 0; a != 63; a = a + 3) {
- fprintf(outputSFile,
+ fprintf (outputSFile,
"\t.byte %%%s, %%%s, %%%s\n",
- bintos(icon1[a], i1), bintos(icon1[a+1], i2), bintos(icon1[a+2], i3));
+ bintos (icon1[a], i1), bintos (icon1[a+1], i2), bintos (icon1[a+2], i3));
}
}
- fprintf(outputSFile,
+ fprintf (outputSFile,
"\t.byte %i, %i, %i\n"
"\t.word __VLIR0_START__, __VLIR0_START__ - 1, __STARTUP_RUN__\n\n",
myHead.dostype, myHead.geostype, myHead.structure);
- fillOut(myHead.classname, 12, "$20");
+ fillOut (myHead.classname, 12, "$20");
- fillOut(myHead.version, 4, "0");
+ fillOut (myHead.version, 4, "0");
- fprintf(outputSFile,
+ fprintf (outputSFile,
"\t.byte 0, 0, 0\n"
"\t.byte %i\n\n",
myHead.mode);
- setLen(myHead.author, 62);
- fprintf(outputSFile,
+ setLen (myHead.author, 62);
+ fprintf (outputSFile,
"\t.byte \"%s\"\n"
"\t.byte 0\n"
"\t.res (63 - %i)\n\n",
- myHead.author, (int)(strlen(myHead.author) + 1));
+ myHead.author, (int)(strlen (myHead.author) + 1));
- setLen(myHead.info, 95);
- fprintf(outputSFile,
+ setLen (myHead.info, 95);
+ fprintf (outputSFile,
"\t.byte \"%s\"\n"
"\t.byte 0\n\n",
myHead.info);
}
-void DoVLIR(void) {
+static void DoVLIR (void) {
char *token;
int record, lastrecord;
int vlirsize, vlirtable[127];
- openSFile();
+ openSFile ();
- vlirsize = strtol(nextWord(), NULL, 0);
+ vlirsize = strtol (nextWord (), NULL, 0);
- if (strcmp(nextWord(), "{") != 0) {
+ if (strcmp(nextWord (), "{") != 0) {
AbEnd ("VLIR description has no opening bracket!");
}
lastrecord = -1;
- memset(vlirtable, 0, sizeof(vlirtable));
+ memset (vlirtable, 0, sizeof(vlirtable));
do {
- token = nextWord();
- if (strcmp(token, "}") == 0) break;
+ token = nextWord ();
+ if (strcmp (token, "}") == 0) break;
- record = atoi(token);
+ record = atoi (token);
if (record < 0 || record > 126) {
AbEnd ("VLIR record %i is out of range 0-126.", record);
}
vlirtable[record] = 1;
if (record > lastrecord) lastrecord = record;
- } while (strcmp(token, "}") != 0);
+ } while (strcmp (token, "}") != 0);
if (lastrecord == -1) {
AbEnd ("There must be at least one VLIR record.");
/* OK, all information is gathered, do flushout */
- fprintf(outputSFile,
+ fprintf (outputSFile,
"\n"
"\t\t.segment \"RECORDS\"\n\n"
"\t.export __OVERLAYSIZE__ : absolute = $%04x\n\n",
for (record = 0; record <= lastrecord; record++) {
if (vlirtable[record] == 1) {
- fprintf(outputSFile,
+ fprintf (outputSFile,
"\t.import __VLIR%i_START__, __VLIR%i_LAST__\n",
record, record);
}
}
- fprintf(outputSFile,
+ fprintf (outputSFile,
"\n");
for (record = 0; record <= lastrecord; record++) {
if (vlirtable[record] == 1) {
- fprintf(outputSFile,
+ fprintf (outputSFile,
"\t.byte .lobyte ((__VLIR%i_LAST__ - __VLIR%i_START__ - 1) / 254) + 1\n"
"\t.byte .lobyte ((__VLIR%i_LAST__ - __VLIR%i_START__ - 1) .MOD 254) + 2\n",
record, record, record, record);
} else {
- fprintf(outputSFile,
+ fprintf (outputSFile,
"\t.byte $00\n"
"\t.byte $FF\n");
}
}
- fprintf(outputSFile,
+ fprintf (outputSFile,
"\n");
- if (fclose(outputSFile) != 0)
+ if (fclose (outputSFile) != 0)
AbEnd ("Error closing %s: %s", outputSName, strerror(errno));
- openCFile();
+ openCFile ();
- fprintf(outputCFile,
+ fprintf (outputCFile,
"extern void _OVERLAYADDR__;\n"
"extern void _OVERLAYSIZE__;\n\n"
"#define OVERLAY_ADDR (char*) &_OVERLAYADDR__\n"
"#define OVERLAY_SIZE (unsigned)&_OVERLAYSIZE__\n\n");
- if (fclose(outputCFile) != 0)
+ if (fclose (outputCFile) != 0)
AbEnd ("Error closing %s: %s", outputCName, strerror(errno));
}
-char *filterInput(FILE *F, char *tbl) {
+static char *filterInput (FILE *F, char *tbl) {
/* loads file into buffer filtering it out */
int a, prevchar = -1, i = 0, bracket = 0, quote = 1;
}
if (a == EOF) {
tbl[i] = '\0';
- xrealloc(tbl, i + 1);
+ xrealloc (tbl, i + 1);
break;
}
- if (IsSpace(a)) {
+ if (IsSpace (a)) {
if ((prevchar != ' ') && (prevchar != -1)) {
tbl[i++] = ' ';
prevchar = ' ';
} else {
if (a == ';' && quote) {
do {
- a = getc(F);
+ a = getc (F);
} while (a != '\n');
- fseek(F, -1, SEEK_CUR);
+ fseek (F, -1, SEEK_CUR);
} else {
tbl[i++] = a;
prevchar = a;
}
-void processFile(const char *filename) {
+static void processFile (const char *filename) {
FILE *F;
int head = 0; /* number of processed HEADER sections */
int vlir = 0; /* number of processed VLIR sections */
- if ((F = fopen(filename, "r")) == 0) {
- AbEnd ("Can't open file %s for reading: %s", filename, strerror(errno));
+ if ((F = fopen (filename, "r")) == 0) {
+ AbEnd ("Can't open file %s for reading: %s", filename, strerror (errno));
}
- str = filterInput(F, xmalloc(BLOODY_BIG_BUFFER));
+ str = filterInput (F, xmalloc (BLOODY_BIG_BUFFER));
- token = strtok(str, " ");
+ token = strtok (str, " ");
do {
if (str != NULL) {
- switch (findToken(mainToken, token)) {
+ switch (findToken (mainToken, token)) {
case 0:
- DoMenu();
+ DoMenu ();
break;
case 1:
if (++head != 1) {
AbEnd ("More than one HEADER section, aborting.");
} else {
- DoHeader();
+ DoHeader ();
}
break;
case 2: break; /* icon not implemented yet */
if (++vlir != 1) {
AbEnd ("More than one VLIR section, aborting.");
} else {
- DoVLIR();
+ DoVLIR ();
}
break;
default:
- AbEnd ("Unknown section %s.",token);
+ AbEnd ("Unknown section %s.", token);
break;
}
}
- token = nextWord();
+ token = nextWord ();
} while (token != NULL);
}
-int main(int argc, char *argv[]) {
+int main (int argc, char *argv[]) {
/* Program long options */
static const LongOpt OptTab[] = {
- { "--help", 0, OptHelp },
- { "--target", 1, OptTarget },
- { "--version", 0, OptVersion },
+ { "--help", 0, OptHelp},
+ { "--target", 1, OptTarget},
+ { "--version", 0, OptVersion},
};
unsigned ffile = 0;
I = 1;
while (I < ArgCount) {
- /* Get the argument */
- const char* Arg = ArgVec [I];
+ /* Get the argument */
+ const char* Arg = ArgVec [I];
- /* Check for an option */
- if (Arg[0] == '-') {
+ /* Check for an option */
+ if (Arg[0] == '-') {
switch (Arg[1]) {
- case '-':
- LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
- break;
+ case '-':
+ LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
+ break;
case 'o':
outputCName = GetArg (&I, 2);
if (outputCName == NULL) outputCName = MakeFilename (Arg, ".h");
if (outputSName == NULL) outputSName = MakeFilename (Arg, ".s");
- processFile(Arg);
+ processFile (Arg);
}
- /* Next argument */
- ++I;
+ /* Next argument */
+ ++I;
}
if (ffile == 0) AbEnd ("No input file");