1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
/*-----------------------------------------------------------------------
File : cio_simplestuff.c
Author: Stephan Schulz (schulz@eprover.org)
Contents
Simple I/O functions needing a home.
Copyright 2012 by the author.
This code is released under the GNU General Public Licence.
See the file COPYING in the main CLIB directory for details.
Run "eprover -h" for contact information.
Changes
<1> Fri Jul 27 01:36:57 CEST 2012
New
-----------------------------------------------------------------------*/
#include "cio_simplestuff.h"
/*---------------------------------------------------------------------*/
/* Global Variables */
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/* Forward Declarations */
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/* Internal Functions */
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/* Exported Functions */
/*---------------------------------------------------------------------*/
/*-----------------------------------------------------------------------
//
// Function: ReadTextBlock()
//
// Read lines from fp until terminator is encountered (on a line by
// itself). Note that termiantor has to end in \n for this to ever
// work. The read text, up to, but not including, terminator, is
// appended to result (which is not cleared!). Returns
// success/failure.
//
// Global Variables: -
//
// Side Effects :
//
/----------------------------------------------------------------------*/
bool ReadTextBlock(DStr_p result, FILE* fp, char* terminator)
{
char buf[256];
char* res;
while(true)
{
res = fgets(buf, 256, fp);
if(!res)
{
return false;
}
if(strcmp(buf, terminator) == 0)
{
break;
}
DStrAppendStr(result, buf);
}
return true;
}
/*-----------------------------------------------------------------------
//
// Function: TCPReadTextBlock()
//
// Read lines from network socket until terminator is encountered (on a line by
// itself). Note that termiantor has to end in \n for this to ever
// work. The read text, up to, but not including, terminator, is
// appended to result (which is not cleared!). Returns
// success/failure.
//
// Global Variables: -
//
// Side Effects :
//
/----------------------------------------------------------------------*/
bool TCPReadTextBlock(DStr_p result, int fd, char* terminator)
{
char* res;
while(true)
{
res = TCPStringRecvX(fd);
if(strcmp(res, terminator) == 0)
{
FREE(res);
break;
}
DStrAppendStr(result, res);
FREE(res);
}
return true;
}
/*---------------------------------------------------------------------*/
/* End of File */
/*---------------------------------------------------------------------*/
|