home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume19 / shape / part25 < prev    next >
Text File  |  1989-05-31  |  30KB  |  1,258 lines

  1. Subject:  v19i038:  A software configuration management system, Part25/33
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: Axel Mahler <unido!coma!axel>
  7. Posting-number: Volume 19, Issue 38
  8. Archive-name: shape/part25
  9.  
  10.  
  11.  
  12. #! /bin/sh
  13. # This is a shell archive.  Remove anything before this line, then unpack
  14. # it by saving it into a file and typing "sh file".  To overwrite existing
  15. # files, type "sh file -c".  You can also feed this as standard input via
  16. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  17. # will see the following message at the end:
  18. #        "End of archive 25 (of 33)."
  19. # Contents:  src/shape/produce.c
  20. # Wrapped by rsalz@papaya.bbn.com on Thu Jun  1 19:27:16 1989
  21. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  22. if test -f 'src/shape/produce.c' -a "${1}" != "-c" ; then 
  23.   echo shar: Will not clobber existing file \"'src/shape/produce.c'\"
  24. else
  25. echo shar: Extracting \"'src/shape/produce.c'\" \(27571 characters\)
  26. sed "s/^X//" >'src/shape/produce.c' <<'END_OF_FILE'
  27. X/*
  28. X * Copyright (C) 1989, 1990 W. Koch, A. Lampen, A. Mahler, W. Obst,
  29. X *  and U. Pralle
  30. X * 
  31. X * This software is published on an as-is basis. There is ABSOLUTELY NO
  32. X * WARRANTY for any part of this software to work correctly or as described
  33. X * in the manuals. We do not accept any liability for any kind of damage
  34. X * caused by use of this software, such as loss of data, time, money, or 
  35. X * effort.
  36. X * 
  37. X * Permission is granted to use, copy, modify, or distribute any part of
  38. X * this software as long as this is done without asking for charge, and
  39. X * provided that this copyright notice is retained as part of the source
  40. X * files. You may charge a distribution fee for the physical act of
  41. X * transferring a copy, and you may at your option offer warranty
  42. X * protection in exchange for a fee.
  43. X * 
  44. X * Direct questions to: Tech. Univ. Berlin
  45. X *              Wilfried Koch
  46. X *              Sekr. FR 5-6 
  47. X *              Franklinstr. 28/29
  48. X *              D-1000 Berlin 10, West Germany
  49. X * 
  50. X *              Tel: +49-30-314-22972
  51. X *              E-mail: shape@coma.uucp or shape@db0tui62.bitnet
  52. X */
  53. X#ifndef lint
  54. Xstatic char *RCSid = "$Header: produce.c,v 3.4 89/02/21 17:11:28 wolfgang Exp $";
  55. X#endif
  56. X#ifndef lint
  57. Xstatic char *ConfFlg = CFFLGS;    /* should be defined from within Makefile */
  58. X#endif
  59. X/*
  60. X * $Log:    produce.c,v $
  61. X * Revision 3.4  89/02/21  17:11:28  wolfgang
  62. X * bug fixed
  63. X * 
  64. X * Revision 3.3  89/02/20  16:26:17  wolfgang
  65. X * NET-RELEASE
  66. X * 
  67. X * Revision 3.2  89/02/14  21:20:51  wolfgang
  68. X * bug fixed.
  69. X * 
  70. X * Revision 3.1  89/02/08  12:45:15  wolfgang
  71. X * performance improved.
  72. X * 
  73. X * Revision 3.0  89/01/24  11:36:19  wolfgang
  74. X * New System Generation
  75. X * 
  76. X * Revision 2.39  89/01/19  12:37:14  wolfgang
  77. X * .DEFAULT added.
  78. X * 
  79. X * Revision 2.38  89/01/18  13:40:59  wolfgang
  80. X * bug fixed: if -n specified the message 'target is up to date' was printed out
  81. X * 
  82. X * Revision 2.37  89/01/13  12:38:37  wolfgang
  83. X * bug fixed. -k option doesn't work correct.
  84. X * 
  85. X * Revision 2.36  89/01/03  13:12:35  wolfgang
  86. X * changes done for lint
  87. X * 
  88. X * Revision 2.35  88/12/22  13:23:38  wolfgang
  89. X * error_occ added.
  90. X * 
  91. X * Revision 2.34  88/12/22  12:33:40  wolfgang
  92. X * bug fixed. handling of -k option has not been correct.
  93. X * call of cleanup_links added.
  94. X * 
  95. X * Revision 2.33  88/12/21  15:11:21  wolfgang
  96. X * changes done for lint
  97. X * 
  98. X * Revision 2.32  88/12/12  13:15:07  wolfgang
  99. X * bug fixed. single suffix rules didn't work
  100. X * 
  101. X * Revision 2.31  88/11/24  12:08:05  wolfgang
  102. X * Argument for -confid *must* now be a target name.
  103. X * 
  104. X * Revision 2.30  88/11/21  20:54:56  wolfgang
  105. X * changes done for sun
  106. X * 
  107. X * Revision 2.29  88/11/21  15:50:07  wolfgang
  108. X * return code of all malloc's checked
  109. X * 
  110. X * Revision 2.28  88/11/09  16:27:05  wolfgang
  111. X * inheritage changed.
  112. X * 
  113. X * Revision 2.27  88/10/27  16:37:04  wolfgang
  114. X * bugs fixed (new variant handling).
  115. X * 
  116. X * Revision 2.26  88/10/26  13:12:45  wolfgang
  117. X * changes done for new syntax of variant deps.
  118. X * 
  119. X * Revision 2.25  88/10/24  16:20:25  wolfgang
  120. X * calls of reduce_path_and_flags() deleted
  121. X * 
  122. X * Revision 2.24  88/10/21  14:56:42  wolfgang
  123. X * calls of attrvar added.
  124. X * 
  125. X * Revision 2.23  88/10/18  17:40:24  wolfgang
  126. X * changes done for new variant handling
  127. X * 
  128. X * Revision 2.22  88/10/10  16:53:24  wolfgang
  129. X * changes for option -t
  130. X * 
  131. X * Revision 2.21  88/10/03  12:54:19  wolfgang
  132. X * if via the -R option an unknown selection rule name is passed to shape, shape
  133. X * now stops (correctly!!).
  134. X * 
  135. X * Revision 2.20  88/09/26  14:15:40  wolfgang
  136. X * strange bug fixed in reduce_vpath_and_vflags (perhaps a malloc problem).
  137. X * 
  138. X * Revision 2.19  88/09/22  18:57:09  wolfgang
  139. X * bug fixed. activ selection rule is now correct (hopefully).
  140. X * 
  141. X * Revision 2.18  88/09/22  16:13:35  wolfgang
  142. X * bugs fixed.
  143. X * 
  144. X * Revision 2.17  88/09/22  10:04:04  wolfgang
  145. X * bugs fixed. ruleset & reset vflags.
  146. X * 
  147. X * Revision 2.16  88/09/20  10:24:53  wolfgang
  148. X * bug fixed. segmentation violation in set_pathi due to non-initialization 
  149. X * of i.
  150. X * 
  151. X * Revision 2.15  88/09/20  10:03:21  wolfgang
  152. X * set_pathi() added.
  153. X * 
  154. X * Revision 2.14  88/09/19  15:23:32  wolfgang
  155. X * This version is part of a release
  156. X * 
  157. X * Revision 2.13  88/09/19  14:41:42  wolfgang
  158. X * Bugs fixed. Single suffix rules weren't evaluated corectly
  159. X * 
  160. X * Revision 2.12  88/09/15  18:41:40  wolfgang
  161. X * calls of set_path_and_flags deleted.
  162. X * 
  163. X * Revision 2.11  88/09/14  14:00:26  wolfgang
  164. X * bug fixed. variant path & flags have not been reset correctly.
  165. X * 
  166. X * Revision 2.10  88/09/14  12:15:27  wolfgang
  167. X * minor bug fixed.
  168. X * 
  169. X * Revision 2.9  88/09/14  10:52:46  wolfgang
  170. X * undone last changes
  171. X * 
  172. X * Revision 2.8  88/09/13  09:56:29  wolfgang
  173. X * Changes done to allow overloading of imlpicit standard rules.
  174. X * 
  175. X * Revision 2.7  88/09/07  11:25:29  wolfgang
  176. X * This version is part of a release
  177. X * 
  178. X * Revision 2.6  88/08/31  12:04:00  wolfgang
  179. X * Bugs fixed.
  180. X * 
  181. X * Revision 2.5  88/08/25  16:03:37  wolfgang
  182. X * Little but effectful change (the procedure select gets more and more
  183. X * unnecessary).
  184. X * 
  185. X * Revision 2.4  88/08/23  16:39:02  wolfgang
  186. X * Rebuild feature added (to rebuild something from a confid).
  187. X * 
  188. X * Revision 2.3  88/08/22  10:14:15  wolfgang
  189. X * Changed produce(), so that it is no longer necessary to have a descrition
  190. X * file. It's enaugh to have the name of a target to produce on the command
  191. X * line.
  192. X * 
  193. X * Revision 2.2  88/08/19  17:02:31  wolfgang
  194. X * little bug fix.
  195. X * 
  196. X * Revision 2.1  88/08/19  10:17:42  wolfgang
  197. X * This version is part of a release
  198. X * 
  199. X */
  200. X
  201. X/* $? neu machen !!!! ????? */
  202. X
  203. X
  204. X#include "shape.h"
  205. X#define MAXCMDLENGTH 1024
  206. Xextern char *rindex();
  207. X
  208. XBool error_happened = FALSE;
  209. XBool error_occ = FALSE;
  210. X
  211. Xextern int cleanup_links();
  212. Xextern struct linkreg *link_reg;
  213. Xextern int free_linklist();
  214. Xextern void warning();
  215. Xextern int errexit();
  216. Xextern int hashval();
  217. Xextern char *expandmacro();
  218. Xextern char *repl_string();
  219. Xextern char *get_src_name();
  220. Xextern char *build_attrstring();
  221. Xextern Bool compare_attrstring();
  222. Xextern Bool exists_file();
  223. Xextern Bool Sselect();
  224. Xextern Bool evtl_set_busy();
  225. Xextern Bool is_selrule_name();
  226. Xextern Bool is_varname();
  227. Xextern Bool attrvar();
  228. Xextern int save_targets();
  229. Xextern char cfname[];
  230. Xextern struct rules *ruletab[];
  231. Xextern int implicit_suffs[];
  232. Xextern int pathi;
  233. Xextern char *cmdtargets[];
  234. Xextern char *firsttarget;
  235. Xextern char actpath[];
  236. Xextern char cursr[];
  237. Xextern char *curvar[];
  238. Xextern char *longattrs[];
  239. Xextern char *stdselrule;
  240. Xextern struct selection_rules *std_selrule;
  241. Xextern struct selection_rules *currule;
  242. Xextern int variants_active;
  243. X
  244. Xchar rbrule[64];
  245. Xchar rbtarg[64];
  246. Xchar ruleset[32];
  247. Xchar lastcurdep[MAXNAMLEN];
  248. X
  249. Xchar current_dep[MAXNAMLEN];
  250. XBool busy_done = FALSE;
  251. XBool reallydone = FALSE;
  252. Xint depth;
  253. Xchar *default_targets = ".DEFAULT";
  254. X
  255. X
  256. Xchar *expand_command (cmd, cur, rel_dep)
  257. X     char *cmd;
  258. X     struct rules *cur;
  259. X     char *rel_dep;
  260. X{
  261. X  char *curdep;
  262. X  char *comm;
  263. X  int i = 0;
  264. X  int j = 0;
  265. X  int k = 0;
  266. X  char *common_prefix;
  267. X  char *p;
  268. X  char *hhhp, *hhh2p;
  269. X  char hhh[64];
  270. X  char hhh2[64];
  271. X  Bool ttt = FALSE;
  272. X  char path1[MAXNAMLEN];
  273. X  if((comm = malloc(MAXCMDLENGTH * sizeof(char))) == NIL)
  274. X    errexit(10,"malloc");
  275. X  
  276. X  while(cmd[i] != '\0')
  277. X    {
  278. X      if((cmd[i] != '$') && (cmd[i] != '%'))
  279. X    {
  280. X      comm[j] =  cmd[i];
  281. X      i++;
  282. X      j++;
  283. X    }
  284. X      else
  285. X    {
  286. X      switch (cmd[i+1])
  287. X        {
  288. X        case '@':
  289. X          if (cur->name[0] != '%')
  290. X        {
  291. X          comm[j] = '\0';
  292. X          (void) strcat(comm, cur->name);
  293. X          (void) strcat(comm," ");
  294. X          j = j + strlen(cur->name) + 1;
  295. X          i = i + 2;
  296. X        }
  297. X          else
  298. X        {
  299. X          comm[j] = '\0';
  300. X          (void) strcpy(hhh,rel_dep);
  301. X          hhhp = rindex(hhh,'.');
  302. X          if (hhhp != NIL)
  303. X            {
  304. X              hhhp[0] = '\0';
  305. X            }
  306. X          (void) strcpy(hhh2, cur->name);
  307. X          hhh2p = rindex(hhh2,'.');
  308. X          (void) strcat(hhh,hhh2p);
  309. X          (void) strcat(comm, hhh);
  310. X          (void) strcat(comm, " ");
  311. X          j = j + strlen(hhh) + 1;
  312. X          i = i + 2;
  313. X        }
  314. X          
  315. X          break;
  316. X        case '?':
  317. X          if (cur->deplist[0] != NIL)
  318. X        {
  319. X          k = 1;
  320. X          curdep = cur->deplist[0];
  321. X          ttt = exists_file(cur->name,0);
  322. X          (void) strcpy(path1,actpath);
  323. X          /*          strcpy(actpath,"");  */
  324. X          while(curdep != NIL)
  325. X            {
  326. X              if (Sselect(cur->name, path1, ttt, cur->deplist[0],curdep))
  327. X            /* if (cur->date < curdep->date)  ????? */
  328. X            {
  329. X              comm[j] = '\0';
  330. X              (void) strcat(comm, curdep);
  331. X              (void) strcat(comm," ");
  332. X              j = j + strlen(curdep) + 1;
  333. X            }
  334. X              k++;
  335. X              curdep = cur->deplist[k];
  336. X            }
  337. X        }
  338. X          i = i + 2;
  339. X          break;
  340. X        case '<':
  341. X          comm[j] = '\0';
  342. X          if (strcmp(actpath,"") != 0)
  343. X        {
  344. X          (void) strcat(comm,actpath);
  345. X          (void) strcat(comm,"/");
  346. X          j = j + strlen(actpath) + 1;
  347. X        }
  348. X          (void) strcat(comm, rel_dep);
  349. X          (void) strcat(comm, " ");
  350. X          j = j + strlen(rel_dep) + 1;
  351. X          i = i + 2;
  352. X          break;
  353. X        case '*':
  354. X        case '.':
  355. X        case ' ':
  356. X          if (cur->name[0] != '%')
  357. X        {
  358. X          if ((common_prefix = malloc((unsigned) (strlen(cur->name) + 1))) == NIL)
  359. X            errexit(10,"malloc");
  360. X          (void) strcpy(common_prefix, cur->name);
  361. X          if ((p = rindex(common_prefix,'.')) != NIL)
  362. X            {
  363. X              p[0] = '\0';
  364. X            }
  365. X          comm[j] = '\0';
  366. X          (void) strcat(comm, common_prefix);
  367. X          j = j + strlen(common_prefix);
  368. X          if (cmd[i+1] == '*')
  369. X            i = i + 2;
  370. X          else
  371. X            i++;
  372. X        }
  373. X          else
  374. X        {
  375. X          comm[j] = '\0';
  376. X          (void) strcpy(hhh,rel_dep);
  377. X          hhhp = rindex(hhh,'.');
  378. X          if(hhhp != NIL)
  379. X            {
  380. X              hhhp[1] = '\0';
  381. X            }
  382. X          (void) strcat(comm, hhh);
  383. X          j = j + strlen(hhh);
  384. X          if (cur->name[1] == '.')
  385. X            i = i + 2;
  386. X          else
  387. X            i = i+1;
  388. X        }
  389. X          
  390. X          break;
  391. X        case '(':
  392. X          errexit(99,"output tarnslation $(name:str1=str2)");
  393. X          /* ???? output translation, not yet implemented */
  394. X          break;
  395. X        case '$':
  396. X          comm[j] = '$';
  397. X          j++;
  398. X          i = i+2;
  399. X          break;
  400. X        default:
  401. X          if(cmd[i] == '%')
  402. X        /* single suffix rule */
  403. X        {
  404. X          comm[j] = '\0';
  405. X          (void) strcpy(hhh,rel_dep);
  406. X          hhhp = rindex(hhh,'.');
  407. X          if(hhhp != NIL)
  408. X            {
  409. X              hhhp[1] = '\0';
  410. X            }
  411. X          (void) strcat(comm, hhh);
  412. X          j = j + strlen(hhh);
  413. X          i = i+1;
  414. X        }
  415. X          else
  416. X        {
  417. X          comm[j] = cmd[i];
  418. X          j++;
  419. X          i++;
  420. X        }
  421. X          break;
  422. X        }
  423. X    }
  424. X    }
  425. X  comm[j] = '\0';
  426. X  if (comm[0] == '\0')
  427. X    (void) strcpy(comm,cmd);
  428. X  return(comm);
  429. X}
  430. X
  431. X
  432. Xstruct rules *get_target(targ)
  433. X     char *targ;
  434. X{
  435. X  int hasht;
  436. X  struct rules *current = (struct rules *) NIL;
  437. X  char *p = NIL;
  438. X  char fname[MAXNAMLEN];
  439. X  char fnames[10][MAXNAMLEN];
  440. X  char targrulename[MAXNAMLEN];
  441. X  int i;
  442. X  int j;
  443. X  Bool ttt = FALSE;
  444. X  Bool tttt = TRUE;
  445. X  Bool xxx = TRUE;
  446. X  char path1[MAXNAMLEN];
  447. X  
  448. X  if (targ == NIL)
  449. X    return((struct rules *) NIL);
  450. X  
  451. X  hasht = hashval(targ);
  452. X  
  453. X  if ( ruletab[hasht] != (struct rules *) NIL)
  454. X    {
  455. X      current = ruletab[hasht];
  456. X      while((current != (struct rules *) NIL ) && (strcmp(targ, current->name) != 0))
  457. X    {
  458. X      current = current->nextrule;
  459. X    }
  460. X    }
  461. X  if (current != (struct rules *) NIL)
  462. X    {
  463. X      if (strcmp(targ, current->name) == 0)
  464. X    return(current);
  465. X    }
  466. X  if ((ruletab[hasht] == (struct rules *) NIL) || ((current == (struct rules *) NIL)) || (strcmp(targ,current->name) != 0))
  467. X    {
  468. X      /* look for std rule */
  469. X
  470. X      if (TRUE)
  471. X    {
  472. X      p = rindex(fname,'.');
  473. X      ttt = exists_file(targ,0);
  474. X      (void) strcpy(path1, actpath);
  475. X      (void) strcpy(actpath,"");
  476. X      for(i = 0; implicit_suffs[i] != -1; i++)
  477. X        {
  478. X          (void) strcpy(fname,targ);
  479. X          p = rindex(fname,'.');
  480. X  
  481. X          tttt = TRUE;
  482. X          /* build source name */
  483. X          if (p != NIL)
  484. X        *p = '\0';   /* p = suffix of target */
  485. X          if (p != NIL)
  486. X        (void) strcpy(targrulename,"%.");
  487. X          else
  488. X        (void) strcpy(targrulename,"%");
  489. X          if (p != NIL)
  490. X        (void) strcat(targrulename,p + 1);
  491. X          if (strcmp(targrulename, stdruletab[implicit_suffs[i]]->name) == 0)
  492. X        {
  493. X          /* several dependents may be necessary */
  494. X
  495. X          for (j = 0; j < 10; j++)
  496. X            {
  497. X              fnames[j][0] = '\0';
  498. X            }
  499. X          
  500. X          for (j = 0; stdruletab[implicit_suffs[i]]->deplist[j] != NIL; j++)
  501. X            {
  502. X              (void) strcat(fname,stdruletab[implicit_suffs[i]]->deplist[j]+1);
  503. X              tttt = tttt && exists_file(fname,0);
  504. X              if (tttt)
  505. X            (void) strcpy(fnames[j],fname);
  506. X              if (p != NIL)
  507. X            *p = '\0';
  508. X              else
  509. X            (void) strcpy(fname,targ);
  510. X            }
  511. X          if(tttt)
  512. X            {
  513. X              
  514. X              if (TRUE)
  515. X            {
  516. X              j = 0;
  517. X              xxx = TRUE;
  518. X              while((fnames[j][0] != '\0') && (xxx))
  519. X                {
  520. X                  xxx = xxx && evtl_set_busy(fnames[j], FALSE);
  521. X                  if (!xxx)
  522. X                break;
  523. X                  j++;
  524. X                }
  525. X              if (xxx)
  526. X                {
  527. X                  for (j = 0; fnames[j][0] != '\0'; j++)
  528. X                (void) evtl_set_busy(fnames[j], TRUE);
  529. X                  (void) strcpy(current_dep,targ);
  530. X                  return(stdruletab[implicit_suffs[i]]);
  531. X                }
  532. X            }
  533. X              
  534. X              if(!ttt)
  535. X            {
  536. X              /* to get the attrs .... */
  537. X              (void) Sselect(targ, path1, ttt, NIL, fnames[0]);/* ???? */
  538. X              
  539. X              (void) strcpy(current_dep,targ);
  540. X              return(stdruletab[implicit_suffs[i]]);
  541. X            }
  542. X              
  543. X              if(Sselect(targ, path1, ttt, NIL, fnames[0])) /* ??? */
  544. X            {
  545. X              (void) strcpy(current_dep,targ);
  546. X              return(stdruletab[implicit_suffs[i]]);
  547. X            }
  548. X              else
  549. X            return (struct rules *) NIL;
  550. X            }
  551. X        }
  552. X        }
  553. X      if(implicit_suffs[i] == -1)
  554. X        return (struct rules *) NIL;
  555. X    }
  556. X    }
  557. X  /*NOTREACHED*/
  558. X  return (struct rules *) NIL;
  559. X}
  560. X
  561. X
  562. Xproduce()
  563. X{
  564. X  int k = 0;
  565. X  char *comm;
  566. X
  567. X  if(confid)
  568. X    {
  569. X      if((get_target(cfname) == (struct rules *) NIL))
  570. X    errexit(35,cfname);
  571. X    }
  572. X      
  573. X  set_pathi();
  574. X
  575. X  (void) strcpy(cursr,"-STD-");
  576. X
  577. X  if (cmdtargets[0] == NIL) /* no targets on commandline */
  578. X    {
  579. X      if((get_target(".DEFAULT") != (struct rules *) NIL))
  580. X    comm = default_targets;
  581. X      else
  582. X    comm = firsttarget;
  583. X    }
  584. X  else
  585. X    comm = cmdtargets[k++];
  586. X
  587. X  if((nostdfile == TRUE) && (fileflg == FALSE) && (cmdtargets[0] == NIL))
  588. X    errexit(11,NIL);
  589. X  
  590. X  if (!rebuildflg)
  591. X    {
  592. X      if (ruleflg)
  593. X    {
  594. X      if (is_selrule_name(ruleset))
  595. X        (void) strcpy(cursr,ruleset);
  596. X      else
  597. X        errexit(32,ruleset);
  598. X    }
  599. X      else
  600. X    (void) strcpy(cursr,"-STD-");
  601. X    }
  602. X  else
  603. X    (void) strcpy(cursr,rbrule);
  604. X  
  605. X  if (!rebuildflg)
  606. X    {
  607. X      while (comm != NIL)
  608. X    {
  609. X      depth = 0;
  610. X      (void) make_target(comm,cursr,curvar[0]);
  611. X      
  612. X      if (!reallydone)
  613. X        printf("shape - `%s' is up to date\n", comm);
  614. X      
  615. X      if (comm != firsttarget)
  616. X        comm = cmdtargets[k++];
  617. X      else
  618. X        comm = NIL;
  619. X    }
  620. X    }
  621. X  else
  622. X    {
  623. X      depth = 0;
  624. X      (void) make_target(rbtarg,cursr,curvar[0]);
  625. X      if (!reallydone)
  626. X    printf("shape - `%s' is up to date\n");
  627. X    }
  628. X}
  629. X
  630. X
  631. X
  632. XBool make_target(targ, sr, vname)
  633. X     char *targ;
  634. X     char *sr;
  635. X     /*ARGSUSED*/
  636. X     char *vname;
  637. X{
  638. X  struct rules *current;
  639. X  char *curdep;
  640. X  char *point = NIL;
  641. X  char *srcname;
  642. X  char dep2[MAXNAMLEN];
  643. X  Bool err_happ = FALSE;
  644. X  Bool todo = FALSE;
  645. X  Bool test = FALSE;
  646. X  Bool t1 = FALSE;
  647. X  char lselrule[64];
  648. X  char lvar[64];
  649. X  char lvarname[64];
  650. X  char *xxx;
  651. X  Bool lbusy_done = FALSE;
  652. X  char path1[MAXNAMLEN];
  653. X  int dep = 0;
  654. X  int curi = 0;
  655. X
  656. X  depth++;
  657. X
  658. X  (void) is_selrule_name(sr);
  659. X
  660. X  (void) strcpy(lselrule,sr);
  661. X  
  662. X  if ((current = get_target(targ)) == (struct rules *) NIL)
  663. X    {
  664. X      if (!exists_file(targ,0))
  665. X    errexit(3,targ);
  666. X      else
  667. X    {
  668. X      if(strcmp(targ,lastcurdep))
  669. X        {
  670. X          if(evtl_set_busy(targ,TRUE))
  671. X        {
  672. X          (void) strcpy(lastcurdep,targ);
  673. X          (void) strcpy(sr,lselrule);
  674. X          return(TRUE);
  675. X        }
  676. X        }
  677. X      else
  678. X        return (FALSE);
  679. X    }
  680. X    }
  681. X
  682. X  if (current->done)
  683. X    {
  684. X      (void) strcpy(sr,lselrule);
  685. X      return(FALSE);
  686. X    }
  687. X  
  688. X  if ((current->deplist[dep] == NIL) && (exists_file(current->name,0)))
  689. X    {
  690. X      (void) strcpy(sr,lselrule);
  691. X      return(FALSE);
  692. X    }
  693. X
  694. X  lbusy_done = busy_done;
  695. X  
  696. X  if (current->deplist[dep] != NIL)
  697. X    {
  698. X      if (is_selrule_name(current->deplist[dep]))
  699. X    {
  700. X      (void) strcpy(lselrule,current->deplist[dep]);
  701. X      if ((xxx = index(lselrule,'+')) != NIL)
  702. X        *xxx = '\0';
  703. X      (void) strcpy(sr,lselrule);
  704. X      (void) strcpy(cursr,sr);
  705. X      dep++;
  706. X    }
  707. X      while(is_varname(current->deplist[dep]))
  708. X    {
  709. X      (void) strcpy(lvarname,current->deplist[dep]);
  710. X      if ((xxx = index(lvarname,'+')) != NIL)
  711. X        {
  712. X          xxx++;
  713. X          (void) strcpy(lvarname,xxx);
  714. X        }
  715. X      (void) strcpy(lvar,lvarname);
  716. X      curi = 0;
  717. X      while(strcmp(curvar[curi],""))
  718. X        curi++;
  719. X      if(curi == 32)
  720. X        errexit(37,NIL);
  721. X      if ((curvar[curi] = malloc((unsigned) (strlen(lvarname)+sizeof(char)))) == NIL)
  722. X        errexit(10,"malloc");
  723. X      variants_active = curi;
  724. X      (void) strcpy(curvar[curi],lvarname);
  725. X      (void) attrvar(lvar, NIL, (Af_set *) NIL);
  726. X      dep++;
  727. X    }
  728. X    }
  729. X  else
  730. X    todo = TRUE;
  731. X  
  732. X  curdep = current->deplist[dep++];
  733. X
  734. X  if(curdep != NIL)
  735. X    {
  736. X      if(!strcmp(curdep,"+"))
  737. X    curdep = current->deplist[dep++];
  738. X    }
  739. X  
  740. X  if (current->name[0] != '%')
  741. X    {
  742. X      if (curdep == NIL)
  743. X    todo = TRUE;
  744. X
  745. X      while (curdep != NIL)
  746. X    {
  747. X      t1 = exists_file(curdep,0);
  748. X
  749. X      if ((t1) && (strcmp(curdep,lastcurdep)))
  750. X        {
  751. X          (void) strcpy(lastcurdep,curdep);
  752. X          (void) evtl_set_busy(curdep,TRUE);
  753. X        }
  754. X
  755. X      test = make_target(curdep,sr,NIL);
  756. X      if (error_happened)
  757. X        {
  758. X          err_happ = TRUE;
  759. X          error_happened = FALSE;
  760. X        }
  761. X      depth--;
  762. X      (void) strcat(longattrs[depth], longattrs[depth+1]);
  763. X      (void) strcpy(longattrs[depth+1],"");
  764. X
  765. X      if (is_selrule_name(current->firstdep))
  766. X        {
  767. X          (void) strcpy(lselrule,current->firstdep);
  768. X          (void) strcpy(cursr,lselrule);
  769. X          (void) strcpy(sr,lselrule);
  770. X        }
  771. X      while(is_varname(current->deplist[dep]))
  772. X        {
  773. X          (void) strcpy(lvarname,current->deplist[dep]);
  774. X          if ((xxx = index(lvarname,'+')) != NIL)
  775. X        {
  776. X          xxx++;
  777. X          (void) strcpy(lvarname,xxx);
  778. X        }
  779. X          (void) strcpy(lvar,lvarname);
  780. X          curi = 0;
  781. X          while(strcmp(curvar[curi],""))
  782. X        curi++;
  783. X          if(curi == 32)
  784. X        errexit(37,NIL);
  785. X          if ((curvar[curi] = malloc((unsigned) (strlen(lvarname)+sizeof(char)))) == NIL)
  786. X        errexit(10,"malloc");
  787. X          variants_active = curi;
  788. X          (void) strcpy(curvar[curi],lvarname);
  789. X          (void) attrvar(lvarname, NIL, (Af_set *) NIL);
  790. X        }
  791. X
  792. X      if (test)
  793. X        todo = TRUE;
  794. X      t1 = exists_file(current->name,0);
  795. X      (void) strcpy(path1,actpath);
  796. X      (void) strcpy(actpath,"");
  797. X      if (!t1)
  798. X        todo = TRUE;
  799. X      if (!todo)
  800. X        {
  801. X          (void) strcpy(lselrule,cursr);
  802. X          (void) strcpy(cursr,"-STD-");
  803. X/*          if (Sselect(current->name, path1, t1, current->deplist[0],curdep))
  804. X        todo = TRUE; */
  805. X          todo = TRUE;
  806. X          (void) is_selrule_name(lselrule);
  807. X          (void) strcpy(cursr,lselrule);
  808. X        }
  809. X      curdep = current->deplist[dep++];
  810. X
  811. X    }
  812. X      current->done = TRUE;
  813. X      
  814. X      if ((!todo) && (current->cmdlist == (struct cmds *) NIL))
  815. X    {
  816. X      srcname = get_src_name(current->name);
  817. X      if (srcname != NIL)
  818. X        {
  819. X/*          if (Sselect(current->name, path1, t1, current->deplist[0],srcname)) */
  820. X        todo = TRUE;
  821. X          if (TRUE) /* (strcmp(sr,"-STD-")) */
  822. X        {
  823. X          if (evtl_set_busy(srcname,TRUE))
  824. X            {
  825. X              todo = TRUE;
  826. X              lbusy_done = busy_done;
  827. X            }
  828. X        } 
  829. X        }
  830. X    }
  831. X    }
  832. X  
  833. X  if(current->name[0] == '%')
  834. X    {
  835. X/*      if(strcmp(cursr,"-STD-"))
  836. X    {
  837. X    (void) strcpy(dep2,current_dep);
  838. X      if((evtl_set_busy(dep2) != TRUE)) 
  839. X        ;
  840. X      else
  841. X        errexit(17,current_dep);
  842. X    } */
  843. X      
  844. X      (void) strcpy(dep2, current_dep);
  845. X      point = rindex(dep2,'.');
  846. X      if(point != NIL)
  847. X    *point = '\0';
  848. X      (void) strcat(dep2,current->deplist[0]+1);
  849. X      
  850. X      t1 = exists_file(current_dep,0);
  851. X      if(t1)
  852. X    {
  853. X      if(lbusy_done) /* ((strcmp(cursr,"-STD-")) && (lbusy_done)) */
  854. X        {
  855. X          if (exists_file(dep2,0))
  856. X        {
  857. X          if (err_happ)
  858. X            {
  859. X              warning(2,current->name);
  860. X              err_happ = FALSE;
  861. X            }
  862. X          else
  863. X            test = execute_commands(current, current_dep, todo);
  864. X        }
  865. X          busy_done = FALSE;
  866. X        }
  867. X      else
  868. X        {
  869. X/*          if (Sselect(current_dep, actpath, t1, NIL, dep2)) */
  870. X          if (TRUE)
  871. X        {
  872. X          if (exists_file(dep2,0))
  873. X            {
  874. X              if (err_happ)
  875. X            {
  876. X              warning(2, current->name);
  877. X              err_happ = FALSE;
  878. X            }
  879. X              else
  880. X            test = execute_commands(current, current_dep, todo);
  881. X            }
  882. X        }
  883. X        }
  884. X    }
  885. X      else
  886. X    {
  887. X      if (exists_file(dep2,0))
  888. X        {
  889. X          if (err_happ)
  890. X        {
  891. X          warning(2, current->name);
  892. X          err_happ = FALSE;
  893. X        }
  894. X          else
  895. X        test = execute_commands(current, current_dep, todo);
  896. X        }
  897. X    }
  898. X      (void) strcpy(current_dep,"");
  899. X    }
  900. X  
  901. X  if (todo)
  902. X    {
  903. X      if (err_happ)
  904. X    {
  905. X      warning(2, current->name);
  906. X      err_happ = FALSE;
  907. X    }
  908. X      else
  909. X    test = execute_commands(current, NIL, todo);
  910. X      /* if((!test) && (!noexflg) && (!exists_file(current->name,1)))
  911. X    errexit(3,current->name);
  912. X      
  913. X      if((!test) && (noexflg) && (current->cmdlist == (struct cmds *) NIL))
  914. X    errexit(3,current->name); */
  915. X
  916. X      if(strcmp(lselrule,""))
  917. X    (void) strcpy(sr,lselrule);
  918. X      return(TRUE);
  919. X    }
  920. X  
  921. X  if (test || todo)
  922. X    {
  923. X      if(strcmp(lselrule,""))
  924. X    (void) strcpy(sr,lselrule);
  925. X      return(TRUE);
  926. X    }
  927. X  else
  928. X    {
  929. X      if(strcmp(lselrule,""))
  930. X    (void) strcpy(sr,lselrule);
  931. X      return(FALSE);
  932. X    }
  933. X}
  934. X
  935. X
  936. X
  937. XBool execute_commands(current, rel_dep, doit)
  938. X     struct rules *current;
  939. X     char *rel_dep;
  940. X     Bool doit;
  941. X{
  942. X  struct cmds *curcmd;
  943. X  char *expcmd;
  944. X  char *p;
  945. X  char *pp;
  946. X  char targrulename[MAXNAMLEN];
  947. X  char file[MAXNAMLEN];
  948. X  struct rules *cursuf;
  949. X  Bool exists = FALSE;
  950. X  Bool tx;
  951. X  int retcode;
  952. X  char *mist;
  953. X  char fname[MAXNAMLEN];
  954. X  int i;
  955. X  char attr[MAXATTRLENGTH];
  956. X  
  957. X  attr[0] = '\0';
  958. X  fname[0] = '\0';
  959. X
  960. X  if (rel_dep != NIL)
  961. X    (void) strcpy(file, rel_dep);
  962. X  else
  963. X    (void) strcpy(file, current->name);
  964. X
  965. X  if (current->name[0] == '%')
  966. X    {
  967. X      (void) strcpy(fname, rel_dep);
  968. X      if ((p = rindex(fname,'.')) != NIL)
  969. X    {
  970. X      *p = '\0';
  971. X      (void) strcat(fname,current->deplist[0]+1);
  972. X    }
  973. X    }
  974. X
  975. X  if ((current != (struct rules *) NIL) && (current->cmdlist != (struct cmds *) NIL))
  976. X    {
  977. X      /* figure out if derived object already exists */
  978. X#ifndef NOBPOOL
  979. X      tx = exists_file(rel_dep,0);
  980. X      if (!tx)
  981. X    tx = exists_file(current->name,0);
  982. X      if (tx)
  983. X    {
  984. X      if (rel_dep == NIL)
  985. X        rel_dep = current->name;
  986. X      (void) strcpy(attr,build_attrstring(current,rel_dep,(struct rules *) NIL));
  987. X      retcode = compare_attrstring(attr, current, rel_dep, (struct rules *) NIL);
  988. X      if ((retcode == 0)) /*  && (!doit)) */
  989. X        {
  990. X/*          if(Sselect(rel_dep,actpath,tx,current->deplist[0],fname)) */
  991. X          return(TRUE); /* FALSE */
  992. X        }
  993. X      if ((retcode == 1) && (!doit))
  994. X        {
  995. X          return (TRUE);
  996. X        }
  997. X    }
  998. X#endif NOBPOOL
  999. X      curcmd = current->cmdlist;
  1000. X      while (curcmd != (struct cmds *) NIL)
  1001. X    {
  1002. X      if (curcmd->command != NIL)
  1003. X        {
  1004. X          if ((mist = malloc(2048)) == NIL)
  1005. X        errexit(10,"malloc");
  1006. X          (void) strcpy(mist,expandmacro(curcmd->command));
  1007. X          if ((expcmd = malloc(2048)) == NIL)
  1008. X        errexit(10,"malloc");
  1009. X          (void) strcpy(expcmd,expand_command(mist, current, fname));
  1010. X          execute(expcmd);
  1011. X          free(expcmd);
  1012. X          free(mist);
  1013. X        }
  1014. X      else
  1015. X        break;
  1016. X      curcmd = curcmd->nextcmd;
  1017. X    }
  1018. X      if (current->cmdlist != (struct cmds *) NIL)
  1019. X    {
  1020. X      cleanup_links(link_reg);
  1021. X      free_linklist();
  1022. X      link_reg = (struct linkreg *) NIL;
  1023. X    }
  1024. X
  1025. X      if (current->name[0] == '%')
  1026. X    {
  1027. X      (void) strcpy(fname, rel_dep);
  1028. X      if ((p = rindex(fname,'.')) != NIL)
  1029. X        {
  1030. X          *p = '\0';
  1031. X          (void) strcat(fname,current->deplist[0]+1);
  1032. X        }
  1033. X      save_targets(current,fname,(struct rules *) NIL,attr);  /* rel_dep */
  1034. X    }
  1035. X      else
  1036. X    {
  1037. X      if (exists_file(current->name,0))
  1038. X        save_targets(current,current->name, (struct rules *) NIL,attr);
  1039. X    }
  1040. X    } 
  1041. X  else
  1042. X    { /* execute stdrule or default commands */
  1043. X      if ((pp = rindex(current->name,'.')) != NIL)
  1044. X    {
  1045. X      (void) strcpy(fname, current->name);
  1046. X      pp = rindex(fname,'.');
  1047. X      *pp = '\0';   /* pp = suffix of target */
  1048. X      (void) strcpy(targrulename,"%.");
  1049. X      (void) strcat(targrulename,pp + 1);
  1050. X      for(i = 0; implicit_suffs[i] != -1; i++)
  1051. X        {
  1052. X          (void) strcpy(fname,current->name);
  1053. X          if ((pp = rindex(fname,'.')) != NIL)
  1054. X        *pp = '\0';
  1055. X          /* build source name */
  1056. X          if (strcmp(targrulename, stdruletab[implicit_suffs[i]]->name) == 0)
  1057. X        {
  1058. X          /* several dependents may be necessary ???? */
  1059. X          (void) strcat(fname,stdruletab[implicit_suffs[i]]->deplist[0]+1);
  1060. X          
  1061. X          /* source file exists ? */
  1062. X          if(exists_file(fname,0))
  1063. X            {
  1064. X              exists = TRUE;
  1065. X              cursuf = stdruletab[implicit_suffs[i]];
  1066. X              break;
  1067. X            }
  1068. X          else
  1069. X            cursuf = (struct rules *) NIL;
  1070. X        }
  1071. X        }
  1072. X      if (exists)
  1073. X        {
  1074. X          /* but first figure out if derived object(s) already exist */
  1075. X#ifndef NOBPOOL
  1076. X          tx = exists_file(current->name,0);
  1077. X          if (tx)
  1078. X        {
  1079. X          (void) strcpy(attr,build_attrstring(cursuf,fname,current));
  1080. X/*          retcode = compare_attrstring(attr, cursuf, fname, current); */
  1081. X          retcode = compare_attrstring(attr, cursuf, current->name, current);
  1082. X          if((retcode == 0)) /* && (!doit)) */
  1083. X            {
  1084. X              /* if (Sselect(rel_dep,actpath,tx,current->deplist[0],fname)) */
  1085. X            return (TRUE); /* FALSE */
  1086. X            }
  1087. X          if ((retcode == 1) && (!doit))
  1088. X            return(TRUE);
  1089. X        }
  1090. X#endif NOBPOOL
  1091. X
  1092. X/*          if (strcmp(cursr,"-STD-"))
  1093. X          (void) evtl_set_busy(fname,TRUE); */
  1094. X
  1095. X          (void) strcpy(attr,build_attrstring(cursuf,fname,current));
  1096. X          retcode = compare_attrstring(attr, cursuf, current->name, current);
  1097. X          if (retcode == 0)
  1098. X        return(TRUE); /*FALSE */
  1099. X
  1100. X          curcmd = cursuf->cmdlist;
  1101. X          while(curcmd != (struct cmds *) NIL)
  1102. X        {
  1103. X          if (curcmd->command != NIL)
  1104. X            {
  1105. X              if ((expcmd = malloc(2048)) == NIL)
  1106. X            errexit(10,"malloc");
  1107. X              (void) strcpy(expcmd,expandmacro(curcmd->command));
  1108. X              (void) strcpy(expcmd,expand_command(expcmd, current, fname)); /* file */
  1109. X              execute(expcmd);
  1110. X              free(expcmd);
  1111. X            }
  1112. X          else
  1113. X            break;
  1114. X          curcmd = curcmd->nextcmd;
  1115. X        }
  1116. X          if (cursuf->cmdlist != (struct cmds *) NIL)
  1117. X        {
  1118. X          cleanup_links(link_reg);
  1119. X          free_linklist();
  1120. X          link_reg = (struct linkreg *) NIL;
  1121. X        }
  1122. X          save_targets(cursuf,fname,current,attr);
  1123. X
  1124. X          /* put derived objects into bpool */
  1125. X          /* and save special attributes */
  1126. X
  1127. X        }
  1128. X    }
  1129. X    }
  1130. X  if (cursuf != (struct rules *) NIL)
  1131. X    return(TRUE);
  1132. X  else
  1133. X    return (FALSE);
  1134. X}
  1135. X
  1136. X  
  1137. X
  1138. Xint execute(cmd)
  1139. X     char *cmd;
  1140. X{
  1141. X  int retcode = 0;
  1142. X  Bool ignflg = FALSE;
  1143. X  char *rc;
  1144. X  Bool silflg;
  1145. X
  1146. X  cmd = repl_string(cmd);
  1147. X  
  1148. X  silflg = silentflg;
  1149. X
  1150. X  while((cmd[0] == '\t') || (cmd[0] == ' ') || (cmd[0] == '\n'))
  1151. X    *cmd++;
  1152. X
  1153. X  if (noexflg)
  1154. X    {
  1155. X      printf("%s\n", cmd);
  1156. X      (void) fflush(stdout);
  1157. X      reallydone = TRUE;
  1158. X    }
  1159. X  else
  1160. X    {
  1161. X      if (cmd[0] == '@')
  1162. X    {
  1163. X      cmd[0] = ' ';
  1164. X      silflg = TRUE;
  1165. X      if (cmd[1] == '-')
  1166. X        {
  1167. X          cmd[1] = ' ';
  1168. X          ignflg = TRUE;
  1169. X        }
  1170. X    }
  1171. X      if (!silflg)
  1172. X    {
  1173. X      printf("shape - executing: %s\n", cmd);
  1174. X      (void) fflush(stdout);
  1175. X    }
  1176. X      if (!touchflg)
  1177. X    {
  1178. X      reallydone = TRUE;
  1179. X      retcode = system(cmd);
  1180. X/*      cleanup_links(link_reg);
  1181. X      free_linklist();
  1182. X      link_reg = (struct linkreg *) NIL; */
  1183. X      if (retcode != 0)
  1184. X        {
  1185. X          error_happened = TRUE;
  1186. X          error_occ = TRUE;
  1187. X          if ((rc = malloc(10 * sizeof(char))) == NIL)
  1188. X        errexit(10,"malloc");
  1189. X          (void) sprintf(rc, "%d", retcode); 
  1190. X          if ((ignflg == FALSE) && (goflg == FALSE))
  1191. X        errexit(13,rc);
  1192. X          if (goflg == FALSE)
  1193. X        errexit(13,rc);
  1194. X        }
  1195. X    }
  1196. X    }
  1197. X  free(cmd);
  1198. X}
  1199. X
  1200. X
  1201. Xchar *get_src_name(name)
  1202. X     char *name;
  1203. X{
  1204. X  int i;
  1205. X  char fname[MAXNAMLEN];
  1206. X  char *p;
  1207. X  (void) strcpy(fname,name);
  1208. X  if ((p = rindex(fname,'.')) != NIL)
  1209. X    {
  1210. X      for (i = 0; implicit_suffs[i] != -1; i++)
  1211. X    {
  1212. X      *p = '\0';
  1213. X      if (!strcmp(stdruletab[implicit_suffs[i]]->name+2,p+1))
  1214. X        {
  1215. X          (void) strcat(fname,stdruletab[implicit_suffs[i]]->deplist[0]+1);
  1216. X          if (exists_file(fname,0))
  1217. X        return(fname);
  1218. X        }
  1219. X    }
  1220. X      if(implicit_suffs[i] == -1)
  1221. X    return(NIL);
  1222. X    }
  1223. X  /*NOTREACHED*/
  1224. X  return(NIL);
  1225. X}
  1226. X       
  1227. X
  1228. Xset_pathi()
  1229. X{
  1230. X  int i = 0;
  1231. X  while(curvpath[i] != NIL)
  1232. X    i++;
  1233. X  pathi = i;
  1234. X}
  1235. END_OF_FILE
  1236. if test 27571 -ne `wc -c <'src/shape/produce.c'`; then
  1237.     echo shar: \"'src/shape/produce.c'\" unpacked with wrong size!
  1238. fi
  1239. # end of 'src/shape/produce.c'
  1240. fi
  1241. echo shar: End of archive 25 \(of 33\).
  1242. cp /dev/null ark25isdone
  1243. MISSING=""
  1244. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 ; do
  1245.     if test ! -f ark${I}isdone ; then
  1246.     MISSING="${MISSING} ${I}"
  1247.     fi
  1248. done
  1249. if test "${MISSING}" = "" ; then
  1250.     echo You have unpacked all 33 archives.
  1251.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1252. else
  1253.     echo You still need to unpack the following archives:
  1254.     echo "        " ${MISSING}
  1255. fi
  1256. ##  End of shell archive.
  1257. exit 0
  1258.