* Europagate, 1995
*
* $Log: urp.c,v $
- * Revision 1.31 1995/05/01 12:43:38 adam
+ * Revision 1.32 1995/05/03 07:37:46 adam
+ * CCL commands stop/continue implemented. New functions gw_res_{int,bool}
+ * are used when possible.
+ *
+ * Revision 1.31 1995/05/01 12:43:38 adam
* First work on resource monitor program.
*
* Revision 1.30 1995/04/20 16:10:47 adam
*
*/
+/*
+ Todo:
+ stop/continue commands
+ info/status (other name?)
+ per-user definitions
+ better persistence diagnostics
+ show - position continuation
+ resource gw.path - use chdir call instead
+
+ Optional:
+ automatic information about target-aliases: name, query-support, etc.
+ */
+
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
char *resource_suffix;
} command_tab [] =
{
-{ "find", "find"},
-{ "show", "show"},
-{ "base", "base" },
-{ "help", "help" },
-{ "info", "info" },
+{ "find", "find"},
+{ "show", "show"},
+{ "base", "base" },
+{ "help", "help" },
+{ "info", "info" },
{ "continue", "continue" },
-{ "status", "status" },
-{ "cancel", "cancel" },
-{ "target", "target" },
-{ "stop", "stop" },
-{ "account", "account" },
+{ "status", "status" },
+{ "stop", "stop" },
+{ "target", "target" },
+{ "cancel", "cancel" },
+{ "account", "account" },
{ NULL, NULL }
};
static char *sep = "-------------------------------\\n";
help_general ();
-#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 (gw_res_get (info.kernel_res, "gw.help.show",
"show <spec> - retrieves and displays "
"records\n"));
-#endif
return 0;
}
strcpy (setname, "Default");
else
sprintf (setname, "%d", info.setno);
+ info.next_position = 1;
+ if (info.setno >= 0)
+ info.setno++;
rpn = ccl_find (info.bibset, list, &error, &pos);
if (!rpn)
{
gw_res_get (info.kernel_res, "gw.msg.hits", "hit(s)"));
us = user_set_add (setname, p->num, info.database, rpn, 1, search_str);
fprintf (reply_fd, "Result-set %s created\n", setname);
- if (info.setno >= 0)
- info.setno++;
return 0;
}
static int exec_status (struct ccl_token *list)
{
- fprintf (reply_fd, " Name Hits Database Find\n");
+ fprintf (reply_fd, " Name Hits Database Find\n");
exec_status_r (info.sets);
return 0;
}
int max_number;
char format_str[16];
- max_number = atoi (gw_res_get (info.kernel_res, "gw.max.show",
- "200"));
+ max_number = gw_res_int (info.kernel_res, "gw.max.show", 200);
if (number > max_number)
number = max_number;
gw_log (GW_LOG_DEBUG, KERNEL_LOG, "present in set %s", set);
us = user_set_search (NULL);
if (us && us->hits != -1) /* proper result-set? */
{
- default_show = atoi (gw_res_get (info.kernel_res,
- "gw.default.show", "20"));
- if (us->hits > default_show)
- present (us->name, 1, default_show, format_token);
- else if (us->hits > 0)
- present (us->name, 1, us->hits, format_token);
+ default_show = gw_res_int (info.kernel_res, "gw.default.show", 20);
+ if (us->hits >= info.next_position + default_show)
+ {
+ present (us->name, info.next_position, default_show,
+ format_token);
+ info.next_position += default_show;
+ }
+ else if (us->hits >= info.next_position)
+ {
+ present (us->name, info.next_position,
+ us->hits - info.next_position + 1,
+ format_token);
+ info.next_position = us->hits + 1;
+ }
}
else /* display error message */
{
return 0;
}
-static int exec_command (const char *str)
+/*
+ * exec_command: parse and execute ccl command in str.
+ * str: ccl command string
+ * stop_flag pointer to integer. On completion the integer
+ * is 1 (stop) or 2 (continue); 0 (other command)
+ * return: 0 success; non-zero otherwise
+ */
+static int exec_command (const char *str, int *stop_flag)
{
struct ccl_token *cmd = ccl_tokenize (str);
int no;
+ *stop_flag = 0;
if (cmd->kind != CCL_TOK_EOL &&
(no = command_search (command_tab, cmd, "ccl.command.")))
{
return exec_base (cmd->next);
case 4:
return exec_help (cmd->next);
+ case 6: /* continue */
+ *stop_flag = 2;
+ return 0;
case 7:
return exec_status (cmd->next);
+ case 8: /* stop */
+ info.zass = NULL;
+ *info.target = 0;
+ *stop_flag = 1;
+ read_kernel_res();
+ return 0;
case 9:
return exec_target (cmd->next);
case 11:
{
info.reply_fname = tempnam (gw_res_get (info.kernel_res,
"gw.reply.tmp.dir", NULL),
- gw_res_get (info.kernel_res,
+ gw_res_get (info.kernel_res,
"gw.reply.tmp.prefix", "gwr"));
reply_fd = fopen (info.reply_fname, "w");
int urp_command (struct str_queue *queue)
{
char *cp;
+ int stop_flag;
while (str_queue_deq (queue, line_buf, LINE_MAX))
{
*cp = '\0';
gw_log (GW_LOG_ACCT, KERNEL_LOG, "cmd: %s", line_buf);
if (isalpha (line_buf[0]))
- exec_command (line_buf);
+ {
+ exec_command (line_buf, &stop_flag);
+ if (stop_flag)
+ {
+ info.command_no++; /* prevent help! */
+ while (str_queue_deq (queue, line_buf, LINE_MAX))
+ ;
+ return stop_flag;
+ }
+ }
info.command_no++;
}
return 0;