1: /* $Header: editmf.c,v 1.4 85/05/02 07:51:40 nicklin Exp $ */
   2: 
   3: /*
   4:  * Author: Peter J. Nicklin
   5:  */
   6: #include <ctype.h>
   7: #include <signal.h>
   8: #include <stdio.h>
   9: #include "Mkmf.h"
  10: #include "dlist.h"
  11: #include "hash.h"
  12: #include "macro.h"
  13: #include "null.h"
  14: #include "slist.h"
  15: #include "system.h"
  16: #include "yesno.h"
  17: 
  18: static char *Mftemp;            /* temporary makefile */
  19: 
  20: /*
  21:  * editmf() replaces macro definitions within a makefile.
  22:  */
  23: void
  24: editmf(mfname, mfpath)
  25:     char *mfname;           /* makefile name */
  26:     char *mfpath;           /* makefile template pathname */
  27: {
  28:     register char *bp;      /* buffer pointer */
  29:     extern char IOBUF[];        /* I/O buffer line */
  30:     extern int DEPEND;      /* dependency analysis? */
  31:     extern SLIST *EXTLIST;      /* external header file name list */
  32:     extern SLIST *HEADLIST;     /* header file name list */
  33:     extern SLIST *LIBLIST;      /* library pathname list */
  34:     extern SLIST *SRCLIST;      /* source file name list */
  35:     extern HASH *MDEFTABLE;     /* macro definition table */
  36:     char *findmacro();      /* is the line a macro definition? */
  37:     char *getlin();         /* get a line from input stream */
  38:     char *mktemp();         /* make file name */
  39:     char mnam[MACRONAMSIZE];    /* macro name buffer */
  40:     DLIST *dlp;         /* dependency list */
  41:     DLIST *mkdepend();      /* generate object-include file deps */
  42:     FILE *ifp;          /* input stream */
  43:     FILE *mustfopen();      /* must open file or die */
  44:     FILE *ofp;          /* output stream */
  45:     HASHBLK *htb;           /* hash table block */
  46:     HASHBLK *htlookup();        /* find hash table entry */
  47:     int cleanup();          /* remove temporary makefile and exit */
  48:     void dlprint();         /* print dependency list */
  49:     void purgcontinue();        /* get rid of continuation lines */
  50:     void putmacro();        /* put macro defs from table */
  51:     void putlin();          /* put a makefile line */
  52:     void putobjmacro();     /* put object file name macro def */
  53:     void putslmacro();      /* put macro defs from linked list */
  54: 
  55:     ifp = mustfopen(mfpath, "r");
  56:     Mftemp = mktemp("mkmfXXXXXX");
  57: 
  58:     signal(SIGHUP, cleanup);
  59:     signal(SIGINT, cleanup);
  60:     signal(SIGQUIT, cleanup);
  61: 
  62:     ofp = mustfopen(Mftemp, "w");
  63:     if (DEPEND)
  64:         {
  65:         dlp = mkdepend();
  66:         }
  67: 
  68:     while (getlin(ifp) != NULL)
  69:         {
  70:         if (DEPEND && EQUAL(IOBUF, DEPENDMARK))
  71:             break;
  72:         for (bp = IOBUF; *bp == ' '; bp++)
  73:             continue;
  74:         if (isalnum(*bp) && findmacro(mnam, bp) != NULL)
  75:             {
  76:             if ((htb = htlookup(mnam, MDEFTABLE)) != NULL)
  77:                 {
  78:                 if (htb->h_val == VREADWRITE)
  79:                     {
  80:                     putmacro(htb->h_def, ofp);
  81:                     purgcontinue(ifp);
  82:                     }
  83:                 else    {
  84:                     putlin(ofp);
  85:                     }
  86:                 }
  87:             else if (EQUAL(mnam, MHEADERS))
  88:                 {
  89:                 putslmacro(HEADLIST, ofp);
  90:                 purgcontinue(ifp);
  91:                 }
  92:             else if (EQUAL(mnam, MOBJECTS))
  93:                 {
  94:                 putobjmacro(ofp);
  95:                 purgcontinue(ifp);
  96:                 }
  97:             else if (EQUAL(mnam, MSOURCE))
  98:                 {
  99:                 putslmacro(SRCLIST, ofp);
 100:                 purgcontinue(ifp);
 101:                 }
 102:             else if (EQUAL(mnam, MEXTERNALS))
 103:                 {
 104:                 if (DEPEND)
 105:                     {
 106:                     putslmacro(EXTLIST, ofp);
 107:                     purgcontinue(ifp);
 108:                     }
 109:                 else    {
 110:                     putlin(ofp);
 111:                     }
 112:                 }
 113:             else if (EQUAL(mnam, MLIBLIST) && LIBLIST != NULL)
 114:                 {
 115:                 putslmacro(LIBLIST, ofp);
 116:                 purgcontinue(ifp);
 117:                 }
 118:             else    {
 119:                 putlin(ofp);
 120:                 }
 121:             }
 122:         else    {
 123:             putlin(ofp);
 124:             }
 125:         }
 126:     fclose(ifp);
 127:     if (DEPEND)
 128:         {
 129:         dlprint(dlp, ofp);
 130:         }
 131:     fclose(ofp);
 132: 
 133:     signal(SIGHUP, SIG_IGN);
 134:     signal(SIGINT, SIG_IGN);
 135:     signal(SIGQUIT, SIG_IGN);
 136: 
 137:     RENAME(Mftemp, mfname);
 138: }
 139: 
 140: 
 141: 
 142: /*
 143:  * cleanup() removes the temporary makefile and dependency file, and
 144:  * calls exit(1).
 145:  */
 146: cleanup()
 147: {
 148:     signal(SIGHUP, cleanup);
 149:     signal(SIGINT, cleanup);
 150:     signal(SIGQUIT, cleanup);
 151: 
 152:     unlink(Mftemp);
 153:     exit(1);
 154: }

Defined functions

cleanup defined in line 146; used 27 times
editmf defined in line 23; used 2 times

Defined variables

Mftemp defined in line 18; used 4 times
Last modified: 1985-07-03
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1244
Valid CSS Valid XHTML 1.0 Strict