Skip to content

Instantly share code, notes, and snippets.

@DreamVB
Created July 19, 2016 22:05
Show Gist options
  • Save DreamVB/59df83edf40dbca38a968b0fb46deed1 to your computer and use it in GitHub Desktop.
Save DreamVB/59df83edf40dbca38a968b0fb46deed1 to your computer and use it in GitHub Desktop.
A Small C Project to Pack CSS files makeing them smaller
/*
DM CSS PACKER v1.0 [STILL NEEDS WORK]
Simple CSS packer comments are not yet supported.
By Ben Jones a.k.a DreamVB
Please feel free to use this code as you like.
if you feel it has helped you let me know at dreamvb@outlook.com
*/
#include <stdio.h>
#include <string>
FILE *fout = NULL;
bool IsWhite(char c){
if((c==' ') || (c == '\t') || (c =='\r') || (c == '\n')){
return true;
}
return false;
}
int main(int argc, char *argv[]){
FILE *fp = NULL;
char c = '\0';
char temp = c;
//Check number of parms.
if(argc != 3){
printf("Syntax Error\n");
printf("Usage: infile outfile\n");
return 0;
}
//open file
fp = fopen(argv[1],"rb");
//Check for source file.
if(!fp){
printf("File Not Found: %s\n",argv[1]);
return 0;
}
//Create output file.
fout = fopen(argv[2],"wb");
if(!fout){
printf("Output File Error.\n");
fclose(fp);
return 0;
}
//While not end of file read in the data.
while(!feof(fp)){
c = fgetc(fp);
//Format the new output file.
if(!feof(fp)){
//Check for line breaks and eat them
if((c == '\r') || (c == '\n')){
//Eat any spaces
while(IsWhite(c)){
//Get next char
c = fgetc(fp);
}
//Write char to output file.
fputc(c,fout);
}
else{
//Trim any white-space after ; or :
if((c== ':') || (c==';')){
//eat space
temp = c;
c = fgetc(fp);
//Eat space
while(isspace(c)){
c = fgetc(fp);
}
//Put prev char
fputc(temp,fout);
}
//Put char to output file.
fputc(c,fout);
}
}
}
//Close input and output file.
fclose(fp);
fclose(fout);
//Return 1
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment