source: buchla-68k/orig/GP/SETCQ.C@ 0170798

Last change on this file since 0170798 was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Imported original source code.

  • Property mode set to 100755
File size: 3.3 KB
RevLine 
[3ae31e9]1/*
2 ============================================================================
3 setcq.c -- character queue functions
4 Version 1 -- 1988-11-02 -- D.N. Lynx Crowe
5 ============================================================================
6*/
7
8#define CHARQHDR /* so charq.h gets it right */
9
10#include "stddefs.h"
11#include "charq.h"
12
13/*
14 ============================================================================
15 setcq(qp, qadr, qsiz, hi, lo) -- setup a character queue
16
17 Where:
18
19 struct charq *qp queue structure pointer
20 char *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
31unsigned short
32setcq(qp, qadr, qsiz, hi, lo)
33register struct charq *qp;
34char *qadr;
35unsigned short qsiz, hi, lo;
36{
37 if ((char *)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 putcq(qp, c) -- put a character in a character queue
58
59 Where:
60
61 qp queue structure pointer
62 c character to put in the queue
63
64 Return values:
65
66 -2 error, queue size was 0
67 -1 queue was full, character not added to queue
68 0 character added to queue
69 1 at high water mark, character added to queue
70 ============================================================================
71*/
72
73short
74putcq(qp, c)
75register struct charq *qp;
76register 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 character 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 getcq(qp, p) -- get a character from a character queue
106
107 Where:
108
109 qp queue structure pointer
110 p character pointer for returned character
111
112 Return values:
113
114 -2 error, queue size was 0
115 -1 queue was empty, no character returned
116 0 character returned
117 1 at low water, character returned
118 ============================================================================
119*/
120
121short
122getcq(qp, p)
123register struct charq *qp;
124register char *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 character 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}
Note: See TracBrowser for help on using the repository browser.