home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 January
/
usenetsourcesnewsgroupsinfomagicjanuary1994.iso
/
sources
/
games
/
volume13
/
okbridge
/
part07
/
ps.h
< prev
next >
Wrap
C/C++ Source or Header
|
1992-01-12
|
4KB
|
110 lines
/* ps.h -- "parse-string" data structure.
!
! Copyright (C) 1990,1991 by Matthew Clegg
!
! This program may be copied and distributed freely. Please do not
! charge money for this program or for any program derived from it.
! If you modify this program, then include a notice stating plainly
! that your program is derived from the okbridge program and is not
! the same as the official okbridge program.
!
! I welcome any suggestions for improvement to okbridge, and
! I would be especially happy to receive improved source code.
! If you have comments or suggestions, or if you would like to
! join the okbridge mailing list, then write to
!
! mclegg@cs.ucsd.edu
!
*
* This file defines a data structure for handling strings which are
* to be parsed. The crucial aspect of a such a data structure is that
* it permit the current character to be read without advancing the
* input pointer.
*
* The lifetime of a parse string can be described crudely as follows:
* Create the parse string
* Repeat:
* Copy data into the parse string (from memory or from a file).
* Read the data out of the parse string.
* End.
*
* Thus, we provide procedures for handling each of these steps and for
* giving some additional information about the string.
*/
typedef char *parse_string;
#define PS_SIZE 0
#define PS_LENGTH 1
#define PS_POS 2
#define PS_OFFSET 3
extern parse_string ps_alloc ();
/* parse_string ps_alloc (int n); */
/* Returns a parse_string which can hold up to n bytes of text. */
/* void ps_reset(parse_string ps); */
/* Clears a parse_string so that new data can be copied into it. */
#define ps_reset(ps) (ps[PS_LENGTH]=ps[PS_POS]=0;)
extern ps_put ();
/* void ps_put (parse_string ps, char ch); */
/* Adds the character ch to the parse_string ps. */
extern ps_copy ();
/* void ps_copy (parse_string ps, char *s); */
/* Copies the string s to the parse_string ps.
Resets ps before doing the copy. */
extern ps_read ();
/* void ps_read (parse_string ps, FILE *fp); */
/* Copies the next text line from the file fp to the parse_string ps.
* Resets ps before doing the copy.
*/
/* char ps_scan (parse_string ps); */
/* Returns the current character in the parse_string ps.
* Does not advance the pointer in ps.
*/
#define ps_scan(ps) ((ps[PS_POS] < ps[PS_LENGTH]) ? ps [PS_OFFSET + ps[PS_POS]] : '\0')
extern int ps_matches ();
/* int ps_matches (parse_string ps, char *key); */
/* Returns TRUE if the next sequence of characters in the parse string
* matches key. If so, then advances the pointer in the parse string
* past key. Otherwise, returns FALSE.
*/
extern int ps_matches_ic ();
/* int ps_matches_ic (parse_string ps, char *key); */
/* Returns TRUE if the next sequence of characters in the parse string
* matches key, after both are converted to upper case. If so, then
* advances the pointer in the parse string past key.
*/
/* int ps_next (parse_string ps); */
/* Advances the pointer in the parse_string ps to the next character.
* Returns the character which the read head has just moved past.
*/
/* #define ps_next(ps) (ps[PS_POS]++) */
#define ps_next(ps) ((ps[PS_POS] < ps[PS_LENGTH]) ? ps[PS_OFFSET+ps[PS_POS]++] : '\0')
/* int ps_size (parse_string ps); */
/* Returns the number of characters allocated for text in ps. */
#define ps_size(ps) (ps[PS_SIZE])
/* int ps_length (parse_string ps); */
/* Returns the number of characters of text currently used in ps. */
#define ps_length(ps) (ps[PS_LENGTH])
/* int ps_pos (parse_string ps); */
/* Returns the index of the current character in ps. */
#define ps_pos(ps) (ps[PS_POS])