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

  1. Subject:  v19i037:  A software configuration management system, Part24/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 37
  8. Archive-name: shape/part24
  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 24 (of 33)."
  19. # Contents:  src/shape/files.c
  20. # Wrapped by rsalz@papaya.bbn.com on Thu Jun  1 19:27:15 1989
  21. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  22. if test -f 'src/shape/files.c' -a "${1}" != "-c" ; then 
  23.   echo shar: Will not clobber existing file \"'src/shape/files.c'\"
  24. else
  25. echo shar: Extracting \"'src/shape/files.c'\" \(27004 characters\)
  26. sed "s/^X//" >'src/shape/files.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: files.c,v 3.3 89/02/20 16:23:45 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:    files.c,v $
  61. X * Revision 3.3  89/02/20  16:23:45  wolfgang
  62. X * NET-RELEASE
  63. X * 
  64. X * Revision 3.2  89/02/13  19:35:15  wolfgang
  65. X * performance improved
  66. X * 
  67. X * Revision 3.1  89/02/08  12:45:42  wolfgang
  68. X * performance improved.
  69. X * 
  70. X * Revision 3.0  89/01/24  11:35:24  wolfgang
  71. X * New System Generation
  72. X * 
  73. X * Revision 2.30  89/01/03  13:09:44  wolfgang
  74. X * changes done for lint
  75. X * 
  76. X * Revision 2.29  88/12/21  15:02:45  wolfgang
  77. X * changes done for lint
  78. X * 
  79. X * Revision 2.28  88/12/12  13:15:58  wolfgang
  80. X * bug fixed (something for sun).
  81. X * 
  82. X * Revision 2.27  88/11/24  14:30:36  wolfgang
  83. X * derived object no longer inherit uda's .
  84. X * 
  85. X * Revision 2.26  88/11/23  15:19:39  wolfgang
  86. X * hidden attrs are no longer part of confid.
  87. X * 
  88. X * Revision 2.25  88/11/23  15:02:57  wolfgang
  89. X * bug fixed.
  90. X * 
  91. X * Revision 2.24  88/11/22  17:27:33  wolfgang
  92. X * bug fixed (strncmp).
  93. X * 
  94. X * Revision 2.22  88/11/21  15:51:11  wolfgang
  95. X * return code of all malloc's checked
  96. X * 
  97. X * Revision 2.21  88/11/08  18:06:04  wolfgang
  98. X * bug fixed: retcode wasn't correct initialized (in exists_file()).
  99. X * 
  100. X * Revision 2.20  88/11/08  11:01:23  wolfgang
  101. X * bug fixed in evtl_set_busy: selction rules are now not applied to
  102. X * derived objects.
  103. X * 
  104. X * Revision 2.19  88/11/05  14:35:51  wolfgang
  105. X * bug fixed. full filenames (including path) were destroyed sometimes.
  106. X * 
  107. X * Revision 2.18  88/11/03  17:28:59  wolfgang
  108. X * bug fixed in exists_file
  109. X * 
  110. X * Revision 2.17  88/10/24  16:19:30  wolfgang
  111. X * bug fixed in exists_file.
  112. X * 
  113. X * Revision 2.16  88/10/18  20:33:48  wolfgang
  114. X * bugs fixed. pathlist wasn't correct. set busy of name including
  115. X * full path didn't work.
  116. X * 
  117. X * Revision 2.15  88/10/10  17:02:34  wolfgang
  118. X * This version is part of a release
  119. X * 
  120. X * Revision 2.14  88/09/22  16:14:06  wolfgang
  121. X * changes done to set busy the same file more than once.
  122. X * 
  123. X * Revision 2.13  88/09/15  18:42:14  wolfgang
  124. X * call of reset_vclass added.
  125. X * 
  126. X * Revision 2.12  88/08/30  12:20:44  wolfgang
  127. X * minor bug fixed.,
  128. X * 
  129. X * Revision 2.11  88/08/25  16:10:55  wolfgang
  130. X * This version is part of a release
  131. X * 
  132. X * Revision 2.10  88/08/25  10:29:31  wolfgang
  133. X * Now a warning is produced, if a confid contains non-frozen versions
  134. X * of a component.
  135. X * 
  136. X * Revision 2.9  88/08/23  16:35:40  wolfgang
  137. X * The handling of author@host is now correct.
  138. X * 
  139. X * Revision 2.8  88/08/23  15:35:45  wolfgang
  140. X * Genarating of confid's has been changed. The name of the selection
  141. X * rule starts now with '@'.
  142. X * 
  143. X * Revision 2.7  88/08/23  14:06:47  wolfgang
  144. X * Minor bug fixed. The dummy predicate SMILEY was followed by ":"
  145. X * instead of ",".
  146. X * 
  147. X * Revision 2.6  88/08/23  11:22:37  wolfgang
  148. X * vardump(fd) added to finish_confid.
  149. X * 
  150. X * Revision 2.5  88/08/23  10:27:01  wolfgang
  151. X * ruledump() added to finish_confid; little bug fix in write_confid.
  152. X * 
  153. X * Revision 2.4  88/08/22  17:13:31  wolfgang
  154. X * Two procedures added:
  155. X * init_confid: to initialize the confid
  156. X * finish_confid: dumps the macrodefinitions.
  157. X * write_confid changed; only the relevant predicates are written to the
  158. X * confid now.
  159. X * Furthermore handling of syspath & host added to evtl_set_busy().
  160. X * 
  161. X * Revision 2.3  88/08/22  11:13:41  wolfgang
  162. X * Minor bug fixed. attr(author,<name>) wasn't evaluated correctly.
  163. X * 
  164. X * Revision 2.2  88/08/19  12:25:02  wolfgang
  165. X * Minor bug fixed. Pathlist contained '/' in filename.
  166. X * 
  167. X * Revision 2.1  88/08/19  10:17:18  wolfgang
  168. X * This version is part of a release
  169. X * 
  170. X */
  171. X
  172. X#include "shape.h"
  173. X#include "files.h"
  174. X
  175. X#include <pwd.h>
  176. X#include <stdio.h>
  177. X#include <sys/stat.h>
  178. X#include <sys/time.h>
  179. X#include <errno.h>
  180. X
  181. Xextern int errno;
  182. X
  183. Xextern register_link();
  184. X
  185. Xextern FILE *af_open();
  186. X
  187. Xextern struct passwd *getpwnam();
  188. Xextern char *mktemp();
  189. X
  190. Xextern int af_setgkey();
  191. Xextern int af_gattrs();
  192. Xextern int WriteXPand();
  193. Xextern int logerr();
  194. Xextern int append_attrs();
  195. Xextern int append_mtime();
  196. Xextern Bool stopit();
  197. Xextern Bool tunix();
  198. Xextern struct rules *get_target();
  199. Xextern int dump();
  200. Xextern int ruledump();
  201. Xextern int vardump();
  202. Xextern int reset_vclass();
  203. X
  204. XAf_attrs buft;
  205. Xextern char *macrostr;
  206. Xextern char cursr[];
  207. Xchar actpath[MAXNAMLEN];
  208. Xextern char *states[];
  209. Xextern struct selection_rules *currule;
  210. X
  211. Xextern Bool busy_done;
  212. Xextern int depth;
  213. Xextern int pathi;
  214. Xchar *pathlist[MAXPATHLIST][2];
  215. Xint lastpath = 0;
  216. Xchar dollarplus[MAXNAMLEN];
  217. X
  218. Xget_date_of(anything,set,path)
  219. X     char *anything;
  220. X     Af_set *set;
  221. X     char *path;
  222. X     {
  223. X       /* attrs of busy version */
  224. XAf_attrs buf;
  225. X
  226. Xchar bname[MAXNAMLEN];
  227. Xchar *p;
  228. Xchar *d;
  229. Xchar sysp[MAXNAMLEN];
  230. X
  231. Xsysp[0] = '\0';
  232. X
  233. X(void) strcpy(bname,anything);
  234. Xif ((p = rindex(bname,'.')) == NIL)
  235. X  ;
  236. Xelse
  237. X  {
  238. X    p[0] = '\0';
  239. X    *p++;
  240. X  }
  241. X
  242. Xif ((d = rindex(bname,'/')) != 0)
  243. X  {
  244. X    (void) strcpy(sysp, bname);
  245. X    d = rindex(sysp, '/');
  246. X    d[0] = '\0';
  247. X    *d++;
  248. X    (void) strcpy(bname,d);
  249. X  }
  250. Xaf_initattrs(&buf);
  251. X
  252. Xbuf.af_gen = AF_BUSYVERS;
  253. Xbuf.af_rev = AF_BUSYVERS;
  254. X
  255. X(void) strcpy(buf.af_name,bname);
  256. Xif (p != NIL)
  257. X     (void) strcpy(buf.af_type,p);
  258. Xelse
  259. X  (void) strcpy(buf.af_type,"");
  260. X
  261. Xif(path != NIL)
  262. X     (void) strcpy(buf.af_syspath, path);
  263. X
  264. X/* if ((retcode = af_bpfind(&buf,&bset)) == -1) 
  265. X  errexit(10,"af_bpfind"); */
  266. X
  267. Xif (af_find(&buf,set) == -1) /* &aset */
  268. X  errexit(10,"af_find");
  269. X
  270. X/* if ((retcode = af_union(&aset,&bset,set)) == -1 )
  271. X  errexit(10,"af_union"); */
  272. X} 
  273. X
  274. X
  275. XBool exists_file(name,mode)
  276. X     char *name;
  277. X     int mode;
  278. X{
  279. X
  280. Xchar bname[MAXNAMLEN];
  281. Xchar type[64];
  282. Xchar *p;
  283. Xchar *d;
  284. X
  285. Xint retcode = -1;
  286. Xint retcodex;
  287. Xint retcodey;
  288. Xint i;
  289. Xint ii = 1;
  290. Xchar sysp[MAXNAMLEN];
  291. Xchar lname[MAXNAMLEN];
  292. Xchar *px;
  293. XAf_attrs buf;
  294. X
  295. Xsysp[0] = '\0';
  296. Xif (name == NIL)
  297. X  return (FALSE);
  298. X
  299. X(void) strcpy(lname,name);
  300. Xif((px = rindex(lname,'/')) != NIL)
  301. X  {
  302. X    *px = '\0';
  303. X    px++;
  304. X  }
  305. Xelse
  306. X  px = &lname[0];
  307. X
  308. Xif (mode != BINARY) 
  309. X    {
  310. X      for(i = lastpath - 1; i >= 0; i--)
  311. X    /* looking in pathlist if file already exists */
  312. X    {
  313. X      if(!strcmp(px,pathlist[i][0]))
  314. X        {
  315. X          if (!strcmp(pathlist[i][1],"&$"))
  316. X        (void) strcpy(actpath,curvpath[0]);
  317. X          else
  318. X        {
  319. X          if(pathlist[i][1][0] != '/')
  320. X            {
  321. X              (void) strcpy(actpath,curvpath[0]);
  322. X              (void) strcat(actpath,"/");
  323. X              (void) strcat(actpath,pathlist[i][1]);
  324. X            }
  325. X          else
  326. X            {
  327. X              (void) strcpy(actpath,pathlist[i][1]);
  328. X            }
  329. X          if ((px = rindex(actpath,'/')) != NIL)
  330. X            *px = '\0';
  331. X        }
  332. X          return(TRUE);
  333. X        }
  334. X    }
  335. X    }
  336. X
  337. X(void) strcpy(bname,name);
  338. Xif ((p = rindex(bname,'.')) == 0)
  339. X  {
  340. X    type[0] = '\0';
  341. X  }
  342. Xelse
  343. X  {
  344. X    p[0] = '\0';
  345. X    *p++;
  346. X    (void) strcpy(type,p);
  347. X  }
  348. Xif ((d = rindex(bname,'/')) != 0)
  349. X  {
  350. X    (void) strcpy(sysp, bname);
  351. X    d = rindex(sysp, '/');
  352. X    d[0] = '\0';
  353. X    *d++;
  354. X    (void) strcpy(bname,d);
  355. X  }
  356. Xaf_initattrs(&buf);
  357. X
  358. Xbuf.af_gen = AF_NOVNUM;
  359. Xbuf.af_rev = AF_NOVNUM;
  360. X
  361. X(void) strcpy(buf.af_name,bname);
  362. X
  363. X(void) strcpy(buf.af_type,type);
  364. X
  365. Xwhile(curvpath[ii] != NIL)
  366. X  ii++;
  367. X
  368. Xi = ii - 1;
  369. X
  370. Xwhile ( i >= 1 )
  371. X  {
  372. X    (void) strcpy(buf.af_syspath, curvpath[i]);
  373. X
  374. X    if (mode == ALL)
  375. X      {
  376. X    retcodex = af_access(buf.af_syspath, buf.af_name, buf.af_type, AF_SOURCE);
  377. X    retcodey = af_access(buf.af_syspath, buf.af_name, buf.af_type, AF_DERIVED);
  378. X    if((retcodex == 0) || (retcodey == 0))
  379. X      retcode = 0;
  380. X    else
  381. X      retcode = -1;
  382. X      }
  383. X
  384. X    if (mode == SOURCE)
  385. X      retcode = af_access(buf.af_syspath, buf.af_name, buf.af_type, AF_SOURCE);
  386. X
  387. X    if (mode == BINARY)
  388. X      retcode = af_access(buf.af_syspath, buf.af_name, buf.af_type, AF_DERIVED);
  389. X
  390. X    if ((retcode == 0)) /*  && (strcmp(buf.af_syspath,curvpath[0]))) */
  391. X      {
  392. X    (void) strcpy(actpath,curvpath[i]);
  393. X    if ((pathlist[lastpath][0] = malloc(MAXNAMLEN)) == NIL)
  394. X      errexit(10,"malloc");
  395. X    (void) strcpy(pathlist[lastpath][0],buf.af_name);
  396. X    if (buf.af_type[0] != '\0')
  397. X      {
  398. X        (void) strcat(pathlist[lastpath][0],".");
  399. X        (void) strcat(pathlist[lastpath][0],buf.af_type);
  400. X      }
  401. X    if (!strcmp(buf.af_syspath,curvpath[0]))
  402. X      {
  403. X        if((pathlist[lastpath][1] = malloc(3)) == NIL)
  404. X          errexit(10,"malloc");
  405. X        (void) strcpy(pathlist[lastpath][1],"&$");
  406. X#ifdef DEBUG_FILES
  407. Xprintf("%d:%s:%s\n", lastpath,pathlist[lastpath][0], pathlist[lastpath][1]);
  408. X#endif DEBUG_FILES
  409. X        lastpath++;
  410. X      }
  411. X    else
  412. X      {
  413. X        if((pathlist[lastpath][1] = malloc(MAXNAMLEN)) == NIL)
  414. X          errexit(10,"malloc");
  415. X        (void) strcpy(pathlist[lastpath][1],buf.af_syspath);
  416. X        (void) strcat(pathlist[lastpath][1],"/");
  417. X        (void) strcat(pathlist[lastpath][1],pathlist[lastpath][0]);
  418. X#ifdef DEBUG_FILES
  419. Xprintf("%d:%s:%s\n", lastpath,pathlist[lastpath][0], pathlist[lastpath][1]);
  420. X#endif DEBUG_FILES
  421. X        lastpath++;
  422. X        break;
  423. X      }
  424. X      }
  425. X    i--;
  426. X    }
  427. Xif (retcode == 0)
  428. X  {
  429. X    (void) strcpy(actpath,curvpath[i]);
  430. X    return(TRUE);
  431. X  }
  432. X
  433. Xif (sysp[0] != '\0')
  434. X     (void) strcpy(buf.af_syspath, sysp);
  435. Xelse
  436. X  (void) strcpy(buf.af_syspath, curvpath[0]);
  437. X
  438. X
  439. Xif (mode == ALL)
  440. X  {
  441. X    retcodex = af_access(buf.af_syspath, buf.af_name, buf.af_type, AF_SOURCE);
  442. X    retcodey = af_access(buf.af_syspath, buf.af_name, buf.af_type, AF_DERIVED);
  443. X    if((retcodex == 0) || (retcodey == 0))
  444. X      retcode = 0;
  445. X    else
  446. X      retcode = -1;
  447. X  }
  448. X
  449. Xif (mode == SOURCE)
  450. X  retcode = af_access(buf.af_syspath, buf.af_name, buf.af_type, AF_SOURCE);
  451. X
  452. Xif (mode == BINARY)
  453. X  retcode = af_access(buf.af_syspath, buf.af_name, buf.af_type, AF_DERIVED);
  454. X
  455. Xif (retcode == 0) /*  && (strcmp(buf.af_syspath,curvpath[0]))) */
  456. X  {
  457. X    (void) strcpy(actpath,buf.af_syspath);
  458. X    if ((pathlist[lastpath][0] = malloc(MAXNAMLEN)) == NIL)
  459. X      errexit(10,"malloc");
  460. X    (void) strcpy(pathlist[lastpath][0],buf.af_name);
  461. X    if (buf.af_type[0] != '\0')
  462. X      {
  463. X    (void) strcat(pathlist[lastpath][0],".");
  464. X    (void) strcat(pathlist[lastpath][0],buf.af_type);
  465. X      }
  466. X    if (!strcmp(buf.af_syspath,curvpath[0]))
  467. X      {
  468. X    if((pathlist[lastpath][1] = malloc(3)) == NIL)
  469. X      errexit(10,"malloc");
  470. X    (void) strcpy(pathlist[lastpath][1],"&$");
  471. X#ifdef DEBUG_FILES
  472. Xprintf("%d:%s:%s\n", lastpath,pathlist[lastpath][0], pathlist[lastpath][1]);
  473. X#endif DEBUG_FILES
  474. X    lastpath++;
  475. X      }
  476. X    else
  477. X      {
  478. X    if ((pathlist[lastpath][1] = malloc(MAXNAMLEN)) == NIL)
  479. X      errexit(10,"malloc");
  480. X    (void) strcpy(pathlist[lastpath][1],buf.af_syspath);
  481. X    (void) strcat(pathlist[lastpath][1],"/");
  482. X    (void) strcat(pathlist[lastpath][1],pathlist[lastpath][0]);
  483. X#ifdef DEBUG_FILES
  484. Xprintf("%d:%s:%s\n", lastpath,pathlist[lastpath][0], pathlist[lastpath][1]);
  485. X#endif DEBUG_FILES
  486. X    lastpath++;
  487. X    return(TRUE);
  488. X      }
  489. X  }
  490. X
  491. Xif(retcode == 0)
  492. X  {
  493. X    (void) strcpy(actpath,buf.af_syspath);
  494. X    return(TRUE);
  495. X  }
  496. X
  497. Xif (retcode == -1)
  498. X  return (FALSE);
  499. Xelse
  500. X  return (TRUE);
  501. X}
  502. X
  503. X
  504. XFILE *vmfopen( filename, mode, gen,rev)
  505. X     char *filename;
  506. X     char *mode;
  507. X     int gen;
  508. X     int rev;
  509. X{
  510. X  char syspath[MAXNAMLEN];
  511. X  char *name = NIL;
  512. X  char *type = NIL;
  513. X  
  514. X  Af_key key;
  515. X
  516. X  char *ind;
  517. X  char *ind2;
  518. X  char *basename;
  519. X  FILE *fp;
  520. X  char fname[MAXNAMLEN];
  521. X  (void) strcpy(fname, filename);
  522. X
  523. X  if ((ind = rindex(fname,'/')) == NIL)
  524. X    {
  525. X      (void) strcpy(syspath,curvpath[0]);
  526. X      basename = fname;
  527. X    }
  528. X  else
  529. X    {
  530. X      ind[0] = '\0';
  531. X      ind++;
  532. X      basename = ind;
  533. X      (void) strcpy(syspath,fname);
  534. X    }
  535. X  
  536. X  if ((ind2 = rindex(basename,'.')) == NIL)
  537. X    {
  538. X      name = basename;
  539. X    }
  540. X  else
  541. X    {
  542. X      ind2[0] = '\0';
  543. X      ind2++;
  544. X      type = ind2;
  545. X      name = basename;
  546. X    }
  547. X  if(af_getkey(syspath, name, type, gen, rev,NIL, &key) == -1)
  548. X    return ((FILE *) NIL);
  549. X  else
  550. X    {
  551. X      fp = af_open(&key, mode);
  552. X      return (fp);
  553. X    }
  554. X}
  555. X
  556. X
  557. Xget_set(anything,set)
  558. X     char *anything;
  559. X     Af_set *set;
  560. X     {
  561. X
  562. XAf_attrs buf;
  563. X
  564. Xchar bname[MAXNAMLEN];
  565. Xchar *p;
  566. Xchar *d;
  567. Xchar sysp[MAXNAMLEN];
  568. X
  569. Xsysp[0] = '\0';
  570. X
  571. X(void) strcpy(bname,anything);
  572. Xif ((p = rindex(bname,'.')) == NIL)
  573. X  ;
  574. Xelse
  575. X  {
  576. X    p[0] = '\0';
  577. X    *p++;
  578. X  }
  579. X
  580. Xif ((d = rindex(bname,'/')) != 0)
  581. X  {
  582. X    (void) strcpy(sysp, bname);
  583. X    d = rindex(sysp, '/');
  584. X    d[0] = '\0';
  585. X    *d++;
  586. X    (void) strcpy(bname,d);
  587. X  }
  588. Xaf_initattrs(&buf);
  589. X
  590. X(void) strcpy(buf.af_name,bname);
  591. Xif (p != NIL)
  592. X     (void) strcpy(buf.af_type,p);
  593. Xif(sysp[0] != '\0')
  594. X     (void) strcpy(buf.af_syspath, sysp);
  595. Xelse
  596. X  (void) strcpy(buf.af_syspath, curvpath[0]);
  597. Xif (af_find(&buf,set) == -1)
  598. X  errexit(10,"af_find");
  599. X}
  600. X
  601. X
  602. X
  603. XBool evtl_set_busy(dep, test)
  604. X     char *dep;
  605. X     Bool test;
  606. X{
  607. X  struct list *sellist;
  608. X  FILE *tmp_fp;
  609. X  FILE *afs_fp;
  610. X  Af_attrs buf1;
  611. X  Af_attrs buf2;
  612. X
  613. X  Af_key key2;
  614. X  Af_key keyt;
  615. X  
  616. X  Af_set set2;
  617. X  Af_set sett;
  618. X
  619. X  Bool t1;
  620. X  Bool match = FALSE;
  621. X  Bool full;
  622. X  Bool has_attr = FALSE;
  623. X  Bool busy_exist;
  624. X  int ii = 0;
  625. X  int tt = 0;
  626. X  int uda = 0;
  627. X  int pathind = 0;
  628. X  char *pp;
  629. X  char *ppp;
  630. X  char *zzz;
  631. X  char *pauth;
  632. X  char dep2[MAXNAMLEN];
  633. X  char *testdep;
  634. X  char testpath[MAXNAMLEN];
  635. X  char *testtype = NIL;
  636. X  Af_attrs testbuf;
  637. X  char *xxx;
  638. X  int testi = 0;
  639. X  int pathj;
  640. X  Af_key testkey;
  641. X  char *buf;
  642. X  char tmpname[MAXNAMLEN];
  643. X  char afsname[MAXNAMLEN];
  644. X  char afslinkname[MAXNAMLEN];
  645. X
  646. X  (void) strcpy(afsname,dep);
  647. X  stopflg = FALSE;
  648. X
  649. X  af_initattrs(&buf1);
  650. X  af_initattrs(&buf2);
  651. X  (void) strcpy(dep2,dep);
  652. X
  653. X  if (exists_file(dep2, 2))
  654. X    return(FALSE);
  655. X
  656. X  t1 = exists_file(dep2,1);
  657. X  if(t1)
  658. X    {
  659. X      if ((testdep = malloc(MAXNAMLEN)) == NIL)
  660. X    errexit(10,"malloc");
  661. X      (void) strcpy(testdep,dep2);
  662. X      if ((xxx = rindex(testdep,'/')) != NIL)
  663. X    {
  664. X      *xxx = '\0';
  665. X      (void) strcpy(testpath,testdep);
  666. X      xxx++;
  667. X      testdep = xxx;
  668. X    }
  669. X      else
  670. X    (void) strcpy(testpath,actpath);
  671. X
  672. X      if ((xxx = rindex(testdep,'.')) != NIL)
  673. X    {
  674. X      *xxx = '\0';
  675. X      xxx++;
  676. X      testtype = xxx;
  677. X    }
  678. X      else
  679. X    testtype = NIL;
  680. X
  681. X      if(af_getkey(testpath, testdep, testtype, AF_BUSYVERS, AF_BUSYVERS, NIL, &testkey) == -1)
  682. X    {
  683. X      if(af_getkey(testpath, testdep, testtype, AF_LASTVERS, AF_LASTVERS, NIL, &testkey) == -1)
  684. X    errexit(10,"af_getkey");
  685. X    }
  686. X      if(af_gattrs(&testkey,&testbuf) == -1)
  687. X    errexit(10,"af_gattrs");
  688. X      while(testbuf.af_udattrs[testi] != NIL)
  689. X    {
  690. X      if(!strncmp(testbuf.af_udattrs[testi],ATTRNAME,10))
  691. X        {
  692. X          has_attr = TRUE;
  693. X          break;
  694. X        }
  695. X      testi++;
  696. X    }
  697. X
  698. X      if((!has_attr) && (get_target(dep) == (struct rules *) NIL))
  699. X    {
  700. X      append_mtime(&testbuf,depth);
  701. X      if((af_dropkey(&testkey)) == -1)
  702. X        errexit(10,"af_dropkey");
  703. X      free(testdep);
  704. X    }
  705. X      (void) strcpy(actpath, testpath);
  706. X      if(has_attr)
  707. X    {
  708. X      if((af_dropkey(&testkey)) == -1)
  709. X        errexit(10,"af_dropkey");
  710. X      free(testdep);
  711. X      return(FALSE);
  712. X    }
  713. X    }
  714. X      
  715. X  if (t1)
  716. X    {
  717. X      /* dep name matches? */
  718. X      ii = 0;
  719. X      while ((currule->predlist[ii] != (struct list *) NIL) && (match == FALSE))
  720. X    {
  721. X      if((currule->predlist[ii]->selfunc(dep,currule->predlist[ii]->parv)) == TRUE)
  722. X        {
  723. X          match = TRUE;
  724. X          if (match == FALSE)
  725. X        ii++;
  726. X        }
  727. X      if (match == TRUE)
  728. X        {
  729. X          if(currule->predlist[ii]->i == SMILEY)
  730. X        {
  731. X          (void) tunix(NIL,NIL,(Af_set *) NIL);
  732. X        }
  733. X          if(currule->predlist[ii]->i == GRIMMY)
  734. X        {
  735. X          (void) stopit(NIL,NIL,(Af_set *) NIL);
  736. X        }
  737. X          
  738. X          (void) strcpy(dollarplus, dep);
  739. X
  740. X          if (index(dep,'/') == NIL)
  741. X        {
  742. X          if(strcmp(actpath,""))
  743. X            (void) strcpy(testpath,actpath);
  744. X          else
  745. X            (void) strcpy(testpath,curvpath[0]);
  746. X          (void) strcat(testpath,"/");
  747. X          (void) strcat(testpath,dep);
  748. X          get_set(testpath,&set2);
  749. X        }
  750. X          else
  751. X        get_set(dep,&set2);
  752. X
  753. X          if (set2.af_setlen == 0)
  754. X        return(TRUE);
  755. X
  756. X          /* generate buffer */
  757. X          af_initattrs(&buft);
  758. X          /* insert unique attrs */
  759. X        
  760. X          if (af_setgkey(&set2,0, &key2) == -1)
  761. X        errexit(10,"af_setgkey");
  762. X
  763. X          if (af_dropset(&set2) == -1)
  764. X        errexit(10,"af_dropset");
  765. X
  766. X          if (af_gattrs(&key2,&buf2) == -1)
  767. X        errexit(10,"af_gattrs");
  768. X          
  769. X          (void) strcpy(buft.af_name,buf2.af_name);
  770. X          (void) strcpy(buft.af_type,buf2.af_type);
  771. X          (void) strcpy(buft.af_syspath,buf2.af_syspath);
  772. X          sellist = currule->predlist[ii];
  773. X          while (sellist != (struct list *) NIL)
  774. X        {
  775. X          if((sellist->i == 0) && (test))
  776. X            sellist->selfunc(sellist->parn,sellist->parv, (Af_set *) NIL);
  777. X          sellist = sellist->cont;
  778. X        }
  779. X          sellist = currule->predlist[ii];
  780. X          while (sellist != (struct list *) NIL)
  781. X        {
  782. X          tt = get_attr_type(sellist->parn);
  783. X          if (sellist->i == 1)
  784. X            {
  785. X              switch (tt)
  786. X            {
  787. X            case 0:
  788. X              buft.af_gen = atoi(sellist->parv);
  789. X              break;
  790. X            case 1:
  791. X              buft.af_rev = atoi(sellist->parv);
  792. X              break;
  793. X            case 2:
  794. X              buft.af_state = (short) get_state_no(sellist->parv);
  795. X              if (buft.af_state == 99)
  796. X                errexit(16, sellist->parv);
  797. X              break;
  798. X            case 3:
  799. X              (void) strcpy(buft.af_author.af_username,sellist->parv);
  800. X              if ((pauth = index(buft.af_author.af_username,'@')) != NIL)
  801. X                {
  802. X                  *pauth = '\0';
  803. X                  pauth++;
  804. X                  (void) strcpy(buft.af_author.af_userhost, pauth);
  805. X                }
  806. X              break;
  807. X            case 4:
  808. X              errexit(10,"group id");
  809. X              break;
  810. X            case 5:
  811. X              if ((ppp = malloc((unsigned) (strlen(sellist->parv) + 1))) == NIL)
  812. X                errexit(10,"malloc");
  813. X              (void) strcpy(ppp,sellist->parv);
  814. X              if (( pp = index(ppp,'.')) == 0)
  815. X                errexit(9,sellist->parv);
  816. X              else
  817. X                {
  818. X                  pp[0] = '\0';
  819. X                  buft.af_gen = atoi(ppp);
  820. X                  pp++;
  821. X                  buft.af_rev = atoi(pp);
  822. X                }
  823. X              break;
  824. X            case 6:
  825. X              /* variant */
  826. X              break; /* evtl. set path & flags ???? */
  827. X            case 7:
  828. X              (void) strcpy(buft.af_syspath,sellist->parv);
  829. X              break;
  830. X            case 8:
  831. X              (void) strcpy(buft.af_host,sellist->parv);
  832. X              break;
  833. X            default:
  834. X              if ((buft.af_udattrs[uda] =
  835. X                   malloc((unsigned) (strlen(sellist->parv) + 1 + strlen(sellist->parn) + 1 + 1))) == NIL)
  836. X                errexit(10,"malloc");
  837. X              (void) strcpy(buft.af_udattrs[uda],sellist->parn);
  838. X              (void) strcat(buft.af_udattrs[uda],"=");
  839. X              (void) strcat(buft.af_udattrs[uda],sellist->parv);
  840. X              uda++;
  841. X              break;
  842. X            }
  843. X            }
  844. X/* else part by Sibylle */
  845. X          else
  846. X            {
  847. X              if ((sellist->i == 2) && (tt > 5))
  848. X                      /* if sellist->selfunc is attrnot, attrlt, attrgt,    */
  849. X                      /* attrle, attrge, attrmax or attrmin and parameter   */
  850. X                      /* type is uda then it's more efficient to perform    */
  851. X                      /* af_find on said uda. Hence parn is copied to buft. */
  852. X            {
  853. X              if ((buft.af_udattrs[uda] =
  854. X                   malloc((unsigned) (strlen(sellist->parn) + 1))) == NIL)
  855. X                errexit(10,"malloc");
  856. X              (void) strcpy(buft.af_udattrs[uda],sellist->parn);
  857. X              uda++;
  858. X              break;
  859. X            }
  860. X            }
  861. X              
  862. X          sellist = sellist->cont;
  863. X        }
  864. X          /* af_find with this buffer */
  865. X
  866. X          pathj = pathi;
  867. X          while(curvpath[pathj] == NIL)
  868. X        pathj--;
  869. X
  870. X          for(pathind = pathj; pathind >= 0; pathind--)
  871. X        {
  872. X          if ((zzz = rindex(dep,'/')) == NIL)
  873. X            {
  874. X              (void) strcpy(buft.af_syspath,curvpath[pathind]);
  875. X            }
  876. X          else
  877. X            {
  878. X              (void) strcpy(buft.af_syspath,dep);
  879. X              zzz = rindex(buft.af_syspath,'/');
  880. X              *zzz = '\0';
  881. X            }
  882. X          if (af_find(&buft,&sett) == -1)
  883. X            errexit(10,"af_find");
  884. X          if (sett.af_nkeys != 0)
  885. X            {
  886. X              sellist = currule->predlist[ii];
  887. X              full = TRUE;
  888. X              while((sellist != (struct list *) NIL) && (full))
  889. X            {
  890. X              if (sellist->i == 2)
  891. X                {
  892. X                  full = sellist->selfunc(sellist->parn, sellist->parv, &sett);
  893. X                }
  894. X              sellist = sellist->cont;
  895. X            }
  896. X            }
  897. X          if (sett.af_nkeys == 1)
  898. X            {
  899. X          /* ==> successful */
  900. X              if (test == FALSE)
  901. X            return(TRUE);
  902. X              if (af_setgkey(&sett,0,&keyt) ==  -1)
  903. X            errexit(10,"af_setgkey");
  904. X              if(af_gattrs(&keyt,&buft) == -1)
  905. X            errexit(10,"af_gattrs");
  906. X              if(confid == TRUE)
  907. X            write_confid(&buft);
  908. X
  909. X              append_attrs(&buft,depth);
  910. X
  911. X              if ((buft.af_state != AF_BUSY ) || (expflg))
  912. X            {
  913. X              /* link, unlink, set busy */
  914. X              if ((afs_fp = af_open(&keyt,"r")) == NULL)
  915. X                errexit(10,"af_open");
  916. X
  917. X              /* creation of a temporary file for the old revision */
  918. X              (void) strcpy(tmpname,mktemp("shapeXXXXXX"));
  919. X              if ((tmp_fp = fopen(tmpname, "w")) == NULL)
  920. X                errexit(10,"could not create tmpfile");
  921. X
  922. X              /* copy old revision into temp. file */
  923. X              if ((buf  = malloc((unsigned) buft.af_size)) == NIL)
  924. X                errexit(10,"malloc");
  925. X              (void) fread(buf,sizeof(char),(int) buft.af_size,afs_fp);
  926. X              
  927. X              if(noexpflg)
  928. X                (void) fwrite(buf,sizeof(char),(int) buft.af_size,tmp_fp);
  929. X              else
  930. X                WriteXPand(buf,buft.af_size,tmp_fp,&keyt);
  931. X              free(buf);
  932. X              af_close(afs_fp);
  933. X              (void) fclose(tmp_fp);
  934. X              if (buft.af_syspath == NIL)
  935. X                {
  936. X                  (void) strcpy(afsname,curvpath[0]);
  937. X                  (void) strcat(afsname,"/");
  938. X                }
  939. X              else
  940. X                {
  941. X                  (void) strcpy(afsname,buft.af_syspath);
  942. X                  (void) strcat(afsname,"/");
  943. X                }
  944. X              (void) strcat(afsname,buft.af_name);
  945. X              (void) strcat(afsname,".");
  946. X              (void) strcat(afsname,buft.af_type);
  947. X              if(buft.af_syspath == NIL)
  948. X                {
  949. X                  (void) strcpy(afslinkname,curvpath[0]);
  950. X                  (void) strcat(afslinkname,"/AFS/");
  951. X                }
  952. X              else
  953. X                {
  954. X                  (void) strcpy(afslinkname,buft.af_syspath);
  955. X                  (void) strcat(afslinkname,"/AFS/");
  956. X                }
  957. X              (void) strcat(afslinkname,buft.af_name);
  958. X              (void) strcat(afslinkname,".");
  959. X              (void) strcat(afslinkname,buft.af_type);
  960. X              (void) strcat(afslinkname,"XXXXXX");
  961. X              (void) strcpy(afslinkname, mktemp(afslinkname));
  962. X
  963. X              /* save busy version into AFS directory */
  964. X              (void) link(afsname,afsname);
  965. X              if (errno == EEXIST)
  966. X                {
  967. X                  busy_exist = TRUE;
  968. X                  if (link(afsname,afslinkname) != 0)
  969. X                errexit(20, dep);
  970. X                  if (unlink(afsname) != 0)
  971. X                errexit(21, afsname);
  972. X                }
  973. X              else
  974. X                busy_exist = FALSE;
  975. X              if (link(tmpname,afsname) != 0)
  976. X                errexit(22, afsname);
  977. X              if (unlink(tmpname) != 0)
  978. X                errexit(21, tmpname);
  979. X              register_link(afsname,afslinkname,busy_exist);
  980. X              if (buft.af_state != AF_BUSY)
  981. X                busy_done = TRUE;
  982. X              return (TRUE);
  983. X            }
  984. X              else
  985. X            return(TRUE);
  986. X            }
  987. X        }
  988. X          if ((sett.af_nkeys == 0) && (currule->predlist[ii+1] == (struct list *) NIL) && (!tunixflg))
  989. X        {
  990. X          if ((get_target(dep2)) != (struct rules *) NIL)
  991. X            return(TRUE);
  992. X          else
  993. X            errexit(17,dep2);
  994. X        }
  995. X          else
  996. X        /* next predicate */
  997. X        {
  998. X          if (stopflg)
  999. X            errexit(28,dep);
  1000. X          if(tunixflg)
  1001. X            {
  1002. X              tunixflg = FALSE;
  1003. X              return(FALSE);
  1004. X            }
  1005. X          if (af_dropset(&sett) == -1)
  1006. X            errexit(10,"af_dropset");
  1007. X          
  1008. X        }
  1009. X        }
  1010. X      ii++;
  1011. X      stopflg = FALSE;
  1012. X      match = FALSE;
  1013. X      reset_vclass();
  1014. X    } /* end while */
  1015. X
  1016. X/*      if (buft.af_syspath != NIL)
  1017. X    {
  1018. X      (void) strcpy(afsname,buft.af_syspath);
  1019. X      (void) strcat(afsname,"/");
  1020. X      (void) strcat(afsname,dep);
  1021. X    }
  1022. X    (void) link(afsname,afsname);
  1023. X      if ((buft.af_state == AF_BUSY) && (errno == EEXIST))
  1024. X    return(TRUE);
  1025. X*/
  1026. X      if ((match == FALSE) && (currule->predlist[ii] == (struct list *) NIL))
  1027. X    {
  1028. X      if ((get_target(dep)) != (struct rules *) NIL)
  1029. X        return(TRUE);
  1030. X      else
  1031. X        errexit(17,dep);
  1032. X    }
  1033. X    }
  1034. X  /*NOTREACHED*/
  1035. X  return(FALSE);
  1036. X}
  1037. X
  1038. X
  1039. X
  1040. Xint init_confid(name)
  1041. X     char *name;
  1042. X{
  1043. X  fprintf(cid,"###### CONFID for %s ######\n", name);
  1044. X  fprintf(cid,"\n");
  1045. X  fprintf(cid,"#%% RULE-SECTION\n");
  1046. X  fprintf(cid,"@%s:\n", name);
  1047. X}
  1048. X
  1049. X
  1050. X
  1051. Xint write_confid(buf)
  1052. X     Af_attrs *buf;
  1053. X{
  1054. X  fprintf(cid,"\t%s.%s,\n", buf->af_name, buf->af_type);
  1055. X  
  1056. X  fprintf(cid,"\tattr(host,%s),\n", buf->af_host);
  1057. X
  1058. X  fprintf(cid,"\tattr(syspath,%s),\n", buf->af_syspath);
  1059. X
  1060. X/*  fprintf(cid,"\tattr(type,%s),\n", buf->af_type); */
  1061. X
  1062. X  if(buf->af_gen != AF_BUSYVERS)
  1063. X    {
  1064. X      fprintf(cid,"\tattr(generation,%d),\n", buf->af_gen);
  1065. X
  1066. X      fprintf(cid,"\tattr(revision,%d),\n", buf->af_rev);
  1067. X    }
  1068. X
  1069. X  if (strcmp(buf->af_variant,""))
  1070. X    fprintf(cid,"\tattr(variant,%s),\n", buf->af_variant);
  1071. X
  1072. X  if (buf->af_state != AF_FROZEN)
  1073. X    {
  1074. X      fprintf(cid,"\tmsg(warning: confid contains %s version for %s.%s),\n",
  1075. X          states[buf->af_state], buf->af_name, buf->af_type);
  1076. X      fprintf(stderr,"shape - warning: confid contains %s version for %s.%s\n",
  1077. X          states[buf->af_state], buf->af_name, buf->af_type);
  1078. X    }
  1079. X
  1080. X  fprintf(cid,"\tattr(state,%s),\n", states[buf->af_state]);
  1081. X/*  fprintf(cid,"\tattr(owner,%s@%s),\n",
  1082. X      buf->af_owner.af_username, buf->af_owner.af_userhost); */
  1083. X
  1084. X  fprintf(cid,"\tattr(author,%s@%s)",
  1085. X      buf->af_author.af_username, buf->af_author.af_userhost);
  1086. X
  1087. X/*  fprintf(cid,"\tattr(size,%d),\n", buf->af_size); */
  1088. X
  1089. X/*  fprintf(cid,"\tattr(mode,%d),\n", buf->af_mode); */
  1090. X
  1091. X/*  if(strcmp(buf->af_locker.af_username,""))
  1092. X    fprintf(cid,"\tattr(locker,%s@%s),\n",
  1093. X        buf->af_locker.af_username, buf->af_locker.af_userhost); */
  1094. X
  1095. X/*  fprintf(cid,"\tattr(mtime,%d),\n", buf->af_mtime); */
  1096. X
  1097. X/*  fprintf(cid,"\tattr(atime,%d),\n", buf->af_atime); */
  1098. X
  1099. X/*  fprintf(cid,"\tattr(ctime,%d),\n", buf->af_ctime); */
  1100. X
  1101. X/*  fprintf(cid,"\tattr(stime,%d),\n", buf->af_stime); */
  1102. X
  1103. X/*  fprintf(cid,"\tattr(ltime,%d)", buf->af_ltime); */
  1104. X  
  1105. X    fprintf(cid,";\n");
  1106. X
  1107. X  fprintf(cid,"\n");
  1108. X  (void) fflush(cid);
  1109. X}
  1110. X
  1111. Xint finish_confid()
  1112. X
  1113. X{
  1114. X  fprintf(cid,"\t:-\) SMILEY,\n\tmsg\(\"Just to get a . to the end of the rule\"\).\n\n");
  1115. X  fprintf(cid,"#%% END-RULE-SECTION\n");
  1116. X  fprintf(cid,"\n");
  1117. X  dump(cid);
  1118. X  ruledump(cid);
  1119. X  vardump(cid);
  1120. X}
  1121. X
  1122. X
  1123. XFILE *cmfopen( filename, mode, gen,rev)
  1124. X     char *filename;
  1125. X     char *mode;
  1126. X     /*ARGSUSED*/
  1127. X     int gen;
  1128. X     int rev;
  1129. X{
  1130. X  char syspath[MAXNAMLEN];
  1131. X  char *name = NIL;
  1132. X  char *type = NIL;
  1133. X  
  1134. X  Af_key key;
  1135. X
  1136. X  char *ind;
  1137. X  char *ind2;
  1138. X  char *basename;
  1139. X  FILE *fp;
  1140. X  char fname[MAXNAMLEN];
  1141. X  (void) strcpy(fname, filename);
  1142. X
  1143. X  if ((ind = rindex(fname,'/')) == NIL)
  1144. X    {
  1145. X      (void) strcpy(syspath,curvpath[0]);
  1146. X      basename = fname;
  1147. X    }
  1148. X  else
  1149. X    {
  1150. X      ind[0] = '\0';
  1151. X      ind++;
  1152. X      basename = ind;
  1153. X      (void) strcpy(syspath,fname);
  1154. X    }
  1155. X  
  1156. X  if ((ind2 = rindex(basename,'.')) == NIL)
  1157. X    {
  1158. X      name = basename;
  1159. X    }
  1160. X  else
  1161. X    {
  1162. X      ind2[0] = '\0';
  1163. X      ind2++;
  1164. X      type = ind2;
  1165. X      name = basename;
  1166. X    }
  1167. X  if(af_crkey(syspath, name, type,&key) == -1)
  1168. X    errexit(10,"af_crkey");
  1169. X  else
  1170. X    {
  1171. X      fp = af_open(&key, mode);
  1172. X      return (fp);
  1173. X    }
  1174. X  return((FILE *) NIL);
  1175. X}
  1176. END_OF_FILE
  1177. if test 27004 -ne `wc -c <'src/shape/files.c'`; then
  1178.     echo shar: \"'src/shape/files.c'\" unpacked with wrong size!
  1179. fi
  1180. # end of 'src/shape/files.c'
  1181. fi
  1182. echo shar: End of archive 24 \(of 33\).
  1183. cp /dev/null ark24isdone
  1184. MISSING=""
  1185. 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
  1186.     if test ! -f ark${I}isdone ; then
  1187.     MISSING="${MISSING} ${I}"
  1188.     fi
  1189. done
  1190. if test "${MISSING}" = "" ; then
  1191.     echo You have unpacked all 33 archives.
  1192.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1193. else
  1194.     echo You still need to unpack the following archives:
  1195.     echo "        " ${MISSING}
  1196. fi
  1197. ##  End of shell archive.
  1198. exit 0
  1199.