Advertisement
Guest User

Zaka's Amazing VNTS re-formatter

a guest
Nov 14th, 2015
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.71 KB | None | 0 0
  1. /*
  2.   intention: replace all instances of > with an HTML color code and terminate all such lines with closing tags
  3.  
  4.   Current implementation breaks somewhat (but not catastrophically?) if there is a > on a line and it is not the first character on said line.
  5.   Otherwise, it seems to test well. Wood-touching advised.
  6. */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10.  
  11. #define COLOR_CODE "<strong><span style=\"color: #99cc00;\">"
  12. #define CLOSING_TAGS "</strong></span>\n"
  13.  
  14. int main(int argc, char *argv[]) {
  15.  
  16.   //over 9000 debug messages
  17.   printf("filename: %s\n", argv[1]);
  18.   printf("starting, oh god what have I done\n");
  19.   printf(COLOR_CODE);
  20.   printf("\n");
  21.  
  22.   if (argc < 3) {
  23.     printf("Usage: stedit(.exe) infile outfile.\nInfile is the file to be processed. Outfile will contain the result, and will be created if not present (probably).");
  24.       exit(EXIT_FAILURE);
  25.       }
  26.  
  27.   FILE *infile = fopen(argv[1], "r");
  28.   FILE *outfile = fopen(argv[2], "w");
  29.   int closetags = 0;
  30.  
  31.   for (char c = fgetc(infile); c != EOF; c = fgetc(infile)) {
  32.     printf("loop nya! %c\n", c, stdin);
  33.    
  34.     if (c == '>' && closetags == 0) {
  35.       printf("match nyan\n", stdin);
  36.       fputs (COLOR_CODE, outfile); // line has >, add HTML color tag
  37.       closetags = 1;
  38.     } else if (c == '\n' && closetags == 1) {
  39.       fputs(CLOSING_TAGS, outfile); // if added, close HTML tags
  40.     closetags = 0;
  41.     } else fputc(c, outfile); // else no processing needed, copy char to outfile
  42. }
  43.  
  44.   if (closetags == 1) fputs(CLOSING_TAGS, outfile); //special case for closing tags at EOF
  45.  
  46.   fclose(outfile);
  47.   fclose(infile);
  48.   printf("You have successfully completed mauling the c language and mocking the programmers' art");
  49.   return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement