1
0
mirror of https://github.com/cc65/cc65.git synced 2025-08-08 06:25:17 +00:00

using functions from common/ in grc, correct order of menus in test.grc

git-svn-id: svn://svn.cc65.org/cc65/trunk@1779 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
izydorst
2002-12-17 09:10:57 +00:00
parent 36084183f2
commit 803c1c0184
5 changed files with 91 additions and 110 deletions

View File

@@ -97,7 +97,8 @@ is present in source that includes generated header. It can point to a function
or to another menu definition. or to another menu definition.
If you are doing sub(sub)menus definitions remember to place the lowest level If you are doing sub(sub)menus definitions remember to place the lowest level
definition first. This way C compiler won't complain about unknown names. definition first and top lever menu as the last one. This way C compiler won't
complain about unknown names.
b) header definition b) header definition

View File

@@ -4,8 +4,6 @@
by Maciej 'YTM/Elysium' Witkowiak by Maciej 'YTM/Elysium' Witkowiak
Error function by Uz
see GEOSLib documentation for license info see GEOSLib documentation for license info
*/ */
@@ -24,25 +22,16 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#include <ctype.h>
#include <errno.h> #include <errno.h>
#include <time.h> #include <time.h>
#include "grc.h" #include "grc.h"
/* common stuff */
void Error (const char* Format, ...) //#include "cmdline.h"
/* borrowed from cl65/error.c */ #include "fname.h"
/* Print an error message and die */ #include "abend.h"
{ #include "chartype.h"
va_list ap;
va_start (ap, Format);
fprintf (stderr, "%s: ", progName);
vfprintf (stderr, Format, ap);
va_end (ap);
exit (EXIT_FAILURE);
}
void VLIRLinker(int argc, char *argv[]) { void VLIRLinker(int argc, char *argv[]) {
FILE *outCVT, *input; FILE *outCVT, *input;
@@ -58,23 +47,23 @@ int blocks,rest;
/* check if we know enough */ /* check if we know enough */
if (argc<4) if (argc<4)
Error("too less arguments, required [out] [cvthead] [vlir0] ...\n"); AbEnd("too few arguments, required [out] [cvthead] [vlir0] ...\n");
/* first open and copy CVT header */ /* first open and copy CVT header */
outCVT = fopen(argv[i],"wb+"); outCVT = fopen(argv[i],"wb+");
if (outCVT==NULL) if (outCVT==NULL)
Error("can't open output\n"); AbEnd("can't open output:%s\n",strerror(errno));
++i; ++i;
input = fopen(argv[i],"rb"); input = fopen(argv[i],"rb");
if (input==NULL) if (input==NULL)
Error("can't open input:%s\n",strerror(errno)); AbEnd("can't open input:%s\n",strerror(errno));
bytes = fread(buffer,1,BLOODY_BIG_BUFFER,input); bytes = fread(buffer,1,BLOODY_BIG_BUFFER,input);
fclose(input); fclose(input);
if (bytes!=508) if (bytes!=508)
Error("%s is not a cvt header\n",argv[i]); AbEnd("%s is not a cvt header\n",argv[i]);
fwrite(buffer,1,bytes,outCVT); fwrite(buffer,1,bytes,outCVT);
@@ -88,7 +77,7 @@ int blocks,rest;
vlirtabs[j]=0; vlirtabs[j]=0;
} }
/* now read all VLIR chains, aligned to 254 bytes */ /* now read all VLIR chains, align to 254 bytes */
++i; ++i;
j=0; j=0;
@@ -101,11 +90,11 @@ int blocks,rest;
memset(buffer,0,BLOODY_BIG_BUFFER); memset(buffer,0,BLOODY_BIG_BUFFER);
input = fopen(argv[i],"rb"); input = fopen(argv[i],"rb");
if (input==NULL) if (input==NULL)
Error("couldn't open %s:%s\n",argv[i],strerror(errno)); AbEnd("couldn't open %s:%s\n",argv[i],strerror(errno));
bytes = fread(buffer,1,BLOODY_BIG_BUFFER,input); bytes = fread(buffer,1,BLOODY_BIG_BUFFER,input);
fclose(input); fclose(input);
if (bytes==0) if (bytes==0)
Error("couldn't read %s:%s\n",argv[i],strerror(errno)); AbEnd("couldn't read %s:%s\n",argv[i],strerror(errno));
blocks = bytes / 254; blocks = bytes / 254;
rest = bytes % 254 + 2; rest = bytes % 254 + 2;
if (rest>255) rest=255; if (rest>255) rest=255;
@@ -156,34 +145,46 @@ void printVHeader (void) {
void openCFile (void) { void openCFile (void) {
if ((CFnum==0) && (forceFlag==0)) { if ((CFnum==0) && (forceFlag==0)) {
/* test if file exists already and no forcing*/ /* test if file exists already and no forcing*/
if ((outputCFile = fopen (outputCName,"r"))!=0) if ((outputCFile = fopen (outputCName,"r"))!=0)
Error("file %s already exists, no forcing, aborting\n", outputCName); AbEnd("file %s already exists, aborting\n", outputCName);
} }
if ((outputCFile = fopen (outputCName,outputCMode))==0) if ((outputCFile = fopen (outputCName,outputCMode))==0)
Error("can't open file %s for writting: %s\n",outputCName,strerror (errno)); AbEnd("can't open file %s for writing: %s\n",outputCName,strerror (errno));
if (CFnum==0) { outputCMode[0]='a'; printCHeader(); CFnum++; } if (CFnum==0) {
outputCMode[0]='a';
printCHeader();
CFnum++;
}
} }
void openSFile (void) { void openSFile (void) {
if ((SFnum==0) && (forceFlag==0)) { if ((SFnum==0) && (forceFlag==0)) {
/* test if file exists already and no forcing*/ /* test if file exists already and no forcing*/
if ((outputSFile = fopen (outputSName,"r"))!=0) if ((outputSFile = fopen (outputSName,"r"))!=0)
Error("file %s already exists, no forcing, aborting\n", outputSName); AbEnd("file %s already exists, aborting\n", outputSName);
} }
if ((outputSFile = fopen (outputSName,outputSMode))==0) if ((outputSFile = fopen (outputSName,outputSMode))==0)
Error("can't open file %s for writting: %s\n",outputSName,strerror (errno)); AbEnd("can't open file %s for writing: %s\n",outputSName,strerror (errno));
if (SFnum==0) { outputSMode[0]='a'; printSHeader(); SFnum++; } if (SFnum==0) {
outputSMode[0]='a';
printSHeader();
SFnum++;
}
} }
void openVFile (void) { void openVFile (void) {
if ((VFnum==0) && (forceFlag==0)) { if ((VFnum==0) && (forceFlag==0)) {
/* test if file exists already and no forcing*/ /* test if file exists already and no forcing*/
if ((outputVFile = fopen (outputVName,"r"))!=0) if ((outputVFile = fopen (outputVName,"r"))!=0)
Error("file %s already exists, no forcing, aborting\n", outputVName); AbEnd("file %s already exists, aborting\n", outputVName);
} }
if ((outputVFile = fopen (outputVName,outputVMode))==0) if ((outputVFile = fopen (outputVName,outputVMode))==0)
Error("can't open file %s for writting: %s\n",outputVName,strerror (errno)); AbEnd("can't open file %s for writting: %s\n",outputVName,strerror (errno));
if (VFnum==0) { outputVMode[0]='a'; printVHeader(); VFnum++; } if (VFnum==0) {
outputVMode[0]='a';
printVHeader();
VFnum++;
}
} }
void printUsage (void) { void printUsage (void) {
@@ -195,8 +196,7 @@ void printUsage (void) {
"\t-s name\t\tname asm output file\n" "\t-s name\t\tname asm output file\n"
"\t-l name\t\tname ld65 config output file (for vlir)\n" "\t-l name\t\tname ld65 config output file (for vlir)\n"
"Or as VLIR linker: %s -vlir output.cvt header [vlir0] ... [blank] ... [vlir_n]\n", "Or as VLIR linker: %s -vlir output.cvt header [vlir0] ... [blank] ... [vlir_n]\n",
progName,progName); ProgName,ProgName);
} }
int findToken (const char **tokenTbl, const char *token) { int findToken (const char **tokenTbl, const char *token) {
@@ -204,8 +204,8 @@ int findToken (const char **tokenTbl, const char *token) {
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;
@@ -236,7 +236,8 @@ int a;
} }
} }
char *bintos(unsigned char a, char *out) { //char *bintos(unsigned char a, char *out) {
char *bintos(unsigned char a, char out[7]) {
int i=0; int i=0;
for (;i<8;i++) { for (;i<8;i++) {
out[7-i] = ((a & 1)==0) ? '0' : '1'; out[7-i] = ((a & 1)==0) ? '0' : '1';
@@ -271,7 +272,7 @@ struct menuitem *curItem, *newItem;
myMenu.type=nextWord(); myMenu.type=nextWord();
if (strcmp(nextWord(),"{")!=0) { if (strcmp(nextWord(),"{")!=0) {
Error ("menu %s description has no opening bracket!\n", myMenu.name); AbEnd ("menu '%s' description has no opening bracket!\n", myMenu.name);
}; };
curItem=malloc(sizeof(struct menuitem)); curItem=malloc(sizeof(struct menuitem));
myMenu.item=curItem; myMenu.item=curItem;
@@ -296,8 +297,8 @@ struct menuitem *curItem, *newItem;
curItem=newItem; curItem=newItem;
item++; item++;
} while (strcmp(token,"}")!=0); } while (strcmp(token,"}")!=0);
if (item==0) Error ("menu %s has 0 items!\n", myMenu.name); if (item==0) AbEnd ("menu '%s' has 0 items!\n", myMenu.name);
if (item>31) Error ("menu %s has too many items!\n", myMenu.name); if (item>31) AbEnd ("menu '%s' has too many items!\n", myMenu.name);
curItem->next=NULL; curItem->next=NULL;
@@ -347,7 +348,7 @@ struct menuitem *curItem, *newItem;
fprintf(outputCFile, "\t};\n\n"); fprintf(outputCFile, "\t};\n\n");
if (fclose (outputCFile)!=0) if (fclose (outputCFile)!=0)
Error("error closing %s: %s\n",outputCName,strerror (errno)); AbEnd("error closing %s: %s\n",outputCName,strerror (errno));
} }
void DoHeader (void) { void DoHeader (void) {
@@ -367,7 +368,7 @@ int a, b;
a = findToken (hdrFTypes, token); a = findToken (hdrFTypes, token);
if (a>1) if (a>1)
Error("filetype %s isn't supported yet\n", token); AbEnd("filetype '%s' is not supported yet\n", token);
switch (a) { switch (a) {
case 0: myHead.geostype = 6; break; case 0: myHead.geostype = 6; break;
@@ -396,16 +397,15 @@ int a, b;
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)
Error ("header %s has no opening bracket!\n", myHead.dosname); AbEnd ("header '%s' has no opening bracket!\n", 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:
Error ("unknown field %s in header %s\n", token, myHead.dosname); AbEnd ("unknown field '%s' in header '%s'\n", token, myHead.dosname);
break; break;
case 0: /* author */ case 0: /* author */
myHead.author = nextPhrase(); break; myHead.author = nextPhrase(); break;
@@ -421,7 +421,7 @@ int a, b;
case 3: /* dostype */ case 3: /* dostype */
switch (b = findToken (hdrDOSTp, nextWord())) { switch (b = findToken (hdrDOSTp, nextWord())) {
case -1: case -1:
Error ("unknown dostype in header %s\n", myHead.dosname); AbEnd ("unknown dostype in header '%s'\n", myHead.dosname);
break; break;
default: default:
myHead.dostype = b/2 + 128 + 1; myHead.dostype = b/2 + 128 + 1;
@@ -431,7 +431,7 @@ int a, b;
case 4: /* mode */ case 4: /* mode */
switch (b = findToken (hdrModes, nextWord())) { switch (b = findToken (hdrModes, nextWord())) {
case -1: case -1:
Error ("unknown mode in header %s\n", myHead.dosname); AbEnd ("unknown mode in header '%s'\n", myHead.dosname);
case 0: case 0:
myHead.mode = 0x40; break; myHead.mode = 0x40; break;
case 1: case 1:
@@ -445,7 +445,7 @@ int a, b;
case 5: /* structure */ case 5: /* structure */
switch (b = findToken(hdrStructTp, nextWord())) { switch (b = findToken(hdrStructTp, nextWord())) {
case -1: case -1:
Error ("unknown structure type in header %s\n", myHead.dosname); AbEnd ("unknown structure type in header '%s'\n", myHead.dosname);
case 0: case 0:
case 1: case 1:
myHead.structure = 0; break; myHead.structure = 0; break;
@@ -499,8 +499,7 @@ int a, b;
myHead.info, (int) (strlen(myHead.info)+1)); myHead.info, (int) (strlen(myHead.info)+1));
if (fclose (outputSFile)!=0) if (fclose (outputSFile)!=0)
Error("error closing %s: %s\n",outputSName,strerror (errno)); AbEnd("error closing %s: %s\n",outputSName,strerror (errno));
} }
@@ -522,9 +521,8 @@ struct vlirentry vlirtable[127];
vlirbase = strtol(nextWord(),NULL,0); vlirbase = strtol(nextWord(),NULL,0);
if (strcmp(nextWord(),"{")!=0) { if (strcmp(nextWord(),"{")!=0)
Error ("VLIR description has no opening bracket!\n"); AbEnd ("VLIR description has no opening bracket!\n");
};
numchains=0; numchains=0;
@@ -533,7 +531,7 @@ struct vlirentry vlirtable[127];
if (strcmp(token, "}")==0) break; if (strcmp(token, "}")==0) break;
numchains++; numchains++;
if (numchains>127) { if (numchains>127) {
Error("Too many VLIR chains!\n"); AbEnd("Too many VLIR chains!\n");
} }
vlirtable[numchains].chainname=token; vlirtable[numchains].chainname=token;
@@ -557,7 +555,7 @@ struct vlirentry vlirtable[127];
fprintf(outputVFile,"}\n\n"); fprintf(outputVFile,"}\n\n");
if (numchains==0) { if (numchains==0) {
Error("There must be at least one VLIR chain.\n"); AbEnd("There must be at least one VLIR chain.\n");
}; };
/* now put segments info */ /* now put segments info */
@@ -584,7 +582,7 @@ struct vlirentry vlirtable[127];
fprintf(outputVFile,"\n"); fprintf(outputVFile,"\n");
if (fclose (outputVFile)!=0) if (fclose (outputVFile)!=0)
Error("error closing %s: %s\n",outputVName,strerror (errno)); AbEnd("error closing %s: %s\n",outputVName,strerror (errno));
} }
char *filterInput (FILE *F, char *tbl) { char *filterInput (FILE *F, char *tbl) {
@@ -601,7 +599,7 @@ int a, prevchar=-1, i=0, bracket=0, quote=1;
if ((a=='}')||(a==')')) bracket--; if ((a=='}')||(a==')')) bracket--;
} }
if (a==EOF) { tbl[i]='\0'; realloc(tbl, i+1); break; }; if (a==EOF) { tbl[i]='\0'; realloc(tbl, i+1); break; };
if (isspace(a)) { if (IsSpace(a)) {
if ((prevchar!=' ') && (prevchar!=-1)) { tbl[i++]=' '; prevchar=' '; } if ((prevchar!=' ') && (prevchar!=-1)) { tbl[i++]=' '; prevchar=' '; }
} else { } else {
if (a==';' && quote) { do { a = getc (F); } while (a!='\n'); fseek(F,-1,SEEK_CUR); } if (a==';' && quote) { do { a = getc (F); } while (a!='\n'); fseek(F,-1,SEEK_CUR); }
@@ -610,7 +608,7 @@ int a, prevchar=-1, i=0, bracket=0, quote=1;
} }
} }
if (bracket!=0) Error("there are unclosed brackets!\n"); if (bracket!=0) AbEnd("there are unclosed brackets!\n");
return tbl; return tbl;
} }
@@ -626,7 +624,7 @@ 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)
Error("can't open file %s for reading: %s\n",filename,strerror (errno)); AbEnd("can't open file %s for reading: %s\n",filename,strerror (errno));
str=filterInput(F, malloc(BLOODY_BIG_BUFFER)); str=filterInput(F, malloc(BLOODY_BIG_BUFFER));
@@ -639,7 +637,7 @@ int vlir=0; /* number of processed VLIR sections */
case 0: DoMenu(); break; case 0: DoMenu(); break;
case 1: case 1:
if (++head!=1) { if (++head!=1) {
Error ("more than one HEADER section, aborting.\n"); AbEnd ("more than one HEADER section, aborting.\n");
} else { } else {
DoHeader(); DoHeader();
} }
@@ -648,12 +646,12 @@ int vlir=0; /* number of processed VLIR sections */
case 3: break; /* dialog not implemented yet */ case 3: break; /* dialog not implemented yet */
case 4: case 4:
if (++vlir!=1) { if (++vlir!=1) {
Error ("more than one VLIR section, aborting.\n"); AbEnd ("more than one VLIR section, aborting.\n");
} else { } else {
DoVLIR(); DoVLIR();
} }
break; break;
default: Error ("unknown section %s.\n",token); break; default: AbEnd ("unknown section %s.\n",token); break;
} }
} }
token = nextWord(); token = nextWord();
@@ -663,9 +661,8 @@ int vlir=0; /* number of processed VLIR sections */
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
int ffile=0, i=1; int ffile=0, i=1;
char *p, *tmp;
progName = argv[0]; ProgName = argv[0];
while (i < argc) { while (i < argc) {
const char *arg = argv[i]; const char *arg = argv[i];
if (arg[0] == '-') { if (arg[0] == '-') {
@@ -693,47 +690,27 @@ char *p, *tmp;
exit (EXIT_SUCCESS); exit (EXIT_SUCCESS);
break; break;
} else { } else {
Error("unknown option %s\n",arg); AbEnd("unknown option %s\n",arg);
break; break;
} }
default: Error("unknown option %s\n",arg); default: AbEnd("unknown option %s\n",arg);
} }
} else { } else {
ffile++; ffile++;
tmp = malloc(strlen(arg)+4); if (outputCName==NULL)
strcpy (tmp, arg); outputCName = MakeFilename(arg,".h");
if ((p = strrchr (tmp, '.'))) if (outputSName==NULL)
*p = '\0'; outputSName = MakeFilename(arg,".s");
if (outputVName==NULL)
outputVName = MakeFilename(arg,".cfg");
if (outputCName==NULL) {
outputCName = malloc(strlen(arg));
strcpy (outputCName, tmp);
strcat (outputCName, ".h");
}
if (outputSName==NULL) {
outputSName = malloc(strlen(arg));
strcpy (outputSName, tmp);
strcat (outputSName, ".s");
}
if (outputVName==NULL) {
outputVName = malloc(strlen(arg));
strcpy (outputVName, tmp);
strcat (outputVName, ".cfg");
}
processFile(arg); processFile(arg);
} }
i++; i++;
} }
if (ffile==0) Error("no input file\n"); if (ffile==0) AbEnd("no input file\n");
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@@ -64,7 +64,7 @@ const unsigned char icon1[] = {
128, 0, 1, 128, 0, 1, 128, 0, 1, 128, 0, 1, 128, 0, 1, 128, 0, 1, 128, 0, 1, 128, 0, 1, 128, 0, 1, 128, 0, 1,
128, 0, 1, 128, 0, 1, 128, 0, 1, 128, 0, 1, 255, 255, 255 }; 128, 0, 1, 128, 0, 1, 128, 0, 1, 128, 0, 1, 255, 255, 255 };
char *progName; char *ProgName; // for AbEnd, later remove and use common/cmdline.h
char *outputCName=NULL, *outputSName=NULL, *outputVName=NULL; char *outputCName=NULL, *outputSName=NULL, *outputVName=NULL;
FILE *outputCFile, *outputSFile, *outputVFile; FILE *outputCFile, *outputSFile, *outputVFile;

View File

@@ -2,7 +2,9 @@
# gcc Makefile for grc # gcc Makefile for grc
# #
CFLAGS = -g -O2 -Wall -W COMMON = ../common
CFLAGS = -g -O2 -Wall -W -I$(COMMON)
CC = gcc CC = gcc
LDFLAGS = LDFLAGS =
EBIND = emxbind EBIND = emxbind
@@ -11,6 +13,8 @@ OBJS = grc.o
EXECS = grc EXECS = grc
LIBS = $(COMMON)/common.a
.PHONY: all .PHONY: all
ifeq (.depend,$(wildcard .depend)) ifeq (.depend,$(wildcard .depend))
all : $(EXECS) all : $(EXECS)
@@ -38,6 +42,6 @@ zap: clean
.PHONY: depend dep .PHONY: depend dep
depend dep: $(OBJS:.o=.c) depend dep: $(OBJS:.o=.c)
@echo "Creating dependency information" @echo "Creating dependency information"
$(CC) -MM $^ > .depend $(CC) -I$(COMMON) -MM $^ > .depend

View File

@@ -7,15 +7,8 @@
;Note that if you want to use any C operators (like '|', '&' etc.) do it WITHOUT spaces ;Note that if you want to use any C operators (like '|', '&' etc.) do it WITHOUT spaces
;between arguments (parser is simple and weak) ;between arguments (parser is simple and weak)
; format: MENU "name" left,top ALIGN { "itemname" TYPE pointer ... } ; format: MENU "name" left,top ALIGN { "itemname" TYPE pointer ... }
MENU mainMenu 0,0 HORIZONTAL
{
"sub menu1" SUB_MENU subMenu1 ; goes for _subMenu1
"quit" MENU_ACTION EnterDeskTop ; goes for _EnterDeskTop
}
MENU subMenu1 15,0 VERTICAL MENU subMenu1 15,0 VERTICAL
{ {
"subitem1" MENU_ACTION smenu1 "subitem1" MENU_ACTION smenu1
@@ -23,6 +16,12 @@ MENU subMenu1 15,0 VERTICAL
"subitem3" MENU_ACTION smenu3 "subitem3" MENU_ACTION smenu3
} }
MENU mainMenu 0,0 HORIZONTAL
{
"sub menu1" SUB_MENU subMenu1 ; goes for _subMenu1
"quit" MENU_ACTION EnterDeskTop ; goes for _EnterDeskTop
}
; format: HEADER GEOS_TYPE "dosname" "classname" "version" ; format: HEADER GEOS_TYPE "dosname" "classname" "version"
HEADER APPLICATION "123456789 1234567" "Class Name" "V1.0.0" HEADER APPLICATION "123456789 1234567" "Class Name" "V1.0.0"