COOPY » Guide  version 0.6.5
/home/paulfitz/cvs/coopy_scm/coopy/src/ssrender/stringify.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 *name = 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", name);
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 (size_t 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           fprintf(fout, "\\%c", ch);      
00034           break;
00035         default:
00036           fprintf(fout, "%c", ch);
00037           break;
00038         }
00039       }
00040       fprintf(fout, "\\n\\\n");
00041     }
00042   }
00043   fprintf(fout, "\";\n");
00044   fprintf(fout, "return result;\n");
00045   fprintf(fout, "}\n");
00046   fclose(fout);
00047   fclose(fin);
00048 }
00049 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines