X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=client%2Fclient.c;h=93741ca9c48bf4f2cc9ee9aed6dfc6d32a469851;hp=5cce8ccc026901b8d0eaaf37a5db8166ab24c7aa;hb=442f9815fa99344367af117cba29f2c0e209a0cf;hpb=75c9defe1c9ffb8efe58507dc994a56e6fd0409b diff --git a/client/client.c b/client/client.c index 5cce8cc..93741ca 100644 --- a/client/client.c +++ b/client/client.c @@ -1,5 +1,5 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2008 Index Data + * Copyright (C) 1995-2009 Index Data * See the file LICENSE for details. */ /** \file client.c @@ -177,6 +177,8 @@ int cmd_querycharset(const char *arg); static void close_session(void); +static void marc_file_write(const char *buf, size_t sz); + ODR getODROutputStream(void) { return out; @@ -195,14 +197,15 @@ const char* query_type_as_string(QueryType q) } } -static void do_hex_dump(const char* buf, int len) +static void do_hex_dump(const char* buf, size_t len) { if (hex_dump) { - int i,x; + size_t i; + int x; for (i = 0; i < len ; i = i+16 ) { - printf(" %4.4d ",i); + printf(" %4.4ld ", (long) i); for(x=0 ; i+xu.octet_aligned->buf, r->u.octet_aligned->len); - if (marc_file) - fwrite(r->u.octet_aligned->buf, 1, r->u.octet_aligned->len, marc_file); + marc_file_write((const char *) r->u.octet_aligned->buf, + r->u.octet_aligned->len); } else if (oid && r->which == Z_External_octet) { @@ -943,7 +951,10 @@ static void display_record(Z_External *r) if (yaz_marc_decode_buf(mt, octet_buf, r->u.octet_aligned->len, &result, &rlen)> 0) { - fwrite(result, rlen, 1, stdout); + if (fwrite(result, rlen, 1, stdout) != 1) + { + printf("write to stdout failed\n"); + } } else { @@ -961,8 +972,7 @@ static void display_record(Z_External *r) r->u.octet_aligned->len); } } - if (marc_file) - fwrite(octet_buf, 1, r->u.octet_aligned->len, marc_file); + marc_file_write(octet_buf, r->u.octet_aligned->len); } else if (oid && !oid_oidcmp(oid, yaz_oid_recsyn_sutrs)) { @@ -972,8 +982,7 @@ static void display_record(Z_External *r) return; } print_record(r->u.sutrs->buf, r->u.sutrs->len); - if (marc_file) - fwrite(r->u.sutrs->buf, 1, r->u.sutrs->len, marc_file); + marc_file_write((const char *) r->u.sutrs->buf, r->u.sutrs->len); } else if (oid && !oid_oidcmp(oid, yaz_oid_recsyn_grs_1)) { @@ -3524,35 +3533,37 @@ int cmd_source(const char* arg, int echo ) FILE* includeFile; char line[102400], *cp; - if(strlen(arg)<1) { - fprintf(stderr,"Error in source command use a filename\n"); + if (strlen(arg) < 1) + { + fprintf(stderr, "Error in source command use a filename\n"); return -1; } includeFile = fopen(arg, "r"); - if(!includeFile) { - fprintf(stderr,"Unable to open file %s for reading\n",arg); + if (!includeFile) + { + fprintf(stderr, "Unable to open file %s for reading\n",arg); return -1; } - while(!feof(includeFile)) { - memset(line,0,sizeof(line)); - fgets(line,sizeof(line),includeFile); - - if(strlen(line) < 2) continue; - if(line[0] == '#') continue; + while (fgets(line, sizeof(line), includeFile)) + { + if (strlen(line) < 2) + continue; + if (line[0] == '#') + continue; if ((cp = strrchr(line, '\n'))) *cp = '\0'; - if( echo ) { - printf( "processing line: %s\n",line ); - }; + if (echo) + printf("processing line: %s\n", line); process_cmd_line(line); } - if(fclose(includeFile)<0) { + if (fclose(includeFile)) + { perror("unable to close include file"); exit(1); } @@ -3574,12 +3585,12 @@ int cmd_source_noecho(const char* arg) int cmd_subshell(const char* args) { - if(strlen(args)) - system(args); - else - system(getenv("SHELL")); - + int ret = system(strlen(args) ? args : getenv("SHELL")); printf("\n"); + if (ret) + { + printf("Exit %d\n", ret); + } return 1; } @@ -3710,6 +3721,16 @@ int cmd_set_marcdump(const char* arg) return 1; } +static void marc_file_write(const char *buf, size_t sz) +{ + if (marc_file) + { + if (fwrite(buf, 1, sz, marc_file) != sz) + { + perror("marcfile write"); + } + } +} /* this command takes 3 arge {name class oid} */ @@ -3890,9 +3911,13 @@ static void handle_srw_record(Z_SRW_record *rec) printf("\n"); if (rec->recordData_buf && rec->recordData_len) { - fwrite(rec->recordData_buf, 1, rec->recordData_len, stdout); - if (marc_file) - fwrite(rec->recordData_buf, 1, rec->recordData_len, marc_file); + if (fwrite(rec->recordData_buf, 1, rec->recordData_len, stdout) != + (size_t) (rec->recordData_len)) + { + printf("write to stdout failed\n"); + } + printf("%.*s", rec->recordData_len, rec->recordData_buf); + marc_file_write(rec->recordData_buf, rec->recordData_len); } else printf("No data!"); @@ -4858,12 +4883,12 @@ static void client(void) static void show_version(void) { - char vstr[20]; + char vstr[20], sha1_str[41]; - yaz_version(vstr, 0); - printf("YAZ version: %s\n", YAZ_VERSION); - if (strcmp(vstr, YAZ_VERSION)) - printf("YAZ DLL/SO: %s\n", vstr); + yaz_version(vstr, sha1_str); + printf("YAZ version: %s %s\n", YAZ_VERSION, YAZ_VERSION_SHA1); + if (strcmp(sha1_str, YAZ_VERSION_SHA1)) + printf("YAZ DLL/SO: %s %s\n", vstr, sha1_str); exit(0); } @@ -5025,6 +5050,7 @@ int main(int argc, char **argv) /* * Local variables: * c-basic-offset: 4 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil * End: * vim: shiftwidth=4 tabstop=8 expandtab