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 #include "afsconfig.h"
12 #define MAXLINELEN 1024
14 #include <sys/param.h>
15 #include <sys/types.h>
22 #define TOK_DONTUSE 1 /* Don't copy if match and this flag is set. */
29 /* free token list returned by parseLine */
31 FreeTokens(struct token *alist)
34 for (; alist; alist = nlist) {
42 #define space(x) ((x) == ' ' || (x) == '\t' || (x) == '<' || (x) == '>')
44 ParseLine(char *aline, struct token **alist)
46 char tbuffer[MAXTOKLEN + 1];
49 struct token *first, *last;
54 inToken = 0; /* not copying token chars at start */
59 if (tc == 0 || space(tc)) { /* terminating null gets us in here, too */
61 inToken = 0; /* end of this token */
63 return -1; /* should never get here */
66 ttok = malloc(sizeof(struct token));
69 ttok->key = strdup(tbuffer + 1); /* Skip first char */
70 ttok->flags = TOK_DONTUSE;
73 ttok->key = strdup(tbuffer);
85 /* an alpha character */
93 if (tptr - tbuffer >= MAXTOKLEN)
94 return -1; /* token too long */
98 /* last token flushed 'cause space(0) --> true */
107 /* read a line into a buffer, putting in null termination and stopping on appropriate
108 end of line char. Returns 0 at eof, > 0 at normal line end, and < 0 on error */
110 GetLine(FILE * afile, char *abuffer, int amax)
121 if (tc <= 0 || tc == '\012') {
124 return (amax > 0 ? 1 : -1);
127 /* keep reading to end of line so next one isn't bogus */
135 mc_copy(FILE * ain, FILE * aout, char *alist[])
137 char tbuffer[MAXLINELEN];
138 struct token *tokens;
145 copying = 1; /* start off copying data */
147 /* copy lines, handling modes appropriately */
148 code = GetLine(ain, tbuffer, MAXLINELEN);
151 /* otherwise process the line */
152 if (tbuffer[0] == '<') {
153 /* interpret the line as a set of options, any one of which will cause us
154 * to start copying the data again. */
155 code = ParseLine(tbuffer, &tokens);
160 for (tp = alist; (!done) && (*tp != NULL); tp++) {
161 for (tt = tokens; tt; tt = tt->next) {
162 if (!strcmp(*tp, tt->key)) {
163 /* Need to search all tokens in case a dont use
164 * flag is set. But we can stop on the first
167 if (tt->flags & TOK_DONTUSE) {
179 /* just copy the line */
181 fwrite(tbuffer, 1, strlen(tbuffer), aout);