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

Last change on this file since 197 was 197, checked in by Maciej Komosinski, 10 years ago

GDK used by developers since 1999, distributed on the web since 2002

  • Property svn:eol-style set to native
File size: 2.0 KB
RevLine 
[121]1// This file is a part of the Framsticks GDK.
[197]2// Copyright (C) 1999-2014  Maciej Komosinski and Szymon Ulatowski.  See LICENSE.txt for details.
[109]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        {
[115]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"
[126]20             "Example: loader_test walking.gen \"Basic Quadruped\" | theater -g -\n"
[115]21                );
[109]22        return 1;
23        }
24
25long count=0,totalsize=0;
26MiniGenotypeLoader loader(argv[1]);
[115]27const char* selected=(argc<3)?NULL:argv[2];
28int selected_index=(selected&&isdigit(selected[0]))?atol(selected):0;
[109]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();
[115]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());
[109]52        }
53// the loop repeats until loaded==NULL, which could be beacause of error
54if (loader.getStatus()==MiniGenotypeLoader::OnError)
[115]55        fprintf(stderr,"Error: %s",(const char*)loader.getError());
[109]56// (otherwise it was the end of the file)
[115]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        }
[109]67}
Note: See TracBrowser for help on using the repository browser.