1
0
mirror of https://github.com/cc65/cc65.git synced 2025-01-25 11:30:06 +00:00

Another try in normalizing C coding style.

git-svn-id: svn://svn.cc65.org/cc65/trunk@5362 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
ol.sc 2012-01-02 11:54:15 +00:00
parent 0cb60439c8
commit 8abedd2bae

View File

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