Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Misc. minor fixes and adjustments #711

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion source/compiler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ set(PAWNC_SRCS
scstate.c
scvars.c
version.h)
set_source_files_properties(sc1.c COMPILE_FLAGS -DNO_MAIN)
if(WIN32)
set(PAWNC_SRCS ${PAWNC_SRCS} libpawnc.rc)
set_source_files_properties(libpawnc.c COMPILE_FLAGS -DPAWNC_DLL)
Expand Down
2 changes: 1 addition & 1 deletion source/compiler/libpawnc.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ void *pc_createtmpsrc(char **filename)
static const char template[]="/tmp/pawnXXXXXX";
if ((tname=malloc(sizeof(template)))!=NULL) {
int fdtmp;
strncpy(tname,template,sizeof(template));
strncpy(tname,template,arraysize(template));
if ((fdtmp=mkstemp(tname))>=0)
ftmp=fdopen(fdtmp,"wt");
if (fdtmp<0 || filename==NULL) {
Expand Down
9 changes: 6 additions & 3 deletions source/compiler/sc.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ typedef struct s_arginfo { /* function argument info */
int dim[sDIMEN_MAX];
int idxtag[sDIMEN_MAX];
int numdim; /* number of dimensions */
unsigned char hasdefault; /* bit0: is there a default value? bit6: "tagof"; bit7: "sizeof" */
unsigned char hasdefault; /* bit0: is there a default value?
* bit5: "tagof" (with tag name as an argument);
* bit6: "tagof" (with symbol name as an argument);
* bit7: "sizeof" */
union {
cell val; /* default value */
struct {
Expand Down Expand Up @@ -992,7 +995,7 @@ SC_VDECL int sc_listing; /* create .LST file? */
SC_VDECL int sc_compress; /* compress bytecode? */
SC_VDECL int sc_needsemicolon;/* semicolon required to terminate expressions? */
SC_VDECL int sc_dataalign; /* data alignment value */
SC_VDECL int sc_alignnext; /* must frame of the next function be aligned? */
SC_VDECL int sc_alignnext; /* must the next variable or the frame of the next function be aligned? */
SC_VDECL int pc_docexpr; /* must expression be attached to documentation comment? */
SC_VDECL int curseg; /* 1 if currently parsing CODE, 2 if parsing DATA */
SC_VDECL cell pc_stksize; /* stack size */
Expand All @@ -1012,7 +1015,7 @@ SC_VDECL short sc_allowtags; /* allow/detect tagnames in lex() */
SC_VDECL int sc_status; /* read/write status */
SC_VDECL int sc_rationaltag; /* tag for rational numbers */
SC_VDECL int rational_digits; /* number of fractional digits */
SC_VDECL int sc_allowproccall;/* allow/detect tagnames in lex() */
SC_VDECL int sc_allowproccall;/* allow "procedure call" syntax */
SC_VDECL short sc_is_utf8; /* is this source file in UTF-8 encoding */
SC_VDECL char *pc_deprecate; /* if non-NULL, mark next declaration as deprecated */
SC_VDECL int sc_curstates; /* ID of the current state list */
Expand Down
283 changes: 0 additions & 283 deletions source/compiler/sc1.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,289 +231,6 @@ static char reportname[_MAX_PATH];/* report file name */
static HWND hwndFinish = 0;
#endif

#if !defined NO_MAIN

#if defined __TURBOC__ && !defined __32BIT__
extern unsigned int _stklen = 0x2000;
#endif

int main(int argc, char *argv[])
{
return pc_compile(argc,argv);
}

/* pc_printf()
* Called for general purpose "console" output. This function prints general
* purpose messages; errors go through pc_error(). The function is modelled
* after printf().
*/
int pc_printf(const char *message,...)
{
int ret;
va_list argptr;

va_start(argptr,message);
ret=vprintf(message,argptr);
va_end(argptr);

return ret;
}

/* pc_error()
* Called for producing error output.
* number the error number (as documented in the manual)
* message a string describing the error with embedded %d and %s tokens
* filename the name of the file currently being parsed
* firstline the line number at which the expression started on which
* the error was found, or -1 if there is no "starting line"
* lastline the line number at which the error was detected
* argptr a pointer to the first of a series of arguments (for macro
* "va_arg")
* Return:
* If the function returns 0, the parser attempts to continue compilation.
* On a non-zero return value, the parser aborts.
*/
int pc_error(int number,char *message,char *filename,int firstline,int lastline,va_list argptr)
{
static char *prefix[3]={ "error", "fatal error", "warning" };

if (number!=0) {
char *pre;

pre=prefix[number/100];
if (number>=200 && pc_geterrorwarnings()){
pre=prefix[0];
}
if (firstline>=0)
fprintf(stderr,"%s(%d -- %d) : %s %03d: ",filename,firstline,lastline,pre,number);
else
fprintf(stderr,"%s(%d) : %s %03d: ",filename,lastline,pre,number);
} /* if */
vfprintf(stderr,message,argptr);
fflush(stderr);
return 0;
}

/* pc_opensrc()
* Opens a source file (or include file) for reading. The "file" does not have
* to be a physical file, one might compile from memory.
* filename the name of the "file" to read from
* Return:
* The function must return a pointer, which is used as a "magic cookie" to
* all I/O functions. When failing to open the file for reading, the
* function must return NULL.
* Note:
* Several "source files" may be open at the same time. Specifically, one
* file can be open for reading and another for writing.
*/
void *pc_opensrc(char *filename)
{
return fopen(filename,"r");
}

/* pc_createsrc()
* Creates/overwrites a source file for writing. The "file" does not have
* to be a physical file, one might compile from memory.
* filename the name of the "file" to create
* Return:
* The function must return a pointer, which is used as a "magic cookie" to
* all I/O functions. When failing to open the file for reading, the
* function must return NULL.
* Note:
* Several "source files" may be open at the same time. Specifically, one
* file can be open for reading and another for writing.
*/
void *pc_createsrc(char *filename)
{
return fopen(filename,"w");
}

/* pc_createtmpsrc()
* Creates a temporary source file with a unique name for writing.
* Return:
* The function must return a pointer, which is used as a "magic cookie" to
* all I/O functions. When failing to open the file for reading, the
* function must return NULL.
*/
void *pc_createtmpsrc(char **filename)
{
char *tname=NULL;
FILE *ftmp=NULL;

#if defined __WIN32__ || defined _WIN32
tname=_tempnam(NULL,"pawn");
ftmp=fopen(tname,"wt");
#elif defined __MSDOS__ || defined _Windows
tname=tempnam(NULL,"pawn");
ftmp=fopen(tname,"wt");
#else
static const char template[]="/tmp/pawnXXXXXX";
if ((tname=malloc(sizeof(template)))!=NULL) {
int fdtmp;
strncpy(tname,template,arraysize(template));
if ((fdtmp=mkstemp(tname)) >= 0) {
ftmp=fdopen(fdtmp,"wt");
} else {
free(tname);
tname=NULL;
} /* if */
} /* if */
#endif
if (filename!=NULL)
*filename=tname;
return ftmp;
}

/* pc_closesrc()
* Closes a source file (or include file). The "handle" parameter has the
* value that pc_opensrc() returned in an earlier call.
*/
void pc_closesrc(void *handle)
{
assert(handle!=NULL);
fclose((FILE*)handle);
}

/* pc_resetsrc()
* "position" may only hold a pointer that was previously obtained from
* pc_getpossrc()
*/
void pc_resetsrc(void *handle,void *position)
{
assert(handle!=NULL);
fsetpos((FILE*)handle,(fpos_t *)position);
}

/* pc_readsrc()
* Reads a single line from the source file (or up to a maximum number of
* characters if the line in the input file is too long).
*/
char *pc_readsrc(void *handle,unsigned char *target,int maxchars)
{
return fgets((char*)target,maxchars,(FILE*)handle);
}

/* pc_writesrc()
* Writes to to the source file. There is no automatic line ending; to end a
* line, write a "\n".
*/
int pc_writesrc(void *handle,unsigned char *source)
{
return fputs((char*)source,(FILE*)handle) >= 0;
}

void *pc_getpossrc(void *handle)
{
static fpos_t lastpos; /* may need to have a LIFO stack of such positions */

fgetpos((FILE*)handle,&lastpos);
return &lastpos;
}

int pc_eofsrc(void *handle)
{
return feof((FILE*)handle);
}

/* should return a pointer, which is used as a "magic cookie" to all I/O
* functions; return NULL for failure
*/
void *pc_openasm(char *filename)
{
#if defined __MSDOS__ || defined SC_LIGHT
return fopen(filename,"w+");
#else
return mfcreate(filename);
#endif
}

void pc_closeasm(void *handle, int deletefile)
{
#if defined __MSDOS__ || defined SC_LIGHT
if (handle!=NULL)
fclose((FILE*)handle);
if (deletefile)
remove(outfname);
#else
if (handle!=NULL) {
if (!deletefile)
mfdump((MEMFILE*)handle);
mfclose((MEMFILE*)handle);
} /* if */
#endif
}

void pc_resetasm(void *handle)
{
assert(handle!=NULL);
#if defined __MSDOS__ || defined SC_LIGHT
fflush((FILE*)handle);
fseek((FILE*)handle,0,SEEK_SET);
#else
mfseek((MEMFILE*)handle,0,SEEK_SET);
#endif
}

int pc_writeasm(void *handle,char *string)
{
#if defined __MSDOS__ || defined SC_LIGHT
return fputs(string,(FILE*)handle) >= 0;
#else
return mfputs((MEMFILE*)handle,string);
#endif
}

char *pc_readasm(void *handle, char *string, int maxchars)
{
#if defined __MSDOS__ || defined SC_LIGHT
return fgets(string,maxchars,(FILE*)handle);
#else
return mfgets((MEMFILE*)handle,string,maxchars);
#endif
}

/* Should return a pointer, which is used as a "magic cookie" to all I/O
* functions; return NULL for failure.
*/
void *pc_openbin(char *filename)
{
FILE *fbin;

fbin=fopen(filename,"wb");
setvbuf(fbin,NULL,_IOFBF,1UL<<20);
return fbin;
}

void pc_closebin(void *handle,int deletefile)
{
fclose((FILE*)handle);
if (deletefile)
remove(binfname);
}

/* pc_resetbin()
* Can seek to any location in the file.
* The offset is always from the start of the file.
*/
void pc_resetbin(void *handle,long offset)
{
fflush((FILE*)handle);
fseek((FILE*)handle,offset,SEEK_SET);
}

int pc_writebin(void *handle,void *buffer,int size)
{
return (int)fwrite(buffer,1,size,(FILE*)handle) == size;
}

long pc_lengthbin(void *handle)
{
return ftell((FILE*)handle);
}

#endif /* !defined NO_MAIN */


/* "main" of the compiler
*/
#if defined __cplusplus
Expand Down
7 changes: 3 additions & 4 deletions source/compiler/sc2.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ static void readline(unsigned char *line)
} while (num>=0 && cont);
}

/* stripcom
/* stripcomment
*
* Replaces all comments from the line by space characters. It updates
* a global variable ("icomment") for multiline comments, and a global
Expand All @@ -454,8 +454,8 @@ static void readline(unsigned char *line)
* The function also detects (and manages) "documentation comments". The
* global variable "icomment" is set to 2 for documentation comments.
*
* Global references: icomment (private to "stripcom")
* Global references: imlstring (private to "stripcom")
* Global references: icomment (private to "stripcomment")
* Global references: imlstring (private to "stripcomment")
*
* Returns 1 if the line started with a multiline string, and 2 if it also
* ends with the same multiline string, so that this won't trigger commands:
Expand All @@ -467,7 +467,6 @@ static void readline(unsigned char *line)
*
* Some code might see that as a line starting with `#define` because there
* was no explicit line continuation, merely an implicit string one.
*
*/
static int stripcomment(unsigned char *line)
{
Expand Down
2 changes: 1 addition & 1 deletion source/compiler/sc3.c
Original file line number Diff line number Diff line change
Expand Up @@ -2469,7 +2469,7 @@ static int nesting=0;
error(48); /* array dimensions must match */
} else {
if (lval.sym==NULL && (arg[argidx].usage & uCONST)==0)
error(239);
error(239); /* literal array/string passed to a non-const parameter */
if (arg[argidx].dim[0]!=0) {
assert(arg[argidx].dim[0]>0);
if (lval.ident==iARRAYCELL) {
Expand Down
4 changes: 2 additions & 2 deletions source/compiler/scvars.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ SC_VDEFINE int sc_listing= FALSE; /* create .LST file? */
SC_VDEFINE int sc_compress=TRUE; /* compress bytecode? */
SC_VDEFINE int sc_needsemicolon=TRUE; /* semicolon required to terminate expressions? */
SC_VDEFINE int sc_dataalign=sizeof(cell); /* data alignment value */
SC_VDEFINE int sc_alignnext=FALSE; /* must frame of the next function be aligned? */
SC_VDEFINE int sc_alignnext=FALSE; /* must the next variable or the frame of the next function be aligned? */
SC_VDEFINE int pc_docexpr=FALSE; /* must expression be attached to documentation comment? */
SC_VDEFINE int curseg=0; /* 1 if currently parsing CODE, 2 if parsing DATA */
SC_VDEFINE cell pc_stksize=sDEF_AMXSTACK; /* default stack size */
Expand All @@ -89,7 +89,7 @@ SC_VDEFINE short sc_allowtags=TRUE; /* allow/detect tagnames in lex() */
SC_VDEFINE int sc_status; /* read/write status */
SC_VDEFINE int sc_rationaltag=0; /* tag for rational numbers */
SC_VDEFINE int rational_digits=0; /* number of fractional digits */
SC_VDEFINE int sc_allowproccall=FALSE; /* allow/detect tagnames in lex() */
SC_VDEFINE int sc_allowproccall=FALSE; /* allow "procedure call" syntax */
SC_VDEFINE short sc_is_utf8=FALSE; /* is this source file in UTF-8 encoding */
SC_VDEFINE char *pc_deprecate=NULL; /* if non-null, mark next declaration as deprecated */
SC_VDEFINE int sc_curstates=0; /* ID of the current state list */
Expand Down