home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / MISC / LO241SRV.ZIP / MAKEINST.C < prev    next >
C/C++ Source or Header  |  1998-08-04  |  7KB  |  256 lines

  1.  
  2. // LoraBBS Version 2.41 Free Edition
  3. // Copyright (C) 1987-98 Marco Maccaferri
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 2 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <dir.h>
  22. #include <io.h>
  23. #include <fcntl.h>
  24. #include <alloc.h>
  25. #include <dos.h>
  26. #include <string.h>
  27. #include <sys\stat.h>
  28.  
  29. int fdin, fdout = -1;
  30.  
  31. #define UNPACK    1
  32. #define MKDIR     2
  33. #define TARGET    3
  34. #define OVERWRITE 4
  35. #define UPGRADE   5
  36. #define ERASE     6
  37. #define STORED    7
  38. #define EXECUTE   8
  39. #define STAMPDATE 9
  40.  
  41. typedef struct {
  42.    int  action;
  43.    int  fid;
  44.    char filename[14];
  45.    unsigned ftime;
  46.    unsigned fdate;
  47.    long complen;
  48. } COMPREC;
  49.  
  50. unsigned ReadBuff (char *buff, unsigned short int *size)
  51. {
  52.    unsigned m;
  53.  
  54.    m = read (fdin, buff, *size);
  55.    printf ("%3d%%\b\b\b\b", (int)(tell (fdin) * 100L / filelength (fdin)));
  56.  
  57.    return (m);
  58. }
  59.  
  60. unsigned WriteBuff (char *buff, unsigned short int *size)
  61. {
  62.    return (write (fdout, buff, *size));
  63. }
  64.  
  65. void store_file (char *work_buff)
  66. {
  67.    unsigned short int i;
  68.    unsigned short int size = 32767U;
  69.  
  70.    do {
  71.       i = ReadBuff (work_buff, &size);
  72.       WriteBuff (work_buff, &i);
  73.    } while (i == size);
  74. }
  75.  
  76. void main (int argc, char *argv[])
  77. {
  78.    FILE *fp;
  79.    int m, dd, mm, yy, hh, ss, rtime = -1, rdate;
  80.    unsigned short int type;
  81.    unsigned short int dsize;
  82.    char string[180], filename[80], *p, *path, *newname, store = 0;
  83.    char *WorkBuff;
  84.    long pos, stublen = -1L;
  85.    struct ffblk blk;
  86.    COMPREC cr;
  87.  
  88.    WorkBuff = (char *)malloc (35256U);
  89.  
  90.    if (argc == 1)
  91.       fp = fopen ("INSTALL.CFG", "rt");
  92.    else
  93.       fp = fopen (argv[1], "rt");
  94.    while (fgets (string, 70, fp) != NULL) {
  95.       while (string[strlen (string) - 1] == 0x0A)
  96.          string[strlen (string) - 1] = '\0';
  97.       if (string[0] == ';')
  98.          continue;
  99.  
  100.       p = strtok (string, " ");
  101.       if (p == NULL || *p == ';')
  102.          continue;
  103.  
  104.       if (!stricmp (p, "OUTFILE")) {
  105.          p = strtok (NULL, " ");
  106.          if (fdout != -1) {
  107.             if (stublen != -1L)
  108.                write (fdout, &stublen, 4);
  109.             close (fdout);
  110.          }
  111.          fdout = open (p, O_RDWR|O_BINARY|O_CREAT|O_TRUNC, S_IREAD|S_IWRITE);
  112.          printf ("\nCreating File: %s\n", p);
  113.       }
  114.       else if (!stricmp (p, "TARGET")) {
  115.          memset (&cr, 0, sizeof (COMPREC));
  116.          cr.action = MKDIR;
  117.  
  118.          p = strtok (NULL, " ");
  119.          printf ("Target Directory: %s\n", p);
  120.          strcpy (cr.filename, strlwr (p));
  121.  
  122.          write (fdout, &cr, sizeof (COMPREC));
  123.       }
  124.       else if (!stricmp (p, "STORE"))
  125.          store = 1;
  126.       else if (!stricmp (p, "COMPRESS"))
  127.          store = 0;
  128.       else if (!stricmp (p, "ERASE")) {
  129.          memset (&cr, 0, sizeof (COMPREC));
  130.          cr.action = ERASE;
  131.  
  132.          p = strtok (NULL, " ");
  133.          printf ("Erase: %s\n", p);
  134.          strcpy (cr.filename, p);
  135.  
  136.          write (fdout, &cr, sizeof (COMPREC));
  137.       }
  138.       else if (!stricmp (p, "EXECUTE")) {
  139.          memset (&cr, 0, sizeof (COMPREC));
  140.          cr.action = EXECUTE;
  141.  
  142.          p = strtok (NULL, " ");
  143.          printf ("Execute: %s\n", p);
  144.          strcpy (cr.filename, strlwr (p));
  145.  
  146.          write (fdout, &cr, sizeof (COMPREC));
  147.       }
  148.       else if (!stricmp (p, "RELEASETIME")) {
  149.          p = strtok (NULL, " ");
  150.          if (!stricmp (p, "ORIGINAL"))
  151.             rtime = -1;
  152.          else {
  153.             sscanf (p, "%2d-%2d-%2d", &dd, &mm, &yy);
  154.             p = strtok (NULL, " ");
  155.             sscanf (p, "%2d:%2d", &hh, &ss);
  156.             rdate = ((yy - 80) << 9) | (mm << 5) | dd;
  157.             rtime = (hh << 11) | (ss << 5);
  158.             printf ("Release Time: %02d-%02d-%02d %02d:%02d\n", dd, mm, yy, hh, ss);
  159.          }
  160.       }
  161.       else if (!stricmp (p, "UPGRADE")) {
  162.          memset (&cr, 0, sizeof (COMPREC));
  163.          cr.action = UPGRADE;
  164.          write (fdout, &cr, sizeof (COMPREC));
  165.       }
  166.       else if (!stricmp (p, "NEWINSTALL")) {
  167.          memset (&cr, 0, sizeof (COMPREC));
  168.          cr.action = OVERWRITE;
  169.          write (fdout, &cr, sizeof (COMPREC));
  170.       }
  171.       else if (!stricmp (p, "STUBEXE")) {
  172.          p = strtok (NULL, " ");
  173.          printf ("Stub Executable: %s\n", p);
  174.  
  175.          if ((fdin = open (p, O_RDONLY|O_BINARY)) != -1) {
  176.             do {
  177.                m = read (fdin, &string, 170);
  178.                write (fdout, &string, m);
  179.             } while (m == 170);
  180.             stublen = filelength (fdin);
  181.             close (fdin);
  182.          }
  183.       }
  184.       else if (!stricmp (p, "SOURCE")) {
  185.          memset (&cr, 0, sizeof (COMPREC));
  186.  
  187.          cr.action = store ? STORED : UNPACK;
  188.  
  189.          path = strtok (NULL, " ");
  190.          p = strtok (NULL, " ");
  191.          newname = strtok (NULL, " ");
  192.  
  193.          printf ("Source Path: %s, FileSpec.: %s\n", path, p);
  194.  
  195.          sprintf (filename, "%s\\%s", path, p);
  196.          if (!findfirst (filename, &blk, 0))
  197.             do {
  198.                printf ("\r    > %-12s ", blk.ff_name);
  199.                if (newname != NULL && newname[0])
  200.                   strcpy (cr.filename, strlwr (newname));
  201.                else
  202.                   strcpy (cr.filename, strlwr (blk.ff_name));
  203.                sprintf (filename, "%s\\%s", path, blk.ff_name);
  204.                fdin = open (filename, O_RDONLY|O_BINARY);
  205.  
  206.                pos = tell (fdout);
  207.                write (fdout, &cr, sizeof (COMPREC));
  208.  
  209. //               if (!store) {
  210. //#ifndef __OS2__
  211. //                  type = CMP_BINARY;
  212. //                  dsize = 4096;
  213. //                  implode (ReadBuff, WriteBuff, WorkBuff, &type, &dsize);
  214. //#endif
  215. //               }
  216. //               else
  217.                   store_file (WorkBuff);
  218.  
  219.                cr.complen = tell (fdout) - pos - sizeof (COMPREC);
  220.                lseek (fdout, pos, SEEK_SET);
  221.                if (rtime == -1)
  222.                   _dos_getftime (fdin, &cr.fdate, &cr.ftime);
  223.                else {
  224.                   cr.fdate = rdate;
  225.                   cr.ftime = rtime;
  226.                }
  227.                write (fdout, &cr, sizeof (COMPREC));
  228.                lseek (fdout, 0L, SEEK_END);
  229.  
  230.                close (fdin);
  231.             } while (!findnext (&blk));
  232.          printf ("\r                       \r");
  233.       }
  234.       else if (!stricmp (p, "STAMPDATE")) {
  235.          memset (&cr, 0, sizeof (COMPREC));
  236.  
  237.          cr.action = STAMPDATE;
  238.  
  239.          newname = strtok (NULL, " ");
  240.          strcpy (cr.filename, strupr (newname));
  241.          cr.fdate = rdate;
  242.          cr.ftime = rtime;
  243.          write (fdout, &cr, sizeof (COMPREC));
  244.       }
  245.    }
  246.    fclose (fp);
  247.  
  248.    if (fdout != -1) {
  249.       if (stublen != -1L)
  250.          write (fdout, &stublen, 4);
  251.  
  252.       close (fdout);
  253.    }
  254. }
  255.  
  256.