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 in version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 static const char versionID
[] =
28 static const char revID
[] =
30 static const char copyrightID
[] =
31 "Copyright (c) 1999-2001\nJoerg Schaible. All rights reserved.\nLicensed under GPL v2.0\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(poptContext optCon
, FILE * f
, char * name
);
37 static void help(poptContext optCon
, FILE * f
, char * name
);
38 static void version(poptContext optCon
, FILE * f
, char * name
);
39 static void license(poptContext optCon
, FILE * f
, char * name
);
41 static char * program_name
;
48 static HBITMAP hBmpOrg
;
52 static BITMAPINFO bmi
;
53 static unsigned char *buffer
;
58 hFont
= GetStockObject( ANSI_FIXED_FONT
);
60 hMem
= CreateCompatibleDC( hScreen
);
61 ReleaseDC( 0, hScreen
);
63 SelectObject( hMem
, hFont
);
64 GetTextMetrics( hMem
, &tm
);
66 hBmp
= CreateBitmap( w
, tm
.tmHeight
, 1, 1, 0 );
67 GetObject( hBmp
, sizeof( bm
), &bm
);
68 memset( &bmi
.bmiHeader
, 0, sizeof( BITMAPINFOHEADER
));
69 bmi
.bmiHeader
.biSize
= sizeof( BITMAPINFOHEADER
);
70 bmi
.bmiHeader
.biWidth
= bm
.bmWidth
;
71 bmi
.bmiHeader
.biHeight
= bm
.bmHeight
;
72 bmi
.bmiHeader
.biPlanes
= 1;
73 bmi
.bmiHeader
.biCompression
= BI_RGB
;
74 bmi
.bmiHeader
.biBitCount
= 1;
75 bmi
.bmiHeader
.biSizeImage
=
76 (((( unsigned int )bm
.bmWidth
+ 31 ) & ~31 ) >> 3 )
78 bmi
.bmiHeader
.biClrUsed
= 2;
79 buffer
= ( unsigned char * )malloc( bmi
.bmiHeader
.biSizeImage
);
81 hBmpOrg
= SelectObject( hMem
, hBmp
);
82 SelectObject( hMem
, GetStockObject( WHITE_BRUSH
));
83 SelectObject( hMem
, GetStockObject( WHITE_PEN
));
85 SetBkColor( hMem
, RGB( 0, 0, 0 ));
86 SetTextColor( hMem
, RGB( 255, 255, 255 ));
87 SetBkMode( hMem
, OPAQUE
);
92 rt
.bottom
= tm
.tmHeight
;
97 SelectObject( hMem
, hBmpOrg
);
103 int print_line( const char *line
)
106 int len
= strlen( line
);
107 if( len
> ( w
/ tm
.tmMaxCharWidth
))
108 len
= ( w
/ tm
.tmMaxCharWidth
);
110 Rectangle( hMem
, 0, 0, rt
.right
, rt
.bottom
);
111 DrawText( hMem
, line
, len
, &rt
,
112 DT_NOCLIP
| DT_NOPREFIX
| DT_SINGLELINE
);
114 SelectObject( hMem
, hBmpOrg
);
115 GetDIBits( hMem
, hBmp
, 0, bmi
.bmiHeader
.biHeight
, buffer
,
116 ( LPBITMAPINFO
)&bmi
.bmiHeader
, DIB_RGB_COLORS
);
117 SelectObject( hMem
, hBmp
);
119 for( y
= tm
.tmHeight
; y
--; )
121 unsigned char *line
= buffer
+ y
* ( bmi
.bmiHeader
.biSizeImage
/ bmi
.bmiHeader
.biHeight
);
123 for( x
= 0; x
< len
* tm
.tmMaxCharWidth
; ++x
)
125 unsigned char byte
= *( line
+ ( x
/ 8 ));
126 putchar(( byte
& ( 1 << (7 - (( int )x
% 8 )))) ? *c
: ' ' );
134 int main(int argc
, const char ** argv
)
142 struct poptOption generalOptionsTable
[] = {
143 { "char", 'c', POPT_ARG_STRING
, &c
, 'c', \
144 "use character <X>", "X"},
145 { "width", 'w', POPT_ARG_INT
, &w
, 'w', \
146 "set display width to <80> ", "80"},
147 { NULL
, '\0', 0, NULL
, 0, NULL
, NULL
}
150 struct poptOption helpOptionsTable
[] = {
151 { "help", '?', POPT_ARG_NONE
, NULL
, '?', \
152 "Show this help message", NULL
},
153 { "usage", '\0', POPT_ARG_NONE
, NULL
, 'u', \
154 "Display brief usage message", NULL
},
155 { "version", '\0', POPT_ARG_NONE
, NULL
, 'v', \
156 "Display version information", NULL
},
157 { "license", '\0', POPT_ARG_NONE
, NULL
, 'l', \
158 "Display licensing information", NULL
},
159 { NULL
, '\0', 0, NULL
, 0, NULL
, NULL
}
162 struct poptOption opt
[] = {
163 { NULL
, '\0', POPT_ARG_INCLUDE_TABLE
, generalOptionsTable
, 0, \
164 "General options", NULL
},
165 { NULL
, '\0', POPT_ARG_INCLUDE_TABLE
, helpOptionsTable
, 0, \
166 "Help options", NULL
},
167 { NULL
, '\0', 0, NULL
, 0, NULL
, NULL
}
170 if( (program_name
= strdup(argv
[0])) == NULL
) {
171 fprintf(stderr
, "%s: memory allocation error\n", argv
[0]);
174 optCon
= poptGetContext(NULL
, argc
, argv
, opt
, 0);
175 poptSetOtherOptionHelp(optCon
, "A string to print...");
177 while ((rc
= poptGetNextOpt(optCon
)) > 0) {
179 case '?': help(optCon
, stderr
, program_name
);
181 case 'u': usage(optCon
, stderr
, program_name
);
183 case 'v': version(optCon
, stderr
, program_name
);
185 case 'l': license(optCon
, stderr
, program_name
);
187 case 'c': /* no additional action needed */
189 case 'w': /* no additional action needed */
194 fprintf(stderr
, "%s: bad argument %s: %s\n",
195 program_name
, poptBadOption(optCon
, POPT_BADOPTION_NOALIAS
),
200 rest
= poptGetArgs(optCon
);
203 fprintf(stderr
, "%s: not enough arguments\n",program_name
);
204 usage(optCon
, stderr
, program_name
);
208 while (*rest
&& !ec
) {
209 ec
|= print_line( *rest
);
216 poptFreeContext(optCon
);
221 static const char * getVersion()
226 static void printTopDescription(FILE * f
, char * name
)
228 fprintf(f
, "%s version %s\n", name
, getVersion());
229 fprintf(f
, " Prints a string enlarged as a banner on the screen.\n\n");
232 static void printBottomDescription(FILE * f
, char * name
)
234 fprintf(f
, "\nThis version works the same way as System V'S banner does:\n");
235 fprintf(f
, "The banner text is displayed horizontally.\n");
238 static printLicense(FILE * f
, char * name
)
240 fprintf(f
, "This program is free software; you can redistribute it and/or\n");
241 fprintf(f
, "modify it under the terms of the GNU General Public License\n");
242 fprintf(f
, "as published by the Free Software Foundation; either version 2\n");
243 fprintf(f
, "of the License, or (at your option) any later version.\n");
245 fprintf(f
, "This program is distributed in the hope that it will be useful,\n");
246 fprintf(f
, "but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
247 fprintf(f
, "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n");
248 fprintf(f
, "GNU General Public License for more details.\n");
250 fprintf(f
, "You should have received a copy of the GNU General Public License\n");
251 fprintf(f
, "along with this program; if not, write to the Free Software\n");
252 fprintf(f
, "Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n");
254 fprintf(f
, "See the COPYING file for license information.\n");
257 static void usage(poptContext optCon
, FILE * f
, char * name
)
259 poptPrintUsage(optCon
, f
, 0);
262 static void help(poptContext optCon
, FILE * f
, char * name
)
264 printTopDescription(f
, name
);
265 poptPrintHelp(optCon
, f
, 0);
266 printBottomDescription(f
, name
);
269 static void version(poptContext optCon
, FILE * f
, char * name
)
271 printTopDescription(f
, name
);
274 static void license(poptContext optCon
, FILE * f
, char * name
)
276 printTopDescription(f
, name
);
277 printLicense(f
, name
);