Thread: [Refdb-cvs] CVS: refdb/src refdb-client.c,1.31.2.2,1.31.2.3 refdb-client.h,1.15.2.1,1.15.2.2
Status: Beta
Brought to you by:
mhoenicka
From: Markus H. <mho...@us...> - 2006-02-05 01:31:25
|
Update of /cvsroot/refdb/refdb/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18855 Modified Files: Tag: Release_0_9_5_stable refdb-client.c refdb-client.h Log Message: new function read_terminated_string() Index: refdb-client.c =================================================================== RCS file: /cvsroot/refdb/refdb/src/refdb-client.c,v retrieving revision 1.31.2.2 retrieving revision 1.31.2.3 diff -u -U2 -r1.31.2.2 -r1.31.2.3 --- refdb-client.c 29 Jul 2005 21:15:35 -0000 1.31.2.2 +++ refdb-client.c 5 Feb 2006 01:31:02 -0000 1.31.2.3 @@ -862,4 +862,104 @@ /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + read_terminated_string(): reads a terminated string, usually a dataset + + size_t read_terminated_string returns the number of bytes written to + pagerfp. In case of an error, *ptr_error + is set to 1 + + struct simplelistvals* ptr_slvals ptr to struct with data for dialog + + FILE *pagerfp ptr to a FILE struct for the output stream for server + messages + + int* ptr_error ptr to error variable + + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +size_t read_terminated_string(struct simplelistvals* ptr_slvals, FILE* pagerfp, int* ptr_error) { + int n_read_done = 0; + int n_curr_trailing_z = 0; + int n_last_trailing_z = 0; + size_t byte_written = 0; + size_t numbyte; + + *ptr_error = 0; + + do { /* loop until a terminated string is complete */ +/* printf("looking for a terminated string...\n"); */ + if (n_curr_trailing_z) { + numbyte += tread(ptr_slvals->n_sockfd, ptr_slvals->inbuffer+numbyte, TERM_LEN-n_curr_trailing_z); + } + else { + numbyte = tread(ptr_slvals->n_sockfd, ptr_slvals->inbuffer, OUTBUF_LEN); + } + + if (numbyte == -1) { + fprintf(stderr, get_status_msg(109)); + fprintf(stderr, "\n"); + if (ptr_slvals->n_file_open || ptr_slvals->n_file_append) { + close_outfile(pagerfp); + } + else { + closepager(pagerfp); + } + n_broken_pipe = 0; +/* delete_all_lilimem(&sentinel); */ + *ptr_error = 1; + return 0; + } + + n_curr_trailing_z = get_trailz(ptr_slvals->inbuffer, numbyte); +/* printf("n_curr_trailing_z went to %d<<n_last_trailing_z went to %d<<numbyte went to %d\n", n_curr_trailing_z, n_last_trailing_z, numbyte); */ + if (numbyte >= TERM_LEN) { + if (n_curr_trailing_z >= TERM_LEN) { + /* terminator is complete */ +/* printf("found complete terminator\n"); */ + n_last_trailing_z = 0; + n_read_done++; + /* send back confirmation to the server */ + send_status(ptr_slvals->n_sockfd, 0, TERM_NO); + } + else { + /* terminator is still incomplete */ +/* printf("incomplete terminator, trying again\n"); */ + } + } + else if (n_curr_trailing_z == numbyte + && n_curr_trailing_z + n_last_trailing_z >= TERM_LEN) { +/* printf("completed terminator\n"); */ + n_last_trailing_z = 0; + /* terminator is complete including the previous cycle */ + n_read_done++; + /* send back confirmation to the server */ + send_status(ptr_slvals->n_sockfd, 0, TERM_NO); + } + else if (n_curr_trailing_z == numbyte) { + /* terminator is still incomplete */ +/* printf("incomplete terminator, trying again\n"); */ + n_last_trailing_z += n_curr_trailing_z; + continue; + } + + /* write numbyte chars to output, unless this is the last chunk: we do not + want to write the terminating \0 */ + if (!n_broken_pipe) { + if (n_last_trailing_z) { +/* printf("writing n_last_trailing_z\n"); */ + byte_written += fwrite(cs_term, sizeof(char), n_last_trailing_z, pagerfp); + } +/* printf("writing numbytes\n"); */ + byte_written += fwrite(ptr_slvals->inbuffer, sizeof(char), numbyte-n_curr_trailing_z, pagerfp); + } +/* printf("n_read_done is %d<<n_done is %d<<\n", n_read_done, n_done); */ +/* printf("inbuffer went to:%s<<\nn_read_done is %d<<n_done is %d<<\n", ptr_slvals->inbuffer, n_read_done, n_done); */ + if (!n_read_done) { + n_last_trailing_z = n_curr_trailing_z; + } + } while (!n_read_done); + + return byte_written; +} + +/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ pipehandler(): handler for the SIGPIPE signal. Sets the global variable n_broken_pipe to non-zero. This condition Index: refdb-client.h =================================================================== RCS file: /cvsroot/refdb/refdb/src/refdb-client.h,v retrieving revision 1.15.2.1 retrieving revision 1.15.2.2 diff -u -U2 -r1.15.2.1 -r1.15.2.2 --- refdb-client.h 15 Apr 2005 22:45:08 -0000 1.15.2.1 +++ refdb-client.h 5 Feb 2006 01:31:02 -0000 1.15.2.2 @@ -20,4 +20,8 @@ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +#ifndef REFDB_CLIENT_H +#define REFDB_CLIENT_H 1 + +#include <stdio.h> /* required for the FILE definition */ struct simplelistvals { @@ -27,5 +31,5 @@ int n_pipe; /* if 1, write to pipe */ char* outbuffer; /* holds the command for the server */ - char inbuffer[OUTBUF_LEN]; /* holds the reply from the server */ + char inbuffer[OUTBUF_LEN+TERM_LEN]; /* holds the reply from the server */ char* outfile; /* ptr to string with output filename */ char* outpipe; /* ptr to string with pipe command */ @@ -42,2 +46,4 @@ void inthandler(int sig); char* build_batchcommand(int argc, char** argv, int optind, char* s, char* the_command); +size_t read_terminated_string(struct simplelistvals* ptr_slvals, FILE* pagerfp, int* ptr_error); +#endif |