-/* $Id: zebraapi.h,v 1.7 2003-06-18 11:46:33 adam Exp $
+/* $Id: zebraapi.h,v 1.8 2003-06-20 14:21:23 heikki Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003
Index Data Aps
02111-1307, USA.
*/
+/* Return codes:
+ * Most functions return an int. Unix-like, 0 means OK,
+ * non-zero means an error. The error info should be available
+ * via zebra_errCode and friends.
+ */
+
#ifndef ZEBRAAPI_H
#define ZEBRAAPI_H
YAZ_EXPORT ZebraService zebra_start (const char *configName);
/* Close the whole Zebra */
-YAZ_EXPORT void zebra_stop (ZebraService zs);
+YAZ_EXPORT int zebra_stop (ZebraService zs);
/* Open a ZebraHandle */
YAZ_EXPORT ZebraHandle zebra_open (ZebraService zs);
/* Close handle */
-YAZ_EXPORT void zebra_close (ZebraHandle zh);
+YAZ_EXPORT int zebra_close (ZebraHandle zh);
/*********
* Error handling
YAZ_EXPORT char *zebra_errAdd (ZebraHandle zh);
/* get the result code and addinfo from zh */
-YAZ_EXPORT void zebra_result (ZebraHandle zh, int *code, char **addinfo);
+YAZ_EXPORT int zebra_result (ZebraHandle zh, int *code, char **addinfo);
/* FIXME - why is this needed?? -H */
+/* clear them error things */
+YAZ_EXPORT void zebra_clearError(ZebraHandle zh);
/**************
* Searching
/* Search using PQF Query */
YAZ_EXPORT int zebra_search_PQF (ZebraHandle zh, const char *pqf_query,
- const char *setname);
+ const char *setname, int *numhits);
/* Search using RPN Query */
-YAZ_EXPORT void zebra_search_RPN (ZebraHandle zh, ODR o, Z_RPNQuery *query,
+YAZ_EXPORT int zebra_search_RPN (ZebraHandle zh, ODR o, Z_RPNQuery *query,
const char *setname, int *hits);
/* Retrieve record(s) */
-YAZ_EXPORT void zebra_records_retrieve (ZebraHandle zh, ODR stream,
+YAZ_EXPORT int zebra_records_retrieve (ZebraHandle zh, ODR stream,
const char *setname, Z_RecordComposition *comp,
oid_value input_format,
int num_recs, ZebraRetrievalRecord *recs);
/* Browse */
-YAZ_EXPORT void zebra_scan (ZebraHandle zh, ODR stream,
+YAZ_EXPORT int zebra_scan (ZebraHandle zh, ODR stream,
Z_AttributesPlusTerm *zapt,
oid_value attributeset,
int *position, int *num_entries,
* Admin
*/
-YAZ_EXPORT void zebra_create_database (ZebraHandle zh, const char *db);
+YAZ_EXPORT int zebra_create_database (ZebraHandle zh, const char *db);
-YAZ_EXPORT void zebra_admin_shutdown (ZebraHandle zh);
-YAZ_EXPORT void zebra_admin_start (ZebraHandle zh);
+YAZ_EXPORT int zebra_admin_shutdown (ZebraHandle zh);
+YAZ_EXPORT int zebra_admin_start (ZebraHandle zh);
-YAZ_EXPORT void zebra_shutdown (ZebraService zs);
+YAZ_EXPORT int zebra_shutdown (ZebraService zs);
-YAZ_EXPORT void zebra_admin_import_begin (ZebraHandle zh, const char *database,
+YAZ_EXPORT int zebra_admin_import_begin (ZebraHandle zh, const char *database,
const char *record_type);
-YAZ_EXPORT void zebra_admin_import_segment (ZebraHandle zh,
+YAZ_EXPORT int zebra_admin_import_segment (ZebraHandle zh,
Z_Segment *segment);
-void zebra_admin_import_end (ZebraHandle zh);
+YAZ_EXPORT int zebra_admin_import_end (ZebraHandle zh);
int zebra_admin_exchange_record (ZebraHandle zh,
const char *database,
int zebra_init (ZebraHandle zh);
int zebra_compact (ZebraHandle zh);
-void zebra_repository_update (ZebraHandle zh);
-void zebra_repository_delete (ZebraHandle zh);
-void zebra_repository_show (ZebraHandle zh);
-int zebra_record_insert (ZebraHandle zh, const char *buf, int len);
+int zebra_repository_update (ZebraHandle zh);
+int zebra_repository_delete (ZebraHandle zh);
+int zebra_repository_show (ZebraHandle zh);
+int zebra_record_insert (ZebraHandle zh, const char *buf, int len, int *sysno);
-YAZ_EXPORT void zebra_set_group (ZebraHandle zh, struct recordGroup *rg);
+YAZ_EXPORT int zebra_set_group (ZebraHandle zh, struct recordGroup *rg);
YAZ_EXPORT int zebra_resultSetTerms (ZebraHandle zh, const char *setname,
int no, int *count,
int *type, char *out, size_t *len);
-YAZ_EXPORT void zebra_sort (ZebraHandle zh, ODR stream,
+YAZ_EXPORT int zebra_sort (ZebraHandle zh, ODR stream,
int num_input_setnames,
const char **input_setnames,
const char *output_setname,
int zebra_select_database (ZebraHandle zh, const char *basename);
YAZ_EXPORT
-void zebra_shadow_enable (ZebraHandle zh, int value);
+int zebra_shadow_enable (ZebraHandle zh, int value);
YAZ_EXPORT
-void zebra_register_statistics (ZebraHandle zh, int dumpdict);
+int zebra_register_statistics (ZebraHandle zh, int dumpdict);
YAZ_EXPORT
int zebra_record_encoding (ZebraHandle zh, const char *encoding);
/* Resources */
YAZ_EXPORT
-void zebra_set_resource(ZebraHandle zh, const char *name, const char *value);
+int zebra_set_resource(ZebraHandle zh, const char *name, const char *value);
YAZ_EXPORT
const char *zebra_get_resource(ZebraHandle zh,
const char *name, const char *defaultvalue);
-/* $Id: index.h,v 1.100 2003-06-18 11:46:33 adam Exp $
+/* $Id: index.h,v 1.101 2003-06-20 14:21:23 heikki Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
Index Data Aps
const struct recordGroup *rGroup, int deleteFlag);
int zebra_begin_read (ZebraHandle zh);
-void zebra_end_read (ZebraHandle zh);
+int zebra_end_read (ZebraHandle zh);
int zebra_file_stat (const char *file_name, struct stat *buf,
int follow_links);
-/* $Id: invstat.c,v 1.34 2002-08-05 14:08:08 adam Exp $
+/* $Id: invstat.c,v 1.35 2003-06-20 14:21:23 heikki Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
Index Data Aps
return 0;
}
-void zebra_register_statistics (ZebraHandle zh, int dumpdict)
+int zebra_register_statistics (ZebraHandle zh, int dumpdict)
{
int blocks;
int size;
char term_dict[2*IT_MAX_WORD+2];
if (zebra_begin_read (zh))
- return;
+ return 1;
stat_info.zh = zh;
stat_info.dumpwords=dumpdict;
prev, stat_info.isam_occurrences[i]);
xmalloc_trav("unfreed"); /*! while hunting memory leaks */
zebra_end_read (zh);
+ return 0;
}
-/* $Id: zebraapi.c,v 1.105 2003-06-18 11:46:33 adam Exp $
+/* $Id: zebraapi.c,v 1.106 2003-06-20 14:21:23 heikki Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003
Index Data Aps
return reg;
}
-void zebra_admin_shutdown (ZebraHandle zh)
+int zebra_admin_shutdown (ZebraHandle zh)
{
ASSERTZH;
yaz_log(LOG_API,"zebra_admin_shutdown");
zebra_mutex_cond_lock (&zh->service->session_lock);
zh->service->stop_flag = 1;
zebra_mutex_cond_unlock (&zh->service->session_lock);
+ return 0;
}
-void zebra_admin_start (ZebraHandle zh)
+int zebra_admin_start (ZebraHandle zh)
{
ZebraService zs;
ASSERTZH;
zs = zh->service;
zebra_mutex_cond_lock (&zs->session_lock);
zebra_mutex_cond_unlock (&zs->session_lock);
+ return 0;
}
static void zebra_register_close (ZebraService zs, struct zebra_register *reg)
xfree (reg);
}
-void zebra_stop(ZebraService zs)
+int zebra_stop(ZebraService zs)
{
if (!zs)
return ;
xfree (zs->configName);
xfree (zs->path_root);
xfree (zs);
+ return 0;
}
-void zebra_close (ZebraHandle zh)
+int zebra_close (ZebraHandle zh)
{
ZebraService zs;
struct zebra_session **sp;
xfree (zh->reg_name);
zh->service=0; /* more likely to trigger an assert */
xfree (zh);
+ return 0;
}
struct map_baseinfo {
return 0;
}
-void zebra_search_RPN (ZebraHandle zh, ODR o,
+int zebra_search_RPN (ZebraHandle zh, ODR o,
Z_RPNQuery *query, const char *setname, int *hits)
{
ASSERTZH;
*hits = 0;
if (zebra_begin_read (zh))
- return;
+ return 1;
zebra_livcode_transform(zh, query);
zebra_end_read (zh);
*hits = zh->hits;
+ return 0;
}
-void zebra_records_retrieve (ZebraHandle zh, ODR stream,
+int zebra_records_retrieve (ZebraHandle zh, ODR stream,
const char *setname, Z_RecordComposition *comp,
oid_value input_format, int num_recs,
ZebraRetrievalRecord *recs)
{
zh->errCode = 30;
zh->errString = odr_strdup (stream, setname);
- return;
+ return 1;
}
zh->errCode = 0;
if (zebra_begin_read (zh))
- return;
+ return 1;
pos_array = (int *) xmalloc (num_recs * sizeof(*pos_array));
for (i = 0; i<num_recs; i++)
}
zebra_end_read (zh);
xfree (pos_array);
+ return 0;
}
-void zebra_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
+int zebra_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
oid_value attributeset,
int *position, int *num_entries, ZebraScanEntry **entries,
int *is_partial)
{
*entries = 0;
*num_entries = 0;
- return;
+ return 1;
}
rpn_scan (zh, stream, zapt, attributeset,
zh->num_basenames, zh->basenames, position,
num_entries, entries, is_partial, 0, 0);
zebra_end_read (zh);
+ return 0;
}
-void zebra_sort (ZebraHandle zh, ODR stream,
+int zebra_sort (ZebraHandle zh, ODR stream,
int num_input_setnames, const char **input_setnames,
const char *output_setname, Z_SortKeySpecList *sort_sequence,
int *sort_status)
yaz_log(LOG_API,"zebra_sort");
zh->errCode=0;
if (zebra_begin_read (zh))
- return;
+ return 1;
resultSetSort (zh, stream->mem, num_input_setnames, input_setnames,
output_setname, sort_sequence, sort_status);
zebra_end_read(zh);
+ return 0;
}
int zebra_deleleResultSet(ZebraHandle zh, int function,
return a;
}
+void zebra_clearError(ZebraHandle zh)
+{
+ if (zh)
+ {
+ zh->errCode=0;
+ zh->errString="";
+ }
+}
+
int zebra_auth (ZebraHandle zh, const char *user, const char *pass)
{
ZebraService zs;
return 1;
}
-void zebra_admin_import_begin (ZebraHandle zh, const char *database,
+int zebra_admin_import_begin (ZebraHandle zh, const char *database,
const char *record_type)
{
ASSERTZH;
database, record_type);
zh->errCode=0;
if (zebra_select_database(zh, database))
- return;
+ return 1;
zebra_begin_trans (zh, 1);
xfree (zh->admin_databaseName);
zh->admin_databaseName = xstrdup(database);
+ return 0;
}
-void zebra_admin_import_end (ZebraHandle zh)
+int zebra_admin_import_end (ZebraHandle zh)
{
ASSERTZH;
yaz_log(LOG_API,"zebra_admin_import_end");
zh->errCode=0;
zebra_end_trans (zh);
+ return 0;
}
-void zebra_admin_import_segment (ZebraHandle zh, Z_Segment *segment)
+int zebra_admin_import_segment (ZebraHandle zh, Z_Segment *segment)
{
int sysno;
int i;
}
}
}
+ return 0;
}
int zebra_admin_exchange_record (ZebraHandle zh,
return 0;
}
-void zebra_create_database (ZebraHandle zh, const char *database)
+int zebra_create_database (ZebraHandle zh, const char *database)
{
ZebraService zs;
ASSERTZH;
zh->errCode=0;
if (zebra_select_database (zh, database))
- return;
+ return -1;
if (zebra_begin_trans (zh, 1))
- return;
+ return -1;
zs = zh->service;
/* announce database */
if (zebraExplain_newDatabase (zh->reg->zei, database, 0
/* explainDatabase */))
{
+ zebra_end_trans (zh);
zh->errCode = 224;
zh->errString = "database already exist";
+ return -1;
}
zebra_end_trans (zh);
+ return 0;
}
int zebra_string_norm (ZebraHandle zh, unsigned reg_id,
}
-void zebra_set_state (ZebraHandle zh, int val, int seqno)
+int zebra_set_state (ZebraHandle zh, int val, int seqno)
{
char state_fname[256];
char *fname;
fprintf (f, "%c %d %ld\n", val, seqno, p);
fclose (f);
xfree (fname);
+ return 0;
}
-void zebra_get_state (ZebraHandle zh, char *val, int *seqno)
+int zebra_get_state (ZebraHandle zh, char *val, int *seqno)
{
char state_fname[256];
char *fname;
fclose (f);
}
xfree (fname);
+ return 0;
}
int zebra_begin_read (ZebraHandle zh)
return zebra_begin_trans(zh, 0);
}
-void zebra_end_read (ZebraHandle zh)
+int zebra_end_read (ZebraHandle zh)
{
- zebra_end_trans(zh);
+ return zebra_end_trans(zh);
}
int zebra_begin_trans (ZebraHandle zh, int rw)
return 0;
}
-void zebra_repository_update (ZebraHandle zh)
+int zebra_repository_update (ZebraHandle zh)
{
ASSERTZH;
zh->errCode=0;
logf (LOG_LOG|LOG_API, "updating %s", zh->rGroup.path);
repositoryUpdate (zh);
+ return zh->errCode;
}
-void zebra_repository_delete (ZebraHandle zh)
+int zebra_repository_delete (ZebraHandle zh)
{
ASSERTZH;
zh->errCode=0;
logf (LOG_LOG|LOG_API, "deleting %s", zh->rGroup.path);
repositoryDelete (zh);
+ return zh->errCode;
}
-void zebra_repository_show (ZebraHandle zh)
+int zebra_repository_show (ZebraHandle zh)
{
ASSERTZH;
yaz_log(LOG_API,"zebra_repository_show");
zh->errCode=0;
repositoryShow (zh);
+ return zh->errCode;
}
static int zebra_commit_ex (ZebraHandle zh, int clean_only)
return 0;
}
-int zebra_record_insert (ZebraHandle zh, const char *buf, int len)
+int zebra_record_insert (ZebraHandle zh, const char *buf, int len, int *sysno)
{
- int sysno = 0;
+ int sysn=0;
ASSERTZH;
yaz_log(LOG_API,"zebra_record_insert");
+ if (sysno)
+ *sysno=0;
zh->errCode=0;
if (zebra_begin_trans (zh, 1))
- return 0;
+ return -1;
extract_rec_in_mem (zh, "grs.sgml",
buf, len,
"Default", /* database */
0 /* delete_flag */,
0 /* test_mode */,
- &sysno /* sysno */,
+ &sysn /* sysno */,
1 /* store_keys */,
1 /* store_data */,
0 /* match criteria */);
if (zebra_end_trans (zh))
- return 0;
- return sysno;
+ return -1;
+ if (sysno)
+ *sysno=sysn;
+ return 0;
}
-void zebra_set_group (ZebraHandle zh, struct recordGroup *rg)
+int zebra_set_group (ZebraHandle zh, struct recordGroup *rg)
{
ASSERTZH;
yaz_log(LOG_API,"zebra_set_group");
zh->errCode=0;
memcpy (&zh->rGroup, rg, sizeof(*rg));
+ return 0;
}
-void zebra_result (ZebraHandle zh, int *code, char **addinfo)
+int zebra_result (ZebraHandle zh, int *code, char **addinfo)
{
ASSERTZH;
yaz_log(LOG_API,"zebra_result");
*code = zh->errCode;
*addinfo = zh->errString;
+ return 0;
}
-void zebra_shadow_enable (ZebraHandle zh, int value)
+int zebra_shadow_enable (ZebraHandle zh, int value)
{
ASSERTZH;
yaz_log(LOG_API,"zebra_shadow_enable");
zh->errCode=0;
zh->shadow_enable = value;
+ return 0;
}
int zebra_record_encoding (ZebraHandle zh, const char *encoding)
/*
* Fixme!
+ * Something about charset aliases. Oleg???
*/
if (zh->iconv_to_utf8 != 0)
return 0;
}
-void zebra_set_resource(ZebraHandle zh, const char *name, const char *value)
+int zebra_set_resource(ZebraHandle zh, const char *name, const char *value)
{
ASSERTZH;
yaz_log(LOG_API,"zebra_set_resource %s:%s",name,value);
zh->errCode=0;
res_put(zh->res, name, value);
+ return 0;
}
const char *zebra_get_resource(ZebraHandle zh,
}
/* moved from zebra_api_ext.c by pop */
+/* FIXME: Should this really be public??? -Heikki */
int zebra_trans_no (ZebraHandle zh) {
ASSERTZH;
return (zh->shadow_enable);
}
-void zebra_set_shadow_enable (ZebraHandle zh, int value) {
+int zebra_set_shadow_enable (ZebraHandle zh, int value) {
yaz_log(LOG_API,"zebra_set_shadow_enable %d",value);
zh->shadow_enable = value;
+ return 0;
}
-void init_recordGroup (struct recordGroup *rg) {
+int init_recordGroup (struct recordGroup *rg) {
assert(rg);
yaz_log(LOG_API,"init_recordGroup");
rg->groupName = NULL;
rg->explainDatabase = 0;
rg->fileVerboseLimit = 100000;
rg->followLinks = -1;
+ return 0;
}
If sysno is provided, then it's used to identify the reocord.
If not, and match_criteria is provided, then sysno is guessed
If not, and a record is provided, then sysno is got from there
+NOTE: Now returns 0 at success and updates sysno, which is an int*
+ 20-jun-2003 Heikki
*/
int zebra_insert_record (ZebraHandle zh,
struct recordGroup *rGroup,
const char *recordType,
- int sysno, const char *match, const char *fname,
+ int *sysno, const char *match, const char *fname,
const char *buf, int buf_size,
int force_update) /* This one is ignored */
0, /* delete_flag */
0, /* test_mode */
recordType,
- &sysno,
+ sysno,
match, fname,
force_update,
0); /* allow_update */
zebra_end_trans(zh);
if (res < 0) return (res);
- return sysno;
+ return res;
}
int zebra_update_record (ZebraHandle zh,
struct recordGroup *rGroup,
const char *recordType,
- int sysno, const char *match, const char *fname,
+ int* sysno, const char *match, const char *fname,
const char *buf, int buf_size,
int force_update)
0, /* delete_flag */
0, /* test_mode */
recordType,
- &sysno,
+ sysno,
match, fname,
force_update,
1); /* allow_update */
zebra_end_trans(zh);
- return sysno;
+ return res;
}
int zebra_delete_record (ZebraHandle zh,
struct recordGroup *rGroup,
const char *recordType,
- int sysno, const char *match, const char *fname,
+ int *sysno, const char *match, const char *fname,
const char *buf, int buf_size,
int force_update)
{
1, /* delete_flag */
0, /* test_mode */
recordType,
- &sysno,
+ sysno,
match,fname,
force_update,
1); /* allow_update */
zebra_end_trans(zh);
- return sysno;
+ return res;
}
/* ---------------------------------------------------------------------------
*/
int zebra_search_PQF (ZebraHandle zh, const char *pqf_query,
- const char *setname)
+ const char *setname, int *numhits)
{
int hits = 0;
+ int res=-1;
Z_RPNQuery *query;
ODR odr = odr_createmem(ODR_ENCODE);
+ assert(numhits);
yaz_log(LOG_API,"zebra_search_PQF s=%s q=%s",setname, pqf_query);
query = p_query_rpn (odr, PROTO_Z3950, pqf_query);
if (!query)
yaz_log (LOG_WARN, "bad query %s\n", pqf_query);
else
- zebra_search_RPN (zh, odr, query, setname, &hits);
+ res=zebra_search_RPN (zh, odr, query, setname, &hits);
odr_destroy(odr);
- return hits;
+ *numhits=hits;
+
+ return res;
}
/* ---------------------------------------------------------------------------
Sort - a simplified interface, with optional read locks.
FIXME - This is a horrible name, will conflict with half the applications
*/
-int sort (ZebraHandle zh,
+int zebra_sort_2 (ZebraHandle zh,
ODR stream,
const char *sort_spec,
const char *output_setname,
/* zebrash.c - command-line interface to zebra API
- * $Id: zebrash.c,v 1.9 2003-06-02 13:33:16 adam Exp $
+ * $Id: zebrash.c,v 1.10 2003-06-20 14:21:23 heikki Exp $
*
* Copyrigth 2003 Index Data Aps
*
return v;
}
-int onecommand( char *line, char *outbuff);
+int onecommand( char *line, char *outbuff, const char *prevout);
/**************************************
* Simple support commands
static int cmd_quickstart( char *args[], char *outbuff)
{
char tmp[128];
- onecommand("yaz_log_file zebrash.log",outbuff);
- onecommand("yaz_log_prefix ZebraSh", outbuff);
+ int rc=0;
+ if (!rc)
+ rc=onecommand("yaz_log_file zebrash.log",outbuff,"");
+ if (!rc)
+ rc=onecommand("yaz_log_prefix ZebraSh", outbuff,"");
sprintf(tmp, "yaz_log_level 0x%x", LOG_DEFAULT_LEVEL | LOG_APP);
- onecommand(tmp,outbuff);
+ if (!rc)
+ rc=onecommand(tmp,outbuff,"");
logf(LOG_APP,"quickstart");
- onecommand("zebra_start",outbuff);
- onecommand("zebra_open",outbuff);
- onecommand("select_database Default",outbuff);
- strcat(outbuff,"ok\n");
- return 0;
+ if (!rc)
+ rc=onecommand("zebra_start",outbuff,"");
+ if (!rc)
+ rc=onecommand("zebra_open",outbuff,"");
+ if (!rc)
+ rc=onecommand("select_database Default",outbuff,"");
+ return rc;
}
/**************************************
static int cmd_select_database ( char *args[], char *outbuff)
{
char *db=args[1];
- if (!db)
- db="Default";
+ if (!db) {
+ db="Default";
+ strcat(outbuff,"Selecting database 'Default'\n");
+ }
return zebra_select_database(zh, db);
}
+static int cmd_create_database( char *args[], char *outbuff)
+{
+ char *db=args[1];
+ int rc;
+ if (!db)
+ db="Default";
+ strcat(outbuff,"Creating database ");
+ strcat(outbuff,db);
+ strcat(outbuff,"\n");
+
+ return zebra_create_database(zh, db);
+}
/**************************************
* Command table, parser, and help
*/
{ "select_database", "basename",
"Selects a database",
cmd_select_database},
-
+ { "create_database", "basename",
+ "Creates a database",
+ cmd_create_database},
{ "", "Misc:","", 0},
{ "echo", "string",
"ouputs the string",
{0,0,0,0} /* end marker */
};
-int onecommand( char *line, char *outbuff)
+int onecommand(
+ char *line, /* input line */
+ char *outbuff, /* output goes here */
+ const char *prevout) /* prev output, for 'expect' */
{
int i;
char *args[MAX_NO_ARGS];
}
#endif
if (0==n)
- return -1; /* no command on line, too bad */
+ return -90; /* no command on line, too bad */
+
+ if (0==strcmp(args[0],"expect"))
+ {
+ char *rest;
+ if (n>1)
+ rest= line + (args[1]-argbuf); /* rest of the line */
+ else
+ return -1; /* need something to expect */
+ printf("expecting '%s'\n",rest); /*!*/
+ if (0==strstr(prevout,rest))
+ {
+ printf( "Failed expectation, '%s' not found\n");
+ exit(9);
+ }
+ return 0;
+ }
for (i=0;cmds[i].cmd;i++)
if (0==strcmp(cmds[i].cmd, args[0]))
{
strcat(outbuff,args[0] );
strcat(outbuff,"'. Try help");
logf(LOG_APP,"Unknown command");
- return -2;
+ return -90;
}
static int cmd_help( char *args[], char *outbuff)
ec=zebra_errCode (zh);
if (ec)
{
- sprintf(tmp, "Zebra error %d: %s, (%s)",
+ sprintf(tmp, " Zebra error %d: %s, (%s)",
ec, zebra_errString (zh),
zebra_errAdd (zh) );
strcat(outbuff, tmp);
strcat(outbuff, "\n");
logf(LOG_APP, tmp);
+ zebra_clearError(zh);
}
}
{
int rc=0;
char tmp[MAX_ARG_LEN];
+ char outbuff[MAX_OUT_BUFF]="";
+ char prevout[MAX_OUT_BUFF]=""; /* previous output for 'expect' */
while (rc!=-99)
{
char buf[MAX_ARG_LEN];
- char outbuff[MAX_OUT_BUFF];
#if HAVE_READLINE_READLINE_H
char* line_in;
line_in=readline(PROMPT);
if (!fgets (buf, MAX_ARG_LEN-1, stdin))
break;
#endif
+
+ strncpy(prevout, outbuff, MAX_OUT_BUFF);
outbuff[0]='\0';
- rc=onecommand(buf, outbuff);
+ rc=onecommand(buf, outbuff, prevout);
if (rc==0)
{
- strcat(outbuff, "OK\n");
+ strcat(outbuff, " OK\n");
logf(LOG_APP, "OK");
}
- else if (rc > 0)
+ else if (rc>-90)
{
- sprintf(tmp, "command returned %d\n",rc);
+ sprintf(tmp, " command returned %d\n",rc);
strcat(outbuff,tmp);
}
Zerrors(outbuff);
-/* $Id: t2.c,v 1.6 2003-05-20 13:52:41 adam Exp $
+/* $Id: t2.c,v 1.7 2003-06-20 14:21:24 heikki Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
Index Data Aps
zh = zebra_open (zs);
zebra_select_database(zh, "Default");
zebra_begin_trans (zh, 1);
- zebra_record_insert (zh, myrec, strlen(myrec));
+ zebra_record_insert (zh, myrec, strlen(myrec),0);
- hits = zebra_search_PQF (zh, "@attr 1=4 my", "set1");
+ zebra_search_PQF (zh, "@attr 1=4 my", "set1", &hits);
if (hits < 1)
{
yaz_log(LOG_FATAL, "At least one hit expected");
-/* $Id: t3.c,v 1.3 2003-06-18 11:46:34 adam Exp $
+/* $Id: t3.c,v 1.4 2003-06-20 14:21:24 heikki Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
Index Data Aps
zebra_select_database(zh, "Default");
zebra_begin_trans (zh, 1);
- zebra_record_insert (zh, myrec, strlen(myrec));
+ zebra_record_insert (zh, myrec, strlen(myrec),0);
zebra_end_trans (zh);
for (i = 0; i<4; i++)
-/* $Id: t4.c,v 1.1 2003-06-18 11:46:34 adam Exp $
+/* $Id: t4.c,v 1.2 2003-06-20 14:21:24 heikki Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
Index Data Aps
zebra_begin_trans (zh, 1);
for (i = 0; i<1200; i++)
- zebra_record_insert (zh, myrec, strlen(myrec));
+ zebra_record_insert (zh, myrec, strlen(myrec),0);
zebra_end_trans (zh);
zebra_close(zh);
zebra_stop(zs);