home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 March / CMCD0304.ISO / Software / Freeware / Programare / nullsoft / nsis20.exe / Source / build.h < prev    next >
C/C++ Source or Header  |  2004-01-04  |  11KB  |  350 lines

  1. #ifndef _BUILD_H_
  2. #define _BUILD_H_
  3.  
  4. #include <StdExcept>
  5.  
  6. using namespace std;
  7.  
  8. #include "strlist.h"
  9. #include "lineparse.h"
  10. #include "lang.h"
  11. #include "ResourceEditor.h"
  12. #include "ResourceVersionInfo.h"
  13. #include "uservars.h"
  14. #include "ShConstants.h"
  15.  
  16. #include "exehead/fileform.h"
  17. #include "exehead/config.h"
  18.  
  19. #ifdef NSIS_SUPPORT_STANDARD_PREDEFINES
  20. // Added by Sunil Kamath 11 June 2003
  21. #include <time.h>
  22. #include <sys/types.h>
  23. #include <sys/stat.h>
  24. #endif
  25.  
  26. #ifdef NSIS_CONFIG_COMPRESSION_SUPPORT
  27. // Changed by Amir Szekely 31st July 2002
  28. #include "compressor.h"
  29. #include "czlib.h"
  30. #include "cbzip2.h"
  31. #include "clzma.h"
  32.  
  33. #endif//NSIS_CONFIG_COMPRESSION_SUPPORT
  34.  
  35. #ifdef NSIS_CONFIG_PLUGIN_SUPPORT
  36. #include "Plugins.h"
  37. #endif //NSIS_CONFIG_PLUGIN_SUPPORT
  38.  
  39. #ifdef NSIS_CONFIG_CRC_SUPPORT
  40. extern "C"
  41. {
  42.   unsigned long NSISCALL CRC32(unsigned long crc, const unsigned char *buf, unsigned int len);
  43. };
  44. #endif
  45.  
  46. #define PS_OK 0
  47. #define PS_EOF 1
  48. #define PS_ERROR 50
  49. #define PS_WARNING 100
  50.  
  51. enum {
  52.   MAKENSIS_NOTIFY_SCRIPT,
  53.   MAKENSIS_NOTIFY_WARNING,
  54.   MAKENSIS_NOTIFY_ERROR,
  55.   MAKENSIS_NOTIFY_OUTPUT
  56. };
  57.  
  58. #define PAGE_CUSTOM 0
  59. #define PAGE_LICENSE 1
  60. #define PAGE_COMPONENTS 2
  61. #define PAGE_DIRECTORY 3
  62. #define PAGE_INSTFILES 4
  63. #define PAGE_UNINSTCONFIRM 5
  64. #define PAGE_COMPLETED 6
  65.  
  66. class CEXEBuild {
  67.   public:
  68.     CEXEBuild();
  69.     ~CEXEBuild();
  70.  
  71.     // to add a warning to the compiler's warning list.
  72.     void warning(const char *s, ...);
  73.     // warning with file name and line count
  74.     void warning_fl(const char *s, ...);
  75.  
  76.     // to add a defined thing.
  77.     void define(const char *p, const char *v="");
  78.  
  79. #ifdef NSIS_CONFIG_PLUGIN_SUPPORT
  80.     // Added by Ximon Eighteen 5th August 2002
  81.     void build_plugin_table(void);
  82.     int plugins_processed;
  83. #endif //NSIS_CONFIG_PLUGIN_SUPPORT
  84.  
  85.  
  86.     // process a script (you can process as many scripts as you want,
  87.     // it is as if they are concatenated)
  88.     int process_script(FILE *fp, char *curfilename);
  89.     int process_oneline(char *line, char *curfilename, int lineptr);
  90.     
  91.     // you only get to call write_output once, so use it wisely.
  92.     int write_output(void);
  93.  
  94.     void print_help(char *commandname=NULL);
  95.  
  96.     DefineList definedlist;
  97.  
  98.     int display_errors;
  99.     int display_script;
  100.     int display_warnings;
  101.     int display_info;
  102.  
  103.     int linecnt;
  104.     char *curfilename;
  105.     FILE *fp;
  106.  
  107.     HWND notify_hwnd;
  108.     void notify(int code, char *data);
  109.  
  110.   private:
  111.     // tokens.cpp
  112.     int get_commandtoken(char *s, int *np, int *op, int *pos);
  113.     int IsTokenPlacedRight(int pos, char *tok);
  114.  
  115.     // script.cpp
  116. #ifdef NSIS_SUPPORT_STANDARD_PREDEFINES
  117.   // Added by Sunil Kamath 11 June 2003
  118.     char* set_file_predefine(char *);
  119.     void restore_file_predefine(char *);
  120.     char* set_timestamp_predefine(char *);
  121.     void restore_timestamp_predefine(char *);
  122.     char* set_line_predefine(int, BOOL);
  123.     void restore_line_predefine(char *);
  124.     void set_date_time_predefines();
  125.     void del_date_time_predefines();
  126. #endif
  127.     int parseScript();
  128.     int includeScript(char *f);
  129.     int MacroExists(const char *macroname);
  130. #ifdef NSIS_FIX_DEFINES_IN_STRINGS
  131.     void ps_addtoline(const char *str, GrowBuf &linedata, StringList &hist, bool bIgnoreDefines = false);
  132. #else
  133.     void ps_addtoline(const char *str, GrowBuf &linedata, StringList &hist);
  134. #endif
  135.     int doParse(const char *str);
  136.     int doCommand(int which_token, LineParser &line);
  137.     int do_add_file(const char *lgss, int attrib, int recurse, int linecnt, int *total_files, const char *name_override=0, int generatecode=1, int *data_handle=0, int rec_depth=0);
  138.     GrowBuf m_linebuild; // used for concatenating lines
  139.  
  140.     // used by doParse to do preprocessing
  141.     struct ifblock
  142.     {
  143.       int hasexeced;
  144.       int elseused;
  145.       int ignore;
  146.       int inherited_ignore;
  147.     } *cur_ifblock;
  148.  
  149.     TinyGrowBuf build_preprocessor_data;
  150.  
  151.     void start_ifblock();
  152.     void end_ifblock();
  153.     int num_ifblock();
  154.  
  155.     int last_line_had_slash;
  156.     bool inside_comment;
  157.  
  158.     void ERROR_MSG(const char *s, ...);
  159.     void SCRIPT_MSG(const char *s, ...);
  160.     void INFO_MSG(const char *s, ...);
  161.  
  162. #ifdef NSIS_CONFIG_PLUGIN_SUPPORT
  163.     int add_plugins_dir_initializer(void);
  164. #endif //NSIS_CONFIG_PLUGIN_SUPPORT
  165.  
  166.     // build.cpp functions used mostly by script.cpp
  167.     int getcurdbsize();
  168.     int add_section(const char *secname, const char *defname, int expand=0);
  169.     int section_end();
  170.     int add_function(const char *funname);
  171.     int function_end();
  172.     void section_add_size_kb(int kb);
  173.     int section_add_flags(int flags);
  174.     int section_add_install_type(int inst_type);
  175.     int add_page(int type);
  176.     int page_end();
  177.     int add_label(const char *name);
  178.     int add_entry(const entry *ent);
  179.     int add_entry_direct(int which, int o0=0, int o1=0, int o2=0, int o3=0, int o4=0, int o5=0);
  180.     int add_db_data(IMMap *map); // returns offset
  181.     int add_db_data(const char *data, int length); // returns offset
  182.     int add_data(const char *data, int length, IGrowBuf *dblock); // returns offset
  183.     int add_string(const char *string, int process=1, WORD codepage=CP_ACP); // returns offset (in string table)
  184.     int add_intstring(const int i); // returns offset in stringblock
  185.  
  186.     int preprocess_string(char *out, const char *in, WORD codepage=CP_ACP);
  187.  
  188. #ifdef NSIS_CONFIG_PLUGIN_SUPPORT
  189.     // Added by Ximon Eighteen 5th August 2002
  190.     Plugins m_plugins;
  191.     bool plugin_used;
  192.     bool uninst_plugin_used;
  193.     int build_plugin_unload;
  194. #endif //NSIS_CONFIG_PLUGIN_SUPPORT
  195.  
  196.     // build.cpp functions used mostly within build.cpp
  197.     int datablock_optimize(int start_offset);
  198.     void printline(int l);
  199.     int process_jump(LineParser &line, int wt, int *offs);
  200.  
  201.     int AddVersionInfo();
  202.     int ProcessPages();
  203.     void PreperInstTypes();
  204.     void PreperHeaders(IGrowBuf *hdrbuf);
  205.  
  206.     int resolve_jump_int(const char *fn, int *a, int offs, int start, int end);
  207.     int resolve_call_int(const char *fn, const char *str, int fptr, int *ofs);
  208.     int resolve_instruction(const char *fn, const char *str, entry *w, int offs, int start, int end);
  209.  
  210.     int resolve_coderefs(const char *str);
  211.     void print_warnings();
  212.     int uninstall_generate();
  213.     void set_uninstall_mode(int un);
  214.  
  215.     // lang.cpp functions and variables
  216.     void InitLangTables();
  217.     LanguageTable *GetLangTable(LANGID &lang);
  218.     int DefineLangString(char *name, int process=-1);
  219.     int DefineInnerLangString(int id, int process=-1);
  220.     int SetLangString(char *name, LANGID lang, char *string);
  221.     int SetInnerString(int id, char *string);
  222.     int GenerateLangTables();
  223.     void FillLanguageTable(LanguageTable *table);
  224.     int HasUserDefined(int id) {
  225.       const char *us = UserInnerStrings.get(id);
  226.       return us && *us;
  227.     };
  228.  
  229.     LanguageTable *LoadLangFile(char *filename);
  230.     void DeleteLangTable(LanguageTable *table);
  231.  
  232.     NLFRef NLFRefs[NLF_STRINGS];
  233.     bool keep_ref;
  234.     StringsArray UserInnerStrings;
  235.     bool defcodepage_set;
  236.     GrowBuf lang_tables;
  237.     LANGID last_used_lang;
  238.     LangStringList build_langstrings;
  239.     int build_langstring_num, ubuild_langstring_num;
  240.     char build_font[1024];
  241.     int build_font_size;
  242.  
  243.     unsigned int uDefCodePage;
  244.  
  245.     // pages stuff
  246.     int license_res_id;
  247.     page *cur_page;
  248.     int cur_page_type;
  249.     int enable_last_page_cancel, uenable_last_page_cancel;
  250.  
  251.     int disable_window_icon;
  252.  
  253.     // User variables stuff
  254.     int GetUserVarIndex(LineParser &line, int token);
  255.     // Added by ramon 3 jun 2003
  256.     UserVarsStringList m_UserVarNames;
  257.     int m_iBaseVarsNum;
  258.     int DeclaredUserVar(const char *VarName);
  259.     void VerifyDeclaredUserVarRefs(UserVarsStringList *pVarsStringList);
  260.  
  261.     ConstantsStringList m_ShellConstants;
  262.  
  263.     // a whole bunch O data.
  264.  
  265. #ifdef NSIS_CONFIG_COMPRESSION_SUPPORT
  266.     ICompressor *compressor;
  267.     CZlib zlib_compressor;
  268.     CBzip2 bzip2_compressor;
  269.     CLZMA lzma_compressor;
  270. #endif
  271.     bool build_compressor_set;
  272.     bool build_compressor_final;
  273.     bool build_compress_whole;
  274.     int build_compress;
  275.     int build_compress_level;
  276.     int build_compress_dict_size;
  277.  
  278.     bool no_space_texts;
  279.  
  280.     int has_called_write_output;
  281.  
  282.     char build_packname[1024], build_packcmd[1024];
  283.     int build_overwrite, build_last_overwrite, build_crcchk,
  284.         build_datesave, build_optimize_datablock,
  285.         build_allowskipfiles; // Added by ramon 23 May 2003
  286.  
  287.     header build_header, build_uninst, *cur_header;
  288.     int uninstall_mode;
  289.     int uninstall_size,uninstall_size_full;
  290.     int uninstaller_writes_used;
  291.  
  292.     char build_output_filename[1024];
  293.  
  294.     int build_include_depth;
  295.  
  296.     // Added by ramon 6 jun 2003
  297. #ifdef NSIS_SUPPORT_VERSION_INFO
  298.     CResourceVersionInfo rVersionInfo;
  299.     char version_product_v[1024];
  300. #endif
  301.  
  302.     int subsection_open_cnt;
  303.     FastStringList m_warnings;
  304.     GrowBuf m_macros;
  305.  
  306.     StringList m_macro_entry;
  307.  
  308.     int db_opt_save, db_comp_save, db_full_size, db_opt_save_u, 
  309.         db_comp_save_u, db_full_size_u;
  310.  
  311.     FastStringList include_dirs;
  312.  
  313.     StringList ns_func; // function namespace
  314.     StringList ns_label; // label namespace
  315.  
  316.     int build_cursection_isfunc;
  317.     section *build_cursection;
  318.     TinyGrowBuf build_sections, ubuild_sections, *cur_sections;
  319.     GrowBuf build_entries,ubuild_entries, *cur_entries;
  320.     TinyGrowBuf build_functions, ubuild_functions, *cur_functions;
  321.     TinyGrowBuf build_labels, ubuild_labels, *cur_labels;
  322.     StringList build_strlist, ubuild_strlist, *cur_strlist;
  323.     GrowBuf build_langtables, ubuild_langtables, *cur_langtables;
  324.     TinyGrowBuf build_pages, ubuild_pages, *cur_pages;
  325.     TinyGrowBuf build_ctlcolors, ubuild_ctlcolors, *cur_ctlcolors;
  326.  
  327.     MMapBuf build_datablock, ubuild_datablock;
  328.     IGrowBuf *cur_datablock;
  329.  
  330.     int build_filebuflen;
  331.  
  332.     TinyGrowBuf verbose_stack;
  333.  
  334.     unsigned char *header_data_new;
  335.     int exeheader_size_new;
  336.     int icon_offset;
  337.     bool branding_image_found;
  338.     WORD branding_image_id;
  339.     unsigned char *m_unicon_data;
  340. #ifdef NSIS_CONFIG_COMPRESSION_SUPPORT
  341.     int deflateToFile(FILE *fp, char *buf, int len); // len==0 to flush
  342. #endif
  343.  
  344.     CResourceEditor *res_editor;
  345.     void init_res_editor();
  346.     void close_res_editor();
  347. };
  348.  
  349. #endif //_BUILD_H_
  350.