SaveCmd.C 2.18 KB
Newer Older
Francois Gygi committed
1 2
////////////////////////////////////////////////////////////////////////////////
//
Francois Gygi committed
3 4 5 6
// Copyright (c) 2008 The Regents of the University of California
//
// This file is part of Qbox
//
Francois Gygi committed
7 8
// Qbox is distributed under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 2 of
Francois Gygi committed
9 10 11 12 13 14
// the License, or (at your option) any later version.
// See the file COPYING in the root directory of this distribution
// or <http://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////////////
//
Francois Gygi committed
15 16 17 18 19 20
// SaveCmd.C:
//
////////////////////////////////////////////////////////////////////////////////


#include "SaveCmd.h"
Francois Gygi committed
21
#include "SampleWriter.h"
22 23
#include "isodate.h"
#include "release.h"
Francois Gygi committed
24 25 26 27 28 29

using namespace std;

////////////////////////////////////////////////////////////////////////////////
int SaveCmd::action(int argc, char **argv)
{
Francois Gygi committed
30 31
  string usage("  Use: save [-text] [-atomsonly]");
  usage += string(" [-serial] [-no_wfv] filename");
Francois Gygi committed
32 33 34
  if ( !(argc>=2 && argc<=4 ) )
  {
    if ( ui->onpe0() )
35
      cout << usage << endl;
Francois Gygi committed
36 37
    return 1;
  }
38

Francois Gygi committed
39
  // set default encoding and flags
Francois Gygi committed
40
  bool base64 = true;
Francois Gygi committed
41
  bool atomsonly = false;
42
  bool serial = false;
Francois Gygi committed
43
  bool save_wfv = true;
Francois Gygi committed
44
  char* filename = 0;
45

46
  // check for -text or -base64 or -atomsonly or -serial arguments
Francois Gygi committed
47 48 49
  for ( int i = 1; i < argc; i++ )
  {
    string arg(argv[i]);
50

Francois Gygi committed
51 52
    if ( arg=="-text" )
    {
Francois Gygi committed
53
      base64 = false;
Francois Gygi committed
54 55 56 57 58
    }
    else if ( arg=="-atomsonly" )
    {
      atomsonly = true;
    }
59 60 61 62
    else if ( arg=="-serial" )
    {
      serial = true;
    }
Francois Gygi committed
63 64 65 66
    else if ( arg=="-no_wfv" )
    {
      save_wfv = false;
    }
Francois Gygi committed
67 68 69 70 71 72 73
    else if ( arg[0] != '-' && i == argc-1 )
    {
      filename = argv[i];
    }
    else
    {
      if ( ui->onpe0() )
74
        cout << usage << endl;
Francois Gygi committed
75 76 77
      return 1;
    }
  }
78

Francois Gygi committed
79 80 81
  if ( filename == 0 )
  {
    if ( ui->onpe0() )
82
      cout << usage << endl;
Francois Gygi committed
83 84
    return 1;
  }
Francois Gygi committed
85 86 87
  SampleWriter swriter(s->ctxt_);
  string description = string(" Created ") + isodate() +
                       string(" by qbox-") + release() + string(" ");
Francois Gygi committed
88 89
  swriter.writeSample(*s, filename, description, base64, atomsonly, serial,
                      save_wfv);
Francois Gygi committed
90 91 92

  return 0;
}