+ max_number = gw_res_int (info.kernel_res, "gw.max.show", 100);
+ if (number > max_number)
+ number = max_number;
+ gw_log (GW_LOG_DEBUG, KERNEL_LOG, "present in set %s", set);
+ gw_log (GW_LOG_DEBUG, KERNEL_LOG, "present of %d records from offset %d",
+ number, offset);
+ zp = zass_p_present(info.zass, (char *) set, offset, number);
+ if (zp)
+ {
+ int i;
+ zass_record *pp;
+ int record_log_fd = -1;
+ const char *record_log_name;
+
+ record_log_name = gw_res_get (info.kernel_res, "gw.marc.log",
+ NULL);
+ if (record_log_name)
+ {
+ record_log_fd = open (record_log_name,
+ O_WRONLY|O_CREAT|O_APPEND, 0666);
+ if (record_log_fd == -1)
+ gw_log (GW_LOG_WARN|GW_LOG_ERRNO, "Cannot open %s",
+ record_log_name);
+ }
+ fprintf (reply_fd, gw_res_get (info.kernel_res,
+ "gw.msg.records",
+ "Got %d records from set %s"),
+ zp->num, set);
+ fprintf (reply_fd, "\n");
+ for (i = 0, pp = zp->records; pp; pp = pp->next, i++)
+ {
+ Iso2709Rec rec;
+#if USE_FML
+ const char *arg_ar[5];
+#endif
+ fprintf (reply_fd, "--- %d/%d ---\n",
+ i+offset, offset+zp->num-1);
+ if (!gw_res_get (info.kernel_res, "gw.ignore.which", NULL))
+ {
+ if (pp->which == ZASS_REC_DIAG)
+ {
+ display_diag_error (pp->errcode, pp->errstring);
+ continue;
+ }
+ else if (pp->which != ZASS_REC_USMARC)
+ {
+ fprintf (reply_fd, "Unknown record kind %d\n",
+ pp->which);
+ continue;
+ }
+ }
+ if (record_log_fd != -1)
+ write (record_log_fd, pp->record, strlen(pp->record));
+ rec = iso2709_cvt (pp->record);
+ if (rec)
+ {
+#if USE_FML
+ strcpy (format_str,
+ gw_res_get (info.kernel_res,
+ "gw.display.format", ""));
+ 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_str &&
+ (!strcmp (format_str, "0") || !strcmp (format_str, "1")
+ || !strcmp(format_str, "2")))
+ {
+ arg_ar[0] = "\\f";
+ arg_ar[1] = format_str;
+ arg_ar[2] = " \\list";
+ arg_ar[3] = marc_to_str (info.fml, rec);
+ arg_ar[4] = NULL;
+ fml_exec_call_argv (info.fml, arg_ar);
+ }
+ else
+ iso2709_display (rec, reply_fd);
+#else
+ iso2709_display (rec, reply_fd);
+#endif
+ iso2709_rm (rec);
+ }
+ else
+ fprintf (reply_fd, "Not a MARC record\n");
+ }
+ if (record_log_fd != -1)
+ close (record_log_fd);
+ }
+}
+
+static int exec_show (struct ccl_token *list)
+{
+ static struct command_word show_tab [] =
+ {
+ { "f", "format"},
+ { "p", "position"},
+ { NULL, NULL }
+ };
+ char tmp_str[20];
+ struct ccl_token *set_token = NULL;
+ struct ccl_token *format_token = NULL;
+ struct ccl_token *li = list;
+ int no_of_present = 0;
+
+ assert (info.zass);
+ while (li->kind != CCL_TOK_EOL)
+ {
+ int modifier_no = 0;
+ if (li->next->kind == CCL_TOK_EQ)
+ {
+ if (li->kind == CCL_TOK_SET) /* set = <name> ? */
+ {
+ li = li->next->next;
+ set_token = li;
+ }
+ else
+ {
+ modifier_no = command_search (show_tab, li, "ccl.token.");
+ if (!modifier_no)
+ {
+ fprintf (reply_fd, "Unknown modifier in show\n");
+ return -1;
+ }
+ li = li->next->next;
+ if (modifier_no == 1) /* f = <name> ? */
+ format_token = li;
+ else if (modifier_no == 2) /* p = <name> ? */
+ {
+ if (li->kind != CCL_TOK_EOL /* p = <name> - <name> ? */
+ && li->next->kind == CCL_TOK_MINUS
+ && li->next->next != CCL_TOK_EOL)
+ li = li->next->next;
+ }
+ }
+ if (!li->next)
+ {
+ fprintf (reply_fd, "%s\n", "Missing token after '='");
+ return -2;
+ }
+ li = li->next;
+ }
+ else
+ {
+ int len = li->len;
+ memcpy (tmp_str, li->name, len);
+ tmp_str[len] = '\0';
+ if (atoi(tmp_str) <= 0)
+ {
+ fprintf (reply_fd, "%s\n",
+ gw_res_get (info.kernel_res, "gw.err.bad.show",
+ "Syntax error"));
+ return -3;
+ }
+ li = li->next;
+ }
+ }
+ if (set_token)
+ gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Got set=%.*s", set_token->len,
+ set_token->name);
+ if (format_token)
+ gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Got format=%.*s", format_token->len,
+ format_token->name);
+
+ li = list;
+ while (li->kind != CCL_TOK_EOL)
+ {
+ int modifier_no = 0;
+ int offset = 0;
+ int number = 0;
+ int len;
+ if (li->next->kind == CCL_TOK_EQ && li->kind != CCL_TOK_SET)
+ {
+ modifier_no = command_search (show_tab, li, "ccl.token.");
+ li = li->next->next;
+ if (modifier_no == 2) /* p = <name> ? */
+ {
+ if (li->kind != CCL_TOK_EOL /* p = <name> - <name> ? */
+ && li->next->kind == CCL_TOK_MINUS
+ && li->next->next != CCL_TOK_EOL)
+ {
+ len = li->len;
+ memcpy (tmp_str, li->name, len);
+ tmp_str [len] = '\0';
+ offset = atoi (tmp_str);
+ li = li->next->next;
+
+ len = li->len;
+ memcpy (tmp_str, li->name, len);
+ tmp_str [len] = '\0';
+ number = atoi (tmp_str) - offset + 1;
+ if (number <= 0)
+ {
+ fprintf (reply_fd, "%s\n",
+ gw_res_get (info.kernel_res,
+ "gw.err.pos.show",
+ "Starting position "
+ "greater than ending position"));
+ return -3;
+ }
+ }
+ else
+ {
+ len = li->len;
+ memcpy (tmp_str, li->name, len);
+ tmp_str [len] = '\0';
+ offset = atoi (tmp_str);
+ number = 1;
+ }
+ }
+ li = li->next;
+ }
+ else if (li->kind == CCL_TOK_TERM)
+ {
+ len = li->len;
+ memcpy (tmp_str, li->name, len);
+ tmp_str[len] = '\0';
+ number = atoi (tmp_str);
+ offset = 1;
+ li = li->next;
+ }
+ if (offset > 0 && number > 0)
+ {
+ struct gw_user_set *us;
+
+ if (set_token)
+ {
+ len = set_token->len;
+ memcpy (tmp_str, set_token->name, len);
+ tmp_str[len] = '\0';
+ us = user_set_search (tmp_str);
+ }
+ else
+ us = user_set_search (NULL);
+ if (us && us->hits != -1) /* proper result-set? */
+ {
+ if (offset <= us->hits)
+ {
+ if (offset+number-1 > us->hits)
+ number = us->hits - offset+1;
+ present (us->name, offset, number, format_token);
+ info.next_position = offset+number;
+ }
+ }
+ else if (!no_of_present) /* display error message once! */
+ {
+ fprintf (reply_fd, "%s\n",
+ gw_res_get (info.kernel_res, "gw.err.no.set",
+ "No result-set generated"));
+ }
+ no_of_present++;
+ }
+ }
+ if (!no_of_present) /* no records shown so far? */
+ {
+ struct gw_user_set *us;
+ int default_show;
+
+ us = user_set_search (NULL);
+ if (us && us->hits != -1) /* proper result-set? */
+ {
+ 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 */
+ {
+ fprintf (reply_fd, "%s\n",
+ gw_res_get (info.kernel_res, "gw.err.no.set",
+ "No result-set generated"));
+ return -3;
+ }
+ }
+ return 0;
+}
+
+static void show_def (void)
+{
+ fprintf (reply_fd, "format %s\n", gw_res_get
+ (info.kernel_res, "gw.display.format", ""));
+ fprintf (reply_fd, "autoshow %s\n", gw_res_get
+ (info.kernel_res, "gw.auto.show", ""));
+ fprintf (reply_fd, "defaultshow %s\n", gw_res_get
+ (info.kernel_res, "gw.default.show", ""));
+ fprintf (reply_fd, "language %s\n", gw_res_get
+ (info.kernel_res, "gw.language", ""));
+}
+
+static int exec_def (struct ccl_token *list)
+{
+ const char *name = NULL;
+ char value[128];
+ char fname[256];
+ static struct command_word def_tab [] =
+ {
+ { "reset", "reset" },
+ { "show", "show" },
+ { "f", "format"},
+ { "autoshow", "autoshow" },
+ { "defaultshow", "defaultshow" },
+ { "lang", "language" },
+ { NULL, NULL }
+ };
+
+ if (info.userid < 0)
+ return -1;
+ sprintf (fname, "user.%d.r", info.userid);
+
+ if (list->kind == CCL_TOK_EOL)
+ show_def ();
+ else
+ {
+ int setting_no = command_search (def_tab, list, "ccl.token.");
+
+ if (!setting_no)
+ {
+ fprintf (reply_fd, "Unknown setting in def\n");
+ return -1;
+ }
+ if (setting_no == 1)
+ {
+ unlink (fname);
+ read_kernel_res ();
+ return 0;
+ }
+ else if (setting_no == 2)
+ {
+ show_def ();
+ return 0;
+ }
+ list = list->next;
+ if (list->kind == CCL_TOK_EOL)
+ return 0;
+ strncpy (value, list->name, 127);
+ value[(size_t) list->len] = '\0';
+ switch (setting_no)
+ {
+ case 3:
+ name = "gw.display.format";
+ break;
+ case 4:
+ name = "gw.auto.show";
+ break;
+ case 5:
+ name = "gw.default.show";
+ break;
+ case 6:
+ name = "gw.language";
+ break;
+ default:
+ return 0;
+ }
+ gw_log (GW_LOG_DEBUG, KERNEL_LOG, "update file %s with %s=%s",
+ fname, name, value);
+ gw_res_put (info.kernel_res, "gw.username", info.from_str, fname);
+ gw_res_put (info.kernel_res, name, value, fname);
+ gw_res_commit (info.kernel_res, fname);
+ if (setting_no == 6)
+ read_kernel_res ();
+ }
+ return 0;
+}
+
+
+/*
+ * 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;
+ const char *cp = str;
+ int no;
+
+ while (*cp && *cp != ' ' && *cp != '\n' && *cp != '\t' && *cp != '\r')
+ cp++;
+
+ *stop_flag = 0;
+ no = command_search_str (command_tab, str, cp-str, "ccl.command.");
+ if (no)