From b1be97444715fa7ed7b3864a987c61ff25118e73 Mon Sep 17 00:00:00 2001 From: kichik Date: Sat, 3 Dec 2005 09:45:17 +0000 Subject: [PATCH] applied patch #1372048 - added /NONFATAL switch to !include statement git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@4437 212acab6-be3b-0410-9dea-997c60f758d6 --- Docs/src/compiler.but | 7 ++++--- Source/Tests/preprocessor.nsi | 14 ++++++++++++++ Source/script.cpp | 21 +++++++++++++++++++-- Source/tokens.cpp | 2 +- 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/Docs/src/compiler.but b/Docs/src/compiler.but index a4fb4311..c908e054 100644 --- a/Docs/src/compiler.but +++ b/Docs/src/compiler.but @@ -6,14 +6,15 @@ These commands are similar to the C preprocessor in terms of purpose and functio \S1{include} !include -\c file +\c [/NONFATAL] file -This command will include 'file' as if it was part of the original script. Note that if a file is included in another directory, the current directory is still where the script was compiled from (not where the included file resides). If the compiler can't find the file it will look for it in every include directory. See \R{addincludedir}{!addincludedir} for more information. +This command will include 'file' as if it was part of the original script. Note that if a file is included in another directory, the current directory is still where the script was compiled from (not where the included file resides). If the compiler can't find the file it will look for it in every include directory. See \R{addincludedir}{!addincludedir} for more information. If the /nonfatal switch is used and no files are found, a warning will be issued instead of an error. \c !include WinMessages.nsh \c !include Library.nsh -\c !include MyConfig.nsh +\c !include C:\MyConfig.nsi \c !include ..\MyConfig.nsh +\c !include /NONFATAL file_that_may_exist_or_not.nsh \S1{addincludedir} !addincludedir diff --git a/Source/Tests/preprocessor.nsi b/Source/Tests/preprocessor.nsi index 6a11ceb4..cfcc6ef1 100644 --- a/Source/Tests/preprocessor.nsi +++ b/Source/Tests/preprocessor.nsi @@ -1,3 +1,6 @@ +!ifndef file_is_included +!define file_is_included + Name preprocessor OutFile preprocessor.exe @@ -48,5 +51,16 @@ d\ i\ f +# this should just give a warning, not an error +!include /NONFATAL file_that_doesnt_exist.nsh + +# this should include this file just one time. +!include preprocessor.nsi + Section SectionEnd + +!else +# this should just give a warning, not an error +!include /NONFATAL another_file_that_doesnt_exist.nsh +!endif diff --git a/Source/script.cpp b/Source/script.cpp index ec42fd98..b0577c90 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -2745,7 +2745,20 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) return PS_OK; case TOK_P_INCLUDE: { + bool required = true; + char *f = line.gettoken_str(1); + + if(!stricmp(f,"/nonfatal")) { + if (line.getnumtokens()!=3) + PRINTHELP(); + + f = line.gettoken_str(2); + required = false; + } else if (line.getnumtokens()!=2) { + PRINTHELP(); + } + #ifdef _WIN32 char *fc = f; #else @@ -2820,8 +2833,12 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) // nothing found if (!included) { - ERROR_MSG("!include: could not find: \"%s\"\n",f); - return PS_ERROR; + if(required) { + ERROR_MSG("!include: could not find: \"%s\"\n",f); + return PS_ERROR; + } else { + warning_fl("!include: could not find: \"%s\"",f); + } } } return PS_OK; diff --git a/Source/tokens.cpp b/Source/tokens.cpp index 904495f2..b2a2cef7 100644 --- a/Source/tokens.cpp +++ b/Source/tokens.cpp @@ -222,7 +222,7 @@ static tokenType tokenlist[TOK__LAST] = {TOK_P_SYSTEMEXEC,"!system",1,2,"command [<|>|<>|=) retval]",TP_ALL}, {TOK_P_EXECUTE,"!execute",1,0,"command",TP_ALL}, {TOK_P_ADDINCLUDEDIR,"!AddIncludeDir",1,0,"dir",TP_ALL}, -{TOK_P_INCLUDE,"!include",1,0,"filename.nsi",TP_ALL}, +{TOK_P_INCLUDE,"!include",1,1,"[/NONFATAL] filename.nsh",TP_ALL}, {TOK_P_CD,"!cd",1,0,"absolute_or_relative_new_directory",TP_ALL}, {TOK_P_IFDEF,"!ifdef",1,-1,"symbol [| symbol2 [& symbol3 [...]]]",TP_ALL}, {TOK_P_IFNDEF,"!ifndef",1,-1,"symbol [| symbol2 [& symbol3 [...]]]",TP_ALL},