Port sc2 to C++.

This commit is contained in:
David Anderson 2014-08-22 00:23:02 -07:00
parent 4608050bd2
commit 48d228e2b1
6 changed files with 20 additions and 20 deletions

View File

@ -83,7 +83,7 @@ binary.sources += [
'memfile.cpp', 'memfile.cpp',
'pawncc.cpp', 'pawncc.cpp',
'sc1.c', 'sc1.c',
'sc2.c', 'sc2.cpp',
'sc3.cpp', 'sc3.cpp',
'sc4.cpp', 'sc4.cpp',
'sc5.cpp', 'sc5.cpp',

View File

@ -828,7 +828,7 @@ SC_FUNC stringlist *insert_docstring(char *string);
SC_FUNC char *get_docstring(int index); SC_FUNC char *get_docstring(int index);
SC_FUNC void delete_docstring(int index); SC_FUNC void delete_docstring(int index);
SC_FUNC void delete_docstringtable(void); SC_FUNC void delete_docstringtable(void);
SC_FUNC stringlist *insert_autolist(char *string); SC_FUNC stringlist *insert_autolist(const char *string);
SC_FUNC char *get_autolist(int index); SC_FUNC char *get_autolist(int index);
SC_FUNC void delete_autolisttable(void); SC_FUNC void delete_autolisttable(void);
SC_FUNC stringlist *insert_dbgfile(const char *filename); SC_FUNC stringlist *insert_dbgfile(const char *filename);
@ -844,7 +844,7 @@ SC_FUNC int cp_path(const char *root,const char *directory);
SC_FUNC int cp_set(const char *name); SC_FUNC int cp_set(const char *name);
SC_FUNC cell cp_translate(const unsigned char *string,const unsigned char **endptr); SC_FUNC cell cp_translate(const unsigned char *string,const unsigned char **endptr);
SC_FUNC cell get_utf8_char(const unsigned char *string,const unsigned char **endptr); SC_FUNC cell get_utf8_char(const unsigned char *string,const unsigned char **endptr);
SC_FUNC int scan_utf8(FILE *fp,const char *filename); SC_FUNC int scan_utf8(void *fp,const char *filename);
/* function prototypes in SCSTATE.C */ /* function prototypes in SCSTATE.C */
SC_FUNC constvalue *automaton_add(const char *name); SC_FUNC constvalue *automaton_add(const char *name);
@ -942,9 +942,9 @@ SC_VDECL int sc_require_newdecls; /* only newdecls are allowed */
SC_VDECL constvalue sc_automaton_tab; /* automaton table */ SC_VDECL constvalue sc_automaton_tab; /* automaton table */
SC_VDECL constvalue sc_state_tab; /* state table */ SC_VDECL constvalue sc_state_tab; /* state table */
SC_VDECL FILE *inpf; /* file read from (source or include) */ SC_VDECL void *inpf; /* file read from (source or include) */
SC_VDECL FILE *inpf_org; /* main source file */ SC_VDECL void *inpf_org; /* main source file */
SC_VDECL FILE *outf; /* file written to */ SC_VDECL void *outf; /* file written to */
SC_VDECL jmp_buf errbuf; /* target of longjmp() on a fatal error */ SC_VDECL jmp_buf errbuf; /* target of longjmp() on a fatal error */

View File

@ -47,7 +47,7 @@ static cell litchar(const unsigned char **lptr,int flags);
static symbol *find_symbol(const symbol *root,const char *name,int fnumber,int automaton,int *cmptag); static symbol *find_symbol(const symbol *root,const char *name,int fnumber,int automaton,int *cmptag);
static void substallpatterns(unsigned char *line,int buffersize); static void substallpatterns(unsigned char *line,int buffersize);
static int match(char *st,int end); static int match(const char *st,int end);
static int alpha(char c); static int alpha(char c);
#define SKIPMODE 1 /* bit field in "#if" stack */ #define SKIPMODE 1 /* bit field in "#if" stack */
@ -134,7 +134,8 @@ SC_FUNC void clearstk(void)
SC_FUNC int plungequalifiedfile(char *name) SC_FUNC int plungequalifiedfile(char *name)
{ {
static char *extensions[] = { ".inc", ".p", ".pawn" }; static const char *extensions[] = { ".inc", ".p", ".pawn" };
void *fp; void *fp;
char *ext; char *ext;
int ext_idx; int ext_idx;
@ -1251,7 +1252,7 @@ static int command(void)
break; break;
default: { default: {
char s2[20]; char s2[20];
extern char *sc_tokens[];/* forward declaration */ extern const char *sc_tokens[];/* forward declaration */
if (tok<256) if (tok<256)
sprintf(s2,"%c",(char)tok); sprintf(s2,"%c",(char)tok);
else else
@ -1482,7 +1483,7 @@ static char *strdel(char *str,size_t len)
return str; return str;
} }
static char *strins(char *dest,char *src,size_t srclen) static char *strins(char *dest,const char *src,size_t srclen)
{ {
size_t destlen=strlen(dest); size_t destlen=strlen(dest);
assert(srclen<=strlen(src)); assert(srclen<=strlen(src));
@ -1943,7 +1944,7 @@ SC_FUNC void lexinit(void)
sTokenBuffer = &sNormalBuffer; sTokenBuffer = &sNormalBuffer;
} }
char *sc_tokens[] = { const char *sc_tokens[] = {
"*=", "/=", "%=", "+=", "-=", "<<=", ">>>=", ">>=", "&=", "^=", "|=", "*=", "/=", "%=", "+=", "-=", "<<=", ">>>=", ">>=", "&=", "^=", "|=",
"||", "&&", "==", "!=", "<=", ">=", "<<", ">>>", ">>", "++", "--", "||", "&&", "==", "!=", "<=", ">=", "<<", ">>>", ">>", "++", "--",
"...", "..", "::", "...", "..", "::",
@ -2003,7 +2004,6 @@ static void lexpop()
SC_FUNC int lex(cell *lexvalue,char **lexsym) SC_FUNC int lex(cell *lexvalue,char **lexsym)
{ {
int i,toolong,newline; int i,toolong,newline;
char **tokptr;
const unsigned char *starttoken; const unsigned char *starttoken;
if (sTokenBuffer->depth > 0) { if (sTokenBuffer->depth > 0) {
@ -2054,7 +2054,7 @@ SC_FUNC int lex(cell *lexvalue,char **lexsym)
tok->start.col = (int)(lptr - pline); tok->start.col = (int)(lptr - pline);
i=tFIRST; i=tFIRST;
tokptr=sc_tokens; const char **tokptr=sc_tokens;
while (i<=tMIDDLE) { /* match multi-character operators */ while (i<=tMIDDLE) { /* match multi-character operators */
if (*lptr==**tokptr && match(*tokptr,FALSE)) { if (*lptr==**tokptr && match(*tokptr,FALSE)) {
tok->id = i; tok->id = i;
@ -2440,7 +2440,7 @@ SC_FUNC int require_newline(int allow_semi)
* *
* Global references: lptr (altered) * Global references: lptr (altered)
*/ */
static int match(char *st,int end) static int match(const char *st,int end)
{ {
int k; int k;
const unsigned char *ptr; const unsigned char *ptr;

View File

@ -391,7 +391,7 @@ SC_FUNC cell get_utf8_char(const unsigned char *string,const unsigned char **end
} }
#endif #endif
SC_FUNC int scan_utf8(FILE *fp,const char *filename) SC_FUNC int scan_utf8(void *fp,const char *filename)
{ {
#if defined NO_UTF8 #if defined NO_UTF8
return 0; return 0;

View File

@ -137,7 +137,7 @@ static int delete_stringpair(stringpair *root,stringpair *item)
} }
/* ----- string list functions ----------------------------------- */ /* ----- string list functions ----------------------------------- */
static stringlist *insert_string(stringlist *root,char *string) static stringlist *insert_string(stringlist *root,const char *string)
{ {
stringlist *cur; stringlist *cur;
@ -418,7 +418,7 @@ SC_FUNC void delete_docstringtable(void)
/* ----- autolisting --------------------------------------------- */ /* ----- autolisting --------------------------------------------- */
static stringlist autolist; static stringlist autolist;
SC_FUNC stringlist *insert_autolist(char *string) SC_FUNC stringlist *insert_autolist(const char *string)
{ {
return insert_string(&autolist,string); return insert_string(&autolist,string);
} }

View File

@ -98,9 +98,9 @@ SC_VDEFINE int sc_require_newdecls=0; /* Require new-style declarations */
SC_VDEFINE constvalue sc_automaton_tab = { NULL, "", 0, 0}; /* automaton table */ SC_VDEFINE constvalue sc_automaton_tab = { NULL, "", 0, 0}; /* automaton table */
SC_VDEFINE constvalue sc_state_tab = { NULL, "", 0, 0}; /* state table */ SC_VDEFINE constvalue sc_state_tab = { NULL, "", 0, 0}; /* state table */
SC_VDEFINE FILE *inpf = NULL; /* file read from (source or include) */ SC_VDEFINE void *inpf = NULL; /* file read from (source or include) */
SC_VDEFINE FILE *inpf_org= NULL; /* main source file */ SC_VDEFINE void *inpf_org= NULL; /* main source file */
SC_VDEFINE FILE *outf = NULL; /* (intermediate) text file written to */ SC_VDEFINE void *outf = NULL; /* (intermediate) text file written to */
SC_VDEFINE jmp_buf errbuf; SC_VDEFINE jmp_buf errbuf;