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>
23 #define TOK_DONTUSE 1 /* Don't copy if match and this flag is set. */
30 /* free token list returned by parseLine */
32 FreeTokens(register struct token *alist)
34 register struct token *nlist;
35 for (; alist; alist = nlist) {
43 #define space(x) ((x) == ' ' || (x) == '\t' || (x) == '<' || (x) == '>')
45 ParseLine(char *aline, struct token **alist)
47 char tbuffer[MAXTOKLEN + 1];
48 register char *tptr = NULL;
50 struct token *first, *last;
51 register struct token *ttok;
55 inToken = 0; /* not copying token chars at start */
60 if (tc == 0 || space(tc)) { /* terminating null gets us in here, too */
62 inToken = 0; /* end of this token */
64 return -1; /* should never get here */
67 ttok = (struct token *)malloc(sizeof(struct token));
70 ttok->key = (char *)malloc(strlen(tbuffer));
71 strcpy(ttok->key, tbuffer + 1);
72 ttok->flags = TOK_DONTUSE;
75 ttok->key = (char *)malloc(strlen(tbuffer) + 1);
76 strcpy(ttok->key, tbuffer);
88 /* an alpha character */
96 if (tptr - tbuffer >= MAXTOKLEN)
97 return -1; /* token too long */
101 /* last token flushed 'cause space(0) --> true */
110 /* read a line into a buffer, putting in null termination and stopping on appropriate
111 end of line char. Returns 0 at eof, > 0 at normal line end, and < 0 on error */
113 GetLine(FILE * afile, register char *abuffer, int amax)
124 if (tc <= 0 || tc == '\012') {
127 return (amax > 0 ? 1 : -1);
130 /* keep reading to end of line so next one isn't bogus */
138 mc_copy(register FILE * ain, register FILE * aout, char *alist[])
140 char tbuffer[MAXLINELEN];
141 struct token *tokens;
143 register struct token *tt;
148 copying = 1; /* start off copying data */
150 /* copy lines, handling modes appropriately */
151 code = GetLine(ain, tbuffer, MAXLINELEN);
154 /* otherwise process the line */
155 if (tbuffer[0] == '<') {
156 /* interpret the line as a set of options, any one of which will cause us
157 * to start copying the data again. */
158 code = ParseLine(tbuffer, &tokens);
163 for (tp = alist; (!done) && (*tp != NULL); tp++) {
164 for (tt = tokens; tt; tt = tt->next) {
165 if (!strcmp(*tp, tt->key)) {
166 /* Need to search all tokens in case a dont use
167 * flag is set. But we can stop on the first
170 if (tt->flags & TOK_DONTUSE) {
182 /* just copy the line */
184 fwrite(tbuffer, 1, strlen(tbuffer), aout);