* Europagate, 1995
*
* $Log: urp.c,v $
- * Revision 1.18 1995/03/01 14:32:26 adam
+ * Revision 1.21 1995/03/27 08:24:04 adam
+ * First use of gip interface and gw-db.
+ * First work on eti program.
+ *
+ * Revision 1.20 1995/03/03 17:19:17 adam
+ * Smarter presentation. Bug fix in email header interpretation.
+ *
+ * Revision 1.19 1995/03/02 09:32:11 adam
+ * New presentation formats. f0=full, f1=brief, f2=mid
+ *
+ * Revision 1.18 1995/03/01 14:32:26 adam
* Better diagnostics. Default is, that only one database selected when
* several are known.
*
static void put_esc_str (const char *s)
{
- int escape_flag = 0;
while (*s)
+ tty_emit (*s++);
+}
+
+int lgets (char *buf, int max, int fd)
+{
+ int r, no = 0;
+
+ --max;
+ while (no <= max)
{
- if (*s == '\\' && s[1])
- {
- switch (*++s)
- {
- case 'n':
- fputc ('\n', reply_fd);
- break;
- case 't':
- fputc ('\t', reply_fd);
- break;
- default:
- fputc (*s, reply_fd);
- break;
- }
- escape_flag = 1;
- }
- else
- {
- if (*s != ' ' || !escape_flag)
- fputc (*s, reply_fd);
- escape_flag = 0;
- }
- s++;
+ if ((r=read (fd, buf+no, 1)) != 1)
+ {
+ if (r == -1)
+ gw_log (GW_LOG_WARN, KERNEL_LOG, "read fail");
+ buf[no] = '\0';
+ return 0;
+ }
+ if (buf[no] == 1)
+ return 0;
+ if (buf[no++] == '\n')
+ break;
}
+ buf[no] = '\0';
+ return 1;
}
static int reopen_target (void)
return NULL;
}
-static int email_header (FILE *inf, char *from_str, char *subject_str)
+static int email_header (int fd, char *from_str, char *subject_str)
{
*from_str = '\0';
*subject_str = '\0';
- while (fgets (line_buf, LINE_MAX, inf))
+ while (lgets (line_buf, LINE_MAX, fd))
{
if (line_buf[0] == '\n')
return 0;
static int exec_help (struct ccl_token *list)
{
+ static char *sep = "-------------------------------\\n";
help_general ();
-#if 0
+#if 1
+ put_esc_str (sep);
put_esc_str (gw_res_get (info.kernel_res, "gw.help.target",
"target <name> - selects a given target\n"));
+ put_esc_str (sep);
put_esc_str (gw_res_get (info.kernel_res, "gw.help.base",
"base <base>.. - selects databases\n"));
+ put_esc_str (sep);
put_esc_str (gw_res_get (info.kernel_res, "gw.help.find",
"find <query> - performs a search request\n"));
+ put_esc_str (sep);
put_esc_str (gw_res_get (info.kernel_res, "gw.help.show",
"show <spec> - retrieves and displays "
"records\n"));
- put_esc_str (gw_res_get (info.kernel_res, "gw.help.help",
- "help - displays help\n"));
#endif
return 0;
}
const struct zass_presentent *zp;
int len;
int max_number;
- char format_str[40];
+ char format_str[16];
max_number = atoi (gw_res_get (info.kernel_res, "gw.max.show",
"200"));
if (format_token)
{
len = format_token->len;
+ if (len >= sizeof(format_str))
+ len = sizeof(format_str)-1;
memcpy (format_str, format_token->name, len);
format_str[len] = '\0';
}
if (info.fml && format_token &&
- (!strcmp (format_str, "0") || !strcmp (format_str, "1")))
+ (!strcmp (format_str, "0") || !strcmp (format_str, "1")
+ || !strcmp(format_str, "2")))
{
arg_ar[0] = "\\f";
arg_ar[1] = format_str;
return 0;
}
-int urp (FILE *inf)
+int urp (int fd)
{
char from_str[128];
char subject_str[128];
int command_no = 0;
char *reply_fname = NULL;
- if (email_header (inf, from_str, subject_str))
+ if (email_header (fd, from_str, subject_str))
{
gw_log (GW_LOG_WARN, KERNEL_LOG, "No message body");
return -1;
}
+ tty_init (stdout, 40, 70);
if (*from_str)
{
reply_fname = tempnam (gw_res_get (info.kernel_res,
reply_fname);
return -1;
}
+ tty_init (reply_fd, 0, 0);
fprintf (reply_fd, "From: %s\n",
gw_res_get (info.kernel_res, "gw.msg.from","Email-gateway"));
fprintf (reply_fd, "Subject: ");
gw_log (GW_LOG_WARN, KERNEL_LOG, "No From in email header");
fprintf (reply_fd, "%s\n", gw_res_get (info.kernel_res, "gw.msg.greeting",
"Email->Z39.50 gateway"));
- while (fgets (line_buf, LINE_MAX, inf))
+ while (lgets (line_buf, LINE_MAX, fd))
{
char *cp;
if (line_buf[0] == '\n')
- break;
+ if (command_no)
+ {
+ while (lgets (line_buf, LINE_MAX, fd))
+ ;
+ break;
+ }
+ else
+ continue;
if ((cp = strchr (line_buf, '\n')))
*cp = '\0';
gw_log (GW_LOG_ACCT, KERNEL_LOG, "cmd: %s", line_buf);