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
This commit is contained in:
kichik 2003-06-05 21:53:52 +00:00
parent e406ae6c1c
commit 2b611d8f70
5 changed files with 68 additions and 42 deletions

View file

@ -437,7 +437,7 @@ int CEXEBuild::preprocess_string(char *out, const char *in)
strncpy(tbuf,p,63); strncpy(tbuf,p,63);
tbuf[63]=0; tbuf[63]=0;
if (strstr(tbuf," ")) strstr(tbuf," ")[0]=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 = '$'; i = '$';
} }
} }
@ -459,7 +459,7 @@ int CEXEBuild::add_string_main(const char *string, int process) // returns offse
if (p) { if (p) {
*p = 0; *p = 0;
if (!strnicmp(cp,"un.",3)) { 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); free(cp);
return 0; return 0;
} }
@ -487,7 +487,7 @@ int CEXEBuild::add_string_uninst(const char *string, int process) // returns off
if (p) { if (p) {
*p = 0; *p = 0;
if (strnicmp(cp,"un.",3)) { 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); free(cp);
return 0; return 0;
} }
@ -802,7 +802,7 @@ int CEXEBuild::section_end()
return PS_OK; 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) if (build_cursection_isfunc)
{ {

View file

@ -67,7 +67,7 @@ class CEXEBuild {
// process a script (you can process as many scripts as you want, // process a script (you can process as many scripts as you want,
// it is as if they are concatenated) // 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); int process_oneline(char *line, char *curfilename, int lineptr);
// you only get to call write_output once, so use it wisely. // you only get to call write_output once, so use it wisely.
@ -82,6 +82,10 @@ class CEXEBuild {
int display_warnings; int display_warnings;
int display_info; int display_info;
int linecnt;
char *curfilename;
FILE *fp;
HWND notify_hwnd; HWND notify_hwnd;
void notify(int code, char *data); void notify(int code, char *data);
@ -90,10 +94,10 @@ class CEXEBuild {
int get_commandtoken(char *s, int *np, int *op); int get_commandtoken(char *s, int *np, int *op);
// script.cpp // script.cpp
int parseScript(FILE *fp, const char *curfilename, int *lineptr); int parseScript();
void ps_addtoline(const char *str, GrowBuf &linedata, StringList &hist); void ps_addtoline(const char *str, GrowBuf &linedata, StringList &hist);
int doParse(const char *str, FILE *fp, const char *curfilename, int *lineptr); int doParse(const char *str);
int doCommand(int which_token, LineParser &line, FILE *fp, const char *curfilename, int *lineptr); 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); 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 GrowBuf m_linebuild; // used for concatenating lines
@ -107,7 +111,7 @@ class CEXEBuild {
// build.cpp functions used mostly by script.cpp // build.cpp functions used mostly by script.cpp
int getcurdbsize(); 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 section_end();
int add_function(const char *funname); int add_function(const char *funname);
int function_end(); int function_end();

View file

@ -1,5 +1,3 @@
// Lang.cpp by Amir Szekely 3rd August 2002
#include <Windows.h> #include <Windows.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>

View file

@ -258,14 +258,13 @@ int main(int argc, char **argv)
fprintf(g_output,"\n\nProcessing config: \n"); fprintf(g_output,"\n\nProcessing config: \n");
fflush(g_output); fflush(g_output);
} }
int lc=0; int ret=build.process_script(cfg,exepath);
int ret=build.process_script(cfg,exepath,&lc);
fclose(cfg); fclose(cfg);
if (ret != PS_OK && ret != PS_EOF) if (ret != PS_OK && ret != PS_EOF)
{ {
if (build.display_errors) 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); fflush(g_output);
} }
return 1; return 1;
@ -341,15 +340,14 @@ int main(int argc, char **argv)
fprintf(g_output,"\n\nProcessing script file: \"%s\"\n",sfile); fprintf(g_output,"\n\nProcessing script file: \"%s\"\n",sfile);
fflush(g_output); fflush(g_output);
} }
int lc=0; int ret=build.process_script(fp,sfile);
int ret=build.process_script(fp,sfile,&lc);
if (fp != stdin) fclose(fp); if (fp != stdin) fclose(fp);
if (ret != PS_EOF && ret != PS_OK) if (ret != PS_EOF && ret != PS_OK)
{ {
if (build.display_errors) 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); fflush(g_output);
} }
return 1; return 1;

View file

@ -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"; "$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) if (has_called_write_output)
{ {
ERROR_MSG("Error (process_script): write_output already called, can't continue\n"); ERROR_MSG("Error (process_script): write_output already called, can't continue\n");
return PS_ERROR; return PS_ERROR;
} }
int ret=parseScript(fp,curfilename,lineptr); int ret=parseScript();
if (ret == PS_ENDIF) ERROR_MSG("!endif: stray !endif\n"); if (ret == PS_ENDIF) ERROR_MSG("!endif: stray !endif\n");
if (IS_PS_ELSE(ret)) ERROR_MSG("!else: stray !else\n"); if (IS_PS_ELSE(ret)) ERROR_MSG("!else: stray !else\n");
if (m_linebuild.getlen()) 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; } #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 ignore;
static int last_line_had_slash; 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)
{ {
if (res==-2) ERROR_MSG("Error: unterminated string parsing line at %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,*lineptr); else ERROR_MSG("Error: error parsing line (%s:%d)\n",curfilename,linecnt);
return PS_ERROR; return PS_ERROR;
} }
@ -215,7 +219,7 @@ parse_again:
} }
if (!ignore) if (!ignore)
{ {
return doCommand(tkid,line,fp,curfilename,lineptr); return doCommand(tkid,line);
} }
return PS_OK; 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]; char str[MAX_LINELENGTH];
@ -305,7 +309,7 @@ int CEXEBuild::parseScript(FILE *fp, const char *curfilename, int *lineptr)
char *p=str; char *p=str;
*p=0; *p=0;
fgets(str,MAX_LINELENGTH,fp); fgets(str,MAX_LINELENGTH,fp);
(*lineptr)++; linecnt++;
if (feof(fp)&&!str[0]) break; if (feof(fp)&&!str[0]) break;
// remove trailing whitespace // remove trailing whitespace
@ -318,20 +322,30 @@ int CEXEBuild::parseScript(FILE *fp, const char *curfilename, int *lineptr)
GrowBuf linedata; GrowBuf linedata;
ps_addtoline(str,linedata,hist); ps_addtoline(str,linedata,hist);
linedata.add((void*)"",1); 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; if (ret != PS_OK) return ret;
} }
return PS_EOF; 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; StringList hist;
GrowBuf linedata; GrowBuf linedata;
ps_addtoline(line,linedata,hist); ps_addtoline(line,linedata,hist);
linedata.add((void*)"",1); 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) 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_GET(field) (FIELD_OFFSET(section, field)/sizeof(int))
#define SECTION_FIELD_SET(field) (-1 - (int)(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] = { static const char *rootkeys[2] = {
"HKCR\0HKLM\0HKCU\0HKU\0HKCC\0HKDD\0HKPD\0", "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" "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")) if (!stricmp(l2.gettoken_str(0),"!macroend"))
{ {
(*lineptr)++; linecnt++;
break; break;
} }
if (!stricmp(l2.gettoken_str(0),"!macro")) 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); if (str[0]) m_macros.add(str,strlen(str)+1);
else m_macros.add(" ",2); else m_macros.add(" ",2);
(*lineptr)++; linecnt++;
} }
m_macros.add("",1); m_macros.add("",1);
} }
@ -2074,15 +2086,29 @@ int CEXEBuild::doCommand(int which_token, LineParser &line, FILE *fp, const char
return PS_ERROR; return PS_ERROR;
} }
depth++; 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--; depth--;
fclose(incfp); fclose(incfp);
if (r != PS_EOF && r != PS_OK) if (r != PS_EOF && r != PS_OK)
{ {
if (r == PS_ENDIF) ERROR_MSG("!endif: stray !endif\n"); if (r == PS_ENDIF) ERROR_MSG("!endif: stray !endif\n");
if (IS_PS_ELSE(r)) ERROR_MSG("!else: stray !else\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); if (malloced) free(f);
return PS_ERROR; return PS_ERROR;
} }
@ -2228,8 +2254,8 @@ int CEXEBuild::doCommand(int which_token, LineParser &line, FILE *fp, const char
int ret; int ret;
if (line.gettoken_str(a)[0]=='-') ret=add_section("",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),curfilename,linecnt,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 (ret != PS_OK) return ret;
if (unselected) 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)); 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)); if (line.gettoken_str(a+1)[0]) SCRIPT_MSG(" ->(%s)",line.gettoken_str(a+1));
SCRIPT_MSG("\n"); 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: case TOK_FUNCTION:
if (!line.gettoken_str(1)[0]) PRINTHELP() 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: case TOK_SETCOMPRESS:
build_compress=line.gettoken_enum(1,"off\0auto\0force\0"); build_compress=line.gettoken_enum(1,"off\0auto\0force\0");
if (build_compress==-1) PRINTHELP() 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)); SCRIPT_MSG("SetCompress: %s\n",line.gettoken_str(1));
return PS_OK; return PS_OK;
@ -4465,7 +4491,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line, FILE *fp, const char
} }
SCRIPT_MSG("\n"); SCRIPT_MSG("\n");
if (nounloadmisused) 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 // next, call it
ent.which=EW_REGISTERDLL; ent.which=EW_REGISTERDLL;