Switch back to a yacc-based compile_et.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@4394 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -1,119 +0,0 @@
|
|||||||
# Copyright (c) 1997 Kungliga Tekniska H<>gskolan
|
|
||||||
# (Royal Institute of Technology, Stockholm, Sweden).
|
|
||||||
# All rights reserved.
|
|
||||||
#
|
|
||||||
# $Id$
|
|
||||||
#
|
|
||||||
|
|
||||||
$1 == "error_table" || $1 == "et" {
|
|
||||||
name = $2
|
|
||||||
base = 0
|
|
||||||
if(NF < 3)
|
|
||||||
base_str = name
|
|
||||||
else
|
|
||||||
base_str = $3
|
|
||||||
for(i = 1; i <= length(base_str); i++){
|
|
||||||
base = base * 64 + index("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_", substr(base_str, i, 1))
|
|
||||||
}
|
|
||||||
base *= 256
|
|
||||||
if(base >= 2147483648){ # 0x80000000
|
|
||||||
base = -(4294967295 - base + 1) # 0xffffffff
|
|
||||||
}
|
|
||||||
split(name, x, "\\.")
|
|
||||||
name=x[1]
|
|
||||||
c_file = name "_err.c"
|
|
||||||
h_file = name "_err.h"
|
|
||||||
h = ""
|
|
||||||
# gsub("[^a-zA-Z0-9]", "_", H_FILE)
|
|
||||||
for(i = 1; i <= length(h_file); i++){
|
|
||||||
c = substr(h_file, i, 1)
|
|
||||||
if(c ~ /[^a-zA-Z0-9]/)
|
|
||||||
c = "_"
|
|
||||||
h = h c
|
|
||||||
}
|
|
||||||
H_FILE= "__" h "__"
|
|
||||||
number = 0
|
|
||||||
print "/* Generated from " FILENAME " */" > c_file
|
|
||||||
if(id_str != "")
|
|
||||||
print id_str > c_file
|
|
||||||
print "" > c_file
|
|
||||||
print "#include <stddef.h>" > c_file # NULL
|
|
||||||
print "#include <error.h>" > c_file
|
|
||||||
print "#include <" h_file ">" > c_file
|
|
||||||
print "" > c_file
|
|
||||||
print "static const char *text[] = {" > c_file
|
|
||||||
|
|
||||||
print "/* Generated from " FILENAME " */" > h_file
|
|
||||||
if(id_str != "")
|
|
||||||
print id_str > h_file
|
|
||||||
print "" > h_file
|
|
||||||
print "#ifndef " H_FILE > h_file
|
|
||||||
print "#define " H_FILE > h_file
|
|
||||||
print "" > h_file
|
|
||||||
print "#include <error.h>" > h_file
|
|
||||||
print "" > h_file
|
|
||||||
print "void initialize_" name "_error_table_r(struct error_table**);" > h_file
|
|
||||||
print "" > h_file
|
|
||||||
n = "initialize_" name "_error_table"
|
|
||||||
print "void " n "(void);" > h_file
|
|
||||||
print "" > h_file
|
|
||||||
print "#define init_" name "_err_tbl " n > h_file
|
|
||||||
print "typedef enum " name "_error_number{" > h_file
|
|
||||||
print "\tERROR_TABLE_BASE_" name " = " base "," > h_file
|
|
||||||
print "\t" name "_err_base = " base "," > h_file
|
|
||||||
next
|
|
||||||
}
|
|
||||||
|
|
||||||
$1 == "index" {
|
|
||||||
newnumber = $2
|
|
||||||
for(; number < newnumber; number++) {
|
|
||||||
# printf("\t%s = %d,\n", toupper(name) "_ERROR_" number, base+ number) > h_file
|
|
||||||
printf("\t/* %3d */ %s,\n", number, "\"Reserved error number " number "\"") > c_file
|
|
||||||
}
|
|
||||||
next
|
|
||||||
}
|
|
||||||
$1 == "prefix" {
|
|
||||||
prefix = $2
|
|
||||||
if(prefix != "")
|
|
||||||
prefix = prefix "_"
|
|
||||||
next
|
|
||||||
}
|
|
||||||
|
|
||||||
$1 == "error_code" || $1 == "ec" {
|
|
||||||
code = $2
|
|
||||||
split(code, x, ",")
|
|
||||||
code = prefix x[1]
|
|
||||||
split($0, x, "\"")
|
|
||||||
string = x[2]
|
|
||||||
printf("\t%s = %d,\n", code, number + base) > h_file
|
|
||||||
printf("\t/* %3d */ \"%s\",\n", number, string) > c_file
|
|
||||||
number++;
|
|
||||||
next
|
|
||||||
}
|
|
||||||
$1 == "id" {
|
|
||||||
# sub("id *", "")
|
|
||||||
for(i = 3; i <= length && substr($0, i, 1) ~ /[ \t]/; i++);
|
|
||||||
id_str ="/* " substr($0, i, length($0)) " */"
|
|
||||||
}
|
|
||||||
END {
|
|
||||||
print "\tNULL" > c_file
|
|
||||||
print "};" > c_file
|
|
||||||
print "" > c_file
|
|
||||||
printf "void initialize_" name "_error_table_r " > c_file
|
|
||||||
print "(struct error_table **list)" > c_file
|
|
||||||
print "{" > c_file
|
|
||||||
printf " initialize_error_table_r(list, text, " > c_file
|
|
||||||
print name "_num_errors, ERROR_TABLE_BASE_" name ");" > c_file
|
|
||||||
print "}" > c_file
|
|
||||||
print "" > c_file
|
|
||||||
print "void initialize_" name "_error_table(void)" > c_file
|
|
||||||
print "{" > c_file
|
|
||||||
printf " init_error_table(text, ERROR_TABLE_BASE_" name ", " > c_file
|
|
||||||
print name "_num_errors);" > c_file
|
|
||||||
print "}" > c_file
|
|
||||||
|
|
||||||
print "\t" name "_num_errors = " number > h_file
|
|
||||||
print "} " name "_error_number;" > h_file
|
|
||||||
print "" > h_file
|
|
||||||
print "#endif /* " H_FILE " */" > h_file
|
|
||||||
}
|
|
172
lib/com_err/compile_et.c
Normal file
172
lib/com_err/compile_et.c
Normal file
@@ -0,0 +1,172 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1998 Kungliga Tekniska H<>gskolan
|
||||||
|
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by Kungliga Tekniska
|
||||||
|
* H<>gskolan and its contributors.
|
||||||
|
*
|
||||||
|
* 4. Neither the name of the Institute nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "compile_et.h"
|
||||||
|
|
||||||
|
RCSID("$Id$");
|
||||||
|
|
||||||
|
#include <roken.h>
|
||||||
|
#include "parse.h"
|
||||||
|
|
||||||
|
int numerror;
|
||||||
|
extern FILE *yyin;
|
||||||
|
FILE *c_file, *h_file;
|
||||||
|
|
||||||
|
extern void yyparse(void);
|
||||||
|
|
||||||
|
long base;
|
||||||
|
int number;
|
||||||
|
char *prefix;
|
||||||
|
char *id_str;
|
||||||
|
|
||||||
|
char name[128];
|
||||||
|
char Basename[128];
|
||||||
|
|
||||||
|
#ifdef YYDEBUG
|
||||||
|
extern int yydebug = 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
char *filename;
|
||||||
|
char hfn[128];
|
||||||
|
char cfn[128];
|
||||||
|
char fn[128];
|
||||||
|
|
||||||
|
void prologue()
|
||||||
|
{
|
||||||
|
char *p;
|
||||||
|
snprintf(fn, sizeof(fn), "__%s__", hfn);
|
||||||
|
for(p = fn; *p; p++)
|
||||||
|
if(!isalnum(*p))
|
||||||
|
*p = '_';
|
||||||
|
|
||||||
|
fprintf(c_file, "/* Generated from %s */\n", filename);
|
||||||
|
if(id_str)
|
||||||
|
fprintf(c_file, "/* %s */\n", id_str);
|
||||||
|
fprintf(c_file, "\n");
|
||||||
|
fprintf(c_file, "#include <stddef.h>\n");
|
||||||
|
fprintf(c_file, "#include <com_right.h>\n");
|
||||||
|
fprintf(c_file, "#include <%s>\n", hfn);
|
||||||
|
fprintf(c_file, "\n");
|
||||||
|
|
||||||
|
fprintf(c_file, "static const char *text[] = {\n");
|
||||||
|
|
||||||
|
fprintf(h_file, "/* Generated from %s */\n", filename);
|
||||||
|
if(id_str)
|
||||||
|
fprintf(h_file, "/* %s */\n", id_str);
|
||||||
|
fprintf(h_file, "\n");
|
||||||
|
fprintf(h_file, "#ifndef %s\n", fn);
|
||||||
|
fprintf(h_file, "#define %s\n", fn);
|
||||||
|
fprintf(h_file, "\n");
|
||||||
|
fprintf(h_file, "#include <com_right.h>\n");
|
||||||
|
fprintf(h_file, "\n");
|
||||||
|
fprintf(h_file,
|
||||||
|
"void initialize_%s_error_table_r(struct error_table**);\n",
|
||||||
|
name);
|
||||||
|
fprintf(h_file, "\n");
|
||||||
|
fprintf(h_file, "void initialize_%s_error_table(void);\n", name);
|
||||||
|
fprintf(h_file, "#define init_%s_err_tbl initialize_%s_error_table\n",
|
||||||
|
name, name);
|
||||||
|
fprintf(h_file, "\n");
|
||||||
|
fprintf(h_file, "typedef enum %s_error_number{\n", name);
|
||||||
|
fprintf(h_file, "\tERROR_TABLE_BASE_%s = %ld,\n", name, base);
|
||||||
|
fprintf(h_file, "\t%s_err_base = %ld,\n", name, base);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
char *p;
|
||||||
|
set_progname(argv[0]);
|
||||||
|
|
||||||
|
if(argc != 2) {
|
||||||
|
fprintf(stderr, "Usage: %s error_table\n", __progname);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
filename = argv[1];
|
||||||
|
yyin = fopen(filename, "r");
|
||||||
|
if(yyin == NULL)
|
||||||
|
err(1, "%s", filename);
|
||||||
|
|
||||||
|
|
||||||
|
p = strrchr(argv[1], '/');
|
||||||
|
if(p)
|
||||||
|
p++;
|
||||||
|
else
|
||||||
|
p = argv[1];
|
||||||
|
strncpy(Basename, p, sizeof(Basename));
|
||||||
|
Basename[sizeof(Basename) - 1] = '\0';
|
||||||
|
|
||||||
|
Basename[strcspn(Basename, "._")] = '\0';
|
||||||
|
|
||||||
|
snprintf(hfn, sizeof(hfn), "%s_err.h", Basename);
|
||||||
|
h_file = fopen(hfn, "w");
|
||||||
|
snprintf(cfn, sizeof(cfn), "%s_err.c", Basename);
|
||||||
|
c_file = fopen(cfn, "w");
|
||||||
|
|
||||||
|
yyparse();
|
||||||
|
|
||||||
|
fprintf(c_file, "\tNULL\n");
|
||||||
|
fprintf(c_file, "};\n");
|
||||||
|
fprintf(c_file, "\n");
|
||||||
|
fprintf(c_file,
|
||||||
|
"void initialize_%s_error_table_r(struct error_table **list)\n",
|
||||||
|
name);
|
||||||
|
fprintf(c_file, "{\n");
|
||||||
|
fprintf(c_file,
|
||||||
|
" initialize_error_table_r(list, text, "
|
||||||
|
"%s_num_errors, ERROR_TABLE_BASE_%s);\n", name, name);
|
||||||
|
fprintf(c_file, "}\n");
|
||||||
|
fprintf(c_file, "\n");
|
||||||
|
fprintf(c_file, "void initialize_%s_error_table(void)\n", name);
|
||||||
|
fprintf(c_file, "{\n");
|
||||||
|
fprintf(c_file,
|
||||||
|
" init_error_table(text, ERROR_TABLE_BASE_%s, "
|
||||||
|
"%s_num_errors);\n", name, name);
|
||||||
|
fprintf(c_file, "}\n");
|
||||||
|
|
||||||
|
fprintf(h_file, "\t%s_num_errors = %d\n", name, number);
|
||||||
|
fprintf(h_file, "} %s_error_number;\n", name);
|
||||||
|
fprintf(h_file, "\n");
|
||||||
|
fprintf(h_file, "#endif /* %s */\n", fn);
|
||||||
|
|
||||||
|
fclose(h_file);
|
||||||
|
fclose(c_file);
|
||||||
|
if(numerror)
|
||||||
|
return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
63
lib/com_err/compile_et.h
Normal file
63
lib/com_err/compile_et.h
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1998 Kungliga Tekniska H<>gskolan
|
||||||
|
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by Kungliga Tekniska
|
||||||
|
* H<>gskolan and its contributors.
|
||||||
|
*
|
||||||
|
* 4. Neither the name of the Institute nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
#ifndef __COMPILE_ET_H__
|
||||||
|
#define __COMPILE_ET_H__
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
extern FILE *c_file;
|
||||||
|
extern FILE *h_file;
|
||||||
|
extern long base;
|
||||||
|
extern int number;
|
||||||
|
extern char *prefix;
|
||||||
|
extern char name[128];
|
||||||
|
extern char *id_str;
|
||||||
|
extern char *filename;
|
||||||
|
extern int numerror;
|
||||||
|
|
||||||
|
#endif /* __COMPILE_ET_H__ */
|
@@ -1,24 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# $Id$
|
|
||||||
|
|
||||||
while :; do
|
|
||||||
case "$1" in
|
|
||||||
-lang*)
|
|
||||||
shift
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
-debug)
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
break
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
for i do
|
|
||||||
@awk@ '
|
|
||||||
#awksrc
|
|
||||||
' "$i"
|
|
||||||
done
|
|
119
lib/com_err/lex.l
Normal file
119
lib/com_err/lex.l
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
%{
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1998 Kungliga Tekniska H<>gskolan
|
||||||
|
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by Kungliga Tekniska
|
||||||
|
* H<>gskolan and its contributors.
|
||||||
|
*
|
||||||
|
* 4. Neither the name of the Institute nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "compile_et.h"
|
||||||
|
#include "parse.h"
|
||||||
|
|
||||||
|
RCSID("$Id$");
|
||||||
|
|
||||||
|
static unsigned lineno = 1;
|
||||||
|
void error_message(char *, ...);
|
||||||
|
int getstring(void);
|
||||||
|
|
||||||
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
%%
|
||||||
|
et { return ET; }
|
||||||
|
error_table { return ET; }
|
||||||
|
ec { return EC; }
|
||||||
|
error_code { return EC; }
|
||||||
|
prefix { return PREFIX; }
|
||||||
|
index { return INDEX; }
|
||||||
|
id { return ID; }
|
||||||
|
end { return END; }
|
||||||
|
[0-9]+ { yylval.number = atoi(yytext); return NUMBER; }
|
||||||
|
#[^\n]* ;
|
||||||
|
[ \t] ;
|
||||||
|
\n { lineno++; }
|
||||||
|
\" { return getstring(); }
|
||||||
|
[a-zA-Z0-9_]+ { yylval.string = strdup(yytext); return STRING; }
|
||||||
|
. { return *yytext; }
|
||||||
|
%%
|
||||||
|
|
||||||
|
#ifndef yywrap /* XXX */
|
||||||
|
int
|
||||||
|
yywrap ()
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int
|
||||||
|
getstring(void)
|
||||||
|
{
|
||||||
|
char x[128];
|
||||||
|
int i = 0;
|
||||||
|
int c;
|
||||||
|
int quote = 0;
|
||||||
|
while((c = getc(yyin)) != EOF){
|
||||||
|
if(quote) {
|
||||||
|
x[i++] = c;
|
||||||
|
quote = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(c == '\n'){
|
||||||
|
error_message("unterminated string");
|
||||||
|
lineno++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(c == '\\'){
|
||||||
|
quote++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(c == '\"')
|
||||||
|
break;
|
||||||
|
x[i++] = c;
|
||||||
|
}
|
||||||
|
x[i] = '\0';
|
||||||
|
yylval.string = strdup(x);
|
||||||
|
return STRING;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
error_message (char *format, ...)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
|
||||||
|
va_start (args, format);
|
||||||
|
fprintf (stderr, "%s:%d: ", filename, lineno);
|
||||||
|
vfprintf (stderr, format, args);
|
||||||
|
va_end (args);
|
||||||
|
numerror++;
|
||||||
|
}
|
156
lib/com_err/parse.y
Normal file
156
lib/com_err/parse.y
Normal file
@@ -0,0 +1,156 @@
|
|||||||
|
%{
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1998 Kungliga Tekniska H<>gskolan
|
||||||
|
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by Kungliga Tekniska
|
||||||
|
* H<>gskolan and its contributors.
|
||||||
|
*
|
||||||
|
* 4. Neither the name of the Institute nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "compile_et.h"
|
||||||
|
RCSID("$Id$");
|
||||||
|
|
||||||
|
void yyerror (char *s);
|
||||||
|
long name2number(const char *str);
|
||||||
|
%}
|
||||||
|
|
||||||
|
%union {
|
||||||
|
char *string;
|
||||||
|
int number;
|
||||||
|
}
|
||||||
|
|
||||||
|
%token ET INDEX PREFIX EC ID END
|
||||||
|
%token <string> STRING
|
||||||
|
%token <number> NUMBER
|
||||||
|
|
||||||
|
%%
|
||||||
|
|
||||||
|
file : /* */
|
||||||
|
| statements
|
||||||
|
;
|
||||||
|
|
||||||
|
statements : statement
|
||||||
|
| statements statement
|
||||||
|
;
|
||||||
|
|
||||||
|
statement : ET STRING
|
||||||
|
{
|
||||||
|
base = name2number($2);
|
||||||
|
strncpy(name, $2, sizeof(name));
|
||||||
|
name[sizeof(name) - 1] = '\0';
|
||||||
|
free($2);
|
||||||
|
prologue();
|
||||||
|
}
|
||||||
|
| ET STRING STRING
|
||||||
|
{
|
||||||
|
base = name2number($2);
|
||||||
|
strncpy(name, $3, sizeof(name));
|
||||||
|
name[sizeof(name) - 1] = '\0';
|
||||||
|
free($2);
|
||||||
|
free($3);
|
||||||
|
prologue();
|
||||||
|
}
|
||||||
|
| INDEX NUMBER
|
||||||
|
{
|
||||||
|
for(; number < $2; number++) {
|
||||||
|
/*
|
||||||
|
fprintf(h_file, "\t%s_ERROR_%d = %d,\n",
|
||||||
|
name, number, base + number);
|
||||||
|
*/
|
||||||
|
fprintf(c_file, "\t/* %03d */ \"Reserved %s error (%d)\",\n",
|
||||||
|
number, name, number);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
| PREFIX STRING
|
||||||
|
{
|
||||||
|
prefix = realloc(prefix, strlen($2) + 2);
|
||||||
|
strcpy(prefix, $2);
|
||||||
|
strcat(prefix, "_");
|
||||||
|
free($2);
|
||||||
|
}
|
||||||
|
| PREFIX
|
||||||
|
{
|
||||||
|
prefix = realloc(prefix, 1);
|
||||||
|
*prefix = '\0';
|
||||||
|
}
|
||||||
|
| EC STRING ',' STRING
|
||||||
|
{
|
||||||
|
fprintf(h_file, "\t%s%s = %d,\n",
|
||||||
|
prefix ? prefix : "", $2, number + base);
|
||||||
|
fprintf(c_file, "\t/* %03d */ \"%s\",\n", number, $4);
|
||||||
|
free($2);
|
||||||
|
free($4);
|
||||||
|
number++;
|
||||||
|
}
|
||||||
|
| ID STRING
|
||||||
|
{
|
||||||
|
id_str = $2;
|
||||||
|
}
|
||||||
|
| END
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
%%
|
||||||
|
|
||||||
|
long
|
||||||
|
name2number(const char *str)
|
||||||
|
{
|
||||||
|
const char *p;
|
||||||
|
long base = 0;
|
||||||
|
const char *x = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
|
"abcdefghijklmnopqrstuvwxyz0123456789_";
|
||||||
|
if(strlen(str) > 4) {
|
||||||
|
yyerror("table name too long");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
for(p = str; *p; p++){
|
||||||
|
char *q = strchr(x, *p);
|
||||||
|
if(q == NULL) {
|
||||||
|
yyerror("invalid character in table name");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
base = (base << 6) + (q - x) + 1;
|
||||||
|
}
|
||||||
|
base <<= 8;
|
||||||
|
if(base > 0x7fffffff)
|
||||||
|
base = -(0xffffffff - base + 1);
|
||||||
|
return base;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
yyerror (char *s)
|
||||||
|
{
|
||||||
|
error_message ("%s\n", s);
|
||||||
|
}
|
Reference in New Issue
Block a user