~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/message/table_writer.cc

  • Committer: Brian Aker
  • Date: 2010-08-18 19:37:19 UTC
  • mto: This revision was merged to the branch mainline in revision 1720.
  • Revision ID: brian@tangent.org-20100818193719-bxxzn1pi22styowd
created function that can be used to simply crash the server.

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>
25
26
#include <drizzled/message/table.pb.h>
26
27
 
27
 
#include <boost/program_options.hpp>
28
 
 
29
28
using namespace std;
30
29
using namespace drizzled;
31
30
 
32
 
namespace po=boost::program_options;
33
 
 
34
31
/*
35
32
  Written from Google proto example
36
33
*/
216
213
 
217
214
}
218
215
 
 
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
}
219
224
 
220
225
int main(int argc, char* argv[])
221
226
{
 
227
  int opt;
222
228
  int table_number= 0;
223
229
 
224
230
  GOOGLE_PROTOBUF_VERIFY_VERSION;
225
231
 
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
 
  // Disable allow_guessing
236
 
  int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing;
237
 
 
238
 
  po::store(po::command_line_parser(argc, argv).options(desc).style(style).
239
 
            positional(p).run(), vm);
240
 
 
241
 
  if (not vm.count("table-name"))
 
232
  while ((opt= getopt(argc, argv, "t:")) != -1)
242
233
  {
 
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) {
243
246
    fprintf(stderr, "Expected Table name argument\n\n");
244
 
    cerr << desc << endl;
 
247
    usage(argv[0]);
245
248
    exit(EXIT_FAILURE);
246
249
  }
247
250
 
257
260
    break;
258
261
  default:
259
262
    fprintf(stderr, "Invalid table number.\n\n");
260
 
    cerr << desc << endl;
 
263
    usage(argv[0]);
261
264
    exit(EXIT_FAILURE);
262
265
  }
263
266
 
264
 
  fstream output(vm["table-name"].as<string>().c_str(),
265
 
                 ios::out | ios::trunc | ios::binary);
 
267
  fstream output(argv[optind], ios::out | ios::trunc | ios::binary);
266
268
  if (!table.SerializeToOstream(&output))
267
269
  {
268
270
    cerr << "Failed to write schema." << endl;