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
#ifdef NSIS_CONFIG_COMPONENTPAGE
void CEXEBuild::PreperInstTypes()
void CEXEBuild::PrepareInstTypes()
{
if (!(cur_header->flags & CH_FLAGS_NO_CUSTOM))
cur_header->install_types[NSIS_MAX_INST_TYPES] = DefineInnerLangString(NLF_COMP_CUSTOM);
@ -2176,7 +2176,7 @@ void CEXEBuild::PreperInstTypes()
}
#endif
void CEXEBuild::PreperHeaders(IGrowBuf *hdrbuf)
void CEXEBuild::PrepareHeaders(IGrowBuf *hdrbuf)
{
hdrbuf->add(cur_header,sizeof(header));
#ifdef NSIS_CONFIG_VISIBLE_SUPPORT
@ -2205,17 +2205,14 @@ void CEXEBuild::PreperHeaders(IGrowBuf *hdrbuf)
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)
{
ERROR_MSG("Error (write_output): write_output already called, can't continue\n");
return PS_ERROR;
}
has_called_write_output++;
if (!build_output_filename[0])
{
ERROR_MSG("Error: invalid script: never had OutFile command\n");
@ -2252,18 +2249,33 @@ int CEXEBuild::write_output(void)
if (cur_page)
{
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.
if (build_cursection_isfunc)
{
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;
err = check_write_output_errors();
if (err != PS_OK)
return err;
has_called_write_output++;
#ifdef NSIS_CONFIG_PLUGIN_SUPPORT
err = add_plugins_dir_initializer();
if (err != PS_OK)
@ -2293,7 +2305,7 @@ int CEXEBuild::write_output(void)
return PS_ERROR;
#ifdef NSIS_CONFIG_COMPONENTPAGE
// set sections to the first insttype
PreperInstTypes();
PrepareInstTypes();
#endif
set_uninstall_mode(0);
}
@ -2311,7 +2323,7 @@ int CEXEBuild::write_output(void)
#ifdef NSIS_CONFIG_COMPONENTPAGE
// set sections to the first insttype
PreperInstTypes();
PrepareInstTypes();
#endif
#ifdef NSIS_CONFIG_VISIBLE_SUPPORT
@ -2494,7 +2506,7 @@ int CEXEBuild::write_output(void)
{
GrowBuf hdrcomp;
PreperHeaders(&hdrcomp);
PrepareHeaders(&hdrcomp);
if (add_data((char*)hdrcomp.get(),hdrcomp.getlen(),&ihd) < 0)
return PS_ERROR;
@ -2818,7 +2830,7 @@ int CEXEBuild::uninstall_generate()
set_uninstall_mode(1);
PreperHeaders(&udata);
PrepareHeaders(&udata);
fh.length_of_header=udata.getlen();
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
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)
{
@ -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)
{
@ -3179,7 +3191,7 @@ void CEXEBuild::print_warnings()
}
#ifdef _WIN32
void CEXEBuild::notify(notify_e code, char *data)
void CEXEBuild::notify(notify_e code, char *data) const
{
if (notify_hwnd)
{

View file

@ -106,12 +106,14 @@ class CEXEBuild {
#ifdef _WIN32
HWND notify_hwnd;
void notify(notify_e code, char *data);
void notify(notify_e code, char *data) const;
#else
void notify(notify_e code, char *data) { }
void notify(notify_e code, char *data) const { }
#endif
private:
int check_write_output_errors() const;
// tokens.cpp
int get_commandtoken(char *s, int *np, int *op, int *pos);
int IsTokenPlacedRight(int pos, char *tok);
@ -160,9 +162,9 @@ class CEXEBuild {
bool inside_comment;
int multiple_entries_instruction;
void ERROR_MSG(const char *s, ...);
void SCRIPT_MSG(const char *s, ...);
void INFO_MSG(const char *s, ...);
void ERROR_MSG(const char *s, ...) const;
void SCRIPT_MSG(const char *s, ...) const;
void INFO_MSG(const char *s, ...) const;
#ifdef NSIS_CONFIG_PLUGIN_SUPPORT
int add_plugins_dir_initializer(void);
@ -205,8 +207,8 @@ class CEXEBuild {
int AddVersionInfo();
int ProcessPages();
void PreperInstTypes();
void PreperHeaders(IGrowBuf *hdrbuf);
void PrepareInstTypes();
void PrepareHeaders(IGrowBuf *hdrbuf);
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);

View file

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