drop libss and make_cmds
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@23160 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
|
2008-05-05 Love H<>rnquist <20>strand <lha@vit.local>
|
||||||
|
|
||||||
|
* drop libss and make_cmds
|
||||||
|
|
||||||
2007-07-17 Love H<>rnquist <20>strand <lha@it.su.se>
|
2007-07-17 Love H<>rnquist <20>strand <lha@it.su.se>
|
||||||
|
|
||||||
* Makefile.am: roken_rename.h is a dist_ source k
|
* Makefile.am: roken_rename.h is a dist_ source k
|
||||||
|
@@ -12,38 +12,25 @@ YFLAGS = -d
|
|||||||
|
|
||||||
include_HEADERS = sl.h
|
include_HEADERS = sl.h
|
||||||
|
|
||||||
lib_LTLIBRARIES = libsl.la libss.la
|
lib_LTLIBRARIES = libsl.la
|
||||||
libsl_la_LDFLAGS = -version-info 2:1:2
|
libsl_la_LDFLAGS = -version-info 2:1:2
|
||||||
libss_la_LDFLAGS = -version-info 1:6:1
|
|
||||||
|
|
||||||
libsl_la_LIBADD = @LIB_readline@
|
libsl_la_LIBADD = @LIB_readline@
|
||||||
libss_la_LIBADD = @LIB_readline@ @LIB_com_err@
|
|
||||||
|
|
||||||
dist_libsl_la_SOURCES = sl_locl.h sl.c roken_rename.h
|
dist_libsl_la_SOURCES = sl_locl.h sl.c roken_rename.h
|
||||||
nodist_libsl_la_SOURCES = $(ES)
|
nodist_libsl_la_SOURCES = $(ES)
|
||||||
dist_libss_la_SOURCES = $(dist_libsl_la_SOURCES) ss.c ss.h
|
|
||||||
nodist_libss_la_SOURCES = $(ES)
|
|
||||||
|
|
||||||
TESTS = test_sl
|
TESTS = test_sl
|
||||||
check_PROGRAMS = $(TESTS)
|
check_PROGRAMS = $(TESTS)
|
||||||
|
|
||||||
# install these?
|
# install these?
|
||||||
|
|
||||||
bin_PROGRAMS = mk_cmds
|
|
||||||
noinst_PROGRAMS = slc
|
noinst_PROGRAMS = slc
|
||||||
|
|
||||||
mk_cmds_SOURCES = make_cmds.c make_cmds.h parse.y lex.l
|
|
||||||
mk_cmds_LDADD = libsl.la $(LDADD)
|
|
||||||
|
|
||||||
slc_SOURCES = slc-gram.y slc-lex.l slc.h
|
slc_SOURCES = slc-gram.y slc-lex.l slc.h
|
||||||
|
|
||||||
ssincludedir = $(includedir)/ss
|
|
||||||
ssinclude_HEADERS = ss.h
|
|
||||||
|
|
||||||
CLEANFILES = snprintf.c strtok_r.c strdup.c strupr.c getprogname.c
|
CLEANFILES = snprintf.c strtok_r.c strdup.c strupr.c getprogname.c
|
||||||
|
|
||||||
$(mk_cmds_OBJECTS): parse.h parse.c
|
|
||||||
|
|
||||||
LDADD = \
|
LDADD = \
|
||||||
libsl.la \
|
libsl.la \
|
||||||
$(LIB_roken) \
|
$(LIB_roken) \
|
||||||
|
119
lib/sl/lex.l
119
lib/sl/lex.l
@@ -1,119 +0,0 @@
|
|||||||
%{
|
|
||||||
/*
|
|
||||||
* Copyright (c) 1998 - 2001 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. 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#undef ECHO
|
|
||||||
|
|
||||||
#include "make_cmds.h"
|
|
||||||
#include "parse.h"
|
|
||||||
|
|
||||||
RCSID("$Id$");
|
|
||||||
|
|
||||||
static unsigned lineno = 1;
|
|
||||||
static int getstring(void);
|
|
||||||
|
|
||||||
#define YY_NO_UNPUT
|
|
||||||
|
|
||||||
#undef ECHO
|
|
||||||
|
|
||||||
%}
|
|
||||||
|
|
||||||
|
|
||||||
%%
|
|
||||||
command_table { return TABLE; }
|
|
||||||
request { return REQUEST; }
|
|
||||||
unknown { return UNKNOWN; }
|
|
||||||
unimplemented { return UNIMPLEMENTED; }
|
|
||||||
end { return END; }
|
|
||||||
#[^\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
|
|
||||||
|
|
||||||
static int
|
|
||||||
getstring(void)
|
|
||||||
{
|
|
||||||
char x[128];
|
|
||||||
int i = 0;
|
|
||||||
int c;
|
|
||||||
int backslash = 0;
|
|
||||||
while((c = input()) != EOF){
|
|
||||||
if(backslash) {
|
|
||||||
if(c == 'n')
|
|
||||||
c = '\n';
|
|
||||||
else if(c == 't')
|
|
||||||
c = '\t';
|
|
||||||
x[i++] = c;
|
|
||||||
backslash = 0;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(c == '\n'){
|
|
||||||
error_message("unterminated string");
|
|
||||||
lineno++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(c == '\\'){
|
|
||||||
backslash++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(c == '\"')
|
|
||||||
break;
|
|
||||||
x[i++] = c;
|
|
||||||
}
|
|
||||||
x[i] = '\0';
|
|
||||||
yylval.string = strdup(x);
|
|
||||||
return STRING;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
error_message (const char *format, ...)
|
|
||||||
{
|
|
||||||
va_list args;
|
|
||||||
|
|
||||||
va_start (args, format);
|
|
||||||
fprintf (stderr, "%s:%d: ", filename, lineno);
|
|
||||||
vfprintf (stderr, format, args);
|
|
||||||
va_end (args);
|
|
||||||
numerror++;
|
|
||||||
}
|
|
@@ -1,239 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 1998-1999 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. 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 "make_cmds.h"
|
|
||||||
#include <getarg.h>
|
|
||||||
|
|
||||||
RCSID("$Id$");
|
|
||||||
|
|
||||||
#include <roken.h>
|
|
||||||
#include <err.h>
|
|
||||||
#include "parse.h"
|
|
||||||
|
|
||||||
int numerror;
|
|
||||||
extern FILE *yyin;
|
|
||||||
FILE *c_file;
|
|
||||||
|
|
||||||
extern void yyparse(void);
|
|
||||||
|
|
||||||
#ifdef YYDEBUG
|
|
||||||
extern int yydebug = 1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
char *filename;
|
|
||||||
char *table_name;
|
|
||||||
|
|
||||||
static struct command_list *commands;
|
|
||||||
|
|
||||||
void
|
|
||||||
add_command(char *function,
|
|
||||||
char *help,
|
|
||||||
struct string_list *aliases,
|
|
||||||
unsigned flags)
|
|
||||||
{
|
|
||||||
struct command_list *cl = malloc(sizeof(*cl));
|
|
||||||
|
|
||||||
if (cl == NULL)
|
|
||||||
err (1, "malloc");
|
|
||||||
cl->function = function;
|
|
||||||
cl->help = help;
|
|
||||||
cl->aliases = aliases;
|
|
||||||
cl->flags = flags;
|
|
||||||
cl->next = NULL;
|
|
||||||
if(commands) {
|
|
||||||
*commands->tail = cl;
|
|
||||||
commands->tail = &cl->next;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
cl->tail = &cl->next;
|
|
||||||
commands = cl;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *
|
|
||||||
quote(const char *str)
|
|
||||||
{
|
|
||||||
char buf[1024]; /* XXX */
|
|
||||||
const char *p;
|
|
||||||
char *q;
|
|
||||||
q = buf;
|
|
||||||
|
|
||||||
*q++ = '\"';
|
|
||||||
for(p = str; *p != '\0'; p++) {
|
|
||||||
if(*p == '\n') {
|
|
||||||
*q++ = '\\';
|
|
||||||
*q++ = 'n';
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(*p == '\t') {
|
|
||||||
*q++ = '\\';
|
|
||||||
*q++ = 't';
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(*p == '\"' || *p == '\\')
|
|
||||||
*q++ = '\\';
|
|
||||||
*q++ = *p;
|
|
||||||
}
|
|
||||||
*q++ = '\"';
|
|
||||||
*q++ = '\0';
|
|
||||||
return strdup(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
generate_commands(void)
|
|
||||||
{
|
|
||||||
char *base;
|
|
||||||
char *cfn;
|
|
||||||
char *p, *q;
|
|
||||||
|
|
||||||
p = strrchr(table_name, '/');
|
|
||||||
if(p == NULL)
|
|
||||||
p = table_name;
|
|
||||||
else
|
|
||||||
p++;
|
|
||||||
|
|
||||||
base = strdup (p);
|
|
||||||
if (base == NULL)
|
|
||||||
err (1, "strdup");
|
|
||||||
|
|
||||||
p = strrchr(base, '.');
|
|
||||||
if(p)
|
|
||||||
*p = '\0';
|
|
||||||
|
|
||||||
asprintf(&cfn, "%s.c", base);
|
|
||||||
if (cfn == NULL)
|
|
||||||
err (1, "asprintf");
|
|
||||||
|
|
||||||
c_file = fopen(cfn, "w");
|
|
||||||
if (c_file == NULL)
|
|
||||||
err (1, "cannot fopen %s", cfn);
|
|
||||||
|
|
||||||
fprintf(c_file, "/* Generated from %s */\n", filename);
|
|
||||||
fprintf(c_file, "\n");
|
|
||||||
fprintf(c_file, "#include <stddef.h>\n");
|
|
||||||
fprintf(c_file, "#include <sl.h>\n");
|
|
||||||
fprintf(c_file, "\n");
|
|
||||||
|
|
||||||
{
|
|
||||||
struct command_list *cl, *xl;
|
|
||||||
|
|
||||||
for(cl = commands; cl; cl = cl->next) {
|
|
||||||
for(xl = commands; xl != cl; xl = xl->next)
|
|
||||||
if(strcmp(cl->function, xl->function) == 0)
|
|
||||||
break;
|
|
||||||
if(xl != cl)
|
|
||||||
continue;
|
|
||||||
/* XXX hack for ss_quit */
|
|
||||||
if(strcmp(cl->function, "ss_quit") == 0) {
|
|
||||||
fprintf(c_file, "int %s (int, char**);\n", cl->function);
|
|
||||||
fprintf(c_file, "#define _ss_quit_wrap ss_quit\n\n");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
fprintf(c_file, "void %s (int, char**);\n", cl->function);
|
|
||||||
fprintf(c_file, "static int _%s_wrap (int argc, char **argv)\n",
|
|
||||||
cl->function);
|
|
||||||
fprintf(c_file, "{\n");
|
|
||||||
fprintf(c_file, " %s (argc, argv);\n", cl->function);
|
|
||||||
fprintf(c_file, " return 0;\n");
|
|
||||||
fprintf(c_file, "}\n\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(c_file, "SL_cmd %s[] = {\n", table_name);
|
|
||||||
for(cl = commands; cl; cl = cl->next) {
|
|
||||||
struct string_list *sl;
|
|
||||||
sl = cl->aliases;
|
|
||||||
p = quote(sl->string);
|
|
||||||
q = quote(cl->help);
|
|
||||||
fprintf(c_file, " { %s, _%s_wrap, %s },\n", p, cl->function, q);
|
|
||||||
free(p);
|
|
||||||
free(q);
|
|
||||||
|
|
||||||
for(sl = sl->next; sl; sl = sl->next) {
|
|
||||||
p = quote(sl->string);
|
|
||||||
fprintf(c_file, " { %s },\n", p);
|
|
||||||
free(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fprintf(c_file, " { NULL },\n");
|
|
||||||
fprintf(c_file, "};\n");
|
|
||||||
fprintf(c_file, "\n");
|
|
||||||
}
|
|
||||||
fclose(c_file);
|
|
||||||
free(base);
|
|
||||||
free(cfn);
|
|
||||||
}
|
|
||||||
|
|
||||||
int version_flag;
|
|
||||||
int help_flag;
|
|
||||||
struct getargs args[] = {
|
|
||||||
{ "version", 0, arg_flag, &version_flag },
|
|
||||||
{ "help", 0, arg_flag, &help_flag }
|
|
||||||
};
|
|
||||||
int num_args = sizeof(args) / sizeof(args[0]);
|
|
||||||
|
|
||||||
static void
|
|
||||||
usage(int code)
|
|
||||||
{
|
|
||||||
arg_printusage(args, num_args, NULL, "command-table");
|
|
||||||
exit(code);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
main(int argc, char **argv)
|
|
||||||
{
|
|
||||||
int optidx = 0;
|
|
||||||
|
|
||||||
setprogname(argv[0]);
|
|
||||||
if(getarg(args, num_args, argc, argv, &optidx))
|
|
||||||
usage(1);
|
|
||||||
if(help_flag)
|
|
||||||
usage(0);
|
|
||||||
if(version_flag) {
|
|
||||||
print_version(NULL);
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(argc == optidx)
|
|
||||||
usage(1);
|
|
||||||
filename = argv[optidx];
|
|
||||||
yyin = fopen(filename, "r");
|
|
||||||
if(yyin == NULL)
|
|
||||||
err(1, "%s", filename);
|
|
||||||
|
|
||||||
yyparse();
|
|
||||||
|
|
||||||
generate_commands();
|
|
||||||
|
|
||||||
if(numerror)
|
|
||||||
return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
@@ -1,76 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 1998 - 2000 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. 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 __MAKE_CMDS_H__
|
|
||||||
#define __MAKE_CMDS_H__
|
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
|
||||||
#include <config.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
|
|
||||||
#include <roken.h>
|
|
||||||
|
|
||||||
extern char *filename;
|
|
||||||
extern char *table_name;
|
|
||||||
extern int numerror;
|
|
||||||
|
|
||||||
struct command_list {
|
|
||||||
char *function;
|
|
||||||
char *help;
|
|
||||||
struct string_list *aliases;
|
|
||||||
unsigned flags;
|
|
||||||
struct command_list *next;
|
|
||||||
struct command_list **tail;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct string_list {
|
|
||||||
char *string;
|
|
||||||
struct string_list *next;
|
|
||||||
struct string_list **tail;
|
|
||||||
};
|
|
||||||
|
|
||||||
void add_command(char*, char*, struct string_list*, unsigned);
|
|
||||||
|
|
||||||
void error_message(const char *, ...)
|
|
||||||
__attribute__ ((format (printf, 1,2)));
|
|
||||||
|
|
||||||
int yylex (void);
|
|
||||||
|
|
||||||
#endif /* __MAKE_CMDS_H__ */
|
|
169
lib/sl/parse.y
169
lib/sl/parse.y
@@ -1,169 +0,0 @@
|
|||||||
%{
|
|
||||||
/*
|
|
||||||
* Copyright (c) 1998 - 2000 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. 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 "make_cmds.h"
|
|
||||||
RCSID("$Id$");
|
|
||||||
|
|
||||||
static void yyerror (char *s);
|
|
||||||
|
|
||||||
struct string_list* append_string(struct string_list*, char*);
|
|
||||||
void free_string_list(struct string_list *list);
|
|
||||||
unsigned string_to_flag(const char *);
|
|
||||||
|
|
||||||
/* This is for bison */
|
|
||||||
|
|
||||||
#if !defined(alloca) && !defined(HAVE_ALLOCA)
|
|
||||||
#define alloca(x) malloc(x)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
%}
|
|
||||||
|
|
||||||
%union {
|
|
||||||
char *string;
|
|
||||||
unsigned number;
|
|
||||||
struct string_list *list;
|
|
||||||
}
|
|
||||||
|
|
||||||
%token TABLE REQUEST UNKNOWN UNIMPLEMENTED END
|
|
||||||
%token <string> STRING
|
|
||||||
%type <number> flag flags
|
|
||||||
%type <list> aliases
|
|
||||||
|
|
||||||
%%
|
|
||||||
|
|
||||||
file : /* */
|
|
||||||
| statements
|
|
||||||
;
|
|
||||||
|
|
||||||
statements : statement
|
|
||||||
| statements statement
|
|
||||||
;
|
|
||||||
|
|
||||||
statement : TABLE STRING ';'
|
|
||||||
{
|
|
||||||
table_name = $2;
|
|
||||||
}
|
|
||||||
| REQUEST STRING ',' STRING ',' aliases ',' '(' flags ')' ';'
|
|
||||||
{
|
|
||||||
add_command($2, $4, $6, $9);
|
|
||||||
}
|
|
||||||
| REQUEST STRING ',' STRING ',' aliases ';'
|
|
||||||
{
|
|
||||||
add_command($2, $4, $6, 0);
|
|
||||||
}
|
|
||||||
| UNIMPLEMENTED STRING ',' STRING ',' aliases ';'
|
|
||||||
{
|
|
||||||
free($2);
|
|
||||||
free($4);
|
|
||||||
free_string_list($6);
|
|
||||||
}
|
|
||||||
| UNKNOWN aliases ';'
|
|
||||||
{
|
|
||||||
free_string_list($2);
|
|
||||||
}
|
|
||||||
| END ';'
|
|
||||||
{
|
|
||||||
YYACCEPT;
|
|
||||||
}
|
|
||||||
;
|
|
||||||
|
|
||||||
aliases : STRING
|
|
||||||
{
|
|
||||||
$$ = append_string(NULL, $1);
|
|
||||||
}
|
|
||||||
| aliases ',' STRING
|
|
||||||
{
|
|
||||||
$$ = append_string($1, $3);
|
|
||||||
}
|
|
||||||
;
|
|
||||||
|
|
||||||
flags : flag
|
|
||||||
{
|
|
||||||
$$ = $1;
|
|
||||||
}
|
|
||||||
| flags ',' flag
|
|
||||||
{
|
|
||||||
$$ = $1 | $3;
|
|
||||||
}
|
|
||||||
;
|
|
||||||
flag : STRING
|
|
||||||
{
|
|
||||||
$$ = string_to_flag($1);
|
|
||||||
free($1);
|
|
||||||
}
|
|
||||||
;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%%
|
|
||||||
|
|
||||||
static void
|
|
||||||
yyerror (char *s)
|
|
||||||
{
|
|
||||||
error_message ("%s\n", s);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct string_list*
|
|
||||||
append_string(struct string_list *list, char *str)
|
|
||||||
{
|
|
||||||
struct string_list *sl = malloc(sizeof(*sl));
|
|
||||||
if (sl == NULL)
|
|
||||||
return sl;
|
|
||||||
sl->string = str;
|
|
||||||
sl->next = NULL;
|
|
||||||
if(list) {
|
|
||||||
*list->tail = sl;
|
|
||||||
list->tail = &sl->next;
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
sl->tail = &sl->next;
|
|
||||||
return sl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
free_string_list(struct string_list *list)
|
|
||||||
{
|
|
||||||
while(list) {
|
|
||||||
struct string_list *sl = list->next;
|
|
||||||
free(list->string);
|
|
||||||
free(list);
|
|
||||||
list = sl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned
|
|
||||||
string_to_flag(const char *string)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
162
lib/sl/ss.c
162
lib/sl/ss.c
@@ -1,162 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 1998 - 2000 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. 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 "sl_locl.h"
|
|
||||||
#include <com_err.h>
|
|
||||||
#include "ss.h"
|
|
||||||
|
|
||||||
RCSID("$Id$");
|
|
||||||
|
|
||||||
struct ss_subst {
|
|
||||||
char *name;
|
|
||||||
char *version;
|
|
||||||
char *info;
|
|
||||||
ss_request_table *table;
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct ss_subst subsystems[2];
|
|
||||||
static int num_subsystems;
|
|
||||||
|
|
||||||
int
|
|
||||||
ss_create_invocation(const char *subsystem,
|
|
||||||
const char *version,
|
|
||||||
const char *info,
|
|
||||||
ss_request_table *table,
|
|
||||||
int *code)
|
|
||||||
{
|
|
||||||
struct ss_subst *ss;
|
|
||||||
|
|
||||||
if(num_subsystems >= sizeof(subsystems) / sizeof(subsystems[0])) {
|
|
||||||
*code = 17;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
ss = &subsystems[num_subsystems];
|
|
||||||
ss->name = ss->version = ss->info = NULL;
|
|
||||||
if (subsystem != NULL) {
|
|
||||||
ss->name = strdup (subsystem);
|
|
||||||
if (ss->name == NULL) {
|
|
||||||
*code = ENOMEM;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (version != NULL) {
|
|
||||||
ss->version = strdup (version);
|
|
||||||
if (ss->version == NULL) {
|
|
||||||
*code = ENOMEM;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (info != NULL) {
|
|
||||||
ss->info = strdup (info);
|
|
||||||
if (ss->info == NULL) {
|
|
||||||
*code = ENOMEM;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ss->table = table;
|
|
||||||
*code = 0;
|
|
||||||
return num_subsystems++;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
ss_error (int idx, long code, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
va_start(ap, fmt);
|
|
||||||
com_err_va (subsystems[idx].name, code, fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
ss_perror (int idx, long code, const char *msg)
|
|
||||||
{
|
|
||||||
ss_error(idx, code, "%s", msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
ss_execute_command(int idx, char **argv)
|
|
||||||
{
|
|
||||||
int argc = 0;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
while(argv[argc++]);
|
|
||||||
ret = sl_command(subsystems[idx].table, argc, argv);
|
|
||||||
if (ret == SL_BADCOMMAND)
|
|
||||||
return SS_ET_COMMAND_NOT_FOUND;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
ss_execute_line (int idx, const char *line)
|
|
||||||
{
|
|
||||||
char *buf = strdup(line);
|
|
||||||
int argc;
|
|
||||||
char **argv;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (buf == NULL)
|
|
||||||
return ENOMEM;
|
|
||||||
sl_make_argv(buf, &argc, &argv);
|
|
||||||
ret = sl_command(subsystems[idx].table, argc, argv);
|
|
||||||
free(buf);
|
|
||||||
if (ret == SL_BADCOMMAND)
|
|
||||||
return SS_ET_COMMAND_NOT_FOUND;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
ss_listen (int idx)
|
|
||||||
{
|
|
||||||
char *prompt = malloc(strlen(subsystems[idx].name) + 3);
|
|
||||||
if (prompt == NULL)
|
|
||||||
return ENOMEM;
|
|
||||||
|
|
||||||
strcpy(prompt, subsystems[idx].name);
|
|
||||||
strcat(prompt, ": ");
|
|
||||||
sl_loop(subsystems[idx].table, prompt);
|
|
||||||
free(prompt);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
ss_list_requests(int argc, char **argv /* , int idx, void *info */)
|
|
||||||
{
|
|
||||||
sl_help(subsystems[0 /* idx */].table, argc, argv);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
ss_quit(int argc, char **argv)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
57
lib/sl/ss.h
57
lib/sl/ss.h
@@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 1998 - 2000 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. 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$ */
|
|
||||||
|
|
||||||
/* SS compatibility for SL */
|
|
||||||
|
|
||||||
#ifndef __ss_h__
|
|
||||||
#define __ss_h__
|
|
||||||
|
|
||||||
#include <sl.h>
|
|
||||||
|
|
||||||
typedef SL_cmd ss_request_table;
|
|
||||||
|
|
||||||
int ss_create_invocation (const char *, const char *, const char*,
|
|
||||||
ss_request_table*, int*);
|
|
||||||
|
|
||||||
void ss_error (int, long, const char*, ...);
|
|
||||||
int ss_execute_command (int, char**);
|
|
||||||
int ss_execute_line (int, const char*);
|
|
||||||
int ss_list_requests (int argc, char**);
|
|
||||||
int ss_listen (int);
|
|
||||||
void ss_perror (int, long, const char*);
|
|
||||||
int ss_quit (int argc, char**);
|
|
||||||
|
|
||||||
#define SS_ET_COMMAND_NOT_FOUND (-1)
|
|
||||||
|
|
||||||
#endif /* __ss_h__ */
|
|
Reference in New Issue
Block a user