home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / reviewed / volume03 / chipset2 / 03 < prev    next >
Encoding:
Text File  |  1993-03-13  |  33.9 KB  |  1,257 lines

  1. From decwrl!athertn!sander.cupertino.ca.us!paul@cs.purdue.edu Wed Jan  6 13:53:15 EST 1993
  2. Submit chipset-2 03/10 
  3. #! /bin/sh
  4. # This is a shell archive.  Remove anything before this line, then unpack
  5. # it by saving it into a file and typing "sh file".  To overwrite existing
  6. # files, type "sh file -c".  You can also feed this as standard input via
  7. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  8. # will see the following message at the end:
  9. #        "End of archive 3 (of 10)."
  10. # Contents:  ChipSet src/btree/btmalloc.c src/btree/btsearch.c
  11. #   src/list/README src/list/dldelete.c src/list/dldelrank.c
  12. #   src/list/dldestroy.c src/list/dlinsert.c src/list/dlinsutl.c
  13. #   src/list/dlnext.c src/list/dlsearch.c src/list/dltrav.c
  14. # Wrapped by paul@sander on Sun Nov 22 15:41:49 1992
  15. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  16. if test -f ChipSet -a "${1}" != "-c" ; then 
  17.   echo shar: Will not over-write existing file \"ChipSet\"
  18. else
  19. echo shar: Extracting \"ChipSet\" \(2019 characters\)
  20. sed "s/^X//" >ChipSet <<'END_OF_ChipSet'
  21. XThe Software ChipSet is a collection of reusable software components that
  22. Xis being placed in the public domain by its author, Paul Sander.  The goal
  23. Xof the Software ChipSet is to provide small, general, production quality
  24. Xoff-the-shelf solutions to common problems that are faced by programmers.
  25. XIf compared to integrated circuits, these components probably best correspond
  26. Xto standard cells.  The complexity of the components are comparable to SSI
  27. X(small-scale integration) and MSI (medium scale integration) devices, but
  28. Xmany of them are reentrant and can be composed into larger components.
  29. X
  30. XThe components that comprise the Software ChipSet are intended to be general
  31. Xenough to be used in a wide variety of applications.  Two of the key features
  32. Xof these components are generalized interfaces, and programmability.  The
  33. Xgeneralized interfaces permit the components to be used with arbitrary data
  34. Xtypes.  Programmability permits the application to tune the components to
  35. Xits data types and performance requirements at run-time.  In addition, several
  36. Xcomponents solve similar problems with varying performance and storage
  37. Xcharacteristics; in such cases, the interfaces of the components are identical,
  38. Xsave for their initial configuration.
  39. X
  40. XThe programmability feature of the components also allows them to be composed
  41. Xinto larger components.  The design of the components is such that components
  42. Xburied deep in such a composition can still be configured by the application
  43. Xin a controlled way.  In addition, such components can be easily swapped out
  44. Xfor others should the programmer find that to be desirable.
  45. X
  46. XThe components are designed to be portable across Unix platforms, but many
  47. Xwill port to other platforms easily.  The target audience is rather ambitious:
  48. XAll platforms that support the standard Unix utilities, support a "void"
  49. Xtype, and have a "make" tool that is at least as capable as SVR2's.
  50. X
  51. XPlease send bug reports and other comments to Paul Sander via Internet mail
  52. Xat paul@sander.cupertino.ca.us .
  53. END_OF_ChipSet
  54. if test 2019 -ne `wc -c <ChipSet`; then
  55.     echo shar: \"ChipSet\" unpacked with wrong size!
  56. fi
  57. # end of overwriting check
  58. fi
  59. if test -f src/btree/btmalloc.c -a "${1}" != "-c" ; then 
  60.   echo shar: Will not over-write existing file \"src/btree/btmalloc.c\"
  61. else
  62. echo shar: Extracting \"src/btree/btmalloc.c\" \(2613 characters\)
  63. sed "s/^X//" >src/btree/btmalloc.c <<'END_OF_src/btree/btmalloc.c'
  64. X/**************************************************************
  65. X *
  66. X * btmalloc.c -- This file contains functions that augment the
  67. X *               C runtime library memory allocator in order
  68. X *               to aid debugging.
  69. X *
  70. X * This file is part of a suite of programs called Software Chipset.
  71. X * The source code for Software Chipset has been released into the
  72. X * public domain by its author, Paul Sander.
  73. X *
  74. X **************************************************************/
  75. X
  76. X#include <stdio.h>
  77. X
  78. X/* The following structure is used for debugging heap corruptions */
  79. X
  80. Xstruct heapblk {
  81. X    void    *blk;
  82. X    int    freeNext;
  83. X};
  84. X
  85. Xstruct heap_struct {
  86. X    int        allocSeq;
  87. X    int        freeLast;
  88. X    struct heapblk    blks[10000];
  89. X};
  90. X
  91. Xstruct heap_struct btheap = {0,-1}; 
  92. X
  93. X
  94. X/*
  95. X * The following code is used for allocating space on the heap.  When not
  96. X * debugging heap corruptions, a macro aliases bt_malloc with malloc.
  97. X */
  98. X
  99. X#ifdef __STDC__
  100. Xvoid *bt_malloc(unsigned size)
  101. X#else
  102. Xvoid *bt_malloc(size)
  103. Xunsigned    size;
  104. X#endif
  105. X{
  106. X    void    *temp;
  107. X
  108. X    temp = (void*) malloc(size);
  109. X    btheap.blks[btheap.allocSeq].blk = temp;
  110. X    btheap.blks[btheap.allocSeq].freeNext = -2;
  111. X    btheap.allocSeq++;
  112. X    return temp;
  113. X}
  114. X
  115. X/*
  116. X * The following code is used for freeing memory on the heap.  If not
  117. X * debugging heap corruptions, bt_free is aliased with free.
  118. X */
  119. X
  120. X#ifdef __STDC__
  121. Xvoid bt_free(void *ptr)
  122. X#else
  123. Xvoid bt_free(ptr)
  124. Xvoid    *ptr;
  125. X#endif
  126. X{
  127. X    int    i;
  128. X
  129. X    printf("Freeing heap storage at %x\n",ptr);
  130. X    for (i = 0; i < btheap.allocSeq; i++)
  131. X    {
  132. X        if (ptr == btheap.blks[i].blk)
  133. X        {
  134. X            if (btheap.blks[i].freeNext == -2)
  135. X            {
  136. X                btheap.blks[i].freeNext = btheap.freeLast;
  137. X                btheap.freeLast = i;
  138. X                free(ptr);
  139. X                return;
  140. X            }
  141. X            else
  142. X            {
  143. X                printf(
  144. X                  "ERROR: freeing %x which was already freed\n",
  145. X                  ptr);
  146. X                printf("Block\n");
  147. X                i = btheap.freeLast;
  148. X                while (i > 0)
  149. X                {
  150. X                    printf("%x\n",btheap.blks[i].blk);
  151. X                    i = btheap.blks[i].freeNext;
  152. X                }
  153. X                fflush(stdout);
  154. X                kill(getpid(),5);
  155. X            }
  156. X        }
  157. X    }
  158. X    printf("ERROR:  Freeing %x which has not been allocated\n",ptr);
  159. X    fflush(stdout);
  160. X    kill(getpid(),5);
  161. X}
  162. X
  163. X/* The following verifies the integrity of the heap. */
  164. X
  165. X#ifdef __STDC__
  166. Xint bt_malloc_verify(void)
  167. X#else
  168. Xint bt_malloc_verify()
  169. X#endif
  170. X{
  171. X    int    retval;
  172. X    int    once;
  173. X    int    i;
  174. X
  175. X    retval = 1;
  176. X    once = 0;
  177. X
  178. X#ifdef DEBUG
  179. X    for (i = 0; i < btheap.allocSeq; i++)
  180. X    {
  181. X        if (btheap.blks[i].freeNext == -2)
  182. X        {
  183. X            if (!once)
  184. X            {
  185. X                once = 1;
  186. X                printf("The following blocks are allocated:\n");
  187. X            }
  188. X            printf("%x\n",btheap.blks[i].blk);
  189. X        }
  190. X    }
  191. X    fflush(stdout);
  192. X#endif
  193. X
  194. X#ifdef sun
  195. X    retval = malloc_verify();
  196. X#endif
  197. X
  198. X    return retval;
  199. X}
  200. X
  201. X/***** End of file *****/
  202. X
  203. END_OF_src/btree/btmalloc.c
  204. if test 2613 -ne `wc -c <src/btree/btmalloc.c`; then
  205.     echo shar: \"src/btree/btmalloc.c\" unpacked with wrong size!
  206. fi
  207. # end of overwriting check
  208. fi
  209. if test -f src/btree/btsearch.c -a "${1}" != "-c" ; then 
  210.   echo shar: Will not over-write existing file \"src/btree/btsearch.c\"
  211. else
  212. echo shar: Extracting \"src/btree/btsearch.c\" \(2365 characters\)
  213. sed "s/^X//" >src/btree/btsearch.c <<'END_OF_src/btree/btsearch.c'
  214. X/********************************************************************
  215. X * btsearch -- This file contains functions needed to locate an
  216. X *             item in an in-memory B-tree.
  217. X *
  218. X * This file is part of a suite of programs called Software Chipset.
  219. X * The source code for Software Chipset has been released into the
  220. X * public domain by its author, Paul Sander.
  221. X *
  222. X ********************************************************************/
  223. X
  224. X#include <stdio.h>
  225. X#include "btpriv.h"
  226. X
  227. X/***********************************************************************
  228. X *
  229. X * bt_locate -- This function performs a recursive-descent search of
  230. X *              a sub-tree for a key.  The key is returned if found,
  231. X *              or NULL otherwise.
  232. X *
  233. X ***********************************************************************/
  234. X
  235. X#ifdef __STDC__
  236. Xstatic void *bt_locate(BTREE tree, BTNODE *node, void *target, int (*comp)(),
  237. X                       void **data)
  238. X#else
  239. Xstatic void *bt_locate(tree,node,target,comp,data)
  240. XBTREE    tree;
  241. XBTNODE    *node;
  242. Xvoid    *target;
  243. Xint    (*comp)();
  244. Xvoid    **data;
  245. X#endif
  246. X{
  247. X    int    res;
  248. X    int    i;
  249. X    int    eq;
  250. X
  251. X    COVER("btsearch.c",1);
  252. X    i = bt_searchNode(node,target,comp,&eq);
  253. X    node->currKey = i;
  254. X    if (eq)
  255. X    {
  256. X        COVER("btsearch.c",2);
  257. X        tree->currNode = node;
  258. X        tree->nextOk = 1;
  259. X        if (data != NULL)
  260. X        {
  261. X            COVER("btsearch.c",3);
  262. X            *data = node->data[i];
  263. X        }
  264. X        COVER("btsearch.c",4);
  265. X        return node->keys[i];
  266. X    }
  267. X    else if (node->children == NULL)
  268. X    {
  269. X        COVER("btsearch.c",5);
  270. X        tree->currNode = node;
  271. X        tree->nextOk = 0;
  272. X        return NULL;
  273. X    }
  274. X    else
  275. X    {
  276. X        COVER("btsearch.c",6);
  277. X        return bt_locate(tree,node->children[i],target,comp,data);
  278. X    }
  279. X}
  280. X
  281. X/***********************************************************************
  282. X *
  283. X * bt_search -- This function searches a tree for a specified key.  The
  284. X *              key is returned if found, or NULL if not.
  285. X *
  286. X ***********************************************************************/
  287. X
  288. X#ifdef __STDC__
  289. Xvoid *bt_search(void *ptree, void *target, void **data)
  290. X#else
  291. Xvoid *bt_search(ptree,target,data)
  292. Xvoid    *ptree;
  293. Xvoid    *target;
  294. Xvoid    **data;
  295. X#endif
  296. X{
  297. X    BTREE    tree;
  298. X
  299. X    tree = (BTREE) ptree;
  300. X    if (tree == NULL)
  301. X    {
  302. X        COVER("btsearch.c",7);
  303. X        return NULL;
  304. X    }
  305. X    if (target == NULL)
  306. X    {
  307. X        COVER("btsearch.c",8);
  308. X        return NULL;
  309. X    }
  310. X    COVER("btsearch.c",9);
  311. X    return bt_locate(tree,tree->root,target,tree->comp,data);
  312. X}
  313. X
  314. X/*********** End of file ************/
  315. X
  316. END_OF_src/btree/btsearch.c
  317. if test 2365 -ne `wc -c <src/btree/btsearch.c`; then
  318.     echo shar: \"src/btree/btsearch.c\" unpacked with wrong size!
  319. fi
  320. # end of overwriting check
  321. fi
  322. if test -f src/list/README -a "${1}" != "-c" ; then 
  323.   echo shar: Will not over-write existing file \"src/list/README\"
  324. else
  325. echo shar: Extracting \"src/list/README\" \(2643 characters\)
  326. sed "s/^X//" >src/list/README <<'END_OF_src/list/README'
  327. XThis directory contains source code to an doubly-linked list implementation.
  328. XIt can be used as a unique-key index (i.e. no two keys can be the same, and
  329. Xthey are kept sorted), or as a stack, queue, or dequeue.
  330. X
  331. XThis implementation has been placed in the public domain by its author,
  332. XPaul Sander, to be used as you wish.  However, if you add neat new features,
  333. XI'd appreciate having a copy sent to me at paul@sander.cupertino.ca.us .
  334. X
  335. XYou are strongly urged to review the Makefile.  It contains a lot of stuff
  336. Xthat is specific to my system, but configuring it to your needs should be
  337. Xstraightforward.  The most important places to look are at the macros near
  338. Xthe beginning of the file, and in the "installDocs" and "installLib" recipes.
  339. X
  340. XAlso review the dldump.c file.  It contains additional debugging code that
  341. Xdisplay the contents of a list to the standard output device.  This file
  342. Xcontains platform-specific code to format pointers.
  343. X
  344. XTo build the library on a Unix system, invoke "make".  VMS users will need
  345. Xto translate the Makefile into a DESCRIP.MMS file.  Others will need to do
  346. Xsomething different, of course.  The code should compile under either an
  347. XANSI or a K&R compiler.  If your implementation predates the "void" type,
  348. Xyou should add a typedef or macro to the .h files to alias the "char" type
  349. Xas "void".
  350. X
  351. XOnline documentation has been provided.  It consists of source code using
  352. Xthe Unix "man" macros, and also ASCII plaintext and PostScript versions
  353. Xproduced by nroff and troff, respectively.  The plaintext and PostScript
  354. Xdocuments can be rebuilt by invoking the "make docs" command.
  355. X
  356. XInstallation should be done by invoking other tools provided with the
  357. XSoftware ChipSet that package the components up and install them in one
  358. Xpass.  For details about using these tools, please see the ../../README
  359. Xfile.
  360. X
  361. XThere is a test program that performs a very rigorous test of the list
  362. Ximplementation.  The program is built by invoking "make test".  It is
  363. Xalso built as the result of "make all" or simply "make".  To run the test,
  364. Xinvoke the command "./test | tail -1" should echo "TEST PASSED" to the
  365. Xcontrolling tty.
  366. X
  367. XAn attempt to do coverage analysis was done by hand.  To view the coverage,
  368. Xcompile the library while #define'ing the COVERAGE macro and run the test
  369. Xprogram.  The test program's output will then contain data reflecting each
  370. Xdecision point in the library.  Portions of the code not stimulated by the
  371. Xtest program are noted in comments in the source code, or fall along paths
  372. Xwhere malloc fails (which is difficult to induce in a controlled way).  Each
  373. Xof these paths has been reviewed and appears to be correct.
  374. X
  375. END_OF_src/list/README
  376. if test 2643 -ne `wc -c <src/list/README`; then
  377.     echo shar: \"src/list/README\" unpacked with wrong size!
  378. fi
  379. # end of overwriting check
  380. fi
  381. if test -f src/list/dldelete.c -a "${1}" != "-c" ; then 
  382.   echo shar: Will not over-write existing file \"src/list/dldelete.c\"
  383. else
  384. echo shar: Extracting \"src/list/dldelete.c\" \(2017 characters\)
  385. sed "s/^X//" >src/list/dldelete.c <<'END_OF_src/list/dldelete.c'
  386. X/*******************************************************************
  387. X *
  388. X * dldelete.c -- This file contains functions to delete from a
  389. X *               sorted list.
  390. X *
  391. X * This file is part of a suite of programs called Software Chipset.
  392. X * The source code for Software Chipset has been released into the
  393. X * public domain by its author, Paul Sander.
  394. X *
  395. X *******************************************************************/
  396. X
  397. X#include <stdio.h>
  398. X#include "dlpriv.h"
  399. X
  400. X/*******************************************************************
  401. X *
  402. X * dll_delete -- This function deletes a node by key from a sorted
  403. X *               list.
  404. X *
  405. X *******************************************************************/
  406. X
  407. X#ifdef __STDC__
  408. Xvoid *dll_delete(DL_LIST plist, void *key, void **data)
  409. X#else
  410. Xvoid *dll_delete(plist,key,data)
  411. XDL_LIST    plist;
  412. Xvoid    *key;
  413. Xvoid    **data;
  414. X#endif
  415. X{
  416. X    LIST    *list;
  417. X    NODE    *this;
  418. X    int    res;
  419. X    void    *retval;
  420. X
  421. X    COVER("dldelete.c",1);
  422. X
  423. X    /* Validate list parameter */
  424. X    if (plist == NULL)
  425. X    {
  426. X        COVER("dldelete.c",2);
  427. X        return NULL;
  428. X    }
  429. X    list = (LIST*) plist;
  430. X    if (list->last == NULL)
  431. X    {
  432. X        COVER("dldelete.c",3);
  433. X        return NULL;
  434. X    }
  435. X    if (list->comp == NULL)
  436. X    {
  437. X        COVER("dldelete.c",4);
  438. X        return NULL;
  439. X    }
  440. X
  441. X    /* Perform sequential search for node */
  442. X    COVER("dldelete.c",5);
  443. X    res = dll_locate(list,key,&this);
  444. X
  445. X    /* Unlink and free node if found */
  446. X    if (res == 0)
  447. X    {
  448. X        COVER("dldelete.c",6);
  449. X        retval = this->key;
  450. X        if (data != NULL)
  451. X        {
  452. X            COVER("dldelete.c",7);
  453. X            *data = this->data;
  454. X        }
  455. X        COVER("dldelete.c",8);
  456. X        dll_unlink(this);
  457. X
  458. X        /* Special consideration if this is the tail of the list */
  459. X        if (this == list->last)
  460. X        {
  461. X            if (this->prev != this)
  462. X            {
  463. X                COVER("dldelete.c",9);
  464. X                list->last = this->prev;
  465. X            }
  466. X            else
  467. X            {
  468. X                COVER("dldelete.c",10);
  469. X                list->last = NULL;
  470. X            }
  471. X        }
  472. X        COVER("dldelete.c",11);
  473. X        dll_freeNode(this);
  474. X        list->size -= 1;
  475. X        dll_touch(list);
  476. X    }
  477. X    else
  478. X    {
  479. X        COVER("dldelete.c",12);
  480. X        retval = NULL;
  481. X    }
  482. X    COVER("dldelete.c",13);
  483. X    return retval;
  484. X}
  485. X
  486. X/************** End of file **************/
  487. X
  488. END_OF_src/list/dldelete.c
  489. if test 2017 -ne `wc -c <src/list/dldelete.c`; then
  490.     echo shar: \"src/list/dldelete.c\" unpacked with wrong size!
  491. fi
  492. # end of overwriting check
  493. fi
  494. if test -f src/list/dldelrank.c -a "${1}" != "-c" ; then 
  495.   echo shar: Will not over-write existing file \"src/list/dldelrank.c\"
  496. else
  497. echo shar: Extracting \"src/list/dldelrank.c\" \(2117 characters\)
  498. sed "s/^X//" >src/list/dldelrank.c <<'END_OF_src/list/dldelrank.c'
  499. X/*******************************************************************
  500. X *
  501. X * dldelrank.c -- This file contains functions to delete from a
  502. X *                list, given an item's rank.
  503. X *
  504. X * This file is part of a suite of programs called Software Chipset.
  505. X * The source code for Software Chipset has been released into the
  506. X * public domain by its author, Paul Sander.
  507. X *
  508. X *******************************************************************/
  509. X
  510. X#include <stdio.h>
  511. X#include "dlpriv.h"
  512. X
  513. X/*******************************************************************
  514. X *
  515. X * dll_delRank -- This function deletes a node by rank from a list.
  516. X *
  517. X *******************************************************************/
  518. X
  519. X#ifdef __STDC__
  520. Xvoid *dll_delRank(DL_LIST plist, int rank, void **data)
  521. X#else
  522. Xvoid *dll_delRank(plist,rank,data)
  523. XDL_LIST    plist;
  524. Xint    rank;
  525. Xvoid    **data;
  526. X#endif
  527. X{
  528. X    LIST    *list;
  529. X    NODE    *this;
  530. X    int    res;
  531. X    void    *retval;
  532. X
  533. X    COVER("dldelrank.c",1);
  534. X
  535. X    /* Validate list parameter */
  536. X    if (plist == NULL)
  537. X    {
  538. X        COVER("dldelrank.c",2);
  539. X        return NULL;
  540. X    }
  541. X    list = (LIST*) plist;
  542. X    if (list->last == NULL)
  543. X    {
  544. X        COVER("dldelrank.c",3);
  545. X        return NULL;
  546. X    }
  547. X    if (rank < 0)
  548. X    {
  549. X        COVER("dldelrank.c",4);
  550. X        return NULL;
  551. X    }
  552. X    if (rank >= list->size)
  553. X    {
  554. X        COVER("dldelrank.c",5);
  555. X        return NULL;
  556. X    }
  557. X
  558. X    /* Find the node with the given rank */
  559. X    COVER("dldelrank.c",6);
  560. X    this = dll_locRank(list,rank);
  561. X
  562. X    /* Unlink and free node if found */
  563. X    if (this != NULL)
  564. X    {
  565. X        COVER("dldelrank.c",7);
  566. X        retval = this->key;
  567. X        if (data != NULL)
  568. X        {
  569. X            COVER("dldelrank.c",8);
  570. X            *data = this->data;
  571. X        }
  572. X        dll_unlink(this);
  573. X
  574. X        /* Special consideration if this is the tail of the list */
  575. X        if (this == list->last)
  576. X        {
  577. X            if (this->prev != this)
  578. X            {
  579. X                COVER("dldelrank.c",9);
  580. X                list->last = this->prev;
  581. X            }
  582. X            else
  583. X            {
  584. X                COVER("dldelrank.c",10);
  585. X                list->last = NULL;
  586. X            }
  587. X        }
  588. X        COVER("dldelrank.c",11);
  589. X        dll_freeNode(this);
  590. X        list->size -= 1;
  591. X        dll_touch(list);
  592. X    }
  593. X    else
  594. X    {
  595. X        /*
  596. X         * Earlier tests on rank prevent this code from being
  597. X         * reached.
  598. X         */
  599. X        COVER("dldelrank.c",12);
  600. X        retval = NULL;
  601. X    }
  602. X    return retval;
  603. X}
  604. X
  605. X/************** End of file **************/
  606. X
  607. END_OF_src/list/dldelrank.c
  608. if test 2117 -ne `wc -c <src/list/dldelrank.c`; then
  609.     echo shar: \"src/list/dldelrank.c\" unpacked with wrong size!
  610. fi
  611. # end of overwriting check
  612. fi
  613. if test -f src/list/dldestroy.c -a "${1}" != "-c" ; then 
  614.   echo shar: Will not over-write existing file \"src/list/dldestroy.c\"
  615. else
  616. echo shar: Extracting \"src/list/dldestroy.c\" \(2627 characters\)
  617. sed "s/^X//" >src/list/dldestroy.c <<'END_OF_src/list/dldestroy.c'
  618. X/************************************************************************
  619. X *
  620. X * dldestroy.c -- This file contains routines needed for destroying
  621. X *                doubly-linked lists.
  622. X *
  623. X * This file is part of a suite of programs called Software Chipset.
  624. X * The source code for Software Chipset has been released into the
  625. X * public domain by its author, Paul Sander.
  626. X *
  627. X ************************************************************************/
  628. X
  629. X#include <stdio.h>
  630. X#include "dlpriv.h"
  631. X
  632. X/************************************************************************
  633. X *
  634. X * dll_destroy -- This function destroys a doubly-linked list.  It is
  635. X *                passed the doomed list, along with pointers to functions
  636. X *                that destroy the keys and client-defined data stored in
  637. X *                each node in the list.  An additional parameter is
  638. X *                passed along to the callback functions without modification.
  639. X *                The freeData function is always called before the freeKey
  640. X *                function.  Either or both of these may be NULL, in which
  641. X *                no action is taken for that item.  The interfaces for
  642. X *                freeKey and freeData are the same, which is the following:
  643. X *
  644. X *                void freeMe(keyOrData,info)
  645. X *                void *keyOrData;
  646. X *                void *info;
  647. X *
  648. X ************************************************************************/
  649. X
  650. X#ifdef __STDC__
  651. Xvoid dll_destroy(DL_LIST plist, void (*freeKey)(void*,void*),
  652. X                 void(*freeData)(void*,void*), void *info)
  653. X#else
  654. Xvoid dll_destroy(plist,freeKey,freeData,info)
  655. XDL_LIST    plist;
  656. Xvoid    (*freeKey)();
  657. Xvoid    (*freeData)();
  658. Xvoid    *info;
  659. X#endif
  660. X{
  661. X    LIST    *list;
  662. X    NODE    *this;
  663. X    NODE    *next;
  664. X
  665. X    COVER("dldestroy.c",1);
  666. X    list = (LIST*) plist;
  667. X    if (list != NULL)
  668. X    {
  669. X        COVER("dldestroy.c",2);
  670. X        if (list->last != NULL)
  671. X        {
  672. X            COVER("dldestroy.c",3);
  673. X            this = list->last->next;
  674. X            while (this != list->last)
  675. X            {
  676. X                COVER("dldestroy.c",4);
  677. X                next = this->next;
  678. X                if (freeData != NULL)
  679. X                {
  680. X                    COVER("dldestroy.c",5);
  681. X                    (*freeData)(this->data,info);
  682. X                }
  683. X                if (freeKey != NULL)
  684. X                {
  685. X                    COVER("dldestroy.c",6);
  686. X                    (*freeKey)(this->key,info);
  687. X                }
  688. X                COVER("dldestroy.c",7);
  689. X                free(this);
  690. X                this = next;
  691. X            }
  692. X            if (freeData != NULL)
  693. X            {
  694. X                COVER("dldestroy.c",8);
  695. X                (*freeData)(this->data,info);
  696. X            }
  697. X            if (freeKey != NULL)
  698. X            {
  699. X                COVER("dldestroy.c",9);
  700. X                (*freeKey)(this->key,info);
  701. X            }
  702. X            COVER("dldestroy.c",10);
  703. X            free(this);
  704. X        }
  705. X        COVER("dldestroy.c",11);
  706. X        free(list);
  707. X    }
  708. X    COVER("dldestroy.c",12);
  709. X    return;
  710. X}
  711. X
  712. X/************* End of file **************/
  713. X
  714. END_OF_src/list/dldestroy.c
  715. if test 2627 -ne `wc -c <src/list/dldestroy.c`; then
  716.     echo shar: \"src/list/dldestroy.c\" unpacked with wrong size!
  717. fi
  718. # end of overwriting check
  719. fi
  720. if test -f src/list/dlinsert.c -a "${1}" != "-c" ; then 
  721.   echo shar: Will not over-write existing file \"src/list/dlinsert.c\"
  722. else
  723. echo shar: Extracting \"src/list/dlinsert.c\" \(2606 characters\)
  724. sed "s/^X//" >src/list/dlinsert.c <<'END_OF_src/list/dlinsert.c'
  725. X/*****************************************************************
  726. X *
  727. X * dlinsert.c -- This file contains functions needed to perform
  728. X *               insertion into sorted doubly-linked lists.
  729. X *
  730. X * This file is part of a suite of programs called Software Chipset.
  731. X * The source code for Software Chipset has been released into the
  732. X * public domain by its author, Paul Sander.
  733. X *
  734. X *****************************************************************/
  735. X
  736. X#include <stdio.h>
  737. X#include "dlpriv.h"
  738. X
  739. X/*****************************************************************
  740. X *
  741. X * dll_insert -- This function takes as its parameters a doubly-
  742. X *               linked list, a key, and a pointer to arbitrary
  743. X *               data.  It performs a linear search of the list
  744. X *               and inserts a new node in the appropriate place
  745. X *               if the key is not found.  Returns values are:
  746. X *               1 for success, 0 for failure, -1 for duplicate
  747. X *               key.
  748. X *
  749. X *****************************************************************/
  750. X
  751. X#ifdef __STDC__
  752. Xint dll_insert(DL_LIST plist, void *key, void *data)
  753. X#else
  754. Xint dll_insert(plist,key,data)
  755. XDL_LIST    plist;
  756. Xvoid    *key;
  757. Xvoid    *data;
  758. X#endif
  759. X{
  760. X    LIST    *list;
  761. X    NODE    *this;
  762. X    NODE    *next;
  763. X    int    res;
  764. X
  765. X    COVER("dlinsert.c",1);
  766. X
  767. X    /* Initialization */
  768. X    list = (LIST*) plist;
  769. X
  770. X    /* Validate list parameter */
  771. X    if (list == NULL)
  772. X    {
  773. X        COVER("dlinsert.c",2);
  774. X        return 0;
  775. X    }
  776. X    if (list->comp == NULL)
  777. X    {
  778. X        COVER("dlinsert.c",3);
  779. X        return 0;
  780. X    }
  781. X
  782. X    /* Validate key parameter */
  783. X    if (key == NULL)
  784. X    {
  785. X        COVER("dlinsert.c",4);
  786. X        return 0;
  787. X    }
  788. X
  789. X    /* Perform insertion */
  790. X    COVER("dlinsert.c",5);
  791. X    if (list->last == NULL)
  792. X    {
  793. X        /* Insert first node into empty list */
  794. X        COVER("dlinsert.c",6);
  795. X        this = dll_newNode(key,data);
  796. X        if (this == NULL) return 0;
  797. X        dll_store(this,this);
  798. X        list->last = this;
  799. X    }
  800. X    else
  801. X    {
  802. X        /* Perform sequential search of list for given key */
  803. X        COVER("dlinsert.c",7);
  804. X        res = dll_locate(list,key,&this);
  805. X
  806. X        /* Test for duplicate */
  807. X        if (res == 0)
  808. X        {
  809. X            COVER("dlinsert.c",8);
  810. X            return -1;
  811. X        }
  812. X
  813. X        /* Create new node for new key */
  814. X        next = dll_newNode(key,data);
  815. X        if (next == NULL)
  816. X        {
  817. X            COVER("dlinsert.c",9);
  818. X            return 0;
  819. X        }
  820. X
  821. X        /*
  822. X         * Insert before "this" node if new key is less than "this",
  823. X         * else insert after end of list and update list structure.
  824. X         */
  825. X        if (res > 0)
  826. X        {
  827. X            COVER("dlinsert.c",10);
  828. X            dll_store(this->prev,next);
  829. X        }
  830. X        else
  831. X        {
  832. X            COVER("dlinsert.c",11);
  833. X            dll_store(list->last,next);
  834. X            list->last = next;
  835. X        }
  836. X    }
  837. X    COVER("dlinsert.c",12);
  838. X    list->size += 1;
  839. X    dll_touch(list);
  840. X    return 1;
  841. X}
  842. X
  843. X/*********** End of file ***********/
  844. X
  845. END_OF_src/list/dlinsert.c
  846. if test 2606 -ne `wc -c <src/list/dlinsert.c`; then
  847.     echo shar: \"src/list/dlinsert.c\" unpacked with wrong size!
  848. fi
  849. # end of overwriting check
  850. fi
  851. if test -f src/list/dlinsutl.c -a "${1}" != "-c" ; then 
  852.   echo shar: Will not over-write existing file \"src/list/dlinsutl.c\"
  853. else
  854. echo shar: Extracting \"src/list/dlinsutl.c\" \(1963 characters\)
  855. sed "s/^X//" >src/list/dlinsutl.c <<'END_OF_src/list/dlinsutl.c'
  856. X/*****************************************************************
  857. X *
  858. X * dlinsutl.c -- This file contains utility functions used in
  859. X *               inserting nodes into a list.
  860. X *
  861. X * This file is part of a suite of programs called Software Chipset.
  862. X * The source code for Software Chipset has been released into the
  863. X * public domain by its author, Paul Sander.
  864. X *
  865. X *****************************************************************/
  866. X
  867. X#include <stdio.h>
  868. X#include "dlpriv.h"
  869. X
  870. X
  871. X/*****************************************************************
  872. X *
  873. X * dll_newNode -- This function creates and initializes a new node
  874. X *                for a linked list.  The function's parameters
  875. X *                are a pointer to a client-defined key and
  876. X *                a pointer to arbitrary data.  The return value
  877. X *                is a pointer to the new node, or NULL in case of
  878. X *                error.
  879. X *
  880. X *****************************************************************/
  881. X
  882. X#ifdef __STDC__
  883. XNODE *dll_newNode(void *key, void *data)
  884. X#else
  885. XNODE *dll_newNode(key,data)
  886. Xvoid    *key;
  887. Xvoid    *data;
  888. X#endif
  889. X{
  890. X    NODE    *retval;
  891. X
  892. X    COVER("dlinsutl.c",1);
  893. X    retval = (NODE*) malloc(sizeof(NODE));
  894. X    if (retval != NULL)
  895. X    {
  896. X        COVER("dlinsutl.c",2);
  897. X        retval->key = key;
  898. X        retval->data = data;
  899. X        retval->next = NULL;
  900. X        retval->prev = NULL;
  901. X    }
  902. X    COVER("dlinsutl.c",3);
  903. X    return retval;
  904. X}
  905. X
  906. X/*****************************************************************
  907. X *
  908. X * dll_store -- This function inserts node2 into the linked list
  909. X *              after node1.  Node2 is assumed not to be linked
  910. X *              into the list.
  911. X *
  912. X *****************************************************************/
  913. X
  914. X#ifdef __STDC__
  915. Xvoid dll_store(NODE *node1, NODE *node2)
  916. X#else
  917. Xvoid dll_store(node1,node2)
  918. XNODE    *node1;
  919. XNODE    *node2;
  920. X#endif
  921. X{
  922. X    COVER("dlinsutl.c",4);
  923. X    node2->prev = node1;
  924. X    node2->next = node1->next;
  925. X    node1->next = node2;
  926. X    node2->next->prev = node2;
  927. X    return;
  928. X}
  929. X
  930. X/************* End of file **************/
  931. X
  932. END_OF_src/list/dlinsutl.c
  933. if test 1963 -ne `wc -c <src/list/dlinsutl.c`; then
  934.     echo shar: \"src/list/dlinsutl.c\" unpacked with wrong size!
  935. fi
  936. # end of overwriting check
  937. fi
  938. if test -f src/list/dlnext.c -a "${1}" != "-c" ; then 
  939.   echo shar: Will not over-write existing file \"src/list/dlnext.c\"
  940. else
  941. echo shar: Extracting \"src/list/dlnext.c\" \(2145 characters\)
  942. sed "s/^X//" >src/list/dlnext.c <<'END_OF_src/list/dlnext.c'
  943. X/***********************************************************************
  944. X *
  945. X * dlnext.c -- This file contains the dll_next function.
  946. X *
  947. X * This file is part of a suite of programs called Software Chipset.
  948. X * The source code for Software Chipset has been released into the
  949. X * public domain by its author, Paul Sander.
  950. X *
  951. X ***********************************************************************/
  952. X
  953. X#include <stdio.h>
  954. X#include "dlpriv.h"
  955. X
  956. X/***********************************************************************
  957. X *
  958. X * dll_next -- This function returns the next key stored in the list.
  959. X *             If the list is sorted, this key is the next highest in
  960. X *             the lexical order of keys stored in the tree.
  961. X *
  962. X ***********************************************************************/
  963. X
  964. X#ifdef __STDC__
  965. Xvoid *dll_next(DL_LIST plist, void **data)
  966. X#else
  967. Xvoid *dll_next(plist,data)
  968. XDL_LIST    plist;
  969. Xvoid    **data;
  970. X#endif
  971. X{
  972. X    LIST    *list;
  973. X
  974. X    COVER("dlnext.c",1);
  975. X
  976. X    /* Validate parameters */
  977. X    list = (LIST*) plist;
  978. X    if (list == NULL)
  979. X    {
  980. X        COVER("dlnext.c",2);
  981. X        return NULL;
  982. X    }
  983. X    if (list->last == NULL)
  984. X    {
  985. X        COVER("dlnext.c",3);
  986. X        return NULL;
  987. X    }
  988. X
  989. X    /* Require a search, first, or next */
  990. X    if (list->changed)
  991. X    {
  992. X        COVER("dlnext.c",4);
  993. X        return NULL;
  994. X    }
  995. X
  996. X    /* If no search was done, return first item in list */
  997. X    if ((list->current == NULL) && (! list->nextOk))
  998. X    {
  999. X        /*
  1000. X         * This is never reached.  This condition is met only after
  1001. X         * the linked list has been changed, in which case the test
  1002. X         * above causes this function to fail.
  1003. X         */
  1004. X        COVER("dlnext.c",5);
  1005. X        return dll_first(plist,data);
  1006. X    }
  1007. X
  1008. X    /* Indicate error if list is overrun */
  1009. X    if (((list->current == list->last) && (! list->nextOk)) ||
  1010. X        (list->current == NULL))
  1011. X    {
  1012. X        COVER("dlnext.c",6);
  1013. X        list->current = NULL;
  1014. X        list->nextOk = 1;
  1015. X        return NULL;
  1016. X    }
  1017. X    COVER("dlnext.c",7);
  1018. X
  1019. X    /* Return next item in list */
  1020. X    if (! list->nextOk)
  1021. X    {
  1022. X        COVER("dlnext.c",8);
  1023. X        list->current = list->current->next;
  1024. X    }
  1025. X    COVER("dlnext.c",9);
  1026. X    list->nextOk = 0;
  1027. X    if (data != NULL)
  1028. X    {
  1029. X        COVER("dlnext.c",10);
  1030. X        *data = list->current->data;
  1031. X    }
  1032. X    return list->current->key;
  1033. X}
  1034. X
  1035. X/************ End of file ************/
  1036. X
  1037. END_OF_src/list/dlnext.c
  1038. if test 2145 -ne `wc -c <src/list/dlnext.c`; then
  1039.     echo shar: \"src/list/dlnext.c\" unpacked with wrong size!
  1040. fi
  1041. # end of overwriting check
  1042. fi
  1043. if test -f src/list/dlsearch.c -a "${1}" != "-c" ; then 
  1044.   echo shar: Will not over-write existing file \"src/list/dlsearch.c\"
  1045. else
  1046. echo shar: Extracting \"src/list/dlsearch.c\" \(1912 characters\)
  1047. sed "s/^X//" >src/list/dlsearch.c <<'END_OF_src/list/dlsearch.c'
  1048. X/******************************************************************
  1049. X *
  1050. X * dlsearch.c -- This file contains functions used for searching
  1051. X *               sorted lists for specified keys.
  1052. X *
  1053. X * This file is part of a suite of programs called Software Chipset.
  1054. X * The source code for Software Chipset has been released into the
  1055. X * public domain by its author, Paul Sander.
  1056. X *
  1057. X ******************************************************************/
  1058. X
  1059. X#include <stdio.h>
  1060. X#include "dlpriv.h"
  1061. X
  1062. X/******************************************************************
  1063. X *
  1064. X * dll_search -- This function searches a sorted list for a specified
  1065. X *               key.
  1066. X *
  1067. X ******************************************************************/
  1068. X
  1069. X#ifdef __STDC__
  1070. Xvoid *dll_search(DL_LIST plist, void *target, void **data)
  1071. X#else
  1072. Xvoid *dll_search(plist,target,data)
  1073. XDL_LIST    plist;
  1074. Xvoid    *target;
  1075. Xvoid    **data;
  1076. X#endif
  1077. X{
  1078. X    LIST    *list;
  1079. X    NODE    *node;
  1080. X    int    res;
  1081. X    void    *retval;
  1082. X
  1083. X    COVER("dlsearch.c",1);
  1084. X
  1085. X    /* Validate parameters */
  1086. X    if (plist == NULL)
  1087. X    {
  1088. X        COVER("dlsearch.c",2);
  1089. X        return NULL;
  1090. X    }
  1091. X    list = (LIST*) plist;
  1092. X    if (list->last == NULL)
  1093. X    {
  1094. X        COVER("dlsearch.c",3);
  1095. X        return NULL;
  1096. X    }
  1097. X    if (list->comp == NULL)
  1098. X    {
  1099. X        COVER("dlsearch.c",4);
  1100. X        return NULL;
  1101. X    }
  1102. X
  1103. X    /* Perform sequential search for target */
  1104. X    res = dll_locate(list,target,&node);
  1105. X    if (res < 0)
  1106. X    {
  1107. X        /* Target is higher than highest key, overran list */
  1108. X        COVER("dlsearch.c",5);
  1109. X        list->current = NULL;
  1110. X        list->nextOk = 1;
  1111. X        retval = NULL;
  1112. X    }
  1113. X    else if (res > 0)
  1114. X    {
  1115. X        /* Target not found, but has a successor */
  1116. X        COVER("dlsearch.c",6);
  1117. X        list->current = node;
  1118. X        list->nextOk = 1;
  1119. X        retval = NULL;
  1120. X    }
  1121. X    else
  1122. X    {
  1123. X        /* Target was found */
  1124. X        COVER("dlsearch.c",7);
  1125. X        list->current = node;
  1126. X        list->nextOk = 0;
  1127. X        if (data != NULL)
  1128. X        {
  1129. X            COVER("dlsearch.c",8);
  1130. X            *data = node->data;
  1131. X        }
  1132. X        retval = target;
  1133. X    }
  1134. X    list->changed = 0;
  1135. X    return retval;
  1136. X}
  1137. X
  1138. X/*************** End of file **************/
  1139. X
  1140. END_OF_src/list/dlsearch.c
  1141. if test 1912 -ne `wc -c <src/list/dlsearch.c`; then
  1142.     echo shar: \"src/list/dlsearch.c\" unpacked with wrong size!
  1143. fi
  1144. # end of overwriting check
  1145. fi
  1146. if test -f src/list/dltrav.c -a "${1}" != "-c" ; then 
  1147.   echo shar: Will not over-write existing file \"src/list/dltrav.c\"
  1148. else
  1149. echo shar: Extracting \"src/list/dltrav.c\" \(2110 characters\)
  1150. sed "s/^X//" >src/list/dltrav.c <<'END_OF_src/list/dltrav.c'
  1151. X/******************************************************************
  1152. X *
  1153. X * dltrav.c -- This file contains functions used for traversing
  1154. X *             linked lists.
  1155. X *
  1156. X * This file is part of a suite of programs called Software Chipset.
  1157. X * The source code for Software Chipset has been released into the
  1158. X * public domain by its author, Paul Sander.
  1159. X *
  1160. X ******************************************************************/
  1161. X
  1162. X#include <stdio.h>
  1163. X#include "dlpriv.h"
  1164. X
  1165. X/******************************************************************
  1166. X *
  1167. X * dll_traverse -- This function traverses a linked list, calling
  1168. X *                 a client-provided visitation function once for
  1169. X *                 each node stored there.  If the list is sorted,
  1170. X *                 the nodes are visited in the lexical order of
  1171. X *                 the keys.  If the list is unsorted, the nodes
  1172. X *                 are visited in the order in which dll_first and
  1173. X *                 dll_next visits them.
  1174. X *
  1175. X *                 The interface for the visitation function follows:
  1176. X *
  1177. X *            void fn(key,parms,data)
  1178. X *            void    *key;
  1179. X *            void    *parms;
  1180. X *            void    *data;
  1181. X *
  1182. X *                 where "key" is the key stored in the node, "parms"
  1183. X *                 is an arbitrary client-specified pointer passed
  1184. X *                 to dll_traverse, and "data" is the data pointer
  1185. X *                 stored in the node.
  1186. X *
  1187. X ******************************************************************/
  1188. X
  1189. X#ifdef __STDC__
  1190. Xvoid    dll_traverse(DL_LIST plist, void (*fn)(void*,void*,void*), void *parms)
  1191. X#else
  1192. Xvoid    dll_traverse(plist,fn,parms)
  1193. XDL_LIST    plist;
  1194. Xvoid    (*fn)();
  1195. Xvoid    *parms;
  1196. X#endif
  1197. X{
  1198. X    LIST    *list;
  1199. X    NODE    *node;
  1200. X
  1201. X    COVER("dltrav.c",1);
  1202. X    list = (LIST*) plist;
  1203. X    if (list == NULL)
  1204. X    {
  1205. X        COVER("dltrav.c",2);
  1206. X        return;
  1207. X    }
  1208. X    if (list->last == NULL)
  1209. X    {
  1210. X        COVER("dltrav.c",3);
  1211. X        return;
  1212. X    }
  1213. X    if (fn == NULL)
  1214. X    {
  1215. X        COVER("dltrav.c",4);
  1216. X        return;
  1217. X    }
  1218. X
  1219. X    node = list->last->next;
  1220. X    do
  1221. X    {
  1222. X        COVER("dltrav.c",5);
  1223. X        (*fn)(node->key,parms,node->data);
  1224. X        node = node->next;
  1225. X    } while (node != list->last->next);
  1226. X    COVER("dltrav.c",6);
  1227. X    return;
  1228. X}
  1229. X
  1230. X/************** End of file **************/
  1231. X
  1232. END_OF_src/list/dltrav.c
  1233. if test 2110 -ne `wc -c <src/list/dltrav.c`; then
  1234.     echo shar: \"src/list/dltrav.c\" unpacked with wrong size!
  1235. fi
  1236. # end of overwriting check
  1237. fi
  1238. echo shar: End of archive 3 \(of 10\).
  1239. cp /dev/null ark3isdone
  1240. MISSING=""
  1241. for I in 1 2 3 4 5 6 7 8 9 10 ; do
  1242.     if test ! -f ark${I}isdone ; then
  1243.     MISSING="${MISSING} ${I}"
  1244.     fi
  1245. done
  1246. if test "${MISSING}" = "" ; then
  1247.     echo You have unpacked all 10 archives.
  1248.     echo "Now edit common.mk and do a 'make all'"
  1249.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1250. else
  1251.     echo You still need to unpack the following archives:
  1252.     echo "        " ${MISSING}
  1253. fi
  1254. ##  End of shell archive.
  1255. exit 0
  1256.  
  1257.