#include <stdio.h>#include <stddef.h>#include <stdlib.h>#include <string.h>Include dependency graph for seewbmp.c:

Go to the source code of this file.
Data Structures | |
| struct | parm |
Functions | |
| long | get_mbi (FILE *infile) |
| int | skip_mbi (FILE *infile) |
| int | show_image_from_file (char *bmpname, FILE *bmpfile, long width, long height) |
| void | clear_extparms (void) |
| int | new_extparm (char *name, char *value) |
| void | print_extparms (FILE *outfile) |
| int | parse_headers (FILE *bmpfile) |
| int | show_wbmp_from_file (char *bmpname, FILE *bmpfile) |
| int | main (int argc, char *argv[]) |
Variables | |
| parm * | extparms = NULL |
|
|
Definition at line 162 of file seewbmp.c. References extparms, free, parm::name, parm::next, and parm::value. Referenced by parse_headers(). 00162 {
00163 while (extparms) {
00164 struct parm *tmp = extparms;
00165 extparms = extparms->next;
00166 free(tmp->name);
00167 free(tmp->value);
00168 free(tmp);
00169 }
00170 }
|
|
|
Definition at line 98 of file seewbmp.c. References result. Referenced by show_wbmp_from_file(). 00098 {
00099 int c;
00100 long result = 0;
00101
00102 do {
00103 c = getc(infile);
00104 if (c < 0) return -1;
00105 result = (result << 7) | (c & 0x7f);
00106 } while (c & 0x80);
00107
00108 return result;
00109 }
|
|
||||||||||||
|
Definition at line 304 of file seewbmp.c. References show_wbmp_from_file(). 00304 {
00305 int i;
00306 /* 1 means an I/O error. No other error values are used yet. */
00307 int exitvalue = 0;
00308
00309 if (argc > 1) {
00310 for (i = 1; i < argc; i++) {
00311 FILE *bmpfile;
00312
00313 bmpfile = fopen(argv[i], "r");
00314 if (bmpfile) {
00315 if (show_wbmp_from_file(argv[i], bmpfile) < 0) {
00316 /* We've already reported the error */
00317 exitvalue = 1;
00318 }
00319 if (fclose(bmpfile) < 0) {
00320 perror(argv[i]);
00321 exitvalue = 1;
00322 }
00323 } else {
00324 perror(argv[i]);
00325 exitvalue = 1;
00326 }
00327 if (i < argc - 1) {
00328 /* more files follow -- separate them */
00329 printf("\n");
00330 }
00331 }
00332 } else {
00333 /* No files specified -- read from standard input */
00334 if (show_wbmp_from_file("stdin", stdin)) {
00335 exitvalue = 1;
00336 }
00337 }
00338
00339 return exitvalue;
00340 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 174 of file seewbmp.c. References extparms, malloc, parm::name, parm::next, and parm::value. Referenced by parse_headers(). 00174 {
00175 struct parm *new;
00176 struct parm *p;
00177
00178 /* Construct a new node */
00179 new = (struct parm *)malloc(sizeof(struct parm));
00180 if (!new)
00181 return -1;
00182
00183 new->name = name;
00184 new->value = value;
00185 new->next = NULL;
00186
00187 /* Add it to the end of the list. */
00188 if (!extparms) {
00189 extparms = new;
00190 } else {
00191 p = extparms;
00192 while (p->next) {
00193 p = p->next;
00194 }
00195 p->next = new;
00196 }
00197
00198 return 0;
00199 }
|
|
|
Definition at line 209 of file seewbmp.c. References clear_extparms(), free, malloc, name, new_extparm(), and skip_mbi(). Referenced by show_wbmp_from_file(). 00209 {
00210 int c;
00211 int exttype;
00212
00213 clear_extparms();
00214
00215 c = getc(bmpfile);
00216 if (c < 0) return -1;
00217 if (!(c & 0x80)) {
00218 /* No extension headers follow */
00219 return 0;
00220 }
00221 exttype = (c >> 5) & 0x03;
00222 /* None of these headers do much at this time, but they
00223 * might be meaningful with later specifications */
00224 switch (exttype) {
00225 case 0:
00226 /* All we know of type 0 headers is that
00227 * the high bit is a continuation bit.
00228 * That makes them exactly like an MBI. */
00229 if (skip_mbi(bmpfile) < 0) return -1;
00230 break;
00231 case 1: case 2:
00232 /* We don't know what to do with these */
00233 return -1;
00234 case 3:
00235 /* A sequence of parameter/value combinations */
00236 do {
00237 int namelen, valuelen;
00238 char *name, *value;
00239 c = getc(bmpfile);
00240 if (c < 0) return -1;
00241
00242 namelen = (c >> 4) & 0x07;
00243 name = malloc(namelen + 1);
00244 if (!name) return -1;
00245 if (fread(name, namelen, 1, bmpfile) < (size_t) namelen)
00246 return -1;
00247
00248 valuelen = c & 0x0f;
00249 value = malloc(valuelen + 1);
00250 if (!value) { free(name); return -1; }
00251 if (fread(value, valuelen, 1, bmpfile) < (size_t) valuelen)
00252 return -1;
00253
00254 new_extparm(name, value);
00255 } while (c & 0x80);
00256 break;
00257 }
00258 return 0;
00259 }
|
Here is the call graph for this function:

|
|
Definition at line 201 of file seewbmp.c. References parm::name, parm::next, and parm::value. Referenced by show_wbmp_from_file(). 00201 {
00202 struct parm *p;
00203
00204 for (p = extparms; p; p = p->next) {
00205 fprintf(outfile, "%s=%s\n", p->name, p->value);
00206 }
00207 }
|
|
||||||||||||||||||||
|
Definition at line 126 of file seewbmp.c. Referenced by show_wbmp_from_file(). 00127 {
00128 long w, h;
00129
00130 for (h = 0; h < height; h++) {
00131 /* w is incremented in its inner loop */
00132 for (w = 0; w < width; ) {
00133 int c;
00134 unsigned int bit;
00135
00136 c = getc(bmpfile);
00137 if (c < 0) {
00138 perror(bmpname);
00139 return -1;
00140 }
00141
00142 for (bit = 0x80; bit > 0 && w < width; bit >>= 1, w++) {
00143 putc((c & bit) ? '*' : ' ', stdout);
00144 }
00145 }
00146 putc('\n', stdout);
00147 }
00148
00149 return 0;
00150 }
|
|
||||||||||||
|
Definition at line 262 of file seewbmp.c. References get_mbi(), parse_headers(), print_extparms(), and show_image_from_file(). Referenced by main(). 00262 {
00263 long typefield;
00264 long width, height;
00265
00266 typefield = get_mbi(bmpfile);
00267 if (typefield < 0) {
00268 perror(bmpname);
00269 return -1;
00270 }
00271
00272 if (parse_headers(bmpfile) < 0) {
00273 fprintf(stderr, "%s: format error in headers\n", bmpname);
00274 return -1;
00275 }
00276
00277 width = get_mbi(bmpfile);
00278 height = get_mbi(bmpfile);
00279 if (width < 0 || height < 0) {
00280 fprintf(stderr, "%s: error reading height and width\n",
00281 bmpname);
00282 return -1;
00283 }
00284
00285 switch (typefield) {
00286 case 0:
00287 printf("%s, %ldx%ld B/W bitmap, no compression\n",
00288 bmpname, width, height);
00289 print_extparms(stdout);
00290 if (show_image_from_file(bmpname, bmpfile,
00291 width, height) < 0) {
00292 return -1;
00293 }
00294 break;
00295 default:
00296 fprintf(stderr, "%s: cannot handle level %ld wbmp\n",
00297 bmpname, typefield);
00298 return -1;
00299 }
00300
00301 return 0;
00302 }
|
Here is the call graph for this function:

|
|
Definition at line 115 of file seewbmp.c. Referenced by parse_headers(). 00115 {
00116 int c;
00117
00118 do {
00119 c = getc(infile);
00120 if (c < 0) return -1;
00121 } while (c & 0x80);
00122
00123 return 0;
00124 }
|
|
|
Definition at line 160 of file seewbmp.c. Referenced by clear_extparms(), and new_extparm(). |