X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=index%2Fzebrash.c;h=bd42f93684a265db7acbe7289cf9a8b175b515f4;hb=refs%2Ftags%2FZEBRA.1.3.14;hp=efa8b2d605d359a9f6d531d61c38c51bfa5265ee;hpb=87c62083368d018a7d159fcfd6fc1c930b02b7e3;p=idzebra-moved-to-github.git diff --git a/index/zebrash.c b/index/zebrash.c index efa8b2d..bd42f93 100644 --- a/index/zebrash.c +++ b/index/zebrash.c @@ -1,4 +1,4 @@ -/* $Id: zebrash.c,v 1.20 2003-07-07 14:56:04 heikki Exp $ +/* $Id: zebrash.c,v 1.23 2003-11-21 15:30:16 heikki Exp $ Copyright (C) 2002,2003 Index Data Aps @@ -76,28 +76,28 @@ static int split_args( char *line, char** args ) p++; while (*p) { - while (*p==' ' || *p=='\t' || *p=='\n') - p++; - if (*p=='#') /* skip comments */ - break; - args[i++]=p; - args[i]=0; - while (*p && *p!=' ' && *p!='\t' && *p!='\n' && *p!='#') - p++; - *p++='\0'; + while (*p==' ' || *p=='\t' || *p=='\n') + p++; + if (*p=='#') /* skip comments */ + break; + args[i++]=p; + args[i]=0; + while (*p && *p!=' ' && *p!='\t' && *p!='\n' && *p!='#') + p++; + *p++='\0'; } n=i; while (n1) /* args[0] is not yet set, can't use restargs */ rest= line + (args[1]-argbuf); /* rest of the line */ else return -1; /* need something to expect */ - if (0==strstr(prevout,rest)) - { - printf( "Failed expectation, '%s' not found\n", rest); + if (0==strstr(prevout,rest)) + { + printf( "Failed expectation, '%s' not found\n", rest); exit(9); - } - return 0; + } + return 0; } for (i=0;cmds[i].cmd;i++) - if (0==strcmp(cmds[i].cmd, args[0])) - { - if (nargs>1) - args[0]= line + (args[1]-argbuf); /* rest of the line */ - else - args[0]=""; - return ((cmds[i].testfunc)(args,outbuff)); - } + if (0==strcmp(cmds[i].cmd, args[0])) + { + if (nargs>1) + args[0]= line + (args[1]-argbuf); /* rest of the line */ + else + args[0]=""; + return ((cmds[i].testfunc)(args,outbuff)); + } wrbuf_printf(outbuff, "Unknown command '%s'. Try help\n",args[0]); logf(LOG_APP,"Unknown command"); return -90; @@ -641,20 +641,20 @@ static int cmd_help( char *args[], WRBUF outbuff) int linelen; if (args[1]) { /* help for a single command */ - for (i=0;cmds[i].cmd;i++) - if (0==strcmp(cmds[i].cmd, args[1])) - { + for (i=0;cmds[i].cmd;i++) + if (0==strcmp(cmds[i].cmd, args[1])) + { wrbuf_printf(outbuff,"%s %s\n%s\n", cmds[i].cmd, cmds[i].args, - cmds[i].explanation); - return 0; - } - wrbuf_printf(outbuff, "Unknown command '%s'", args[1]); - } + cmds[i].explanation); + return 0; + } + wrbuf_printf(outbuff, "Unknown command '%s'", args[1]); + } else { /* list all commands */ linelen=9999; - for (i=0;cmds[i].cmd;i++) + for (i=0;cmds[i].cmd;i++) { if (*cmds[i].cmd) { /* ordinary command */ @@ -682,20 +682,20 @@ static void Zerrors ( WRBUF outbuff) { int ec; if (!zh) - return ; + return ; ec=zebra_errCode (zh); if (ec) { - logf(LOG_APP, " Zebra error %d: %s, (%s)", - ec, zebra_errString (zh), - zebra_errAdd (zh) ); - wrbuf_printf(outbuff, " Zebra error %d: %s, (%s)\n", - ec, zebra_errString (zh), - zebra_errAdd (zh) ); - zebra_clearError(zh); + logf(LOG_APP, " Zebra error %d: %s, (%s)", + ec, zebra_errString (zh), + zebra_errAdd (zh) ); + wrbuf_printf(outbuff, " Zebra error %d: %s, (%s)\n", + ec, zebra_errString (zh), + zebra_errAdd (zh) ); + zebra_clearError(zh); } } - + /************************************** * The shell */ @@ -708,48 +708,61 @@ void shell() wrbuf_puts(outbuff,"Zebrash at your service"); while (rc!=-99) { - char buf[MAX_ARG_LEN]; + char *nl_cp; + char buf[MAX_ARG_LEN]; + char* line_in = 0; #if HAVE_READLINE_READLINE_H - char* line_in; + if (isatty(0)) { line_in=readline(PROMPT); if (!line_in) - break; + break; #if HAVE_READLINE_HISTORY_H if (*line_in) - add_history(line_in); + add_history(line_in); +#endif + } #endif + /* line_in != NULL if readine is present and input is a tty */ + + printf (PROMPT); + fflush (stdout); + if (line_in) + { if(strlen(line_in) > MAX_ARG_LEN-1) { - fprintf(stderr,"Input line too long\n"); - break; + fprintf(stderr,"Input line too long\n"); + break; } strcpy(buf,line_in); free (line_in); -#else - printf (PROMPT); - fflush (stdout); + } + else + { if (!fgets (buf, MAX_ARG_LEN-1, stdin)) - break; -#endif + break; + } - strncpy(prevout, wrbuf_buf(outbuff), MAX_OUT_BUFF); + /* get rid of \n in line */ + if ((nl_cp = strchr(buf, '\n'))) + *nl_cp = '\0'; + strncpy(prevout, wrbuf_buf(outbuff), MAX_OUT_BUFF); wrbuf_rewind(outbuff); - rc=onecommand(buf, outbuff, prevout); - if (rc==0) - { - wrbuf_puts(outbuff, " OK\n"); - logf(LOG_APP, "OK"); - } - else if (rc>-90) - { - wrbuf_printf(outbuff, " command returned %d\n",rc); - } - Zerrors(outbuff); - printf("%s\n", wrbuf_buf(outbuff)); + rc=onecommand(buf, outbuff, prevout); + if (rc==0) + { + wrbuf_puts(outbuff, " OK\n"); + logf(LOG_APP, "OK"); + } + else if (rc>-90) + { + wrbuf_printf(outbuff, " command returned %d\n",rc); + } + Zerrors(outbuff); + printf("%s\n", wrbuf_buf(outbuff)); } /* while */ wrbuf_free(outbuff,1); } /* shell() */ - - + + /************************************** * Main */