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

  1. Subject:  v19i046:  A software configuration management system, Part33/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 46
  8. Archive-name: shape/part33
  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 33 (of 33)."
  19. # Contents:  src/shape/attr.c
  20. # Wrapped by rsalz@papaya.bbn.com on Thu Jun  1 19:27:22 1989
  21. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  22. if test -f 'src/shape/attr.c' -a "${1}" != "-c" ; then 
  23.   echo shar: Will not clobber existing file \"'src/shape/attr.c'\"
  24. else
  25. echo shar: Extracting \"'src/shape/attr.c'\" \(50463 characters\)
  26. sed "s/^X//" >'src/shape/attr.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: attr.c,v 3.1 89/02/08 12:45:55 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:    attr.c,v $
  61. X * Revision 3.1  89/02/08  12:45:55  wolfgang
  62. X * performance improved.
  63. X * 
  64. X * Revision 3.0  89/01/24  11:34:30  wolfgang
  65. X * New System Generation
  66. X * 
  67. X * Revision 2.15  89/01/03  12:59:57  wolfgang
  68. X * changes done for lint
  69. X * 
  70. X * Revision 2.14  88/12/21  14:57:30  wolfgang
  71. X * changes done for lint
  72. X * 
  73. X * Revision 2.13  88/11/22  17:25:17  wolfgang
  74. X * bug fixed in pattern().
  75. X * 
  76. X * Revision 2.11  88/11/21  15:51:50  wolfgang
  77. X * return code of all malloc's checked
  78. X * 
  79. X * Revision 2.10  88/10/27  16:39:03  wolfgang
  80. X * bug fixed (new variant handling).
  81. X * 
  82. X * Revision 2.9  88/09/20  10:05:30  wolfgang
  83. X * biug fixed. the offset of 'real' vpath's wasn't correct, if 2 attrvars
  84. X * occured.
  85. X * 
  86. X * Revision 2.8  88/09/19  18:10:19  wolfgang
  87. X * concatenation of vflags added (if more than 1 attrvar occurs).
  88. X * 
  89. X * Revision 2.7  88/09/16  13:29:36  wolfgang
  90. X * minor bug fixed in msg()
  91. X * 
  92. X * Revision 2.6  88/09/16  11:04:11  wolfgang
  93. X * bug fixed in msg.
  94. X * 
  95. X * Revision 2.5  88/09/15  18:42:51  wolfgang
  96. X * bugs in attrvar fixed.
  97. X * 
  98. X * Revision 2.4  88/09/15  12:43:12  wolfgang
  99. X * bug fixed in attrvar.
  100. X * 
  101. X * Revision 2.3  88/09/14  14:04:46  wolfgang
  102. X * new global variable introduced. decomposition of vpath added.
  103. X * 
  104. X * Revision 2.2  88/08/22  15:31:40  wolfgang
  105. X * Handling of two types added: syspath & host; are necessary for the
  106. X * production of confid's.
  107. X * 
  108. X * Revision 2.1  88/08/19  10:16:41  wolfgang
  109. X * This version is part of a release
  110. X * 
  111. X */
  112. X
  113. X#include <stdio.h>
  114. X
  115. X#include "shape.h"
  116. X#include "attr.h"
  117. X
  118. Xextern struct vardef *vardefs[];
  119. Xextern char dollarplus[];
  120. X
  121. Xint err;
  122. Xint pathi;
  123. Xextern char *re_comp();
  124. Xextern int re_exec();
  125. Xextern char *replace();
  126. Xextern char *malloc();
  127. Xextern char *strcpy();
  128. X
  129. Xextern int errexit();
  130. Xextern Bool check_vclass();
  131. Xextern int get_attr_type();
  132. Xextern int get_state_no();
  133. X
  134. XBool pattern(string, patt)
  135. X     char *string;
  136. X     char *patt;
  137. X{
  138. Xchar *retcode;
  139. Xchar *pat;
  140. X
  141. Xif (string == NIL)
  142. X  return(FALSE);
  143. X
  144. Xpat = replace(patt);
  145. X
  146. Xif ((retcode = re_comp(pat)) != 0)
  147. X  {
  148. X    (void) strcat(retcode, ": re_comp");
  149. X    errexit(10, "re_comp");
  150. X  }
  151. X
  152. X#ifdef DEBUG_ATTR
  153. Xprintf("pattern: string = #%s#; pattern = #%s# ", string, pat);
  154. X#endif DEBUG_ATTR
  155. X
  156. Xif (re_exec(string) == 1)
  157. X    return (TRUE);
  158. Xelse
  159. X  return(FALSE);
  160. X}
  161. X
  162. XBool msg(name, value, set)
  163. X     char *name;
  164. X     char *value;
  165. X     /*ARGSUSED*/
  166. X     Af_set *set;
  167. X{
  168. X  char *p;
  169. X  char message2[256];
  170. X  char *message;
  171. X  int len;
  172. X  (void) strcpy(message2,name);
  173. X  if (strcmp(value,""))
  174. X    {
  175. X      (void) strcat(message2,", ");
  176. X      (void) strcat(message2,value);
  177. X    }
  178. X  message = &message2[0];
  179. X
  180. X  len = strlen(message) - 1;
  181. X  
  182. X  if (((message[0] == '\'') && (message[len] == '\'')) ||
  183. X      ((message[0] == '\"') && (message[len] == '\"')))
  184. X    {
  185. X      message[len] = '\0';
  186. X      message++;
  187. X    }
  188. X
  189. X  if (((p = index(message,'$')) != NIL) && (*(p+1) == '+'))
  190. X    {
  191. X      *p = '\0';
  192. X      printf("%s%s%s", message, dollarplus, p+2);
  193. X    }
  194. X  else
  195. X    {
  196. X      if (strcmp(message,""))
  197. X    printf("%s", message);
  198. X    }
  199. X  printf("\n");
  200. X
  201. X  (void) strcpy(dollarplus,"");
  202. X
  203. X  return(TRUE);
  204. X}
  205. X
  206. XBool tunix(name, value, set)
  207. X     /*ARGSUSED*/
  208. X     char *name;
  209. X     char *value;
  210. X     Af_set *set;
  211. X{
  212. X  tunixflg = TRUE;
  213. X  return (TRUE);
  214. X}
  215. X
  216. XBool stopit(name, value, set)
  217. X     /*ARGSUSED*/
  218. X     char *name;
  219. X     char *value;
  220. X     Af_set *set;
  221. X{
  222. X  stopflg = TRUE;
  223. X  return(TRUE);
  224. X}
  225. X
  226. XBool attr(name, value, set)
  227. X     char *name;
  228. X     char *value;
  229. X     Af_set *set;
  230. X{
  231. Xint attr_type;
  232. Xint nrofkeys;
  233. Xint cur_pos;
  234. Xint pos1;
  235. Xint i;
  236. X
  237. XAf_key cur_key;
  238. X
  239. XAf_attrs cur_attrbuf;
  240. X
  241. XBool last_match;
  242. XBool found;
  243. XBool attr_found;
  244. X
  245. Xchar val1[256];
  246. Xchar *val2;
  247. Xchar *val3;
  248. X
  249. X#ifdef DEBUG_ATTR
  250. Xprintf("attr(): name = #%s#,  value = #%s#\n", name,value);
  251. X#endif DEBUG_ATTR
  252. X
  253. X
  254. Xattr_type = get_attr_type(name);
  255. X
  256. Xif ((nrofkeys = af_nrofkeys(set)) == -1)
  257. X  errexit(10, "af_nrofkeys");
  258. X
  259. X#ifdef DEBUG_ATTR
  260. Xprintf("nrofkeys = %d\n", nrofkeys);
  261. X#endif DEBUG_ATTR
  262. X
  263. Xswitch (attr_type)
  264. X  {
  265. X  case 0 :
  266. X    if ((af_sortset(set,AF_ATTGEN)) == -1)
  267. X      errexit(10,"af_sortset");
  268. X    break;
  269. X  case 1 :
  270. X    if ((af_sortset(set,AF_ATTREV)) == -1)
  271. X      errexit(10,"af_sortset");
  272. X    break;
  273. X  case 2 :
  274. X    if ((af_sortset(set,AF_ATTSTATE)) == -1)
  275. X      errexit(10,"af_sortset");
  276. X    break;
  277. X  case 3 :
  278. X    if ((af_sortset(set,AF_ATTAUTHOR)) == -1)
  279. X      errexit(10,"af_sortset");
  280. X    break;
  281. X  case 4 :
  282. X    errexit(10,"group id");
  283. X    break;
  284. X  case 5 :
  285. X    if ((af_sortset(set,AF_ATTVERSION)) == -1)
  286. X      errexit(10,"af_sortset");
  287. X    break;
  288. X  case 6 :
  289. X    if ((af_sortset(set,AF_ATTVARIANT)) == -1)
  290. X      errexit(10,"af_sortset");
  291. X    break;
  292. X  case 7:
  293. X    if ((af_sortset(set,AF_ATTSPATH)) == -1)
  294. X      errexit(10,"af_sortset");
  295. X    break;
  296. X  case 8:
  297. X    if ((af_sortset(set,AF_ATTHOST)) == -1)
  298. X      errexit(10,"af_sortset");
  299. X    break;
  300. X  default :
  301. X    if ((af_sortset(set,name)) == -1)
  302. X      errexit(10,"af_sortset");
  303. X  }
  304. X
  305. Xcur_pos = 0;
  306. Xlast_match = FALSE;
  307. Xfound = FALSE;
  308. X
  309. Xwhile ((cur_pos < nrofkeys) && (!(last_match)))
  310. X  {
  311. X    if ((err = af_setgkey(set, cur_pos, &cur_key)) == -1)
  312. X      errexit(10, "af_setgkey");
  313. X    
  314. X    if (af_gattrs(&cur_key, &cur_attrbuf) == -1)
  315. X      errexit(10, "af_gattrs");
  316. X
  317. X    switch (attr_type)
  318. X      {
  319. X      case 0 :
  320. X    if (cur_attrbuf.af_gen != atoi(value))
  321. X      {
  322. X        if (found)
  323. X          last_match = TRUE;
  324. X        else
  325. X          cur_pos++;    /* here probably better : */
  326. X           /* if (cur_attrbuf.af_gen > atoi(value)) */
  327. X           /*   cur_pos = nrofkeys;                  */
  328. X           /* else                                   */
  329. X           /*   cur_pos++;                           */
  330. X      }
  331. X    else
  332. X      {
  333. X        if (!(found))
  334. X          {
  335. X        found = TRUE;
  336. X        pos1 = cur_pos;
  337. X          }
  338. X        cur_pos++;
  339. X      }
  340. X    break;
  341. X      case 1 :
  342. X    if (cur_attrbuf.af_rev != atoi(value))
  343. X      {
  344. X        if (found)
  345. X          last_match = TRUE;
  346. X        else
  347. X          cur_pos++;
  348. X      }
  349. X    else
  350. X      {
  351. X        if (!(found))
  352. X          {
  353. X        found = TRUE;
  354. X        pos1 = cur_pos;
  355. X          }
  356. X        cur_pos++;
  357. X      }
  358. X    break;
  359. X      case 2 :
  360. X    if ((int) cur_attrbuf.af_state != get_state_no(value))
  361. X      {
  362. X        if (found)
  363. X          last_match = TRUE;
  364. X        else
  365. X          cur_pos++;
  366. X      }
  367. X    else
  368. X      {
  369. X        if (!(found))
  370. X          {
  371. X        found = TRUE;
  372. X        pos1 = cur_pos;
  373. X          }
  374. X        cur_pos++;
  375. X      }
  376. X    break;
  377. X      case 3 :
  378. X    if (strcmp(cur_attrbuf.af_author.af_username,value))
  379. X      {
  380. X        if (found)
  381. X          last_match = TRUE;
  382. X        else
  383. X          cur_pos++;
  384. X      }
  385. X    else
  386. X      {
  387. X        if (!(found))
  388. X          {
  389. X        found = TRUE;
  390. X        pos1 = cur_pos;
  391. X          }
  392. X        cur_pos++;
  393. X      }
  394. X    break;
  395. X      case 4 :
  396. X    errexit(10,"group id");
  397. X    break;
  398. X      case 5 :
  399. X    (void) strcpy(val1, value);
  400. X    if ((val2 = index(val1,'.')) == 0)
  401. X      errexit(9, value);
  402. X    val2[0] = '\0';
  403. X    val2++;
  404. X    if ((atoi(val1) == cur_attrbuf.af_gen)
  405. X        && (atoi(val2) == cur_attrbuf.af_rev))
  406. X      {
  407. X        if (!(found))
  408. X          {
  409. X        found = TRUE;
  410. X        pos1 = cur_pos;
  411. X          }
  412. X        cur_pos++;
  413. X      }
  414. X    else
  415. X      {
  416. X        if (found)
  417. X          last_match = TRUE;
  418. X        else
  419. X          cur_pos++;
  420. X      }
  421. X    break;
  422. X      case 6:
  423. X    /* Variants */
  424. X    if ((strcmp(cur_attrbuf.af_variant,value)) != 0)
  425. X      {
  426. X        if (found)
  427. X          last_match = TRUE;
  428. X        else
  429. X          cur_pos++;
  430. X      }
  431. X    else
  432. X      {
  433. X        if (!(found))
  434. X          {
  435. X        found = TRUE;
  436. X        pos1 = cur_pos;
  437. X          }
  438. X        cur_pos++;
  439. X      }
  440. X    break;
  441. X      case 7 :
  442. X    if (strcmp(cur_attrbuf.af_syspath,value))
  443. X      {
  444. X        if (found)
  445. X          last_match = TRUE;
  446. X        else
  447. X          cur_pos++;
  448. X      }
  449. X    else
  450. X      {
  451. X        if (!(found))
  452. X          {
  453. X        found = TRUE;
  454. X        pos1 = cur_pos;
  455. X          }
  456. X        cur_pos++;
  457. X      }
  458. X    break;
  459. X      case 8 :
  460. X    if (strcmp(cur_attrbuf.af_host,value))
  461. X      {
  462. X        if (found)
  463. X          last_match = TRUE;
  464. X        else
  465. X          cur_pos++;
  466. X      }
  467. X    else
  468. X      {
  469. X        if (!(found))
  470. X          {
  471. X        found = TRUE;
  472. X        pos1 = cur_pos;
  473. X          }
  474. X        cur_pos++;
  475. X      }
  476. X    break;
  477. X      default :
  478. X/* af_udattrs must contain a '=', even if they don't contain a value */
  479. X/* currently only the first value (if existing) in the string is     */
  480. X/* considered */
  481. X    i = 0;
  482. X    attr_found = FALSE;
  483. X/* find name in list of udattrs */
  484. X    while ((!(attr_found)) && (i < AF_MAXUDAS) &&
  485. X           (cur_attrbuf.af_udattrs[i] != NIL))
  486. X      {
  487. X        (void) strcpy(val1, cur_attrbuf.af_udattrs[i]);
  488. X        if ((val2 = index(val1, '=')) == 0)
  489. X          errexit(10, "attr");
  490. X        val2[0] = '\0';
  491. X        if (strcmp(name, val1) != 0)
  492. X          i++;
  493. X        else
  494. X          attr_found = TRUE;
  495. X      }
  496. X/* name should be found now */
  497. X    if (!(attr_found))
  498. X      errexit(10, "attr");
  499. X
  500. X/* value comparison */
  501. X    val2++;
  502. X    if (*val2 == '\0')        /* no value given is considered as != */
  503. X      {
  504. X        if (found)
  505. X          last_match = TRUE;
  506. X        else
  507. X          cur_pos++;
  508. X      }
  509. X    else
  510. X      {
  511. X        if ((val3 = index(val2, AF_UDAVALDEL)) != 0) 
  512. X          val3[0] = '\0';     /* only first value in attrbuf is     */
  513. X                                  /* considered; parameter value should */
  514. X                                  /* contain only one value             */
  515. X        if (strcmp(value, val2) == 0)
  516. X          {
  517. X        if (!(found))
  518. X          {
  519. X            found = TRUE;
  520. X            pos1 = cur_pos;
  521. X          }
  522. X        cur_pos++;
  523. X          }
  524. X        else
  525. X          {
  526. X        if (found)
  527. X          last_match = TRUE;
  528. X        else
  529. X          cur_pos++;
  530. X          }
  531. X      }
  532. X      }
  533. X  }
  534. X
  535. Xif (!(found))
  536. X  cur_pos = 0;
  537. Xelse
  538. X  {
  539. X    i = pos1;
  540. X    while (i > 0)
  541. X      {
  542. X    if (af_setposrmkey(set, 0) == -1)
  543. X      errexit(10, "af_setposrmkey");
  544. X    i--;
  545. X    cur_pos--;
  546. X    nrofkeys--;
  547. X      }
  548. X  }
  549. X
  550. Xwhile (cur_pos < nrofkeys)
  551. X  {
  552. X    if (af_setposrmkey(set, cur_pos) == -1)
  553. X      errexit(10, "af_setposrmkey");
  554. X    nrofkeys--;
  555. X  }
  556. Xif (nrofkeys == 0)
  557. X  {
  558. X#ifdef DEBUG_ATTR
  559. X    printf("no matches\n");
  560. X#endif DEBUG_ATTR
  561. X    return (FALSE);
  562. X  }
  563. Xelse
  564. X  {
  565. X#ifdef DEBUG_ATTR
  566. X    printf("matches:\n");
  567. X    nrofkeys = af_nrofkeys(set);
  568. X    i = 0;
  569. X    while (i < nrofkeys)
  570. X      {
  571. X    af_setgkey(set, i, &cur_key);
  572. X    af_gattrs(&cur_key, &cur_attrbuf);
  573. X    printf("version %d.%d\n", cur_attrbuf.af_gen, cur_attrbuf.af_rev);
  574. X    i++;
  575. X      }
  576. X#endif DEBUG_ATTR
  577. X    return (TRUE);
  578. X  }
  579. X}
  580. X
  581. XBool attrnot(name, value, set)
  582. X     char *name;
  583. X     char *value;
  584. X     Af_set *set;
  585. X{
  586. Xint attr_type;
  587. Xint nrofkeys;
  588. Xint cur_pos;
  589. Xint pos1;
  590. Xint i;
  591. X
  592. XAf_key cur_key;
  593. X
  594. XAf_attrs cur_attrbuf;
  595. X
  596. XBool last_match;
  597. XBool found;
  598. XBool attr_found;
  599. X
  600. Xchar val1[256];
  601. Xchar *val2;
  602. Xchar *val3;
  603. X
  604. X#ifdef DEBUG_ATTR
  605. Xprintf("attrnot(): name = #%s#,  value = #%s#\n", name,value);
  606. X#endif DEBUG_ATTR
  607. X
  608. X
  609. Xattr_type = get_attr_type(name);
  610. X
  611. Xif ((nrofkeys = af_nrofkeys(set)) == -1)
  612. X  errexit(10, "af_nrofkeys");
  613. X
  614. X#ifdef DEBUG_ATTR
  615. Xprintf("nrofkeys = %d\n", nrofkeys);
  616. X#endif DEBUG_ATTR
  617. X
  618. Xswitch (attr_type)
  619. X  {
  620. X  case 0 :
  621. X    if ((af_sortset(set,AF_ATTGEN)) == -1)
  622. X      errexit(10,"af_sortset");
  623. X    break;
  624. X  case 1 :
  625. X    if ((af_sortset(set,AF_ATTREV)) == -1)
  626. X      errexit(10,"af_sortset");
  627. X    break;
  628. X  case 2 :
  629. X    if ((af_sortset(set,AF_ATTSTATE)) == -1)
  630. X      errexit(10,"af_sortset");
  631. X    break;
  632. X  case 3 :
  633. X    if ((af_sortset(set,AF_ATTAUTHOR)) == -1)
  634. X      errexit(10,"af_sortset");
  635. X    break;
  636. X  case 4 :
  637. X    errexit(10,"group id");
  638. X    break;
  639. X  case 5 :
  640. X    if ((af_sortset(set,AF_ATTVERSION)) == -1)
  641. X      errexit(10,"af_sortset");
  642. X    break;
  643. X  case 6 :
  644. X    if ((af_sortset(set,AF_ATTVARIANT)) == -1)
  645. X      errexit(10,"af_sortset");
  646. X    break;
  647. X  case 7:
  648. X    if ((af_sortset(set,AF_ATTSPATH)) == -1)
  649. X      errexit(10,"af_sortset");
  650. X    break;
  651. X  case 8:
  652. X    if ((af_sortset(set,AF_ATTHOST)) == -1)
  653. X      errexit(10,"af_sortset");
  654. X    break;
  655. X  default :
  656. X    if ((af_sortset(set,name)) == -1)
  657. X      errexit(10,"af_sortset");
  658. X  }
  659. X
  660. Xcur_pos = 0;
  661. Xlast_match = FALSE;
  662. Xfound = FALSE;
  663. X
  664. Xwhile ((cur_pos < nrofkeys) && (!(last_match)))
  665. X  {
  666. X    if ((err = af_setgkey(set, cur_pos, &cur_key) == -1))
  667. X      errexit(10, "af_setgkey");
  668. X    
  669. X    if (af_gattrs(&cur_key, &cur_attrbuf) == -1)
  670. X      errexit(10, "af_gattrs");
  671. X
  672. X#ifdef DEBUG_ATTR
  673. X    printf("key[%d] -> version %d.%d\n", cur_pos, cur_attrbuf.af_gen, cur_attrbuf.af_rev);
  674. X#endif DEBUG_ATTR
  675. X
  676. X    switch (attr_type)
  677. X      {
  678. X      case 0 :
  679. X    if (cur_attrbuf.af_gen != atoi(value))
  680. X      {
  681. X        if (found)
  682. X          last_match = TRUE;
  683. X        else
  684. X          cur_pos++;    /* here probably better : */
  685. X           /* if (cur_attrbuf.af_gen > atoi(value)) */
  686. X           /*   cur_pos = nrofkeys;                  */
  687. X           /* else                                   */
  688. X           /*   cur_pos++;                           */
  689. X      }
  690. X    else
  691. X      {
  692. X        if (!(found))
  693. X          {
  694. X        found = TRUE;
  695. X        pos1 = cur_pos;
  696. X          }
  697. X        cur_pos++;
  698. X      }
  699. X    break;
  700. X      case 1 :
  701. X    if (cur_attrbuf.af_rev != atoi(value))
  702. X      {
  703. X        if (found)
  704. X          last_match = TRUE;
  705. X        else
  706. X          cur_pos++;
  707. X      }
  708. X    else
  709. X      {
  710. X        if (!(found))
  711. X          {
  712. X        found = TRUE;
  713. X        pos1 = cur_pos;
  714. X          }
  715. X        cur_pos++;
  716. X      }
  717. X    break;
  718. X      case 2 :
  719. X    if ((int) cur_attrbuf.af_state != atoi(value))
  720. X      {
  721. X        if (found)
  722. X          last_match = TRUE;
  723. X        else
  724. X          cur_pos++;
  725. X      }
  726. X    else
  727. X      {
  728. X        if (!(found))
  729. X          {
  730. X        found = TRUE;
  731. X        pos1 = cur_pos;
  732. X          }
  733. X        cur_pos++;
  734. X      }
  735. X    break;
  736. X      case 3 :
  737. X    if (strcmp(cur_attrbuf.af_author.af_username,value))
  738. X      {
  739. X        if (found)
  740. X          last_match = TRUE;
  741. X        else
  742. X          cur_pos++;
  743. X      }
  744. X    else
  745. X      {
  746. X        if (!(found))
  747. X          {
  748. X        found = TRUE;
  749. X        pos1 = cur_pos;
  750. X          }
  751. X        cur_pos++;
  752. X      }
  753. X    break;
  754. X      case 4 :
  755. X    errexit(10,"group id");
  756. X    break;
  757. X      case 5 :
  758. X    (void) strcpy(val1, value);
  759. X    if ((val2 = index(val1,'.')) == 0)
  760. X      errexit(9, value);
  761. X    val2[0] = '\0';
  762. X    val2++;
  763. X    if ((atoi(val1) == cur_attrbuf.af_gen)
  764. X        && (atoi(val2) == cur_attrbuf.af_rev))
  765. X      {
  766. X        if (!(found))
  767. X          {
  768. X        found = TRUE;
  769. X        pos1 = cur_pos;
  770. X          }
  771. X        cur_pos++;
  772. X      }
  773. X    else
  774. X      {
  775. X        if (found)
  776. X          last_match = TRUE;
  777. X        else
  778. X          cur_pos++;
  779. X      }
  780. X    break;
  781. X      case 6:
  782. X    /* Variants */
  783. X    if ((strcmp(cur_attrbuf.af_variant,value)) != 0)
  784. X      {
  785. X        if (found)
  786. X          last_match = TRUE;
  787. X        else
  788. X          cur_pos++;
  789. X      }
  790. X    else
  791. X      {
  792. X        if (!(found))
  793. X          {
  794. X        found = TRUE;
  795. X        pos1 = cur_pos;
  796. X          }
  797. X        cur_pos++;
  798. X      }
  799. X    break;
  800. X      case 7 :
  801. X    if (strcmp(cur_attrbuf.af_syspath,value))
  802. X      {
  803. X        if (found)
  804. X          last_match = TRUE;
  805. X        else
  806. X          cur_pos++;
  807. X      }
  808. X    else
  809. X      {
  810. X        if (!(found))
  811. X          {
  812. X        found = TRUE;
  813. X        pos1 = cur_pos;
  814. X          }
  815. X        cur_pos++;
  816. X      }
  817. X    break;
  818. X      case 8 :
  819. X    if (strcmp(cur_attrbuf.af_host,value))
  820. X      {
  821. X        if (found)
  822. X          last_match = TRUE;
  823. X        else
  824. X          cur_pos++;
  825. X      }
  826. X    else
  827. X      {
  828. X        if (!(found))
  829. X          {
  830. X        found = TRUE;
  831. X        pos1 = cur_pos;
  832. X          }
  833. X        cur_pos++;
  834. X      }
  835. X    break;
  836. X      default :
  837. X/* af_udattrs must contain a '=', even if they don't contain a value */
  838. X/* currently only the first value (if existing) in the string is     */
  839. X/* considered */
  840. X    i = 0;
  841. X    attr_found = FALSE;
  842. X/* find name in list of udattrs */
  843. X    while ((!(attr_found)) && (i < AF_MAXUDAS) &&
  844. X           (cur_attrbuf.af_udattrs[i] != NIL))
  845. X      {
  846. X        (void) strcpy(val1, cur_attrbuf.af_udattrs[i]);
  847. X        if ((val2 = index(val1, '=')) == 0)
  848. X          errexit(10, "attrnot");
  849. X        val2[0] = '\0';
  850. X        if (strcmp(name, val1) != 0)
  851. X          i++;
  852. X        else
  853. X          attr_found = TRUE;
  854. X      }
  855. X/* name should be found now */
  856. X    if (!(attr_found))
  857. X      errexit(10, "attrnot");
  858. X
  859. X/* value comparison */
  860. X    val2++;
  861. X    if (*val2 == '\0')        /* no value given is considered as != */
  862. X      {
  863. X        if (found)
  864. X          last_match = TRUE;
  865. X        else
  866. X          cur_pos++;
  867. X      }
  868. X    else
  869. X      {
  870. X        if ((val3 = index(val2, AF_UDAVALDEL)) != 0) 
  871. X          val3[0] = '\0';     /* only first value in attrbuf is     */
  872. X                                  /* considered; parameter value should */
  873. X                                  /* contain only one value             */
  874. X        if (strcmp(value, val2) == 0)
  875. X          {
  876. X        if (!(found))
  877. X          {
  878. X            found = TRUE;
  879. X            pos1 = cur_pos;
  880. X          }
  881. X        cur_pos++;
  882. X          }
  883. X        else
  884. X          {
  885. X        if (found)
  886. X          last_match = TRUE;
  887. X        else
  888. X          cur_pos++;
  889. X          }
  890. X      }
  891. X      }
  892. X  }
  893. X
  894. Xif (!(found))
  895. X  {
  896. X#ifdef DEBUG_ATTR
  897. X    printf("matches:\n");
  898. X    i = 0;
  899. X    while (i < nrofkeys)
  900. X      {
  901. X    af_setgkey(set, i, &cur_key);
  902. X    af_gattrs(&cur_key, &cur_attrbuf);
  903. X    printf("version %d.%d\n", cur_attrbuf.af_gen, cur_attrbuf.af_rev);
  904. X    i++;
  905. X      }
  906. X#endif DEBUG_ATTR
  907. X
  908. X    return (TRUE);
  909. X  }
  910. Xelse
  911. X  {
  912. X    i = (cur_pos - pos1);
  913. X    while (i > 0)
  914. X      {
  915. X    if (af_setposrmkey(set, pos1) == -1)
  916. X      errexit(10, "af_setposrmkey");
  917. X    i--;
  918. X    nrofkeys--;
  919. X      }
  920. X    if (nrofkeys == 0)
  921. X      {
  922. X#ifdef DEBUG_ATTR
  923. X    printf("no match\n");
  924. X#endif DEBUG_ATTR
  925. X    return (FALSE);
  926. X      }
  927. X    else
  928. X      {
  929. X#ifdef DEBUG_ATTR
  930. X    printf("matches:\n");
  931. X    nrofkeys = af_nrofkeys(set);
  932. X    i = 0;
  933. X    while (i < nrofkeys)
  934. X      {
  935. X        af_setgkey(set, i, &cur_key);
  936. X        af_gattrs(&cur_key, &cur_attrbuf);
  937. X        printf("version %d.%d\n", cur_attrbuf.af_gen, cur_attrbuf.af_rev);
  938. X        i++;
  939. X      }
  940. X#endif DEBUG_ATTR
  941. X
  942. X    return (TRUE);
  943. X      }
  944. X  }
  945. X}
  946. X
  947. XBool attrlt(name, value, set)
  948. X     char *name;
  949. X     char *value;
  950. X     Af_set *set;
  951. X{
  952. Xint attr_type;
  953. Xint nrofkeys;
  954. Xint cur_pos;
  955. Xint i;
  956. X
  957. XAf_key cur_key;
  958. X
  959. XAf_attrs cur_attrbuf;
  960. X
  961. XBool match;
  962. XBool found;
  963. X
  964. Xchar val1[256];
  965. Xchar *val2;
  966. Xchar *val3;
  967. X
  968. X#ifdef DEBUG_ATTR
  969. Xprintf("attrlt(): name = #%s#,  value = #%s#\n", name,value);
  970. X#endif DEBUG_ATTR
  971. X
  972. X
  973. Xattr_type = get_attr_type(name);
  974. X
  975. Xif ((nrofkeys = af_nrofkeys(set)) == -1)
  976. X  errexit(10, "af_nrofkeys");
  977. X
  978. X#ifdef DEBUG_ATTR
  979. Xprintf("nrofkeys = %d\n", nrofkeys);
  980. X#endif DEBUG_ATTR
  981. X
  982. Xswitch (attr_type)
  983. X  {
  984. X  case 0 :
  985. X    if ((af_sortset(set,AF_ATTGEN)) == -1)
  986. X      errexit(10,"af_sortset");
  987. X    break;
  988. X  case 1 :
  989. X    if ((af_sortset(set,AF_ATTREV)) == -1)
  990. X      errexit(10,"af_sortset");
  991. X    break;
  992. X  case 2 :
  993. X    if ((af_sortset(set,AF_ATTSTATE)) == -1)
  994. X      errexit(10,"af_sortset");
  995. X    break;
  996. X  case 3 :
  997. X    if ((af_sortset(set,AF_ATTAUTHOR)) == -1)
  998. X      errexit(10,"af_sortset");
  999. X    break;
  1000. X  case 4 :
  1001. X    errexit(10,"group id");
  1002. X    break;
  1003. X  case 5 :
  1004. X    if ((af_sortset(set,AF_ATTVERSION)) == -1)
  1005. X      errexit(10,"af_sortset");
  1006. X    break;
  1007. X  case 6 :
  1008. X    if ((af_sortset(set,AF_ATTVARIANT)) == -1)
  1009. X      errexit(10,"af_sortset");
  1010. X    break;
  1011. X  case 7:
  1012. X    if ((af_sortset(set,AF_ATTSPATH)) == -1)
  1013. X      errexit(10,"af_sortset");
  1014. X    break;
  1015. X  case 8:
  1016. X    if ((af_sortset(set,AF_ATTHOST)) == -1)
  1017. X      errexit(10,"af_sortset");
  1018. X    break;
  1019. X  default :
  1020. X    if ((af_sortset(set,name)) == -1)
  1021. X      errexit(10,"af_sortset");
  1022. X  }
  1023. X
  1024. Xcur_pos = 0;
  1025. Xmatch = TRUE;
  1026. X
  1027. Xwhile ((cur_pos < nrofkeys) && match)
  1028. X  {
  1029. X    if ((err = af_setgkey(set, cur_pos, &cur_key)) == -1)
  1030. X      errexit(10, "af_setgkey");
  1031. X    
  1032. X    if (af_gattrs(&cur_key, &cur_attrbuf) == -1)
  1033. X      errexit(10, "af_gattrs");
  1034. X
  1035. X#ifdef DEBUG_ATTR
  1036. X    printf("key[%d] -> version %d.%d\n", cur_pos, cur_attrbuf.af_gen, cur_attrbuf.af_rev);
  1037. X#endif DEBUG_ATTR
  1038. X
  1039. X    switch (attr_type)
  1040. X      {
  1041. X      case 0 :
  1042. X    if (cur_attrbuf.af_gen < atoi(value))
  1043. X      cur_pos++;
  1044. X    else
  1045. X      match = FALSE;
  1046. X    break;
  1047. X      case 1 :
  1048. X    if (cur_attrbuf.af_rev < atoi(value))
  1049. X      cur_pos++;
  1050. X    else
  1051. X      match = FALSE;
  1052. X    break;
  1053. X      case 2 :
  1054. X    if ((int) cur_attrbuf.af_state < atoi(value))
  1055. X      cur_pos++;
  1056. X    else
  1057. X      match = FALSE;
  1058. X    break;
  1059. X      case 3 :
  1060. X    if ((strcmp(cur_attrbuf.af_author.af_username,value)) < 0)
  1061. X      cur_pos++;
  1062. X    else
  1063. X      match = FALSE;
  1064. X    break;
  1065. X      case 4 :
  1066. X    errexit(10,"group id");
  1067. X    break;
  1068. X      case 5 :
  1069. X    (void) strcpy(val1, value);
  1070. X    if ((val2 = index(val1,'.')) == 0)
  1071. X      errexit(9, value);
  1072. X    val2[0] = '\0';
  1073. X    val2++;
  1074. X    if (atoi(val1) < cur_attrbuf.af_gen)
  1075. X      match = FALSE;
  1076. X    else
  1077. X      {
  1078. X        if ((atoi(val1) == cur_attrbuf.af_gen) &&
  1079. X        (atoi(val2) <= cur_attrbuf.af_rev))
  1080. X          match = FALSE;
  1081. X        else
  1082. X          cur_pos++;
  1083. X      }
  1084. X    break;
  1085. X      case 6:
  1086. X    /* Variants */
  1087. X    if ((strcmp(cur_attrbuf.af_variant,value)) < 0)
  1088. X      cur_pos++;
  1089. X    else
  1090. X      match = FALSE;
  1091. X    break;
  1092. X      case 7 :
  1093. X    if ((strcmp(cur_attrbuf.af_syspath,value)) < 0)
  1094. X      cur_pos++;
  1095. X    else
  1096. X      match = FALSE;
  1097. X    break;
  1098. X      case 8 :
  1099. X    if ((strcmp(cur_attrbuf.af_host,value)) < 0 )
  1100. X      cur_pos++;
  1101. X    else
  1102. X      match = FALSE;
  1103. X    break;
  1104. X      default :
  1105. X/* af_udattrs must contain a '=', even if they don't contain a value */
  1106. X/* currently only the first value (if existing) in the string is     */
  1107. X/* considered */
  1108. X    i = 0;
  1109. X    found = FALSE;
  1110. X/* find name in list of udattrs */
  1111. X    while ((!(found)) && (i < AF_MAXUDAS) &&
  1112. X           (cur_attrbuf.af_udattrs[i] != NIL))
  1113. X      {
  1114. X        (void) strcpy(val1, cur_attrbuf.af_udattrs[i]);
  1115. X        if ((val2 = index(val1, '=')) == 0)
  1116. X          errexit(10, "attrlt");
  1117. X        val2[0] = '\0';
  1118. X        if (strcmp(name, val1) != 0)
  1119. X          i++;
  1120. X        else
  1121. X          found = TRUE;
  1122. X      }
  1123. X/* name should be found now */
  1124. X    if (!(found))
  1125. X      errexit(10, "attrlt");
  1126. X
  1127. X/* value comparison */
  1128. X    val2++;
  1129. X    if (*val2 == '\0')        /* no value given is considered as != */
  1130. X      cur_pos++;
  1131. X    else
  1132. X      {
  1133. X        if ((val3 = index(val2, AF_UDAVALDEL)) != 0) 
  1134. X          val3[0] = '\0';     /* only first value in attrbuf is     */
  1135. X                                  /* considered; parameter value should */
  1136. X                                  /* contain only one value             */
  1137. X        if (strcmp(value, val2) <= 0)
  1138. X          match = FALSE;
  1139. X        else
  1140. X          cur_pos++;
  1141. X      }
  1142. X      }
  1143. X  }  
  1144. Xif (match)
  1145. X  {
  1146. X#ifdef DEBUG_ATTR
  1147. X    printf("matches:\n");
  1148. X    i = 0;
  1149. X    while (i < nrofkeys)
  1150. X      {
  1151. X    af_setgkey(set, i, &cur_key);
  1152. X    af_gattrs(&cur_key, &cur_attrbuf);
  1153. X    printf("version %d.%d\n", cur_attrbuf.af_gen, cur_attrbuf.af_rev);
  1154. X    i++;
  1155. X      }
  1156. X#endif DEBUG_ATTR
  1157. X
  1158. X    return (TRUE);
  1159. X  }
  1160. Xelse                             /* remove keys from set if necessary */
  1161. X  {
  1162. X    while (cur_pos < nrofkeys)
  1163. X      {
  1164. X    if (af_setposrmkey(set, cur_pos) == -1)
  1165. X      errexit(10, "af_setposrmkey");
  1166. X    nrofkeys--;
  1167. X      }
  1168. X    if (nrofkeys == 0)
  1169. X      {
  1170. X#ifdef DEBUG_ATTR
  1171. X    printf("no matches\n");
  1172. X#endif DEBUG_ATTR
  1173. X
  1174. X    return (FALSE);
  1175. X      }
  1176. X    else
  1177. X      {
  1178. X#ifdef DEBUG_ATTR
  1179. X    printf("matches:\n");
  1180. X    nrofkeys = af_nrofkeys(set);
  1181. X    i = 0;
  1182. X    while (i < nrofkeys)
  1183. X      {
  1184. X        af_setgkey(set, i, &cur_key);
  1185. X        af_gattrs(&cur_key, &cur_attrbuf);
  1186. X        printf("version %d.%d\n", cur_attrbuf.af_gen, cur_attrbuf.af_rev);
  1187. X        i++;
  1188. X      }
  1189. X#endif DEBUG_ATTR
  1190. X
  1191. X    return (TRUE);
  1192. X      }
  1193. X  }
  1194. X
  1195. X}
  1196. X
  1197. XBool attrgt(name, value, set)
  1198. X     char *name;
  1199. X     char *value;
  1200. X     Af_set *set;
  1201. X{
  1202. Xint attr_type;
  1203. Xint nrofkeys;
  1204. Xint cur_pos;
  1205. Xint i;
  1206. X
  1207. XAf_key cur_key;
  1208. X
  1209. XAf_attrs cur_attrbuf;
  1210. X
  1211. XBool match;
  1212. XBool found;
  1213. X
  1214. Xchar val1[256];
  1215. Xchar *val2;
  1216. Xchar *val3;
  1217. X
  1218. X#ifdef DEBUG_ATTR
  1219. Xprintf("attrgt(): name = #%s#,  value = #%s#\n", name,value);
  1220. X#endif DEBUG_ATTR
  1221. X
  1222. Xattr_type = get_attr_type(name);
  1223. X
  1224. Xif ((nrofkeys = af_nrofkeys(set)) == -1)
  1225. X  errexit(10, "af_nrofkeys");
  1226. X
  1227. X#ifdef DEBUG_ATTR
  1228. Xprintf("nrofkeys = %d\n", nrofkeys);
  1229. X#endif DEBUG_ATTR
  1230. X
  1231. Xswitch (attr_type)
  1232. X  {
  1233. X  case 0 :
  1234. X    if ((af_sortset(set,AF_ATTGEN)) == -1)
  1235. X      errexit(10,"af_sortset");
  1236. X    break;
  1237. X  case 1 :
  1238. X    if ((af_sortset(set,AF_ATTREV)) == -1)
  1239. X      errexit(10,"af_sortset");
  1240. X    break;
  1241. X  case 2 :
  1242. X    if ((af_sortset(set,AF_ATTSTATE)) == -1)
  1243. X      errexit(10,"af_sortset");
  1244. X    break;
  1245. X  case 3 :
  1246. X    if ((af_sortset(set,AF_ATTAUTHOR)) == -1)
  1247. X      errexit(10,"af_sortset");
  1248. X    break;
  1249. X  case 4 :
  1250. X    errexit(10,"group id");
  1251. X    break;
  1252. X  case 5 :
  1253. X    if ((af_sortset(set,AF_ATTVERSION)) == -1)
  1254. X      errexit(10,"af_sortset");
  1255. X    break;
  1256. X  case 6 :
  1257. X    if ((af_sortset(set,AF_ATTVARIANT)) == -1)
  1258. X      errexit(10,"af_sortset");
  1259. X    break;
  1260. X  case 7:
  1261. X    if ((af_sortset(set,AF_ATTSPATH)) == -1)
  1262. X      errexit(10,"af_sortset");
  1263. X    break;
  1264. X  case 8:
  1265. X    if ((af_sortset(set,AF_ATTHOST)) == -1)
  1266. X      errexit(10,"af_sortset");
  1267. X    break;
  1268. X  default :
  1269. X    if ((af_sortset(set,name)) == -1)
  1270. X      errexit(10,"af_sortset");
  1271. X  }
  1272. X
  1273. Xcur_pos = (nrofkeys - 1);
  1274. Xmatch = TRUE;
  1275. X
  1276. Xwhile ((cur_pos >= 0) && match)
  1277. X  {
  1278. X    if ((err = af_setgkey(set, cur_pos, &cur_key)) == -1)
  1279. X      errexit(10, "af_setgkey");
  1280. X    
  1281. X    if (af_gattrs(&cur_key, &cur_attrbuf) == -1)
  1282. X      errexit(10, "af_gattrs");
  1283. X
  1284. X#ifdef DEBUG_ATTR
  1285. X    printf("key[%d] -> version %d.%d\n", cur_pos, cur_attrbuf.af_gen, cur_attrbuf.af_rev);
  1286. X#endif DEBUG_ATTR
  1287. X
  1288. X    switch (attr_type)
  1289. X      {
  1290. X      case 0 :
  1291. X    if (cur_attrbuf.af_gen > atoi(value))
  1292. X      cur_pos--;
  1293. X    else
  1294. X      match = FALSE;
  1295. X    break;
  1296. X      case 1 :
  1297. X    if (cur_attrbuf.af_rev > atoi(value))
  1298. X      cur_pos--;
  1299. X    else
  1300. X      match = FALSE;
  1301. X    break;
  1302. X      case 2 :
  1303. X    if ((int) cur_attrbuf.af_state > atoi(value))
  1304. X      cur_pos--;
  1305. X    else
  1306. X      match = FALSE;
  1307. X    break;
  1308. X      case 3 :
  1309. X    if ((strcmp(cur_attrbuf.af_author.af_username,value)) > 0)
  1310. X      cur_pos--;
  1311. X    else
  1312. X      match = FALSE;
  1313. X    break;
  1314. X      case 4 :
  1315. X    errexit(10,"group id");
  1316. X    break;
  1317. X      case 5 :
  1318. X    (void) strcpy(val1, value);
  1319. X    if ((val2 = index(val1,'.')) == 0)
  1320. X      errexit(9, value);
  1321. X    val2[0] = '\0';
  1322. X    val2++;
  1323. X    if (atoi(val1) > cur_attrbuf.af_gen)
  1324. X      match = FALSE;
  1325. X    else
  1326. X      {
  1327. X        if ((atoi(val1) == cur_attrbuf.af_gen) &&
  1328. X        (atoi(val2) >= cur_attrbuf.af_rev))
  1329. X          match = FALSE;
  1330. X        else
  1331. X          cur_pos--;
  1332. X      }
  1333. X    break;
  1334. X      case 6:
  1335. X    /* Variants */
  1336. X    if ((strcmp(cur_attrbuf.af_variant,value))  > 0)
  1337. X      cur_pos--;
  1338. X    else
  1339. X      match = FALSE;
  1340. X    break;
  1341. X      case 7 :
  1342. X    if ((strcmp(cur_attrbuf.af_syspath,value)) > 0)
  1343. X      cur_pos--;
  1344. X    else
  1345. X      match = FALSE;
  1346. X    break;
  1347. X      case 8 :
  1348. X    if ((strcmp(cur_attrbuf.af_host,value)) > 0)
  1349. X      cur_pos--;
  1350. X    else
  1351. X      match = FALSE;
  1352. X    break;
  1353. X      default :
  1354. X/* af_udattrs must contain a '=', even if they don't contain a value */
  1355. X/* currently only the first value (if existing) in the string is     */
  1356. X/* considered */
  1357. X    i = 0;
  1358. X    found = FALSE;
  1359. X/* find name in list of udattrs */
  1360. X    while ((!(found)) && (i < AF_MAXUDAS) &&
  1361. X           (cur_attrbuf.af_udattrs[i] != NIL))
  1362. X      {
  1363. X        (void) strcpy(val1, cur_attrbuf.af_udattrs[i]);
  1364. X        if ((val2 = index(val1, '=')) == 0)
  1365. X          errexit(10, "attrgt");
  1366. X        val2[0] = '\0';
  1367. X        if (strcmp(name, val1) != 0)
  1368. X          i++;
  1369. X        else
  1370. X          found = TRUE;
  1371. X      }
  1372. X/* name should be found now */
  1373. X    if (!(found))
  1374. X      errexit(10, "attrgt");
  1375. X
  1376. X/* value comparison */
  1377. X    val2++;
  1378. X    if (*val2 == '\0')        /* no value given is considered as < */
  1379. X      match = FALSE;
  1380. X    else
  1381. X      {
  1382. X        if ((val3 = index(val2, AF_UDAVALDEL)) != 0) 
  1383. X          val3[0] = '\0';     /* only first value is considered */
  1384. X        if (strcmp(value, val2) >= 0)
  1385. X          match = FALSE;
  1386. X        else
  1387. X          cur_pos--;
  1388. X      }
  1389. X      }
  1390. X  }
  1391. Xif (match)
  1392. X  {
  1393. X#ifdef DEBUG_ATTR
  1394. X    printf("matches:\n");
  1395. X    i = 0;
  1396. X    while (i < nrofkeys)
  1397. X      {
  1398. X    af_setgkey(set, i, &cur_key);
  1399. X    af_gattrs(&cur_key, &cur_attrbuf);
  1400. X    printf("version %d.%d\n", cur_attrbuf.af_gen, cur_attrbuf.af_rev);
  1401. X    i++;
  1402. X      }
  1403. X#endif DEBUG_ATTR
  1404. X
  1405. X    return (TRUE);
  1406. X  }
  1407. Xelse                             /* remove keys from set if necessary */
  1408. X  {
  1409. X    while (cur_pos >= 0)
  1410. X      {
  1411. X    if (af_setposrmkey(set, cur_pos) == -1)
  1412. X      errexit(10, "af_setposrmkey");
  1413. X    cur_pos--;
  1414. X    nrofkeys--;
  1415. X      }
  1416. X    if (nrofkeys == 0)
  1417. X      {
  1418. X#ifdef DEBUG_ATTR
  1419. X    printf("no matches\n");
  1420. X#endif DEBUG_ATTR
  1421. X
  1422. X    return (FALSE);
  1423. X      }
  1424. X    else
  1425. X      {
  1426. X#ifdef DEBUG_ATTR
  1427. X    printf("matches:\n");
  1428. X    nrofkeys = af_nrofkeys(set);
  1429. X    i = 0;
  1430. X    while (i < nrofkeys)
  1431. X      {
  1432. X        af_setgkey(set, i, &cur_key);
  1433. X        af_gattrs(&cur_key, &cur_attrbuf);
  1434. X        printf("version %d.%d\n", cur_attrbuf.af_gen, cur_attrbuf.af_rev);
  1435. X        i++;
  1436. X      }
  1437. X#endif DEBUG_ATTR
  1438. X
  1439. X    return (TRUE);
  1440. X      }
  1441. X  }
  1442. X}
  1443. X
  1444. XBool attrle(name, value, set)
  1445. X     char *name;
  1446. X     char *value;
  1447. X     Af_set *set;
  1448. X{
  1449. Xint attr_type;
  1450. Xint nrofkeys;
  1451. Xint cur_pos;
  1452. Xint i;
  1453. X
  1454. XAf_key cur_key;
  1455. X
  1456. XAf_attrs cur_attrbuf;
  1457. X
  1458. XBool match;
  1459. XBool found;
  1460. X
  1461. Xchar val1[256];
  1462. Xchar *val2;
  1463. Xchar *val3;
  1464. X
  1465. X#ifdef DEBUG_ATTR
  1466. Xprintf("attrle(): name = #%s#,  value = #%s#\n", name,value);
  1467. X#endif DEBUG_ATTR
  1468. X
  1469. Xattr_type = get_attr_type(name);
  1470. X
  1471. Xif ((nrofkeys = af_nrofkeys(set)) == -1)
  1472. X  errexit(10, "af_nrofkeys");
  1473. X
  1474. X#ifdef DEBUG_ATTR
  1475. Xprintf("nrofkeys = %d\n", nrofkeys);
  1476. X#endif DEBUG_ATTR
  1477. X
  1478. Xswitch (attr_type)
  1479. X  {
  1480. X  case 0 :
  1481. X    if ((af_sortset(set,AF_ATTGEN)) == -1)
  1482. X      errexit(10,"af_sortset");
  1483. X    break;
  1484. X  case 1 :
  1485. X    if ((af_sortset(set,AF_ATTREV)) == -1)
  1486. X      errexit(10,"af_sortset");
  1487. X    break;
  1488. X  case 2 :
  1489. X    if ((af_sortset(set,AF_ATTSTATE)) == -1)
  1490. X      errexit(10,"af_sortset");
  1491. X    break;
  1492. X  case 3 :
  1493. X    if ((af_sortset(set,AF_ATTAUTHOR)) == -1)
  1494. X      errexit(10,"af_sortset");
  1495. X    break;
  1496. X  case 4 :
  1497. X    errexit(10,"group id");
  1498. X    break;
  1499. X  case 5 :
  1500. X    if ((af_sortset(set,AF_ATTVERSION)) == -1)
  1501. X      errexit(10,"af_sortset");
  1502. X    break;
  1503. X  case 6 :
  1504. X    if ((af_sortset(set,AF_ATTVARIANT)) == -1)
  1505. X      errexit(10,"af_sortset");
  1506. X    break;
  1507. X  case 7:
  1508. X    if ((af_sortset(set,AF_ATTSPATH)) == -1)
  1509. X      errexit(10,"af_sortset");
  1510. X    break;
  1511. X  case 8:
  1512. X    if ((af_sortset(set,AF_ATTHOST)) == -1)
  1513. X      errexit(10,"af_sortset");
  1514. X    break;
  1515. X  default :
  1516. X    if ((af_sortset(set,name)) == -1)
  1517. X      errexit(10,"af_sortset");
  1518. X  }
  1519. X
  1520. Xcur_pos = 0;
  1521. Xmatch = TRUE;
  1522. X
  1523. Xwhile ((cur_pos < nrofkeys) && match)
  1524. X  {
  1525. X    if ((err = af_setgkey(set, cur_pos, &cur_key)) == -1)
  1526. X      errexit(10, "af_setgkey");
  1527. X    
  1528. X    if (af_gattrs(&cur_key, &cur_attrbuf) == -1)
  1529. X      errexit(10, "af_gattrs");
  1530. X
  1531. X#ifdef DEBUG_ATTR
  1532. X    printf("key[%d] -> version %d.%d\n", cur_pos, cur_attrbuf.af_gen, cur_attrbuf.af_rev);
  1533. X#endif DEBUG_ATTR
  1534. X
  1535. X    switch (attr_type)
  1536. X      {
  1537. X      case 0 :
  1538. X    if (cur_attrbuf.af_gen <= atoi(value))
  1539. X      cur_pos++;
  1540. X    else
  1541. X      match = FALSE;
  1542. X    break;
  1543. X      case 1 :
  1544. X    if (cur_attrbuf.af_rev <= atoi(value))
  1545. X      cur_pos++;
  1546. X    else
  1547. X      match = FALSE;
  1548. X    break;
  1549. X      case 2 :
  1550. X    if ((int) cur_attrbuf.af_state <= atoi(value))
  1551. X      cur_pos++;
  1552. X    else
  1553. X      match = FALSE;
  1554. X    break;
  1555. X      case 3 :
  1556. X    if ((strcmp(cur_attrbuf.af_author.af_username,value)) <= 0)
  1557. X      cur_pos++;
  1558. X    else
  1559. X      match = FALSE;
  1560. X    break;
  1561. X      case 4 :
  1562. X    errexit(10,"group id");
  1563. X    break;
  1564. X      case 5 :
  1565. X    (void) strcpy(val1, value);
  1566. X    if ((val2 = index(val1,'.')) == 0)
  1567. X      errexit(9, value);
  1568. X    val2[0] = '\0';
  1569. X    val2++;
  1570. X    if (atoi(val1) < cur_attrbuf.af_gen)
  1571. X      match = FALSE;
  1572. X    else
  1573. X      {
  1574. X        if ((atoi(val1) == cur_attrbuf.af_gen) &&
  1575. X        (atoi(val2) < cur_attrbuf.af_rev))
  1576. X          match = FALSE;
  1577. X        else
  1578. X          cur_pos++;
  1579. X      }
  1580. X    break;
  1581. X      case 6:
  1582. X    /* Variants */
  1583. X    if ((strcmp(cur_attrbuf.af_variant,value)) <= 0)
  1584. X      cur_pos++;
  1585. X    else
  1586. X      match = FALSE;
  1587. X    break;
  1588. X      case 7 :
  1589. X    if ((strcmp(cur_attrbuf.af_syspath,value)) <= 0)
  1590. X      cur_pos++;
  1591. X    else
  1592. X      match = FALSE;
  1593. X    break;
  1594. X      case 8 :
  1595. X    if ((strcmp(cur_attrbuf.af_host,value)) <= 0)
  1596. X      cur_pos++;
  1597. X    else
  1598. X      match = FALSE;
  1599. X    break;
  1600. X      default :
  1601. X/* af_udattrs must contain a '=', even if they don't contain a value */
  1602. X/* currently only the first value (if existing) in the string is     */
  1603. X/* considered */
  1604. X    i = 0;
  1605. X    found = FALSE;
  1606. X/* find name in list of udattrs */
  1607. X    while ((!(found)) && (i < AF_MAXUDAS) &&
  1608. X           (cur_attrbuf.af_udattrs[i] != NIL))
  1609. X      {
  1610. X        (void) strcpy(val1, cur_attrbuf.af_udattrs[i]);
  1611. X        if ((val2 = index(val1, '=')) == 0)
  1612. X          errexit(10, "attrle");
  1613. X        val2[0] = '\0';
  1614. X        if (strcmp(name, val1) != 0)
  1615. X          i++;
  1616. X        else
  1617. X          found = TRUE;
  1618. X      }
  1619. X/* name should be found now */
  1620. X    if (!(found))
  1621. X      errexit(10, "attrle");
  1622. X
  1623. X/* value comparison */
  1624. X    val2++;
  1625. X    if (*val2 == '\0')        /* no value given is considered as <= */
  1626. X      cur_pos++;
  1627. X    else
  1628. X      {
  1629. X        if ((val3 = index(val2, AF_UDAVALDEL)) != 0) 
  1630. X          val3[0] = '\0';     /* only first value is considered */
  1631. X        if (strcmp(value, val2) < 0)
  1632. X          match = FALSE;
  1633. X        else
  1634. X          cur_pos++;
  1635. X      }
  1636. X      }
  1637. X  }  
  1638. Xif (match)
  1639. X  {
  1640. X#ifdef DEBUG_ATTR
  1641. X    printf("matches:\n");
  1642. X    i = 0;
  1643. X    while (i < nrofkeys)
  1644. X      {
  1645. X    af_setgkey(set, i, &cur_key);
  1646. X    af_gattrs(&cur_key, &cur_attrbuf);
  1647. X    printf("version %d.%d\n", cur_attrbuf.af_gen, cur_attrbuf.af_rev);
  1648. X    i++;
  1649. X      }
  1650. X#endif DEBUG_ATTR
  1651. X    return (TRUE);
  1652. X  }
  1653. Xelse                             /* remove keys from set if necessary */
  1654. X  {
  1655. X    while (cur_pos < nrofkeys)
  1656. X      {
  1657. X    if (af_setposrmkey(set, cur_pos) == -1)
  1658. X      errexit(10, "af_setposrmkey");
  1659. X    nrofkeys--;
  1660. X      }
  1661. X    if (nrofkeys == 0)
  1662. X      {
  1663. X#ifdef DEBUG_ATTR
  1664. X    printf("no matches\n");
  1665. X#endif DEBUG_ATTR
  1666. X
  1667. X    return (FALSE);
  1668. X      }
  1669. X    else
  1670. X      {
  1671. X#ifdef DEBUG_ATTR
  1672. X    printf("matches:\n");
  1673. X    nrofkeys = af_nrofkeys(set);
  1674. X    i = 0;
  1675. X    while (i < nrofkeys)
  1676. X      {
  1677. X        af_setgkey(set, i, &cur_key);
  1678. X        af_gattrs(&cur_key, &cur_attrbuf);
  1679. X        printf("version %d.%d\n", cur_attrbuf.af_gen, cur_attrbuf.af_rev);
  1680. X        i++;
  1681. X      }
  1682. X#endif DEBUG_ATTR
  1683. X
  1684. X    return (TRUE);
  1685. X      }
  1686. X  }
  1687. X        
  1688. X}
  1689. X
  1690. X
  1691. XBool attrge(name , value, set)
  1692. X     char *name;
  1693. X     char *value;
  1694. X     Af_set *set;
  1695. X{
  1696. Xint attr_type;
  1697. Xint nrofkeys;
  1698. Xint cur_pos;
  1699. Xint i;
  1700. X
  1701. XAf_key cur_key;
  1702. X
  1703. XAf_attrs cur_attrbuf;
  1704. X
  1705. XBool match;
  1706. XBool found;
  1707. X
  1708. Xchar val1[256];
  1709. Xchar *val2;
  1710. Xchar *val3;
  1711. X
  1712. X#ifdef DEBUG_ATTR
  1713. Xprintf("attrge(): name = #%s#,  value = #%s#\n", name,value);
  1714. X#endif DEBUG_ATTR
  1715. X
  1716. Xattr_type = get_attr_type(name);
  1717. X
  1718. Xif ((nrofkeys = af_nrofkeys(set)) == -1)
  1719. X  errexit(10, "af_nrofkeys");
  1720. X
  1721. X#ifdef DEBUG_ATTR
  1722. Xprintf("nrofkeys = %d\n", nrofkeys);
  1723. X#endif DEBUG_ATTR
  1724. X
  1725. Xswitch (attr_type)
  1726. X  {
  1727. X  case 0 :
  1728. X    if ((af_sortset(set,AF_ATTGEN)) == -1)
  1729. X      errexit(10,"af_sortset");
  1730. X    break;
  1731. X  case 1 :
  1732. X    if ((af_sortset(set,AF_ATTREV)) == -1)
  1733. X      errexit(10,"af_sortset");
  1734. X    break;
  1735. X  case 2 :
  1736. X    if ((af_sortset(set,AF_ATTSTATE)) == -1)
  1737. X      errexit(10,"af_sortset");
  1738. X    break;
  1739. X  case 3 :
  1740. X    if ((af_sortset(set,AF_ATTAUTHOR)) == -1)
  1741. X      errexit(10,"af_sortset");
  1742. X    break;
  1743. X  case 4 :
  1744. X    errexit(10,"group id");
  1745. X    break;
  1746. X  case 5 :
  1747. X    if ((af_sortset(set,AF_ATTVERSION)) == -1)
  1748. X      errexit(10,"af_sortset");
  1749. X    break;
  1750. X  case 6 :
  1751. X    if ((af_sortset(set,AF_ATTVARIANT)) == -1)
  1752. X      errexit(10,"af_sortset");
  1753. X    break;
  1754. X  case 7:
  1755. X    if ((af_sortset(set,AF_ATTSPATH)) == -1)
  1756. X      errexit(10,"af_sortset");
  1757. X    break;
  1758. X  case 8:
  1759. X    if ((af_sortset(set,AF_ATTHOST)) == -1)
  1760. X      errexit(10,"af_sortset");
  1761. X    break;
  1762. X  default :
  1763. X    if ((af_sortset(set,name)) == -1)
  1764. X      errexit(10,"af_sortset");
  1765. X  }
  1766. X
  1767. Xcur_pos = (nrofkeys - 1);
  1768. Xmatch = TRUE;
  1769. X
  1770. Xwhile ((cur_pos >= 0) && match)
  1771. X  {
  1772. X    if ((err = af_setgkey(set, cur_pos, &cur_key)) == -1)
  1773. X      errexit(10, "af_setgkey");
  1774. X    
  1775. X    if (af_gattrs(&cur_key, &cur_attrbuf) == -1)
  1776. X      errexit(10, "af_gattrs");
  1777. X
  1778. X#ifdef DEBUG_ATTR
  1779. X    printf("key[%d] -> version %d.%d\n", cur_pos, cur_attrbuf.af_gen, cur_attrbuf.af_rev);
  1780. X#endif DEBUG_ATTR
  1781. X
  1782. X    switch (attr_type)
  1783. X      {
  1784. X      case 0 :
  1785. X    if (cur_attrbuf.af_gen >= atoi(value))
  1786. X      cur_pos--;
  1787. X    else
  1788. X      match = FALSE;
  1789. X    break;
  1790. X      case 1 :
  1791. X    if (cur_attrbuf.af_rev >= atoi(value))
  1792. X      cur_pos--;
  1793. X    else
  1794. X      match = FALSE;
  1795. X    break;
  1796. X      case 2 :
  1797. X    if ((int) cur_attrbuf.af_state >= get_state_no(value))
  1798. X      cur_pos--;
  1799. X    else
  1800. X      match = FALSE;
  1801. X    break;
  1802. X      case 3 :
  1803. X    if ((strcmp(cur_attrbuf.af_author.af_username,value)) >= 0)
  1804. X      cur_pos--;
  1805. X    else
  1806. X      match = FALSE;
  1807. X    break;
  1808. X      case 4 :
  1809. X    errexit(10,"group id");
  1810. X    break;
  1811. X      case 5 :
  1812. X    (void) strcpy(val1, value);
  1813. X    if ((val2 = index(val1,'.')) == 0)
  1814. X      errexit(9, value);
  1815. X    val2[0] = '\0';
  1816. X    val2++;
  1817. X    if (atoi(val1) > cur_attrbuf.af_gen)
  1818. X      match = FALSE;
  1819. X    else
  1820. X      {
  1821. X        if ((atoi(val1) == cur_attrbuf.af_gen) &&
  1822. X        (atoi(val2) > cur_attrbuf.af_rev))
  1823. X          match = FALSE;
  1824. X        else
  1825. X          cur_pos--;
  1826. X      }
  1827. X    break;
  1828. X      case 6:
  1829. X    /* Variants */
  1830. X    if ((strcmp(cur_attrbuf.af_variant,value)) >= 0)
  1831. X      cur_pos--;
  1832. X    else
  1833. X      match = FALSE;
  1834. X    break;
  1835. X      case 7 :
  1836. X    if ((strcmp(cur_attrbuf.af_syspath,value)) >= 0)
  1837. X      cur_pos--;
  1838. X    else
  1839. X      match = FALSE;
  1840. X    break;
  1841. X      case 8 :
  1842. X    if ((strcmp(cur_attrbuf.af_host,value)) >= 0)
  1843. X      cur_pos--;
  1844. X    else
  1845. X      match = FALSE;
  1846. X    break;
  1847. X      default :
  1848. X/* af_udattrs must contain a '=', even if they don't contain a value */
  1849. X/* currently only the first value (if existing) in the string is     */
  1850. X/* considered */
  1851. X    i = 0;
  1852. X    found = FALSE;
  1853. X/* find name in list of udattrs */
  1854. X    while ((!(found)) && (i < AF_MAXUDAS) &&
  1855. X           (cur_attrbuf.af_udattrs[i] != NIL))
  1856. X      {
  1857. X        (void) strcpy(val1, cur_attrbuf.af_udattrs[i]);
  1858. X        if ((val2 = index(val1, '=')) == 0)
  1859. X          errexit(10, "attrge");
  1860. X        val2[0] = '\0';
  1861. X        if (strcmp(name, val1) != 0)
  1862. X          i++;
  1863. X        else
  1864. X          found = TRUE;
  1865. X      }
  1866. X/* name should be found now */
  1867. X    if (!(found))
  1868. X      errexit(10, "attrge");
  1869. X
  1870. X/* value comparison */
  1871. X    val2++;
  1872. X    if (*val2 == '\0')        /* no value given is considered as < */
  1873. X      match = FALSE;
  1874. X    else
  1875. X      {
  1876. X        if ((val3 = index(val2, AF_UDAVALDEL)) != 0) 
  1877. X          val3[0] = '\0';     /* only first value is considered */
  1878. X        if (strcmp(value, val2) > 0)
  1879. X          match = FALSE;
  1880. X        else
  1881. X          cur_pos--;
  1882. X      }
  1883. X      }
  1884. X  }
  1885. Xif (match)
  1886. X  {
  1887. X#ifdef DEBUG_ATTR
  1888. X    printf("matches:\n");
  1889. X    i = 0;
  1890. X    while (i < nrofkeys)
  1891. X      {
  1892. X    af_setgkey(set, i, &cur_key);
  1893. X    af_gattrs(&cur_key, &cur_attrbuf);
  1894. X    printf("version %d.%d\n", cur_attrbuf.af_gen, cur_attrbuf.af_rev);
  1895. X    i++;
  1896. X      }
  1897. X#endif DEBUG_ATTR
  1898. X
  1899. X    return (TRUE);
  1900. X  }
  1901. Xelse                             /* remove keys from set if necessary */
  1902. X  {
  1903. X    while (cur_pos >= 0)
  1904. X      {
  1905. X    if (af_setposrmkey(set, cur_pos) == -1)
  1906. X      errexit(10, "af_setposrmkey");
  1907. X    cur_pos--;
  1908. X    nrofkeys--;
  1909. X      }
  1910. X    if (nrofkeys == 0)
  1911. X      {
  1912. X#ifdef DEBUG_ATTR
  1913. X    printf("no matches\n");
  1914. X#endif DEBUG_ATTR
  1915. X
  1916. X    return (FALSE);
  1917. X      }
  1918. X    else
  1919. X      {
  1920. X#ifdef DEBUG_ATTR
  1921. X    printf("matches:\n");
  1922. X    nrofkeys = af_nrofkeys(set);
  1923. X    i = 0;
  1924. X    while (i < nrofkeys)
  1925. X      {
  1926. X        af_setgkey(set, i, &cur_key);
  1927. X        af_gattrs(&cur_key, &cur_attrbuf);
  1928. X        printf("version %d.%d\n", cur_attrbuf.af_gen, cur_attrbuf.af_rev);
  1929. X        i++;
  1930. X      }
  1931. X#endif DEBUG_ATTR
  1932. X
  1933. X    return (TRUE);
  1934. X      }
  1935. X  }
  1936. X
  1937. X}
  1938. X
  1939. X
  1940. X
  1941. XBool attrmax(name, value, set)
  1942. X     char *name;
  1943. X     char *value;
  1944. X     Af_set *set;
  1945. X{
  1946. Xint attr_type;
  1947. Xint nrofkeys;
  1948. Xint cur_pos;
  1949. Xint i;
  1950. Xint udattr_pos;
  1951. X
  1952. XAf_key cur_key;
  1953. X
  1954. XAf_attrs cur_attrbuf;
  1955. XAf_attrs max_attrbuf;
  1956. X
  1957. XBool match;
  1958. XBool found;
  1959. X
  1960. Xchar val1[256];
  1961. Xchar *val2;
  1962. X
  1963. X#ifdef DEBUG_ATTR
  1964. Xprintf("attrmax(): name = #%s#\n", name);
  1965. X#endif DEBUG_ATTR
  1966. X
  1967. Xattr_type = get_attr_type(name);
  1968. X
  1969. Xif ((nrofkeys = af_nrofkeys(set)) == -1)
  1970. X  errexit(10, "af_nrofkeys");
  1971. X
  1972. X#ifdef DEBUG_ATTR
  1973. Xprintf("nrofkeys = %d\n", nrofkeys);
  1974. X#endif DEBUG_ATTR
  1975. X
  1976. Xswitch (attr_type)
  1977. X  {
  1978. X  case 0 :
  1979. X    if ((af_sortset(set,AF_ATTGEN)) == -1)
  1980. X      errexit(10,"af_sortset");
  1981. X    break;
  1982. X  case 1 :
  1983. X    if ((af_sortset(set,AF_ATTREV)) == -1)
  1984. X      errexit(10,"af_sortset");
  1985. X    break;
  1986. X  case 2 :
  1987. X    if ((af_sortset(set,AF_ATTSTATE)) == -1)
  1988. X      errexit(10,"af_sortset");
  1989. X    break;
  1990. X  case 3 :
  1991. X    if ((af_sortset(set,AF_ATTAUTHOR)) == -1)
  1992. X      errexit(10,"af_sortset");
  1993. X    break;
  1994. X  case 4 :
  1995. X    errexit(10,"group id");
  1996. X    break;
  1997. X  case 5 :
  1998. X    if ((af_sortset(set,AF_ATTVERSION)) == -1)
  1999. X      errexit(10,"af_sortset");
  2000. X    break;
  2001. X  case 6 :
  2002. X    if ((af_sortset(set,AF_ATTVARIANT)) == -1)
  2003. X      errexit(10,"af_sortset");
  2004. X    break;
  2005. X  case 7:
  2006. X    if ((af_sortset(set,AF_ATTSPATH)) == -1)
  2007. X      errexit(10,"af_sortset");
  2008. X    break;
  2009. X  case 8:
  2010. X    if ((af_sortset(set,AF_ATTHOST)) == -1)
  2011. X      errexit(10,"af_sortset");
  2012. X    break;
  2013. X  default :
  2014. X    if ((af_sortset(set,name)) == -1)
  2015. X      errexit(10,"af_sortset");
  2016. X  }
  2017. X
  2018. Xif (nrofkeys == 1)
  2019. X  {
  2020. X#ifdef DEBUG_ATTR
  2021. X    printf("one match :\n");
  2022. X    af_setgkey(set, 0, &cur_key);
  2023. X    af_gattrs(&cur_key, &cur_attrbuf);
  2024. X    printf("version %d.%d\n", cur_attrbuf.af_gen, cur_attrbuf.af_rev);
  2025. X#endif DEBUG_ATTR
  2026. X
  2027. X    return (TRUE);
  2028. X  }
  2029. Xelse
  2030. X  {
  2031. X    if (nrofkeys == 0)
  2032. X      {
  2033. X#ifdef DEBUG_ATTR
  2034. X    printf("no match\n");
  2035. X#endif DEBUG_ATTR
  2036. X    return (FALSE);
  2037. X      }
  2038. X  }
  2039. X
  2040. Xcur_pos = (nrofkeys - 1);
  2041. Xmatch = TRUE;
  2042. X
  2043. Xif ((err = af_setgkey(set, cur_pos, &cur_key)) == -1)
  2044. X  errexit(10, "af_setgkey");
  2045. Xif (af_gattrs(&cur_key, &max_attrbuf) == -1)
  2046. X  errexit(10, "af_gattrs");
  2047. Xcur_pos--;
  2048. X
  2049. Xif (attr_type > STD_ATTRS)  /* if looking for udattrs  */
  2050. X/* name has to be found in list of udattrs     */
  2051. X  {
  2052. X    udattr_pos = 0;
  2053. X    found = FALSE;
  2054. X/* find name in list of udattrs */
  2055. X    while ((!(found)) && (udattr_pos < AF_MAXUDAS) &&
  2056. X       (max_attrbuf.af_udattrs[udattr_pos] != NIL))
  2057. X      {
  2058. X    (void) strcpy(val1, max_attrbuf.af_udattrs[udattr_pos]);
  2059. X    if ((val2 = index(val1, '=')) == 0)
  2060. X      errexit(10, "attrmax");
  2061. X    val2[0] = '\0';
  2062. X    if (strcmp(name, val1) != 0)
  2063. X      udattr_pos++;
  2064. X    else
  2065. X      found = TRUE;
  2066. X      }
  2067. X/* name should be found now */
  2068. X    if (!(found))
  2069. X      errexit(10, "attrmax");
  2070. X  }
  2071. X
  2072. Xwhile ((cur_pos >= 0) && match)
  2073. X  {
  2074. X    if ((err = af_setgkey(set, cur_pos, &cur_key)) == -1)
  2075. X      errexit(10, "af_setgkey");
  2076. X    
  2077. X    if (af_gattrs(&cur_key, &cur_attrbuf) == -1)
  2078. X      errexit(10, "af_gattrs");
  2079. X
  2080. X#ifdef DEBUG_ATTR
  2081. X    printf("key[%d] -> version %d.%d\n", cur_pos, cur_attrbuf.af_gen, cur_attrbuf.af_rev);
  2082. X#endif DEBUG_ATTR
  2083. X
  2084. X    switch (attr_type)
  2085. X      {
  2086. X      case 0 :
  2087. X    if (cur_attrbuf.af_gen == max_attrbuf.af_gen)
  2088. X      cur_pos--;
  2089. X    else
  2090. X      match = FALSE;
  2091. X    break;
  2092. X      case 1 :
  2093. X    if (cur_attrbuf.af_rev == max_attrbuf.af_rev)
  2094. X      cur_pos--;
  2095. X    else
  2096. X      match = FALSE;
  2097. X    break;
  2098. X      case 2 :
  2099. X    if (cur_attrbuf.af_state == max_attrbuf.af_state)
  2100. X      cur_pos--;
  2101. X    else
  2102. X      match = FALSE;
  2103. X    break;
  2104. X      case 3 :
  2105. X    if(!strcmp(cur_attrbuf.af_author.af_username,max_attrbuf.af_author.af_username))
  2106. X      cur_pos--;
  2107. X    else
  2108. X      match = FALSE;
  2109. X    break;
  2110. X      case 4 :
  2111. X    errexit(10,"group id");
  2112. X    break;
  2113. X      case 5 :
  2114. X    if ((cur_attrbuf.af_gen == max_attrbuf.af_gen) &&
  2115. X        (cur_attrbuf.af_rev == max_attrbuf.af_rev))
  2116. X      cur_pos--;
  2117. X    else
  2118. X      match = FALSE;
  2119. X    break;
  2120. X      case 6:
  2121. X    /* Variants */
  2122. X    if ((strcmp(cur_attrbuf.af_variant,max_attrbuf.af_variant) == 0))
  2123. X      cur_pos--;
  2124. X    else
  2125. X      match = FALSE;
  2126. X    break;
  2127. X      case 7 :
  2128. X    if ((strcmp(cur_attrbuf.af_syspath,value)) == 0)
  2129. X      cur_pos--;
  2130. X    else
  2131. X      match = FALSE;
  2132. X    break;
  2133. X      case 8 :
  2134. X    if ((strcmp(cur_attrbuf.af_host,value)) == 0)
  2135. X      cur_pos--;
  2136. X    else
  2137. X      match = FALSE;
  2138. X    break;
  2139. X      default :
  2140. X/* af_udattrs must contain a '=', even if they don't contain a value */
  2141. X/* currently only the first value (if existing) in the string is     */
  2142. X/* considered */
  2143. X    i = 0;
  2144. X    found = FALSE;
  2145. X/* find name in list of udattrs */
  2146. X    while ((!(found)) && (i < AF_MAXUDAS) &&
  2147. X           (cur_attrbuf.af_udattrs[i] != NIL))
  2148. X      {
  2149. X        (void) strcpy(val1, cur_attrbuf.af_udattrs[i]);
  2150. X        if ((val2 = index(val1, '=')) == 0)
  2151. X          errexit(10, "attrle");
  2152. X        val2[0] = '\0';
  2153. X        if (strcmp(name, val1) != 0)
  2154. X          i++;
  2155. X        else
  2156. X          found = TRUE;
  2157. X      }
  2158. X/* name should be found now */
  2159. X    if (!(found))
  2160. X      errexit(10, "attrmax");
  2161. X
  2162. X/* value comparison */
  2163. X    if (strcmp(cur_attrbuf.af_udattrs[i], 
  2164. X           max_attrbuf.af_udattrs[udattr_pos]) != 0)
  2165. X      match = FALSE;
  2166. X    else
  2167. X      cur_pos--;
  2168. X     
  2169. X      }
  2170. X  }
  2171. X
  2172. X/* remove keys from set if necessary */
  2173. Xi = cur_pos + 1;
  2174. Xwhile (i > 0)
  2175. X  {
  2176. X    if (af_setposrmkey(set, 0) == -1)
  2177. X      errexit(10, "af_setposrmkey");
  2178. X    i--;
  2179. X  }
  2180. X
  2181. X#ifdef DEBUG_ATTR
  2182. Xprintf("matches:\n");
  2183. Xnrofkeys = af_nrofkeys(set);
  2184. Xi = 0;
  2185. Xwhile (i < nrofkeys)
  2186. X  {
  2187. X    af_setgkey(set, i, &cur_key);
  2188. X    af_gattrs(&cur_key, &cur_attrbuf);
  2189. X    printf("version %d.%d\n", cur_attrbuf.af_gen, cur_attrbuf.af_rev);
  2190. X    i++;
  2191. X   }
  2192. X#endif DEBUG_ATTR
  2193. X  
  2194. Xreturn (TRUE);
  2195. X
  2196. X}
  2197. X
  2198. XBool attrmin(name, value, set)
  2199. X     char *name;
  2200. X     char *value;
  2201. X     Af_set *set;
  2202. X{
  2203. Xint attr_type;
  2204. Xint nrofkeys;
  2205. Xint cur_pos;
  2206. Xint i;
  2207. Xint udattr_pos;
  2208. X
  2209. XAf_key cur_key;
  2210. X
  2211. XAf_attrs cur_attrbuf;
  2212. XAf_attrs max_attrbuf;
  2213. X
  2214. XBool match;
  2215. XBool found;
  2216. X
  2217. Xchar val1[256];
  2218. Xchar *val2;
  2219. X
  2220. X#ifdef DEBUG_ATTR
  2221. Xprintf("attrmin(): name = #%s#\n", name);
  2222. X#endif DEBUG_ATTR
  2223. X
  2224. Xattr_type = get_attr_type(name);
  2225. X
  2226. Xif ((nrofkeys = af_nrofkeys(set)) == -1)
  2227. X  errexit(10, "af_nrofkeys");
  2228. X
  2229. X#ifdef DEBUG_ATTR
  2230. Xprintf("nrofkeys = %d\n", nrofkeys);
  2231. X#endif DEBUG_ATTR
  2232. X
  2233. Xif (nrofkeys == 1)
  2234. X  {
  2235. X#ifdef DEBUG_ATTR
  2236. X    printf("one match :\n");
  2237. X    af_setgkey(set, 0, &cur_key);
  2238. X    af_gattrs(&cur_key, &cur_attrbuf);
  2239. X    printf("version %d.%d\n", cur_attrbuf.af_gen, cur_attrbuf.af_rev);
  2240. X#endif DEBUG_ATTR
  2241. X
  2242. X    return (TRUE);
  2243. X  }
  2244. X
  2245. Xswitch (attr_type)
  2246. X  {
  2247. X  case 0 :
  2248. X    if ((af_sortset(set,AF_ATTGEN)) == -1)
  2249. X      errexit(10,"af_sortset");
  2250. X    break;
  2251. X  case 1 :
  2252. X    if ((af_sortset(set,AF_ATTREV)) == -1)
  2253. X      errexit(10,"af_sortset");
  2254. X    break;
  2255. X  case 2 :
  2256. X    if ((af_sortset(set,AF_ATTSTATE)) == -1)
  2257. X      errexit(10,"af_sortset");
  2258. X    break;
  2259. X  case 3 :
  2260. X    if ((af_sortset(set,AF_ATTAUTHOR)) == -1)
  2261. X      errexit(10,"af_sortset");
  2262. X    break;
  2263. X  case 4 :
  2264. X    errexit(10,"group id");
  2265. X    break;
  2266. X  case 5 :
  2267. X    if ((af_sortset(set,AF_ATTVERSION)) == -1)
  2268. X      errexit(10,"af_sortset");
  2269. X    break;
  2270. X  case 6 :
  2271. X    if ((af_sortset(set,AF_ATTVARIANT)) == -1)
  2272. X      errexit(10,"af_sortset");
  2273. X    break;
  2274. X  case 7:
  2275. X    if ((af_sortset(set,AF_ATTSPATH)) == -1)
  2276. X      errexit(10,"af_sortset");
  2277. X    break;
  2278. X  case 8:
  2279. X    if ((af_sortset(set,AF_ATTHOST)) == -1)
  2280. X      errexit(10,"af_sortset");
  2281. X    break;
  2282. X  default :
  2283. X    if ((af_sortset(set,name)) == -1)
  2284. X      errexit(10,"af_sortset");
  2285. X  }
  2286. X
  2287. Xcur_pos = (0);
  2288. Xmatch = TRUE;
  2289. X
  2290. Xif ((err = af_setgkey(set, cur_pos, &cur_key)) == -1)
  2291. X  errexit(10, "af_setgkey");
  2292. Xif (af_gattrs(&cur_key, &max_attrbuf) == -1)
  2293. X  errexit(10, "af_gattrs");
  2294. Xcur_pos++;
  2295. X
  2296. Xif (attr_type > STD_ATTRS)  /* if looking for udattrs  */
  2297. X/* name has to be found in list of udattrs     */
  2298. X  {
  2299. X    udattr_pos = 0;
  2300. X    found = FALSE;
  2301. X/* find name in list of udattrs */
  2302. X    while ((!(found)) && (udattr_pos < AF_MAXUDAS) &&
  2303. X       (max_attrbuf.af_udattrs[udattr_pos] != NIL))
  2304. X      {
  2305. X    (void) strcpy(val1, max_attrbuf.af_udattrs[udattr_pos]);
  2306. X    if ((val2 = index(val1, '=')) == 0)
  2307. X      errexit(10, "attrmin");
  2308. X    val2[0] = '\0';
  2309. X    if (strcmp(name, val1) != 0)
  2310. X      udattr_pos++;
  2311. X    else
  2312. X      found = TRUE;
  2313. X      }
  2314. X/* name should be found now */
  2315. X    if (!(found))
  2316. X      errexit(10, "attrmin");
  2317. X  }
  2318. X
  2319. Xwhile ((cur_pos < nrofkeys) && match)
  2320. X  {
  2321. X    if ((err = af_setgkey(set, cur_pos, &cur_key)) == -1)
  2322. X      errexit(10, "af_setgkey");
  2323. X    
  2324. X    if (af_gattrs(&cur_key, &cur_attrbuf) == -1)
  2325. X      errexit(10, "af_gattrs");
  2326. X
  2327. X#ifdef DEBUG_ATTR
  2328. X    printf("key[%d] -> version %d.%d\n", cur_pos, cur_attrbuf.af_gen, cur_attrbuf.af_rev);
  2329. X#endif DEBUG_ATTR
  2330. X
  2331. X    switch (attr_type)
  2332. X      {
  2333. X      case 0 :
  2334. X    if (cur_attrbuf.af_gen == max_attrbuf.af_gen)
  2335. X      cur_pos++;
  2336. X    else
  2337. X      match = FALSE;
  2338. X    break;
  2339. X      case 1 :
  2340. X    if (cur_attrbuf.af_rev == max_attrbuf.af_rev)
  2341. X      cur_pos++;
  2342. X    else
  2343. X      match = FALSE;
  2344. X    break;
  2345. X      case 2 :
  2346. X    if (cur_attrbuf.af_state == max_attrbuf.af_state)
  2347. X      cur_pos++;
  2348. X    else
  2349. X      match = FALSE;
  2350. X    break;
  2351. X      case 3 :
  2352. X    if (!strcmp(cur_attrbuf.af_author.af_username,max_attrbuf.af_author.af_username))
  2353. X      cur_pos++;
  2354. X    else
  2355. X      match = FALSE;
  2356. X    break;
  2357. X      case 4 :
  2358. X    errexit(10,"group id");
  2359. X    break;
  2360. X      case 5 :
  2361. X    if ((cur_attrbuf.af_gen == max_attrbuf.af_gen) &&
  2362. X        (cur_attrbuf.af_rev == max_attrbuf.af_rev))
  2363. X      cur_pos++;
  2364. X    else
  2365. X      match = FALSE;
  2366. X    break;
  2367. X      case 6:
  2368. X    /* Variants */
  2369. X    if ((strcmp(cur_attrbuf.af_variant,max_attrbuf.af_variant) == 0))
  2370. X      cur_pos++;
  2371. X    else
  2372. X      match = FALSE;
  2373. X    break;
  2374. X      case 7 :
  2375. X    if ((strcmp(cur_attrbuf.af_syspath,value)) == 0)
  2376. X      cur_pos++;
  2377. X    else
  2378. X      match = FALSE;
  2379. X    break;
  2380. X      case 8 :
  2381. X    if ((strcmp(cur_attrbuf.af_host,value)) == 0)
  2382. X      cur_pos++;
  2383. X    else
  2384. X      match = FALSE;
  2385. X    break;
  2386. X      default :
  2387. X/* af_udattrs must contain a '=', even if they don't contain a value */
  2388. X/* currently only the first value (if existing) in the string is     */
  2389. X/* considered */
  2390. X    i = 0;
  2391. X    found = FALSE;
  2392. X/* find name in list of udattrs */
  2393. X    while ((!(found)) && (i < AF_MAXUDAS) &&
  2394. X           (cur_attrbuf.af_udattrs[i] != NIL))
  2395. X      {
  2396. X        (void) strcpy(val1, cur_attrbuf.af_udattrs[i]);
  2397. X        if ((val2 = index(val1, '=')) == 0)
  2398. X          errexit(10, "attrle");
  2399. X        val2[0] = '\0';
  2400. X        if (strcmp(name, val1) != 0)
  2401. X          i++;
  2402. X        else
  2403. X          found = TRUE;
  2404. X      }    
  2405. X/* name should be found now */
  2406. X    if (!(found))
  2407. X      errexit(10, "attrmax");
  2408. X
  2409. X/* value comparison */
  2410. X    if (strcmp(cur_attrbuf.af_udattrs[i], 
  2411. X           max_attrbuf.af_udattrs[udattr_pos]) != 0)
  2412. X      match = FALSE;
  2413. X    else
  2414. X      cur_pos++;
  2415. X     
  2416. X      }
  2417. X  }
  2418. X
  2419. X/* remove keys from set if necessary */
  2420. Xwhile (cur_pos < nrofkeys)
  2421. X  {
  2422. X    if (af_setposrmkey(set, cur_pos) == -1)
  2423. X      errexit(10, "af_setposrmkey");
  2424. X    nrofkeys--;
  2425. X  }
  2426. X
  2427. X#ifdef DEBUG_ATTR
  2428. Xprintf("matches:\n");
  2429. Xnrofkeys = af_nrofkeys(set);
  2430. Xi = 0;
  2431. Xwhile (i < nrofkeys)
  2432. X  {
  2433. X    af_setgkey(set, i, &cur_key);
  2434. X    af_gattrs(&cur_key, &cur_attrbuf);
  2435. X    printf("version %d.%d\n", cur_attrbuf.af_gen, cur_attrbuf.af_rev);
  2436. X    i++;
  2437. X   }
  2438. X#endif DEBUG_ATTR
  2439. X
  2440. Xreturn (TRUE);
  2441. X
  2442. X}
  2443. X
  2444. X
  2445. XBool getfromcid()
  2446. X{
  2447. X/* not yet implemented */
  2448. X;
  2449. X}
  2450. X
  2451. XBool attrvar(name, value, set)
  2452. X     char *name;
  2453. X     /*ARGSUSED*/
  2454. X     char *value;
  2455. X     Af_set *set;
  2456. X{
  2457. X/* set variant path & variant flags */
  2458. Xint k = 0;
  2459. Xint i = 0;
  2460. Xchar *ind;
  2461. Xchar pathlist[256];
  2462. X
  2463. Xif (check_vclass(name) != TRUE)
  2464. X  errexit(30,name);
  2465. X
  2466. Xwhile( vardefs[k] != (struct vardef *) NIL)
  2467. X  {
  2468. X    if (strcmp (vardefs[k]->name, name) != 0)
  2469. X      k++;
  2470. X    else
  2471. X      {
  2472. X    while(curvpath[i] != NIL)
  2473. X      i++;
  2474. X    if (vardefs[k]->vpath != NIL)
  2475. X      {
  2476. X        (void) strcpy(pathlist,vardefs[k]->vpath);
  2477. X    
  2478. X        while(( ind = index(pathlist,':')) != NIL)
  2479. X          {
  2480. X        *ind = '\0';
  2481. X        if ((curvpath[i] = malloc((unsigned) (strlen(pathlist) + sizeof(char)))) == NIL)
  2482. X          errexit(10,"malloc");
  2483. X        (void) strcpy(curvpath[i],pathlist);
  2484. X        ind++;
  2485. X        (void) strcpy(pathlist,ind);
  2486. X        i++;
  2487. X          }
  2488. X        if ((curvpath[i] = malloc((unsigned) (strlen(pathlist) + sizeof(char)))) == NIL)
  2489. X          errexit(10,"malloc");
  2490. X        (void) strcpy(curvpath[i],pathlist);
  2491. X      }
  2492. X/*    strcpy(p,"vflags=");
  2493. X    (void) strcat(p,expandmacro("$(vflags)"));
  2494. X    (void) strcat(p," ");
  2495. X    (void) strcat(p,vardefs[k]->vflags);
  2496. X    macrodef(p);
  2497. X    free(p); */
  2498. X    break;
  2499. X      }
  2500. X  }
  2501. X
  2502. Xif (vardefs[k] != (struct vardef *) NIL)
  2503. X  {
  2504. X    if (strcmp(vardefs[k]->name, name) == 0)
  2505. X      return (TRUE);
  2506. X  }
  2507. Xelse
  2508. X  errexit(19,name);
  2509. X/*NOTREACHED*/
  2510. X}
  2511. X
  2512. X
  2513. X
  2514. Xchar *replace(patt)
  2515. X     char *patt;
  2516. X{
  2517. X
  2518. X/* converts shell-like pattern to ex-like pattern */
  2519. X/* not yet complete ???? */
  2520. X/* a{bc,d,e}f mactches abcf adf & aef not implemented */
  2521. X  int i,j;
  2522. X  char result[128];
  2523. X  char tmp_result[64];
  2524. X
  2525. X  static char rechars[] = "^.$?*[]{}";
  2526. X
  2527. X  j = 0;
  2528. X  
  2529. X  for(i = 0; i < strlen(patt); i++)
  2530. X    {
  2531. X      switch (patt[i])
  2532. X    {
  2533. X    case '?':
  2534. X      tmp_result[j++]='.';
  2535. X      break;
  2536. X    case '*':
  2537. X      tmp_result[j++]='.';
  2538. X        tmp_result[j++]='*'; 
  2539. X      break;
  2540. X    case '.':
  2541. X      tmp_result[j++]='\\';
  2542. X      tmp_result[j++]='.';
  2543. X      break;
  2544. X    default:
  2545. X      tmp_result[j++]=patt[i];
  2546. X      }
  2547. X  }
  2548. Xtmp_result[j]='\0';
  2549. X
  2550. X(void) sprintf(result,"%s%s%s",(!(index(rechars,tmp_result[0]))) ? "^" : "",
  2551. X    tmp_result, (!(index(rechars,tmp_result[strlen(tmp_result) - 1]))) ? 
  2552. X    "$" : "");
  2553. X  
  2554. Xreturn(result);
  2555. X}
  2556. X
  2557. END_OF_FILE
  2558. if test 50463 -ne `wc -c <'src/shape/attr.c'`; then
  2559.     echo shar: \"'src/shape/attr.c'\" unpacked with wrong size!
  2560. fi
  2561. # end of 'src/shape/attr.c'
  2562. fi
  2563. echo shar: End of archive 33 \(of 33\).
  2564. cp /dev/null ark33isdone
  2565. MISSING=""
  2566. 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
  2567.     if test ! -f ark${I}isdone ; then
  2568.     MISSING="${MISSING} ${I}"
  2569.     fi
  2570. done
  2571. if test "${MISSING}" = "" ; then
  2572.     echo You have unpacked all 33 archives.
  2573.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2574. else
  2575.     echo You still need to unpack the following archives:
  2576.     echo "        " ${MISSING}
  2577. fi
  2578. ##  End of shell archive.
  2579. exit 0
  2580.