home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Harvest C 1.3 / Source Code / emake.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-21  |  5.2 KB  |  160 lines  |  [TEXT/ALFA]

  1. /*
  2.  * Harvest C
  3.  * 
  4.  * Copyright 1991 Eric W. Sink   All rights reserved.
  5.  * 
  6.  * Built-in Make facility for Harvest C
  7.  * 
  8.  * 
  9.  */
  10.  
  11.  
  12. #include "conditcomp.h"
  13. #include <stdio.h>
  14. #include <string.h>
  15. #include "structs.h"
  16. #include "CHarvestDoc.h"
  17.  
  18. extern CHarvestDoc *gProject;
  19.  
  20. #pragma segment EMake
  21.  
  22. /*
  23.  * The built in make facility for Harvest C is based on the Harvest C project
  24.  * file.  A project file for Harvest C is a list of C source files,
  25.  * Libraries, and Resource files which must be included in a project.  The
  26.  * project file itself is a text file, containing one UNIX command line on
  27.  * each line of the file.
  28.  */
  29.  
  30. unsigned long
  31. GetFModDate(char *filename, short volrefnum, long dirID)
  32. {
  33.     HFileParam                      k;
  34.     Str255                          nm;
  35.     OSErr                           bad;
  36.     strcpy((char *) nm, filename);
  37.     c2pstr(nm);
  38.     k.ioCompletion = NULL;
  39.     k.ioNamePtr = nm;
  40.     k.ioVRefNum = volrefnum;
  41.     k.ioFDirIndex = 0;
  42.     k.ioDirID = dirID;
  43.     bad = PBHGetFInfo((HParmBlkPtr) & k, false);
  44.     if (!bad)
  45.     return k.ioFlMdDat;
  46.     else
  47.     return 0;
  48. }
  49.  
  50. void
  51. EMake(char *filename, short volrefnum, long dirID, int buildall)
  52. /* This routine accepts the Project file */
  53. {
  54.  
  55.     char                            comline[512];
  56.     GenericFileVia_t                thefile;
  57.     InFileVia_t                     FileList;
  58.     InFileVia_t                     newFileList = NULL;
  59.     InFileVia_t                     LinkList = NULL;
  60.     FSSpec                          filespec;
  61.     int                             argc = 1;
  62.     OSErr                           bad;
  63.     char                           *argv[50];
  64.     int                             CountCompiled = 0;
  65.     char                           *entry;
  66.     unsigned long                   MaxOMFDate = 0;
  67.     unsigned long                   AppDate;
  68.     CurVolrefnum = volrefnum;
  69.     CurDirID = dirID;
  70.     thefile = OpenGenericFile(filename, volrefnum, dirID, "r", 0);
  71.     if (thefile) {
  72.     int                             donefile = 0;
  73.     while (!donefile) {
  74.         GenericGetLine(thefile, comline);
  75.         argc = 1;
  76.         if (comline[0]) {
  77.         /*
  78.          * Now, divide comline into parts separated by spaces,
  79.          * storing the parts into argv[][]
  80.          */
  81.         entry = strtok(comline, " \n\r");
  82.         if (entry) {
  83.             if (entry[0] == '#')
  84.             entry = NULL;
  85.             else {
  86.             argv[argc] = (char *) NewPtr(strlen(entry) + 1);
  87.             strcpy(argv[argc++], entry);
  88.             }
  89.         }
  90.         while (entry) {
  91.             entry = strtok(NULL, " \n\r");
  92.             if (entry) {
  93.             if (entry[0] == '#')
  94.                 entry = NULL;
  95.             else {
  96.                 argv[argc] = (char *) NewPtr(strlen(entry) + 1);
  97.                 strcpy(argv[argc++], entry);
  98.             }
  99.             }
  100.         }
  101.         FileList = SetOpts(argc, argv);
  102.         newFileList = NULL;
  103.         while ((--argc) > 0) {
  104.             DisposPtr(argv[argc]);
  105.         }
  106.         /*
  107.          * Now, add all the files in the FileList, to the LinkList,
  108.          * then delete all the files from the FileList which are
  109.          * already up to date
  110.          */
  111.         {
  112.             InFileVia_t                     templist = FileList;
  113.             InFileVia_t                     newnode;
  114.             InFileVia_t                     newnode2;
  115.             Str255                          pnm;
  116.             unsigned long                   dateSRC;
  117.             unsigned long                   dateOMF;
  118.             while (templist) {
  119.             newnode = Ealloc(sizeof(InFile_t));
  120.             strcpy((char *) pnm, Via(templist)->fname);
  121.             strcpy(Via(newnode)->fname, (char *) pnm);
  122.             switch (pnm[strlen((char *) pnm) - 2]) {
  123.             case '.':
  124.                 switch (pnm[strlen((char *) pnm) - 1]) {
  125.                 case 'c':
  126.                 case 'm':    /* For ObjC */
  127.                 strcat(Via(newnode)->fname, ".o");
  128.                 /* fall thru */
  129.                 default:
  130.                 break;
  131.                 }
  132.                 break;
  133.             case 'r':
  134.                 switch (Via(newnode)->fname[strlen(Via(newnode)->fname) - 1]) {
  135.                 case 'c':
  136.                 /* This is a .rsrc file */
  137.                 break;
  138.                 default:
  139.                 break;
  140.                 }
  141.                 break;
  142.             default:
  143.                 break;
  144.             }
  145.             bad = FindCFile((char *) pnm, Via(templist)->volrefnum, Via(templist)->dirID, &filespec);
  146.             if (!bad) {
  147.                 Via(newnode)->volrefnum = filespec.vRefNum;
  148.                 Via(newnode)->dirID = filespec.parID;
  149.                 Via(newnode)->next = LinkList;
  150.                 LinkList = newnode;
  151.                 dateSRC = GetFModDate((char *) pnm, Via(newnode)->volrefnum, Via(newnode)->dirID);
  152.                 HLock((Handle) newnode);
  153.                 dateOMF = GetFModDate(Via(newnode)->fname, Via(newnode)->volrefnum, Via(newnode)->dirID);
  154.                 if (dateOMF > MaxOMFDate)
  155.                 MaxOMFDate = dateOMF;
  156.                 HUnlock((Handle) newnode);
  157.                 if (buildall || (dateSRC > dateOMF)) {
  158.                 CountCompiled++;
  159.                 newnode2 = Ealloc(sizeof(InFile_t));
  160.                 strcpy(Via(newnode2)->fname, (char