home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
vol_300
/
344_01
/
cirque.doc
< prev
next >
Wrap
Text File
|
1991-03-05
|
2KB
|
67 lines
File on the enclosed disk:
cirque.c
cirqtest.c
cirque.doc
Conrad Thornton
RR1 Box 87C
Downsville,La. 71234
(318)982 5201
Usage:
This code is for a circular queue of any size
and any data type.
It can be used for event trapping........ect
It stores 2 items for each record.
(1) The 1st byte of a record is user-data-type.
This type number is user supplied.
( should be min 1 to max 100 ? ).
When a record is read from the queue, this type
controls how you use the pointer. (see cirqtest.c)
(2) A char * to a memory address returned from malloc.
----------------------------------------------------------
Defines:
ITEMSIZE will equal 3 or 5 depending on sizeof(char *);
return codes:
ITSOK 0
ERROR -1
QUEFULL -2
QUEEMPTY -3
----------------------------------------------------
functions:
int setupque(int)
Set up the queue of size (arg).
Quesize in bytes is (int arg * ITEMSIZE + 1).
Returns ITSOK (0) or ERROR (-1)
---------------------------------------
int quewrite(char *,int)
Write "type" and "data" (ITEMSIZE) to the queue.
Returns ITSOK (0) on success.
Returns QUEFULL (-2) if cannot write.
---------------------------------------
int queovwrite(char *,int)
Same basic fun as quewrite() Execpt it will over-write
existing records.
Return values ITSOK (0) or ERROR (-1) ONLY.
NOTE: If this function is used, and it must overwrite
an existing record for needed space, IT FREES
THE PREVIOUS MALLOC FOR THE DATA-AREA THAT IS
BEING OVERWRITTEN.
---------------------------------------
int queread(char **,int *)
Read a record from the queue.
NOTE: Send the address of users char *.
The record (address) will be copied to the char *.
The pointer can then be used as usual.
The record type (users type) will be assigned to int *.
Returns ITSOK (0) or QUEEMPTY (-3).
---------------------------------------
int quekill(void)
Free previous malloc for "cir_que" string.
NOTE: Returns ERROR (-1) if itemsinque is true.
---------------------------------------