2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #define MAXLINELEN 1024
12 #include <sys/param.h>
13 #include <sys/types.h>
18 #include <afsconfig.h>
21 #define TOK_DONTUSE 1 /* Don't copy if match and this flag is set. */
28 /* free token list returned by parseLine */
30 FreeTokens(register struct token *alist)
32 register struct token *nlist;
33 for (; alist; alist = nlist) {
41 #define space(x) ((x) == ' ' || (x) == '\t' || (x) == '<' || (x) == '>')
43 ParseLine(char *aline, struct token **alist)
45 char tbuffer[MAXTOKLEN + 1];
46 register char *tptr = NULL;
48 struct token *first, *last;
49 register struct token *ttok;
53 inToken = 0; /* not copying token chars at start */
58 if (tc == 0 || space(tc)) { /* terminating null gets us in here, too */
60 inToken = 0; /* end of this token */
62 return -1; /* should never get here */
65 ttok = (struct token *)malloc(sizeof(struct token));
68 ttok->key = (char *)malloc(strlen(tbuffer));
69 strcpy(ttok->key, tbuffer + 1);
70 ttok->flags = TOK_DONTUSE;
73 ttok->key = (char *)malloc(strlen(tbuffer) + 1);
74 strcpy(ttok->key, tbuffer);
86 /* an alpha character */
94 if (tptr - tbuffer >= MAXTOKLEN)
95 return -1; /* token too long */
99 /* last token flushed 'cause space(0) --> true */
108 /* read a line into a buffer, putting in null termination and stopping on appropriate
109 end of line char. Returns 0 at eof, > 0 at normal line end, and < 0 on error */
111 GetLine(FILE * afile, register char *abuffer, int amax)
122 if (tc <= 0 || tc == '\012') {
125 return (amax > 0 ? 1 : -1);
128 /* keep reading to end of line so next one isn't bogus */
136 mc_copy(register FILE * ain, register FILE * aout, char *alist[])
138 char tbuffer[MAXLINELEN];
139 struct token *tokens;
141 register struct token *tt;
146 copying = 1; /* start off copying data */
148 /* copy lines, handling modes appropriately */
149 code = GetLine(ain, tbuffer, MAXLINELEN);
152 /* otherwise process the line */
153 if (tbuffer[0] == '<') {
154 /* interpret the line as a set of options, any one of which will cause us
155 * to start copying the data again. */
156 code = ParseLine(tbuffer, &tokens);
161 for (tp = alist; (!done) && (*tp != NULL); tp++) {
162 for (tt = tokens; tt; tt = tt->next) {
163 if (!strcmp(*tp, tt->key)) {
164 /* Need to search all tokens in case a dont use
165 * flag is set. But we can stop on the first
168 if (tt->flags & TOK_DONTUSE) {
180 /* just copy the line */
182 fwrite(tbuffer, 1, strlen(tbuffer), aout);