/[LeafOK_CVS]/pvpgn-1.7.4/src/bniutils/bnilist.c
ViewVC logotype

Annotation of /pvpgn-1.7.4/src/bniutils/bnilist.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Tue Jun 6 03:41:37 2006 UTC (19 years, 9 months ago) by sysadm
CVS Tags: pvpgn_1-7-4-0_MIL
Branch point for: GNU, MAIN
Content type: text/x-csrc
Initial revision

1 sysadm 1.1 /*
2     Copyright (C) 2000 Marco Ziech (mmz@gmx.net)
3     Copyright (C) 2000 Ross Combs (rocombs@cs.nmsu.edu)
4    
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 2 of the License, or
8     (at your option) any later version.
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.
14    
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18     */
19     #include "common/setup_before.h"
20     #ifdef HAVE_STDDEF_H
21     # include <stddef.h>
22     #else
23     # ifndef NULL
24     # define NULL ((void *)0)
25     # endif
26     #endif
27     #include <stdio.h>
28     #ifdef STDC_HEADERS
29     # include <stdlib.h>
30     #endif
31     #include "compat/exitstatus.h"
32     #ifdef HAVE_STRING_H
33     # include <string.h>
34     #else
35     # ifdef HAVE_STRINGS_H
36     # include <strings.h>
37     # endif
38     #endif
39     #include <errno.h>
40     #include "compat/strerror.h"
41     #include "tga.h"
42     #include "fileio.h"
43     #include "common/version.h"
44     #include "common/setup_after.h"
45    
46    
47     static void usage(char const * progname)
48     {
49     fprintf(stderr,
50     "usage: %s [<options>] [--] [<BNI file>]\n"
51     " -h, --help, --usage show this information and exit\n"
52     " -v, --version print version number and exit\n",progname);
53    
54     exit(STATUS_FAILURE);
55     }
56    
57    
58     extern int main(int argc, char * argv[])
59     {
60     char const * bnifile=NULL;
61     FILE * fp;
62     int a;
63     int forcefile=0;
64     char dash[]="-"; /* unique address used as flag */
65    
66     if (argc<1 || !argv || !argv[0])
67     {
68     fprintf(stderr,"bad arguments\n");
69     return STATUS_FAILURE;
70     }
71    
72     for (a=1; a<argc; a++)
73     if (forcefile && !bnifile)
74     bnifile = argv[a];
75     else if (strcmp(argv[a],"-")==0 && !bnifile)
76     bnifile = dash;
77     else if (argv[a][0]!='-' && !bnifile)
78     bnifile = argv[a];
79     else if (forcefile || argv[a][0]!='-' || strcmp(argv[a],"-")==0)
80     {
81     fprintf(stderr,"%s: extra file argument \"%s\"\n",argv[0],argv[a]);
82     usage(argv[0]);
83     }
84     else if (strcmp(argv[a],"--")==0)
85     forcefile = 1;
86     else if (strcmp(argv[a],"-v")==0 || strcmp(argv[a],"--version")==0)
87     {
88     printf("version "PVPGN_VERSION"\n");
89     return STATUS_SUCCESS;
90     }
91     else if (strcmp(argv[a],"-h")==0 || strcmp(argv[a],"--help")==0 || strcmp(argv[a],"--usage")
92     ==0)
93     usage(argv[0]);
94     else
95     {
96     fprintf(stderr,"%s: unknown option \"%s\"\n",argv[0],argv[a]);
97     usage(argv[0]);
98     }
99    
100     if (!bnifile)
101     bnifile = dash;
102    
103     if (bnifile==dash)
104     fp = stdin;
105     else
106     if (!(fp = fopen(bnifile,"r")))
107     {
108     fprintf(stderr,"%s: could not open BNI file \"%s\" for reading (fopen: %s)\n",argv[0],bnifile,pstrerror(errno));
109     exit(STATUS_FAILURE);
110     }
111    
112     {
113     t_tgaimg * tgaimg;
114     int i;
115     int bniid, unknown, icons, datastart;
116     int expected_width, expected_height;
117    
118     file_rpush(fp);
119     bniid = file_readd_le();
120     unknown = file_readd_le();
121     icons = file_readd_le();
122     datastart = file_readd_le();
123     fprintf(stderr,"BNIHeader: id=0x%08x unknown=0x%08x icons=0x%08x datastart=0x%08x\n",bniid,unknown,icons,datastart);
124     expected_width = 0;
125     expected_height = 0;
126     for (i = 0; i < icons; i++) {
127     int id,x,y,flags,tag;
128     id = file_readd_le();
129     x = file_readd_le();
130     y = file_readd_le();
131     if (id == 0) {
132     tag = file_readd_le();
133     } else {
134     tag = 0;
135     }
136     flags = file_readd_le();
137     fprintf(stderr,"Icon[%d]: id=0x%08x x=%d y=%d tag=0x%08x(\"%c%c%c%c\") flags=0x%08x\n",i,id,x,y,tag,
138     ((unsigned char)((tag >> 24) & 0xff)),
139     ((unsigned char)((tag >> 16) & 0xff)),
140     ((unsigned char)((tag >> 8) & 0xff)),
141     ((unsigned char)((tag) & 0xff)),flags);
142     if (x > expected_width) expected_width = x;
143     expected_height += y;
144     }
145     if (ftell(fp)!=datastart) {
146     fprintf(stderr,"Warning: garbage after header (pos=0x%lx-datastart=0x%lx) = %ld bytes of garbage! \n",(unsigned long)ftell(fp),(unsigned long)datastart,(long)(ftell(fp)-datastart));
147     }
148     tgaimg = load_tgaheader();
149     print_tga_info(tgaimg,stdout);
150     fprintf(stderr,"\n");
151     fprintf(stderr,"Check: Expected %dx%d TGA, got %ux%u. %s\n",expected_width,expected_height,tgaimg->width,tgaimg->height,((tgaimg->width == expected_width)&&(tgaimg->height == expected_height)) ? "OK." : "FAIL.");
152     fprintf(stderr,"Check: Expected 24bit color depth TGA, got %dbit. %s\n",tgaimg->bpp,(tgaimg->bpp == 24) ? "OK." : "FAIL.");
153     fprintf(stderr,"Check: Expected ImageType 10, got %d. %s\n",tgaimg->imgtype,(tgaimg->imgtype == 10) ? "OK." : "FAIL.");
154     file_rpop();
155     }
156    
157     if (bnifile!=dash && fclose(fp)<0)
158     fprintf(stderr,"%s: could not close BNI file \"%s\" after reading (fclose: %s)\n",argv[0],bnifile,pstrerror(errno));
159     return STATUS_SUCCESS;
160     }

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1