3 * Copyright (c) 2004-2018, Juniper Networks, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "manifest_parser.h"
38 extern int parser_version;
40 void yyerror(const char *message);
41 void warning(const char *message);
54 [/a-zA-Z0-9\.][^ \t\n=]* {
55 yylval.string = strdup(yytext);
68 [ \t\r] ; /* eat white ones */
72 * If we are older than the specified version
73 * ignore rest of line, otherwise just discard this token.
75 int skip = atoi(&yytext[2]);
77 VERBOSE(3, ("%s: skip if %d <= %d\n", yytext, parser_version, skip));
78 if (parser_version <= skip) {
79 /* treat as a comment, yyless() is cheaper than yyunput() */
80 yytext[yyleng - 1] = '#';
85 #[^>\n].* ; /* comment */
87 . yyerror("invalid character");
91 static char *manifest_file = NULL;
99 read_string_buf (void *token, char *dest, int count)
101 struct string_buf *str_buf_p = (struct string_buf *)token;
107 n = str_buf_p->size - str_buf_p->pos;
111 memcpy(dest, str_buf_p->buf + str_buf_p->pos, n);
118 manifest_open (const char *file, const char *file_content)
120 static struct string_buf str_buf;
127 str_buf.buf = file_content;
129 str_buf.size = strlen(file_content);
130 yyin = fropen(&str_buf, read_string_buf);
132 manifest_file = strdup(file);
134 manifest_parser_init();
136 manifest_file = NULL;
141 yyerror(const char *string)
143 fprintf(stderr, "%s: %d: %s at %s\n",
144 manifest_file, lineno, string, yytext);