2 * banner - make posters
3 * Copyright (C) 1999-2001 Joerg Schaible
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 * See the COPYING file for full license information.
27 static const char versionID
[] = PACKAGE_VERSION
;
28 static const char revID
[] =
30 static const char copyrightID
[] =
31 "Copyright (c) 1999-2001\nJoerg Schaible. All rights reserved.\nLicensed under GPLv3+\n";
33 static void printTopDescription (FILE * f
, char *name
);
34 static void printBottomDescription (FILE * f
, char *name
);
35 static const char *getVersion (void);
36 static void usage (FILE * f
, char *name
);
37 static void help (FILE * f
, char *name
);
38 static void version (FILE * f
, char *name
);
39 static void license (FILE * f
, char *name
);
41 static char *program_name
;
42 static poptContext optCon
;
49 static HBITMAP hBmpOrg
;
53 static BITMAPINFO bmi
;
54 static unsigned char *buffer
;
60 hFont
= GetStockObject (ANSI_FIXED_FONT
);
62 hMem
= CreateCompatibleDC (hScreen
);
63 ReleaseDC (0, hScreen
);
65 SelectObject (hMem
, hFont
);
66 GetTextMetrics (hMem
, &tm
);
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
);
82 hBmpOrg
= SelectObject (hMem
, hBmp
);
83 SelectObject (hMem
, GetStockObject (WHITE_BRUSH
));
84 SelectObject (hMem
, GetStockObject (WHITE_PEN
));
86 SetBkColor (hMem
, RGB (0, 0, 0));
87 SetTextColor (hMem
, RGB (255, 255, 255));
88 SetBkMode (hMem
, OPAQUE
);
93 rt
.bottom
= tm
.tmHeight
;
99 SelectObject (hMem
, hBmpOrg
);
106 print_line (const char *line
)
109 int len
= strlen (line
);
110 if (len
> (w
/ tm
.tmMaxCharWidth
))
111 len
= (w
/ tm
.tmMaxCharWidth
);
113 Rectangle (hMem
, 0, 0, rt
.right
, rt
.bottom
);
114 DrawText (hMem
, line
, len
, &rt
, DT_NOCLIP
| DT_NOPREFIX
| DT_SINGLELINE
);
116 SelectObject (hMem
, hBmpOrg
);
117 GetDIBits (hMem
, hBmp
, 0, bmi
.bmiHeader
.biHeight
, buffer
,
118 (LPBITMAPINFO
) & bmi
.bmiHeader
, DIB_RGB_COLORS
);
119 SelectObject (hMem
, hBmp
);
121 for (y
= tm
.tmHeight
; y
--;)
123 unsigned char *line
=
124 buffer
+ y
* (bmi
.bmiHeader
.biSizeImage
/ bmi
.bmiHeader
.biHeight
);
126 for (x
= 0; x
< len
* tm
.tmMaxCharWidth
; ++x
)
128 unsigned char byte
= *(line
+ (x
/ 8));
129 putchar ((byte
& (1 << (7 - ((int) x
% 8)))) ? *c
: ' ');
138 main (int argc
, const char **argv
)
145 struct poptOption generalOptionsTable
[] = {
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
}
153 struct poptOption helpOptionsTable
[] = {
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
}
165 struct poptOption opt
[] = {
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
}
173 if ((program_name
= strdup (argv
[0])) == NULL
)
175 fprintf (stderr
, "%s: memory allocation error\n", argv
[0]);
178 optCon
= poptGetContext (NULL
, argc
, argv
, opt
, 0);
179 poptSetOtherOptionHelp (optCon
, "A string to print...");
181 while ((rc
= poptGetNextOpt (optCon
)) > 0)
186 help (stdout
, program_name
);
189 usage (stdout
, program_name
);
192 version (stdout
, program_name
);
195 license (stdout
, program_name
);
197 case 'c': /* no additional action needed */
199 case 'w': /* no additional action needed */
205 fprintf (stderr
, "%s: bad argument %s: %s\n",
206 program_name
, poptBadOption (optCon
, POPT_BADOPTION_NOALIAS
),
211 rest
= poptGetArgs (optCon
);
215 fprintf (stderr
, "%s: not enough arguments\n", program_name
);
216 usage (stderr
, program_name
);
223 ec
|= print_line (*rest
);
230 poptFreeContext (optCon
);
242 printTopDescription (FILE * f
, char *name
)
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");
249 printBottomDescription (FILE * f
, char *name
)
252 "\nThis version works the same way as System V'S banner does:\n");
253 fprintf (f
, "The banner text is displayed horizontally.\n");
257 printLicense (FILE * f
, char *name
)
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");
274 usage (FILE * f
, char *name
)
276 poptPrintUsage (optCon
, f
, 0);
280 help (FILE * f
, char *name
)
282 printTopDescription (f
, name
);
283 poptPrintHelp (optCon
, f
, 0);
284 printBottomDescription (f
, name
);
288 version (FILE * f
, char *name
)
290 printTopDescription (f
, name
);
294 license (FILE * f
, char *name
)
296 printTopDescription (f
, name
);
297 printLicense (f
, name
);