- static struct {
- char *cmd;
- int (*fun)(char *arg);
- char *ad;
- } cmd[] = {
- {"open", cmd_open, "('tcp'|'ssl')':<host>[':'<port>][/<db>]"},
- {"quit", cmd_quit, ""},
- {"find", cmd_find, "<query>"},
- {"delete", cmd_delete, "<setname>"},
- {"base", cmd_base, "<base-name>"},
- {"show", cmd_show, "<rec#>['+'<#recs>['+'<setname>]]"},
- {"scan", cmd_scan, "<term>"},
- {"sort", cmd_sort, "<sortkey> <flag> <sortkey> <flag> ..."},
- {"sort+", cmd_sort_newset, "<sortkey> <flag> <sortkey> <flag> ..."},
- {"authentication", cmd_authentication, "<acctstring>"},
- {"lslb", cmd_lslb, "<largeSetLowerBound>"},
- {"ssub", cmd_ssub, "<smallSetUpperBound>"},
- {"mspn", cmd_mspn, "<mediumSetPresentNumber>"},
- {"status", cmd_status, ""},
- {"setnames", cmd_setnames, ""},
- {"cancel", cmd_cancel, ""},
- {"format", cmd_format, "<recordsyntax>"},
- {"schema", cmd_schema, "<schema>"},
- {"elements", cmd_elements, "<elementSetName>"},
- {"close", cmd_close, ""},
- {"attributeset", cmd_attributeset, "<attrset>"},
- {"querytype", cmd_querytype, "<type>"},
- {"refid", cmd_refid, "<id>"},
- {"itemorder", cmd_itemorder, "ill|item <itemno>"},
- {"update", cmd_update, "<item>"},
- {"packagename", cmd_packagename, "<packagename>"},
- {"proxy", cmd_proxy, "('tcp'|'osi')':'[<tsel>'/']<host>[':'<port>]"},
- {".", cmd_source, "<filename>"},
- {"!", cmd_subshell, "Subshell command"},
- /* Server Admin Functions */
- {"adm-reindex", cmd_adm_reindex, "<database-name>"},
- {"adm-truncate", cmd_adm_truncate, "('database'|'index')<object-name>"},
- {"adm-create", cmd_adm_create, ""},
- {"adm-drop", cmd_adm_drop, "('database'|'index')<object-name>"},
- {"adm-import", cmd_adm_import, "<record-type> <dir> <pattern>"},
- {"adm-refresh", cmd_adm_refresh, ""},
- {"adm-commit", cmd_adm_commit, ""},
- {"adm-shutdown", cmd_adm_shutdown, ""},
- {"adm-startup", cmd_adm_startup, ""},
- {0,0}
- };
+ int error, pos;
+ struct ccl_rpn_node *rpn=NULL;
+
+
+ rpn = ccl_find_str (bibset, arg, &error, &pos);
+
+ if (error) {
+ printf ("%*s^ - ", 3+strlen(last_cmd)+1+pos, " ");
+ printf ("%s\n", ccl_err_msg (error));
+ }
+ else
+ {
+ if (rpn)
+ {
+ ccl_pr_tree(rpn, stdout);
+ }
+ }
+ if (rpn)
+ ccl_rpn_delete(rpn);
+
+ printf ("\n");
+
+ return 0;
+}
+
+
+int cmd_set_otherinfo(const char* args)
+{
+ char oid[101], otherinfoString[101];
+ int otherinfoNo;
+ int sscan_res;
+ int oidval;
+
+ sscan_res = sscanf (args, "%d %100[^ ] %100s", &otherinfoNo, oid, otherinfoString);
+ if(sscan_res==1) {
+ /* reset this otherinfo */
+ if(otherinfoNo>=maxOtherInfosSupported) {
+ printf("Error otherinfo index to large (%d>%d)\n",otherinfoNo,maxOtherInfosSupported);
+ }
+ extraOtherInfos[otherinfoNo].oidval = -1;
+ if(extraOtherInfos[otherinfoNo].value) free(extraOtherInfos[otherinfoNo].value);
+ return 0;
+ }
+ if (sscan_res<3) {
+ printf("Error in set_otherinfo command \n");
+ return 0;
+ }
+
+ if(otherinfoNo>=maxOtherInfosSupported) {
+ printf("Error otherinfo index to large (%d>%d)\n",otherinfoNo,maxOtherInfosSupported);
+ }
+
+ oidval = oid_getvalbyname (oid);
+ if(oidval == -1 ) {
+ printf("Error in set_otherinfo command unknown oid %s \n",oid);
+ return 0;
+ }
+ extraOtherInfos[otherinfoNo].oidval = oidval;
+ if(extraOtherInfos[otherinfoNo].value) free(extraOtherInfos[otherinfoNo].value);
+ extraOtherInfos[otherinfoNo].value = strdup(otherinfoString);
+
+ return 0;
+}
+
+int cmd_list_otherinfo(const char* args)
+{
+ int i;
+
+ if(strlen(args)>0) {
+ i = atoi(args);
+ if( i >= maxOtherInfosSupported ) {
+ printf("Error otherinfo index to large (%d>%d)\n",i,maxOtherInfosSupported);
+ return 0;
+ }
+
+ if(extraOtherInfos[i].oidval != -1)
+ printf(" otherinfo %d %s %s\n",
+ i,
+ yaz_z3950_oid_value_to_str(
+ (enum oid_value) extraOtherInfos[i].oidval,
+ CLASS_RECSYN),
+ extraOtherInfos[i].value);
+
+ } else {
+ for(i=0; i<maxOtherInfosSupported; ++i) {
+ if(extraOtherInfos[i].oidval != -1)
+ printf(" otherinfo %d %s %s\n",
+ i,
+ yaz_z3950_oid_value_to_str(
+ (enum oid_value) extraOtherInfos[i].oidval,
+ CLASS_RECSYN),
+ extraOtherInfos[i].value);
+ }
+
+ }
+ return 0;
+}
+
+
+int cmd_list_all(const char* args) {
+ int i;
+
+ /* connection options */
+ if(conn) {
+ printf("Connected to : %s\n",last_open_command);
+ } else {
+ if(last_open_command)
+ printf("Not connected to : %s\n",last_open_command);
+ else
+ printf("Not connected : \n");
+
+ }
+ if(yazProxy) printf("using proxy : %s\n",yazProxy);
+
+ printf("auto_reconnect : %s\n",auto_reconnect?"on":"off");
+
+ if (!auth) {
+ printf("Authentication : none\n");
+ } else {
+ switch(auth->which) {
+ case Z_IdAuthentication_idPass:
+ printf("Authentication : IdPass\n");
+ printf(" Login User : %s\n",auth->u.idPass->userId?auth->u.idPass->userId:"");
+ printf(" Login Group : %s\n",auth->u.idPass->groupId?auth->u.idPass->groupId:"");
+ printf(" Password : %s\n",auth->u.idPass->password?auth->u.idPass->password:"");
+ break;
+ case Z_IdAuthentication_open:
+ printf("Authentication : psOpen\n");
+ printf(" Open string : %s\n",auth->u.open);
+ break;
+ default:
+ printf("Authentication : Unknown\n");
+ }
+ }
+ if (negotiationCharset)
+ printf("Neg. Character set : `%s'\n", negotiationCharset);
+
+ /* bases */
+ printf("Bases : ");
+ for (i = 0; i<num_databaseNames; i++) printf("%s ",databaseNames[i]);
+ printf("\n");
+
+ /* Query options */
+ printf("CCL file : %s\n",ccl_fields);
+ printf("CQL file : %s\n",cql_fields);
+ printf("Query type : %s\n",query_type_as_string(queryType));
+
+ printf("Named Result Sets : %s\n",setnumber==-1?"off":"on");
+
+ /* piggy back options */
+ printf("ssub/lslb/mspn : %d/%d/%d\n",smallSetUpperBound,largeSetLowerBound,mediumSetPresentNumber);
+
+ /* print present related options */
+ printf("Format : %s\n",yaz_z3950_oid_value_to_str(recordsyntax,CLASS_RECSYN));
+ printf("Schema : %s\n",schema);
+ printf("Elements : %s\n",elementSetNames?elementSetNames->u.generic:"");
+
+ /* loging options */
+ printf("APDU log : %s\n",apdu_file?"on":"off");
+ printf("Record log : %s\n",marc_file?"on":"off");
+
+ /* other infos */
+ printf("Other Info: \n");
+ cmd_list_otherinfo("");
+
+ return 0;
+}
+
+int cmd_clear_otherinfo(const char* args)
+{
+ if(strlen(args)>0) {
+ int otherinfoNo;
+ otherinfoNo = atoi(args);
+ if( otherinfoNo >= maxOtherInfosSupported ) {
+ printf("Error otherinfo index to large (%d>%d)\n",otherinfoNo,maxOtherInfosSupported);
+ return 0;
+ }
+
+ if(extraOtherInfos[otherinfoNo].oidval != -1) {
+ /* only clear if set. */
+ extraOtherInfos[otherinfoNo].oidval=-1;
+ free(extraOtherInfos[otherinfoNo].value);
+ }
+ } else {
+ int i;
+
+ for(i=0; i<maxOtherInfosSupported; ++i) {
+ if (extraOtherInfos[i].oidval!=-1 ) {
+ extraOtherInfos[i].oidval=-1;
+ free(extraOtherInfos[i].value);
+ }
+ }
+ }
+ return 0;
+}
+
+static int cmd_help (const char *line);
+
+typedef char *(*completerFunctionType)(const char *text, int state);
+
+static struct {
+ char *cmd;
+ int (*fun)(const char *arg);
+ char *ad;
+ completerFunctionType rl_completerfunction;
+ int complete_filenames;
+ char **local_tabcompletes;
+} cmd_array[] = {
+ {"open", cmd_open, "('tcp'|'ssl')':<host>[':'<port>][/<db>]",NULL,0,NULL},
+ {"quit", cmd_quit, "",NULL,0,NULL},
+ {"find", cmd_find, "<query>",NULL,0,NULL},
+ {"delete", cmd_delete, "<setname>",NULL,0,NULL},
+ {"base", cmd_base, "<base-name>",NULL,0,NULL},
+ {"show", cmd_show, "<rec#>['+'<#recs>['+'<setname>]]",NULL,0,NULL},
+ {"scan", cmd_scan, "<term>",NULL,0,NULL},
+ {"sort", cmd_sort, "<sortkey> <flag> <sortkey> <flag> ...",NULL,0,NULL},
+ {"sort+", cmd_sort_newset, "<sortkey> <flag> <sortkey> <flag> ...",NULL,0,NULL},
+ {"authentication", cmd_authentication, "<acctstring>",NULL,0,NULL},
+ {"lslb", cmd_lslb, "<largeSetLowerBound>",NULL,0,NULL},
+ {"ssub", cmd_ssub, "<smallSetUpperBound>",NULL,0,NULL},
+ {"mspn", cmd_mspn, "<mediumSetPresentNumber>",NULL,0,NULL},
+ {"status", cmd_status, "",NULL,0,NULL},
+ {"setnames", cmd_setnames, "",NULL,0,NULL},
+ {"cancel", cmd_cancel, "",NULL,0,NULL},
+ {"format", cmd_format, "<recordsyntax>",complete_format,0,NULL},
+ {"schema", cmd_schema, "<schema>",complete_schema,0,NULL},
+ {"elements", cmd_elements, "<elementSetName>",NULL,0,NULL},
+ {"close", cmd_close, "",NULL,0,NULL},
+ {"attributeset", cmd_attributeset, "<attrset>",complete_attributeset,0,NULL},
+ {"querytype", cmd_querytype, "<type>",complete_querytype,0,NULL},
+ {"refid", cmd_refid, "<id>",NULL,0,NULL},
+ {"itemorder", cmd_itemorder, "ill|item <itemno>",NULL,0,NULL},
+ {"update", cmd_update, "<action> <recid> [<file>]",NULL,0,NULL},
+ {"update0", cmd_update0, "<action> <recid> [<file>]",NULL,0,NULL},
+ {"packagename", cmd_packagename, "<packagename>",NULL,0,NULL},
+ {"proxy", cmd_proxy, "[('tcp'|'ssl')]<host>[':'<port>]",NULL,0,NULL},
+ {"charset", cmd_charset, "<nego_charset> <output_charset>",NULL,0,NULL},
+ {"marccharset", cmd_marccharset, "<charset_name>",NULL,0,NULL},
+ {"lang", cmd_lang, "<language_code>",NULL,0,NULL},
+ {".", cmd_source, "<filename>",NULL,1,NULL},
+ {"!", cmd_subshell, "Subshell command",NULL,1,NULL},
+ {"set_apdufile", cmd_set_apdufile, "<filename>",NULL,1,NULL},
+ {"set_berfile", cmd_set_berfile, "<filename>",NULL,1,NULL},
+ {"set_marcdump", cmd_set_marcdump," <filename>",NULL,1,NULL},
+ {"set_cclfile", cmd_set_cclfile," <filename>",NULL,1,NULL},
+ {"set_cqlfile", cmd_set_cqlfile," <filename>",NULL,1,NULL},
+ {"set_auto_reconnect", cmd_set_auto_reconnect," on|off",complete_auto_reconnect,1,NULL},
+ {"set_otherinfo", cmd_set_otherinfo,"<otherinfoinddex> <oid> <string>",NULL,0,NULL},
+ {"register_oid", cmd_register_oid,"<name> <class> <oid>",NULL,0,NULL},
+ {"push_command", cmd_push_command,"<command>",command_generator,0,NULL},
+ {"register_tab", cmd_register_tab,"<commandname> <tab>",command_generator,0,NULL},
+ {"cclparse", cmd_cclparse,"<ccl find command>",NULL,0,NULL},
+ {"list_otherinfo",cmd_list_otherinfo,"[otherinfoinddex]",NULL,0,NULL},
+ {"list_all",cmd_list_all,"",NULL,0,NULL},
+ {"clear_otherinfo",cmd_clear_otherinfo,"",NULL,0,NULL},
+ /* Server Admin Functions */
+ {"adm-reindex", cmd_adm_reindex, "<database-name>",NULL,0,NULL},
+ {"adm-truncate", cmd_adm_truncate, "('database'|'index')<object-name>",NULL,0,NULL},
+ {"adm-create", cmd_adm_create, "",NULL,0,NULL},
+ {"adm-drop", cmd_adm_drop, "('database'|'index')<object-name>",NULL,0,NULL},
+ {"adm-import", cmd_adm_import, "<record-type> <dir> <pattern>",NULL,0,NULL},
+ {"adm-refresh", cmd_adm_refresh, "",NULL,0,NULL},
+ {"adm-commit", cmd_adm_commit, "",NULL,0,NULL},
+ {"adm-shutdown", cmd_adm_shutdown, "",NULL,0,NULL},
+ {"adm-startup", cmd_adm_startup, "",NULL,0,NULL},
+ {"explain", cmd_explain, "", NULL, 0, NULL},
+ {"help", cmd_help, "", NULL,0,NULL},
+ {0,0,0,0,0,0}
+};
+
+static int cmd_help (const char *line)
+{
+ int i;
+ char topic[21];
+
+ *topic = 0;
+ sscanf (line, "%20s", topic);
+
+ if (*topic == 0)
+ printf("Commands:\n");
+ for (i = 0; cmd_array[i].cmd; i++)
+ if (*topic == 0 || strcmp (topic, cmd_array[i].cmd) == 0)
+ printf(" %s %s\n", cmd_array[i].cmd, cmd_array[i].ad);
+ if (strcmp (topic, "find") == 0)
+ {
+ printf ("RPN:\n");
+ printf (" \"term\" Simple Term\n");
+ printf (" @attr [attset] type=value op Attribute\n");
+ printf (" @and opl opr And\n");
+ printf (" @or opl opr Or\n");
+ printf (" @not opl opr And-Not\n");
+ printf (" @set set Result set\n");
+ printf ("\n");
+ printf ("Bib-1 attribute types\n");
+ printf ("1=Use: ");
+ printf ("4=Title 7=ISBN 8=ISSN 30=Date 62=Abstract 1003=Author 1016=Any\n");
+ printf ("2=Relation: ");
+ printf ("1< 2<= 3= 4>= 5> 6!= 102=Relevance\n");
+ printf ("3=Position: ");
+ printf ("1=First in Field 2=First in subfield 3=Any position\n");
+ printf ("4=Structure: ");
+ printf ("1=Phrase 2=Word 3=Key 4=Year 5=Date 6=WordList\n");
+ printf ("5=Truncation: ");
+ printf ("1=Right 2=Left 3=L&R 100=No 101=# 102=Re-1 103=Re-2\n");
+ printf ("6=Completeness:");
+ printf ("1=Incomplete subfield 2=Complete subfield 3=Complete field\n");
+ }
+ return 1;
+}
+
+int cmd_register_tab(const char* arg) {
+
+ char command[101], tabargument[101];
+ int i;
+ int num_of_tabs;
+ char** tabslist;
+
+ if (sscanf (arg, "%100s %100s", command, tabargument) < 1) {
+ return 0;
+ }
+
+ /* locate the amdn in the list */
+ for (i = 0; cmd_array[i].cmd; i++) {
+ if (!strncmp(cmd_array[i].cmd, command, strlen(command))) {
+ break;
+ }
+ }
+
+ if(!cmd_array[i].cmd) {
+ fprintf(stderr,"Unknown command %s\n",command);
+ return 1;
+ }
+
+
+ if(!cmd_array[i].local_tabcompletes)
+ cmd_array[i].local_tabcompletes = (char **) calloc(1,sizeof(char**));
+
+ num_of_tabs=0;
+
+ tabslist = cmd_array[i].local_tabcompletes;
+ for(;tabslist && *tabslist;tabslist++) {
+ num_of_tabs++;
+ }
+
+ cmd_array[i].local_tabcompletes = (char **)
+ realloc(cmd_array[i].local_tabcompletes,(num_of_tabs+2)*sizeof(char**));
+ tabslist=cmd_array[i].local_tabcompletes;
+ tabslist[num_of_tabs]=strdup(tabargument);
+ tabslist[num_of_tabs+1]=NULL;
+ return 1;
+}
+
+
+void process_cmd_line(char* line)
+{