From d6d4da1baeeb19cefa84033e73e8ebe1a4e3ed56 Mon Sep 17 00:00:00 2001 From: anders_k Date: Thu, 26 Feb 2015 18:19:37 +0000 Subject: [PATCH] Added !appendfile /RawNL switch git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6580 212acab6-be3b-0410-9dea-997c60f758d6 --- Docs/src/compiler.but | 4 ++-- Docs/src/history.but | 10 ++++------ Source/script.cpp | 26 +++++++++++++++++--------- Source/tokens.cpp | 2 +- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/Docs/src/compiler.but b/Docs/src/compiler.but index 77e33495..dd69d215 100644 --- a/Docs/src/compiler.but +++ b/Docs/src/compiler.but @@ -40,9 +40,9 @@ Causes the NSIS compiler to scan the given directory for plug-in DLLs. If you do \# NOTE: \NsisOutputCharset define cannot be used in a \c block -\c [/CHARSET=ACP|OEM|CP#|UTF8[SIG]|UTF16[BOM]] file text +\c [/CHARSET=ACP|OEM|CP#|UTF8[SIG]|UTF16[BOM]] [/RawNL] file text -Appends \e{text} to \e{file}. The text is written as ANSI (ACP) unless the file already has a BOM. Using /CHARSET will force a specific character encoding. +Appends \e{text} to \e{file}. The text is written as ANSI (ACP) unless the file already has a BOM. Using /CHARSET will force a specific character encoding. \c{$\\n} will be translated to \c{$\\r$\\n} on Windows unless you specify /RawNL. \c !tempfile FILE \c !appendfile "${FILE}" "XPStyle on$\n" diff --git a/Docs/src/history.but b/Docs/src/history.but index 5fa11c17..59d206ce 100644 --- a/Docs/src/history.but +++ b/Docs/src/history.but @@ -12,13 +12,11 @@ Released on ?, 201? \S2{} Minor Changes +\b Added !appendfile /RawNL switch + \b Exec[Wait] sets the CREATE_DEFAULT_ERROR_MODE flag when creating a process -\b Fixed minor issues in the Pascal NSIS plug-in SDK and removed the extrap global variable - -\S1{v3.0b2-cl} Changelog - -\S2{} Minor Changes +\b Fixed minor issues in the Pascal NSIS plug-in SDK and removed the \cw{extrap} global variable \b Windows 10 support @@ -40,7 +38,7 @@ Released on October 6th, 2014 \b Added new MUI2 bitmap stretch modes, *_NOSTRETCH is now deprecated (\W{http://sf.net/p/nsis/feature-requests/521}{RFE #521}) -\b InitiateShutdown is used to reboot the machine if available (\W{http://sf.net/p/nsis/patches/247}{patch #247}) +\b \c{InitiateShutdown()} is used to reboot the machine if available (\W{http://sf.net/p/nsis/patches/247}{patch #247}) \b Added PPO and SafePPO preprocess-only compiler switches diff --git a/Source/script.cpp b/Source/script.cpp index f2c7cc39..42f6150f 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -1407,18 +1407,25 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) case TOK_P_APPENDFILE: { WORD tok = 0, cp = 0; - bool bom = false, forceEnc = false; - TCHAR *param = line.gettoken_str(++tok), buf[9+1]; - my_strncpy(buf,param,COUNTOF(buf)); - if(!_tcsicmp(buf,_T("/charset="))) + bool bom = false, forceEnc = false, rawnl = false; + TCHAR *param, buf[9+!0]; + for (;;) { - ++tok, ++forceEnc, cp = GetEncodingFromString(param+9, bom); - if (NStreamEncoding::UNKNOWN == cp) + param = line.gettoken_str(++tok); + my_strncpy(buf, param, COUNTOF(buf)); + if (!_tcsicmp(param,_T("/RawNL"))) ++rawnl; + else if(!_tcsicmp(buf,_T("/CharSet="))) { - ERROR_MSG(_T("!appendfile: Invalid parameter \"%") NPRIs _T("\"!\n"), param); - return PS_ERROR; + ++forceEnc, cp = GetEncodingFromString(param+9, bom); + if (NStreamEncoding::UNKNOWN == cp) + { + ERROR_MSG(_T("!appendfile: Invalid parameter \"%") NPRIs _T("\"!\n"), param); + return PS_ERROR; + } } + else break; } + if (line.getnumtokens() != 2 + tok) { PRINTHELP(); return PS_ERROR; } param = line.gettoken_str(tok); NOStream ostrm; if (!ostrm.CreateFileForAppending(param, NStreamEncoding::ACP)) @@ -1429,7 +1436,8 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (ostrm.IsUnicode()) bom = false; if (forceEnc) ostrm.StreamEncoding().SetCodepage(cp); const TCHAR *const text = line.gettoken_str(++tok); - if ((bom ? !ostrm.WriteBOM(ostrm.StreamEncoding()) : 0) || !ostrm.WriteString(text)) + bool succ = bom ? ostrm.WriteBOM(ostrm.StreamEncoding()) : true; + if (!succ || rawnl ? !ostrm.WriteString(text) : !ostrm.WritePlatformNLString(text)) { ERROR_MSG(_T("!appendfile: error writing to \"%") NPRIs _T("\".\n"), param); return PS_ERROR; diff --git a/Source/tokens.cpp b/Source/tokens.cpp index 7cf60032..acac9551 100644 --- a/Source/tokens.cpp +++ b/Source/tokens.cpp @@ -273,7 +273,7 @@ static tokenType tokenlist[TOK__LAST] = {TOK_P_TEMPFILE,_T("!tempfile"),1,0,_T("symbol"),TP_ALL}, {TOK_P_DELFILE,_T("!delfile"),1,1,_T("[/nonfatal] file"),TP_ALL}, -{TOK_P_APPENDFILE,_T("!appendfile"),2,1,_T("[/CHARSET=<") TSTR_OUTPUTCHARSET _T(">] file appended_line"),TP_ALL}, +{TOK_P_APPENDFILE,_T("!appendfile"),2,2,_T("[/CHARSET=<") TSTR_OUTPUTCHARSET _T(">] [/RAWNL] file appended_line"),TP_ALL}, {TOK_P_GETDLLVERSION,_T("!getdllversion"),2,0,_T("localfilename define_basename"),TP_ALL}, {TOK_P_SEARCHPARSESTRING,_T("!searchparse"),3,-1,_T("[/ignorecase] [/noerrors] [/file] source_string substring OUTPUTSYM1 [substring [OUTPUTSYM2 [substring ...]]]"),TP_ALL},