1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-10 13:29:50 +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)),
const char* Arg attribute ((unused)))
const char* Arg attribute ((unused)))
/* Print usage information and exit */
{
Usage ();
@ -136,7 +136,7 @@ static void OptHelp (const char* Opt attribute ((unused)),
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;
@ -161,7 +161,7 @@ static void OptTarget (const char* Opt attribute ((unused)), const char* Arg)
static void OptVersion (const char* Opt attribute ((unused)),
const char* Arg attribute ((unused)))
const char* Arg attribute ((unused)))
/* Print the assembler version */
{
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"
"//\tThis file was generated by the GEOS Resource Compiler\n"
"//\n"
@ -184,9 +184,9 @@ void printCHeader(void) {
}
void printSHeader(void) {
static void printSHeader (void) {
fprintf(outputSFile,
fprintf (outputSFile,
";\n"
";\tThis file was generated by the GEOS Resource Compiler\n"
";\n"
@ -197,80 +197,80 @@ void printSHeader(void) {
}
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;
@ -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 */
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;
char *token;
@ -306,39 +306,39 @@ void DoMenu(void) {
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);
@ -347,18 +347,18 @@ void DoMenu(void) {
/* 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;
}
@ -368,15 +368,15 @@ void DoMenu(void) {
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"
@ -386,27 +386,27 @@ void DoMenu(void) {
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;
@ -416,9 +416,9 @@ void DoHeader(void) {
char i1[9], i2[9], i3[9];
int a, b;
openSFile();
openSFile ();
token = nextWord();
token = nextWord ();
a = findToken(hdrFTypes, token);
@ -443,11 +443,11 @@ void DoHeader(void) {
}
}
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";
@ -458,41 +458,41 @@ void DoHeader(void) {
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;
@ -502,7 +502,7 @@ void DoHeader(void) {
}
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:
@ -520,7 +520,7 @@ void DoHeader(void) {
}
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:
@ -534,27 +534,27 @@ void DoHeader(void) {
}
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"
@ -572,14 +572,14 @@ void DoHeader(void) {
} 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"
@ -590,47 +590,47 @@ void DoHeader(void) {
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);
@ -640,28 +640,28 @@ void DoHeader(void) {
}
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);
}
@ -671,7 +671,7 @@ void DoVLIR(void) {
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.");
@ -682,7 +682,7 @@ void DoVLIR(void) {
/* 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",
@ -690,46 +690,46 @@ void DoVLIR(void) {
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;
@ -745,10 +745,10 @@ char *filterInput(FILE *F, char *tbl) {
}
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 = ' ';
@ -756,9 +756,9 @@ char *filterInput(FILE *F, char *tbl) {
} 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;
@ -772,7 +772,7 @@ char *filterInput(FILE *F, char *tbl) {
}
void processFile(const char *filename) {
static void processFile (const char *filename) {
FILE *F;
@ -782,25 +782,25 @@ void processFile(const char *filename) {
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 */
@ -809,26 +809,26 @@ void processFile(const char *filename) {
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;
@ -842,16 +842,16 @@ int main(int argc, char *argv[]) {
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);
@ -884,11 +884,11 @@ int main(int argc, char *argv[]) {
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");