summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2008-12-28 10:34:40 (GMT)
committer Jaromil <jaromil@dyne.org>2009-03-22 15:06:15 (GMT)
commitcea626fa2bd6501f09510768dbf0ffb5ea9d8ac4 (patch)
tree3938d74993e8412d8d13d03f69d9af604d586fe2
parent089a8dff564835437a7aa4833c4c28412fad00ad (diff)
added dokuwiki tbt-tag/JSON wrapper format.
-rw-r--r--cmdline.cpp14
-rw-r--r--tbt.cpp42
2 files changed, 54 insertions, 2 deletions
diff --git a/cmdline.cpp b/cmdline.cpp
index d9c92f1..a93d922 100644
--- a/cmdline.cpp
+++ b/cmdline.cpp
@@ -111,6 +111,7 @@ int operation = 0x0;
#define BIN 1
#define ASCII 2
#define HTML 3
+#define DOKU 4
int render = BIN;
@@ -187,6 +188,8 @@ void cmdline(int argc, char **argv) {
render = ASCII;
else if( strcasecmp(optarg, "HTML") ==0)
render = HTML;
+ else if( strncasecmp(optarg, "DOKU", 4) ==0)
+ render = DOKU;
else {
error ("render format not recognized: %s", optarg);
act ("using default binary format render");
@@ -403,7 +406,7 @@ int main(int argc, char** argv)
status = new SLW_Text();
switch(operation) {
-
+
case REC:
if( !record_console() ) break;
@@ -417,6 +420,11 @@ int main(int argc, char** argv)
tbt.save_ascii( filename );
break;
+ case DOKU:
+ tbt.save_doku( filename );
+ act("TBT file %s rendered in dokuwiki format",filename);
+ break;
+
case HTML:
tbt.save_html( filename );
break;
@@ -486,6 +494,10 @@ int main(int argc, char** argv)
tbt.save_html( filename );
break;
+ case DOKU:
+ tbt.save_doku( filename );
+ act("TBT file %s rendered in dokuwiki format",filename);
+ break;
}
break;
diff --git a/tbt.cpp b/tbt.cpp
index 2eb201f..de31048 100644
--- a/tbt.cpp
+++ b/tbt.cpp
@@ -255,7 +255,6 @@ void TBT::append(uint64_t key) {
-
uint64_t TBT::getkey() {
TBTEntry *ent;
ent = (TBTEntry*) buffer->pick(position);
@@ -465,6 +464,47 @@ int TBT::save_ascii(char *filename) {
return c;
}
+int TBT::save_doku(char *filename) {
+
+ int c, len;
+
+ void *buf;
+
+ FILE *fd;
+
+ fd = fopen(filename, "w");
+ if(!fd) return false;
+
+ fputs("{{tbt>[", fd);
+ // max bytes for an entry here
+ buf = malloc(512);
+ TBTEntry *ent;
+ ent = (TBTEntry*) buffer->begin();
+ // cycle thru with counter
+ c = 0;
+ while( ent ) {
+
+ if(c>0) // put a comma
+ fwrite(",",sizeof(char),1,fd);
+
+ len = ent->render_html(buf);
+
+ fwrite(buf, len, 1, fd);
+
+ c++;
+
+ ent = (TBTEntry*) ent->next;
+ }
+
+ fputs("]}}\n", fd);
+ fflush(fd);
+ fclose(fd);
+
+ free(buf);
+
+ return c;
+}
+
int TBT::save_html(char *filename) {
int c, len;