Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- /*
- * This subtracts 5 from the "ENCODING" field of a BDF font file for each instance of it.
- * Good luck reading it. You'll need it, I think. I can barely read it looking back, but it
- * made a lot of sense when I first wrote it.
- * Kids, don't write code like this at work!
- */
- int main(int argc, char *argv[]){
- FILE *file=fopen(argv[1],"r");
- char strbuf[100]; /* if you have a BDF with a single line larger than 100 chars you'll want to fix this */
- /* seek for ENCODING line */
- int seeking=0;
- int go=0;
- int strbufpos=0;
- long lastlinestartpos=0;
- int intchr;
- char chr;
- while (seeking == 0){
- strbufpos=0;
- int j=0;
- /* clear strbuf */
- while(j < 100){
- strbuf[j]='\0';
- j=j+1;
- }
- while (go == 0){
- intchr= fgetc(file);
- if(intchr == EOF) {
- exit(0);
- }
- chr=(char)intchr;
- if(chr == '\n') {
- go=1;
- lastlinestartpos=ftell(file);
- }
- strbuf[strbufpos]=chr;
- strbufpos = strbufpos + 1;
- /* printf("%c",chr);*/
- } /* go */
- /* new line started, is string "ENCODING"? */
- if( strbuf[0]=='E' && strbuf[1]=='N' && strbuf[2]=='C' && strbuf[3]=='O' && strbuf[4] == 'D' && strbuf[5] == 'I' && strbuf[6] == 'N' && strbuf[7] == 'G')
- {
- int j=0;
- char tmpforatoi[10];
- while(strbuf[9 + j] != '\0') {
- tmpforatoi[j]=strbuf[9 + j];
- j=j+1;
- }
- /* subtract 5 to fix horrible crap from hex/decimal disparity */
- int encodingnum=atoi(tmpforatoi) - 5;
- /* zero out strbuf */
- j=0;
- while(j < 100){
- strbuf[j]='\0';
- j=j+1;
- }
- j=0;
- /* too lazy to figure out how to set a non-pointer char array to a string with doublequotes */
- strbuf[0]='E';
- strbuf[1]='N';
- strbuf[2]='C';
- strbuf[3]='O';
- strbuf[4]='D';
- strbuf[5]='I';
- strbuf[6]='N';
- strbuf[7]='G';
- strbuf[8]=' ';
- char newstr[10];
- snprintf(newstr,10,"%d",encodingnum);
- while(newstr[j] != '\0')
- {
- strbuf[9+j]=newstr[j];
- j=j+1;
- }
- strbuf[9+j]='\n';
- strbuf[10+j]='\0';
- } /* ENCODING */
- printf("%s",strbuf); /* print last line */
- go=0; /* resume seeking for next instance of ENCODING */
- } /* seeking */
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement