SaveCmd.C 2.23 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
// SaveCmd.C:
//
////////////////////////////////////////////////////////////////////////////////
Francois Gygi committed
18
// $Id: SaveCmd.C,v 1.17 2008-09-08 16:26:36 fgygi Exp $
Francois Gygi committed
19 20 21


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

using namespace std;

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

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

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

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

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

  return 0;
}