Skip to content

Instantly share code, notes, and snippets.

@DreamVB
Created July 18, 2016 22:20
Show Gist options
  • Save DreamVB/65663e34b627f7fd221441f4b981304e to your computer and use it in GitHub Desktop.
Save DreamVB/65663e34b627f7fd221441f4b981304e to your computer and use it in GitHub Desktop.
Small console project in C to unpack a packed css file
/*
DM CSS UNPACKER v1.0
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 [email protected]
*/
#include <stdio.h>
#include <string>
FILE *fout = NULL;
void PutLineBreak(){
//Add line break
fputc('\r',fout);
fputc('\n',fout);
}
void Ident(){
//Set indent to two spaces.
fputc(32,fout);
fputc(32,fout);
}
int main(int argc, char *argv[]){
FILE *fp = NULL;
char c = '\0';
//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)){
if(c == '{'){
fputc('{',fout);
PutLineBreak();
//Indent with space
Ident();
}else if(c == '}'){
PutLineBreak();
fputc('}',fout);
PutLineBreak();
PutLineBreak();
}else if(c == ';'){
fputc(';',fout);
PutLineBreak();
//Indent with space
Ident();
}
else{
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