1 /*
2  * Copyright (c) 2000, 2001 Peter Bozarov.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *      This product includes software developed by Peter Bozarov.
16  * 4. The name of the author may not be used to endorse or promote products
17  *    derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
23  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 # include "../ds.h"
32 extern const char* nullstr(const char *);
33 extern const char* okfail(int);
34 
35 int
main(int argc,char ** argv)36 main(int argc,char **argv)
37 {
38     QUEUE 	q;
39     char *	s;
40     int		i;
41 
42     if (argc == 1)
43     {
44 	printf("Use: %s arguments\n",argv[0]);
45 	printf("    The arguments are placed in the queue and various test\n"
46 	       "    routines are performed on the queue.\n");
47 	return -1;
48     }
49     q = qMake();
50 
51     for (i = 0; i < argc; i++)
52     {
53 	qAdd(q,(void*)argv[i]);
54 	printf("current should be last: %s\n",
55 	       okfail(qLast(q) == qCurrent(q)));
56     }
57 
58     for (s = (char*)qFirst(q);s; s = (char*)qNext(q))
59 	printf("s = %s\n",s);
60     printf("===============\n");
61 
62     printf("qLast() returns %s\n",nullstr((char*)qLast(q)));
63     printf("qNext() returns %s (should be (null))\n",nullstr((char*)qNext(q)));
64     printf("Current is now %s\n",nullstr((char*)qCurrent(q)));
65     printf("qPrev() returns %s (should be same as last)\n",
66 	   nullstr((char*)qPrev(q)));
67     printf("Current is now %s\n",nullstr((char*)qCurrent(q)));
68     printf("qNext() returns %s\n",nullstr((char*)qNext(q)));
69     printf("qFirst() returns %s\n",nullstr((char*)qFirst(q)));
70     printf("qPrev() returns %s\n",nullstr((char*)qPrev(q)));
71     printf("Current is now %s\n",nullstr((char*)qCurrent(q)));
72     printf("qNext() returns %s\n",nullstr((char*)qFirst(q)));
73 
74     printf("\n\nUSE AS LINKED LIST:\n");
75     printf("Current is now %s\n",nullstr((char*)qCurrent(q)));
76     printf("qPrev() returns %s\n",nullstr((char*)qPrev(q)));
77     printf("qPrev() returns %s\n",nullstr((char*)qPrev(q)));
78     printf("qCurrent() returns %s\n",nullstr((char*)qCurrent(q)));
79     printf("qPrev() returns %s\n",nullstr((char*)qPrev(q)));
80     printf("etc....\n");
81     return 0;
82 }
83