| 1 |
/* |
| 2 |
* Copyright (c) 1993-1994 by Xerox Corporation. All rights reserved. |
| 3 |
* |
| 4 |
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED |
| 5 |
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK. |
| 6 |
* |
| 7 |
* Permission is hereby granted to use or copy this program |
| 8 |
* for any purpose, provided the above notices are retained on all copies. |
| 9 |
* Permission to modify the code and to distribute modified code is granted, |
| 10 |
* provided the above notices are retained, and a notice that the code was |
| 11 |
* modified is included with the above copyright notice. |
| 12 |
*/ |
| 13 |
|
| 14 |
#ifndef EC_H |
| 15 |
#define EC_H |
| 16 |
|
| 17 |
# ifndef CORD_H |
| 18 |
# include "cord.h" |
| 19 |
# endif |
| 20 |
|
| 21 |
#ifdef __cplusplus |
| 22 |
extern "C" { |
| 23 |
#endif |
| 24 |
|
| 25 |
/* Extensible cords are strings that may be destructively appended to. */ |
| 26 |
/* They allow fast construction of cords from characters that are */ |
| 27 |
/* being read from a stream. */ |
| 28 |
/* |
| 29 |
* A client might look like: |
| 30 |
* |
| 31 |
* { |
| 32 |
* CORD_ec x; |
| 33 |
* CORD result; |
| 34 |
* char c; |
| 35 |
* FILE *f; |
| 36 |
* |
| 37 |
* ... |
| 38 |
* CORD_ec_init(x); |
| 39 |
* while (...) { |
| 40 |
* c = getc(f); |
| 41 |
* ... |
| 42 |
* CORD_ec_append(x, c); |
| 43 |
* } |
| 44 |
* result = CORD_balance(CORD_ec_to_cord(x)); |
| 45 |
* |
| 46 |
* If a C string is desired as the final result, the call to CORD_balance |
| 47 |
* may be replaced by a call to CORD_to_char_star. |
| 48 |
*/ |
| 49 |
|
| 50 |
# ifndef CORD_BUFSZ |
| 51 |
# define CORD_BUFSZ 128 |
| 52 |
# endif |
| 53 |
|
| 54 |
/* This structure represents the concatenation of ec_cord with */ |
| 55 |
/* ec_buf[0 .. ec_bufptr-ec_buf-1]. */ |
| 56 |
typedef struct CORD_ec_struct { |
| 57 |
CORD ec_cord; |
| 58 |
char * ec_bufptr; |
| 59 |
char ec_buf[CORD_BUFSZ+1]; |
| 60 |
} CORD_ec[1]; |
| 61 |
|
| 62 |
/* Flush the buffer part of the extended cord into ec_cord. */ |
| 63 |
/* Note that this is almost the only real function, and it is */ |
| 64 |
/* implemented in 6 lines in cordxtra.c */ |
| 65 |
void CORD_ec_flush_buf(CORD_ec x); |
| 66 |
|
| 67 |
/* Convert an extensible cord to a cord. */ |
| 68 |
# define CORD_ec_to_cord(x) (CORD_ec_flush_buf(x), (x)[0].ec_cord) |
| 69 |
|
| 70 |
/* Initialize an extensible cord. */ |
| 71 |
#define CORD_ec_init(x) \ |
| 72 |
((x)[0].ec_cord = 0, (void)((x)[0].ec_bufptr = (x)[0].ec_buf)) |
| 73 |
|
| 74 |
/* Append a character to an extensible cord. */ |
| 75 |
#define CORD_ec_append(x, c) \ |
| 76 |
((void)((x)[0].ec_bufptr == (x)[0].ec_buf + CORD_BUFSZ \ |
| 77 |
? (CORD_ec_flush_buf(x), 0) : 0), \ |
| 78 |
(void)(*(x)[0].ec_bufptr++ = (c))) |
| 79 |
|
| 80 |
/* Append a cord to an extensible cord. Structure remains shared with */ |
| 81 |
/* original. */ |
| 82 |
void CORD_ec_append_cord(CORD_ec x, CORD s); |
| 83 |
|
| 84 |
#ifdef __cplusplus |
| 85 |
} /* extern "C" */ |
| 86 |
#endif |
| 87 |
|
| 88 |
#endif /* EC_H */ |