preproc.c (556B)
1 // Copyright 2021, Brian Swetland <swetland@frotz.net> 2 // Licensed under the Apache License, Version 2.0. 3 4 #include <stdio.h> 5 #include <string.h> 6 7 int main(int argc, char** argv) { 8 char line[1024]; 9 int discard = 0; 10 11 while (fgets(line, 1024, stdin) != NULL) { 12 if (strncmp(line, "#if C", 5) == 0) { 13 discard = 1; 14 continue; 15 } 16 if (strncmp(line, "#else", 5) == 0) { 17 discard = 0; 18 continue; 19 } 20 if (strncmp(line, "#endif", 6) == 0) { 21 discard = 0; 22 continue; 23 } 24 if (discard) { 25 continue; 26 } 27 fputs(line, stdout); 28 } 29 return 0; 30 } 31