[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r26085 - monkey/trunk/pathologist/src/struct_parse
From: |
gnunet |
Subject: |
[GNUnet-SVN] r26085 - monkey/trunk/pathologist/src/struct_parse |
Date: |
Wed, 13 Feb 2013 11:19:29 +0100 |
Author: teichm
Date: 2013-02-13 11:19:29 +0100 (Wed, 13 Feb 2013)
New Revision: 26085
Modified:
monkey/trunk/pathologist/src/struct_parse/p.c
Log:
structparse draft uses stdin now and outputs xml
Modified: monkey/trunk/pathologist/src/struct_parse/p.c
===================================================================
--- monkey/trunk/pathologist/src/struct_parse/p.c 2013-02-13 08:50:06 UTC
(rev 26084)
+++ monkey/trunk/pathologist/src/struct_parse/p.c 2013-02-13 10:19:29 UTC
(rev 26085)
@@ -1,6 +1,7 @@
#include <stdio.h>
+#include <stdlib.h>
-int parse(char* str) {
+int parse(char* str, int indent) {
char* token = str;
char* name;
char* value;
@@ -38,26 +39,61 @@
if(*(token+1) != '\0') return 0;
else {
*(token++) = '\0';
- printf("name: %s\tvalue: %s\n", name, value);
+ printf("%*s<expression
name=\"%s\">%s</expression>\n", 2*indent, "", name, value);
break;
}
*(token++) = '\0';
- if(!i && printf("name: %s\n", name)) {
- if(!parse(value)) ret = 0;
- } else printf("name: %s\tvalue: %s\n", name, value);
+ if(!i && printf("%*s<expression name=\"%s\">\n", 2*indent, "",
name)) {
+ if(!parse(value, indent+1)) ret = 0;
+ printf("%*s</expression>\n", 2*indent, "");
+ } else printf("%*s<expression name=\"%s\">%s</expression>\n",
2*indent, "", name, value);
while(*token == ',' || *token == ' ') token++;
if(*token == '}' && *(token+1) == '\0') break;
}
return ret;
}
+char * getl(void) {
+ char * line = malloc(128), * linep = line;
+ size_t lenmax = 128, len = lenmax;
+ int c;
+ if(line == NULL)
+ return NULL;
+ for(;;) {
+ c = fgetc(stdin);
+ if(c == EOF)
+ break;
+
+ if(--len == 0) {
+ len = lenmax;
+ char * linen = realloc(linep, lenmax *= 2);
+
+ if(linen == NULL) {
+ free(linep);
+ return NULL;
+ }
+ line = linen + (line - linep);
+ linep = linen;
+ }
+
+ if((*line = c) == '\n')
+ break;
+ line++;
+ }
+ *line = '\0';
+ return linep;
+}
+
+
int main(int argc, char* argv[]) {
- int i;
- for(i=1; i<argc; i++) {
- printf("\nreturned: %d\n", parse(argv[i]));
+ char* line;
+ while(line = getl()) {
+ if(*line == '\0') break;
+ printf("\nreturned: %d\n", parse(line, 1));
+ free(line);
}
-
+ if(line) free(line);
return 0;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r26085 - monkey/trunk/pathologist/src/struct_parse,
gnunet <=