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

Annotation of /pvpgn-1.7.4/src/bniutils/tgainfo.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>] [--] [<TGA 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 * tgafile=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 && !tgafile)
74     tgafile = argv[a];
75     else if (strcmp(argv[a],"-")==0 && !tgafile)
76     tgafile = dash;
77     else if (argv[a][0]!='-' && !tgafile)
78     tgafile = 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 (!tgafile)
101     tgafile = dash;
102    
103     if (tgafile==dash)
104     fp = stdin;
105     else
106     if (!(fp = fopen(tgafile,"r")))
107     {
108     fprintf(stderr,"%s: could not open TGA file \"%s\" for reading (fopen: %s)\n",argv[0],tgafile,pstrerror(errno));
109     return STATUS_FAILURE;
110     }
111    
112     {
113     t_tgaimg * tgaimg;
114    
115     file_rpush(fp);
116     if (!(tgaimg = load_tgaheader()))
117     {
118     fprintf(stderr,"%s: could not load TGA header\n",argv[0]);
119     if (tgafile!=dash && fclose(fp)<0)
120     fprintf(stderr,"%s: could not close file \"%s\" after reading (fclose: %s)\n",argv[0],tgafile,pstrerror(errno));
121     return STATUS_FAILURE;
122     }
123     print_tga_info(tgaimg,stdout);
124     file_rpop();
125     }
126    
127     if (tgafile!=dash && fclose(fp)<0)
128     fprintf(stderr,"%s: could not close file \"%s\" after reading (fclose: %s)\n",argv[0],tgafile,pstrerror(errno));
129     return STATUS_SUCCESS;
130     }

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