]> cygwin.com Git - cygwin-apps/cygutils.git/blame - src/banner/banner.c
Change license for banner to GPLv3+
[cygwin-apps/cygutils.git] / src / banner / banner.c
CommitLineData
d4a28ab0 1/*
bd695173
CW
2 * banner - make posters
3 * Copyright (C) 1999-2001 Joerg Schaible
4 *
5db1fa14 5 * This program is free software: you can redistribute it and/or modify
bd695173 6 * it under the terms of the GNU General Public License as published by
5db1fa14
CW
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
bd695173
CW
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
5db1fa14 14 *
bd695173 15 * You should have received a copy of the GNU General Public License
5db1fa14
CW
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * See the COPYING file for full license information.
bd695173 19 */
d4a28ab0 20
bd695173 21#if HAVE_CONFIG_H
fe3a7d70 22# include "config.h"
bd695173 23#endif
d4a28ab0 24
d2b03e6a 25#include "common.h"
d4a28ab0 26
b96d6602 27static const char versionID[] = PACKAGE_VERSION;
d4a28ab0 28static const char revID[] =
fe3a7d70 29 "$Id$";
d4a28ab0 30static const char copyrightID[] =
5db1fa14 31 "Copyright (c) 1999-2001\nJoerg Schaible. All rights reserved.\nLicensed under GPLv3+\n";
d4a28ab0 32
fe3a7d70
CW
33static void printTopDescription (FILE * f, char *name);
34static void printBottomDescription (FILE * f, char *name);
35static const char *getVersion (void);
a4905427
CW
36static void usage (FILE * f, char *name);
37static void help (FILE * f, char *name);
38static void version (FILE * f, char *name);
39static void license (FILE * f, char *name);
d4a28ab0 40
fe3a7d70 41static char *program_name;
a4905427 42static poptContext optCon;
d4a28ab0
CW
43
44static char *c = "X";
45static int w = 80;
46static TEXTMETRIC tm;
47static HFONT hFont;
48static HBITMAP hBmp;
49static HBITMAP hBmpOrg;
50static HDC hMem;
51static RECT rt;
52static BITMAP bm;
53static BITMAPINFO bmi;
54static unsigned char *buffer;
55
fe3a7d70
CW
56void
57initialize ()
d4a28ab0 58{
fe3a7d70
CW
59 HDC hScreen;
60 hFont = GetStockObject (ANSI_FIXED_FONT);
61 hScreen = GetDC (0);
62 hMem = CreateCompatibleDC (hScreen);
63 ReleaseDC (0, hScreen);
64
65 SelectObject (hMem, hFont);
66 GetTextMetrics (hMem, &tm);
67
68 hBmp = CreateBitmap (w, tm.tmHeight, 1, 1, 0);
69 GetObject (hBmp, sizeof (bm), &bm);
70 memset (&bmi.bmiHeader, 0, sizeof (BITMAPINFOHEADER));
71 bmi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
72 bmi.bmiHeader.biWidth = bm.bmWidth;
73 bmi.bmiHeader.biHeight = bm.bmHeight;
74 bmi.bmiHeader.biPlanes = 1;
75 bmi.bmiHeader.biCompression = BI_RGB;
76 bmi.bmiHeader.biBitCount = 1;
77 bmi.bmiHeader.biSizeImage =
78 ((((unsigned int) bm.bmWidth + 31) & ~31) >> 3) * bm.bmHeight;
79 bmi.bmiHeader.biClrUsed = 2;
80 buffer = (unsigned char *) malloc (bmi.bmiHeader.biSizeImage);
81
82 hBmpOrg = SelectObject (hMem, hBmp);
83 SelectObject (hMem, GetStockObject (WHITE_BRUSH));
84 SelectObject (hMem, GetStockObject (WHITE_PEN));
85
86 SetBkColor (hMem, RGB (0, 0, 0));
87 SetTextColor (hMem, RGB (255, 255, 255));
88 SetBkMode (hMem, OPAQUE);
89
90 rt.top = 0;
91 rt.left = 0;
92 rt.right = w;
93 rt.bottom = tm.tmHeight;
d4a28ab0
CW
94}
95
fe3a7d70
CW
96void
97deinitialize ()
d4a28ab0 98{
fe3a7d70
CW
99 SelectObject (hMem, hBmpOrg);
100 DeleteObject (hBmp);
101 DeleteDC (hMem);
102 free (buffer);
d4a28ab0
CW
103}
104
fe3a7d70
CW
105int
106print_line (const char *line)
d4a28ab0 107{
fe3a7d70
CW
108 int x, y;
109 int len = strlen (line);
110 if (len > (w / tm.tmMaxCharWidth))
111 len = (w / tm.tmMaxCharWidth);
112
113 Rectangle (hMem, 0, 0, rt.right, rt.bottom);
114 DrawText (hMem, line, len, &rt, DT_NOCLIP | DT_NOPREFIX | DT_SINGLELINE);
115
116 SelectObject (hMem, hBmpOrg);
117 GetDIBits (hMem, hBmp, 0, bmi.bmiHeader.biHeight, buffer,
118 (LPBITMAPINFO) & bmi.bmiHeader, DIB_RGB_COLORS);
119 SelectObject (hMem, hBmp);
120
121 for (y = tm.tmHeight; y--;)
122 {
123 unsigned char *line =
124 buffer + y * (bmi.bmiHeader.biSizeImage / bmi.bmiHeader.biHeight);
125
126 for (x = 0; x < len * tm.tmMaxCharWidth; ++x)
127 {
128 unsigned char byte = *(line + (x / 8));
129 putchar ((byte & (1 << (7 - ((int) x % 8)))) ? *c : ' ');
130 }
131
132 putchar ('\n');
133 }
134 return 0;
d4a28ab0
CW
135}
136
fe3a7d70
CW
137int
138main (int argc, const char **argv)
d4a28ab0 139{
fe3a7d70 140 const char **rest;
d4a28ab0
CW
141 int rc;
142 int ec = 0;
143 int i;
144
145 struct poptOption generalOptionsTable[] = {
fe3a7d70
CW
146 {"char", 'c', POPT_ARG_STRING, &c, 'c',
147 "use character <X>", "X"},
148 {"width", 'w', POPT_ARG_INT, &w, 'w',
149 "set display width to <80> ", "80"},
150 {NULL, '\0', 0, NULL, 0, NULL, NULL}
d4a28ab0
CW
151 };
152
153 struct poptOption helpOptionsTable[] = {
fe3a7d70
CW
154 {"help", '?', POPT_ARG_NONE, NULL, '?',
155 "Show this help message", NULL},
156 {"usage", '\0', POPT_ARG_NONE, NULL, 'u',
157 "Display brief usage message", NULL},
158 {"version", '\0', POPT_ARG_NONE, NULL, 'v',
159 "Display version information", NULL},
160 {"license", '\0', POPT_ARG_NONE, NULL, 'l',
161 "Display licensing information", NULL},
162 {NULL, '\0', 0, NULL, 0, NULL, NULL}
d4a28ab0
CW
163 };
164
165 struct poptOption opt[] = {
fe3a7d70
CW
166 {NULL, '\0', POPT_ARG_INCLUDE_TABLE, generalOptionsTable, 0,
167 "General options", NULL},
168 {NULL, '\0', POPT_ARG_INCLUDE_TABLE, helpOptionsTable, 0,
169 "Help options", NULL},
170 {NULL, '\0', 0, NULL, 0, NULL, NULL}
d4a28ab0
CW
171 };
172
fe3a7d70
CW
173 if ((program_name = strdup (argv[0])) == NULL)
174 {
175 fprintf (stderr, "%s: memory allocation error\n", argv[0]);
176 exit (1);
177 }
178 optCon = poptGetContext (NULL, argc, argv, opt, 0);
179 poptSetOtherOptionHelp (optCon, "A string to print...");
180
181 while ((rc = poptGetNextOpt (optCon)) > 0)
182 {
183 switch (rc)
184 {
185 case '?':
a4905427 186 help (stdout, program_name);
fe3a7d70
CW
187 goto exit;
188 case 'u':
a4905427 189 usage (stdout, program_name);
fe3a7d70
CW
190 goto exit;
191 case 'v':
a4905427 192 version (stdout, program_name);
fe3a7d70
CW
193 goto exit;
194 case 'l':
a4905427 195 license (stdout, program_name);
fe3a7d70
CW
196 goto exit;
197 case 'c': /* no additional action needed */
198 break;
199 case 'w': /* no additional action needed */
200 break;
201 }
202 }
203 if (rc < -1)
204 {
205 fprintf (stderr, "%s: bad argument %s: %s\n",
206 program_name, poptBadOption (optCon, POPT_BADOPTION_NOALIAS),
207 poptStrerror (rc));
208 ec = 2;
209 goto exit;
210 }
211 rest = poptGetArgs (optCon);
212
213 if (rest == NULL)
214 {
215 fprintf (stderr, "%s: not enough arguments\n", program_name);
a4905427 216 usage (stderr, program_name);
fe3a7d70
CW
217 }
218 else
219 {
220 initialize ();
221 while (*rest && !ec)
222 {
223 ec |= print_line (*rest);
224 rest++;
225 }
226 deinitialize ();
d4a28ab0 227 }
d4a28ab0
CW
228
229exit:
fe3a7d70
CW
230 poptFreeContext (optCon);
231 free (program_name);
232 return (ec);
d4a28ab0 233}
fe3a7d70
CW
234
235static const char *
236getVersion ()
d4a28ab0
CW
237{
238 return versionID;
239}
240
fe3a7d70
CW
241static void
242printTopDescription (FILE * f, char *name)
d4a28ab0 243{
fe3a7d70
CW
244 fprintf (f, "%s is part of cygutils version %s\n", name, getVersion ());
245 fprintf (f, " Prints a string enlarged as a banner on the screen.\n\n");
d4a28ab0
CW
246}
247
fe3a7d70
CW
248static void
249printBottomDescription (FILE * f, char *name)
d4a28ab0 250{
fe3a7d70
CW
251 fprintf (f,
252 "\nThis version works the same way as System V'S banner does:\n");
253 fprintf (f, "The banner text is displayed horizontally.\n");
d4a28ab0
CW
254}
255
fe3a7d70
CW
256static
257printLicense (FILE * f, char *name)
d4a28ab0 258{
fe3a7d70 259 fprintf (f,
5db1fa14
CW
260 "This program is free software: you can redistribute it and/or modify\n"
261 "it under the terms of the GNU General Public License as published by\n"
262 "the Free Software Foundation, either version 3 of the License, or\n"
263 "(at your option) any later version.\n\n"
264 "This program is distributed in the hope that it will be useful,\n"
265 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
266 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
267 "GNU General Public License for more details.\n\n"
268 "You should have received a copy of the GNU General Public License\n"
269 "along with this program. If not, see <http://www.gnu.org/licenses/>.\n\n"
270 "See the COPYING file for full license information.\n");
d4a28ab0
CW
271}
272
fe3a7d70 273static void
a4905427 274usage (FILE * f, char *name)
d4a28ab0 275{
fe3a7d70 276 poptPrintUsage (optCon, f, 0);
d4a28ab0
CW
277}
278
fe3a7d70 279static void
a4905427 280help (FILE * f, char *name)
d4a28ab0 281{
fe3a7d70
CW
282 printTopDescription (f, name);
283 poptPrintHelp (optCon, f, 0);
284 printBottomDescription (f, name);
d4a28ab0
CW
285}
286
fe3a7d70 287static void
a4905427 288version (FILE * f, char *name)
d4a28ab0 289{
fe3a7d70 290 printTopDescription (f, name);
d4a28ab0
CW
291}
292
fe3a7d70 293static void
a4905427 294license (FILE * f, char *name)
d4a28ab0 295{
fe3a7d70
CW
296 printTopDescription (f, name);
297 printLicense (f, name);
b96d6602 298}
This page took 0.0552 seconds and 5 git commands to generate.