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