X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Fzebrash.c;h=e1532f9f9e7f9bec836d40768140926e129809e5;hb=3df3e928408f9b730578eba65737e9c8a19dd707;hp=c0b96f7a34e214bcf1c0a902dcaed788e7b24ac1;hpb=c860ce4e5d976ea40d5b571c9d0d4fe9ff2f6e88;p=idzebra-moved-to-github.git diff --git a/index/zebrash.c b/index/zebrash.c index c0b96f7..e1532f9 100644 --- a/index/zebrash.c +++ b/index/zebrash.c @@ -1,5 +1,5 @@ /* zebrash.c - command-line interface to zebra API - * $ID$ + * $Id: zebrash.c,v 1.7 2003-03-05 16:44:02 adam Exp $ * * Copyrigth 2003 Index Data Aps * @@ -128,7 +128,7 @@ int onecommand( char *line, char *outbuff); { if (!zs) strcat(outbuff,"zebra seems not to have been started, " - "stopping anyway"); + "stopping anyway\n"); zebra_stop(zs); zs=0; return 0; /* ok */ @@ -138,7 +138,7 @@ static int cmd_zebra_open( char *args[], char *outbuff) { if (!zs) strcat(outbuff,"zebra seems not to have been started, " - "trying anyway"); + "trying anyway\n"); zh=zebra_open(zs); return 0; /* ok */ } @@ -147,7 +147,7 @@ static int cmd_zebra_close( char *args[], char *outbuff) { if (!zh) strcat(outbuff,"Seems like you have not called zebra_open," - "trying anyway"); + "trying anyway\n"); zebra_close(zh); return 0; /* ok */ } @@ -374,13 +374,12 @@ int onecommand( char *line, char *outbuff) char *args[MAX_NO_ARGS]; int n; char argbuf[MAX_ARG_LEN]; - int rc; logf(LOG_APP,"%s",line); strncpy(argbuf,line, MAX_ARG_LEN-1); argbuf[MAX_ARG_LEN-1]='\0'; /* just to be sure */ n=split_args(argbuf, args); if (0==n) - return 0; /* no command on line, too bad */ + return -1; /* no command on line, too bad */ for (i=0;cmds[i].cmd;i++) if (0==strcmp(cmds[i].cmd, args[0])) { @@ -394,7 +393,7 @@ int onecommand( char *line, char *outbuff) strcat(outbuff,args[0] ); strcat(outbuff,"'. Try help"); logf(LOG_APP,"Unknown command"); - return -1; + return -2; } static int cmd_help( char *args[], char *outbuff) @@ -452,7 +451,7 @@ int onecommand( char *line, char *outbuff) } /* If Zebra reports an error after an operation, - * append it to the outbuff */ + * append it to the outbuff and log it */ static void Zerrors ( char *outbuff) { int ec; @@ -462,10 +461,12 @@ static void Zerrors ( char *outbuff) ec=zebra_errCode (zh); if (ec) { - sprintf(tmp, "Zebra error %d: %s, (%s) \n", + sprintf(tmp, "Zebra error %d: %s, (%s)", ec, zebra_errString (zh), zebra_errAdd (zh) ); strcat(outbuff, tmp); + strcat(outbuff, "\n"); + logf(LOG_APP, tmp); } } @@ -500,22 +501,25 @@ void shell() printf (PROMPT); fflush (stdout); if (!fgets (buf, MAX_ARG_LEN-1, stdin)) - break; + break; #endif outbuff[0]='\0'; rc=onecommand(buf, outbuff); if (rc==0) + { strcat(outbuff, "OK\n"); + logf(LOG_APP, "OK"); + } else if (rc > 0) { sprintf(tmp, "command returned %d\n",rc); strcat(outbuff,tmp); - } + } Zerrors(outbuff); printf("%s\n", outbuff); } /* while */ } /* shell() */ - + /************************************** * Main