/[dtapublic]/projs/dtats/trunk/projs/2018/20180718_ets_ifsfscan/c_main.c
ViewVC logotype

Diff of /projs/dtats/trunk/projs/2018/20180718_ets_ifsfscan/c_main.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

projs/dtats/trunk/projs/2018/20180112_ifsfscan/c_main.c revision 202 by dashley, Sun Jul 15 17:17:37 2018 UTC projs/dtats/trunk/projs/2018/20180718_ets_ifsfscan/c_main.c revision 212 by dashley, Thu Jul 19 02:25:24 2018 UTC
# Line 1  Line 1 
1  //$Header$  //$Header$
2  //{f0d952cc-7499-4d5c-9f46-d0b509c5701c}  //{9d0125ed-73c3-43f6-8435-8f161ab7ea6d}
3  //-------------------------------------------------------------------------------------------------  //-------------------------------------------------------------------------------------------------
4  //Copyright (c) 2018, David T. Ashley  //Copyright (c) 2018, David T. Ashley
5  //  //
6  //This file is part of "ifsfscan", a program for identifying gross formatting anomalies in source  //This file is part of "ets_ifsfscan", a program for identifying gross formatting anomalies in
7  //files (Windows/ASCII text files only).  //source files (Windows/ASCII text files only).
8  //  //
9  //This source code and any program in which it is compiled/used is licensed under the MIT License,  //This source code and any program in which it is compiled/used is licensed under the MIT License,
10  //reproduced below.  //reproduced below.
# Line 41  Line 41 
41  //less than aesthetic).  //less than aesthetic).
42  const char * const license_preamble[] =  const char * const license_preamble[] =
43  {  {
44     "ifsfscan, (c) 2018 David T. Ashley (dashley@gmail.com)",     "ets_ifsfscan, (c) 2018 David T. Ashley (dashley@gmail.com)",
45     "This program's source files, executable files, and all other related files",     "This program's source files, executable files, and all other related files",
46     "(such as Visual Studio project files) are licensed under \"The MIT License\",",     "(such as Visual Studio project files) are licensed under \"The MIT License\",",
47     "reproduced below."     "reproduced below."
# Line 70  const char * const license_text[] = Line 70  const char * const license_text[] =
70    
71  const char * const prog_desc_text[] =  const char * const prog_desc_text[] =
72  {  {
73     "ifsfscan (mnemonic: Ill-Formed Source File SCAN) is a program for detecting",     "ets_ifsfscan (mnemonic: Ill-Formed Source File SCAN) is a program for",
74     "gross formatting errors in source files (Windows/ASCII text files only).  The",     "detecting gross formatting errors in source files (Windows/ASCII text",
75     "errors detected are non-ASCII characters, tab characters, abnormal",     "files only).  The errors detected are non-ASCII characters, tab characters,",
76     "end-of-line characters, and trailing whitespace on lines.",     "abnormal end-of-line characters, and trailing whitespace on lines."
77  };  };
78    
79  const char * const prog_help_text[] =  const char * const prog_help_text[] =
80  {  {
81     "Usage:  ifsfscan [filename_or_wildcard [filename_or_wildcard [...]]]",     "Usage:  ets_ifsfscan [filename_or_wildcard [filename_or_wildcard [...]]]",
82     "",     "",
83     "Notes:",     "Notes:",
84     "   (1) : Wildcards (\"*\", \"?\") are processed by Windows, so Windows is",     "   (1) : Wildcards (\"*\", \"?\") are processed by Windows, so Windows is",
# Line 119  void USERASSERT_assert(int assertion, co Line 119  void USERASSERT_assert(int assertion, co
119     }     }
120  }  }
121    
 //--------------------------------------------------------------------------------  
 //  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__);  
    }  
   
    memset(rv, 0, size);  
   
    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__);  
    }  
   
    memset(rv, 0, size);  
   
    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);  
 }  
   
 //--------------------------------------------------------------------------------  
 //  C H A R A C T E R    F U N C T I O N S  
 //--------------------------------------------------------------------------------  
 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:  
       USERASSERT_assert(0, __FILE__, __LINE__);  
       return('?');  
       break;  
    }  
 }  
   
 void CHARFUNC_int_to_lc_hex_rev(int arg, char *s)  
 {  
    int i;  
   
    USERASSERT_assert(s != NULL, __FILE__, __LINE__);  
   
    for (i = 0; i<8; i++)  
    {  
       s[i] = CHARFUNC_nibble_to_lc_hex_digit(arg);  
       arg >>= 4;  
    }  
 }  
122    
123  //--------------------------------------------------------------------------------  //--------------------------------------------------------------------------------
124  //  S T R I N G    A N D    C H A R A C T E R    A R R A Y    F U N C T I O N S  //  S T R I N G    A N D    C H A R A C T E R    A R R A Y    F U N C T I O N S
# Line 341  const char *STRING_vcinfo(size_t which) Line 175  const char *STRING_vcinfo(size_t which)
175        "$Date$",        "$Date$",
176        "$Revision$",        "$Revision$",
177        "$Author$",        "$Author$",
178        "Project GUID:       {f7d7586a-557c-43cb-bec5-b49765d96a5d}",        "Project GUID:           {beb3d945-d010-41c4-b7b5-7d4b84203408}",
179        "c_main.c GUID:      {f0d952cc-7499-4d5c-9f46-d0b509c5701c}",        "c_main.c GUID:          {9d0125ed-73c3-43f6-8435-8f161ab7ea6d}",
180        "ifsfscan.cpp GUID:  {2abd4437-101c-49eb-99ac-c1174f55b626}",        "ets_ifsfscan.cpp GUID:  {aa3777d0-4cd3-46e5-b84e-03f01957cc71}",
181     };     };
182    
183     if (which < (sizeof(vcinfo) / sizeof(vcinfo[0])))     if (which < (sizeof(vcinfo) / sizeof(vcinfo[0])))
# Line 388  void FCMIOF_stream_hline(FILE *s) Line 222  void FCMIOF_stream_hline(FILE *s)
222     fprintf(s, "\n");     fprintf(s, "\n");
223  }  }
224    
 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.  
    */  
    USERASSERT_assert(f != NULL, __FILE__, __LINE__);  
    USERASSERT_assert(s != NULL, __FILE__, __LINE__);  
    USERASSERT_assert(n_extra_lines >= 0, __FILE__, __LINE__);  
   
    /* Print the right number of solid lines of asterisks to the  
    ** standard output.  
    */  
    for (i = 0; i<n_extra_lines; i++)  
    {  
       FCMIOF_stream_repchar(f, '*', FCMIOF_LINE_LEN);  
       fprintf(f, "\n");  
    }  
   
    /* Figure out how many asterisks to print on each side of the  
    ** argument, and how many spaces.  We also need to figure out  
    ** how many characters of the input argument to print--if there  
    ** are too many characters, we need to truncate.  
    */  
    input_arg_len = strlen(s);  
    if (input_arg_len > (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<input_arg_len; i++)  
       fprintf(f, "%c", s[i]);  
    FCMIOF_stream_repchar(f, ' ', n_right_spaces);  
    FCMIOF_stream_repchar(f, '*', n_asterisks);  
    fprintf(f, "\n");  
   
    /* Print the right number of solid lines of asterisks to the  
    ** standard output.  
    */  
    for (i = 0; i<n_extra_lines; i++)  
    {  
       FCMIOF_stream_repchar(f, '*', FCMIOF_LINE_LEN);  
       fprintf(f, "\n");  
    }  
 }  
   
 void FCMIOF_bannerheading(char *s, int n_extra_lines)  
 {  
    USERASSERT_assert(s != NULL, __FILE__, __LINE__);  
    USERASSERT_assert(n_extra_lines >= 0, __FILE__, __LINE__);  
   
    FCMIOF_stream_bannerheading(stdout, s, n_extra_lines);  
 }  
   
 void FCMIOF_time_stream(FILE *s, time_t ltime)  
 {  
    char *p;  
   
    USERASSERT_assert(s != NULL, __FILE__, __LINE__);  
   
    time(&ltime);  
   
    p = ctime(&ltime);  
   
    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, "??? ??? ?? ??:??:?? ????");  
    }  
 }  
   
225  int is_legal_non_eol_character(char c)  int is_legal_non_eol_character(char c)
226  {  {
227     if ((c >= 32) && (c <= 126))     if ((c >= 32) && (c <= 126))
# Line 543  void emit_human_friendly_llu(unsigned lo Line 267  void emit_human_friendly_llu(unsigned lo
267     size_t i, len;     size_t i, len;
268     char buffer[100];     char buffer[100];
269    
270     sprintf(buffer, "%llu", arg);     sprintf_s(buffer, sizeof(buffer)/sizeof(buffer[0]), "%llu", arg);
271     len = strlen(buffer);     len = strlen(buffer);
272    
273     for (i = 0; i < len; i++)     for (i = 0; i < len; i++)

Legend:
Removed from v.202  
changed lines
  Added in v.212

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25