COOPY » Guide  version 0.6.5
/home/paulfitz/cvs/coopy_scm/coopy/src/libjs/codify.cpp
Go to the documentation of this file.
00001 
00002 #include <stdio.h>
00003 #include <string.h>
00004 
00005 int main(int argc, char *argv[]) {
00006   if (argc!=4) {
00007     return 1;
00008   }
00009   char *src = argv[1];
00010   char *dest = argv[2];
00011   char *tag = argv[3];
00012 
00013   FILE *fin = fopen(src,"r");
00014   FILE *fout = fopen(dest,"w");
00015   if (fin==NULL) return 1;
00016   if (fout==NULL) return 1;
00017   fprintf(fout, "#include <string>\n");
00018   fprintf(fout, "std::string %s() { \n", tag);
00019   fprintf(fout, "std::string result = \"");
00020   while (!feof(fin)) {
00021     char buf[1000];
00022     char *result = fgets(buf,sizeof(buf),fin);
00023     if (result!=NULL) {
00024       for (int i=0; i<strlen(result); i++) {
00025         char ch = result[i];
00026         switch (ch) {
00027         case '\r':
00028         case '\n':
00029           break;
00030         case '\?':
00031         case '\"':
00032         case '\'':
00033         case '\\':
00034           fprintf(fout, "\\%c", ch);      
00035           break;
00036         default:
00037           fprintf(fout, "%c", ch);
00038           break;
00039         }
00040       }
00041       fprintf(fout, "\\n\\\n");
00042     }
00043   }
00044   fprintf(fout, "\";\n");
00045   fprintf(fout, "return result;\n");
00046   fprintf(fout, "}\n");
00047   fclose(fout);
00048   fclose(fin);
00049 }
00050 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines