/* * libexplain - Explain errno values returned by libc functions * Copyright (C) 2009 Peter Miller * Written by Peter Miller * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #include #include #include #include #include #include #include #include #include #include #include static int initialised; static int fixme_count; static void begin(void) { if (initialised) return; initialised = 1; printf("\n"); printf("\n"); printf("

Fix Me, Please!

\n"); printf("The following notes were automatically extracted from\n"); printf("the source files, at places where the code is marked\n"); printf("“FIXME:”.\n"); printf("\n"); printf("\n"); } static void process(const char *filename) { FILE *fp; int line_number; begin(); fp = explain_fopen_or_die(filename, "r"); line_number = 0; for (;;) { char line[1000]; char *cp; if (!explain_fgets_or_die(line, sizeof(line), fp)) break; ++line_number; cp = strstr(line, "FIXME:"); if (cp) { char *ep; const char *fn; const char *bp; cp += 6; while (*cp && isspace((unsigned char)*cp)) ++cp; ep = cp + strlen(cp); while (ep > cp) { if (isspace((unsigned char)ep[-1])) { --ep; continue; } if (ep - cp >= 2 && ep[-2] == '*' && ep[-1] == '/') { ep -= 2; continue; } break; } fn = filename; bp = fn; while (bp[0] == 'b' && bp[1] == 'l') bp += 2; if (*bp == '/') fn = bp + 1; if ( 0 != strcmp(fn, "fixme-html/main.c") && 0 != strcmp(fn, "web-src/index.html") ) { printf("\n", fn); printf ( " \n", line_number ); printf ( " \n", (int)(ep - cp), cp ); printf(" \n"); ++fixme_count; } } } explain_fclose_or_die(fp); } static void end(void) { printf("
FilenameLineComment
%s%d:%.*s
\n"); printf("

\n"); printf ( "Found %d places in the code marked “FIXME:”.\n", fixme_count ); printf("\n"); printf("\n"); } static void process_list(const char *filename) { FILE *fp; fp = stdin; if (0 != strcmp(filename, "-")) fp = explain_fopen_or_die(filename, "r"); for (;;) { size_t len; char line[1000]; if (!explain_fgets_or_die(line, sizeof(line), fp)) break; len = strlen(line); if (line[len - 1] == '\n') line[len - 1] = '\0'; process(line); } if (fp != stdin) explain_fclose_or_die(fp); } static void usage(void) { const char *prog; prog = explain_program_name_get(); fprintf(stderr, "Usage: %s [