home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume19 / shape / part13 < prev    next >
Encoding:
Internet Message Format  |  1989-05-31  |  45.8 KB

  1. Subject:  v19i026:  A software configuration management system, Part13/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 26
  8. Archive-name: shape/part13
  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 13 (of 33)."
  19. # Contents:  src/afs/afcattrs.c src/afs/affiles.c src/shape/selrule.c
  20. #   src/shape/shapeopt.c
  21. # Wrapped by rsalz@papaya.bbn.com on Thu Jun  1 19:27:03 1989
  22. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  23. if test -f 'src/afs/afcattrs.c' -a "${1}" != "-c" ; then 
  24.   echo shar: Will not clobber existing file \"'src/afs/afcattrs.c'\"
  25. else
  26. echo shar: Extracting \"'src/afs/afcattrs.c'\" \(10117 characters\)
  27. sed "s/^X//" >'src/afs/afcattrs.c' <<'END_OF_FILE'
  28. X/*
  29. X * Copyright (C) 1989, 1990 W. Koch, A. Lampen, A. Mahler, W. Obst,
  30. X *  and U. Pralle
  31. X * 
  32. X * This software is published on an as-is basis. There is ABSOLUTELY NO
  33. X * WARRANTY for any part of this software to work correctly or as described
  34. X * in the manuals. We do not accept any liability for any kind of damage
  35. X * caused by use of this software, such as loss of data, time, money, or 
  36. X * effort.
  37. X * 
  38. X * Permission is granted to use, copy, modify, or distribute any part of
  39. X * this software as long as this is done without asking for charge, and
  40. X * provided that this copyright notice is retained as part of the source
  41. X * files. You may charge a distribution fee for the physical act of
  42. X * transferring a copy, and you may at your option offer warranty
  43. X * protection in exchange for a fee.
  44. X * 
  45. X * Direct questions to: Tech. Univ. Berlin
  46. X *              Wilfried Koch
  47. X *              Sekr. FR 5-6 
  48. X *              Franklinstr. 28/29
  49. X *              D-1000 Berlin 10, West Germany
  50. X * 
  51. X *              Tel: +49-30-314-22972
  52. X *              E-mail: shape@coma.uucp or shape@db0tui62.bitnet
  53. X */
  54. X/*LINTLIBRARY*/
  55. X/*
  56. X *    Shape/AFS
  57. X *
  58. X *    afcattrs.c - read and write complex attributes
  59. X *
  60. X *    Author: Andreas Lampen, TU-Berlin (andy@coma.UUCP
  61. X *                       andy@db0tui62.BITNET)
  62. X *
  63. X *    $Header: afcattrs.c[1.5] Wed Feb 22 16:27:20 1989 andy@coma published $
  64. X *
  65. X *    EXPORT:
  66. X *    af_snote -- set note (write note text)
  67. X *    af_rnote -- return note
  68. X *    af_svariant -- set variant attribute
  69. X *    af_rvariant -- return variant
  70. X *    af_sudattr -- set or modify user defined attribute
  71. X *    af_rudattr -- return user defined attributes
  72. X */
  73. X
  74. X#include <stdio.h>
  75. X#include <string.h>
  76. X#ifdef SUNOS_4_0
  77. X#include <strings.h>
  78. X#endif
  79. X
  80. X#include "typeconv.h"
  81. X#include "afsys.h"
  82. X#include "afs.h"
  83. X
  84. X#ifdef MEMDEBUG
  85. Xextern FILE *memprot;
  86. X#endif
  87. X
  88. Xchar *malloc();
  89. X
  90. X/*====================================================================
  91. X *    af_snote -- set note (write note text)
  92. X *
  93. X *====================================================================*/
  94. X
  95. XEXPORT af_snote (key, buf)
  96. X     Af_key *key;
  97. X     char   *buf;
  98. X{
  99. X  int  len;
  100. X  char internalbuf[1];
  101. X
  102. X  internalbuf[0] = '\0';
  103. X
  104. X  if (af_keytest (key))
  105. X    SFAIL ("snote", "", AF_EINVKEY, ERROR);
  106. X  if (VATTR(key).af_state == AF_BUSY)
  107. X    SFAIL ("snote", "", AF_EBUSY, ERROR);
  108. X  if (VATTR(key).af_class & AF_DERIVED)
  109. X    SFAIL ("snote", "", AF_EDERIVED, ERROR);
  110. X  if (af_checkperm (key, AF_LOCKHOLDER | AF_AUTHOR | AF_OWNER) == ERROR)
  111. X    SFAIL ("snote", "", AF_EACCES, ERROR);
  112. X
  113. X  if (af_readdata (key->af_ldes) == ERROR)
  114. X    return (ERROR);
  115. X
  116. X  if (!buf) /* if buf is a nil pointer */
  117. X    buf = internalbuf;
  118. X
  119. X  len = strlen(buf) + sizeof (char); /* length of string plus nullbyte */
  120. X  if (len > VATTR(key).af_notesize)
  121. X    {
  122. X      if ((VATTR(key).af_note = af_malloc (key->af_ldes, (unsigned) (len * sizeof (char)))) == (char *)0)
  123. X    FAIL ("snote", "malloc", AF_ESYSERR, ERROR);
  124. X    }
  125. X  /* change datasize in header */
  126. X  key->af_ldes->af_datasize -= VATTR(key).af_notesize;
  127. X  key->af_ldes->af_datasize += len;
  128. X
  129. X  (void) strncpy (VATTR(key).af_note, buf, len);
  130. X  VATTR(key).af_notesize = len;
  131. X
  132. X  /* save changes */
  133. X  if (af_updtvers (key, AF_CHANGE) == ERROR)
  134. X    return (ERROR);
  135. X  return (AF_OK);
  136. X}
  137. X
  138. X
  139. X
  140. X/*====================================================================
  141. X *    af_rnote -- get pointer to note (read only)
  142. X *
  143. X *====================================================================*/
  144. X
  145. XEXPORT char *af_rnote (key)
  146. X     Af_key *key;
  147. X{
  148. X  char *note;
  149. X
  150. X  if (af_keytest (key))
  151. X    SFAIL ("rnote", "", AF_EINVKEY, (char *)0);
  152. X  if (VATTR(key).af_state == AF_BUSY)
  153. X    SFAIL ("rnote", "", AF_EBUSY, (char *)0);
  154. X  if (VATTR(key).af_class & AF_DERIVED)
  155. X    SFAIL ("rnote", "", AF_EDERIVED, (char *)0);
  156. X
  157. X  if (af_readdata (key->af_ldes) == ERROR)
  158. X    return ((char *)0);
  159. X
  160. X  if (VATTR(key).af_notesize != 0)
  161. X    {
  162. X      if ((note = malloc ((unsigned) VATTR(key).af_notesize)) == (char *)0)
  163. X    FAIL ("rnote", "malloc", AF_ESYSERR, (char *)0);
  164. X      (void) strcpy (note, VATTR(key).af_note);
  165. X      /* replace newline by nullbyte */
  166. X      note[VATTR(key).af_notesize-1] = '\0';
  167. X    }
  168. X  else
  169. X    {
  170. X      if ((note = malloc ((unsigned) sizeof (char))) == (char *)0)
  171. X    FAIL ("rnote", "malloc", AF_ESYSERR, (char *)0);
  172. X      note[0] = '\0';
  173. X    }
  174. X
  175. X  return (note);
  176. X}
  177. X
  178. X
  179. X
  180. X/*====================================================================
  181. X *    af_svariant -- set variant attribute
  182. X *
  183. X *====================================================================*/
  184. X
  185. XEXPORT af_svariant (key, buf)
  186. X     Af_key *key;
  187. X     char   *buf;
  188. X{
  189. X  if (af_keytest (key))
  190. X    SFAIL ("svariant", "", AF_EINVKEY, ERROR);
  191. X  if (buf)
  192. X    if (strlen (buf) >= MAXVARLEN)
  193. X      SFAIL ("svariant", "", AF_ETOOLONG, ERROR);
  194. X  if (VATTR(key).af_class & AF_DERIVED)
  195. X    SFAIL ("svariant", "", AF_EDERIVED, ERROR);
  196. X  if (af_checkperm (key, AF_OWNER | AF_AUTHOR) == ERROR)
  197. X    return (ERROR);
  198. X
  199. X  VATTR(key).af_variant = af_entersym (buf);
  200. X
  201. X  /* save changes */
  202. X  if (af_updtvers (key, AF_CHANGE) == ERROR)
  203. X    return (ERROR);
  204. X  return (AF_OK);
  205. X}
  206. X
  207. X
  208. X
  209. X/*====================================================================
  210. X *    af_rvariant -- return variant attribute
  211. X *
  212. X *====================================================================*/
  213. X
  214. XEXPORT char *af_rvariant (key)
  215. X     Af_key *key;
  216. X{
  217. X  char *variant;
  218. X
  219. X  if (af_keytest (key))
  220. X    SFAIL ("rvariant", "", AF_EINVKEY, (char *)0);
  221. X  if (VATTR(key).af_class & AF_DERIVED)
  222. X    SFAIL ("rvariant", "", AF_EDERIVED, (char *)0);
  223. X
  224. X  if (VATTR(key).af_variant)
  225. X    {
  226. X      if ((variant = malloc ((unsigned) strlen (VATTR(key).af_variant) + sizeof (char))) == (char *)0)
  227. X    FAIL ("rvariant", "malloc", AF_ESYSERR, (char *)0);
  228. X      (void) strcpy (variant, VATTR(key).af_variant);
  229. X    }
  230. X  else
  231. X    {
  232. X      if ((variant = malloc ((unsigned) sizeof (char))) == (char *)0)
  233. X    FAIL ("rvariant", "malloc", AF_ESYSERR, (char *)0);
  234. X      variant[0] = '\0';
  235. X    }
  236. X
  237. X  return (variant);
  238. X}
  239. X
  240. X/*====================================================================
  241. X *    af_sudattr -- set or modify user defined attribute
  242. X *               User defined attributes are strings of the following form:
  243. X *                 name=value
  244. X *               For manipulating user defined attributes you have three
  245. X *               modes:
  246. X *               AF_ADD -- add value to attribute if name is present or
  247. X *                         add user defined attribute otherwise
  248. X *               AF_REMOVE -- remove attribute
  249. X *               AF_REPLACE -- replace attribute
  250. X *
  251. X *               Returns AF_OK on successful execution, otherwise ERROR
  252. X *
  253. X *               Caution: the string "attr" must not contain '\n' !!
  254. X *
  255. X *====================================================================*/
  256. X
  257. XEXPORT af_sudattr (key, mode, attr)
  258. X     Af_key *key;
  259. X     int    mode;
  260. X     char   *attr;
  261. X{
  262. X  char *udaptr, *tmpuda, *valptr;
  263. X  int  tail;
  264. X
  265. X  if (af_keytest (key))
  266. X    SFAIL ("sudattr", "", AF_EINVKEY, ERROR);
  267. X  if (VATTR(key).af_state == AF_FROZEN)
  268. X    SFAIL ("sudattr", "", AF_EWRONGSTATE, ERROR);
  269. X
  270. X  /* look for delimiter character in attribute string */
  271. X  if (!attr || (index (attr, AF_UDAVALDEL) != (char *)0))
  272. X    SFAIL ("sudattr", "", AF_EFORMAT, ERROR);
  273. X
  274. X  if (af_checkperm (key, AF_WORLD) == ERROR)
  275. X    return (ERROR);
  276. X
  277. X  /* search entry */
  278. X  udaptr = af_symlookup (&(VATTR(key).af_uhtab), attr,
  279. X             (Af_revlist *)0, (Af_revlist **)0); 
  280. X
  281. X  switch (mode)
  282. X    {
  283. X    case AF_ADD: if (udaptr != (char *)0)
  284. X                   {
  285. X             /* build new entry and replace old one */
  286. X             valptr = index (attr, '=') + sizeof (char);
  287. X             if ((tmpuda = malloc ((unsigned) ((strlen (udaptr) + strlen (valptr) +2) * sizeof (char)))) == (char *)0)
  288. X               FAIL ("sudattr", "malloc", AF_ESYSERR, ERROR);
  289. X
  290. X             (void) strcpy (tmpuda, udaptr);
  291. X             tail = strlen (tmpuda);
  292. X             tmpuda[tail] = AF_UDAVALDEL;
  293. X             tmpuda[tail+1] = '\0';
  294. X             (void) strcat (tmpuda, valptr);
  295. X             (void) af_replsym (&(VATTR(key).af_uhtab), tmpuda, (Af_revlist *)0);
  296. X             free (tmpuda);
  297. X            }    
  298. X                 else
  299. X           {
  300. X             /* add new entry */
  301. X             if (VATTR(key).af_udanum == AF_MAXUDAS-1)
  302. X               SFAIL ("sudattr", "", AF_EUDASNUM, ERROR);
  303. X             (void) af_hashsym (&(VATTR(key).af_uhtab), attr,(Af_revlist *)0);
  304. X#ifdef MEMDEBUG
  305. X             fprintf (memprot, "UdaCattr (%s)\n", attr);
  306. X#endif
  307. X             VATTR(key).af_udanum++;
  308. X           }
  309. X                 break;
  310. X
  311. X    case AF_REMOVE: if (udaptr == (char *)0)
  312. X                      SFAIL ("sudattr", "", AF_ENOUDA, ERROR);
  313. X            (void) af_delsym (&(VATTR(key).af_uhtab), udaptr,(Af_revlist *)0);
  314. X            VATTR(key).af_udanum--;
  315. X                    break;
  316. X
  317. X    case AF_REPLACE: if (udaptr == (char *)0)
  318. X                       SFAIL ("sudattr", "", AF_ENOUDA, ERROR);
  319. X                     (void) af_replsym (&(VATTR(key).af_uhtab), attr, (Af_revlist *)0);
  320. X                     break;
  321. X    default: SFAIL ("sudattr", "", AF_EMODE, ERROR);
  322. X    }
  323. X
  324. X  /* save changes */
  325. X  if (af_updtvers (key, AF_CHANGE) == ERROR)
  326. X    return (ERROR);
  327. X  return (AF_OK);
  328. X}
  329. X
  330. X
  331. X
  332. X/*====================================================================
  333. X *    af_rudattr -- return user defined attributes
  334. X *
  335. X *====================================================================*/
  336. X
  337. XEXPORT char *af_rudattr (key, name)
  338. X     Af_key *key;
  339. X     char   *name;
  340. X{
  341. X  char *udattr, *entry, *valptr;
  342. X
  343. X  if (af_keytest (key))
  344. X    SFAIL ("rudattr", "", AF_EINVKEY, (char *)0);
  345. X  if (!name)
  346. X    SFAIL ("rudattr", "no attribute name given", AF_EMISC, (char *)0);
  347. X
  348. X  if ((entry = af_symlookup (&(VATTR(key).af_uhtab), name,
  349. X                 (Af_revlist *)0, (Af_revlist **)0)) == (char *)0)
  350. X    return (char *)0;
  351. X
  352. X  if ((valptr = index (entry, AF_UDANAMDEL)) != (char *)0)
  353. X    {
  354. X      if ((udattr = malloc ((unsigned) strlen(valptr) + sizeof(char))) == (char *)0)
  355. X    FAIL ("rudattr", "malloc", AF_ESYSERR, (char *)0);
  356. X      /* replace delimiters by '\n' */
  357. X      (void) strcpy (udattr, valptr+1);
  358. X      valptr = udattr;
  359. X      while ((valptr = index (valptr, AF_UDAVALDEL)) != (char *)0)
  360. X    valptr[0] = '\n';
  361. X    }
  362. X  else
  363. X    {
  364. X      if ((udattr = malloc ((unsigned) sizeof(char))) == (char *)0)
  365. X    FAIL ("rudattr", "malloc", AF_ESYSERR, (char *)0);
  366. X      udattr[0] = '\0';
  367. X    }
  368. X  
  369. X  return (udattr);
  370. X}
  371. X
  372. END_OF_FILE
  373. if test 10117 -ne `wc -c <'src/afs/afcattrs.c'`; then
  374.     echo shar: \"'src/afs/afcattrs.c'\" unpacked with wrong size!
  375. fi
  376. # end of 'src/afs/afcattrs.c'
  377. fi
  378. if test -f 'src/afs/affiles.c' -a "${1}" != "-c" ; then 
  379.   echo shar: Will not clobber existing file \"'src/afs/affiles.c'\"
  380. else
  381. echo shar: Extracting \"'src/afs/affiles.c'\" \(10601 characters\)
  382. sed "s/^X//" >'src/afs/affiles.c' <<'END_OF_FILE'
  383. X/*
  384. X * Copyright (C) 1989, 1990 W. Koch, A. Lampen, A. Mahler, W. Obst,
  385. X *  and U. Pralle
  386. X * 
  387. X * This software is published on an as-is basis. There is ABSOLUTELY NO
  388. X * WARRANTY for any part of this software to work correctly or as described
  389. X * in the manuals. We do not accept any liability for any kind of damage
  390. X * caused by use of this software, such as loss of data, time, money, or 
  391. X * effort.
  392. X * 
  393. X * Permission is granted to use, copy, modify, or distribute any part of
  394. X * this software as long as this is done without asking for charge, and
  395. X * provided that this copyright notice is retained as part of the source
  396. X * files. You may charge a distribution fee for the physical act of
  397. X * transferring a copy, and you may at your option offer warranty
  398. X * protection in exchange for a fee.
  399. X * 
  400. X * Direct questions to: Tech. Univ. Berlin
  401. X *              Wilfried Koch
  402. X *              Sekr. FR 5-6 
  403. X *              Franklinstr. 28/29
  404. X *              D-1000 Berlin 10, West Germany
  405. X * 
  406. X *              Tel: +49-30-314-22972
  407. X *              E-mail: shape@coma.uucp or shape@db0tui62.bitnet
  408. X */
  409. X/*LINTLIBRARY*/
  410. X/*
  411. X *    Shape/AFS
  412. X *
  413. X *    affiles.c -- UNIX-files in AFS
  414. X *
  415. X *    Author: Andreas Lampen, TU-Berlin (andy@coma.UUCP)
  416. X *                      (andy@db0tui62.BITNET)
  417. X *
  418. X *    $Header: affiles.c[1.6] Wed Feb 22 16:27:34 1989 andy@coma published $
  419. X *
  420. X *    EXPORT:
  421. X *      af_access -- see if any version of named file exists
  422. X *    af_crkey -- create filekey
  423. X *    af_open -- open AFS-file
  424. X *    af_close -- close AFS-file
  425. X *      af_link -- create a link to a AFS-file
  426. X *    af_rm -- remove AFS-file
  427. X *    af_restore -- restore derived file
  428. X */
  429. X
  430. X#include <stdio.h>
  431. X#include <sys/param.h>
  432. X#include <sys/file.h>
  433. X#include <sys/types.h>
  434. X#include <sys/stat.h>
  435. X
  436. X#include "typeconv.h"
  437. X#include "afsys.h"
  438. X#include "afs.h"
  439. X
  440. X/*================================================================
  441. X *    af_access -- see if any version of named file exists
  442. X *
  443. X *================================================================*/
  444. X
  445. XEXPORT af_access (path, name, type, mode)
  446. X     char *path, *name, *type;
  447. X     int  mode;
  448. X{
  449. X  char *unixname, *arnamptr, *pathname, *nameptr, *typeptr;
  450. X  Af_revlist *list, *af_rbplist(), *af_readattrs();
  451. X  short maxindex, i;
  452. X  bool loaded = FALSE;
  453. X  
  454. X  pathname = af_uniqpath (path);
  455. X
  456. X  if (mode & AF_DERIVED) /* look in binary pool */
  457. X    {
  458. X      /* lookup in binary pool */
  459. X      
  460. X      if ((list = af_rbplist (pathname)) == (Af_revlist *)0)
  461. X    return (ERROR);
  462. X      
  463. X      nameptr = af_entersym (name);
  464. X      typeptr = af_entersym (type);
  465. X      maxindex = list->af_nrevs;
  466. X      for (i = 0; i < maxindex; i++)
  467. X    {
  468. X      /* skip holes in the list */
  469. X      if (!(list->af_list[i].af_class & AF_VALID))
  470. X        {
  471. X          maxindex++;
  472. X          continue;
  473. X        }
  474. X      if ((nameptr == list->af_list[i].af_name) &&
  475. X          (typeptr == list->af_list[i].af_type))
  476. X        return (AF_OK);
  477. X    }
  478. X    }
  479. X  else /* look in directory */
  480. X    {
  481. X      unixname = af_unixname (pathname, name, type);
  482. X      /* if a named unix file exists */
  483. X      if (!af_sysaccess (unixname, F_OK))
  484. X    return (AF_OK);
  485. X      /* look for archive */
  486. X      arnamptr = af_garname (pathname, name, type);
  487. X      if (!af_sysaccess (arnamptr, F_OK))
  488. X    {
  489. X      /* look if there are versions in archive file */
  490. X      list = af_readattrs (pathname, name, type, &loaded);
  491. X      if (list->af_nrevs > 0)
  492. X        return (AF_OK);
  493. X    }
  494. X    }
  495. X  return (ERROR);
  496. X}
  497. X
  498. X/*================================================================
  499. X *    af_crkey
  500. X *
  501. X *================================================================*/
  502. X
  503. XEXPORT af_crkey (path, name, type, key)
  504. X     char *path;
  505. X     char *name, *type;
  506. X     Af_key *key;
  507. X{
  508. X  char *busyname, *uniqpath;
  509. X  FILE *busyfile;
  510. X  Af_revlist *af_readattrs();
  511. X  bool loaded = FALSE;
  512. X  Af_key *busykey, *af_gbuskey();
  513. X  Af_user *author;
  514. X  struct stat bibuf;
  515. X  
  516. X  uniqpath = af_uniqpath (path);
  517. X  busyname = af_gbusname (uniqpath, name, type);
  518. X  
  519. X  /* if file does not exist -- create it */
  520. X  if ((lstat (busyname, &bibuf)) == ERROR)
  521. X    {
  522. X      if ((busyfile = fopen (busyname, "w")) == (FILE *)0)
  523. X    FAIL ("crkey", "fopen", AF_ESYSERR, ERROR);
  524. X      (void) fclose (busyfile);
  525. X      (void) stat (busyname, &bibuf);
  526. X    }
  527. X  
  528. X  key->af_ldes = af_readattrs (uniqpath, name, type, &loaded);
  529. X  
  530. X  /* select busy version if present */
  531. X  if ((busykey = af_gbuskey (key->af_ldes)) == (Af_key *)0)
  532. X    FAIL ("crkey", "no space for busy version", AF_EINTERNAL, ERROR);
  533. X  key->af_lpos = busykey->af_lpos;
  534. X
  535. X  if (af_checkperm (busykey, AF_WORLD) == ERROR)
  536. X    return (ERROR);
  537. X
  538. X  /* if busy version was invalid up to now, initialize it */
  539. X  if (!(VATTR(key).af_class & AF_VALID))
  540. X    {
  541. X      key->af_ldes->af_nrevs += 1;
  542. X      VATTR(key).af_class = AF_VALID;
  543. X      if ((author = af_getuser (bibuf.st_uid)) == (Af_user *)0)
  544. X    {
  545. X      af_wng ("crkey", "invalid userID in inode of busy file");
  546. X      author = af_getuser (getuid());
  547. X    }
  548. X      VATTR(key).af_auname = af_entersym (author->af_username);
  549. X      VATTR(key).af_auhost = af_enterhost (author->af_userhost);
  550. X      VATTR(key).af_mode = (u_short) bibuf.st_mode;
  551. X      VATTR(key).af_lckname = (char *)0;
  552. X      VATTR(key).af_lckhost = (char *)0;
  553. X      VATTR(key).af_mtime = (time_t) af_cvttime (bibuf.st_mtime);
  554. X      VATTR(key).af_atime = (time_t) af_cvttime (bibuf.st_atime);
  555. X      VATTR(key).af_ctime = (time_t) af_cvttime (bibuf.st_ctime);
  556. X      VATTR(key).af_stime = AF_NOTIME;
  557. X      VATTR(key).af_ltime = AF_NOTIME;
  558. X      VATTR(key).af_fsize = (off_t) bibuf.st_size;
  559. X    }
  560. X
  561. X  key->af_ldes->af_refcount++;
  562. X  VATTR(key).af_nlinks++;
  563. X
  564. X/* possibly the date of last access is *not* set properly */
  565. X/* instead of */
  566. X  (void) af_updtvers (key, 0);
  567. X/* this should be */
  568. X/* if (af_updtvers (key, 0) == ERROR) */
  569. X/*    return (ERROR); */
  570. X
  571. X  return (AF_OK);
  572. X}
  573. X
  574. X/*================================================================
  575. X *    af_open
  576. X *
  577. X *================================================================*/
  578. X
  579. XEXPORT FILE *af_open (key, mode)
  580. X     Af_key *key;
  581. X     char   *mode;
  582. X{
  583. X  FILE   *file;
  584. X  char   *tmpname;
  585. X  
  586. X  if (af_keytest (key))
  587. X    SFAIL ("open", "", AF_EINVKEY, (FILE *)0);
  588. X  
  589. X  /* if file is present as busy version */
  590. X  if (VATTR(key).af_state == AF_BUSY)
  591. X    {
  592. X      if ((file = fopen (key->af_ldes->af_busyfilename, mode)) == (FILE *)0)
  593. X    FAIL ("open", "fopen", AF_ESYSERR, (FILE *)0);
  594. X      return (file);
  595. X    }
  596. X  
  597. X  /* saved versions can be opened only for reading */
  598. X  if (mode[0] != 'r')
  599. X    SFAIL ("open", "", AF_ESAVED, (FILE *)0);
  600. X  
  601. X  /* see if file is readable */
  602. X  if (af_checkread (key) == ERROR)
  603. X    SFAIL ("open", "", AF_EACCES, (FILE *)0);
  604. X
  605. X  /* build name for temporary file */
  606. X  tmpname = af_gtmpname (CATTR(key).af_syspath, VATTR(key).af_name);
  607. X  af_regtmpfile (tmpname);
  608. X
  609. X  if (af_bldfile (key, tmpname) == ERROR)
  610. X    return ((FILE *)0);
  611. X
  612. X  if ((file = fopen (tmpname, mode)) == (FILE *)0)
  613. X    FAIL ("open", "fopen", AF_ESYSERR, (FILE *)0);
  614. X
  615. X  (void) af_unlink (tmpname); /* this causes the tmp file to be removed on closing */
  616. X  af_unregtmpfile (tmpname);
  617. X
  618. X  VATTR(key).af_atime = (time_t)af_acttime ();
  619. X/* possibly the date of last access is *not* set properly */
  620. X/* instead of */
  621. X  (void) af_updtvers (key, 0);
  622. X/* this should be */
  623. X/* if (af_updtvers (key, 0) == ERROR) */
  624. X/*    return ((FILE *)0); */
  625. X
  626. X  return (file);
  627. X}
  628. X
  629. X
  630. X/*================================================================
  631. X *    af_close
  632. X *
  633. X *================================================================*/
  634. X
  635. XEXPORT af_close (file)
  636. X     FILE *file;
  637. X{
  638. X  return (fclose (file));
  639. X}
  640. X
  641. X/*================================================================
  642. X *    af_link
  643. X *
  644. X *================================================================*/
  645. X
  646. XEXPORT af_link (oldkey, newkey)
  647. X     /*ARGSUSED*/
  648. X     Af_key *oldkey, *newkey;
  649. X{
  650. X  /* not yet implemented (af_link) */
  651. X}
  652. X
  653. X/*================================================================
  654. X *    af_rm
  655. X *
  656. X *================================================================*/
  657. X
  658. XEXPORT af_rm (key)
  659. X     Af_key *key;
  660. X{
  661. X  Af_user *locker;
  662. X  if (af_keytest (key))
  663. X    SFAIL ("rm", "", AF_EINVKEY, ERROR);
  664. X
  665. X  /* if object is a derived object or not locked */
  666. X  locker = af_testlock (key, AF_VERSIONLOCK);
  667. X  if (!((VATTR(key).af_class & AF_DERIVED) || (locker->af_username[0]=='\0')))
  668. X    {
  669. X      if (af_checkperm (key, AF_LOCKHOLDER) == ERROR)
  670. X    SFAIL ("rm", "", AF_ENOTLOCKED, ERROR);
  671. X    }
  672. X
  673. X  if (af_delvers (key) == ERROR)
  674. X    return (ERROR);
  675. X
  676. X  if (VATTR(key).af_nlinks > 1)
  677. X    af_wng ("af_rm", "deleted object has more than one reference");
  678. X
  679. X  /* decrease reference count for corresponding archive */
  680. X  if ((key->af_ldes->af_refcount -= VATTR(key).af_nlinks) <= 0)
  681. X    {
  682. X      VATTR(key).af_class &= ~AF_VALID;
  683. X      VATTR(key).af_nlinks = 0;
  684. X      (void) af_detlist (key->af_ldes);
  685. X    }
  686. X  else
  687. X    {
  688. X      VATTR(key).af_class &= ~AF_VALID;
  689. X      VATTR(key).af_nlinks = 0;
  690. X    }
  691. X  
  692. X  return (AF_OK);
  693. X}
  694. X
  695. X/*================================================================
  696. X *    af_restore
  697. X *
  698. X *================================================================*/
  699. X
  700. XEXPORT af_restore (key, restkey)
  701. X     Af_key *key, *restkey;
  702. X{
  703. X  char *busyname;
  704. X  bool loaded = FALSE;
  705. X  int  af_fhash ();
  706. X  Af_revlist *list;
  707. X
  708. X  if (af_keytest (key))
  709. X    SFAIL ("restore", "", AF_EINVKEY, ERROR);
  710. X
  711. X  if (!(VATTR(key).af_class & AF_DERIVED))
  712. X    SFAIL ("restore", "", AF_ENOTDERIVED, ERROR);
  713. X
  714. X  /* see if file is readable */
  715. X  if (af_checkread (key) == ERROR)
  716. X    SFAIL ("restore", "", AF_EACCES, ERROR);
  717. X
  718. X  busyname = af_gbusname (CATTR(key).af_syspath,
  719. X               VATTR(key).af_name, VATTR(key).af_type);
  720. X  if (af_bldfile (key, busyname) == ERROR)
  721. X    return (ERROR);
  722. X
  723. X  /* build key for restored file */
  724. X  if ((list = af_readattrs (CATTR(key).af_syspath, VATTR(key).af_name,
  725. X                VATTR(key).af_type, &loaded)) == (Af_revlist *)0)
  726. X    FAIL ("restore", "cannot access restored file", AF_EINTERNAL, ERROR);
  727. X  if (af_buildkey (list, AF_BUSYVERS, AF_BUSYVERS, restkey) == ERROR)
  728. X    FAIL ("restore", "cannot access restored file", AF_EINTERNAL, ERROR);
  729. X  restkey->af_ldes->af_refcount++;
  730. X  VATTR(restkey).af_nlinks++;
  731. X
  732. X  /* if key is in use, an error message should be generated */
  733. X
  734. X  /* restore user defined attributes from binary pool */
  735. X  af_hashfree (&(VATTR(restkey).af_uhtab));
  736. X  (void) af_hashinit (&(VATTR(restkey).af_uhtab), AF_MAXUDAS, af_fhash);
  737. X  VATTR(restkey).af_udanum = VATTR(key).af_udanum;
  738. X  (void) af_hashcopy (&(VATTR(key).af_uhtab), &(VATTR(restkey).af_uhtab));
  739. X
  740. X  VATTR(key).af_atime = (time_t)af_acttime ();
  741. X  /* possibly the date of last access is *not* set properly */
  742. X  /* instead of */
  743. X  (void) af_updtvers (key, 0);
  744. X  (void) af_updtvers (restkey, 0);
  745. X  /* this should be */
  746. X  /* if (af_updtvers (key, 0) == ERROR) */
  747. X  /*    return ((FILE *)0); */
  748. X  
  749. X  return (AF_OK);
  750. X}
  751. X
  752. X
  753. END_OF_FILE
  754. if test 10601 -ne `wc -c <'src/afs/affiles.c'`; then
  755.     echo shar: \"'src/afs/affiles.c'\" unpacked with wrong size!
  756. fi
  757. # end of 'src/afs/affiles.c'
  758. fi
  759. if test -f 'src/shape/selrule.c' -a "${1}" != "-c" ; then 
  760.   echo shar: Will not clobber existing file \"'src/shape/selrule.c'\"
  761. else
  762. echo shar: Extracting \"'src/shape/selrule.c'\" \(11309 characters\)
  763. sed "s/^X//" >'src/shape/selrule.c' <<'END_OF_FILE'
  764. X/*
  765. X * Copyright (C) 1989, 1990 W. Koch, A. Lampen, A. Mahler, W. Obst,
  766. X *  and U. Pralle
  767. X * 
  768. X * This software is published on an as-is basis. There is ABSOLUTELY NO
  769. X * WARRANTY for any part of this software to work correctly or as described
  770. X * in the manuals. We do not accept any liability for any kind of damage
  771. X * caused by use of this software, such as loss of data, time, money, or 
  772. X * effort.
  773. X * 
  774. X * Permission is granted to use, copy, modify, or distribute any part of
  775. X * this software as long as this is done without asking for charge, and
  776. X * provided that this copyright notice is retained as part of the source
  777. X * files. You may charge a distribution fee for the physical act of
  778. X * transferring a copy, and you may at your option offer warranty
  779. X * protection in exchange for a fee.
  780. X * 
  781. X * Direct questions to: Tech. Univ. Berlin
  782. X *              Wilfried Koch
  783. X *              Sekr. FR 5-6 
  784. X *              Franklinstr. 28/29
  785. X *              D-1000 Berlin 10, West Germany
  786. X * 
  787. X *              Tel: +49-30-314-22972
  788. X *              E-mail: shape@coma.uucp or shape@db0tui62.bitnet
  789. X */
  790. X#ifndef lint
  791. Xstatic char *RCSid = "$Header: selrule.c,v 3.1 89/02/20 18:55:14 wolfgang Exp $";
  792. X#endif
  793. X#ifndef lint
  794. Xstatic char *ConfFlg = CFFLGS;    /* should be defined from within Makefile */
  795. X#endif
  796. X/*
  797. X * $Log:    selrule.c,v $
  798. X * Revision 3.1  89/02/20  18:55:14  wolfgang
  799. X * inititialisation of ->cont added.
  800. X * 
  801. X * Revision 3.0  89/01/24  11:36:48  wolfgang
  802. X * New System Generation
  803. X * 
  804. X * Revision 2.12  89/01/18  13:42:05  wolfgang
  805. X * init_selruletab() added.
  806. X * 
  807. X * Revision 2.11  89/01/03  13:13:27  wolfgang
  808. X * changes done for lint
  809. X * 
  810. X * Revision 2.10  88/12/21  15:12:40  wolfgang
  811. X * changes done for lint
  812. X * 
  813. X * Revision 2.9  88/11/21  15:48:33  wolfgang
  814. X * return code of all malloc's checked
  815. X * 
  816. X * Revision 2.8  88/11/02  13:30:40  wolfgang
  817. X * This version is part of a release
  818. X * 
  819. X * Revision 2.7  88/10/18  17:43:20  wolfgang
  820. X * new variant handling
  821. X * 
  822. X * Revision 2.6  88/10/10  17:03:06  wolfgang
  823. X * This version is part of a release
  824. X * 
  825. X * Revision 2.5  88/09/16  19:58:35  wolfgang
  826. X * bug fixed.
  827. X * 
  828. X * Revision 2.4  88/09/16  19:39:24  wolfgang
  829. X * syntactic analysis of rule section improved.
  830. X * 
  831. X * Revision 2.3  88/09/16  11:04:44  wolfgang
  832. X * bug fixed.
  833. X * 
  834. X * Revision 2.2  88/08/23  14:40:15  wolfgang
  835. X * Minor bug fixed. Still the syntactical analysis is a hack.
  836. X * 
  837. X * Revision 2.1  88/08/19  10:18:00  wolfgang
  838. X * This version is part of a release
  839. X * 
  840. X */
  841. X
  842. X#include "shape.h"
  843. X#include "selrule.h"
  844. X
  845. X  char *stdattr[]  = { "attr",
  846. X               "attrnot",
  847. X               "attrlt",
  848. X               "attrgt",
  849. X               "attrle",
  850. X               "attrge",
  851. X               "attrmin",
  852. X               "attrmax",
  853. X               "getfromcid",
  854. X               "attrvar",
  855. X               "msg",
  856. X               "0"
  857. X               };
  858. X
  859. X
  860. X
  861. Xextern int hashval();
  862. Xextern int errexit();
  863. Xextern struct selection_rules *currule;
  864. X
  865. Xstruct selection_rules *sels[SELTABSIZE];
  866. X
  867. Xint selruledef(string)
  868. X     char *string;
  869. X{
  870. X  char rulename[MAXNAMELENGTH];
  871. X  char pred[MAXPREDLENGTH];
  872. X  char name[MAXNAMELENGTH];
  873. X  char value[MAXVALLENGTH];
  874. X  struct selection_rules *cursec;
  875. X  struct list *curlist;
  876. X  char *predptr;
  877. X  int what = 0;
  878. X  int hashr;
  879. X  int i = 0;
  880. X  int j = 0;
  881. X  int l = 0;
  882. X  int k = 0;
  883. X  int kla = 0;
  884. X  while (string[i] != '\n')
  885. X    i++;
  886. X  i++;
  887. X  
  888. X  while((string[i] != '#') && (string[i+1] != '%'))
  889. X    {
  890. X      l = 0;
  891. X      while((string[i] == '\t') || (string[i] == ' ') || (string[i] == '\n'))
  892. X    i++;
  893. X
  894. X      if ((string[i] == '#') && (string[i+1] == '%'))
  895. X    errexit(31,NIL);
  896. X
  897. X      /* rule name */
  898. X      j = 0;
  899. X      while ((string[i] != ' ') && (string[i] != '\t') && (string[i] != ':'))
  900. X    {
  901. X      if (string[i] == '\n')
  902. X        errexit(31,NIL);
  903. X      if ((string[i] == '#') && (string[i+1] == '%'))
  904. X        errexit(31,NIL);
  905. X      rulename[j] = string[i];
  906. X      j++;
  907. X      i++;
  908. X    }
  909. X      rulename[j] = '\0';
  910. X#ifdef DEBUG_SELRULE
  911. Xprintf("selrulename:###%s###\n", rulename);
  912. X#endif DEBUG_SELRULE
  913. X      hashr = hashval(rulename);
  914. X      if (sels[hashr] == (struct selection_rules*) NIL)
  915. X    {
  916. X      if((cursec = sels[hashr] = (struct selection_rules *) malloc( sizeof( struct selection_rules))) == (struct selection_rules *) NIL)
  917. X        errexit(10,"malloc");
  918. X    }
  919. X      else
  920. X    {
  921. X      cursec = sels[hashr];
  922. X      while((strcmp(cursec->name, rulename) != 0) && (cursec->next != (struct selection_rules *) NIL))
  923. X        cursec = cursec->next;
  924. X      if( strcmp(cursec->name, rulename) == 0)
  925. X        errexit(5, rulename);
  926. X      else
  927. X        {
  928. X          if((cursec = cursec->next = (struct selection_rules *) malloc ( sizeof( struct selection_rules))) == (struct selection_rules *) NIL)
  929. X        errexit(10,"malloc");
  930. X        }
  931. X    }
  932. X      if ((cursec->name = malloc((unsigned) (strlen(rulename) + 1 ))) == NIL)
  933. X    errexit(10,"malloc");
  934. X      (void) strcpy(cursec->name, rulename);
  935. X
  936. X      while((string[i] == ' ') || (string[i] == '\t') || (string[i] == '\n') || (string[i] == ':'))
  937. X    i++;
  938. X
  939. X      if((string[i] == '#') && (string[i+1] == '%'))
  940. X    errexit(31,NIL);
  941. X
  942. X      while((string[i] != '.'))
  943. X    {
  944. X      if ((string[i] == '#') && (string[i+1] == '%'))
  945. X        errexit(31,NIL);
  946. X
  947. X      if (string[i] == ';')
  948. X        {
  949. X          if((string[i] == '#') && (string[i+1] == '%'))
  950. X        errexit(31,NIL);
  951. X          k++;
  952. X          i++;
  953. X          if((string[i] == '#') && (string[i+1] == '%'))
  954. X        errexit(31,NIL);
  955. X          l = 0;
  956. X        }
  957. X      while((string[i] == '\n') || (string[i] == ' ') || (string[i] == '\t'))
  958. X        i++;
  959. X
  960. X      if ((string[i] == '#') && (string[i+1] == '%'))
  961. X        errexit(31,NIL);
  962. X
  963. X      while((string[i] != ';') || (kla != 0))
  964. X        {
  965. X          if ((string[i] == '#') && (string[i+1] == '%'))
  966. X        errexit(31,NIL);
  967. X          if (string[i] == '.')
  968. X        break;
  969. X          j = 0;
  970. X          while((string[i] != ',') && (string[i] != ';') && (string[i] != '('))
  971. X        {
  972. X          if ((string[i] == '#') && (string[i+1] == '%'))
  973. X            errexit(31,NIL);
  974. X          if ((string[i] != ' ') && (string[i] != '\t') &&
  975. X              (string[i] != '\n'))
  976. X            {
  977. X              pred[j] = string[i];
  978. X              j++;
  979. X            }
  980. X          if (((string[i] == '-') && (string[i+1] == ')')) ||
  981. X              ((string[i] == '-') && (string[i+1] == '(')))
  982. X            {
  983. X              pred[j] = string[i+1];
  984. X              j++;
  985. X              i++;
  986. X            }
  987. X          if ((string[i] == '#') && (string[i+1] == '%'))
  988. X            errexit(31,NIL);
  989. X          i++;
  990. X          if ((string[i] == '#') && (string[i+1] == '%'))
  991. X            errexit(31,NIL);
  992. X        }
  993. X          pred[j]='\0';
  994. X#ifdef DEBUG_SELRULE
  995. Xprintf("predicate found:###%s###\n", pred);
  996. X#endif DEBUG_SELRULE
  997. X
  998. X          while(string[i] == '(')
  999. X        i++;
  1000. X
  1001. X          if ((string[i] == '#') && (string[i+1] == '%'))
  1002. X        errexit(31,NIL);
  1003. X
  1004. X          j  = 0;
  1005. X
  1006. X          while((string[i] != ',') && (string[i] != ')') && (l != 0))
  1007. X        {
  1008. X          if ((string[i] == '#') && (string[i+1] == '%'))
  1009. X            errexit(31,NIL);
  1010. X/*          if ((string[i] != ' ') && (string[i] != '\t')) 
  1011. X            { */
  1012. X              name[j] = string[i];
  1013. X              j++;
  1014. X/*            } */
  1015. X          i++;
  1016. X
  1017. X          if ((string[i] == '#') && (string[i+1] == '%'))
  1018. X            errexit(31,NIL);
  1019. X
  1020. X        }
  1021. X          name[j] = '\0';
  1022. X      
  1023. X          if (string[i] == ',')
  1024. X        i++;
  1025. X
  1026. X          if ((string[i] == '#') && (string[i+1] == '%'))
  1027. X        errexit(31,NIL);
  1028. X          
  1029. X          while((string[i] == '\t') || (string[i] == ' '))
  1030. X        i++;
  1031. X
  1032. X          if ((string[i] == '#') && (string[i+1] == '%'))
  1033. X        errexit(31,NIL);
  1034. X
  1035. X          j = 0;
  1036. X          while((string[i] != ')') && ( l != 0))
  1037. X        {
  1038. X          if((string[i] == '#') && (string[i+1] == '%'))
  1039. X            errexit(31,NIL);
  1040. X/*          if((string[i] != ' ') && (string[i] != '\t'))
  1041. X            { */
  1042. X              value[j] = string[i];
  1043. X              j++;
  1044. X/*            } */
  1045. X          i++;
  1046. X        }
  1047. X          value[j] = '\0';
  1048. X
  1049. X          while((string[i] == ')') || (string[i] == ','))
  1050. X        i++;
  1051. X
  1052. X
  1053. X          while((string[i] == ' ') || (string[i] == '\t'))
  1054. X        i++;
  1055. X
  1056. X          if ((string[i] == '#') && (string[i+1] == '%'))
  1057. X        errexit(31,NIL);
  1058. X        
  1059. X#ifdef DEBUG_SELRULE
  1060. Xif (l != 0)
  1061. X  printf("name: ###%s###\nvalue: ###%s###\n", name, value);
  1062. X#endif DEBUG_SELRULE
  1063. X
  1064. X          if (l == 0)
  1065. X        {
  1066. X          if((curlist = cursec->predlist[k] = (struct list *) malloc( sizeof (struct list))) == (struct list *) NIL)
  1067. X            errexit(10,"malloc");
  1068. X          cursec->predlist[k+1] = (struct list *) NIL;
  1069. X          curlist->selfunc = pattern;
  1070. X          curlist->parn = NIL;
  1071. X          curlist->cont = (struct list *) NIL;
  1072. X
  1073. X          predptr = &pred[0];
  1074. X          predptr = predptr + specials(predptr, &what);
  1075. X
  1076. X          if ((curlist->parv = malloc ((unsigned) (strlen(predptr) + sizeof(char)))) == NIL)
  1077. X            errexit(10,"malloc");
  1078. X          (void) strcpy(curlist->parv, predptr);
  1079. X          curlist->i = what;
  1080. X          l++;
  1081. X          what = 0;
  1082. X        }
  1083. X          else
  1084. X        {
  1085. X          j = 0;
  1086. X          while ((strcmp(pred, stdattr[j]) != 0) && (strcmp(stdattr[j],"0")!= 0))
  1087. X            j++;
  1088. X          if (strcmp(pred,stdattr[j]) != 0 )
  1089. X            errexit(6, pred);
  1090. X          else
  1091. X            {
  1092. X              if((curlist = curlist->cont = (struct list *) malloc( sizeof (struct list))) == (struct list *) NIL)
  1093. X            errexit(10,"malloc");
  1094. X              curlist->cont = (struct list *) NIL;
  1095. X              if((curlist->parn = malloc((unsigned) (strlen(name) + 1))) == NIL)
  1096. X            errexit(10,"malloc");
  1097. X              (void) strcpy(curlist->parn, name);
  1098. X              if ((curlist->parv = malloc((unsigned) (strlen(value) + 1))) == NIL)
  1099. X            errexit(10,"malloc");
  1100. X              (void) strcpy(curlist->parv, value);
  1101. X            
  1102. X              switch (j)
  1103. X            {
  1104. X            case 0:
  1105. X              curlist->selfunc = attr;
  1106. X              curlist->i = 1;
  1107. X              break;
  1108. X            case 1:
  1109. X              curlist->selfunc = attrnot;
  1110. X              curlist->i = 2;
  1111. X              break;
  1112. X            case 2:
  1113. X              curlist->selfunc = attrlt;
  1114. X              curlist->i = 2;
  1115. X              break;
  1116. X            case 3:
  1117. X              curlist->selfunc = attrgt;
  1118. X              curlist->i = 2;
  1119. X              break;
  1120. X            case 4:
  1121. X              curlist->selfunc = attrle;
  1122. X              curlist->i = 2;
  1123. X              break;
  1124. X            case 5:
  1125. X              curlist->selfunc = attrge;
  1126. X              curlist->i = 2;
  1127. X              break;
  1128. X            case 6:
  1129. X              curlist->selfunc = attrmin;
  1130. X              curlist->i = 2;
  1131. X              break;
  1132. X            case 7:
  1133. X              curlist->selfunc = attrmax;
  1134. X              curlist->i = 2;
  1135. X              break;
  1136. X            case 8:
  1137. X              curlist->selfunc = getfromcid;
  1138. X              curlist->i = 1;
  1139. X              break;
  1140. X            case 9:
  1141. X              curlist->selfunc = attrvar;
  1142. X              curlist->i = 0;
  1143. X              break;
  1144. X            case 10:
  1145. X              curlist->selfunc = msg;
  1146. X              curlist->i = 0;
  1147. X              break;
  1148. X            }
  1149. X              pred[0] = '\0';
  1150. X              j = 0;
  1151. X            }
  1152. X        }
  1153. X        }
  1154. X    }
  1155. X
  1156. X      while((string[i] == ' ') || (string[i+1] == '\t'))
  1157. X    i++;
  1158. X
  1159. X      if (string[i] == '.')
  1160. X    {
  1161. X      i++;
  1162. X      k = 0;
  1163. X    }
  1164. X      while ((string[i] == ' ') || (string[i] == '\n') || (string[i] == '\t'))
  1165. X    i++;
  1166. X    }
  1167. X}
  1168. X
  1169. X
  1170. X#ifdef DEBUG_SELRULE
  1171. Xint seldump()
  1172. X{
  1173. X  int i = 0;
  1174. X  for (i = 0; i < SELTABSIZE; i++)
  1175. X    {
  1176. X      if (sels[i] != (struct selection_rules *) NIL)
  1177. X    {
  1178. X      printf("i = %d, name = %s\n",i, sels[i]->name);
  1179. X    }
  1180. X    }
  1181. X}
  1182. X#endif
  1183. X
  1184. X
  1185. XBool is_selrule_name(name)
  1186. X     char *name;
  1187. X{
  1188. X  int hash;
  1189. X  struct selection_rules *current;
  1190. X
  1191. X  hash = hashval(name);
  1192. X  
  1193. X  if (sels[hash] == (struct selection_rules *) NIL)
  1194. X    return (FALSE);
  1195. X  else
  1196. X    current = sels[hash];
  1197. X
  1198. X  while (current != (struct selection_rules *) NIL)
  1199. X    {
  1200. X      if ((strcmp(current->name, name)) == 0)
  1201. X    {
  1202. X      currule = current;
  1203. X      return(TRUE);
  1204. X    }
  1205. X      else
  1206. X    current = current->next;
  1207. X    }
  1208. X  
  1209. X  if ( current == (struct selection_rules *) NIL)
  1210. X    return(FALSE);
  1211. X
  1212. X  /*NOTREACHED*/
  1213. X  return(FALSE);
  1214. X}
  1215. X
  1216. X
  1217. Xint specials(ptr, what)
  1218. X     char *ptr;
  1219. X     int *what;
  1220. X{
  1221. X  if(*ptr == '+')
  1222. X    {
  1223. X      *what = SMILEY;
  1224. X      return(1);
  1225. X    }
  1226. X
  1227. X  if(*ptr == '-')
  1228. X    {
  1229. X      *what = GRIMMY;
  1230. X      return(1);
  1231. X    }
  1232. X
  1233. X  if (!strncmp(ptr,":-)",3))
  1234. X    {
  1235. X      *what = SMILEY;
  1236. X      return(3);
  1237. X    }
  1238. X
  1239. X  if (!strncmp(ptr,":-(",3))
  1240. X    {
  1241. X      *what = GRIMMY;
  1242. X      return(3);
  1243. X    }
  1244. X  
  1245. X  what = 0;
  1246. X  return(0);
  1247. X
  1248. X}
  1249. X  
  1250. Xinit_selruletab()
  1251. X{
  1252. X  bzero((char *) sels, SELTABSIZE * sizeof(struct rules *));
  1253. X}
  1254. END_OF_FILE
  1255. if test 11309 -ne `wc -c <'src/shape/selrule.c'`; then
  1256.     echo shar: \"'src/shape/selrule.c'\" unpacked with wrong size!
  1257. fi
  1258. # end of 'src/shape/selrule.c'
  1259. fi
  1260. if test -f 'src/shape/shapeopt.c' -a "${1}" != "-c" ; then 
  1261.   echo shar: Will not clobber existing file \"'src/shape/shapeopt.c'\"
  1262. else
  1263. echo shar: Extracting \"'src/shape/shapeopt.c'\" \(10193 characters\)
  1264. sed "s/^X//" >'src/shape/shapeopt.c' <<'END_OF_FILE'
  1265. X/*
  1266. X * Copyright (C) 1989, 1990 W. Koch, A. Lampen, A. Mahler, W. Obst,
  1267. X *  and U. Pralle
  1268. X * 
  1269. X * This software is published on an as-is basis. There is ABSOLUTELY NO
  1270. X * WARRANTY for any part of this software to work correctly or as described
  1271. X * in the manuals. We do not accept any liability for any kind of damage
  1272. X * caused by use of this software, such as loss of data, time, money, or 
  1273. X * effort.
  1274. X * 
  1275. X * Permission is granted to use, copy, modify, or distribute any part of
  1276. X * this software as long as this is done without asking for charge, and
  1277. X * provided that this copyright notice is retained as part of the source
  1278. X * files. You may charge a distribution fee for the physical act of
  1279. X * transferring a copy, and you may at your option offer warranty
  1280. X * protection in exchange for a fee.
  1281. X * 
  1282. X * Direct questions to: Tech. Univ. Berlin
  1283. X *              Wilfried Koch
  1284. X *              Sekr. FR 5-6 
  1285. X *              Franklinstr. 28/29
  1286. X *              D-1000 Berlin 10, West Germany
  1287. X * 
  1288. X *              Tel: +49-30-314-22972
  1289. X *              E-mail: shape@coma.uucp or shape@db0tui62.bitnet
  1290. X */
  1291. X#ifndef lint
  1292. Xstatic char *RCSid = "$Header: shapeopt.c,v 3.0 89/01/24 11:36:54 wolfgang Stable $";
  1293. X#endif
  1294. X#ifndef lint
  1295. Xstatic char *ConfFlg = CFFLGS;    /* should be defined from within Makefile */
  1296. X#endif
  1297. X/*
  1298. X * $Log:    shapeopt.c,v $
  1299. X * Revision 3.0  89/01/24  11:36:54  wolfgang
  1300. X * New System Generation
  1301. X * 
  1302. X * Revision 2.17  89/01/03  13:13:43  wolfgang
  1303. X * changes done for lint
  1304. X * 
  1305. X * Revision 2.16  88/12/19  13:20:51  wolfgang
  1306. X * h_force_option added.
  1307. X * 
  1308. X * Revision 2.15  88/11/24  12:08:31  wolfgang
  1309. X * Argument for -confid *must* now be a target name.
  1310. X * 
  1311. X * Revision 2.14  88/11/21  15:47:34  wolfgang
  1312. X * return code of all malloc's checked
  1313. X * 
  1314. X * Revision 2.13  88/11/08  19:26:24  wolfgang
  1315. X * -expandall & -expandnothing are not allowed at the same time
  1316. X * 
  1317. X * Revision 2.12  88/11/08  11:03:00  wolfgang
  1318. X * h_expandall_option & h_expandnothing_option added.
  1319. X * 
  1320. X * Revision 2.11  88/10/20  12:03:11  wolfgang
  1321. X * This version is part of a release
  1322. X * 
  1323. X * Revision 2.10  88/10/10  16:55:38  wolfgang
  1324. X * handling of -t option activated
  1325. X * 
  1326. X * Revision 2.9  88/10/03  12:53:54  wolfgang
  1327. X * undone last changes.
  1328. X * 
  1329. X * Revision 2.8  88/10/03  11:37:10  wolfgang
  1330. X * handling of the -R option changed: if an  unknown selection rule is
  1331. X * passed to shape, shape now stops.
  1332. X * 
  1333. X * Revision 2.7  88/09/22  10:03:18  wolfgang
  1334. X * bug fixed: -R option.
  1335. X * 
  1336. X * Revision 2.6  88/09/19  15:07:38  wolfgang
  1337. X * h_r_option changed to h_R_option.
  1338. X * 
  1339. X * Revision 2.5  88/08/23  16:36:57  wolfgang
  1340. X * To rebuild something from a confid the option -rebuild is added.
  1341. X * 
  1342. X * Revision 2.4  88/08/23  10:28:21  wolfgang
  1343. X * Changed the -Z option to -confid.
  1344. X * 
  1345. X * Revision 2.3  88/08/22  17:00:26  wolfgang
  1346. X * Initialization of confid added.
  1347. X * 
  1348. X * Revision 2.2  88/08/12  08:58:25  wolfgang
  1349. X * This version is part of a release
  1350. X * 
  1351. X */
  1352. X
  1353. X#include "shape.h"
  1354. X#include "ParseArgs.h"
  1355. Xchar *version();
  1356. Xchar *af_version();
  1357. Xchar cfname[MAXNAMLEN];
  1358. Xchar *forcelist[10];
  1359. X
  1360. Xextern int init_confid();
  1361. Xextern struct linked_list *shapefiles;
  1362. Xextern char ruleset[];
  1363. Xextern char rbtarg[];
  1364. Xextern int implicit_suffs[];
  1365. X
  1366. Xextern int h_d_option();
  1367. Xextern int h_e_option();
  1368. Xextern int h_f_option();
  1369. Xextern int h_force_option();
  1370. Xextern int h_h_option();
  1371. Xextern int h_i_option();
  1372. Xextern int h_k_option();
  1373. Xextern int h_log_option();
  1374. Xextern int h_m_option();
  1375. Xextern int h_n_option();
  1376. Xextern int h_p_option();
  1377. Xextern int h_q_option();
  1378. Xextern int h_r_option();
  1379. Xextern int h_R_option();
  1380. Xextern int h_s_option();
  1381. Xextern int h_S_option();
  1382. Xextern int h_t_option();
  1383. Xextern int h_v_option();
  1384. Xextern int h_b_option();
  1385. Xextern int h_V_option();
  1386. Xextern int h_confid_option();
  1387. Xextern int h_version_option();
  1388. Xextern int h_rebuild_option();
  1389. Xextern int h_expandall_option();
  1390. Xextern int h_expandnothing_option();
  1391. Xextern FILE *cmfopen();
  1392. X
  1393. XOptDesc odesc[] = {
  1394. X  { "d", OPT_IS_SWITCH,    h_d_option },
  1395. X  { "e", OPT_IS_SWITCH,    h_e_option },
  1396. X  { "f", OPT_HAS_ARG, h_f_option },
  1397. X  { "force", OPT_HAS_ARG, h_force_option },
  1398. X  { "h", OPT_IS_SWITCH,    h_h_option },
  1399. X  { "i", OPT_IS_SWITCH,    h_i_option },
  1400. X  { "k", OPT_IS_SWITCH,    h_k_option },
  1401. X  { "log", OPT_IS_SWITCH, h_log_option },
  1402. X  { "m", OPT_IS_SWITCH,    h_m_option },
  1403. X  { "n", OPT_IS_SWITCH,    h_n_option },
  1404. X  { "p", OPT_IS_SWITCH,    h_p_option },
  1405. X  { "q", OPT_IS_SWITCH,    h_q_option },
  1406. X  { "r", OPT_IS_SWITCH, h_r_option },
  1407. X  { "R", OPT_HAS_ARG, h_R_option },
  1408. X  { "s", OPT_IS_SWITCH,    h_s_option },
  1409. X  { "S", OPT_IS_SWITCH,    h_S_option },
  1410. X  { "t", OPT_IS_SWITCH,    h_t_option }, 
  1411. X  { "v", OPT_HAS_ARG, h_v_option },
  1412. X  { "V", OPT_HAS_ARG, h_V_option },
  1413. X  { "version", OPT_IS_SWITCH, h_version_option },
  1414. X  { "confid", OPT_HAS_ARG, h_confid_option },
  1415. X  { "rebuild", OPT_HAS_ARG, h_rebuild_option },
  1416. X  { "expandall", OPT_IS_SWITCH, h_expandall_option },
  1417. X  { "expandnothing", OPT_IS_SWITCH, h_expandnothing_option },
  1418. X  { "b", OPT_IS_SWITCH, h_b_option },
  1419. X  { (char *) NULL, NULL, NULL }
  1420. X};
  1421. X
  1422. X
  1423. Xint h_d_option(opt, arg)
  1424. X     /*ARGSUSED*/
  1425. X     char *opt;
  1426. X     char *arg;
  1427. X{
  1428. X  debugflg = TRUE;
  1429. X  return(0);
  1430. X}
  1431. X
  1432. Xint h_e_option(opt, arg)
  1433. X     /*ARGSUSED*/
  1434. X     char *opt;
  1435. X     char *arg;
  1436. X{
  1437. X  envflg = TRUE;
  1438. X  return(0);
  1439. X}
  1440. X
  1441. Xint h_f_option(opt, arg)
  1442. X     /*ARGSUSED*/
  1443. X     char *opt;
  1444. X     char *arg;
  1445. X{
  1446. X
  1447. Xstruct linked_list *shfiles;
  1448. Xif (!strcmp(arg,""))
  1449. X  return(1);
  1450. Xfileflg = TRUE;
  1451. Xif (strcmp(arg,"-") == 0)
  1452. X  stdinflg = TRUE;
  1453. Xelse
  1454. X  {
  1455. X    if (shapefiles == (struct linked_list *) NIL)
  1456. X      {
  1457. X    if ((shapefiles = (struct linked_list *) malloc(sizeof(struct linked_list))) == (struct linked_list *) NIL)
  1458. X      errexit(10,"malloc");
  1459. X    if ((shapefiles->string = malloc((unsigned) strlen(arg) + sizeof(char))) == NIL)
  1460. X      errexit(10,"malloc");
  1461. X    (void) strcpy(shapefiles->string,arg);
  1462. X    shapefiles->nextstring = (struct linked_list *) NIL;
  1463. X      }
  1464. X    else
  1465. X      {
  1466. X    shfiles = shapefiles;
  1467. X    while( shfiles->nextstring != (struct linked_list *) NIL)
  1468. X      shfiles = shfiles->nextstring;
  1469. X    
  1470. X    if((shfiles->nextstring  = (struct linked_list *) malloc(sizeof(struct linked_list))) == (struct linked_list *) NIL)
  1471. X      errexit(10,"malloc");
  1472. X    shfiles = shfiles->nextstring;
  1473. X    if ((shfiles->string = malloc((unsigned) strlen(arg) + sizeof(char))) == NIL)
  1474. X      errexit(10,"malloc");
  1475. X    (void) strcpy(shfiles->string, arg);
  1476. X    shfiles->nextstring = (struct linked_list *) NIL;
  1477. X      }
  1478. X  }
  1479. X  return(0);
  1480. X}
  1481. X
  1482. X
  1483. Xint h_force_option(opt,arg)
  1484. X     /*ARGSUSED*/
  1485. X     char *opt;
  1486. X     char *arg;
  1487. X{
  1488. X  int i = 0;
  1489. X  forceflg = TRUE;
  1490. X  while(forcelist[i] != NIL)
  1491. X    {
  1492. X      if (i == 10)
  1493. X    errexit(36, NIL);
  1494. X      i++;
  1495. X    }
  1496. X  if ((forcelist[i] = malloc((unsigned) (strlen(arg) + sizeof(char)))) == NIL)
  1497. X    errexit(10,"malloc");
  1498. X  (void) strcpy(forcelist[i],arg);
  1499. X  return (0);
  1500. X}
  1501. X
  1502. Xint h_h_option(opt, arg)
  1503. X     /*ARGSUSED*/
  1504. X     char *opt;
  1505. X     char *arg;
  1506. X{
  1507. X  return(1);
  1508. X}
  1509. X
  1510. Xint h_i_option(opt, arg)
  1511. X     /*ARGSUSED*/
  1512. X     char *opt;
  1513. X     char *arg;
  1514. X{
  1515. X  ignoreflg = TRUE;
  1516. X  return(0);
  1517. X}
  1518. X
  1519. Xint h_k_option(opt, arg)
  1520. X     /*ARGSUSED*/
  1521. X     char *opt; 
  1522. X     char *arg;
  1523. X{
  1524. X  goflg = TRUE;
  1525. X  return(0);
  1526. X}
  1527. X
  1528. Xint h_log_option(opt, arg)
  1529. X     /*ARGSUSED*/
  1530. X     char *opt;
  1531. X     char *arg;
  1532. X{
  1533. X  logflg = TRUE;
  1534. X  return(0);
  1535. X}
  1536. X
  1537. Xint h_m_option(opt, arg)
  1538. X     /*ARGSUSED*/
  1539. X     char *opt;
  1540. X     char *arg;
  1541. X{
  1542. X  /* weiss ich nich */
  1543. X  return(0);
  1544. X}
  1545. X
  1546. Xint h_n_option(opt, arg)
  1547. X     /*ARGSUSED*/
  1548. X     char *opt;
  1549. X     char *arg;
  1550. X{
  1551. X  noexflg = TRUE;
  1552. X  return(0);
  1553. X}
  1554. X
  1555. Xint h_p_option(opt, arg)
  1556. X     /*ARGSUSED*/
  1557. X     char *opt;
  1558. X     char *arg;
  1559. X{
  1560. X  printflg = TRUE;
  1561. X  return(0);
  1562. X}
  1563. X
  1564. Xint h_q_option(opt, arg)
  1565. X     /*ARGSUSED*/
  1566. X     char *opt;
  1567. X     char *arg;
  1568. X{
  1569. X  questflg = TRUE;
  1570. X  return(0);
  1571. X}
  1572. X
  1573. Xint h_r_option(opt,arg)
  1574. X     /*ARGSUSED*/
  1575. X     char *opt;
  1576. X     char *arg;
  1577. X{
  1578. X  implicit_suffs[0] = -1;
  1579. X  return(0);
  1580. X}
  1581. X
  1582. X
  1583. Xint h_R_option(opt, arg)
  1584. X     /*ARGSUSED*/
  1585. X     char *opt;
  1586. X     char *arg;
  1587. X{
  1588. X  ruleflg = TRUE;
  1589. X  (void) strcpy(ruleset,arg);
  1590. X  return(0);
  1591. X}
  1592. X
  1593. Xint h_s_option(opt, arg)
  1594. X     /*ARGSUSED*/
  1595. X     char *opt;
  1596. X     char *arg;
  1597. X{
  1598. X  silentflg = TRUE;
  1599. X  return(0);
  1600. X}
  1601. X
  1602. Xint h_S_option(opt, arg)
  1603. X     /*ARGSUSED*/
  1604. X     char *opt;
  1605. X     char *arg;
  1606. X{
  1607. X  goflg = FALSE;
  1608. X  return(0);
  1609. X}
  1610. X
  1611. Xint h_t_option(opt, arg)
  1612. X     /*ARGSUSED*/
  1613. X     char *opt;
  1614. X     char *arg;
  1615. X{
  1616. X  touchflg = TRUE;
  1617. X  return(0);
  1618. X}
  1619. X
  1620. Xint h_v_option(opt, arg)
  1621. X     /*ARGSUSED*/
  1622. X     char *opt;
  1623. X     char *arg;
  1624. X{
  1625. X/*  variant = arg  ???? */;
  1626. X  return(0);
  1627. X}
  1628. X
  1629. Xint h_version_option(opt, arg)
  1630. X     /*ARGSUSED*/
  1631. X     char *opt;
  1632. X     char *arg;
  1633. X{
  1634. X  printf("shape - Version %s\n", version());
  1635. X  printf("uses AFS: Version %s\n", af_version());
  1636. X  exit(0);
  1637. X}
  1638. X
  1639. Xint h_expandall_option(opt, arg)
  1640. X     /*ARGSUSED*/
  1641. X     char *opt;
  1642. X     char *arg;
  1643. X{
  1644. X  if (noexpflg)
  1645. X    errexit(34,NIL);
  1646. X  expflg = TRUE;
  1647. X  return(0);
  1648. X}
  1649. X
  1650. Xint h_expandnothing_option(opt, arg)
  1651. X     /*ARGSUSED*/
  1652. X     char *opt;
  1653. X     char *arg;
  1654. X{
  1655. X  if(expflg)
  1656. X    errexit(34,NIL);
  1657. X  noexpflg = TRUE;
  1658. X  return(0);
  1659. X}
  1660. X
  1661. X
  1662. Xint h_b_option(opt, arg)
  1663. X     /*ARGSUSED*/
  1664. X     char *opt;
  1665. X     char *arg;
  1666. X{
  1667. X; /* because of compatibility; does nothing (i hope so ...) */
  1668. X  return(0);
  1669. X}
  1670. X
  1671. Xint h_V_option(opt, arg)
  1672. X     /*ARGSUSED*/
  1673. X     char *opt;
  1674. X     char *arg;
  1675. X{
  1676. X  /* set generation and revision (for shapefile) */
  1677. X
  1678. X
  1679. X/*      case 'V':
  1680. X    if ((ccc = index(optarg,'.')) == 0)
  1681. X      errexit(9, optarg);
  1682. X    else
  1683. X      {
  1684. X        ccc[0] = '\0';
  1685. X        gen = atoi(optarg);
  1686. X        *ccc++;
  1687. X        rev = atoi(ccc);
  1688. X      }
  1689. X    break;
  1690. X      default:
  1691. X    h[0] = c;
  1692. X    h[1] = '\0';
  1693. X    errexit( 2, h);  */
  1694. X  return(0);
  1695. X
  1696. X}
  1697. X
  1698. Xint h_confid_option(opt, arg)
  1699. X     /*ARGSUSED*/
  1700. X     char *opt;
  1701. X     char *arg;
  1702. X{
  1703. X  if (!strcmp(arg,""))
  1704. X    return(1);
  1705. X
  1706. X  confid = TRUE;
  1707. X  (void) strcpy(cfname,arg);
  1708. X  (void) strcat(cfname,".cid");
  1709. X  if ((cid = cmfopen(cfname,"w",AF_BUSYVERS, AF_BUSYVERS)) == (FILE *) NIL)
  1710. X    errexit(12, cfname);
  1711. X  init_confid(arg);
  1712. X  (void) strcpy(cfname,arg);
  1713. X  return(0);
  1714. X}
  1715. X
  1716. Xint h_rebuild_option(opt, arg)
  1717. X     /*ARGSUSED*/
  1718. X     char *opt;
  1719. X     char *arg;
  1720. X{
  1721. Xchar *p;
  1722. Xchar fname[MAXNAMLEN];
  1723. X(void) strcpy(fname,arg);
  1724. X
  1725. Xif((p = rindex(fname,'.')) == NIL)
  1726. X  {
  1727. X    (void) strcpy(rbrule,"@");
  1728. X    (void) strcat(rbrule,fname);
  1729. X    (void) strcpy(rbtarg,fname);
  1730. X    (void) strcat(fname,".cid");
  1731. X    (void) strcpy(rbfile,fname);
  1732. X  }
  1733. Xelse
  1734. X  {
  1735. X    (void) strcpy(rbfile,fname);
  1736. X    *p = '\0';
  1737. X    (void) strcpy(rbtarg,fname);
  1738. X    (void) strcpy(rbrule,"@");
  1739. X    (void) strcat(rbrule,fname);
  1740. X  }
  1741. X
  1742. Xrebuildflg = TRUE;
  1743. X
  1744. Xreturn(0);
  1745. X
  1746. X}
  1747. END_OF_FILE
  1748. if test 10193 -ne `wc -c <'src/shape/shapeopt.c'`; then
  1749.     echo shar: \"'src/shape/shapeopt.c'\" unpacked with wrong size!
  1750. fi
  1751. # end of 'src/shape/shapeopt.c'
  1752. fi
  1753. echo shar: End of archive 13 \(of 33\).
  1754. cp /dev/null ark13isdone
  1755. MISSING=""
  1756. 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
  1757.     if test ! -f ark${I}isdone ; then
  1758.     MISSING="${MISSING} ${I}"
  1759.     fi
  1760. done
  1761. if test "${MISSING}" = "" ; then
  1762.     echo You have unpacked all 33 archives.
  1763.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1764. else
  1765.     echo You still need to unpack the following archives:
  1766.     echo "        " ${MISSING}
  1767. fi
  1768. ##  End of shell archive.
  1769. exit 0
  1770.