/[gtktalog]/gtktalog/plugins/modinfo.cc
ViewVC logotype

Diff of /gtktalog/plugins/modinfo.cc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by ymettier, Sun Oct 13 16:52:24 2002 UTC revision 1.2 by ymettier, Sun Jun 22 16:10:53 2003 UTC
# Line 31  void P(char *s) Line 31  void P(char *s)
31    while(i>=0)    while(i>=0)
32      {      {
33        if((unsigned char)s[i]>127 || (unsigned char)s[i]<32)        if((unsigned char)s[i]>127 || (unsigned char)s[i]<32)
34          s[i]='.';          s[i]='.';
35        i--;        i--;
36      }      }
37    printf("%s\n", s);    printf("%s\n", s);
# Line 41  bool m669(FILE *f) Line 41  bool m669(FILE *f)
41  {  {
42    char buf[109];    char buf[109];
43    
44    if(fseek(f, 0, SEEK_SET) < 0)    rewind(f);
     exit(1);  
45    if(fgets(buf, 3, f) == NULL)    if(fgets(buf, 3, f) == NULL)
46      exit(1);      exit(1);
47    
# Line 92  bool MOD(FILE *f) Line 91  bool MOD(FILE *f)
91    if(!flag)    if(!flag)
92      return false;      return false;
93    
94    if(fseek(f, 0, SEEK_SET) < 0)    rewind(f);
     exit(1);  
95    if(fgets(buf, 20, f) == NULL)    if(fgets(buf, 20, f) == NULL)
96      exit(1);      exit(1);
97        
# Line 106  bool MOD(FILE *f) Line 104  bool MOD(FILE *f)
104  bool XM(FILE *f)  bool XM(FILE *f)
105  {  {
106    char buf[21];    char buf[21];
107    if(fseek(f, 0, SEEK_SET) < 0)    rewind(f);
     exit(1);  
108    if(fgets(buf, 18, f) == NULL)    if(fgets(buf, 18, f) == NULL)
109      exit(1);      exit(1);
110    
# Line 128  bool XM(FILE *f) Line 125  bool XM(FILE *f)
125  bool MTM(FILE *f)  bool MTM(FILE *f)
126  {  {
127    char buf[21];    char buf[21];
128    if(fseek(f, 0, SEEK_SET) < 0)    rewind(f);
     exit(1);  
129    if(fgets(buf, 4, f) == NULL)    if(fgets(buf, 4, f) == NULL)
130      exit(1);      exit(1);
131    
# Line 150  bool MTM(FILE *f) Line 146  bool MTM(FILE *f)
146  bool PSID(FILE *f)  bool PSID(FILE *f)
147  {  {
148    char buf[33];    char buf[33];
149    if(fseek(f, 0, SEEK_SET) < 0)    rewind(f);
     exit(1);  
150    if(fgets(buf, 5, f) == NULL)    if(fgets(buf, 5, f) == NULL)
151      exit(1);      exit(1);
152    
153    if(strncmp(buf, "PSID", 4))    if(strncmp(buf, "PSID", 4))
154      return false;      if(strncmp(buf, "RSID", 4))
155          return false;
156    
157    if(fseek(f, 0x16, SEEK_SET) < 0)    if(fseek(f, 0x16, SEEK_SET) < 0)
158      exit(1);      exit(1);
159    for(int i=1; i<=3; i++)    for(int i=1; i<=3; i++)
160      {      {
161        if(fgets(buf, 33, f) == NULL)        if(fgets(buf, 33, f) == NULL)
162          exit(1);          exit(1);
163        printf("%s ", buf);        printf("%s ", buf);
164      }      }
165    printf("\n");    printf("\n");
# Line 173  bool PSID(FILE *f) Line 169  bool PSID(FILE *f)
169  bool IT(FILE *f)  bool IT(FILE *f)
170  {  {
171    char buf[27];    char buf[27];
172    if(fseek(f, 0, SEEK_SET) < 0)    rewind(f);
     exit(1);  
173    if(fgets(buf, 5, f) == NULL)    if(fgets(buf, 5, f) == NULL)
174      exit(1);      exit(1);
175    
# Line 192  bool IT(FILE *f) Line 187  bool IT(FILE *f)
187    return true;    return true;
188  }  }
189    
190    bool S3M(FILE *f)
191    {
192      rewind(f);
193    
194      char buf[0x20];
195      fread(buf, 0x20, 1, f);
196      if(buf[0x1C]==0x1A && buf[0x1D]==16)
197        {
198          P(buf);
199          return true;
200        }
201    
202      return false;
203    }
204    
205  static void help()  static void help()
206  {  {
207    fprintf(stderr,    fprintf(stderr,
208            "modinfo: show titles from modules\n"            "modinfo: show titles from modules\n"
209            "usage:   modinfo filename\n"            "usage:   modinfo filename\n"
210            "currently the following file types are recognized:\n"            "currently the following file types are recognized:\n"
211            "669, mod, xm, mtm, psid, it\n"            "669, it, mod, mtm, psid, s3m, xm\n"
212            "comments go to Dirk Jagdmann <doj@cubic.org> http://llg.cubic.org\n"            "comments go to Dirk Jagdmann <doj@cubic.org> http://llg.cubic.org\n"
213            );            );
214    exit(1);    exit(1);
215  }  }
216    
# Line 215  int main(int argc, char **argv) Line 225  int main(int argc, char **argv)
225    FILE *f=fopen(argv[1], "r");    FILE *f=fopen(argv[1], "r");
226    if(f==0)    if(f==0)
227      {      {
228        fprintf(stderr, "could not open %s: %s\n", argv[1], strerror(errno));        fprintf(stderr, "could not open %s: %s\n", argv[1],
229    strerror(errno));
230        return 1;        return 1;
231      }      }
232    
# Line 225  int main(int argc, char **argv) Line 236  int main(int argc, char **argv)
236    else if(m669(f));    else if(m669(f));
237    else if(XM(f));    else if(XM(f));
238    else if(MOD(f));    else if(MOD(f));
239      else if(S3M(f));
240    else fprintf(stderr, "not recognized\n");    else fprintf(stderr, "not recognized\n");
241    
242    fclose(f);    fclose(f);

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26