Advertisement
wyatt8740

bdf font fixer for gbdfed

Mar 23rd, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. /*
  5. * This subtracts 5 from the "ENCODING" field of a BDF font file for each instance of it.
  6. * Good luck reading it. You'll need it, I think. I can barely read it looking back, but it
  7. * made a lot of sense when I first wrote it.
  8. * Kids, don't write code like this at work!
  9. */
  10.  
  11. int main(int argc, char *argv[]){
  12. FILE *file=fopen(argv[1],"r");
  13. char strbuf[100]; /* if you have a BDF with a single line larger than 100 chars you'll want to fix this */
  14. /* seek for ENCODING line */
  15. int seeking=0;
  16. int go=0;
  17. int strbufpos=0;
  18. long lastlinestartpos=0;
  19. int intchr;
  20. char chr;
  21. while (seeking == 0){
  22. strbufpos=0;
  23. int j=0;
  24. /* clear strbuf */
  25. while(j < 100){
  26. strbuf[j]='\0';
  27. j=j+1;
  28. }
  29. while (go == 0){
  30. intchr= fgetc(file);
  31. if(intchr == EOF) {
  32. exit(0);
  33. }
  34. chr=(char)intchr;
  35. if(chr == '\n') {
  36. go=1;
  37. lastlinestartpos=ftell(file);
  38. }
  39. strbuf[strbufpos]=chr;
  40. strbufpos = strbufpos + 1;
  41. /* printf("%c",chr);*/
  42. } /* go */
  43. /* new line started, is string "ENCODING"? */
  44. 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')
  45. {
  46. int j=0;
  47. char tmpforatoi[10];
  48. while(strbuf[9 + j] != '\0') {
  49. tmpforatoi[j]=strbuf[9 + j];
  50. j=j+1;
  51. }
  52. /* subtract 5 to fix horrible crap from hex/decimal disparity */
  53. int encodingnum=atoi(tmpforatoi) - 5;
  54. /* zero out strbuf */
  55. j=0;
  56. while(j < 100){
  57. strbuf[j]='\0';
  58. j=j+1;
  59. }
  60. j=0;
  61. /* too lazy to figure out how to set a non-pointer char array to a string with doublequotes */
  62. strbuf[0]='E';
  63. strbuf[1]='N';
  64. strbuf[2]='C';
  65. strbuf[3]='O';
  66. strbuf[4]='D';
  67. strbuf[5]='I';
  68. strbuf[6]='N';
  69. strbuf[7]='G';
  70. strbuf[8]=' ';
  71. char newstr[10];
  72. snprintf(newstr,10,"%d",encodingnum);
  73. while(newstr[j] != '\0')
  74. {
  75. strbuf[9+j]=newstr[j];
  76. j=j+1;
  77. }
  78. strbuf[9+j]='\n';
  79. strbuf[10+j]='\0';
  80. } /* ENCODING */
  81. printf("%s",strbuf); /* print last line */
  82. go=0; /* resume seeking for next instance of ENCODING */
  83. } /* seeking */
  84. return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement