/[dtapublic]/projs/trunk/shared_source/c_datd/fcmiof.c
ViewVC logotype

Diff of /projs/trunk/shared_source/c_datd/fcmiof.c

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

revision 70 by dashley, Sat Oct 29 01:53:01 2016 UTC revision 71 by dashley, Sat Nov 5 11:07:06 2016 UTC
# Line 1  Line 1 
1  //$Header$  //$Header$
2  //-------------------------------------------------------------------------------------------------  //-------------------------------------------------------------------------------------------------
3  //This file is part of "David T. Ashley's Shared Source Code", a set of shared components  //This file is part of "David T. Ashley's Shared Source Code", a set of shared components
4  //integrated into many of David T. Ashley's projects.  //integrated into many of David T. Ashley's projects.
5  //-------------------------------------------------------------------------------------------------  //-------------------------------------------------------------------------------------------------
6  //This source code and any program in which it is compiled/used is provided under the MIT License,  //This source code and any program in which it is compiled/used is provided under the MIT License,
7  //reproduced below.  //reproduced below.
8  //-------------------------------------------------------------------------------------------------  //-------------------------------------------------------------------------------------------------
9  //Permission is hereby granted, free of charge, to any person obtaining a copy of  //Permission is hereby granted, free of charge, to any person obtaining a copy of
10  //this software and associated documentation files(the "Software"), to deal in the  //this software and associated documentation files(the "Software"), to deal in the
11  //Software without restriction, including without limitation the rights to use,  //Software without restriction, including without limitation the rights to use,
12  //copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the  //copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the
13  //Software, and to permit persons to whom the Software is furnished to do so,  //Software, and to permit persons to whom the Software is furnished to do so,
14  //subject to the following conditions :  //subject to the following conditions :
15  //  //
16  //The above copyright notice and this permission notice shall be included in all  //The above copyright notice and this permission notice shall be included in all
17  //copies or substantial portions of the Software.  //copies or substantial portions of the Software.
18  //  //
19  //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  //IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  //IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  //FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE  //FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
22  //AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  //AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,  //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24  //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE  //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25  //SOFTWARE.  //SOFTWARE.
26  //-------------------------------------------------------------------------------------------------  //-------------------------------------------------------------------------------------------------
27  #define MODULE_FCMIOF  #define MODULE_FCMIOF
28    
29  #include <assert.h>  #include <assert.h>
30  #include <stdio.h>  #include <stdio.h>
31  #include <string.h>  #include <string.h>
32  #include <time.h>  #include <time.h>
33    
34  #include "fcmiof.h"  #include "fcmiof.h"
35    
36    
37  #define FCMIOF_HORIZONTAL_BAR_SEP_CHAR    ('-')  #define FCMIOF_HORIZONTAL_BAR_SEP_CHAR    ('-')
38  #define FCMIOF_LINE_LEN                   (78)  #define FCMIOF_LINE_LEN                   (78)
39    
40    
41  //08/16/01:  Visual inspection OK.  //08/16/01:  Visual inspection OK.
42  int FCMIOF_get_line_len(void)  int FCMIOF_get_line_len(void)
43     {     {
44     return(FCMIOF_LINE_LEN);     return(FCMIOF_LINE_LEN);
45     }     }
46    
47    
48  //08/16/01:  Visual inspection OK.  //08/16/01:  Visual inspection OK.
49  void FCMIOF_stream_repchar(FILE *s, char c, unsigned n)  void FCMIOF_stream_repchar(FILE *s, char c, unsigned n)
50     {     {
51     assert(s != NULL);     assert(s != NULL);
52    
53     while(n--)     while(n--)
54             fprintf(s, "%c", c);             fprintf(s, "%c", c);
55     }     }
56    
57    
58  //08/16/01:  Visual inspection OK.  //08/16/01:  Visual inspection OK.
59  void FCMIOF_repchar(char c, unsigned n)  void FCMIOF_repchar(char c, unsigned n)
60     {     {
61     while(n--)     while(n--)
62             printf("%c", c);             printf("%c", c);
63     }     }
64    
65    
66  //08/16/01:  Visual inspection OK.  //08/16/01:  Visual inspection OK.
67  void FCMIOF_hline(void)  void FCMIOF_hline(void)
68     {     {
69     FCMIOF_repchar(FCMIOF_HORIZONTAL_BAR_SEP_CHAR, FCMIOF_LINE_LEN);     FCMIOF_repchar(FCMIOF_HORIZONTAL_BAR_SEP_CHAR, FCMIOF_LINE_LEN);
70     printf("\n");     printf("\n");
71     }     }
72    
73    
74  //08/16/01:  Visual inspection OK.  //08/16/01:  Visual inspection OK.
75  void FCMIOF_stream_hline(FILE *s)  void FCMIOF_stream_hline(FILE *s)
76     {     {
77     assert(s != NULL);     assert(s != NULL);
78    
79     FCMIOF_stream_repchar(s, FCMIOF_HORIZONTAL_BAR_SEP_CHAR, FCMIOF_LINE_LEN);     FCMIOF_stream_repchar(s, FCMIOF_HORIZONTAL_BAR_SEP_CHAR, FCMIOF_LINE_LEN);
80     fprintf(s, "\n");     fprintf(s, "\n");
81     }     }
82    
83    
84  //08/16/01:  Visual inspection OK.  //08/16/01:  Visual inspection OK.
85  void FCMIOF_stream_bannerheading(FILE *f,  void FCMIOF_stream_bannerheading(FILE *f,
86                                   char *s,                                   char *s,
87                                   int n_extra_lines)                                   int n_extra_lines)
88     {     {
89     const int lr_padding = 3;     const int lr_padding = 3;
90        /* The number of spaces on each side of what is printed.        /* The number of spaces on each side of what is printed.
91        */        */
92     int i;     int i;
93        /* General iteration variable.        /* General iteration variable.
94        */        */
95    
96     int n_asterisks;     int n_asterisks;
97     int input_arg_len;     int input_arg_len;
98     int n_left_spaces;     int n_left_spaces;
99     int n_right_spaces;     int n_right_spaces;
100    
101     /* Check the file pointer, string pointer, and other par.     /* Check the file pointer, string pointer, and other par.
102     */     */
103     assert(f != NULL);     assert(f != NULL);
104     assert(s != NULL);     assert(s != NULL);
105     assert(n_extra_lines >= 0);     assert(n_extra_lines >= 0);
106    
107     /* Print the right number of solid lines of asterisks to the     /* Print the right number of solid lines of asterisks to the
108     ** standard output.     ** standard output.
109     */     */
110     for (i=0; i<n_extra_lines; i++)     for (i=0; i<n_extra_lines; i++)
111        {        {
112        FCMIOF_stream_repchar(f, '*', FCMIOF_LINE_LEN);        FCMIOF_stream_repchar(f, '*', FCMIOF_LINE_LEN);
113        fprintf(f, "\n");        fprintf(f, "\n");
114        }        }
115    
116     /* Figure out how many asterisks to print on each side of the     /* Figure out how many asterisks to print on each side of the
117     ** argument, and how many spaces.  We also need to figure out     ** argument, and how many spaces.  We also need to figure out
118     ** how many characters of the input argument to print--if there     ** how many characters of the input argument to print--if there
119     ** are too many characters, we need to truncate.     ** are too many characters, we need to truncate.
120     */     */
121     input_arg_len = strlen(s);     input_arg_len = strlen(s);
122     if(input_arg_len > (FCMIOF_LINE_LEN - 2 * lr_padding - 2))     if(input_arg_len > (FCMIOF_LINE_LEN - 2 * lr_padding - 2))
123        input_arg_len = FCMIOF_LINE_LEN - 2 * lr_padding - 2;        input_arg_len = FCMIOF_LINE_LEN - 2 * lr_padding - 2;
124    
125     n_asterisks = (FCMIOF_LINE_LEN - 2*lr_padding - input_arg_len)/2;     n_asterisks = (FCMIOF_LINE_LEN - 2*lr_padding - input_arg_len)/2;
126    
127     n_left_spaces = lr_padding;     n_left_spaces = lr_padding;
128    
129     if ((FCMIOF_LINE_LEN - 2*lr_padding - input_arg_len) % 2)     if ((FCMIOF_LINE_LEN - 2*lr_padding - input_arg_len) % 2)
130        {        {
131        /* Odd, need to pad the right by one. */        /* Odd, need to pad the right by one. */
132        n_right_spaces = lr_padding+1;        n_right_spaces = lr_padding+1;
133        }        }
134     else     else
135        {        {
136        n_right_spaces = lr_padding;        n_right_spaces = lr_padding;
137        }        }
138    
139     /* Print the text. */     /* Print the text. */
140     FCMIOF_stream_repchar(f, '*', n_asterisks);     FCMIOF_stream_repchar(f, '*', n_asterisks);
141     FCMIOF_stream_repchar(f, ' ', n_left_spaces);     FCMIOF_stream_repchar(f, ' ', n_left_spaces);
142     for (i=0; i<input_arg_len; i++)     for (i=0; i<input_arg_len; i++)
143        fprintf(f, "%c", s[i]);        fprintf(f, "%c", s[i]);
144     FCMIOF_stream_repchar(f, ' ', n_right_spaces);     FCMIOF_stream_repchar(f, ' ', n_right_spaces);
145     FCMIOF_stream_repchar(f, '*', n_asterisks);     FCMIOF_stream_repchar(f, '*', n_asterisks);
146     fprintf(f, "\n");     fprintf(f, "\n");
147    
148     /* Print the right number of solid lines of asterisks to the     /* Print the right number of solid lines of asterisks to the
149     ** standard output.     ** standard output.
150     */     */
151     for (i=0; i<n_extra_lines; i++)     for (i=0; i<n_extra_lines; i++)
152        {        {
153        FCMIOF_stream_repchar(f, '*', FCMIOF_LINE_LEN);        FCMIOF_stream_repchar(f, '*', FCMIOF_LINE_LEN);
154        fprintf(f, "\n");        fprintf(f, "\n");
155        }        }
156     }     }
157    
158    
159  //08/16/01:  Visual inspection OK.  //08/16/01:  Visual inspection OK.
160  void FCMIOF_bannerheading(char *s, int n_extra_lines)  void FCMIOF_bannerheading(char *s, int n_extra_lines)
161     {     {
162     assert(s != NULL);     assert(s != NULL);
163     assert(n_extra_lines >= 0);     assert(n_extra_lines >= 0);
164    
165     FCMIOF_stream_bannerheading(stdout, s, n_extra_lines);     FCMIOF_stream_bannerheading(stdout, s, n_extra_lines);
166     }     }
167    
168    
169  void FCMIOF_time_stream(FILE *s, time_t ltime)  void FCMIOF_time_stream(FILE *s, time_t ltime)
170     {     {
171     char *p;     char *p;
172    
173     assert(s != NULL);     assert(s != NULL);
174    
175     time(&ltime);     time(&ltime);
176    
177     p = ctime(&ltime);     p = ctime(&ltime);
178    
179     if (p)     if (p)
180        {        {
181        int i;        int i;
182    
183        for (i=11; i<19; i++)        for (i=11; i<19; i++)
184           fprintf(s, "%c", p[i]);           fprintf(s, "%c", p[i]);
185        fprintf(s, " ");        fprintf(s, " ");
186        for (i=0; i<10; i++)        for (i=0; i<10; i++)
187           fprintf(s, "%c", p[i]);           fprintf(s, "%c", p[i]);
188        fprintf(s, " ");        fprintf(s, " ");
189        for (i=20; i<24; i++)        for (i=20; i<24; i++)
190           fprintf(s, "%c", p[i]);           fprintf(s, "%c", p[i]);
191        }        }
192     else     else
193        {        {
194        fprintf(s, "??? ??? ?? ??:??:?? ????");        fprintf(s, "??? ??? ?? ??:??:?? ????");
195        }        }
196     }     }
197    
198    
199    
200  //08/16/01:  Visual inspection OK.  //08/16/01:  Visual inspection OK.
201  const char *FCMIOF_cvcinfo(void)  const char *FCMIOF_cvcinfo(void)
202     {     {
203     return("$Header$");     return("$Header$");
204     }     }
205    
206    
207  //08/16/01:  Visual inspection OK.  //08/16/01:  Visual inspection OK.
208  const char *FCMIOF_hvcinfo(void)  const char *FCMIOF_hvcinfo(void)
209     {     {
210     return(FCMIOF_H_VERSION);     return(FCMIOF_H_VERSION);
211     }     }
212    
213  //End of fcmiof.c.  //End of fcmiof.c.

Legend:
Removed from v.70  
changed lines
  Added in v.71

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25