source: cpp/frams/_demos/loader_test.cpp @ 193

Last change on this file since 193 was 126, checked in by sz, 11 years ago

minor corrections

  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
1// This file is a part of the Framsticks GDK.
2// Copyright (C) 2002-2014  Maciej Komosinski and Szymon Ulatowski.  See LICENSE.txt for details.
3// Refer to http://www.framsticks.com/ for further information.
4
5#include "genotypeloader.h"
6
7/**
8 @file
9 Sample code: Loading genotypes from Framsticks files
10
11 \include loader_test.cpp
12*/
13
14int main(int argc,char*argv[])
15{
16if (argc<2)
17        {
18        fprintf(stderr,"Arguments: filename [optional: genotype name or index (1-based)]\n"
19             "If a genotype is indicated (by providing the optional genotype identifier), the program will output the raw genotype, suitable for Framsticks Theater's genotype viewer mode. If the second optional argument is not given, the genotype names from the file will be listed.\n"
20             "Example: loader_test walking.gen \"Basic Quadruped\" | theater -g -\n"
21                );
22        return 1;
23        }
24
25long count=0,totalsize=0;
26MiniGenotypeLoader loader(argv[1]);
27const char* selected=(argc<3)?NULL:argv[2];
28int selected_index=(selected&&isdigit(selected[0]))?atol(selected):0;
29// using char* constructor (passing the file name to open)
30MiniGenotype *loaded;
31while(loaded=loader.loadNextGenotype())
32        { // if loaded != NULL then the "org:" object data was
33         // loaded into MiniGenotype object
34        count++;
35        totalsize+=loaded->genotype.len();
36        if (selected)
37                {
38                if (selected_index)
39                        {
40                        if (selected_index!=count)
41                                continue;
42                        }
43                else
44                        {
45                        if (strcmp((const char*)loaded->name,selected))
46                                continue;
47                        }
48                puts((const char*)loaded->genotype);
49                return 0;
50                }
51        fprintf(stderr,"%d. %s\t(%d characters)\n",count,(const char*)loaded->name,loaded->genotype.len());
52        }
53// the loop repeats until loaded==NULL, which could be beacause of error
54if (loader.getStatus()==MiniGenotypeLoader::OnError)
55        fprintf(stderr,"Error: %s",(const char*)loader.getError());
56// (otherwise it was the end of the file)
57if (selected)
58        {
59        fprintf(stderr,"genotype %s not found in %s\n",selected,argv[1]);
60        return 2;
61        }
62else
63        {
64        fprintf(stderr,"\ntotal: %d items, %d characters\n",count,totalsize);
65        return 0;
66        }
67}
Note: See TracBrowser for help on using the repository browser.