Fixed comment handling.
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@4328 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
b8991b1482
commit
174feaed16
3 changed files with 368 additions and 324 deletions
|
@ -50,7 +50,7 @@ CEXEBuild::~CEXEBuild()
|
|||
free(m_unicon_data);
|
||||
|
||||
delete [] m_exehead;
|
||||
|
||||
|
||||
int nlt = lang_tables.getlen() / sizeof(LanguageTable);
|
||||
LanguageTable *nla = (LanguageTable*)lang_tables.get();
|
||||
|
||||
|
@ -224,6 +224,10 @@ CEXEBuild::CEXEBuild() :
|
|||
// Added by Sunil Kamath 11 June 2003
|
||||
definedlist.add("NSIS_SUPPORT_STANDARD_PREDEFINES");
|
||||
#endif
|
||||
#ifdef NSIS_FIX_COMMENT_HANDLING
|
||||
// Added by Sunil Kamath 15 October 2005
|
||||
definedlist.add("NSIS_FIX_COMMENT_HANDLING");
|
||||
#endif
|
||||
|
||||
// no more optional
|
||||
definedlist.add("NSIS_SUPPORT_NAMED_USERVARS");
|
||||
|
@ -403,12 +407,12 @@ definedlist.add("NSIS_SUPPORT_LANG_IN_STRINGS");
|
|||
int i;
|
||||
for (i = 0; i < 10; i++) // 0 - 9
|
||||
{
|
||||
sprintf(Aux, "%d", i);
|
||||
sprintf(Aux, "%d", i);
|
||||
m_UserVarNames.add(Aux,1);
|
||||
}
|
||||
for (i = 0; i < 10; i++) // 10 - 19
|
||||
{
|
||||
sprintf(Aux, "R%d", i);
|
||||
sprintf(Aux, "R%d", i);
|
||||
m_UserVarNames.add(Aux,1);
|
||||
}
|
||||
m_UserVarNames.add("CMDLINE",1); // 20 everything before here doesn't have trailing slash removal
|
||||
|
@ -562,7 +566,7 @@ int CEXEBuild::preprocess_string(char *out, const char *in, WORD codepage/*=CP_A
|
|||
int i = (unsigned char)*p;
|
||||
|
||||
p=np;
|
||||
|
||||
|
||||
// Test for characters extending into the variable codes
|
||||
if (i >= NS_CODES_START) {
|
||||
*out++ = (char)NS_SKIP_CODE;
|
||||
|
@ -589,7 +593,7 @@ int CEXEBuild::preprocess_string(char *out, const char *in, WORD codepage/*=CP_A
|
|||
int idxUserVar = m_UserVarNames.get((char*)p, pUserVarName-p);
|
||||
if (idxUserVar >= 0)
|
||||
{
|
||||
// Well, using variables inside string formating doens't mean
|
||||
// Well, using variables inside string formating doens't mean
|
||||
// using the variable, beacuse it will be always an empty string
|
||||
// which is also memory wasting
|
||||
// So the line below must be commented !??
|
||||
|
@ -632,7 +636,7 @@ int CEXEBuild::preprocess_string(char *out, const char *in, WORD codepage/*=CP_A
|
|||
int idx = -1;
|
||||
char *cp = strdup(p+1);
|
||||
char *pos = strchr(cp, ')');
|
||||
if (pos)
|
||||
if (pos)
|
||||
{
|
||||
*pos = 0;
|
||||
idx = DefineLangString(cp);
|
||||
|
@ -645,7 +649,7 @@ int CEXEBuild::preprocess_string(char *out, const char *in, WORD codepage/*=CP_A
|
|||
bProceced = true;
|
||||
}
|
||||
}
|
||||
free(cp);
|
||||
free(cp);
|
||||
}
|
||||
if ( bProceced )
|
||||
continue;
|
||||
|
@ -661,10 +665,10 @@ int CEXEBuild::preprocess_string(char *out, const char *in, WORD codepage/*=CP_A
|
|||
cBracket = ')';
|
||||
else if ( *p == '{' )
|
||||
cBracket = '}';
|
||||
|
||||
|
||||
strncpy(tbuf,p,63);
|
||||
tbuf[63]=0;
|
||||
|
||||
|
||||
if ( cBracket != 0 )
|
||||
{
|
||||
if (strchr(tbuf,cBracket)) (strchr(tbuf,cBracket)+1)[0]=0;
|
||||
|
@ -801,7 +805,7 @@ int CEXEBuild::add_db_data(IMMap *mmap) // returns offset
|
|||
{
|
||||
int in_len = min(build_filebuflen, avail_in);
|
||||
int out_len = min(build_filebuflen, avail_out);
|
||||
|
||||
|
||||
compressor->SetNextIn((char *) mmap->get(length - avail_in, in_len), in_len);
|
||||
compressor->SetNextOut((char *) db->get(st + sizeof(int) + bufferlen - avail_out, out_len), out_len);
|
||||
if ((ret = compressor->Compress(0)) < 0)
|
||||
|
@ -1691,7 +1695,7 @@ int CEXEBuild::AddVersionInfo()
|
|||
{
|
||||
int imm, iml, ilm, ill;
|
||||
if ( sscanf(version_product_v, "%d.%d.%d.%d", &imm, &iml, &ilm, &ill) != 4 )
|
||||
{
|
||||
{
|
||||
ERROR_MSG("Error: invalid VIProductVersion format, should be X.X.X.X\n");
|
||||
return PS_ERROR;
|
||||
}
|
||||
|
@ -1717,7 +1721,7 @@ int CEXEBuild::AddVersionInfo()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return PS_OK;
|
||||
}
|
||||
#endif // NSIS_SUPPORT_VERSION_INFO
|
||||
|
@ -1798,7 +1802,7 @@ again:
|
|||
{
|
||||
int i = 0;
|
||||
page *p = (page *) cur_pages->get();
|
||||
|
||||
|
||||
for (i = 0; i < cur_header->blocks[NB_PAGES].num; i++, p++) {
|
||||
page *pp = 0;
|
||||
|
||||
|
@ -2261,7 +2265,7 @@ int CEXEBuild::prepare_uninstaller() {
|
|||
DefineInnerLangString(NLF_UCAPTION);
|
||||
if (resolve_coderefs("uninstall"))
|
||||
return PS_ERROR;
|
||||
#ifdef NSIS_CONFIG_COMPONENTPAGE
|
||||
#ifdef NSIS_CONFIG_COMPONENTPAGE
|
||||
// set sections to the first insttype
|
||||
PrepareInstTypes();
|
||||
#endif
|
||||
|
@ -2470,7 +2474,7 @@ int CEXEBuild::write_output(void)
|
|||
return PS_ERROR;
|
||||
}
|
||||
}
|
||||
else
|
||||
else
|
||||
#endif
|
||||
{
|
||||
if (fwrite(ihd.get(),1,ihd.getlen(),fp) != (unsigned int)ihd.getlen())
|
||||
|
@ -2625,7 +2629,7 @@ int CEXEBuild::write_output(void)
|
|||
return PS_ERROR;
|
||||
}
|
||||
}
|
||||
else
|
||||
else
|
||||
#endif
|
||||
{
|
||||
#ifdef NSIS_CONFIG_CRC_SUPPORT
|
||||
|
@ -2646,7 +2650,7 @@ int CEXEBuild::write_output(void)
|
|||
build_datablock.clear();
|
||||
}
|
||||
#ifdef NSIS_CONFIG_COMPRESSION_SUPPORT
|
||||
if (build_compress_whole)
|
||||
if (build_compress_whole)
|
||||
{
|
||||
if (deflateToFile(fp,NULL,0))
|
||||
{
|
||||
|
@ -3281,14 +3285,14 @@ int CEXEBuild::DeclaredUserVar(const char *szVarName)
|
|||
if (m_ShellConstants.get((char*)szVarName) >= 0)
|
||||
{
|
||||
ERROR_MSG("Error: name \"%s\" in use by constant\n", szVarName);
|
||||
return PS_ERROR;
|
||||
return PS_ERROR;
|
||||
}
|
||||
|
||||
int idxUserVar = m_UserVarNames.get((char*)szVarName);
|
||||
if (idxUserVar >= 0)
|
||||
{
|
||||
ERROR_MSG("Error: variable \"%s\" already declared\n", szVarName);
|
||||
return PS_ERROR;
|
||||
return PS_ERROR;
|
||||
}
|
||||
const char *pVarName = szVarName;
|
||||
int iVarLen = strlen(szVarName);
|
||||
|
@ -3354,9 +3358,9 @@ void CEXEBuild::VerifyDeclaredUserVarRefs(UserVarsStringList *pVarsStringList)
|
|||
for (int i = m_iBaseVarsNum; i < pVarsStringList->getnum(); i++)
|
||||
{
|
||||
if (!pVarsStringList->get_reference(i))
|
||||
{
|
||||
{
|
||||
warning("Variable \"%s\" not referenced, wasting memory!", pVarsStringList->idx2name(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,12 +27,12 @@ int LineParser::parse(char *line, int ignore_escaping/*=0*/) // returns -1 on er
|
|||
bool bPrevCB=m_bCommentBlock;
|
||||
int n=doline(line, ignore_escaping);
|
||||
if (n) return n;
|
||||
if (m_nt)
|
||||
if (m_nt)
|
||||
{
|
||||
m_bCommentBlock=bPrevCB;
|
||||
m_tokens=(char**)malloc(sizeof(char*)*m_nt);
|
||||
n=doline(line, ignore_escaping);
|
||||
if (n)
|
||||
if (n)
|
||||
{
|
||||
freetokens();
|
||||
return -1;
|
||||
|
@ -54,7 +54,7 @@ void LineParser::eattoken()
|
|||
double LineParser::gettoken_float(int token, int *success/*=0*/)
|
||||
{
|
||||
token+=m_eat;
|
||||
if (token < 0 || token >= m_nt)
|
||||
if (token < 0 || token >= m_nt)
|
||||
{
|
||||
if (success) *success=0;
|
||||
return 0.0;
|
||||
|
@ -63,7 +63,7 @@ double LineParser::gettoken_float(int token, int *success/*=0*/)
|
|||
{
|
||||
char *t=m_tokens[token];
|
||||
*success=*t?1:0;
|
||||
while (*t)
|
||||
while (*t)
|
||||
{
|
||||
if ((*t < '0' || *t > '9')&&*t != '.') *success=0;
|
||||
t++;
|
||||
|
@ -72,10 +72,10 @@ double LineParser::gettoken_float(int token, int *success/*=0*/)
|
|||
return atof(m_tokens[token]);
|
||||
}
|
||||
|
||||
int LineParser::gettoken_int(int token, int *success/*=0*/)
|
||||
{
|
||||
int LineParser::gettoken_int(int token, int *success/*=0*/)
|
||||
{
|
||||
token+=m_eat;
|
||||
if (token < 0 || token >= m_nt || !m_tokens[token][0])
|
||||
if (token < 0 || token >= m_nt || !m_tokens[token][0])
|
||||
{
|
||||
if (success) *success=0;
|
||||
return 0;
|
||||
|
@ -88,11 +88,11 @@ int LineParser::gettoken_int(int token, int *success/*=0*/)
|
|||
return l;
|
||||
}
|
||||
|
||||
char* LineParser::gettoken_str(int token)
|
||||
{
|
||||
char* LineParser::gettoken_str(int token)
|
||||
{
|
||||
token+=m_eat;
|
||||
if (token < 0 || token >= m_nt) return "";
|
||||
return m_tokens[token];
|
||||
return m_tokens[token];
|
||||
}
|
||||
|
||||
int LineParser::gettoken_enum(int token, const char *strlist) // null seperated list
|
||||
|
@ -124,6 +124,7 @@ void LineParser::freetokens()
|
|||
int LineParser::doline(char *line, int ignore_escaping/*=0*/)
|
||||
{
|
||||
m_nt=0;
|
||||
#ifndef NSIS_FIX_COMMENT_HANDLING
|
||||
if ( m_bCommentBlock )
|
||||
{
|
||||
while ( *line )
|
||||
|
@ -137,66 +138,96 @@ int LineParser::doline(char *line, int ignore_escaping/*=0*/)
|
|||
line++;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
while (*line == ' ' || *line == '\t') line++;
|
||||
while (*line)
|
||||
while (*line)
|
||||
{
|
||||
int lstate=0; // 1=", 2=`, 4='
|
||||
if (*line == ';' || *line == '#') break;
|
||||
if (*line == '/' && *(line+1) == '*')
|
||||
#ifdef NSIS_FIX_COMMENT_HANDLING
|
||||
if ( m_bCommentBlock )
|
||||
{
|
||||
m_bCommentBlock = true;
|
||||
line+=2;
|
||||
return doline(line, ignore_escaping);
|
||||
}
|
||||
if (*line == '\"') lstate=1;
|
||||
else if (*line == '\'') lstate=2;
|
||||
else if (*line == '`') lstate=4;
|
||||
if (lstate) line++;
|
||||
int nc=0;
|
||||
char *p = line;
|
||||
while (*line)
|
||||
{
|
||||
if (line[0] == '$' && line[1] == '\\') {
|
||||
switch (line[2]) {
|
||||
case '"':
|
||||
case '\'':
|
||||
case '`':
|
||||
nc += ignore_escaping ? 3 : 1;
|
||||
line += 3;
|
||||
continue;
|
||||
while ( *line )
|
||||
{
|
||||
if ( *line == '*' && *(line+1) == '/' )
|
||||
{
|
||||
m_bCommentBlock=false; // Found end of comment block
|
||||
line+=2;
|
||||
while (*line == ' ' || *line == '\t') line++;
|
||||
break;
|
||||
}
|
||||
else line++;
|
||||
}
|
||||
if (lstate==1 && *line =='\"') break;
|
||||
if (lstate==2 && *line =='\'') break;
|
||||
if (lstate==4 && *line =='`') break;
|
||||
if (!lstate && (*line == ' ' || *line == '\t')) break;
|
||||
line++;
|
||||
nc++;
|
||||
}
|
||||
if (m_tokens)
|
||||
{
|
||||
int i;
|
||||
m_tokens[m_nt]=(char*)malloc(nc+1);
|
||||
for (i = 0; p < line; i++, p++) {
|
||||
if (!ignore_escaping && p[0] == '$' && p[1] == '\\') {
|
||||
switch (p[2]) {
|
||||
case '"':
|
||||
case '\'':
|
||||
case '`':
|
||||
p += 2;
|
||||
else {
|
||||
#endif
|
||||
int lstate=0; // 1=", 2=`, 4='
|
||||
if (*line == ';' || *line == '#') break;
|
||||
if (*line == '/' && *(line+1) == '*')
|
||||
{
|
||||
m_bCommentBlock = true;
|
||||
line+=2;
|
||||
#ifndef NSIS_FIX_COMMENT_HANDLING
|
||||
return doline(line, ignore_escaping);
|
||||
#endif
|
||||
}
|
||||
#ifdef NSIS_FIX_COMMENT_HANDLING
|
||||
else {
|
||||
#endif
|
||||
if (*line == '\"') lstate=1;
|
||||
else if (*line == '\'') lstate=2;
|
||||
else if (*line == '`') lstate=4;
|
||||
if (lstate) line++;
|
||||
int nc=0;
|
||||
char *p = line;
|
||||
while (*line)
|
||||
{
|
||||
if (line[0] == '$' && line[1] == '\\') {
|
||||
switch (line[2]) {
|
||||
case '"':
|
||||
case '\'':
|
||||
case '`':
|
||||
nc += ignore_escaping ? 3 : 1;
|
||||
line += 3;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (lstate==1 && *line =='\"') break;
|
||||
if (lstate==2 && *line =='\'') break;
|
||||
if (lstate==4 && *line =='`') break;
|
||||
if (!lstate && (*line == ' ' || *line == '\t')) break;
|
||||
#ifdef NSIS_FIX_COMMENT_HANDLING
|
||||
if (!lstate && (*line == ';' || *line == '#' || (*line == '/' && *(line+1) == '*'))) break;
|
||||
#endif
|
||||
line++;
|
||||
nc++;
|
||||
}
|
||||
m_tokens[m_nt][i] = *p;
|
||||
if (m_tokens)
|
||||
{
|
||||
int i;
|
||||
m_tokens[m_nt]=(char*)malloc(nc+1);
|
||||
for (i = 0; p < line; i++, p++) {
|
||||
if (!ignore_escaping && p[0] == '$' && p[1] == '\\') {
|
||||
switch (p[2]) {
|
||||
case '"':
|
||||
case '\'':
|
||||
case '`':
|
||||
p += 2;
|
||||
}
|
||||
}
|
||||
m_tokens[m_nt][i] = *p;
|
||||
}
|
||||
m_tokens[m_nt][nc]=0;
|
||||
}
|
||||
m_nt++;
|
||||
if (lstate)
|
||||
{
|
||||
if (*line) line++;
|
||||
else return -2;
|
||||
}
|
||||
while (*line == ' ' || *line == '\t') line++;
|
||||
#ifdef NSIS_FIX_COMMENT_HANDLING
|
||||
}
|
||||
m_tokens[m_nt][nc]=0;
|
||||
}
|
||||
m_nt++;
|
||||
if (lstate)
|
||||
{
|
||||
if (*line) line++;
|
||||
else return -2;
|
||||
}
|
||||
while (*line == ' ' || *line == '\t') line++;
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue