home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 October / Chip_2001-10_cd1.bin / zkuste / delphi / nastroje / d23456 / NSIS.EXE / Source / tokens.cpp < prev    next >
C/C++ Source or Header  |  2001-05-30  |  8KB  |  146 lines

  1. #include <windows.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4.  
  5. #include "build.h"
  6. #include "tokens.h"
  7.  
  8. typedef struct 
  9. {
  10.   int id;
  11.   char *name;
  12.   int num_parms; // minimum number of parameters
  13.   int opt_parms; // optional parmaters, usually 0, can be -1 for unlimited.
  14.   char *usage_str;
  15. } tokenType;
  16.  
  17.  
  18. static tokenType tokenlist[TOK__LAST] =
  19. {
  20. {TOK_ABORT,"Abort",0,1,"[message]"},
  21. {TOK_AUTOCLOSE,"AutoCloseWindow",1,0,"(false|true)"},
  22. {TOK_BGGRADIENT,"BGGradient",0,3,"(off | [top_color [bottom_color [text_color]]])"},
  23. {TOK_BRINGTOFRONT,"BringToFront",0,0,""},
  24. {TOK_CALL,"Call",1,0,"function_name"},
  25. {TOK_CAPTION,"Caption",1,0,"installer_caption"},
  26. {TOK_CLEARERRORS,"ClearErrors",0,0,""},
  27. {TOK_COMPTEXT,"ComponentText",0,1,"[component_page_description]"},
  28. {TOK_COMPAREDLLS,"CompareDLLVersions",4,1,"[/STOREFROM] dll1 dll2 goto_if_dll1_newer goto_if_dll2_newer"},
  29. {TOK_COMPAREFILETIMES,"CompareFileTimes",4,1,"[/STOREFROM] file1 file2 goto_if_file1_newer goto_if_file2_newer"},
  30. {TOK_COPYFILES,"CopyFiles",3,0,"source_path destination_path total_size_in_kb"},
  31. {TOK_CRCCHECK,"CRCCheck",1,0,"(on|off)"},
  32. {TOK_CREATEDIR,"CreateDirectory",1,0,"directory_name"},
  33. {TOK_CREATESHORTCUT,"CreateShortCut",2,5,"shortcut_name.lnk shortcut_target [parameters [icon_file [icon index [showmode [hotkey]]]]]\n    showmode=(SW_SHOWNORMAL|SW_SHOWMAXIMIZED|SW_SHOWMINIMIZED)\n    hotkey=(ALT|CONTROL|EXT|SHIFT)|(F1-F24|A-Z)"},
  34. {TOK_DBOPTIMIZE,"SetDatablockOptimize",1,0,"(off|on)"},
  35. {TOK_DELETEINISEC,"DeleteINISec",2,0,"ini_file section_name"},
  36. {TOK_DELETEINISTR,"DeleteINIStr",3,0,"ini_file section_name entry_name"},
  37. {TOK_DELETEREGKEY,"DeleteRegKey",2,1,"[/ifempty] root_key subkey\n    root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD)"},
  38. {TOK_DELETEREGVALUE,"DeleteRegValue",3,0,"root_key subkey entry_name\n    root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD)"},
  39. {TOK_DELETENSPLUG,"DeleteNSPlug",1,0,"netscape_plugin_name.dll"},
  40. {TOK_DELETE,"Delete",1,1,"[/REBOOTOK] filespec"},
  41. {TOK_DETAILPRINT,"DetailPrint",1,0,"message"},
  42. {TOK_DIRTEXT,"DirText",0,1,"[directory_page_description]"},
  43. {TOK_DIRSHOW,"DirShow",1,0,"(show|hide)"},
  44. {TOK_DISABLEDBITMAP,"DisabledBitmap",1,0,"local_bitmap.bmp"},
  45. {TOK_ENABLEDBITMAP,"EnabledBitmap",1,0,"local_bitmap.bmp"},
  46. {TOK_EXEC,"Exec",1,0,"command_line"},
  47. {TOK_EXECWAIT,"ExecWait",1,0,"command_line"},
  48. {TOK_EXECSHELL,"ExecShell",2,2,"(open|print|etc) command_line [parameters [showmode]]\n   showmode=(SW_SHOWNORMAL|SW_SHOWMAXIMIZED|SW_SHOWMINIMIZED)"},
  49. {TOK_FINDWINDOW,"FindWindow",2,1,"(prompt|close|closeinstant|goto:Label) WindowClass [prompt_text]"},
  50. {TOK_FINDWINDOWBYTITLE,"FindWindowByTitle",2,1,"(prompt|close|closeinstant|goto:Label) WindowTitle [prompt_text]"},
  51. {TOK_FILE,"File",1,-1,"(/r filespec [...]|/oname=outfile one_file_only)"},
  52. {TOK_FUNCTION,"Function",1,0,"function_name"},
  53. {TOK_FUNCTIONEND,"FunctionEnd",0,0,""},
  54. {TOK_GETFULLDLLPATH,"GetFullDLLPath",2,0,"$(0-9) dll_name"},
  55. {TOK_HIDEWINDOW,"HideWindow",0,0,""},
  56. {TOK_ICON,"Icon",1,0,"local_icon.ico"},
  57. {TOK_IFERRORS,"IfErrors",1,1,"label_to_goto_if_errors [label_to_goto_if_no_errors]"},
  58. {TOK_IFFILEEXISTS,"IfFileExists",2,1,"filename label_to_goto_if_file_exists [label_to_goto_otherwise]"},
  59. {TOK_INSTALLDIRREGKEY,"InstallDirRegKey",3,0,"root_key subkey entry_name\n    root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD)"},
  60. {TOK_INSTCOLORS,"InstallColors",1,1,"(/windows | (foreground_color background_color))"},
  61. {TOK_INSTDIR,"InstallDir",1,0,"default_install_directory"},
  62. {TOK_INSTNSPLUG,"InstNSPlug",1,0,"local_nsplugin.dll"},
  63. {TOK_INSTTYPE,"InstType",1,0,"(/NOCUSTOM|TypeName)"},
  64. {TOK_GETPARENTDIR,"GetParentDir",2,0,"$(0-9|INSTDIR|OUTDIR) FilePath"},
  65. {TOK_GOTO,"Goto",1,0,"label"},
  66. {TOK_LICENSEDATA,"LicenseData",1,0,"local_file_that_has_license_text.txt"},
  67. {TOK_LICENSETEXT,"LicenseText",1,0,"license_page_description"},
  68. {TOK_MESSAGEBOX,"MessageBox",2,2,"mode messagebox_text [return_check [label_to_goto_if_equal]]\n    mode=modeflag[|modeflag[|modeflag[...]]]\n    "
  69.                                 "modeflag=(MB_ABORTRETRYIGNORE|MB_OK|MB_OKCANCEL|MB_RETRYCANCEL|MB_YESNO|MB_YESNOCANCEL|MB_ICONEXCLAMATION|MB_ICONINFORMATION|MB_ICONQUESTION|MB_ICONSTOP|MB_TOPMOST|MB_SETFOREGROUND|MB_RIGHT"},
  70. {TOK_NOP,"Nop",0,0,""},
  71. {TOK_NAME,"Name",1,0,"installer_name"},
  72. {TOK_OUTFILE,"OutFile",1,0,"install_output.exe"},
  73. {TOK_READINISTR,"ReadINIStr",4,0,"$(0-9|INSTDIR|OUTDIR) ini_file section entry_name"},
  74. {TOK_READREGSTR,"ReadRegStr",4,0,"$(0-9|INSTDIR|OUTDIR) rootkey subkey entry\n   root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD)"},
  75. {TOK_REGDLL,"RegDLL",1,1,"dll_path_on_target.dll [entrypoint_symbol]"},
  76. {TOK_RENAME,"Rename",2,1,"[/REBOOTOK] source_file destination_file"},
  77. {TOK_RMDIR,"RMDir",1,1,"[/r] directory_name"},
  78. {TOK_SECTION,"Section",0,1,"[section_name|-section_name]"},
  79. {TOK_SECTIONDIVIDER,"SectionDivider",0,0,""},
  80. {TOK_SECTIONEND,"SectionEnd",0,0,""},
  81. {TOK_SECTIONIN,"SectionIn",1,-1,"InstType [InstType [...]]"},
  82. {TOK_SETCOMPRESS,"SetCompress",1,0,"(off|auto|force)"},
  83. {TOK_SETDATESAVE,"SetDateSave",1,0,"(off|on)"},
  84. {TOK_SETDETAILSVIEW,"SetDetailsView",1,0,"(hide|show)"},
  85. {TOK_SETFILEATTRIBUTES,"SetFileAttributes",2,0,"file attribute[|attribute[...]]\n    attribute=(NORMAL|ARCHIVE|HIDDEN|OFFLINE|READONLY|SYSTEM|TEMPORARY|0)"},
  86. {TOK_SETERRORS,"SetErrors",0,0,""},
  87. {TOK_SETAUTOCLOSE,"SetAutoClose",1,0,"(false|true)"},
  88. {TOK_SETOUTPATH,"SetOutPath",1,0,"output_path"},
  89. {TOK_SETOVERWRITE,"SetOverwrite",1,0,"(on|off|try|ifnewer)"},
  90. {TOK_SHOWDETAILS,"ShowInstDetails",1,0,"(hide|show|nevershow)"},
  91. {TOK_SILENTINST,"SilentInstall",1,0,"(normal|silent|silentlog)"},
  92. {TOK_SLEEP,"Sleep",1,0,"sleep_time_in_ms"},
  93. {TOK_STRCMP,"StrCmp",3,1,"str1 str2 label_to_goto_if_equal [label_to_goto_if_not]"},
  94. {TOK_STRCPY,"StrCpy",2,1,"$(0-9,INSTDIR,OUTDIR) str [maxlen]"},
  95. {TOK_UNINSTALLEXENAME,"UninstallExeName",1,0,"uninstaller_exe_name_to_generate.exe"},
  96. {TOK_UNINSTICON,"UninstallIcon",1,0,"icon_on_local_system.ico"},
  97. {TOK_UNINSTTEXT,"UninstallText",1,0,"Text_to_go_on_uninstall page"},
  98. {TOK_UNREGDLL,"UnRegDLL",1,0,"dll_path_on_target.dll"},
  99. {TOK_WRITEINISTR,"WriteINIStr",4,0,"ini_file section_name entry_name new_value"},
  100. {TOK_WRITEREGBIN,"WriteRegBin",4,0,"rootkey subkey entry_name hex_string_like_12848412AB\n    root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD)"},
  101. {TOK_WRITEREGDWORD,"WriteRegDword",4,0,"rootkey subkey entry_name new_value_dword\n    root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD)"},
  102. {TOK_WRITEREGSTR,"WriteRegStr",4,0,"rootkey subkey entry_name new_value_string\n    root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD)"},
  103. {TOK_P_PACKEXEHEADER,"!packhdr",2,0,"temp_file_name command_line_to_compress_that_temp_file"},
  104. {TOK_P_SYSTEMEXEC,"!system",3,0,"command (<|>|<>|=|ignore) retval"},
  105. {TOK_P_INCLUDE,"!include",1,0,"filename.nsi"},
  106. {TOK_P_CD,"!cd",1,0,"absolute_or_relative_new_directory"},
  107. {TOK_P_IFDEF,"!ifdef",1,-1,"symbol [| symbol2 [& symbol3 [...]]]"},
  108. {TOK_P_IFNDEF,"!ifndef",1,-1,"symbol [| symbol2 [& symbol3 [...]]]"},
  109. {TOK_P_ENDIF,"!endif",0,0,""},
  110. {TOK_P_DEFINE,"!define",1,0,"symbol"},
  111. {TOK_P_ELSE,"!else",0,-1,"[ifdef|ifndef symbol [|symbol2 [& symbol3 [...]]]]"},
  112. {TOK_P_ERROR,"!error",0,1,"[error_message]"},
  113. {TOK_P_WARNING,"!warning",0,1,"[warning_message]"},
  114. };
  115.  
  116. void CEXEBuild::print_help(char *commandname)
  117. {
  118.   int x;
  119.   for (x = 0; x < TOK__LAST; x ++)
  120.   {
  121.     if (!commandname || !stricmp(tokenlist[x].name,commandname))
  122.     {
  123.       printf("%s%s %s\n",commandname?"Usage: ":"",tokenlist[x].name,tokenlist[x].usage_str);
  124.       if (commandname) break;
  125.     }
  126.   }
  127.   if (x == TOK__LAST && commandname)\
  128.   {
  129.     printf("Invalid command \"%s\"\n",commandname);
  130.   }
  131.  
  132. }
  133.  
  134. int CEXEBuild::get_commandtoken(char *s, int *np, int *op)
  135. {
  136.   int x;
  137.   for (x = 0; x < TOK__LAST; x ++)
  138.     if (!stricmp(tokenlist[x].name,s)) 
  139.     {
  140.       *np=tokenlist[x].num_parms;
  141.       *op=tokenlist[x].opt_parms;
  142.       return tokenlist[x].id;
  143.     }
  144.   return -1;
  145. }
  146.