From c0be0d0d5d9a79c6ae09cb60a08d806e2ea0ccdf Mon Sep 17 00:00:00 2001 From: Amyr Ahmady Date: Mon, 7 Oct 2019 13:22:29 +0330 Subject: [PATCH 1/3] Add '#pragma once' --- source/compiler/sc2.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index 25c0d9d8..d640fadf 100644 --- a/source/compiler/sc2.c +++ b/source/compiler/sc2.c @@ -1231,6 +1231,31 @@ static int command(void) cell val; preproc_expr(&val,NULL); sc_needsemicolon=(int)val; + } else if (strcmp(str,"once")==0) { + char symname[sNAMEMAX]; + symbol *included; + /* make it compatible for Windows paths with '\\' directory separator */ + char* basefname=inpfname; + for (char* _cchar=inpfname; *_cchar!='\0'; _cchar++) + if (*_cchar=='/'||*_cchar=='\\') + basefname=_cchar+1; + /* assign '_inc_includename' string to symname */ + strcpy(symname,"_inc_"); + strlcat(symname,basefname,sizeof symname); + /* check if '_inc_includename' is already in global symbols table or not */ + included=find_symbol(&glbtab,symname,fcurrent,-1,NULL); + if (included==NULL) + /* couldn't find '_inc_includename' in symbols table */ + add_constant(symname,1,sGLOBAL,0); // add symname ('_inc_includename') to global symbols table + else { + /* found '_inc_includename' symbol in global symbols table */ + if (!SKIPPING) { + assert(inpf!=NULL); + if (inpf!=inpf_org) + pc_closesrc(inpf); // close input file (like #endinput) + inpf=NULL; + } /* if */ + } } else if (strcmp(str,"tabsize")==0) { cell val; preproc_expr(&val,NULL); From a0edfd122d84e5ba842cf3be8e013ea749d5636f Mon Sep 17 00:00:00 2001 From: Amyr Ahmady Date: Mon, 7 Oct 2019 15:17:06 +0330 Subject: [PATCH 2/3] change `_cchar` variable name and declare variables at start of scope --- source/compiler/sc2.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index d640fadf..9f9947f5 100644 --- a/source/compiler/sc2.c +++ b/source/compiler/sc2.c @@ -1232,13 +1232,14 @@ static int command(void) preproc_expr(&val,NULL); sc_needsemicolon=(int)val; } else if (strcmp(str,"once")==0) { + char* curr_char; + char* basefname=inpfname; char symname[sNAMEMAX]; symbol *included; /* make it compatible for Windows paths with '\\' directory separator */ - char* basefname=inpfname; - for (char* _cchar=inpfname; *_cchar!='\0'; _cchar++) - if (*_cchar=='/'||*_cchar=='\\') - basefname=_cchar+1; + for (curr_char=inpfname; *curr_char!='\0'; curr_char++) + if (*curr_char=='/'||*curr_char=='\\') + basefname=curr_char+1; /* assign '_inc_includename' string to symname */ strcpy(symname,"_inc_"); strlcat(symname,basefname,sizeof symname); From 678a91bc540fbc9484ff6333d8afccad79074d04 Mon Sep 17 00:00:00 2001 From: Amyr Ahmady Date: Thu, 10 Oct 2019 14:17:39 +0330 Subject: [PATCH 3/3] follow compiler include guard style (with `-Z`) for '#pragma once' --- source/compiler/sc2.c | 54 ++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index 9f9947f5..783b22ed 100644 --- a/source/compiler/sc2.c +++ b/source/compiler/sc2.c @@ -1232,30 +1232,36 @@ static int command(void) preproc_expr(&val,NULL); sc_needsemicolon=(int)val; } else if (strcmp(str,"once")==0) { - char* curr_char; - char* basefname=inpfname; - char symname[sNAMEMAX]; - symbol *included; - /* make it compatible for Windows paths with '\\' directory separator */ - for (curr_char=inpfname; *curr_char!='\0'; curr_char++) - if (*curr_char=='/'||*curr_char=='\\') - basefname=curr_char+1; - /* assign '_inc_includename' string to symname */ - strcpy(symname,"_inc_"); - strlcat(symname,basefname,sizeof symname); - /* check if '_inc_includename' is already in global symbols table or not */ - included=find_symbol(&glbtab,symname,fcurrent,-1,NULL); - if (included==NULL) - /* couldn't find '_inc_includename' in symbols table */ - add_constant(symname,1,sGLOBAL,0); // add symname ('_inc_includename') to global symbols table - else { - /* found '_inc_includename' symbol in global symbols table */ - if (!SKIPPING) { - assert(inpf!=NULL); - if (inpf!=inpf_org) - pc_closesrc(inpf); // close input file (like #endinput) - inpf=NULL; - } /* if */ + /* check if compiler is not running with `-Z` arg */ + if(!pc_compat) { + char symname[sNAMEMAX]; + char *ptr; + symbol *included; + /* remove unnecessary directory names from include file absolute path */ + char dirsep= + #if DIRSEP_CHAR!='\\' + '\\'; + #else + DIRSEP_CHAR; + #endif + strcpy(symname,"_inc_"); + if ((ptr=strrchr(inpfname,dirsep))!=NULL) + strlcat(symname,ptr+1,sizeof symname); + else + strlcat(symname,inpfname,sizeof symname); + included=find_symbol(&glbtab,symname,fcurrent,-1,NULL); + if (included==NULL) + /* couldn't find '_inc_includename' in symbols table */ + add_constant(symname,1,sGLOBAL,0); // add symname ('_inc_includename') to global symbols table + else { + /* found '_inc_includename' symbol in global symbols table */ + if (!SKIPPING) { + assert(inpf!=NULL); + if (inpf!=inpf_org) + pc_closesrc(inpf); // close input file (like #endinput) + inpf=NULL; + } /* if */ + } } } else if (strcmp(str,"tabsize")==0) { cell val;