From be640e88131c9d74b88872b2a02b02eaa9bf7fe4 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 16 Feb 1995 13:20:59 +0000 Subject: [PATCH] Organization of resource files for targets and conversion language implemented. --- kernel/default.bib | 17 ++++++++ kernel/default.res | 20 +++++++-- kernel/kernel.h | 12 ++++- kernel/lang.dk.res | 38 ++++++++++++++++ kernel/loc.bib | 6 +++ kernel/loc.res | 9 ++++ kernel/main.c | 123 +++++++++++++++++++++++++++++++++++++++++----------- kernel/urp.c | 81 ++++++++++++++++++++++++++++------ 8 files changed, 262 insertions(+), 44 deletions(-) create mode 100644 kernel/default.bib create mode 100644 kernel/lang.dk.res create mode 100644 kernel/loc.bib create mode 100644 kernel/loc.res diff --git a/kernel/default.bib b/kernel/default.bib new file mode 100644 index 0000000..3f27d57 --- /dev/null +++ b/kernel/default.bib @@ -0,0 +1,17 @@ +# Subset of bib-1 attributes map to CCL qualifiers +# $Id: default.bib,v 1.1 1995/02/16 13:20:59 adam Exp $ +# +term s=pw t=l,r +au u=1 s=pw +ti u=4 s=pw +isbn u=7 +issn u=8 +cc u=20 +su u=21 s=pw +date u=30 r=o +dp u=31 r=o +da u=32 r=o +la u=54 s=pw +ab u=62 s=pw +note u=63 s=pw +af u=1006 s=pw diff --git a/kernel/default.res b/kernel/default.res index 8d213f8..4c8711a 100644 --- a/kernel/default.res +++ b/kernel/default.res @@ -1,11 +1,25 @@ # Email gateway - general kernel resources -# $Id: default.res,v 1.1 1995/02/15 17:45:29 adam Exp $ +# $Id: default.res,v 1.2 1995/02/16 13:20:59 adam Exp $ # -gw.msg.greeting: Europagate email-Z39.50 gateway -gw.err.nullbody: Empty body +# Important directories, programs, etc. gw.reply.mta: /usr/bin/smail gw.reply.tmp.prefix: gwr gw.reply.tmp.dir: /tmp +gw.path: /home/adam/egate/kernel + +# Target definitions +gw.portno: 2000 +gw.hostname: localhost +gw.bibset: default.bib +gw.target.loc: loc.res + +# Language definitions +gw.lang.dk: lang.dk.res + +# Messages +gw.msg.subject: Your gateway query +gw.msg.greeting: Europagate email-Z39.50 gateway +gw.err.nullbody: Empty body ccl.command.find: find f ccl.command.show: show s ccl.command.base: base b diff --git a/kernel/kernel.h b/kernel/kernel.h index 185085e..7548335 100644 --- a/kernel/kernel.h +++ b/kernel/kernel.h @@ -2,7 +2,11 @@ * Europagate, 1995 * * $Log: kernel.h,v $ - * Revision 1.1 1995/02/15 17:45:29 adam + * Revision 1.2 1995/02/16 13:20:59 adam + * Organization of resource files for targets and conversion + * language implemented. + * + * Revision 1.1 1995/02/15 17:45:29 adam * First version of email gateway kernel. Email requests are read * from stdin. The output is transferred to an MTA if 'From' is * found in the header - or stdout if absent. No Z39.50 client is used. @@ -17,4 +21,10 @@ int urp (FILE *inf); extern CCL_bibset bibset; extern GwRes kernel_res; +extern const char *default_res; +extern const char *target; +extern const char *lang; + extern FILE *reply_fd; + +void read_kernel_res (void); diff --git a/kernel/lang.dk.res b/kernel/lang.dk.res new file mode 100644 index 0000000..c20c6ef --- /dev/null +++ b/kernel/lang.dk.res @@ -0,0 +1,38 @@ +# Email gateway - resources for danish conversation +# $Id: lang.dk.res,v 1.1 1995/02/16 13:21:00 adam Exp $ +# +# Beskeder +gw.msg.subject: Din forespørgsel +gw.msg.greeting: Europagate email-Z39.50 gateway, dansk udgave. + +# Fejlmeddelelser +gw.err.nullbody: Ingen email-krop. Ingen forespørgsel foretaget. +gw.err.unimplemented: Kommandoen er endnu ikke implementeret +gw.err.unknown.command: Ukendt kommando +gw.err.term.expected: Søgeord forventet +gw.err.rp.expected: ')' forventet +gw.err.setname.expected: Navn på søgesæt forventet +gw.err.op.expected: Operator forventet +gw.err.bad.rp: Ubalanceret ')' +gw.err.unknown.qual: Ukendt kvalifikator +gw.err.double.qual: Kvalifikator(er) angivet to gange +gw.err.eq.qual: '=' forventet +gw.err.bad.relation: Fejl i relation +gw.err.trunc.not.left: Venstretrunkering er ikke tilladt +gw.err.trunc.not.both: Højre- og venstretrunkering ikke tilladt +gw.err.trunc.not.right: Højretrunkering er ikke tilladt + +# Navne på kommandoer og operatorer +ccl.command.find: find f +ccl.command.show: vis +ccl.command.base: base +ccl.command.help: help hjælp h +ccl.command.info: info i +ccl.command.continue: fortsæt fort +ccl.command.status: status +ccl.command.cancel: afbryd +ccl.token.and: og +ccl.token.or: eller +ccl.token.not: ikke +ccl.token.set: s + diff --git a/kernel/loc.bib b/kernel/loc.bib new file mode 100644 index 0000000..300b6d7 --- /dev/null +++ b/kernel/loc.bib @@ -0,0 +1,6 @@ +# Subset of bib-1 attributes map to CCL qualifiers for a target +# $Id: loc.bib,v 1.1 1995/02/16 13:21:00 adam Exp $ +# +term s=pw t=l,r +au u=1 s=pw +ti u=4 s=pw diff --git a/kernel/loc.res b/kernel/loc.res new file mode 100644 index 0000000..b517591 --- /dev/null +++ b/kernel/loc.res @@ -0,0 +1,9 @@ +# Email gateway - resource for a specific target +# $Id: loc.res,v 1.1 1995/02/16 13:21:00 adam Exp $ +# See p. 40-43 in Europagate, Background Study, Part II +gw.portno: 210 +gw.hostname: IBM2.LOC.gov +gw.description: LC Z39.50 Test Server Information, Library of Congress +gw.bibset: loc.bib +gw.bases: BOOKS NAMES + diff --git a/kernel/main.c b/kernel/main.c index c3e4f65..dbcbc89 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -2,7 +2,11 @@ * Europagate, 1995 * * $Log: main.c,v $ - * Revision 1.1 1995/02/15 17:45:29 adam + * Revision 1.2 1995/02/16 13:21:00 adam + * Organization of resource files for targets and conversion + * language implemented. + * + * Revision 1.1 1995/02/15 17:45:29 adam * First version of email gateway kernel. Email requests are read * from stdin. The output is transferred to an MTA if 'From' is * found in the header - or stdout if absent. No Z39.50 client is used. @@ -14,45 +18,54 @@ #include "kernel.h" -GwRes kernel_res; -CCL_bibset bibset; +GwRes kernel_res = NULL; +const char *default_res = "default.res"; +const char *target = NULL; +const char *lang = NULL; +CCL_bibset bibset = NULL; + FILE *reply_fd = stdout; int main (int argc, char **argv) { - char *bib_fname; - FILE *bib_inf; - gw_log_init (*argv); kernel_res = gw_res_init (); - bibset = ccl_qual_mk (); while (--argc > 0) { if (**++argv == '-') { switch (argv[0][1]) { - case 'b': + case 'd': + gw_log_level (GW_LOG_ALL); + break; + case 't': if (argv[0][2]) - bib_fname = argv[0]+2; + target = argv[0]+2; else if (argc > 0) { --argc; - bib_fname = *++argv; + target= *++argv; } else { - gw_log (GW_LOG_FATAL, "main", "missing bib filename"); + gw_log (GW_LOG_FATAL, "main", "missing target name"); exit (1); } - bib_inf = fopen (bib_fname, "r"); - if (!bib_inf) + break; + case 'l': + if (argv[0][2]) + lang = argv[0]+2; + else if (argc > 0) { - gw_log (GW_LOG_FATAL, "main", "cannot open %s", bib_fname); + --argc; + lang = *++argv; + } + else + { + gw_log (GW_LOG_FATAL, "main", "missing language name"); exit (1); } - ccl_qual_file (bibset, bib_inf); - fclose (bib_inf); break; default: gw_log (GW_LOG_FATAL, "main", "unknown option %s", *argv); @@ -60,17 +73,75 @@ int main (int argc, char **argv) } } else - { - int r; - r = gw_res_merge (kernel_res, *argv); - if (r) - { - gw_log (GW_LOG_FATAL, "main", "failed to read resource " - "file %s", *argv); - exit (1); - } - } + default_res = *argv; } + read_kernel_res (); urp (stdin); return 0; } + +void read_kernel_res (void) +{ + char path_prefix[128]; + char fname[160]; + const char *v; + char resource_name[256]; + + bibset = ccl_qual_mk (); + + gw_log (GW_LOG_DEBUG, "main", "reading kernel resource, default %s", + default_res); + if (target) + gw_log (GW_LOG_DEBUG, "main", "reading kernel resource, target %s", + target); + if (lang) + gw_log (GW_LOG_DEBUG, "main", "reading kernel resource, lang %s", + lang); + if (kernel_res) + gw_res_close (kernel_res); + kernel_res = gw_res_init (); + if (gw_res_merge (kernel_res, default_res)) + { + gw_log (GW_LOG_WARN, "main", "Couldn't read resource file %s", + default_res); + return; + } + strcpy (path_prefix, gw_res_get (kernel_res, "gw.path", ".")); + + if (target) + { + sprintf (resource_name, "gw.target.%s", target); + v = gw_res_get (kernel_res, resource_name, NULL); + if (v) + { + sprintf (fname, "%s/%s", path_prefix, v); + gw_res_merge (kernel_res, fname); + } + } + if (lang) + { + sprintf (resource_name, "gw.lang.%s", lang); + v = gw_res_get (kernel_res, resource_name, NULL); + if (v) + { + sprintf (fname, "%s/%s", path_prefix, v); + gw_res_merge (kernel_res, fname); + } + } + v = gw_res_get (kernel_res, "gw.bibset", NULL); + if (v) + { + FILE *bib_inf; + + sprintf (fname, "%s/%s", path_prefix, v); + bib_inf = fopen (fname, "r"); + if (!bib_inf) + gw_log (GW_LOG_WARN, "main", "cannot open %s", fname); + else + { + gw_log (GW_LOG_DEBUG, "main", "reading bib file %s", fname); + ccl_qual_file (bibset, bib_inf); + fclose (bib_inf); + } + } +} diff --git a/kernel/urp.c b/kernel/urp.c index b8a27a8..dce2ba8 100644 --- a/kernel/urp.c +++ b/kernel/urp.c @@ -2,7 +2,11 @@ * Europagate, 1995 * * $Log: urp.c,v $ - * Revision 1.1 1995/02/15 17:45:30 adam + * Revision 1.2 1995/02/16 13:21:00 adam + * Organization of resource files for targets and conversion + * language implemented. + * + * Revision 1.1 1995/02/15 17:45:30 adam * First version of email gateway kernel. Email requests are read * from stdin. The output is transferred to an MTA if 'From' is * found in the header - or stdout if absent. No Z39.50 client is used. @@ -34,6 +38,7 @@ static struct command_word { { "continue", "continue" }, { "status", "status" }, { "cancel", "cancel" }, +{ "target", "target" }, { NULL, NULL } }; @@ -76,6 +81,38 @@ const char *resource_prefix) return 0; } +static struct error_no_struct { + int no; + char *resource_name; +} error_ccl_tab[] = { +{ CCL_ERR_OK, "ok"}, +{ CCL_ERR_TERM_EXPECTED, "term.expected" }, +{ CCL_ERR_RP_EXPECTED, "rp.expected" }, +{ CCL_ERR_SETNAME_EXPECTED, "setname.expected" }, +{ CCL_ERR_OP_EXPECTED, "op.expected" }, +{ CCL_ERR_BAD_RP, "bad.rp" }, +{ CCL_ERR_UNKNOWN_QUAL, "unknown.qual" }, +{ CCL_ERR_DOUBLE_QUAL, "double.qual" }, +{ CCL_ERR_EQ_EXPECTED, "eq.expected" }, +{ CCL_ERR_BAD_RELATION, "bad.relation" }, +{ CCL_ERR_TRUNC_NOT_LEFT, "trunc.not.left" }, +{ CCL_ERR_TRUNC_NOT_BOTH, "trunc.not.both" }, +{ CCL_ERR_TRUNC_NOT_RIGHT, "trunc.not.right" }, +{ 0, NULL } +}; + +static char *error_no_search (struct error_no_struct *tab, int no) +{ + struct error_no_struct *p = tab; + while (p->resource_name) + { + if (no == p->no) + return p->resource_name; + p++; + } + return NULL; +} + static int email_header (FILE *inf, char *from_str) { *from_str = '\0'; @@ -98,8 +135,20 @@ static int exec_find (struct ccl_token *list) rpn = ccl_find (bibset, list, &error, &pos); if (!rpn) { - fprintf (reply_fd, " %*s^ - ", pos - line_buf, " "); - fprintf (reply_fd, "%s\n", ccl_err_msg (error)); + const char *v = NULL, *n; + char name[128]; + + fprintf (reply_fd, " %*s^ - ", pos - line_buf, " "); + + n = error_no_search (error_ccl_tab, error); + if (n) + { + sprintf (name, "gw.err.%s", n); + v = gw_res_get (kernel_res, name, NULL); + } + if (!v) + v = ccl_err_msg (error); + fprintf (reply_fd, "%s\n", v); return -1; } ccl_pr_tree (rpn, reply_fd); @@ -112,13 +161,8 @@ static int exec_command (const char *str) struct ccl_token *cmd = ccl_tokenize (str); int no; - ccl_token_and = gw_res_get (kernel_res, "ccl.token.and", "and"); - ccl_token_or = gw_res_get (kernel_res, "ccl.token.or", "or"); - ccl_token_not = gw_res_get (kernel_res, "ccl.token.not", "not"); - ccl_token_set = gw_res_get (kernel_res, "ccl.token.set", "set"); - fprintf (reply_fd, "> %s", str); - if (cmd->kind == CCL_TOK_TERM && + if (cmd->kind != CCL_TOK_EOL && (no = command_search (command_tab, cmd, "ccl.command."))) { switch (no) @@ -126,15 +170,18 @@ static int exec_command (const char *str) case 1: return exec_find (cmd->next); break; - case 2: - fprintf (reply_fd, " show found\n"); - break; default: - fprintf (reply_fd, " unimplemented command\n"); + fprintf (reply_fd, " %s\n", + gw_res_get (kernel_res, "gw.err.unimplemented", + "Not implemented yet")); } } else - fprintf (reply_fd, " ^ unknown command\n"); + { + fprintf (reply_fd, " ^ %s\n", + gw_res_get (kernel_res, "gw.err.unknown.command", + "unknown command")); + } return 0; } @@ -164,12 +211,18 @@ int urp (FILE *inf) return -1; } } + else + gw_log (GW_LOG_WARN, "urp", "No From in email header"); fprintf (reply_fd, "%s\n", gw_res_get (kernel_res, "gw.msg.greeting", "Email->Z39.50 gateway")); while (fgets (line_buf, LINE_MAX, inf)) { if (line_buf[0] == '\n') break; + ccl_token_and = gw_res_get (kernel_res, "ccl.token.and", "and"); + ccl_token_or = gw_res_get (kernel_res, "ccl.token.or", "or"); + ccl_token_not = gw_res_get (kernel_res, "ccl.token.not", "not"); + ccl_token_set = gw_res_get (kernel_res, "ccl.token.set", "set"); if (isalpha (line_buf[0])) exec_command (line_buf); command_no++; -- 1.7.10.4