Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- intention: replace all instances of > with an HTML color code and terminate all such lines with closing tags
- Current implementation breaks somewhat (but not catastrophically?) if there is a > on a line and it is not the first character on said line.
- Otherwise, it seems to test well. Wood-touching advised.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #define COLOR_CODE "<strong><span style=\"color: #99cc00;\">"
- #define CLOSING_TAGS "</strong></span>\n"
- int main(int argc, char *argv[]) {
- //over 9000 debug messages
- printf("filename: %s\n", argv[1]);
- printf("starting, oh god what have I done\n");
- printf(COLOR_CODE);
- printf("\n");
- if (argc < 3) {
- 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).");
- exit(EXIT_FAILURE);
- }
- FILE *infile = fopen(argv[1], "r");
- FILE *outfile = fopen(argv[2], "w");
- int closetags = 0;
- for (char c = fgetc(infile); c != EOF; c = fgetc(infile)) {
- printf("loop nya! %c\n", c, stdin);
- if (c == '>' && closetags == 0) {
- printf("match nyan\n", stdin);
- fputs (COLOR_CODE, outfile); // line has >, add HTML color tag
- closetags = 1;
- } else if (c == '\n' && closetags == 1) {
- fputs(CLOSING_TAGS, outfile); // if added, close HTML tags
- closetags = 0;
- } else fputc(c, outfile); // else no processing needed, copy char to outfile
- }
- if (closetags == 1) fputs(CLOSING_TAGS, outfile); //special case for closing tags at EOF
- fclose(outfile);
- fclose(infile);
- printf("You have successfully completed mauling the c language and mocking the programmers' art");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement