~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/message/table_writer.cc

  • Committer: Monty Taylor
  • Date: 2010-08-12 07:35:31 UTC
  • mto: (1711.1.11 build)
  • mto: This revision was merged to the branch mainline in revision 1713.
  • Revision ID: mordred@inaugust.com-20100812073531-17wopgfzmz771ukm
Removed gnulib and the last usage of normal getopt.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include <iostream>
23
23
#include <fstream>
24
24
#include <string>
25
 
#include <getopt.h>
26
25
#include <drizzled/message/table.pb.h>
27
26
 
 
27
#include <boost/program_options.hpp>
 
28
 
28
29
using namespace std;
29
30
using namespace drizzled;
30
31
 
 
32
namespace po=boost::program_options;
 
33
 
31
34
/*
32
35
  Written from Google proto example
33
36
*/
213
216
 
214
217
}
215
218
 
216
 
static void usage(char *argv0)
217
 
{
218
 
  cerr << "Usage:  " << argv0 << " [-t N] TABLE_NAME.dfe" << endl;
219
 
  cerr << endl;
220
 
  cerr << "-t N\tTable Number" << endl;
221
 
  cerr << "\t0 - default" << endl;
222
 
  cerr << endl;
223
 
}
224
219
 
225
220
int main(int argc, char* argv[])
226
221
{
227
 
  int opt;
228
222
  int table_number= 0;
229
223
 
230
224
  GOOGLE_PROTOBUF_VERIFY_VERSION;
231
225
 
232
 
  while ((opt= getopt(argc, argv, "t:")) != -1)
 
226
  po::options_description desc("Allowed options");
 
227
  desc.add_options()
 
228
    ("help", "produce help message")
 
229
    ("table-number,t", po::value<int>(&table_number)->default_value(0), "Table Number");
 
230
 
 
231
  po::variables_map vm;
 
232
  po::positional_options_description p;
 
233
  p.add("table-name", 1);
 
234
 
 
235
  po::store(po::command_line_parser(argc, argv).options(desc).
 
236
            positional(p).run(), vm);
 
237
 
 
238
  if (not vm.count("table-name"))
233
239
  {
234
 
    switch (opt)
235
 
    {
236
 
    case 't':
237
 
      table_number= atoi(optarg);
238
 
      break;
239
 
    default:
240
 
      usage(argv[0]);
241
 
      exit(EXIT_FAILURE);
242
 
    }
243
 
  }
244
 
 
245
 
  if (optind >= argc) {
246
240
    fprintf(stderr, "Expected Table name argument\n\n");
247
 
    usage(argv[0]);
 
241
    cerr << desc << endl;
248
242
    exit(EXIT_FAILURE);
249
243
  }
250
244
 
260
254
    break;
261
255
  default:
262
256
    fprintf(stderr, "Invalid table number.\n\n");
263
 
    usage(argv[0]);
 
257
    cerr << desc << endl;
264
258
    exit(EXIT_FAILURE);
265
259
  }
266
260
 
267
 
  fstream output(argv[optind], ios::out | ios::trunc | ios::binary);
 
261
  fstream output(vm["table-name"].as<string>().c_str(),
 
262
                 ios::out | ios::trunc | ios::binary);
268
263
  if (!table.SerializeToOstream(&output))
269
264
  {
270
265
    cerr << "Failed to write schema." << endl;