From bff435f1069676975c2ca48e00a5d2aac7911a62 Mon Sep 17 00:00:00 2001 From: kichik Date: Sat, 27 Jan 2007 15:32:04 +0000 Subject: [PATCH] applied patch #1644712 - new compiler predefines git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@4906 212acab6-be3b-0410-9dea-997c60f758d6 --- Source/build.cpp | 57 +++++++++++++++++++++--- Source/build.h | 11 +++++ Source/tokens.cpp | 107 +++++++++++++++++++++++----------------------- 3 files changed, 115 insertions(+), 60 deletions(-) diff --git a/Source/build.cpp b/Source/build.cpp index 4e23bd80..d7432f28 100644 --- a/Source/build.cpp +++ b/Source/build.cpp @@ -338,6 +338,8 @@ CEXEBuild::CEXEBuild() : m_ShellConstants.add("RESOURCES", CSIDL_RESOURCES, CSIDL_RESOURCES); m_ShellConstants.add("RESOURCES_LOCALIZED", CSIDL_RESOURCES_LOCALIZED, CSIDL_RESOURCES_LOCALIZED); m_ShellConstants.add("CDBURN_AREA", CSIDL_CDBURN_AREA, CSIDL_CDBURN_AREA); + + set_code_type_predefines(); } void CEXEBuild::initialize(const char *makensis_path) @@ -937,10 +939,10 @@ int CEXEBuild::add_function(const char *funname) for (x = 0; x < n; x ++) { if (tmp[x].name_ptr == addr) - { - ERROR_MSG("Error: Function named \"%s\" already exists.\n",funname); - return PS_ERROR; - } + { + ERROR_MSG("Error: Function named \"%s\" already exists.\n",funname); + return PS_ERROR; + } } cur_functions->resize((n+1)*sizeof(section)); @@ -953,6 +955,12 @@ int CEXEBuild::add_function(const char *funname) build_cursection->flags=0; build_cursection->size_kb=0; memset(build_cursection->name,0,sizeof(build_cursection->name)); + + if (uninstall_mode) + set_code_type_predefines(funname+3); + else + set_code_type_predefines(funname); + return PS_OK; } @@ -970,6 +978,8 @@ int CEXEBuild::function_end() build_cursection=NULL; set_uninstall_mode(0); + + set_code_type_predefines(); return PS_OK; } @@ -1023,6 +1033,8 @@ int CEXEBuild::section_end() build_cursection=NULL; if (!sectiongroup_open_cnt) set_uninstall_mode(0); + + set_code_type_predefines(); return PS_OK; } @@ -1146,7 +1158,9 @@ int CEXEBuild::add_section(const char *secname, const char *defname, int expand/ else sectiongroup_open_cnt++; } - + + set_code_type_predefines(name); + return PS_OK; } @@ -1560,7 +1574,8 @@ int CEXEBuild::add_page(int type) cur_page = (page *)cur_pages->get() + cur_header->blocks[NB_PAGES].num++; cur_page_type = type; - + + set_code_type_predefines(); return PS_OK; } @@ -1568,6 +1583,7 @@ int CEXEBuild::page_end() { cur_page = 0; + set_code_type_predefines(); return PS_OK; } #endif @@ -3388,3 +3404,32 @@ void CEXEBuild::update_exehead(const unsigned char *new_exehead, size_t new_size memset(m_exehead + new_size, 0, m_exehead_size - new_size); } +void CEXEBuild::set_code_type_predefines(const char *value) +{ + definedlist.del("__SECTION__"); + definedlist.del("__FUNCTION__"); + definedlist.del("__PAGEEX__"); + definedlist.del("__GLOBAL__"); + definedlist.del("__UNINSTALL__"); + + switch (GetCurrentTokenPlace()) + { + case TP_SEC: + definedlist.add("__SECTION__", value==NULL?"":value); + break; + case TP_FUNC: + definedlist.add("__FUNCTION__", value==NULL?"":value); + break; + case TP_PAGEEX: + definedlist.add("__PAGEEX__"); + break; + default: + definedlist.add("__GLOBAL__"); + } + + if (uninstall_mode) + { + definedlist.add("__UNINSTALL__"); + } +} + diff --git a/Source/build.h b/Source/build.h index a1c8f1a6..042966c6 100644 --- a/Source/build.h +++ b/Source/build.h @@ -57,6 +57,15 @@ #define PS_ERROR 50 #define PS_WARNING 100 +// token placement +#define TP_SEC 1 +#define TP_FUNC 2 +#define TP_CODE (TP_SEC | TP_FUNC) +#define TP_GLOBAL 4 +#define TP_PAGEEX 8 +#define TP_PG (TP_GLOBAL | TP_PAGEEX) +#define TP_ALL (TP_CODE | TP_PG) + enum notify_e { MAKENSIS_NOTIFY_SCRIPT, MAKENSIS_NOTIFY_WARNING, @@ -132,6 +141,7 @@ class CEXEBuild { // tokens.cpp int get_commandtoken(char *s, int *np, int *op, int *pos); + int GetCurrentTokenPlace(); int IsTokenPlacedRight(int pos, char *tok); // script.cpp @@ -195,6 +205,7 @@ class CEXEBuild { #endif //NSIS_CONFIG_PLUGIN_SUPPORT // build.cpp functions used mostly by script.cpp + void set_code_type_predefines(const char *value = NULL); int getcurdbsize(); int add_section(const char *secname, const char *defname, int expand=0); int section_end(); diff --git a/Source/tokens.cpp b/Source/tokens.cpp index b6b7a588..512d80e7 100644 --- a/Source/tokens.cpp +++ b/Source/tokens.cpp @@ -21,15 +21,6 @@ #include "build.h" #include "tokens.h" -// token placement -#define TP_SEC 1 -#define TP_FUNC 2 -#define TP_CODE (TP_SEC | TP_FUNC) -#define TP_GLOBAL 4 -#define TP_PAGEEX 8 -#define TP_PG (TP_GLOBAL | TP_PAGEEX) -#define TP_ALL (TP_CODE | TP_PG) - typedef struct { int id; @@ -320,69 +311,77 @@ int CEXEBuild::get_commandtoken(char *s, int *np, int *op, int *pos) return -1; } +int CEXEBuild::GetCurrentTokenPlace() +{ + if (build_cursection) + { + if (build_cursection_isfunc) + { + return TP_FUNC; + } + else + { + return TP_SEC; + } + } + + if (cur_page) + return TP_PAGEEX; + + return TP_GLOBAL; +} + int CEXEBuild::IsTokenPlacedRight(int pos, char *tok) { if ((unsigned int) pos > (sizeof(tokenlist) / sizeof(tokenType))) return PS_OK; int tp = tokenlist[pos].placement; - if (build_cursection && !build_cursection_isfunc) - { - // section - if (tp & TP_SEC) - return PS_OK; - ERROR_MSG("Error: command %s not valid in section\n", tok); - return PS_ERROR; + int cp = GetCurrentTokenPlace(); + if (tp & cp) { + return PS_OK; } - else if (build_cursection && build_cursection_isfunc) - { - // function - if (tp & TP_FUNC) - return PS_OK; - ERROR_MSG("Error: command %s not valid in function\n", tok); - return PS_ERROR; - } - else if (cur_page) - { - // pageex - if (tp & TP_PAGEEX) - return PS_OK; - ERROR_MSG("Error: command %s not valid in PageEx\n", tok); - return PS_ERROR; - } - else - { - // global - if (tp & TP_GLOBAL) - return PS_OK; + else { char err[1024]; - strcpy(err, "Error: command %s not valid outside "); - if (tp & TP_SEC) - strcat(err, "section"); - if (tp & TP_FUNC) + if (cp == TP_SEC) { + strcpy(err, "Error: command %s not valid in Section\n"); + } + else if (cp == TP_FUNC) { + strcpy(err, "Error: command %s not valid in Function\n"); + } + else if (cp == TP_PAGEEX) { + strcpy(err, "Error: command %s not valid in PageEx\n"); + } + else { + strcpy(err, "Error: command %s not valid outside "); if (tp & TP_SEC) + strcat(err, "Section"); + if (tp & TP_FUNC) { - if (tp & TP_PAGEEX) + if (tp & TP_SEC) { - strcat(err, ", "); + if (tp & TP_PAGEEX) + { + strcat(err, ", "); + } + else + { + strcat(err, " or "); + } } - else + strcat(err, "Function"); + } + if (tp & TP_PAGEEX) + { + if (tp & TP_CODE) { strcat(err, " or "); } + strcat(err, "PageEx"); } - strcat(err, "function"); + strcat(err, "\n"); } - if (tp & TP_PAGEEX) - { - if (tp & TP_CODE) - { - strcat(err, " or "); - } - strcat(err, "PageEx"); - } - strcat(err, "\n"); ERROR_MSG(err, tok); return PS_ERROR; }