home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume27 / dmake / part29 < prev    next >
Encoding:
Text File  |  1992-01-29  |  40.0 KB  |  1,446 lines

  1. Newsgroups: comp.sources.misc
  2. From: dvadura@plg.waterloo.edu (Dennis Vadura)
  3. Subject:  v27i130:  dmake - dmake Version 3.8, Part29/41
  4. Message-ID: <1992Jan28.214901.20152@sparky.imd.sterling.com>
  5. X-Md4-Signature: 76e348ec0071479ffadee1ac79f2ee82
  6. Date: Tue, 28 Jan 1992 21:49:01 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: dvadura@plg.waterloo.edu (Dennis Vadura)
  10. Posting-number: Volume 27, Issue 130
  11. Archive-name: dmake/part29
  12. Environment: Atari-ST, Coherent, Mac, MSDOS, OS/2, UNIX
  13. Supersedes: dmake: Volume 19, Issue 22-58
  14.  
  15. ---- Cut Here and feed the following to sh ----
  16. # this is dmake.shar.29 (part 29 of a multipart archive)
  17. # do not concatenate these parts, unpack them in order with /bin/sh
  18. # file dmake/os2/mscdos/startup.mk continued
  19. #
  20. if test ! -r _shar_seq_.tmp; then
  21.     echo 'Please unpack part 1 first!'
  22.     exit 1
  23. fi
  24. (read Scheck
  25.  if test "$Scheck" != 29; then
  26.     echo Please unpack part "$Scheck" next!
  27.     exit 1
  28.  else
  29.     exit 0
  30.  fi
  31. ) < _shar_seq_.tmp || exit 1
  32. if test -f _shar_wnt_.tmp; then
  33. sed 's/^X//' << 'SHAR_EOF' >> 'dmake/os2/mscdos/startup.mk' &&
  34. #       and is found in os2/mscdos/dmake.ini
  35. .INCLUDE : "os2/mscdos/dmake.ini"
  36. SHAR_EOF
  37. chmod 0640 dmake/os2/mscdos/startup.mk ||
  38. echo 'restore of dmake/os2/mscdos/startup.mk failed'
  39. Wc_c="`wc -c < 'dmake/os2/mscdos/startup.mk'`"
  40. test 132 -eq "$Wc_c" ||
  41.     echo 'dmake/os2/mscdos/startup.mk: original size 132, current size' "$Wc_c"
  42. rm -f _shar_wnt_.tmp
  43. fi
  44. # ============= dmake/os2/mscdos/tempnam.c ==============
  45. if test -f 'dmake/os2/mscdos/tempnam.c' -a X"$1" != X"-c"; then
  46.     echo 'x - skipping dmake/os2/mscdos/tempnam.c (File already exists)'
  47.     rm -f _shar_wnt_.tmp
  48. else
  49. > _shar_wnt_.tmp
  50. sed 's/^X//' << 'SHAR_EOF' > 'dmake/os2/mscdos/tempnam.c' &&
  51. /*LINTLIBRARY*/
  52. #include <stdio.h>
  53. #include <string.h>
  54. #include <stdlib.h>
  55. #include <dos.h>
  56. X
  57. #if defined(max)
  58. #   undef  max
  59. #endif
  60. #define max(A,B) (((A)<(B))?(B):(A))
  61. X
  62. extern int access();
  63. int _access();
  64. X
  65. /* MSC stdio.h defines P_tmpdir, so let's undo it here */
  66. /* Under DOS leave the default tmpdir pointing here!        */
  67. #ifdef P_tmpdir
  68. #undef P_tmpdir
  69. #endif
  70. static char *P_tmpdir = "";
  71. X
  72. char *
  73. tempnam(dir, prefix)
  74. char *dir;        /* use this directory please (if non-NULL) */
  75. char *prefix;        /* use this (if non-NULL) as filename prefix */
  76. {
  77. X   static         int count = 0;
  78. X   register char *p, *q, *tmpdir;
  79. X   int            tl=0, dl=0, pl;
  80. X   char          buf[30];
  81. X
  82. X   pl = strlen(P_tmpdir);
  83. X
  84. X   if( (tmpdir = getenv("TMPDIR")) != NULL )
  85. X      tl = strlen(tmpdir);
  86. X   else if( (tmpdir = getenv("TMP")) != NULL )
  87. X      tl = strlen(tmpdir);
  88. X   if( dir != NULL ) dl = strlen(dir);
  89. X
  90. X   if( (p = malloc((unsigned)(max(max(dl,tl),pl)+13))) == NULL )
  91. X     return(NULL);
  92. X
  93. X   *p = '\0';
  94. X
  95. X   if( (tl == 0) || (_access( strcpy(p, tmpdir), 0) != 0) )
  96. X     if( (dl == 0) || (_access( strcpy(p, dir), 0) != 0) )
  97. X    if( _access( strcpy(p, P_tmpdir), 0) != 0 )
  98. X       if( !prefix )
  99. X          prefix = "tp";
  100. X
  101. X   if(prefix)
  102. X   {
  103. X      *(p+strlen(p)+2) = '\0';
  104. X      (void)strncat(p, prefix, 2);
  105. X   }
  106. X
  107. #ifdef OS2
  108. X   sprintf( buf, "%08x", getpid() );
  109. #else
  110. X   sprintf( buf, "%08x", _psp );
  111. #endif
  112. X   buf[6]='\0';
  113. X   (void)strcat(p, buf );
  114. X   sprintf( buf, "%04d", count++ );
  115. X   q=p+strlen(p)-6;
  116. X   *q++ = buf[0]; *q++ = buf[1];
  117. X   *q++ = buf[2]; *q++ = buf[3];
  118. X
  119. X   if( (q = strrchr(p,'.')) != NULL ) *q = '\0';
  120. X
  121. X   return strlwr(p);
  122. }
  123. X
  124. X
  125. X
  126. _access( name, flag )
  127. char *name;
  128. int  flag;
  129. {
  130. X   char *p;
  131. X   int r;
  132. X
  133. X   if( name == NULL || !*name ) return(1);  /* NULL dir means current dir */
  134. X   p = name+strlen(name)-1;
  135. X   if(*p == ':' ) strcat( p++, "\\" );
  136. X   r = access( name, flag );
  137. X   if(*p != '/' && *p != '\\') strcat( p, "\\" );
  138. X
  139. X   return( r );
  140. }
  141. SHAR_EOF
  142. chmod 0640 dmake/os2/mscdos/tempnam.c ||
  143. echo 'restore of dmake/os2/mscdos/tempnam.c failed'
  144. Wc_c="`wc -c < 'dmake/os2/mscdos/tempnam.c'`"
  145. test 1919 -eq "$Wc_c" ||
  146.     echo 'dmake/os2/mscdos/tempnam.c: original size 1919, current size' "$Wc_c"
  147. rm -f _shar_wnt_.tmp
  148. fi
  149. # ============= dmake/os2/optoff.h ==============
  150. if test -f 'dmake/os2/optoff.h' -a X"$1" != X"-c"; then
  151.     echo 'x - skipping dmake/os2/optoff.h (File already exists)'
  152.     rm -f _shar_wnt_.tmp
  153. else
  154. > _shar_wnt_.tmp
  155. sed 's/^X//' << 'SHAR_EOF' > 'dmake/os2/optoff.h' &&
  156. #if _MSC_VER < 600
  157. # pragma loop_opt(off)
  158. #endif
  159. SHAR_EOF
  160. chmod 0640 dmake/os2/optoff.h ||
  161. echo 'restore of dmake/os2/optoff.h failed'
  162. Wc_c="`wc -c < 'dmake/os2/optoff.h'`"
  163. test 49 -eq "$Wc_c" ||
  164.     echo 'dmake/os2/optoff.h: original size 49, current size' "$Wc_c"
  165. rm -f _shar_wnt_.tmp
  166. fi
  167. # ============= dmake/os2/ruletab.c ==============
  168. if test -f 'dmake/os2/ruletab.c' -a X"$1" != X"-c"; then
  169.     echo 'x - skipping dmake/os2/ruletab.c (File already exists)'
  170.     rm -f _shar_wnt_.tmp
  171. else
  172. > _shar_wnt_.tmp
  173. sed 's/^X//' << 'SHAR_EOF' > 'dmake/os2/ruletab.c' &&
  174. /* RCS      -- $Header: /u2/dvadura/src/generic/dmake/src/os2/ruletab.c,v 1.1 1992/01/24 03:29:18 dvadura Exp $
  175. -- SYNOPSIS -- Default initial configuration of dmake.
  176. -- 
  177. -- DESCRIPTION
  178. --     Define here the initial set of rules that are defined before
  179. --    dmake performs any processing.
  180. --
  181. -- AUTHOR
  182. --      Dennis Vadura, dvadura@watdragon.uwaterloo.ca
  183. --      CS DEPT, University of Waterloo, Waterloo, Ont., Canada
  184. --
  185. -- COPYRIGHT
  186. --      Copyright (c) 1990 by Dennis Vadura.  All rights reserved.
  187. -- 
  188. --      This program is free software; you can redistribute it and/or
  189. --      modify it under the terms of the GNU General Public License
  190. --      (version 1), as published by the Free Software Foundation, and
  191. --      found in the file 'LICENSE' included with this distribution.
  192. -- 
  193. --      This program is distributed in the hope that it will be useful,
  194. --      but WITHOUT ANY WARRANTY; without even the implied warrant of
  195. --      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  196. --      GNU General Public License for more details.
  197. -- 
  198. --      You should have received a copy of the GNU General Public License
  199. --      along with this program;  if not, write to the Free Software
  200. --      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  201. --
  202. -- LOG
  203. --     $Log: ruletab.c,v $
  204. X * Revision 1.1  1992/01/24  03:29:18  dvadura
  205. X * dmake Version 3.8, Initial revision
  206. X *
  207. */
  208. X
  209. /* These are control macros for dmake that MUST be defined at some point
  210. X * if they are NOT dmake will not work!  These are default definitions.  They
  211. X * may be overridden inside the .STARTUP makefile, they are here
  212. X * strictly so that dmake can parse the STARTUP makefile */
  213. /*
  214. X * For OS/2 these are close to the Unix definitions in terms of limits.
  215. X * We dont need the two different cases of Makefile, so only keep the
  216. X * pretty one.
  217. X */
  218. static char *_rules[] = {
  219. X    "MAXLINELENGTH := 2046",
  220. X    "MAXPROCESSLIMIT := 16",
  221. X    ".IMPORT .IGNORE: ROOTDIR INIT",
  222. X    ".MAKEFILES : makefile.mk Makefile",
  223. X    ".SOURCE    : .NULL",
  224. #include "startup.h"
  225. X    0 };
  226. X
  227. char **Rule_tab = _rules; /* for sundry reasons in Get_environment() */
  228. X
  229. SHAR_EOF
  230. chmod 0640 dmake/os2/ruletab.c ||
  231. echo 'restore of dmake/os2/ruletab.c failed'
  232. Wc_c="`wc -c < 'dmake/os2/ruletab.c'`"
  233. test 2107 -eq "$Wc_c" ||
  234.     echo 'dmake/os2/ruletab.c: original size 2107, current size' "$Wc_c"
  235. rm -f _shar_wnt_.tmp
  236. fi
  237. # ============= dmake/os2/runargv.c ==============
  238. if test -f 'dmake/os2/runargv.c' -a X"$1" != X"-c"; then
  239.     echo 'x - skipping dmake/os2/runargv.c (File already exists)'
  240.     rm -f _shar_wnt_.tmp
  241. else
  242. > _shar_wnt_.tmp
  243. sed 's/^X//' << 'SHAR_EOF' > 'dmake/os2/runargv.c' &&
  244. /* RCS      -- $Header: /u2/dvadura/src/generic/dmake/src/os2/runargv.c,v 1.1 1992/01/24 03:29:19 dvadura Exp $
  245. -- SYNOPSIS -- invoke a sub process, modified unix/runargv.c for OS/2.
  246. -- 
  247. -- DESCRIPTION
  248. --     Use the standard methods of executing a sub process.
  249. --
  250. -- AUTHOR
  251. --      Dennis Vadura, dvadura@watdragon.uwaterloo.ca
  252. --      CS DEPT, University of Waterloo, Waterloo, Ont., Canada
  253. --
  254. -- COPYRIGHT
  255. --      Copyright (c) 1990 by Dennis Vadura.  All rights reserved.
  256. -- 
  257. --      This program is free software; you can redistribute it and/or
  258. --      modify it under the terms of the GNU General Public License
  259. --      (version 1), as published by the Free Software Foundation, and
  260. --      found in the file 'LICENSE' included with this distribution.
  261. -- 
  262. --      This program is distributed in the hope that it will be useful,
  263. --      but WITHOUT ANY WARRANTY; without even the implied warrant of
  264. --      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  265. --      GNU General Public License for more details.
  266. -- 
  267. --      You should have received a copy of the GNU General Public License
  268. --      along with this program;  if not, write to the Free Software
  269. --      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  270. --
  271. -- LOG
  272. --     $Log: runargv.c,v $
  273. X * Revision 1.1  1992/01/24  03:29:19  dvadura
  274. X * dmake Version 3.8, Initial revision
  275. X *
  276. */
  277. X
  278. #define INCL_DOSPROCESS
  279. #include <os2.h>
  280. X
  281. #include <process.h>
  282. #include <stdlib.h>
  283. #include <signal.h>
  284. #include "extern.h"
  285. #include "sysintf.h"
  286. X
  287. typedef struct prp {
  288. X   char *prp_cmd;
  289. X   int   prp_group;
  290. X   int   prp_ignore;
  291. X   int   prp_last;
  292. X   int     prp_shell;
  293. X   struct prp *prp_next;
  294. } RCP, *RCPPTR;
  295. X
  296. typedef struct pr {
  297. X   int        pr_valid;
  298. X   int        pr_pid;
  299. X   CELLPTR    pr_target;
  300. X   int        pr_ignore;
  301. X   int        pr_last;
  302. X   RCPPTR      pr_recipe;
  303. X   RCPPTR      pr_recipe_end;
  304. X   char        *pr_dir;
  305. } PR;
  306. X
  307. static PR  *_procs    = NIL(PR);
  308. static int  _proc_cnt = 0;
  309. static int  _abort_flg= FALSE;
  310. static int  _use_i    = -1;
  311. static int  _do_upd   = 0;
  312. X
  313. extern unsigned int _far _pascal DosSmSetTitle(char _far *s);
  314. static  void    SetSessionTitle (char *s);
  315. static  void    _add_child ANSI((int, CELLPTR, int, int));
  316. static  void    _attach_cmd ANSI((char *, int, int, CELLPTR, int, int));
  317. static  void    _finished_child ANSI((int, int));
  318. static  int     _running ANSI((CELLPTR));
  319. X
  320. PUBLIC int
  321. runargv(target, ignore, group, last, shell, cmd)
  322. CELLPTR target;
  323. int     ignore;
  324. int    group;
  325. int    last;
  326. int     shell;
  327. char    *cmd;
  328. {
  329. X   int          pid;
  330. X   char         **argv;
  331. X
  332. X   if( _running(target) /*&& Max_proc != 1*/ ) {
  333. X      /* The command will be executed when the previous recipe
  334. X       * line completes. */
  335. X      _attach_cmd( cmd, group, ignore, target, last, shell );
  336. X      return(1);
  337. X   }
  338. X
  339. X   while( _proc_cnt == Max_proc )
  340. X      if( Wait_for_child(FALSE, -1) == -1 )  Fatal( "Lost a child" );
  341. X
  342. #ifdef SESSTITLE
  343. X   SetSessionTitle(target->CE_NAME);
  344. #endif
  345. X   argv = Pack_argv( group, shell, cmd );
  346. X
  347. X   if((pid=spawnvp((_osmode == DOS_MODE)?P_WAIT:P_NOWAIT,argv[0],argv)) == -1){
  348. X      Error("%s: %s", argv[0], sys_errlist[errno]);
  349. X      Handle_result(-1, ignore, _abort_flg, target);
  350. X      return(-1);
  351. X   }
  352. X   else if( _osmode == DOS_MODE ) {
  353. X     _add_child(4711, target, ignore, last);
  354. X     _finished_child(4711, pid);
  355. X   }
  356. X   else
  357. X     _add_child(pid, target, ignore, last);
  358. X
  359. X   return(1);
  360. }
  361. X
  362. X
  363. #ifdef SESSTITLE
  364. /* N.B. The system call used below is undocumented and therefore possibly
  365. X * subject to change. It sets the session title even from a full screen
  366. X * session, so you can see which target is being built.
  367. X * If dubious about undocumented calls simply remove it.
  368. X */
  369. PUBLIC void
  370. SetSessionTitle(char *s)
  371. {
  372. X   char buff[128];
  373. X   strncpy(buff, Pname, sizeof(buff));
  374. X   buff[sizeof(buff)-1] = 0;
  375. X   strncat(buff, " - ", sizeof(buff));
  376. X   strncat(buff, s, sizeof(buff));
  377. X   buff[sizeof(buff)-1] = 0;
  378. X   DosSmSetTitle(buff);
  379. }
  380. #endif
  381. X
  382. X
  383. PUBLIC int
  384. Wait_for_child( abort_flg, pid )
  385. int abort_flg;
  386. int pid;
  387. {
  388. X   int wid;
  389. X   int status;
  390. X   int waitchild;
  391. X
  392. X   if( _osmode == DOS_MODE ) return(1);
  393. X
  394. X   waitchild = (pid == -1)? FALSE : Wait_for_completion;
  395. X
  396. X   do {
  397. X      if( (wid = wait(&status)) == -1 ) return(-1);
  398. X
  399. X      _abort_flg = abort_flg;
  400. X      _finished_child(wid, status);
  401. X      _abort_flg = FALSE;
  402. X   }
  403. X   while( waitchild && pid != wid );
  404. X
  405. X   return(0);
  406. }
  407. X
  408. X
  409. PUBLIC void
  410. Clean_up_processes()
  411. {
  412. X   register int i;
  413. X
  414. X   if( _osmode == DOS_MODE ) {
  415. X      _abort_flg = TRUE;
  416. X      _finished_child(4711, -1);
  417. X      return;
  418. X   }
  419. X
  420. X   if( _procs != NIL(PR) ) {
  421. X      for( i=0; i<Max_proc; i++ )
  422. X     if( _procs[i].pr_valid )
  423. X        DosKillProcess(DKP_PROCESSTREE, _procs[i].pr_pid);
  424. X
  425. X      while( Wait_for_child(TRUE, -1) != -1 );
  426. X   }
  427. }
  428. X
  429. X
  430. static void
  431. _add_child( pid, target, ignore, last )
  432. int    pid;
  433. CELLPTR target;
  434. int    ignore;
  435. int     last;
  436. {
  437. X   register int i;
  438. X   register PR *pp;
  439. X
  440. X   if( _procs == NIL(PR) ) {
  441. X      TALLOC( _procs, Max_proc, PR );
  442. X   }
  443. X
  444. X   if( (i = _use_i) == -1 )
  445. X      for( i=0; i<Max_proc; i++ )
  446. X     if( !_procs[i].pr_valid )
  447. X        break;
  448. X
  449. X   pp = _procs+i;
  450. X
  451. X   pp->pr_valid  = 1;
  452. X   pp->pr_pid    = pid;
  453. X   pp->pr_target = target;
  454. X   pp->pr_ignore = ignore;
  455. X   pp->pr_last   = last;
  456. X   pp->pr_dir    = _strdup(Get_current_dir());
  457. X
  458. X   Current_target = NIL(CELL);
  459. X
  460. X   _proc_cnt++;
  461. X
  462. X   if( Wait_for_completion ) Wait_for_child( FALSE, pid );
  463. }
  464. X
  465. X
  466. static void
  467. _finished_child(pid, status)
  468. int    pid;
  469. int    status;
  470. {
  471. X   register int i;
  472. X   register PR *pp;
  473. X   char     *dir;
  474. X
  475. X   for( i=0; i<Max_proc; i++ )
  476. X      if( _procs[i].pr_valid && _procs[i].pr_pid == pid )
  477. X     break;
  478. X
  479. X   /* Some children we didn't make esp true if using /bin/sh to execute a
  480. X    * a pipe and feed the output as a makefile into dmake. */
  481. X   if( i == Max_proc ) return;
  482. X   _procs[i].pr_valid = 0;
  483. X   _proc_cnt--;
  484. X   dir = _strdup(Get_current_dir());
  485. X   Set_dir( _procs[i].pr_dir );
  486. X
  487. X   if( _procs[i].pr_recipe != NIL(RCP) && !_abort_flg ) {
  488. X      RCPPTR rp = _procs[i].pr_recipe;
  489. X
  490. X
  491. X      Current_target = _procs[i].pr_target;
  492. X      Handle_result( status, _procs[i].pr_ignore, FALSE, _procs[i].pr_target );
  493. X      Current_target = NIL(CELL);
  494. X
  495. X      _procs[i].pr_recipe = rp->prp_next;
  496. X
  497. X      _use_i = i;
  498. X      runargv( _procs[i].pr_target, rp->prp_ignore, rp->prp_group,
  499. X           rp->prp_last, rp->prp_shell, rp->prp_cmd );
  500. X      _use_i = -1;
  501. X
  502. X      FREE( rp->prp_cmd );
  503. X      FREE( rp );
  504. X
  505. X      if( _proc_cnt == Max_proc ) Wait_for_child( FALSE, -1 );
  506. X   }
  507. X   else {
  508. X      Unlink_temp_files( _procs[i].pr_target );
  509. X      Handle_result(status,_procs[i].pr_ignore,_abort_flg,_procs[i].pr_target);
  510. X
  511. X      if( _procs[i].pr_last ) {
  512. X     FREE(_procs[i].pr_dir );
  513. X
  514. X     if( !Doing_bang ) Update_time_stamp( _procs[i].pr_target );
  515. X      }
  516. X   }
  517. X
  518. X   Set_dir(dir);
  519. X   FREE(dir);
  520. }
  521. X
  522. X
  523. static int
  524. _running( cp )
  525. CELLPTR cp;
  526. {
  527. X   register int i;
  528. X
  529. X   if( !_procs ) return(FALSE);
  530. X
  531. X   for( i=0; i<Max_proc; i++ )
  532. X      if( _procs[i].pr_valid &&
  533. X      _procs[i].pr_target == cp  )
  534. X     break;
  535. X     
  536. X   return( i != Max_proc );
  537. }
  538. X
  539. X
  540. static void
  541. _attach_cmd( cmd, group, ignore, cp, last, shell )
  542. char    *cmd;
  543. int    group;
  544. int     ignore;
  545. CELLPTR cp;
  546. int     last;
  547. int     shell;
  548. {
  549. X   register int i;
  550. X   RCPPTR rp;
  551. X
  552. X   for( i=0; i<Max_proc; i++ )
  553. X      if( _procs[i].pr_valid &&
  554. X      _procs[i].pr_target == cp  )
  555. X     break;
  556. X
  557. X   TALLOC( rp, 1, RCP );
  558. X   rp->prp_cmd   = _strdup(cmd);
  559. X   rp->prp_group = group;
  560. X   rp->prp_ignore= ignore;
  561. X   rp->prp_last  = last;
  562. X   rp->prp_shell = shell;
  563. X
  564. X   if( _procs[i].pr_recipe == NIL(RCP) )
  565. X      _procs[i].pr_recipe = _procs[i].pr_recipe_end = rp;
  566. X   else {
  567. X      _procs[i].pr_recipe_end->prp_next = rp;
  568. X      _procs[i].pr_recipe_end = rp;
  569. X   }
  570. }
  571. SHAR_EOF
  572. chmod 0640 dmake/os2/runargv.c ||
  573. echo 'restore of dmake/os2/runargv.c failed'
  574. Wc_c="`wc -c < 'dmake/os2/runargv.c'`"
  575. test 7573 -eq "$Wc_c" ||
  576.     echo 'dmake/os2/runargv.c: original size 7573, current size' "$Wc_c"
  577. rm -f _shar_wnt_.tmp
  578. fi
  579. # ============= dmake/os2/startup.h ==============
  580. if test -f 'dmake/os2/startup.h' -a X"$1" != X"-c"; then
  581.     echo 'x - skipping dmake/os2/startup.h (File already exists)'
  582.     rm -f _shar_wnt_.tmp
  583. else
  584. > _shar_wnt_.tmp
  585. sed 's/^X//' << 'SHAR_EOF' > 'dmake/os2/startup.h' &&
  586. /* This file contains the default value of the MAKESTARTUP variable.
  587. X * You must set the quoted string below to the default path to the startup
  588. X * variable, so that it gets compiled in.  LEAVE ROOTDIR at the front of
  589. X * the path.  This allows the user to customize his environment for dmake
  590. X * by setting up a new ROOTDIR environment variable. */
  591. X
  592. "MAKESTARTUP := $(INIT)/dmake.ini",
  593. SHAR_EOF
  594. chmod 0640 dmake/os2/startup.h ||
  595. echo 'restore of dmake/os2/startup.h failed'
  596. Wc_c="`wc -c < 'dmake/os2/startup.h'`"
  597. test 384 -eq "$Wc_c" ||
  598.     echo 'dmake/os2/startup.h: original size 384, current size' "$Wc_c"
  599. rm -f _shar_wnt_.tmp
  600. fi
  601. # ============= dmake/os2/stdarg.h ==============
  602. if test -f 'dmake/os2/stdarg.h' -a X"$1" != X"-c"; then
  603.     echo 'x - skipping dmake/os2/stdarg.h (File already exists)'
  604.     rm -f _shar_wnt_.tmp
  605. else
  606. > _shar_wnt_.tmp
  607. sed 's/^X//' << 'SHAR_EOF' > 'dmake/os2/stdarg.h' &&
  608. /*
  609. X * stdarg.h
  610. X *
  611. X * defines ANSI style macros for accessing arguments of a function which takes
  612. X * a variable number of arguments
  613. X *
  614. X */
  615. X
  616. #if !defined(__STDARG)
  617. #define __STDARG
  618. X
  619. typedef char *va_list;
  620. X
  621. #define va_dcl int va_alist
  622. #define va_start(ap,v)  ap = (va_list)&va_alist
  623. #define va_arg(ap,t)    ((t*)(ap += sizeof(t)))[-1]
  624. #define va_end(ap)      ap = NULL
  625. #endif
  626. SHAR_EOF
  627. chmod 0640 dmake/os2/stdarg.h ||
  628. echo 'restore of dmake/os2/stdarg.h failed'
  629. Wc_c="`wc -c < 'dmake/os2/stdarg.h'`"
  630. test 373 -eq "$Wc_c" ||
  631.     echo 'dmake/os2/stdarg.h: original size 373, current size' "$Wc_c"
  632. rm -f _shar_wnt_.tmp
  633. fi
  634. # ============= dmake/os2/switchar.c ==============
  635. if test -f 'dmake/os2/switchar.c' -a X"$1" != X"-c"; then
  636.     echo 'x - skipping dmake/os2/switchar.c (File already exists)'
  637.     rm -f _shar_wnt_.tmp
  638. else
  639. > _shar_wnt_.tmp
  640. sed 's/^X//' << 'SHAR_EOF' > 'dmake/os2/switchar.c' &&
  641. /*
  642. ** return switch char
  643. */
  644. #if defined(OS2) || defined(_MSC_VER)
  645. #include <stdlib.h>
  646. #endif
  647. #if !defined(OS2)
  648. #include <dos.h>
  649. #endif /* !OS2 */
  650. #include <stdio.h>
  651. #include "stdmacs.h"
  652. X
  653. getswitchar()/*
  654. ===============
  655. X   Try the environment first.  If you don't find SWITCHAR there, then use
  656. X   the DOS call.  The call is undocumented, and doesn't work for DOS versions
  657. X   4.0 and up, so the check of the environment will fix that. */
  658. {
  659. #if defined(M_I86)
  660. #if !defined(OS2)
  661. X   union REGS rg;
  662. #endif /* ! OS2 */
  663. X   static char *_env_switchar = NIL(char);
  664. X
  665. X   if( _env_switchar != NIL(char) ||
  666. X       (_env_switchar = (char *)getenv("SWITCHAR")) != NIL(char) )
  667. X      return(*_env_switchar);
  668. X
  669. #if !defined(OS2)
  670. X   rg.h.ah = 0x37;      /* switch char request */
  671. X   rg.h.al = 0;         /* get (not set) */
  672. X
  673. X   intdos(&rg, &rg);
  674. X   return (rg.h.dl);
  675. #endif /* ! OS2 */
  676. #endif /* M_I86 */
  677. X
  678. X   return ('/');
  679. }
  680. SHAR_EOF
  681. chmod 0640 dmake/os2/switchar.c ||
  682. echo 'restore of dmake/os2/switchar.c failed'
  683. Wc_c="`wc -c < 'dmake/os2/switchar.c'`"
  684. test 904 -eq "$Wc_c" ||
  685.     echo 'dmake/os2/switchar.c: original size 904, current size' "$Wc_c"
  686. rm -f _shar_wnt_.tmp
  687. fi
  688. # ============= dmake/os2/sysintf.h ==============
  689. if test -f 'dmake/os2/sysintf.h' -a X"$1" != X"-c"; then
  690.     echo 'x - skipping dmake/os2/sysintf.h (File already exists)'
  691.     rm -f _shar_wnt_.tmp
  692. else
  693. > _shar_wnt_.tmp
  694. sed 's/^X//' << 'SHAR_EOF' > 'dmake/os2/sysintf.h' &&
  695. /*
  696. ** assorted bits of system interface
  697. */
  698. X
  699. #define STAT stat
  700. #define VOID_LCACHE(l,m)
  701. #define Hook_std_writes(A)
  702. #define GETPID getpid()
  703. X
  704. extern char * tempnam();
  705. extern char * getcwd();
  706. X
  707. /*
  708. ** standard C items
  709. */
  710. X
  711. /*
  712. ** DOS interface standard items
  713. */
  714. #define    chdir(p) _chdir(p)
  715. X
  716. /*
  717. ** make parameters
  718. */
  719. #define    MAX_PATH_LEN    256
  720. X
  721. SHAR_EOF
  722. chmod 0640 dmake/os2/sysintf.h ||
  723. echo 'restore of dmake/os2/sysintf.h failed'
  724. Wc_c="`wc -c < 'dmake/os2/sysintf.h'`"
  725. test 333 -eq "$Wc_c" ||
  726.     echo 'dmake/os2/sysintf.h: original size 333, current size' "$Wc_c"
  727. rm -f _shar_wnt_.tmp
  728. fi
  729. # ============= dmake/parse.c ==============
  730. if test -f 'dmake/parse.c' -a X"$1" != X"-c"; then
  731.     echo 'x - skipping dmake/parse.c (File already exists)'
  732.     rm -f _shar_wnt_.tmp
  733. else
  734. > _shar_wnt_.tmp
  735. sed 's/^X//' << 'SHAR_EOF' > 'dmake/parse.c' &&
  736. /* RCS      -- $Header: /u2/dvadura/src/generic/dmake/src/RCS/parse.c,v 1.1 1992/01/24 03:26:53 dvadura Exp $
  737. -- SYNOPSIS -- parse the input, and perform semantic analysis
  738. -- 
  739. -- DESCRIPTION
  740. --     This file contains the routines that parse the input makefile and
  741. --    call the appropriate routines to perform the semantic analysis and
  742. --    build the internal dag.
  743. --
  744. -- AUTHOR
  745. --      Dennis Vadura, dvadura@watdragon.uwaterloo.ca
  746. --      CS DEPT, University of Waterloo, Waterloo, Ont., Canada
  747. --
  748. -- COPYRIGHT
  749. --      Copyright (c) 1990 by Dennis Vadura.  All rights reserved.
  750. -- 
  751. --      This program is free software; you can redistribute it and/or
  752. --      modify it under the terms of the GNU General Public License
  753. --      (version 1), as published by the Free Software Foundation, and
  754. --      found in the file 'LICENSE' included with this distribution.
  755. -- 
  756. --      This program is distributed in the hope that it will be useful,
  757. --      but WITHOUT ANY WARRANTY; without even the implied warrant of
  758. --      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  759. --      GNU General Public License for more details.
  760. -- 
  761. --      You should have received a copy of the GNU General Public License
  762. --      along with this program;  if not, write to the Free Software
  763. --      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  764. --
  765. -- LOG
  766. --     $Log: parse.c,v $
  767. X * Revision 1.1  1992/01/24  03:26:53  dvadura
  768. X * dmake Version 3.8, Initial revision
  769. X *
  770. */
  771. X
  772. #include "extern.h"
  773. X
  774. X
  775. PUBLIC void
  776. Parse( fil )/*
  777. ==============  Parse the makefile input */
  778. FILE *fil;
  779. {
  780. X   int  rule  = FALSE;                 /* have seen a recipe line        */
  781. X   char *p;                   /* termporary pointer into Buffer */
  782. X
  783. X   DB_ENTER( "Parse" );
  784. X
  785. X   State = NORMAL_SCAN;
  786. X   Group = FALSE;                 /* true if scanning a group rcpe  */
  787. X   while( TRUE ) {
  788. X      if( Get_line( Buffer, fil ) ) {
  789. X     if( fil != NIL( FILE ) )               /* end of parsable input */
  790. X        Closefile();
  791. X
  792. X     Bind_rules_to_targets( F_DEFAULT );
  793. X         if( Group )  Fatal( "Incomplete rule recipe group detected" );
  794. X
  795. X     DB_VOID_RETURN;
  796. X      }
  797. X      else {
  798. X         switch( State ) {
  799. X        case RULE_SCAN:
  800. X
  801. X           /* Check for the `[' that starts off a group rule definition.  It
  802. X            * must appear as the first non-white space
  803. X        * character in the line. */
  804. X
  805. X           p = _strspn( Buffer, " \t\r\n" );
  806. X               if( Set_group_attributes( p ) ) {
  807. X                  if( rule && Group )
  808. X                     Fatal( "Cannot mix single and group recipe lines" );
  809. X                  else
  810. X                     Group = TRUE;
  811. X
  812. X                  rule = TRUE;
  813. X
  814. X                  break;                     /* ignore the group start  */
  815. X               }
  816. X
  817. X               if( Group ) {
  818. X                  if( *p != ']' ) {
  819. X                     Add_recipe_to_list( Buffer, TRUE, TRUE );
  820. X                     rule = TRUE;
  821. X                  }
  822. X                  else
  823. X                     State = NORMAL_SCAN;
  824. X               }
  825. X               else {
  826. X                  if(    *Buffer == '\t'
  827. X              || (Notabs && *Buffer == ' ') ) {
  828. X                     Add_recipe_to_list( Buffer, FALSE, FALSE );
  829. X                     rule = TRUE;
  830. X                  }
  831. X                  else if( *p == ']' )
  832. X                     Fatal( "Found unmatched ']'" );
  833. X                  else if( *Buffer && *p || (Notabs && !*Buffer && !*p))
  834. X             State = NORMAL_SCAN;
  835. X               }
  836. X               if( State == RULE_SCAN ) break;     /* ie. keep going    */
  837. X               
  838. X           Bind_rules_to_targets( (Group) ? F_GROUP: F_DEFAULT );
  839. X
  840. X               rule = FALSE;
  841. X               if( Group ) {
  842. X                  Group = FALSE;
  843. X                  break;
  844. X               }
  845. X           /*FALLTRHOUGH*/
  846. X
  847. X               /* In this case we broke out of the rule scan because we do not
  848. X                * have a recipe line that begins with a <TAB>, so lets
  849. X        * try to scan the thing as a macro or rule definition. */
  850. X               
  851. X
  852. X        case NORMAL_SCAN:
  853. X           if( !*Buffer ) continue;         /* we have null input line */
  854. X
  855. X           /* STUPID AUGMAKE uses "include" at the start of a line as
  856. X            * a signal to include a new file, so let's look for it.
  857. X        * if we see it replace it by .INCLUDE: and stick this back
  858. X        * into the buffer. */
  859. X           if( !strncmp( "include", Buffer, 7 ) &&
  860. X           (Buffer[7] == ' ' || Buffer[7] == '\t') )
  861. X           {
  862. X          char *tmp;
  863. X
  864. X          tmp = _strjoin( ".INCLUDE:", Buffer+7, -1, FALSE );
  865. X          strcpy( Buffer, tmp );
  866. X          FREE( tmp );
  867. X           }
  868. X
  869. X               /* look for a macro definition, they all contain an = sign
  870. X            * if we fail to recognize it as a legal macro op then try to
  871. X        * parse the same line as a rule definition, it's one or the
  872. X        * other */
  873. X        
  874. X           if( Parse_macro(Buffer, M_DEFAULT) ) break;/* it's a macro def */
  875. X           if( Parse_rule_def( &State ) )         break;/* it's a rule def  */
  876. X
  877. X           /* if just blank line then ignore it */
  878. X           if( *_strspn( Buffer, " \t\r\n" ) == '\0' ) break;
  879. X           
  880. X           /* otherwise assume it was a line of unrecognized input, or a
  881. X            * recipe line out of place so print a message */
  882. X        
  883. X           Fatal( "Expecting macro or rule defn, found neither" );
  884. X           break;
  885. X
  886. X        default:
  887. X           Fatal( "Internal -- UNKNOWN Parser state %d", State );
  888. X     }
  889. X      }
  890. X   }
  891. }
  892. X
  893. SHAR_EOF
  894. chmod 0640 dmake/parse.c ||
  895. echo 'restore of dmake/parse.c failed'
  896. Wc_c="`wc -c < 'dmake/parse.c'`"
  897. test 5291 -eq "$Wc_c" ||
  898.     echo 'dmake/parse.c: original size 5291, current size' "$Wc_c"
  899. rm -f _shar_wnt_.tmp
  900. fi
  901. # ============= dmake/patchlvl.h ==============
  902. if test -f 'dmake/patchlvl.h' -a X"$1" != X"-c"; then
  903.     echo 'x - skipping dmake/patchlvl.h (File already exists)'
  904.     rm -f _shar_wnt_.tmp
  905. else
  906. > _shar_wnt_.tmp
  907. sed 's/^X//' << 'SHAR_EOF' > 'dmake/patchlvl.h' &&
  908. /* dmake patch level, reset to 0 for each new version release. */
  909. X
  910. #define PATCHLEVEL 0
  911. SHAR_EOF
  912. chmod 0640 dmake/patchlvl.h ||
  913. echo 'restore of dmake/patchlvl.h failed'
  914. Wc_c="`wc -c < 'dmake/patchlvl.h'`"
  915. test 88 -eq "$Wc_c" ||
  916.     echo 'dmake/patchlvl.h: original size 88, current size' "$Wc_c"
  917. rm -f _shar_wnt_.tmp
  918. fi
  919. # ============= dmake/path.c ==============
  920. if test -f 'dmake/path.c' -a X"$1" != X"-c"; then
  921.     echo 'x - skipping dmake/path.c (File already exists)'
  922.     rm -f _shar_wnt_.tmp
  923. else
  924. > _shar_wnt_.tmp
  925. sed 's/^X//' << 'SHAR_EOF' > 'dmake/path.c' &&
  926. /* RCS      -- $Header: /u2/dvadura/src/generic/dmake/src/RCS/path.c,v 1.1 1992/01/24 03:27:54 dvadura Exp $
  927. -- SYNOPSIS -- pathname manipulation code
  928. -- 
  929. -- DESCRIPTION
  930. --    Pathname routines to handle building and pulling appart
  931. --    pathnames.
  932. -- 
  933. -- AUTHOR
  934. --      Dennis Vadura, dvadura@watdragon.uwaterloo.ca
  935. --      CS DEPT, University of Waterloo, Waterloo, Ont., Canada
  936. --
  937. -- COPYRIGHT
  938. --      Copyright (c) 1990 by Dennis Vadura.  All rights reserved.
  939. -- 
  940. --      This program is free software; you can redistribute it and/or
  941. --      modify it under the terms of the GNU General Public License
  942. --      (version 1), as published by the Free Software Foundation, and
  943. --      found in the file 'LICENSE' included with this distribution.
  944. -- 
  945. --      This program is distributed in the hope that it will be useful,
  946. --      but WITHOUT ANY WARRANTY; without even the implied warrant of
  947. --      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  948. --      GNU General Public License for more details.
  949. -- 
  950. --      You should have received a copy of the GNU General Public License
  951. --      along with this program;  if not, write to the Free Software
  952. --      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  953. --
  954. -- LOG
  955. --     $Log: path.c,v $
  956. X * Revision 1.1  1992/01/24  03:27:54  dvadura
  957. X * dmake Version 3.8, Initial revision
  958. X *
  959. */
  960. X
  961. #include "extern.h"
  962. X
  963. /*
  964. ** Return the suffix portion of a filename, assumed to begin with a `.'.
  965. */
  966. PUBLIC char *
  967. Get_suffix(name)
  968. char *name;
  969. {
  970. X   char *suff;
  971. X
  972. X   if(name == NIL(char)  || (suff = strrchr(name, '.')) == NIL(char))
  973. X      suff = ".NULL";
  974. X
  975. X   return (suff);
  976. }
  977. X
  978. X
  979. X
  980. /*
  981. ** Take dir and name, and return a path which has dir as the directory
  982. ** and name afterwards.
  983. **
  984. ** N.B. Assumes that the dir separator string is in DirSepStr.
  985. **      Return path is built in a static buffer, if you need to use it
  986. **      again you must _strdup the result returned by Build_path.
  987. */
  988. PUBLIC char *
  989. Build_path(dir, name)
  990. char *dir;
  991. char *name;
  992. {
  993. X   register char *p;
  994. X   register char *q;
  995. X   static char     *path  = NIL(char);
  996. X   static unsigned buflen = 0;
  997. X   int  plen = 0;
  998. X   int  dlen = 0;
  999. X   int  len;
  1000. X
  1001. X   if( dir  != NIL(char) ) dlen = strlen( dir  );
  1002. X   if( name != NIL(char) ) plen = strlen( name );
  1003. X   len = plen+dlen+strlen(DirSepStr)+1;
  1004. X
  1005. X   if( len > buflen ) {
  1006. X      buflen = (len+16) & ~0xf;        /* buf is always multiple of 16 */
  1007. X
  1008. X      if( path == NIL(char) )
  1009. X         path = MALLOC( buflen, char );
  1010. X      else
  1011. X         path = realloc( path, (unsigned) (buflen*sizeof(char)) );
  1012. X   }
  1013. X   
  1014. X   *path = '\0';
  1015. X
  1016. X   if( dlen ) {
  1017. X      strcpy( path, dir );
  1018. X      if( *path && strchr(DirBrkStr, dir[dlen-1]) == NIL(char) )
  1019. X     strcat( path, DirSepStr );
  1020. X   }
  1021. X   strcat( path, name );
  1022. X
  1023. X   q=path;
  1024. X   while( *q ) {
  1025. X      char *t;
  1026. X
  1027. X      p=_strpbrk(q,DirBrkStr);
  1028. X      t=_strpbrk(p+1,DirBrkStr);
  1029. X      if( !*p || !*t ) break;
  1030. X
  1031. X      if(    !(p-q == 2 && strncmp(q,"..",2) == 0)
  1032. X          && t-p-1 == 2 && strncmp(p+1,"..",2) == 0 ) {
  1033. X     t = _strspn(t,DirBrkStr);
  1034. X     strcpy(q,t);
  1035. X      }
  1036. X      else
  1037. X     q = p+1;
  1038. X   }
  1039. X
  1040. X   return( path );
  1041. }
  1042. SHAR_EOF
  1043. chmod 0640 dmake/path.c ||
  1044. echo 'restore of dmake/path.c failed'
  1045. Wc_c="`wc -c < 'dmake/path.c'`"
  1046. test 3076 -eq "$Wc_c" ||
  1047.     echo 'dmake/path.c: original size 3076, current size' "$Wc_c"
  1048. rm -f _shar_wnt_.tmp
  1049. fi
  1050. # ============= dmake/percent.c ==============
  1051. if test -f 'dmake/percent.c' -a X"$1" != X"-c"; then
  1052.     echo 'x - skipping dmake/percent.c (File already exists)'
  1053.     rm -f _shar_wnt_.tmp
  1054. else
  1055. > _shar_wnt_.tmp
  1056. sed 's/^X//' << 'SHAR_EOF' > 'dmake/percent.c' &&
  1057. /* RCS      -- $Header: /u2/dvadura/src/generic/dmake/src/RCS/percent.c,v 1.1 1992/01/24 03:29:34 dvadura Exp $
  1058. -- SYNOPSIS -- handle building or %-rule meta-target nfa.
  1059. -- 
  1060. -- DESCRIPTION
  1061. --    Builds the NFA used by dmake to match targets against %-meta
  1062. --    rule constructs.  The NFA is built as a set of DFA's.
  1063. -- 
  1064. -- AUTHOR
  1065. --      Dennis Vadura, dvadura@watdragon.uwaterloo.ca
  1066. --      CS DEPT, University of Waterloo, Waterloo, Ont., Canada
  1067. --
  1068. -- COPYRIGHT
  1069. --      Copyright (c) 1990 by Dennis Vadura.  All rights reserved.
  1070. -- 
  1071. --      This program is free software; you can redistribute it and/or
  1072. --      modify it under the terms of the GNU General Public License
  1073. --      (version 1), as published by the Free Software Foundation, and
  1074. --      found in the file 'LICENSE' included with this distribution.
  1075. -- 
  1076. --      This program is distributed in the hope that it will be useful,
  1077. --      but WITHOUT ANY WARRANTY; without even the implied warrant of
  1078. --      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1079. --      GNU General Public License for more details.
  1080. -- 
  1081. --      You should have received a copy of the GNU General Public License
  1082. --      along with this program;  if not, write to the Free Software
  1083. --      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1084. --
  1085. -- LOG
  1086. --     $Log: percent.c,v $
  1087. X * Revision 1.1  1992/01/24  03:29:34  dvadura
  1088. X * dmake Version 3.8, Initial revision
  1089. X *
  1090. */
  1091. X
  1092. #include "extern.h"
  1093. X
  1094. static DFAPTR _build_dfa ANSI((char *));
  1095. static char   _shift_dfa ANSI((DFAPTR, char *));
  1096. X
  1097. X
  1098. #define NO_ACTION    0
  1099. #define START_PERCENT    1
  1100. #define END_PERCENT    2
  1101. #define ACCEPT        4
  1102. #define FAIL           -1
  1103. X
  1104. static  NFAPTR _nfa = NIL( NFA );
  1105. X
  1106. X
  1107. PUBLIC DFALINKPTR
  1108. Match_dfa( buf )/*
  1109. ==================
  1110. X   This routines runs all DFA's in parrallel and selects the one that best
  1111. X   matches the string.  If no match then it returns NIL( DFA ) */
  1112. char *buf;
  1113. {
  1114. X   register NFAPTR nfa;
  1115. X   int         adv;
  1116. X   DFALINKPTR       dfa_list = NIL(DFALINK);
  1117. X
  1118. X   DB_ENTER( "Match_dfa" );
  1119. X   DB_PRINT( "dfa", ("Matching %s", buf) );
  1120. X
  1121. X   /* Run each of the DFA's on the input string in parallel, we terminate
  1122. X    * when all DFA's have either failed or ACCEPTED, if more than one DFA
  1123. X    * accepts we build a list of all accepting DFA's sorted on states with
  1124. X    * those matching in a higher numbered state heading the list. */
  1125. X
  1126. X   do {
  1127. X      adv = FALSE;
  1128. X
  1129. X      for( nfa = _nfa; nfa != NIL( NFA ); nfa = nfa->next )
  1130. X     if( nfa->status != (char) FAIL && nfa->status != (char) ACCEPT ) {
  1131. X        adv++;
  1132. X        nfa->status = _shift_dfa( nfa->dfa, buf );
  1133. X
  1134. X        /* Construct the list of matching DFA's */
  1135. X        if( nfa->status == (char) ACCEPT ) {
  1136. X           DFALINKPTR dl;
  1137. X
  1138. X           TALLOC( dl, 1, DFALINK );
  1139. X           dl->dl_meta  = nfa->dfa->node;
  1140. X           dl->dl_per   = _substr( nfa->dfa->pstart, nfa->dfa->pend );
  1141. X           dl->dl_state = nfa->dfa->states - nfa->dfa->c_state;
  1142. X
  1143. X           if( dfa_list == NIL(DFALINK) )
  1144. X              dfa_list = dl;
  1145. X           else {
  1146. X          DFALINKPTR tdli = dfa_list;
  1147. X          DFALINKPTR tdlp = NIL(DFALINK);
  1148. X
  1149. X          for( ; tdli != NIL(DFALINK); tdli = tdli->dl_next ) {
  1150. X             if( dl->dl_state >= tdli->dl_state )
  1151. X            break;
  1152. X             tdlp = tdli;
  1153. X          }
  1154. X
  1155. X          if( tdli != NIL(DFALINK) ) {
  1156. X             tdli->dl_prev = dl;
  1157. X             dl->dl_next   = tdli;
  1158. X          }
  1159. X
  1160. X          if( tdlp != NIL(DFALINK) ) {
  1161. X             tdlp->dl_next = dl;
  1162. X             dl->dl_prev   = tdlp;
  1163. X          }
  1164. X          else
  1165. X             dfa_list = dl;
  1166. X           }
  1167. X
  1168. X           DB_PRINT( "dfa", ("Matched [%s]", dl->dl_meta->CE_NAME) );
  1169. X        }
  1170. X     }
  1171. X
  1172. X      buf++;
  1173. X   }
  1174. X   while ( adv );
  1175. X
  1176. X   for( nfa = _nfa; nfa != NIL( NFA ); nfa = nfa->next ) {
  1177. X      nfa->status = 0;
  1178. X      nfa->dfa->c_state = nfa->dfa->states;
  1179. X   }
  1180. X
  1181. X   DB_RETURN( dfa_list );
  1182. }
  1183. X
  1184. X
  1185. PUBLIC void
  1186. Check_circle_dfa()/*
  1187. ====================
  1188. X   This function is called to test for circularities in the DFA lists
  1189. X   constructed from %-meta targets. */
  1190. {
  1191. X   register NFAPTR nfa;
  1192. X
  1193. X   for( nfa = _nfa; nfa != NIL(NFA); nfa = nfa->next )
  1194. X      if( Test_circle( nfa->dfa->node, FALSE ) )
  1195. X     Fatal( "Detected circular dependency in inference graph at [%s]",
  1196. X        nfa->dfa->node->CE_NAME );
  1197. }
  1198. X
  1199. X
  1200. PUBLIC void
  1201. Add_nfa( name )/*
  1202. =================
  1203. X   Given name, build a DFA and add it to the NFA.  The NFA is maintained as
  1204. X   a singly linked list of DFA's. */
  1205. char *name;
  1206. {
  1207. X   NFAPTR nfa;
  1208. X
  1209. X   TALLOC(nfa, 1, NFA);
  1210. X   nfa->dfa = _build_dfa(name);
  1211. X
  1212. X   if( _nfa != NIL(NFA) ) nfa->next = _nfa;
  1213. X
  1214. X   _nfa = nfa;
  1215. }
  1216. X
  1217. X
  1218. static DFAPTR
  1219. _build_dfa( name )/*
  1220. ====================
  1221. X   Construct a dfa for the passed in cell name.  The routine returns a struct
  1222. X   that represents a finite state machine that can recognize a regular
  1223. X   expression with exactly one '%' sign in it.  The '%' symbol is used as a
  1224. X   wildcard character that will match anything except the character that
  1225. X   immediately follows it or NUL.
  1226. X
  1227. X   The Construction of DFA's is well know and can be found in Hopcroft and
  1228. X   Ullman or any other book discussing formal language theory.
  1229. X   A more practical treatise can be found in Compilers, Aho, Sethi and Ullman.
  1230. */
  1231. char *name;
  1232. {
  1233. X   DFAPTR   dfa;
  1234. X   int      nstates;
  1235. X   register STATEPTR sp;
  1236. X   STATEPTR per_state = NIL(STATE);
  1237. X   int      pcount=0;
  1238. X   int      end_percent=FALSE;
  1239. X
  1240. X   nstates = strlen(name)+2;
  1241. X
  1242. X   /* Allocate a DFA node and the right number of states. */
  1243. X   TALLOC(dfa, 1, DFA);
  1244. X   TALLOC(sp=dfa->c_state=dfa->states, nstates, STATE);
  1245. X   dfa->node = Def_cell( name );
  1246. X
  1247. X   /* Now construct the state table for the DFA */
  1248. X   do {
  1249. X      if( *name == '%' ) {
  1250. X     if( pcount++ > 0 )
  1251. X        Error( "Only one %% allowed within a %%-meta target" );
  1252. X
  1253. X     sp->symbol   = 0;
  1254. X     sp->action   = START_PERCENT;
  1255. X     sp->no_match = sp->match = per_state = sp+1;
  1256. X     end_percent  = TRUE;
  1257. X      }
  1258. X      else {
  1259. X     sp->symbol   = *name;
  1260. X     sp->no_match = per_state;
  1261. X
  1262. X     if( *name == '\0' ) {
  1263. X        sp->action = ACCEPT;
  1264. X        sp->match  = dfa->states;
  1265. X     }
  1266. X     else {
  1267. X        sp->action = NO_ACTION;
  1268. X        sp->match  = sp+1;
  1269. X     }
  1270. X
  1271. X     if( end_percent ) {
  1272. X        sp->action |= END_PERCENT;
  1273. X        end_percent = FALSE;
  1274. X     }
  1275. X      }
  1276. X      
  1277. X      sp++; 
  1278. X   }
  1279. X   while( *name++ );
  1280. X
  1281. X   return(dfa);
  1282. }
  1283. X
  1284. X
  1285. static char
  1286. _shift_dfa( dfa, data )/*
  1287. =========================
  1288. X   Take a given dfa and advance it based on the current state, the shift
  1289. X   action in that state, and the current data value. */
  1290. DFAPTR dfa;
  1291. char   *data;
  1292. {
  1293. X   register STATEPTR sp = dfa->c_state;
  1294. X   char c = *data;
  1295. X
  1296. X   /* Check if it is a START_PERCENT action if so then we need to save
  1297. X    * a pointer to the start of the string and advance to the next state. */
  1298. X   if( sp->action & START_PERCENT ) {
  1299. X      dfa->pstart = data;
  1300. X      sp++;
  1301. X   }
  1302. X
  1303. X   /* Now check if the current char matches the character expected in the
  1304. X    * current state.  If it does then perform the specified action, otherwise
  1305. X    * either shift it or fail.  We fail if the next state on no-match is
  1306. X    * NIL. */
  1307. X   if( sp->symbol == c ) {
  1308. X      if( sp->action & END_PERCENT ) dfa->pend = data;
  1309. X      if( sp->action & ACCEPT ) return(ACCEPT);
  1310. X      dfa->c_state = sp->match;
  1311. X   }
  1312. X   else if( (dfa->c_state = sp->no_match) == NIL(STATE) || !c )
  1313. X      return(FAIL);
  1314. X
  1315. X   return(NO_ACTION);
  1316. }
  1317. SHAR_EOF
  1318. chmod 0640 dmake/percent.c ||
  1319. echo 'restore of dmake/percent.c failed'
  1320. Wc_c="`wc -c < 'dmake/percent.c'`"
  1321. test 7063 -eq "$Wc_c" ||
  1322.     echo 'dmake/percent.c: original size 7063, current size' "$Wc_c"
  1323. rm -f _shar_wnt_.tmp
  1324. fi
  1325. # ============= dmake/quit.c ==============
  1326. if test -f 'dmake/quit.c' -a X"$1" != X"-c"; then
  1327.     echo 'x - skipping dmake/quit.c (File already exists)'
  1328.     rm -f _shar_wnt_.tmp
  1329. else
  1330. > _shar_wnt_.tmp
  1331. sed 's/^X//' << 'SHAR_EOF' > 'dmake/quit.c' &&
  1332. /* RCS      -- $Header: /u2/dvadura/src/generic/dmake/src/RCS/quit.c,v 1.1 1992/01/24 03:27:53 dvadura Exp $
  1333. -- SYNOPSIS -- end the dmake session.
  1334. -- 
  1335. -- DESCRIPTION
  1336. --     Handles dmake termination.
  1337. --
  1338. -- AUTHOR
  1339. --      Dennis Vadura, dvadura@watdragon.uwaterloo.ca
  1340. --      CS DEPT, University of Waterloo, Waterloo, Ont., Canada
  1341. --
  1342. -- COPYRIGHT
  1343. --      Copyright (c) 1990 by Dennis Vadura.  All rights reserved.
  1344. -- 
  1345. --      This program is free software; you can redistribute it and/or
  1346. --      modify it under the terms of the GNU General Public License
  1347. --      (version 1), as published by the Free Software Foundation, and
  1348. --      found in the file 'LICENSE' included with this distribution.
  1349. -- 
  1350. --      This program is distributed in the hope that it will be useful,
  1351. --      but WITHOUT ANY WARRANTY; without even the implied warrant of
  1352. --      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1353. --      GNU General Public License for more details.
  1354. -- 
  1355. --      You should have received a copy of the GNU General Public License
  1356. --      along with this program;  if not, write to the Free Software
  1357. --      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1358. --
  1359. -- LOG
  1360. --     $Log: quit.c,v $
  1361. X * Revision 1.1  1992/01/24  03:27:53  dvadura
  1362. X * dmake Version 3.8, Initial revision
  1363. X *
  1364. */
  1365. X
  1366. #include "extern.h"
  1367. X
  1368. static    void    _handle_quit ANSI((char*));
  1369. static    int    _dont_quit = 0;
  1370. X
  1371. X
  1372. PUBLIC void
  1373. Quit()/*
  1374. ======== Error or quit */
  1375. {
  1376. X   if( _dont_quit ) return;
  1377. X
  1378. X   while( Closefile() != NIL( FILE ) );
  1379. X   Clean_up_processes();
  1380. X
  1381. X   if( Current_target != NIL(CELL) )
  1382. X      Unlink_temp_files(Current_target);
  1383. X
  1384. X   if( _dont_quit == 0 ) _handle_quit( ".ERROR" );
  1385. X
  1386. X   Set_dir( Makedir );        /* No Error message if we can't do it */
  1387. X   Epilog( ERROR_EXIT_VALUE );
  1388. }
  1389. X
  1390. X
  1391. static void
  1392. _handle_quit( err_target )/*
  1393. ============================
  1394. X   Called by quit and the others to handle the execution of termination code
  1395. X   from within make */
  1396. char *err_target;
  1397. {
  1398. X   HASHPTR hp;
  1399. X   CELLPTR cp;
  1400. X
  1401. X   if( (hp = Get_name(err_target, Defs, FALSE)) != NIL(HASH) ) {
  1402. X      cp = hp->CP_OWNR;
  1403. X      Glob_attr |= A_IGNORE;
  1404. X
  1405. X      _dont_quit = 1;
  1406. X      cp->ce_flag |= F_TARGET;
  1407. X      Make( cp, NIL(CELL) );
  1408. X   }
  1409. }
  1410. SHAR_EOF
  1411. chmod 0640 dmake/quit.c ||
  1412. echo 'restore of dmake/quit.c failed'
  1413. Wc_c="`wc -c < 'dmake/quit.c'`"
  1414. test 2196 -eq "$Wc_c" ||
  1415.     echo 'dmake/quit.c: original size 2196, current size' "$Wc_c"
  1416. rm -f _shar_wnt_.tmp
  1417. fi
  1418. # ============= dmake/readme/apple.mac ==============
  1419. if test ! -d 'dmake/readme'; then
  1420.     mkdir 'dmake/readme'
  1421. fi
  1422. if test -f 'dmake/readme/apple.mac' -a X"$1" != X"-c"; then
  1423.     echo 'x - skipping dmake/readme/apple.mac (File already exists)'
  1424.     rm -f _shar_wnt_.tmp
  1425. else
  1426. > _shar_wnt_.tmp
  1427. sed 's/^X//' << 'SHAR_EOF' > 'dmake/readme/apple.mac' &&
  1428. Notes on the Macintosh implementation of dmake:
  1429. X
  1430. This port for the Macintosh is specifically designed to be run
  1431. under MPW.
  1432. X
  1433. I had to make a couple of changes to dmake in order to get it to work
  1434. on the Mac.  First, MPW provides no documented way to run a
  1435. subprocess, so when you use dmake, you MUST use the -n option and
  1436. execute the output.  Typically, you will probably want to write a
  1437. simple script file to do these operations for you.
  1438. SHAR_EOF
  1439. true || echo 'restore of dmake/readme/apple.mac failed'
  1440. fi
  1441. echo 'End of part 29, continue with part 30'
  1442. echo 30 > _shar_seq_.tmp
  1443. exit 0
  1444. exit 0 # Just in case...
  1445.