From 2b611d8f7017bcd32162a316c57afe5e95943004 Mon Sep 17 00:00:00 2001 From: kichik Date: Thu, 5 Jun 2003 21:53:52 +0000 Subject: [PATCH] All acceptable warnings now contain a file name and a line number git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@2614 212acab6-be3b-0410-9dea-997c60f758d6 --- Source/build.cpp | 8 ++--- Source/build.h | 14 ++++++--- Source/lang.cpp | 2 -- Source/makenssi.cpp | 10 +++--- Source/script.cpp | 76 ++++++++++++++++++++++++++++++--------------- 5 files changed, 68 insertions(+), 42 deletions(-) diff --git a/Source/build.cpp b/Source/build.cpp index 6e2c4ca9..902642c8 100644 --- a/Source/build.cpp +++ b/Source/build.cpp @@ -437,7 +437,7 @@ int CEXEBuild::preprocess_string(char *out, const char *in) strncpy(tbuf,p,63); tbuf[63]=0; if (strstr(tbuf," ")) strstr(tbuf," ")[0]=0; - warning("unknown variable \"%s\" detected, ignoring",tbuf); + warning("unknown variable \"%s\" detected, ignoring (%s:%d)",tbuf,curfilename,linecnt); i = '$'; } } @@ -459,7 +459,7 @@ int CEXEBuild::add_string_main(const char *string, int process) // returns offse if (p) { *p = 0; if (!strnicmp(cp,"un.",3)) { - warning("Installer language strings can't start with un. (%s)!", string); + warning("Installer language strings can't start with un. (%s)! (%s:%d)", string, curfilename, linecnt); free(cp); return 0; } @@ -487,7 +487,7 @@ int CEXEBuild::add_string_uninst(const char *string, int process) // returns off if (p) { *p = 0; if (strnicmp(cp,"un.",3)) { - warning("Uninstaller language strings must start with un. (%s)!", string); + warning("Uninstaller language strings must start with un. (%s)! (%s:%d)", string, curfilename, linecnt); free(cp); return 0; } @@ -802,7 +802,7 @@ int CEXEBuild::section_end() return PS_OK; } -int CEXEBuild::add_section(const char *secname, const char *file, int line, const char *defname, int expand/*=0*/) +int CEXEBuild::add_section(const char *secname, const char *defname, int expand/*=0*/) { if (build_cursection_isfunc) { diff --git a/Source/build.h b/Source/build.h index 088f887d..fad24fdd 100644 --- a/Source/build.h +++ b/Source/build.h @@ -67,7 +67,7 @@ class CEXEBuild { // process a script (you can process as many scripts as you want, // it is as if they are concatenated) - int process_script(FILE *fp, char *curfilename, int *lineptr); + int process_script(FILE *fp, char *curfilename); int process_oneline(char *line, char *curfilename, int lineptr); // you only get to call write_output once, so use it wisely. @@ -82,6 +82,10 @@ class CEXEBuild { int display_warnings; int display_info; + int linecnt; + char *curfilename; + FILE *fp; + HWND notify_hwnd; void notify(int code, char *data); @@ -90,10 +94,10 @@ class CEXEBuild { int get_commandtoken(char *s, int *np, int *op); // script.cpp - int parseScript(FILE *fp, const char *curfilename, int *lineptr); + int parseScript(); void ps_addtoline(const char *str, GrowBuf &linedata, StringList &hist); - int doParse(const char *str, FILE *fp, const char *curfilename, int *lineptr); - int doCommand(int which_token, LineParser &line, FILE *fp, const char *curfilename, int *lineptr); + int doParse(const char *str); + int doCommand(int which_token, LineParser &line); int do_add_file(const char *lgss, int attrib, int recurse, int linecnt, int *total_files, const char *name_override=0, int generatecode=1, int *data_handle=0, int rec_depth=0); GrowBuf m_linebuild; // used for concatenating lines @@ -107,7 +111,7 @@ class CEXEBuild { // build.cpp functions used mostly by script.cpp int getcurdbsize(); - int add_section(const char *secname, const char *file, int line, const char *defname, int expand=0); + int add_section(const char *secname, const char *defname, int expand=0); int section_end(); int add_function(const char *funname); int function_end(); diff --git a/Source/lang.cpp b/Source/lang.cpp index a7b347f9..13612311 100644 --- a/Source/lang.cpp +++ b/Source/lang.cpp @@ -1,5 +1,3 @@ -// Lang.cpp by Amir Szekely 3rd August 2002 - #include #include #include diff --git a/Source/makenssi.cpp b/Source/makenssi.cpp index e7265452..e62f1baf 100644 --- a/Source/makenssi.cpp +++ b/Source/makenssi.cpp @@ -258,14 +258,13 @@ int main(int argc, char **argv) fprintf(g_output,"\n\nProcessing config: \n"); fflush(g_output); } - int lc=0; - int ret=build.process_script(cfg,exepath,&lc); + int ret=build.process_script(cfg,exepath); fclose(cfg); if (ret != PS_OK && ret != PS_EOF) { if (build.display_errors) { - fprintf(g_output,"Error in config on line %d -- aborting creation process\n",lc); + fprintf(g_output,"Error in config on line %d -- aborting creation process\n",build.linecnt); fflush(g_output); } return 1; @@ -341,15 +340,14 @@ int main(int argc, char **argv) fprintf(g_output,"\n\nProcessing script file: \"%s\"\n",sfile); fflush(g_output); } - int lc=0; - int ret=build.process_script(fp,sfile,&lc); + int ret=build.process_script(fp,sfile); if (fp != stdin) fclose(fp); if (ret != PS_EOF && ret != PS_OK) { if (build.display_errors) { - fprintf(g_output,"Error in script \"%s\" on line %d -- aborting creation process\n",sfile,lc); + fprintf(g_output,"Error in script \"%s\" on line %d -- aborting creation process\n",sfile,build.linecnt); fflush(g_output); } return 1; diff --git a/Source/script.cpp b/Source/script.cpp index c9775874..d3fbedb8 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -25,14 +25,18 @@ static const char *usrvars="$0\0$1\0$2\0$3\0$4\0$5\0$6\0$7\0$8\0$9\0" "$CMDLINE\0$INSTDIR\0$OUTDIR\0$EXEDIR\0$LANGUAGE\0"; -int CEXEBuild::process_script(FILE *fp, char *curfilename, int *lineptr) +int CEXEBuild::process_script(FILE *filepointer, char *filename) { + linecnt = 0; + fp = filepointer; + curfilename = filename; + if (has_called_write_output) { ERROR_MSG("Error (process_script): write_output already called, can't continue\n"); return PS_ERROR; } - int ret=parseScript(fp,curfilename,lineptr); + int ret=parseScript(); if (ret == PS_ENDIF) ERROR_MSG("!endif: stray !endif\n"); if (IS_PS_ELSE(ret)) ERROR_MSG("!else: stray !else\n"); if (m_linebuild.getlen()) @@ -46,7 +50,7 @@ int CEXEBuild::process_script(FILE *fp, char *curfilename, int *lineptr) #define PRINTHELP() { print_help(line.gettoken_str(0)); return PS_ERROR; } -int CEXEBuild::doParse(const char *str, FILE *fp, const char *curfilename, int *lineptr) +int CEXEBuild::doParse(const char *str) { static int ignore; static int last_line_had_slash; @@ -78,8 +82,8 @@ int CEXEBuild::doParse(const char *str, FILE *fp, const char *curfilename, int * if (res) { - if (res==-2) ERROR_MSG("Error: unterminated string parsing line at %s:%d\n",curfilename,*lineptr); - else ERROR_MSG("Error: error parsing line (%s:%d)\n",curfilename,*lineptr); + if (res==-2) ERROR_MSG("Error: unterminated string parsing line at %s:%d\n",curfilename,linecnt); + else ERROR_MSG("Error: error parsing line (%s:%d)\n",curfilename,linecnt); return PS_ERROR; } @@ -215,7 +219,7 @@ parse_again: } if (!ignore) { - return doCommand(tkid,line,fp,curfilename,lineptr); + return doCommand(tkid,line); } return PS_OK; } @@ -296,7 +300,7 @@ void CEXEBuild::ps_addtoline(const char *str, GrowBuf &linedata, StringList &his } } -int CEXEBuild::parseScript(FILE *fp, const char *curfilename, int *lineptr) +int CEXEBuild::parseScript() { char str[MAX_LINELENGTH]; @@ -305,7 +309,7 @@ int CEXEBuild::parseScript(FILE *fp, const char *curfilename, int *lineptr) char *p=str; *p=0; fgets(str,MAX_LINELENGTH,fp); - (*lineptr)++; + linecnt++; if (feof(fp)&&!str[0]) break; // remove trailing whitespace @@ -318,20 +322,30 @@ int CEXEBuild::parseScript(FILE *fp, const char *curfilename, int *lineptr) GrowBuf linedata; ps_addtoline(str,linedata,hist); linedata.add((void*)"",1); - int ret=doParse((char*)linedata.get(),fp,curfilename,lineptr); + int ret=doParse((char*)linedata.get()); if (ret != PS_OK) return ret; } return PS_EOF; } -int CEXEBuild::process_oneline(char *line, char *curfilename, int lineptr) +int CEXEBuild::process_oneline(char *line, char *filename, int linenum) { + char *last_filename=curfilename; + curfilename=filename; + int last_linecnt=linecnt; + linecnt=linenum; + StringList hist; GrowBuf linedata; ps_addtoline(line,linedata,hist); linedata.add((void*)"",1); - return doParse((char*)linedata.get(),NULL,curfilename,&lineptr); + int ret=doParse((char*)linedata.get()); + + linecnt=last_linecnt; + curfilename=last_filename; + + return ret; } int CEXEBuild::process_jump(LineParser &line, int wt, int *offs) @@ -365,10 +379,8 @@ int CEXEBuild::process_jump(LineParser &line, int wt, int *offs) #define SECTION_FIELD_GET(field) (FIELD_OFFSET(section, field)/sizeof(int)) #define SECTION_FIELD_SET(field) (-1 - (int)(FIELD_OFFSET(section, field)/sizeof(int))) -int CEXEBuild::doCommand(int which_token, LineParser &line, FILE *fp, const char *curfilename, int *lineptr) +int CEXEBuild::doCommand(int which_token, LineParser &line) { - int linecnt = *lineptr; - static const char *rootkeys[2] = { "HKCR\0HKLM\0HKCU\0HKU\0HKCC\0HKDD\0HKPD\0", "HKEY_CLASSES_ROOT\0HKEY_LOCAL_MACHINE\0HKEY_CURRENT_USER\0HKEY_USERS\0HKEY_CURRENT_CONFIG\0HKEY_DYN_DATA\0HKEY_PERFORMANCE_DATA\0" @@ -452,7 +464,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line, FILE *fp, const char { if (!stricmp(l2.gettoken_str(0),"!macroend")) { - (*lineptr)++; + linecnt++; break; } if (!stricmp(l2.gettoken_str(0),"!macro")) @@ -463,7 +475,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line, FILE *fp, const char } if (str[0]) m_macros.add(str,strlen(str)+1); else m_macros.add(" ",2); - (*lineptr)++; + linecnt++; } m_macros.add("",1); } @@ -2074,15 +2086,29 @@ int CEXEBuild::doCommand(int which_token, LineParser &line, FILE *fp, const char return PS_ERROR; } depth++; - int lc=0; - int r=parseScript(incfp,f,&lc); + + int last_linecnt=linecnt; + linecnt=0; + char *last_filename=curfilename; + curfilename=f; + FILE *last_fp=fp; + fp=incfp; + + int r=parseScript(); + + int errlinecnt=linecnt; + + linecnt=last_linecnt; + curfilename=last_filename; + fp=last_fp; + depth--; fclose(incfp); if (r != PS_EOF && r != PS_OK) { if (r == PS_ENDIF) ERROR_MSG("!endif: stray !endif\n"); if (IS_PS_ELSE(r)) ERROR_MSG("!else: stray !else\n"); - ERROR_MSG("!include: error in script: \"%s\" on line %d\n",f,lc); + ERROR_MSG("!include: error in script: \"%s\" on line %d\n",f,errlinecnt); if (malloced) free(f); return PS_ERROR; } @@ -2228,8 +2254,8 @@ int CEXEBuild::doCommand(int which_token, LineParser &line, FILE *fp, const char int ret; - if (line.gettoken_str(a)[0]=='-') ret=add_section("",curfilename,linecnt,line.gettoken_str(a+1)); - else ret=add_section(line.gettoken_str(a),curfilename,linecnt,line.gettoken_str(a+1)); + if (line.gettoken_str(a)[0]=='-') ret=add_section("",line.gettoken_str(a+1)); + else ret=add_section(line.gettoken_str(a),line.gettoken_str(a+1)); if (ret != PS_OK) return ret; if (unselected) @@ -2306,7 +2332,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line, FILE *fp, const char SCRIPT_MSG("%s %s",line.gettoken_str(0),line.gettoken_str(a)); if (line.gettoken_str(a+1)[0]) SCRIPT_MSG(" ->(%s)",line.gettoken_str(a+1)); SCRIPT_MSG("\n"); - return add_section(buf,curfilename,linecnt,line.gettoken_str(a+1),ex); + return add_section(buf,line.gettoken_str(a+1),ex); } case TOK_FUNCTION: if (!line.gettoken_str(1)[0]) PRINTHELP() @@ -2358,9 +2384,9 @@ int CEXEBuild::doCommand(int which_token, LineParser &line, FILE *fp, const char case TOK_SETCOMPRESS: build_compress=line.gettoken_enum(1,"off\0auto\0force\0"); if (build_compress==-1) PRINTHELP() - if (build_compress == 0 && build_compress_whole) + if (build_compress==0 && build_compress_whole) { - warning("'SetCompress off' encountered, and in whole compression mode. Effectively ignored.\n"); + warning("'SetCompress off' encountered, and in whole compression mode. Effectively ignored. (%s:%d)",curfilename,linecnt); } SCRIPT_MSG("SetCompress: %s\n",line.gettoken_str(1)); return PS_OK; @@ -4465,7 +4491,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line, FILE *fp, const char } SCRIPT_MSG("\n"); if (nounloadmisused) - warning("/NOUNLOAD must come first before any plugin parameter. Unless the plugin you are trying to use has a parameter /NOUNLOAD, you are doing something wrong."); + warning("/NOUNLOAD must come first before any plugin parameter. Unless the plugin you are trying to use has a parameter /NOUNLOAD, you are doing something wrong. (%s:%d)",curfilename,linecnt); // next, call it ent.which=EW_REGISTERDLL;