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

Last change on this file since 382 was 382, checked in by sz, 9 years ago

Moving frams/virtfile to common/virtfile:

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