Last active
July 30, 2016 09:38
-
-
Save DreamVB/58c0141c848871cb29d64479b28d091f to your computer and use it in GitHub Desktop.
Compress htm and html sourcecode by reduceing not needed chars, allowing pages to load faster
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Compress HTML By DreamVB | |
Version 1.0 | |
A small tool to compress htm and html files makeing them smaller | |
in size to allow your web pages to load faster. | |
Please feel free to to use as you like or if you want add your own features and let me see the changes. | |
Please let me know if you found this code usfull e. [email protected] | |
*/ | |
#include <stdio.h> | |
#include <string> | |
int main(int argc, char* argv[]){ | |
FILE *fin = NULL; | |
FILE *fout = NULL; | |
char c = '\0'; | |
if(argc < 3){ | |
printf("Usage: <InFile> <OutFile>\n"); | |
return 0; | |
} | |
//Open inputfile. | |
fin = fopen(argv[1],"r"); | |
//Try and see if inputfile opened. | |
if(fin == NULL){ | |
printf("IO/Error cannot open file\n"); | |
return 0; | |
} | |
//Open output file | |
fout = fopen(argv[2],"w"); | |
//See if output file opened. | |
if(!fout){ | |
printf("IO/Error cannot write file\n"); | |
return 0; | |
} | |
while(!feof(fin)){ | |
//Read char | |
c = getc(fin); | |
//Remove \n | |
switch(c){ | |
case '\n': | |
c = fgetc(fin); | |
//Exit if at end of file | |
if(c == EOF){ | |
break; | |
} | |
//Eat spaces | |
while((c == ' ') || (c=='\t')) | |
{ | |
c = fgetc(fin); | |
} | |
//Eat line breaks | |
if(c == '\n'){continue;} | |
if(c == '\r'){continue;} | |
fputc(c,fout); | |
case '\t': | |
//Eat tab | |
continue; | |
} | |
//else{ | |
if(!feof(fin)){ | |
//Put char into output file. | |
fputc(c,fout); | |
} | |
} | |
//Close files | |
fclose(fin); | |
fclose(fout); | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment