//$Header$ //------------------------------------------------------------------------------------------------- //This file is part of "ifsfscan", a program for identifying and correcting gross formatting //anomalies in source files. //------------------------------------------------------------------------------------------------- //This source code and any program in which it is compiled/used is provided under the MIT License, //reproduced below. //------------------------------------------------------------------------------------------------- //Permission is hereby granted, free of charge, to any person obtaining a copy of //this software and associated documentation files(the "Software"), to deal in the //Software without restriction, including without limitation the rights to use, //copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the //Software, and to permit persons to whom the Software is furnished to do so, //subject to the following conditions : // //The above copyright notice and this permission notice shall be included in all //copies or substantial portions of the Software. // //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE //AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE //SOFTWARE. //------------------------------------------------------------------------------------------------- #include #include static const char * const license_text[] = { "Permission is hereby granted, free of charge, to any person obtaining a copy of", "this software and associated documentation files(the \"Software\"), to deal in the", "Software without restriction, including without limitation the rights to use,", "copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the", "Software, and to permit persons to whom the Software is furnished to do so," "subject to the following conditions :", "", "The above copyright notice and this permission notice shall be included in all", "copies or substantial portions of the Software.", "", "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR", "IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,", "FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE", "AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER", "LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,", "OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE" "SOFTWARE." }; static const char * const prog_desc_text[] = { "ifsfscan (mnemonic: Ill-Formed Source File SCAN) is a program for detecting and", "correcting gross formatting errors in source files. The errors detected and", "corrected include non-ASCII characters, tab characters, trailing whitespace on", "lines, and other errors.", }; static const char * const prog_help_text[] = { "Usage: ifsfscan ", "", "Options:", " -fixall", " Fixes all known formatting issues non-interactively. For users who", " understand the program's behavior, this is the most common option used.", " -fixnone (default)", " Identifies formatting issues, but does make any corrections.", "", "Notes:", " ( 1) : THIS PROGRAM CAN DESTROY DATA. This program does not make backup", " files. If this program were used to make \"corrections\" on a binary", " file, the file would likely be irreparably corrupted.", " ( 2) : This program does not process wildcards.", " ( 3) : This program is limited by available memory. This program parses a", " source file, writing the corrected file to a RAM buffer, then finally", " overwrites the source file from the RAM buffer. The practical limit", " for the size of the file that can be corrected using this program is", " probably a couple gigabytes.", " ( 4) : The license of this program does not prohibit copying the source code", " to another version control repository or simply \"stealing\" the", " program and source code for any other use. The MIT License is a very", " unrestrictive open-source license." }; //-------------------------------------------------------------------------------- // T E R M I N A T I O N F U N C T I O N S //-------------------------------------------------------------------------------- static void CCMFATAL_fatal(const char *desc, const char *file, size_t line) { printf("Fatal error. Must terminate execution.\n"); printf("File: %s, Line: %zu.\n", file, line); printf("Error description: %s\n", desc); exit(4); //Error code 4 for error termination. } //-------------------------------------------------------------------------------- // A S S E R T I O N F U N C T I O N S //-------------------------------------------------------------------------------- //-------------------------------------------------------------------------------- // M E M O R Y A L L O C A T I O N F U N C T I O N S //-------------------------------------------------------------------------------- //These functions form a layer over the standard library so that conditions of //concern can be more easily trapped. //-------------------------------------------------------------------------------- void *CCMALLOC_malloc(size_t size) { void *rv; rv = malloc(size); if (!rv) { CCMFATAL_fatal("NULL pointer from malloc()--probable out of memory.", __FILE__, __LINE__); } return(rv); } void *CCMALLOC_calloc(size_t num, size_t size) { void *rv; rv = calloc(num, size); if (!rv) { CCMFATAL_fatal("NULL pointer from calloc()--probable out of memory.", __FILE__, __LINE__); } return(rv); } void *CCMALLOC_realloc(void *memblock, size_t size) { void *rv; rv = realloc(memblock, size); if ((!rv) && (size)) { CCMFATAL_fatal("NULL pointer from realloc()--probable out of memory.", __FILE__, __LINE__); } return(rv); } void CCMALLOC_free(void *memblock) { free(memblock); } #if 0 int CHARFUNC_digit_to_val(char digit) { switch (digit) { case '0': return(0); break; case '1': return(1); break; case '2': return(2); break; case '3': return(3); break; case '4': return(4); break; case '5': return(5); break; case '6': return(6); break; case '7': return(7); break; case '8': return(8); break; case '9': return(9); break; default: return(-1); break; } } char CHARFUNC_nibble_to_lc_hex_digit(int nibble) { switch (nibble & 0x0F) { case 0: return('0'); break; case 1: return('1'); break; case 2: return('2'); break; case 3: return('3'); break; case 4: return('4'); break; case 5: return('5'); break; case 6: return('6'); break; case 7: return('7'); break; case 8: return('8'); break; case 9: return('9'); break; case 10: return('a'); break; case 11: return('b'); break; case 12: return('c'); break; case 13: return('d'); break; case 14: return('e'); break; case 15: return('f'); break; default: assert(0); return('?'); break; } } void CHARFUNC_int_to_lc_hex_rev(int arg, char *s) { int i; assert(s != NULL); for (i = 0; i<8; i++) { s[i] = CHARFUNC_nibble_to_lc_hex_digit(arg); arg >>= 4; } } #define FCMIOF_HORIZONTAL_BAR_SEP_CHAR ('-') #define FCMIOF_LINE_LEN (78) //08/16/01: Visual inspection OK. int FCMIOF_get_line_len(void) { return(FCMIOF_LINE_LEN); } //08/16/01: Visual inspection OK. void FCMIOF_stream_repchar(FILE *s, char c, unsigned n) { assert(s != NULL); while (n--) fprintf(s, "%c", c); } //08/16/01: Visual inspection OK. void FCMIOF_repchar(char c, unsigned n) { while (n--) printf("%c", c); } //08/16/01: Visual inspection OK. void FCMIOF_hline(void) { FCMIOF_repchar(FCMIOF_HORIZONTAL_BAR_SEP_CHAR, FCMIOF_LINE_LEN); printf("\n"); } //08/16/01: Visual inspection OK. void FCMIOF_stream_hline(FILE *s) { assert(s != NULL); FCMIOF_stream_repchar(s, FCMIOF_HORIZONTAL_BAR_SEP_CHAR, FCMIOF_LINE_LEN); fprintf(s, "\n"); } //08/16/01: Visual inspection OK. void FCMIOF_stream_bannerheading(FILE *f, char *s, int n_extra_lines) { const int lr_padding = 3; /* The number of spaces on each side of what is printed. */ int i; /* General iteration variable. */ int n_asterisks; int input_arg_len; int n_left_spaces; int n_right_spaces; /* Check the file pointer, string pointer, and other par. */ assert(f != NULL); assert(s != NULL); assert(n_extra_lines >= 0); /* Print the right number of solid lines of asterisks to the ** standard output. */ for (i = 0; i (FCMIOF_LINE_LEN - 2 * lr_padding - 2)) input_arg_len = FCMIOF_LINE_LEN - 2 * lr_padding - 2; n_asterisks = (FCMIOF_LINE_LEN - 2 * lr_padding - input_arg_len) / 2; n_left_spaces = lr_padding; if ((FCMIOF_LINE_LEN - 2 * lr_padding - input_arg_len) % 2) { /* Odd, need to pad the right by one. */ n_right_spaces = lr_padding + 1; } else { n_right_spaces = lr_padding; } /* Print the text. */ FCMIOF_stream_repchar(f, '*', n_asterisks); FCMIOF_stream_repchar(f, ' ', n_left_spaces); for (i = 0; i= 0); FCMIOF_stream_bannerheading(stdout, s, n_extra_lines); } void FCMIOF_time_stream(FILE *s, time_t ltime) { char *p; assert(s != NULL); time(<ime); p = ctime(<ime); if (p) { int i; for (i = 11; i<19; i++) fprintf(s, "%c", p[i]); fprintf(s, " "); for (i = 0; i<10; i++) fprintf(s, "%c", p[i]); fprintf(s, " "); for (i = 20; i<24; i++) fprintf(s, "%c", p[i]); } else { fprintf(s, "??? ??? ?? ??:??:?? ????"); } } #endif int c_main(int argc, char **argv) { if (argc <= 1) { //This is most likely someone trying to figure out what the program is or does. //Treat this the same as a request for help. } return 0; }