refactoring

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@3680 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2004-09-30 18:48:03 +00:00
parent 2da10af05b
commit efcb38d737
3 changed files with 75 additions and 58 deletions

View file

@ -2141,7 +2141,7 @@ again:
#endif // NSIS_CONFIG_VISIBLE_SUPPORT #endif // NSIS_CONFIG_VISIBLE_SUPPORT
#ifdef NSIS_CONFIG_COMPONENTPAGE #ifdef NSIS_CONFIG_COMPONENTPAGE
void CEXEBuild::PreperInstTypes() void CEXEBuild::PrepareInstTypes()
{ {
if (!(cur_header->flags & CH_FLAGS_NO_CUSTOM)) if (!(cur_header->flags & CH_FLAGS_NO_CUSTOM))
cur_header->install_types[NSIS_MAX_INST_TYPES] = DefineInnerLangString(NLF_COMP_CUSTOM); cur_header->install_types[NSIS_MAX_INST_TYPES] = DefineInnerLangString(NLF_COMP_CUSTOM);
@ -2176,7 +2176,7 @@ void CEXEBuild::PreperInstTypes()
} }
#endif #endif
void CEXEBuild::PreperHeaders(IGrowBuf *hdrbuf) void CEXEBuild::PrepareHeaders(IGrowBuf *hdrbuf)
{ {
hdrbuf->add(cur_header,sizeof(header)); hdrbuf->add(cur_header,sizeof(header));
#ifdef NSIS_CONFIG_VISIBLE_SUPPORT #ifdef NSIS_CONFIG_VISIBLE_SUPPORT
@ -2205,17 +2205,14 @@ void CEXEBuild::PreperHeaders(IGrowBuf *hdrbuf)
memcpy(hdrbuf->get(),cur_header,sizeof(header)); memcpy(hdrbuf->get(),cur_header,sizeof(header));
} }
int CEXEBuild::write_output(void) int CEXEBuild::check_write_output_errors() const
{ {
#ifndef NSIS_CONFIG_CRC_SUPPORT
build_crcchk=0;
#endif
if (has_called_write_output) if (has_called_write_output)
{ {
ERROR_MSG("Error (write_output): write_output already called, can't continue\n"); ERROR_MSG("Error (write_output): write_output already called, can't continue\n");
return PS_ERROR; return PS_ERROR;
} }
has_called_write_output++;
if (!build_output_filename[0]) if (!build_output_filename[0])
{ {
ERROR_MSG("Error: invalid script: never had OutFile command\n"); ERROR_MSG("Error: invalid script: never had OutFile command\n");
@ -2252,18 +2249,33 @@ int CEXEBuild::write_output(void)
if (cur_page) if (cur_page)
{ {
ERROR_MSG("Error: PageEx still open at EOF, cannot proceed\n"); ERROR_MSG("Error: PageEx still open at EOF, cannot proceed\n");
return 1; return PS_ERROR;
} }
// deal with functions, for both install and uninstall modes. // deal with functions, for both install and uninstall modes.
if (build_cursection_isfunc) if (build_cursection_isfunc)
{ {
ERROR_MSG("Error: Function still open at EOF, cannot proceed\n"); ERROR_MSG("Error: Function still open at EOF, cannot proceed\n");
return 1; return PS_ERROR;
} }
return PS_OK;
}
int CEXEBuild::write_output(void)
{
#ifndef NSIS_CONFIG_CRC_SUPPORT
build_crcchk=0;
#endif
int err; int err;
err = check_write_output_errors();
if (err != PS_OK)
return err;
has_called_write_output++;
#ifdef NSIS_CONFIG_PLUGIN_SUPPORT #ifdef NSIS_CONFIG_PLUGIN_SUPPORT
err = add_plugins_dir_initializer(); err = add_plugins_dir_initializer();
if (err != PS_OK) if (err != PS_OK)
@ -2293,7 +2305,7 @@ int CEXEBuild::write_output(void)
return PS_ERROR; return PS_ERROR;
#ifdef NSIS_CONFIG_COMPONENTPAGE #ifdef NSIS_CONFIG_COMPONENTPAGE
// set sections to the first insttype // set sections to the first insttype
PreperInstTypes(); PrepareInstTypes();
#endif #endif
set_uninstall_mode(0); set_uninstall_mode(0);
} }
@ -2311,7 +2323,7 @@ int CEXEBuild::write_output(void)
#ifdef NSIS_CONFIG_COMPONENTPAGE #ifdef NSIS_CONFIG_COMPONENTPAGE
// set sections to the first insttype // set sections to the first insttype
PreperInstTypes(); PrepareInstTypes();
#endif #endif
#ifdef NSIS_CONFIG_VISIBLE_SUPPORT #ifdef NSIS_CONFIG_VISIBLE_SUPPORT
@ -2494,7 +2506,7 @@ int CEXEBuild::write_output(void)
{ {
GrowBuf hdrcomp; GrowBuf hdrcomp;
PreperHeaders(&hdrcomp); PrepareHeaders(&hdrcomp);
if (add_data((char*)hdrcomp.get(),hdrcomp.getlen(),&ihd) < 0) if (add_data((char*)hdrcomp.get(),hdrcomp.getlen(),&ihd) < 0)
return PS_ERROR; return PS_ERROR;
@ -2818,7 +2830,7 @@ int CEXEBuild::uninstall_generate()
set_uninstall_mode(1); set_uninstall_mode(1);
PreperHeaders(&udata); PrepareHeaders(&udata);
fh.length_of_header=udata.getlen(); fh.length_of_header=udata.getlen();
int err=add_data((char*)udata.get(),udata.getlen(),&uhd); int err=add_data((char*)udata.get(),udata.getlen(),&uhd);
@ -3113,7 +3125,7 @@ void CEXEBuild::warning_fl(const char *s, ...)
} }
} }
void CEXEBuild::ERROR_MSG(const char *s, ...) void CEXEBuild::ERROR_MSG(const char *s, ...) const
{ {
#ifdef _WIN32 #ifdef _WIN32
if (display_errors || notify_hwnd) if (display_errors || notify_hwnd)
@ -3139,7 +3151,7 @@ void CEXEBuild::ERROR_MSG(const char *s, ...)
} }
} }
void CEXEBuild::SCRIPT_MSG(const char *s, ...) void CEXEBuild::SCRIPT_MSG(const char *s, ...) const
{ {
if (display_script) if (display_script)
{ {
@ -3151,7 +3163,7 @@ void CEXEBuild::SCRIPT_MSG(const char *s, ...)
} }
} }
void CEXEBuild::INFO_MSG(const char *s, ...) void CEXEBuild::INFO_MSG(const char *s, ...) const
{ {
if (display_info) if (display_info)
{ {
@ -3179,7 +3191,7 @@ void CEXEBuild::print_warnings()
} }
#ifdef _WIN32 #ifdef _WIN32
void CEXEBuild::notify(notify_e code, char *data) void CEXEBuild::notify(notify_e code, char *data) const
{ {
if (notify_hwnd) if (notify_hwnd)
{ {

View file

@ -106,12 +106,14 @@ class CEXEBuild {
#ifdef _WIN32 #ifdef _WIN32
HWND notify_hwnd; HWND notify_hwnd;
void notify(notify_e code, char *data); void notify(notify_e code, char *data) const;
#else #else
void notify(notify_e code, char *data) { } void notify(notify_e code, char *data) const { }
#endif #endif
private: private:
int check_write_output_errors() const;
// tokens.cpp // tokens.cpp
int get_commandtoken(char *s, int *np, int *op, int *pos); int get_commandtoken(char *s, int *np, int *op, int *pos);
int IsTokenPlacedRight(int pos, char *tok); int IsTokenPlacedRight(int pos, char *tok);
@ -160,9 +162,9 @@ class CEXEBuild {
bool inside_comment; bool inside_comment;
int multiple_entries_instruction; int multiple_entries_instruction;
void ERROR_MSG(const char *s, ...); void ERROR_MSG(const char *s, ...) const;
void SCRIPT_MSG(const char *s, ...); void SCRIPT_MSG(const char *s, ...) const;
void INFO_MSG(const char *s, ...); void INFO_MSG(const char *s, ...) const;
#ifdef NSIS_CONFIG_PLUGIN_SUPPORT #ifdef NSIS_CONFIG_PLUGIN_SUPPORT
int add_plugins_dir_initializer(void); int add_plugins_dir_initializer(void);
@ -205,8 +207,8 @@ class CEXEBuild {
int AddVersionInfo(); int AddVersionInfo();
int ProcessPages(); int ProcessPages();
void PreperInstTypes(); void PrepareInstTypes();
void PreperHeaders(IGrowBuf *hdrbuf); void PrepareHeaders(IGrowBuf *hdrbuf);
int resolve_jump_int(const char *fn, int *a, int offs, int start, int end); int resolve_jump_int(const char *fn, int *a, int offs, int start, int end);
int resolve_call_int(const char *fn, const char *str, int fptr, int *ofs); int resolve_call_int(const char *fn, const char *str, int fptr, int *ofs);

View file

@ -11,23 +11,25 @@
# include <unistd.h> # include <unistd.h>
#endif #endif
#include <cassert> // for assert
class IGrowBuf class IGrowBuf
{ {
public: public:
virtual int add(const void *data, int len)=0; virtual int add(const void *data, int len)=0;
virtual void resize(int newlen)=0; virtual void resize(int newlen)=0;
virtual int getlen()=0; virtual int getlen() const=0;
virtual void *get()=0; virtual void *get() const=0;
}; };
class IMMap class IMMap
{ {
public: public:
virtual void resize(int newlen)=0; virtual void resize(int newlen)=0;
virtual int getsize()=0; virtual int getsize() const=0;
virtual void *get(int offset, int size)=0; virtual void *get(int offset, int size) const=0;
virtual void *get(int offset, int *size)=0; virtual void *get(int offset, int *size) const=0;
virtual void *getmore(int offset, int *size)=0; virtual void *getmore(int offset, int *size) const=0;
virtual void release()=0; virtual void release()=0;
virtual void release(void *view, int size)=0; virtual void release(void *view, int size)=0;
virtual void clear()=0; virtual void clear()=0;
@ -97,8 +99,8 @@ class GrowBuf : public IGrowBuf
} }
} }
int getlen() { return m_used; } int getlen() const { return m_used; }
void *get() { return m_s; } void *get() const { return m_s; }
private: private:
void *m_s; void *m_s;
@ -189,7 +191,7 @@ public:
} }
char *get() { return (char*)gr.get(); } char *get() { return (char*)gr.get(); }
int getlen() { return gr.getlen(); } int getlen() const { return gr.getlen(); }
private: private:
GrowBuf gr; GrowBuf gr;
}; };
@ -467,17 +469,17 @@ class FastStringList : public SortedStringListND<struct string_t>
return ((struct string_t*)gr.get())[pos].name; return ((struct string_t*)gr.get())[pos].name;
} }
char *get() char *get() const
{ {
return (char*)strings.get(); return (char*)strings.get();
} }
int getlen() int getlen() const
{ {
return strings.getlen(); return strings.getlen();
} }
int getnum() int getnum() const
{ {
return gr.getlen()/sizeof(struct string_t); return gr.getlen()/sizeof(struct string_t);
} }
@ -678,23 +680,22 @@ class MMapFile : public IMMap
} }
} }
int getsize() int getsize() const
{ {
return m_iSize; return m_iSize;
} }
void *get(int offset, int size) void *get(int offset, int size) const
{ {
return get(offset, &size); return get(offset, &size);
} }
void *get(int offset, int *sizep) void *get(int offset, int *sizep) const
{ {
if (!sizep) if (!sizep)
return NULL; return NULL;
if (m_pView) assert(!m_pView);
release();
int size = *sizep; int size = *sizep;
@ -715,10 +716,12 @@ class MMapFile : public IMMap
size += offset - alignedoffset; size += offset - alignedoffset;
#ifdef _WIN32 #ifdef _WIN32
m_pView = MapViewOfFile(m_hFileMap, m_bReadOnly ? FILE_MAP_READ : FILE_MAP_WRITE, 0, alignedoffset, size); const_cast<MMapFile*>(this)->m_pView =
MapViewOfFile(m_hFileMap, m_bReadOnly ? FILE_MAP_READ : FILE_MAP_WRITE, 0, alignedoffset, size);
#else #else
m_pView = mmap(0, size, m_bReadOnly ? PROT_READ : PROT_READ | PROT_WRITE, MAP_SHARED, m_hFileDesc, alignedoffset); const_cast<MMapFile*>(this)->m_pView =
m_iMappedSize = *sizep = size; mmap(0, size, m_bReadOnly ? PROT_READ : PROT_READ | PROT_WRITE, MAP_SHARED, m_hFileDesc, alignedoffset);
const_cast<MMapFile*>(this)->m_iMappedSize = *sizep = size;
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
@ -740,18 +743,18 @@ class MMapFile : public IMMap
return (void *)((char *)m_pView + offset - alignedoffset); return (void *)((char *)m_pView + offset - alignedoffset);
} }
void *getmore(int offset, int *size) void *getmore(int offset, int *size) const
{ {
void *pView; void *pView;
void *pViewBackup = m_pView; void *pViewBackup = m_pView;
#ifndef _WIN32 #ifndef _WIN32
int iMappedSizeBackup = m_iMappedSize; int iMappedSizeBackup = m_iMappedSize;
#endif #endif
m_pView = 0; const_cast<MMapFile*>(this)->m_pView = 0;
pView = get(offset, size); pView = get(offset, size);
m_pView = pViewBackup; const_cast<MMapFile*>(this)->m_pView = pViewBackup;
#ifndef _WIN32 #ifndef _WIN32
m_iMappedSize = iMappedSizeBackup; const_cast<MMapFile*>(this)->m_iMappedSize = iMappedSizeBackup;
#endif #endif
return pView; return pView;
} }
@ -822,24 +825,24 @@ class MMapFake : public IMMap
m_iSize = iSize; m_iSize = iSize;
} }
int getsize() int getsize() const
{ {
return m_iSize; return m_iSize;
} }
void *get(int offset, int size) void *get(int offset, int size) const
{ {
return get(offset, &size); return get(offset, &size);
} }
void *get(int offset, int *size) void *get(int offset, int *size) const
{ {
if (!size || (offset + *size > m_iSize)) if (!size || (offset + *size > m_iSize))
return NULL; return NULL;
return (void *)(m_pMem + offset); return (void *)(m_pMem + offset);
} }
void *getmore(int offset, int *size) void *getmore(int offset, int *size) const
{ {
return get(offset, size); return get(offset, size);
} }
@ -911,26 +914,26 @@ class MMapBuf : public IGrowBuf, public IMMap
} }
} }
int getsize() int getsize() const
{ {
if (m_gb_u) if (m_gb_u)
return m_fm.getsize(); return m_fm.getsize();
return m_gb.getlen(); return m_gb.getlen();
} }
int getlen() int getlen() const
{ {
if (m_gb_u) if (m_gb_u)
return m_used; return m_used;
return m_gb.getlen(); return m_gb.getlen();
} }
void *get() void *get() const
{ {
return get(0, m_alloc); return get(0, m_alloc);
} }
void *get(int offset, int *sizep) void *get(int offset, int *sizep) const
{ {
if (!sizep) if (!sizep)
return NULL; return NULL;
@ -938,14 +941,14 @@ class MMapBuf : public IGrowBuf, public IMMap
return get(offset, size); return get(offset, size);
} }
void *get(int offset, int size) void *get(int offset, int size) const
{ {
if (m_gb_u) if (m_gb_u)
return m_fm.get(offset, size); return m_fm.get(offset, size);
return (void *) ((char *) m_gb.get() + offset); return (void *) ((char *) m_gb.get() + offset);
} }
void *getmore(int offset, int *size) void *getmore(int offset, int *size) const
{ {
if (m_gb_u) if (m_gb_u)
return m_fm.getmore(offset, size); return m_fm.getmore(offset, size);