1 | /*
|
---|
2 | ============================================================================
|
---|
3 | setwq.c -- word queue functions
|
---|
4 | Version 1 -- 1988-11-02 -- D.N. Lynx Crowe
|
---|
5 | ============================================================================
|
---|
6 | */
|
---|
7 |
|
---|
8 | #define WORDQHDR /* so wordq.h gets it right */
|
---|
9 |
|
---|
10 | #include "stddefs.h"
|
---|
11 | #include "wordq.h"
|
---|
12 |
|
---|
13 | /*
|
---|
14 | ============================================================================
|
---|
15 | setwq(qp, qadr, qsiz, hi, lo) -- setup a word queue
|
---|
16 |
|
---|
17 | Where:
|
---|
18 |
|
---|
19 | struct wordq *qp queue structure pointer
|
---|
20 | unsigned short *qadr queue buffer pointer
|
---|
21 | unsigned short qsiz maximum length of queue
|
---|
22 | unsigned short hi high water mark count
|
---|
23 | unsigned short lo low water mark count
|
---|
24 |
|
---|
25 | Return value:
|
---|
26 |
|
---|
27 | unsigned short qsiz size of queue
|
---|
28 | ============================================================================
|
---|
29 | */
|
---|
30 |
|
---|
31 | unsigned short
|
---|
32 | setwq(qp, qadr, qsiz, hi, lo)
|
---|
33 | register struct wordq *qp;
|
---|
34 | unsigned short *qadr;
|
---|
35 | unsigned short qsiz, hi, lo;
|
---|
36 | {
|
---|
37 | if ((unsigned short *)0L EQ qadr)
|
---|
38 | qsiz = 0;
|
---|
39 |
|
---|
40 | qp->qbuf = qadr;
|
---|
41 | qp->qsize = qsiz;
|
---|
42 | qp->qlen = 0;
|
---|
43 | qp->qin = 0;
|
---|
44 | qp->qout = 0;
|
---|
45 | qp->qhi = hi;
|
---|
46 | qp->qlo = lo;
|
---|
47 |
|
---|
48 | return(qsiz);
|
---|
49 | }
|
---|
50 |
|
---|
51 | /* |
---|
52 |
|
---|
53 | */
|
---|
54 |
|
---|
55 | /*
|
---|
56 | ============================================================================
|
---|
57 | putwq(qp, c) -- put a word in a word queue
|
---|
58 |
|
---|
59 | Where:
|
---|
60 |
|
---|
61 | qp queue structure pointer
|
---|
62 | c word to put in the queue
|
---|
63 |
|
---|
64 | Return values:
|
---|
65 |
|
---|
66 | -2 error, queue size was 0
|
---|
67 | -1 queue was full, word not added to queue
|
---|
68 | 0 word added to queue
|
---|
69 | 1 at high water mark, word added to queue
|
---|
70 | ============================================================================
|
---|
71 | */
|
---|
72 |
|
---|
73 | short
|
---|
74 | putwq(qp, c)
|
---|
75 | register struct wordq *qp;
|
---|
76 | register unsigned short c;
|
---|
77 | {
|
---|
78 | if (0 NE qp->qsize) { /* verify queue is ok */
|
---|
79 |
|
---|
80 | if (qp->qlen EQ qp->qsize) /* check queue length */
|
---|
81 | return(-1); /* -1 = full */
|
---|
82 |
|
---|
83 | qp->qbuf[qp->qin++] = c; /* put word in queue */
|
---|
84 |
|
---|
85 | if (qp->qin GE qp->qsize) /* update input index */
|
---|
86 | qp->qin = 0; /* wrap around */
|
---|
87 |
|
---|
88 | if (++qp->qlen EQ qp->qhi) /* check length again */
|
---|
89 | return(1); /* 1 = at hi water */
|
---|
90 | else
|
---|
91 | return(0); /* 0 = OK */
|
---|
92 |
|
---|
93 | } else {
|
---|
94 |
|
---|
95 | return(-2); /* -2 = error */
|
---|
96 | }
|
---|
97 | }
|
---|
98 |
|
---|
99 | /* |
---|
100 |
|
---|
101 | */
|
---|
102 |
|
---|
103 | /*
|
---|
104 | ============================================================================
|
---|
105 | getwq(qp, p) -- get a word from a word queue
|
---|
106 |
|
---|
107 | Where:
|
---|
108 |
|
---|
109 | qp queue structure pointer
|
---|
110 | p word pointer for returned word
|
---|
111 |
|
---|
112 | Return values:
|
---|
113 |
|
---|
114 | -2 error, queue size was 0
|
---|
115 | -1 queue was empty, no word returned
|
---|
116 | 0 word returned
|
---|
117 | 1 at low water, word returned
|
---|
118 | ============================================================================
|
---|
119 | */
|
---|
120 |
|
---|
121 | short
|
---|
122 | getwq(qp, p)
|
---|
123 | register struct wordq *qp;
|
---|
124 | register unsigned short *p;
|
---|
125 | {
|
---|
126 | if (0 NE qp->qsize) { /* check queue is ok */
|
---|
127 |
|
---|
128 | if (0 NE qp->qlen) { /* check queue length */
|
---|
129 |
|
---|
130 | *p = qp->qbuf[qp->qout++]; /* get word from queue */
|
---|
131 |
|
---|
132 | if (qp->qout GE qp->qsize) /* check out pointer */
|
---|
133 | qp->qout = 0; /* wrap around */
|
---|
134 |
|
---|
135 | if (--qp->qlen EQ qp->qlo) /* check length again */
|
---|
136 | return(1); /* 1 = at low water */
|
---|
137 | else
|
---|
138 | return(0); /* 0 = OK */
|
---|
139 |
|
---|
140 | } else {
|
---|
141 |
|
---|
142 | return(-1); /* -1 = emtpy */
|
---|
143 | }
|
---|
144 |
|
---|
145 | } else {
|
---|
146 |
|
---|
147 | return(-2); /* -2 = error */
|
---|
148 | }
|
---|
149 | }
|
---|