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

  1. #define NSIS_VERSION "MakeNSIS v1.44"
  2. /* 
  3.   Nullsoft "SuperPimp" Installation System - makensis.cpp - installer compiler code
  4.   version 1.44 - June 11, 2001
  5.  
  6.   Copyright (C) 1999-2001 Nullsoft, Inc.
  7.  
  8.   This software is provided 'as-is', without any express or implied
  9.   warranty.  In no event will the authors be held liable for any damages
  10.   arising from the use of this software.
  11.  
  12.   Permission is granted to anyone to use this software for any purpose,
  13.   including commercial applications, and to alter it and redistribute it
  14.   freely, subject to the following restrictions:
  15.  
  16.   1. The origin of this software must not be misrepresented; you must not
  17.      claim that you wrote the original software. If you use this software
  18.      in a product, an acknowledgment in the product documentation would be
  19.      appreciated but is not required.
  20.   2. Altered source versions must be plainly marked as such, and must not be
  21.      misrepresented as being the original software.
  22.   3. This notice may not be removed or altered from any source distribution.
  23.  
  24.   This source distribution includes portions of zlib. see zlib/zlib.h for 
  25.   its license and so forth. Note that this license is also borrowed from zlib.
  26. */
  27.  
  28. #include <windows.h>
  29. #include <stdio.h>
  30. #include <signal.h>
  31.  
  32. #include "build.h"
  33. #include "util.h"
  34. #include "exedata.h"
  35.  
  36.  
  37. int g_noconfig;
  38.  
  39. static char *get_featurestring();
  40.  
  41. void quit()
  42. {
  43.   printf("\nNote: you may have one or two (large) stale temporary file(s)\n"
  44.          "left in your temporary directory (Generally this only happens on Windows 9x).\n");
  45.   exit(1);
  46. }
  47.  
  48. static void sigint(int sig)
  49. {
  50.   printf("\n\nAborting on Ctrl+C...\n");
  51.   quit();
  52. }
  53.  
  54. int main(int argc, char **argv)
  55. {
  56.   CEXEBuild build;
  57.   int do_cd=0;
  58.   int do_license=0;
  59.   int argpos=1;
  60.   FILE *fp;
  61.   printf("%s - Copyright 1999-2001 Nullsoft, Inc.\n"
  62.          "\n"
  63.          "Portions Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler.\n"
  64.          "Contributors: nnop@newmail.ru, Ryan Geiss, Andras Varga, Drew Davidson, et al.\n\n",NSIS_VERSION);
  65.  
  66.   atexit(dopause);
  67.  
  68.   signal(SIGINT,sigint);
  69.  
  70.   while (argpos < argc)
  71.   {
  72.     if (argv[argpos][0]=='/' && (argv[argpos][1]=='D' || argv[argpos][1]=='d'))
  73.     {
  74.       char *p=argv[argpos]+2;
  75.       if (p[0])
  76.       {
  77.         printf("Command line defined: \"%s\"\n",p);
  78.         build.define(p);
  79.       }
  80.       else
  81.       {
  82.         build.warning("command line /D requires argument (i.e. \"/Ddefine\"). ignored.");
  83.       }
  84.     }
  85.     else if (!stricmp(argv[argpos],"/CD")) do_cd=1;
  86.     else if (!stricmp(argv[argpos],"/NOCONFIG")) g_noconfig=1;
  87.     else if (!stricmp(argv[argpos],"/PAUSE")) g_dopause=1;
  88.     else if (!stricmp(argv[argpos],"/LICENSE")) do_license=1;
  89.     else if (!stricmp(argv[argpos],"/CMDHELP"))
  90.     {
  91.       if (argpos < argc-1)
  92.         build.print_help(argv[argpos+1]);
  93.       else 
  94.         build.print_help(NULL);
  95.       return 1;
  96.     }
  97.     else break;
  98.     argpos++;
  99.   }
  100.  
  101.   if (do_license)
  102.   {
  103.     printf("This software is provided 'as-is', without any express or implied warranty.  In\n"
  104.            "no event will the authors be held liable for any damages arising from the use\n"
  105.            "of this software.\n\n"
  106.            "Permission is granted to anyone to use this software for any purpose, including\n"
  107.            "commercial applications, and to alter it and redistribute it freely, subject to\n"
  108.            "the following restrictions:\n"
  109.            "  1. The origin of this software must not be misrepresented; you must not claim\n"
  110.            "     that you wrote the original software. If you use this software in a\n"
  111.            "     product, an acknowledgment in the product documentation would be\n"
  112.            "     appreciated but is not required.\n"
  113.            "  2. Altered source versions must be plainly marked as such, and must not be\n"
  114.            "     misrepresented as being the original software.\n"
  115.            "  3. This notice may not be removed or altered from any source distribution.\n\n");
  116.  
  117.     return 1;
  118.   }
  119.  
  120.   printf("Use the /LICENSE switch to view license information.\n\n");
  121.  
  122.   if (argpos != argc-1)
  123.   {
  124.     printf("  Compiled-in features (header size of %d bytes):%s\n", exeheader_size,get_featurestring());
  125.     printf("\nUsage:\n"
  126.            "  makensis [/LICENSE /PAUSE /NOCONFIG /CD /Ddefine ...] [script.nsi | - ]\n"
  127.            "  makensis /CMDHELP [item]\n");
  128.     printf("    /CMDHELP item prints out help for 'item', or lists all commands\n"
  129.            "    /LICENSE prints the license\n"
  130.            "    /PAUSE pauses after execution\n"
  131.            "    /NOCONFIG disables inclusion of <path to makensis.exe>\\nsisconf.nsi\n"
  132.            "    /CD makes makensis change the current directory to that of the .nsi file\n"
  133.            "    /Ddefine defines the symbol \"define\" for the script\n"
  134.            "  ...and for a script file name, you can use - to read from the standard input\n");
  135.  
  136.     return 1;
  137.   }
  138.  
  139.  
  140.   if (!strcmp(argv[argpos],"-"))
  141.   {
  142.     g_dopause=0;
  143.   }
  144.  
  145.   if (!g_noconfig)
  146.   {
  147.     char exepath[1024];
  148.     strncpy(exepath,argv[0],1023);
  149.     exepath[1023]=0;
  150.     char *p=exepath;
  151.     while (*p) p++;
  152.     while (p > exepath && *p != '\\') p--;
  153.     strcpy(p,"nsisconf.nsi");
  154.     FILE *cfg=fopen(exepath,"rt");
  155.     if (cfg)
  156.     {
  157.       printf("-=-=-=-=-=-=-=-=-=-=- Processing config -=-=-=-=-=-=-=-=-=-=-\n");
  158.       int lc=0;
  159.       int ret=build.process_script(cfg,exepath,&lc);
  160.       fclose(cfg);
  161.       if (ret != PS_OK && ret != PS_EOF)
  162.       {
  163.         printf("Error in config on line %d -- aborting creation process\n",lc);
  164.         return 1;
  165.       }
  166.     }
  167.   }
  168.  
  169.   char sfile[1024];
  170.   if (!strcmp(argv[argpos],"-"))
  171.   {
  172.     fp=stdin;
  173.     strcpy(sfile,"stdin");
  174.   }
  175.   else
  176.   {
  177.     strcpy(sfile,argv[argpos]);
  178.     fp=fopen(sfile,"rt");
  179.     if (!fp)
  180.     {
  181.       sprintf(sfile,"%s.nsi",argv[argpos]);
  182.       fp=fopen(sfile,"rt");
  183.       if (!fp)
  184.       {
  185.         perror("Can't open script");
  186.         return 1;
  187.       }
  188.     }
  189.     if (do_cd)
  190.     {
  191.       char dirbuf[1024],*p;
  192.       GetFullPathName(sfile,sizeof(dirbuf),dirbuf,&p);
  193.       p=dirbuf;
  194.       while (*p) p++;
  195.       while (p > dirbuf && *p != '\\') p--;
  196.       *p=0;
  197.       if (dirbuf[0]) 
  198.       {
  199.         printf("Changing directory to: \"%s\"\n",dirbuf);
  200.         SetCurrentDirectory(dirbuf);
  201.       }
  202.     }
  203.   }
  204.  
  205.  
  206.   printf("-=-=-=-=-=-=-=-=-=-=- Processing script -=-=-=-=-=-=-=-=-=-=-\n");
  207.   printf("Script file: \"%s\"\n",sfile);
  208.   int lc=0;
  209.   int ret=build.process_script(fp,sfile,&lc);
  210.   if (fp != stdin) fclose(fp);
  211.  
  212.   if (ret != PS_EOF && ret != PS_OK)
  213.   {
  214.     printf("Error in script \"%s\" on line %d -- aborting creation process\n",sfile,lc);
  215.     return 1;
  216.   }
  217.   
  218.   ret=build.write_output();
  219.  
  220.   if (ret)
  221.   { 
  222.     printf("Error - aborting creation process\n");
  223.     return 1;
  224.   }
  225.   printf("\n");
  226.   return 0; 
  227. }
  228.  
  229.  
  230.  
  231.  
  232.  
  233. static char *get_featurestring()
  234. {
  235.   char *f=" "
  236. #ifdef NSIS_CONFIG_LOG
  237.          "NSIS_CONFIG_LOG,"
  238. #endif
  239. #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT
  240.          "NSIS_CONFIG_UNINSTALL_SUPPORT,"
  241. #endif
  242. #ifdef NSIS_SUPPORT_NETSCAPEPLUGINS
  243.          "NSIS_SUPPORT_NETSCAPEPLUGINS,"
  244. #endif
  245. #ifdef NSIS_SUPPORT_ACTIVEXREG
  246.          "NSIS_SUPPORT_ACTIVEXREG,"
  247. #endif
  248. #ifdef NSIS_SUPPORT_BGBG
  249.          "NSIS_SUPPORT_BGBG,"
  250. #endif
  251. ;
  252.   if (!f[1]) return "none.";
  253.   f[strlen(f)-1]='.';
  254.   return f;
  255. }