/* zebrash.c - command-line interface to zebra API
- * $Id: zebrash.c,v 1.10 2003-06-20 14:21:23 heikki Exp $
+ * $Id: zebrash.c,v 1.12 2003-06-23 15:35:25 adam Exp $
*
* Copyrigth 2003 Index Data Aps
*
static int cmd_create_database( char *args[], char *outbuff)
{
char *db=args[1];
- int rc;
if (!db)
db="Default";
strcat(outbuff,"Creating database ");
return zebra_create_database(zh, db);
}
-/**************************************
+
+static int cmd_begin_trans( char *args[], char *outbuff)
+{
+ int rw=0;
+ if (args[1] && ( (args[1][0]=='1') || (args[1][0]=='w') ))
+ rw=1;
+ return zebra_begin_trans(zh,rw);
+}
+static int cmd_end_trans( char *args[], char *outbuff)
+{
+ return zebra_end_trans(zh);
+}
+/*************************************
+ * Inserting and deleting
+ */
+
+static int cmd_record_insert( char *args[], char *outbuff)
+{
+ int sysno=0;
+ char buf[MAX_ARG_LEN];
+ int i;
+ int rc;
+
+ i=1;
+ buf[0]='\0';
+ while (args[i])
+ {
+ strcat(buf, args[i++]);
+ strcat(buf, " ");
+ }
+ rc=zebra_record_insert(zh,buf, strlen(buf), &sysno);
+ if (0==rc)
+ {
+ sprintf(buf,"ok sysno=%d\n",sysno);
+ strcat(outbuff,buf);
+ }
+ return rc;
+}
+
+
+static int cmd_exchange_record( char *args[], char *outbuff)
+{
+ char *base=args[1];
+ char *id = args[2];
+ char *action = args[3];
+ int i=4;
+ int rc;
+ char buf[MAX_ARG_LEN];
+ if (!(base && id && action && args[4] ))
+ {
+ strcat(outbuff,"Missing arguments!\n");
+ onecommand("help exchange_record", outbuff, "");
+ return -90;
+ }
+ while (args[i])
+ {
+ strcat(buf, args[i++]);
+ strcat(buf, " ");
+ }
+ rc=zebra_admin_exchange_record(zh, base, buf, strlen(buf),
+ id, strlen(id), atoi(action));
+ return rc;
+}
+
+
+/**************************************)
* Command table, parser, and help
*/
{ "create_database", "basename",
"Creates a database",
cmd_create_database},
+ { "begin_trans", "[rw]",
+ "Begins a transaction. rw=1 means write, otherwise read-only",
+ cmd_begin_trans},
+ { "end_trans","",
+ "Ends a transaction",
+ cmd_end_trans},
+
+ { "","Updating:","",0},
+ { "record_insert","record",
+ "inserts an sgml record into Default",
+ cmd_record_insert},
+ { "exchange_record","database record-id action record",
+ "inserts (1), updates (2), or deletes (3) a record \n"
+ "record-id must be a unique identifier for the record",
+ cmd_exchange_record},
{ "", "Misc:","", 0},
{ "echo", "string",
"ouputs the string",
printf("expecting '%s'\n",rest); /*!*/
if (0==strstr(prevout,rest))
{
- printf( "Failed expectation, '%s' not found\n");
+ printf( "Failed expectation, '%s' not found\n", res);
exit(9);
}
return 0;