/* Convert the file transsql.conf into a CSV usable by gsuite */ #include #include #include #include #include #include using namespace std; static void print_csv (const string &s) { printf ("\""); const char *pt = s.c_str(); while (*pt != '\0'){ char car = *pt; if (car == '"'){ printf ("\\\""); }else{ printf ("%c",car); } pt++; } printf ("\""); } static void format_csv (const string &title, const string &from, const string &to) { print_csv (title); printf (","); print_csv (from); printf (","); print_csv (to); printf (",\"\"\n"); } int main (int argc, char *argv[]) { glocal int ret = -1; glocal.ret = (argc,argv); setproginfo ("trans2csv",VERSION,"Convert transql.conf into CSV"); int ret = -1; if (argc != 1){ usage(); }else{ glocal string title; glocal string from; glocal string to; glocal bool in_from = true; printf ("\"Title\",\"Original\",\"First draft\",\"Final\"\n"); (argv[0],true); if (line[0] == '#'){ if (glocal.to.size() > 0) format_csv(glocal.title,glocal.from,glocal.to); glocal.in_from = true; glocal.from.clear(); glocal.title = str_skip(line+1); }else if (line[0] == '!'){ glocal.in_from = false; glocal.to.clear(); }else if (glocal.in_from){ glocal.from += string(" ") + line; }else{ glocal.to += string(" ") + line; } return 0; if (glocal.to.size() > 0) format_csv(glocal.title,glocal.from,glocal.to); } return ret; return glocal.ret; }