| 723 | } |
| 724 | |
| 725 | static int |
| 726 | parsefile(const char *filename) |
| 727 | { |
| 728 | FILE *file; |
| 729 | char line[BUFSIZ], *p, *pq, *pdq; |
| 730 | int warncount = 0, lineno = 0; |
| 731 | |
| 732 | file = fopen(filename, "r"); |
| 733 | if (file == NULL) |
| 734 | err(EX_NOINPUT, "%s", filename); |
| 735 | while (fgets(line, sizeof(line), file) != NULL) { |
| 736 | lineno++; |
| 737 | p = line; |
| 738 | pq = strchr(line, '\''); |
| 739 | pdq = strchr(line, '\"'); |
| 740 | /* Replace the first # with \0. */ |
| 741 | while((p = strchr(p, '#')) != NULL) { |
| 742 | if (pq != NULL && p > pq) { |
| 743 | if ((p = strchr(pq+1, '\'')) != NULL) |
| 744 | *(++p) = '\0'; |
| 745 | break; |
| 746 | } else if (pdq != NULL && p > pdq) { |
| 747 | if ((p = strchr(pdq+1, '\"')) != NULL) |
| 748 | *(++p) = '\0'; |
| 749 | break; |
| 750 | } else if (p == line || *(p-1) != '\\') { |
| 751 | *p = '\0'; |
| 752 | break; |
| 753 | } |
| 754 | p++; |
| 755 | } |
| 756 | /* Trim spaces */ |
| 757 | p = line + strlen(line) - 1; |
| 758 | while (p >= line && isspace((int)*p)) { |
| 759 | *p = '\0'; |
| 760 | p--; |
| 761 | } |
| 762 | p = line; |
| 763 | while (isspace((int)*p)) |
| 764 | p++; |
| 765 | if (*p == '\0') |
| 766 | continue; |
| 767 | else |
| 768 | warncount += parse(p, lineno); |
| 769 | } |
| 770 | fclose(file); |
| 771 | |
| 772 | return (warncount); |
| 773 | } |
| 774 | |
| 775 | /* These functions will dump out various interesting structures. */ |
| 776 | |