home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / INSTALL2.TD0 / SOURCES.LIF / INSTALL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-27  |  6.2 KB  |  192 lines

  1. /*=============================================================================
  2.  
  3.      The INSTALL program source code, object code, sample  script files,
  4.      executable  program,  and  documentation  are  subject to copyright
  5.      protection under the laws of the United States and other countries.
  6.  
  7.      This software is licensed, not sold, and may only be  redistributed
  8.      in  executable format and only in accordance with the provisions of
  9.      the INSTALL Source Code License Agreement.
  10.  
  11.         INSTALL is Copyright(C) 1987-1990 by Knowledge Dynamics Corp
  12.        Highway Contract 4 Box 185-H, Canyon Lake, TX (USA) 78133-3508
  13.               512-964-3994 (Voice)   512-964-3958 (24-hr FAX)
  14.  
  15.                       All rights reserved worldwide.
  16.  
  17. ===============================================================================
  18.  
  19. FILENAME:
  20.     install.c
  21.  
  22. AUTHOR:
  23.     eric jon heflin
  24.  
  25. PUBLIC FUNCTIONS:
  26.     install() - master file copy function
  27.     disk_avail() - get free disk space after adding overwritten file space
  28.  
  29. LOCAL FUNCTIONS:
  30.     none
  31.  
  32. DESCRIPTION:
  33.     This file first checks to see if there is enough available space on the
  34.     target drive and then either copies the specified files, or if there is
  35.     insufficient space, it notify the user.  If the target drive is
  36.     non-removable, then the end-user is told to install onto another drive,
  37.     or to free up ##### bytes of disk space.  If the target drive is a
  38.     removable drive, then the end-user is given the additional option of
  39.     replacing the output disk.
  40.  
  41. REVISION HISTORY:
  42.     DATE:    AUTHOR:            DESCRIPTION OF CHANGES:
  43.     891030    allyn jordan    Beginning of detailed documentation.
  44.     891116    ejh                Added code to handle ambiguous filename specifiers 
  45.                             for library files.
  46.     900102    ejh                Cosmetic changes.
  47.  
  48. ==============================================================================*/
  49.  
  50. #include "install.h"
  51. #include <string.h>
  52. #include <assert.h>
  53.  
  54. void install(project)
  55. project_t *project;
  56.     {                    /* install */
  57.     disk_t *disk;        /* input disk pointer */
  58.     file_t *file;
  59.     file_t *f;
  60.     unsigned long needed, have;
  61.  
  62.     /*
  63.      *    Algorithm: Check for adequate free disk space on the output drive
  64.      *    using a lazy algorithm which only checks for space before writing
  65.      *    the first output file to that disk.
  66.      *
  67.      *    This is necessary since the input drive and output drive may be the
  68.      *    same, and future versions of INSTALL will probably support an
  69.      *    unlimited number of output drives.
  70.      */
  71.  
  72.     /*
  73.      *    Loop to determine if adequate free space exists on the output drive.
  74.      *    This loop is only executed for non-removable disks.
  75.      */
  76.     if (!project->removable)
  77.         {
  78.         have = disk_avail(project->out_drive, project->subdir, project->disk, project->disk->file);
  79.         needed = project->requirement;
  80.  
  81.         /* see if adequate space was found */
  82.         if (needed > have)
  83.             {
  84.             wputs(message_w, "The disk in output drive %c: does not have enough space to install", project->out_drive);
  85.             wputs(message_w, "%s.", project->name);
  86.             if (project->removable)
  87.                 {
  88.                 wputs(message_w, NULL);
  89.                 wputs(message_w, "Please place a disk with at least %lu bytes free in drive %c:", project->requirement, project->out_drive);
  90.                 wputs(message_w, "or press [Esc] to abort ...");
  91.                 put_message(message_w);
  92.                 project->out_free = disk_free(project->out_drive);
  93.                 project->out_size = disk_size(project->out_drive);
  94.                 }        /* removable */
  95.             else 
  96.                 {        /* fixed */
  97.                 wputs(message_w, NULL);
  98.                 wputs(message_w, "Since the output disk is non-removable, in order to install");
  99.                 wputs(message_w, "this product you will have to 1) free up %lu bytes of space", needed - have);
  100.                 wputs(message_w, "on this disk, or 2) install onto another drive.");
  101.                 put_message(message_w);
  102.                 bye();
  103.                 }
  104.             /*
  105.             wputs(error_w, "The minimum required free space is: %lu bytes\n", needed);
  106.             wputs(error_w, "Drive %c: only has %lu bytes free\n", project->out_drive, have);
  107.             wputs(error_w, NULL);
  108.             wputs(error_w, "You should either free up some disk space, or");
  109.             wputs(error_w, "only install part of this product.");
  110.             put_error(error_w);
  111.             */
  112.             }            /* if we don't have enough disk space */
  113.         }                /* if outdrive is fixed */
  114.  
  115.     /* for loop to copy all distribution disks */
  116.     for (disk = project->disk;  disk != NULL;  disk = disk->next)
  117.         {
  118.         /* for loop to copy all files on one distribution disk */
  119.         for (file = disk->file;  file != NULL;  file = file->next)
  120.             {
  121.             if (file->type == PARENT && file->sub != NULL)
  122.                 {
  123.                 /* this file is a library file */
  124.                 /* first, open lib and read all header info */
  125.                 copy_file(project, disk, file, &have);
  126.                 /* for loop to copy each each library file */
  127.                 for (f = file->sub;  f != NULL;  f = f->next)
  128.                     copy_file(project, disk, f, &have);
  129.                 continue;
  130.                 }
  131.             else if (file->type != PARENT)
  132.                 copy_file(project, disk, file, &have);
  133.             }            /* copy file loop */
  134.         }                /* copy disk loop */
  135.     }        /* install() proper */
  136.  
  137.  
  138. /* determine logically available space on disk */
  139.  
  140. unsigned long disk_avail(byte drive, byte *dir, disk_t * disk, file_t * file)
  141.     {                    /* disk_avail */
  142.     unsigned long have = 0L;
  143.     file_t *f, *temp_f;
  144.     byte temp_n[100];
  145.     disk_t *d;
  146.  
  147.     if (disk == NULL)
  148.         return 0L;
  149.  
  150.     have = disk_free(drive);
  151.  
  152.     /*
  153.      *    process each disk, starting with file f on disk d.
  154.      */
  155.     for (d = disk,  f = file;  d != NULL;  d = d->next)
  156.         {
  157.         f = d->file;
  158.         /*
  159.          *    process each file on disk d.
  160.          */
  161.         for (temp_f = f;  temp_f != NULL;  temp_f = temp_f->next)
  162.             {
  163.             if (temp_f->type == PARENT)
  164.                 {
  165.                 /* this is a library */
  166.                 for (f = temp_f->sub;  f != NULL;  f = f->next)
  167.                     {
  168.                     if (!f->abs)
  169.                         sprintf(temp_n, "%c:%s%s", drive, dir, f->out_fname);
  170.                     else 
  171.                         strcpy(temp_n, f->out_fname);
  172.                     /* if file exists, add its size to avail disk space */
  173.                     have += (ulong)findsize(temp_n);
  174.                     }
  175.                 }
  176.             else 
  177.                 {
  178.                 if (!temp_f->abs)
  179.                     sprintf(temp_n, "%c:%s%s", drive, dir, temp_f->out_fname);
  180.                 else 
  181.                     strcpy(temp_n, temp_f->out_fname);
  182.                 /* if file exists, add its size to avail disk space */
  183.                 have += (ulong)findsize(temp_n);
  184.                 }
  185.             }            /* for all output files */
  186.         }                /* for loop to check for disk space */
  187.     return have;
  188.     }        /* disk_avail */
  189.  
  190.  
  191. /* end-of-file */
  192.