#include #include #include #include #include #define WASMOUT "w.out" #define BASE64SUFFIX ".base64" #define WASMBASE64 WASMOUT BASE64SUFFIX #define HTMLOUT "index.html" #define NL(T) do { if (printWhitespace == true) fprintf(out,"\n"); for (int __t = T;__t > 0;__t--) fputc('\t',out); } while(0) #define write(STRING) fwrite(STRING,strlen(STRING),1,out); int main(int argc, char **argv) { (void)argc; (void)argv; bool printWhitespace = true; //compile input C if (argc < 2) { fprintf(stderr,"No arguments.\n"); } char *outName = HTMLOUT; if (argc >= 3) outName = argv[2]; char commandString[10000] = { 0 }; int status = 0; int printed = 0; fprintf(stderr,"Compiling %s to %s\n",argv[1],WASMOUT); {//compile printed = snprintf(commandString,10000,"clang --target=wasm32 -Os -flto -nostdlib -fno-builtin -Wl,--no-entry -Wl,--export-all -Wl,--lto-O3 -Wl,-z,stack-size=8388608 -o %s %s",WASMOUT,argv[1]); if (printed == 10000) { commandString[9999] = 0; fprintf(stderr,"commandString exceeded 10000 characters:%s\n",commandString); return -1; } status = system(commandString); if (status != 0) { fprintf(stderr,"Error executing command:%d:%s\n",status,commandString); return -1; } } fprintf(stderr,"Converting %s to bas64 %s\n",WASMOUT,WASMBASE64); {//base64 printed = snprintf(commandString,10000,"base64 -w 0 %s > %s",WASMOUT,WASMBASE64); if (printed == 10000) { commandString[9999] = 0; fprintf(stderr,"commandString exceeded 10000 characters:%s\n",commandString); return -1; } status = system(commandString); if (status != 0) { fprintf(stderr,"Error executing command:%d:%s:%s\n",status,strerror(errno),commandString); return -1; } } fprintf(stderr,"Output %s\n",outName); {//output page FILE *w64File; w64File = fopen(WASMBASE64,"r"); if (w64File == NULL) { fprintf(stderr,"fopen: %s",strerror(errno)); return -1; } FILE *out; out = fopen(outName,"w"); if (out == NULL) { fprintf(stderr,"fopen: %s",strerror(errno)); return -1; } int t = 0; write("");NL(t); write("");NL(t++); write("");NL(t++); write("");NL(t); fprintf(out,"%s",outName);NL(t--); write("");NL(t); write("");NL(t); //background:repeating-conic-gradient(#808080 0% 25%, #404040 0% 50%) 50% / 20px 20px; write("");NL(0); for (int c = fgetc(w64File);feof(w64File) == 0;c = fgetc(w64File)) { if (fputc(c,out) == EOF) { fprintf(stderr,"fputc: %s",strerror(errno)); return -1; } } NL(t); write("");NL(t); write("");NL(t--); write("");NL(t--); write("");NL(0); } {//clean up fprintf(stderr,"Deleting %s\n",WASMOUT); printed = snprintf(commandString,10000,"rm %s",WASMOUT); if (printed == 10000) { commandString[9999] = 0; fprintf(stderr,"commandString exceeded 10000 characters:%s\n",commandString); return -1; } status = system(commandString); if (status != 0) { fprintf(stderr,"Error executing command:%d:%s:%s\n",status,strerror(errno),commandString); return -1; } fprintf(stderr,"Deleting %s\n",WASMBASE64); printed = snprintf(commandString,10000,"rm %s",WASMBASE64); if (printed == 10000) { commandString[9999] = 0; fprintf(stderr,"commandString exceeded 10000 characters:%s\n",commandString); return -1; } status = system(commandString); if (status != 0) { fprintf(stderr,"Error executing command:%d:%s:%s\n",status,strerror(errno),commandString); return -1; } } return 0; }