Commit in epics/trunk/epics_example on MAIN
include/client_util.h+1739 -> 740
myexampleApp/src/client_util.c+100739 -> 740
+101
2 modified files
new main read fnc

epics/trunk/epics_example/include
client_util.h 739 -> 740
--- epics/trunk/epics_example/include/client_util.h	2014-06-25 22:51:17 UTC (rev 739)
+++ epics/trunk/epics_example/include/client_util.h	2014-06-25 22:54:11 UTC (rev 740)
@@ -16,6 +16,7 @@
 int close_socket(int socketfd);
 void getSystemDOM(int* sockfd, xmlDoc** document, xmlNode** root);
 char* read_system_xml_string(int* socketfd);
+void read_system_xml_string2(int* socketfd, char buffer[], const int MAX);
 xmlNode* retrieveElement(xmlDoc* doc, xmlNode* node, char* tag);
 void retrieveValue(xmlDoc* doc, xmlNode* node, char* tags, char value[], const unsigned int MAX);
 void readTemp(int* sockfd,char value[],const unsigned int MAX);

epics/trunk/epics_example/myexampleApp/src
client_util.c 739 -> 740
--- epics/trunk/epics_example/myexampleApp/src/client_util.c	2014-06-25 22:51:17 UTC (rev 739)
+++ epics/trunk/epics_example/myexampleApp/src/client_util.c	2014-06-25 22:54:11 UTC (rev 740)
@@ -119,7 +119,107 @@
 
 
 
+void read_system_xml_string2(int* socketfd, char buffer[], const int MAX) {
+  const unsigned int READ_BUFFER_SIZE = 256;
+  char buffer_read[MAX];
+  char buf[READ_BUFFER_SIZE];
+  int read_i = 0;
+  int read_n;
+  int debug = 0;
+  int n_endings = 0;
+  int offset = 0;
+  //reset
+  bzero(buffer,MAX);
+  if(debug>0) printf("read xml2\n");
 
+  while(read_i<10000) { // some large number to avoid problems
+    if(debug>0) printf("at read_i %d\n",read_i);
+
+    //strcpy(buffer_read_overlap,buffer_read);//,READ_BUFFER_SIZE); 
+    bzero(buf,READ_BUFFER_SIZE);
+    read_n = read((*socketfd),buf,(READ_BUFFER_SIZE-1));
+    if(debug>0) printf("read_n %d\n",read_n);
+
+    if (read_n < 0) 
+      error("ERROR reading from socket");
+    //printf("buffer_read_overlap after clearing the old buffer:\n%s\nbuffer below:\n",buffer_read_overlap);
+    if(debug!=0) printf("%s\n",buf);
+
+
+    //if(strstr(buf,"\f")!=0) {
+    if(strchr(buf,'\f')!=0) {
+      if(debug>0) printf("found ending in this buf!\n");
+      n_endings++;
+    }
+
+    //check for overflow
+    if(offset > MAX) {
+      printf("\nread offset %d exceeds available buffer length %d at  read_i %d\n",offset, MAX,read_i);
+      return;
+    }
+
+    if(debug!=0) printf("\ncopy buf to %d offset after %p\n",offset,buffer_read);
+    strcpy(buffer_read+offset,buf);
+    offset = offset + strlen(buf);
+    //memcpy(buffer_read+read_i*(READ_BUFFER_SIZE),buf,READ_BUFFER_SIZE-1);
+    //buffer_read[read_i*READ_BUFFER_SIZE+READ_BUFFER_SIZE] = NULL;
+
+    if(debug!=0) {
+      printf("\nlen is %d after read_i %d\n%s\n",strlen(buffer_read),read_i,buffer_read);
+      //int k;
+      //for(k=253;k<260;++k) printf("%d \'%c\'\n",k,buffer_read[k]);
+    }
+    
+    if(n_endings>=2) {
+      if(debug!=0) printf("\nfound two endings at read_i %d with total len\n",read_i,strlen(buffer_read));      
+      break;
+    }
+
+    if(read_i>10000) {
+      if(debug!=0) printf("\ntoo many reads, error getting xml string at read_i %d\n",read_i);
+      break;
+    }
+
+    ++read_i;
+  }
+
+  if(n_endings==2) {
+    
+    if(debug!=0) printf("\nPick out string between endings \n%s\n",buffer_read);
+    //int k=0;
+    //for(k=read_i*READ_BUFFER_SIZE;k>(read_i-2)*READ_BUFFER_SIZE;--k) printf("%d \'%c\'\n",k,buffer_read[k]);
+    if(debug!=0) printf("\ndone\n");
+    if(debug!=0) printf("\nlen %d\n",strlen(buffer_read));
+    //char* start = strstr(buffer_read,"\f");
+    char* start = strchr(buffer_read,'\f');
+    char* end2 = strrchr(buffer_read,'\f');
+    if(start!=NULL) {
+      if(debug!=0) printf("\nstart at %p offset %d\n",start,start-buffer_read);
+      if(end2!=NULL) {
+	if(debug!=0) printf("\n end2 at %p offset %d\n",end2,end2-buffer_read);
+      }
+      //char* end = strstr(start+2,"\f");
+      char* end = strchr(start+1,'\f');
+      if(end!=NULL) {
+	if(debug!=0) printf("\nend at %p\n",end);
+	memcpy(buffer,start+1,end-(start+1));
+	buffer[end-(start+1)+1] = NULL; // terminate it
+	if(debug!=0) printf("\ncopied %d chars to %p\n%s\n",end-(start+1),buffer,buffer);	
+      } else {
+	if(debug!=0) printf("\n no end found\n");
+      }
+    } else {
+      if(debug!=0) printf("\n no start found found\n");
+    }
+    
+  }
+
+  return;
+
+}
+
+
+
 char* read_system_xml_string(int* socketfd) {
   int debug = 0;
   int read_ii;
SVNspam 0.1