~ubuntu-branches/ubuntu/wily/afnix/wily

« back to all changes in this revision

Viewing changes to src/clt/axl/exe/Main.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anibal Monsalve Salazar
  • Date: 2011-03-16 21:31:18 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110316213118-gk4k3ez3e5d2huna
Tags: 2.0.0-1
* QA upload.
* New upstream release
* Debian source format is 3.0 (quilt)
* Fix debhelper-but-no-misc-depends
* Fix ancient-standards-version
* Fix package-contains-linda-override
* debhelper compatibility is 7
* Fix dh-clean-k-is-deprecated

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
// - the copyright holder be liable for any  direct, indirect, incidental or -
12
12
// - special damages arising in any way out of the use of this software.     -
13
13
// ---------------------------------------------------------------------------
14
 
// - copyright (c) 1999-2007 amaury darsch                                   -
 
14
// - copyright (c) 1999-2011 amaury darsch                                   -
15
15
// ---------------------------------------------------------------------------
16
16
 
17
17
#include "System.hpp"
36
36
  static const String S_OPT_MSG = "    [s]        \t short librarian list";
37
37
  static const String T_OPT_MSG = "    [t]        \t print librarian list";
38
38
  static const String F_OPT_MSG = "    [f name]   \t set librarian file name";
 
39
  static const String M_OPT_MSG = "    [m name]   \t set start module name";
39
40
 
40
41
  // this procedure returns the libarian option object
41
 
  static Options* get_options (Output& os,const long argc,const char** argv) {
 
42
  static Options* get_options (OutputStream& os,
 
43
                               const long argc, const char** argv) {
42
44
    // create the option class
43
45
    Options* opts = new Options (U_CLS_MSG);
44
46
    // add the string options
 
47
    opts->add (Options::SOPT, 'm', M_OPT_MSG);
45
48
    opts->add (Options::SOPT, 'f', F_OPT_MSG);
46
49
    // add the uniq options
47
50
    opts->add (Options::UNIQ, 't', T_OPT_MSG);
77
80
        os << "fatal: both create and extract flags are set" << eolc;
78
81
        System::exit (1);
79
82
      }
 
83
      // make sure that the module flag is only set in create mode
 
84
      if ((opts->getoflg ('m') == true) && (opts->getoflg ('c') == false)) {
 
85
        os << "fatal: start module flag in non create mode" << eolc;
 
86
        System::exit (1);
 
87
      }
 
88
 
80
89
    } catch (...) {
81
90
      opts->usage (os);
82
91
      delete opts;
102
111
  
103
112
  // this procedure extract a file from the librarian
104
113
  static void axl_extract (const Librarian& axl, const String& name) {
105
 
    Input* is = axl.extract (name);
 
114
    InputStream* is = axl.extract (name);
106
115
    if (is == nilp) return;
107
 
    OutputFile os (name);
108
 
    while (is->iseof () == false) os.write (is->read ());
 
116
    try {
 
117
      OutputFile os (name);
 
118
      while (is->iseos () == false) os.write (is->read ());
 
119
      Object::cref (is);
 
120
    } catch (...) {
 
121
      Object::cref (is);
 
122
      throw;
 
123
    }
109
124
  }
110
125
 
111
126
  // this procedure process the options
112
 
  static void run_options (Options* opts) {
 
127
  static void run_options (const Options& opts) {
 
128
    // preset the afnix system
 
129
    System::preset (opts.getpgmn (), false);
113
130
    // get the options value
114
 
    bool   cflg = opts->getoflg ('c');
115
 
    bool   xflg = opts->getoflg ('x');
116
 
    bool   sflg = opts->getoflg ('s');
117
 
    bool   tflg = opts->getoflg ('t') || sflg;
118
 
    String name = opts->getopts ('f');
119
 
    Strvec args = opts->getargs ();
 
131
    bool   cflg = opts.getoflg ('c');
 
132
    bool   xflg = opts.getoflg ('x');
 
133
    bool   mflg = opts.getoflg ('m');
 
134
    bool   sflg = opts.getoflg ('s');
 
135
    bool   tflg = opts.getoflg ('t') || sflg;
 
136
    String name = opts.getopts ('f');
 
137
    Strvec args = opts.getargs ();
120
138
 
121
139
    // process the create flag
122
140
    if (cflg == true) {
125
143
      // loop in the vector
126
144
      long argc = args.length ();
127
145
      for (long i = 0; i < argc; i++) axl.add (args.get (i));
 
146
      // eventuall set the start module
 
147
      if (mflg == true) axl.setstm (opts.getopts ('m'));
128
148
      // write the librarian
129
149
      axl.write (name);
130
150
      // check for report
168
188
 
169
189
  // main processing loop
170
190
  try {
171
 
    // register the program name
172
 
    System::initialize (argv[0]);
173
191
    // get the options
174
192
    Options* opts = get_options (terr, argc, argv);
175
193
    // process the options
176
 
    run_options (opts);
 
194
    run_options (*opts);
177
195
    // clean everything
178
196
    delete opts;
179
197
  } catch (const Exception& e) {