Beispiel #1
0
int main(int argc, char* argv[])
{
	for ( int i = 1; i < argc; ++i )
		if ( strcmp( argv[i], "--help" ) == 0 )
			return print_help();

	for ( int i = 1; i < argc; ++i )
		if ( strcmp( argv[i], "--version" ) == 0 )
			return print_version();

	for ( int i = 1; i < argc; ++i )
	{
		if ( is_integer(argv[i]) )
			print_properties_text(argv[i]);
		else
		{
			if ( *argv[i] == '-' )
			{
				if ( strcmp(argv[i], "-i") == 0 )
				{
					if ( i + 1 >= argc )
						return fprintf(stderr, "ngossip: file not specified\n");

					process_filename(argv[i + 1]);
				}
			}
			else
			{
				//process_property(argv[i]);
			}
		}
	}

	return 0;
}
Beispiel #2
0
int main (int argc, char *argv[]){
  //from http://web.cs.wpi.edu/~cs4513/d14/samples/env.c
  extern char **environ;      /* externally declared */
  char *match;
  //end code from samples/env.c
  
  char *trash_env_name = "TRASH";
  int predefined_trash_flag = 0;
  
  //adapted from http://web.cs.wpi.edu/~cs4513/d14/samples/get-opt.c
  int c;
  int custom_trash_flag = 0;
  char *custom_trash_path = NULL;
  char *entity_to_undelete = NULL;
  int num_files_to_undelete = 0;
  extern int optind, opterr;
  //end code from samples/get-opt.c

  //adapted from http://web.cs.wpi.edu/~cs4513/d14/samples/env.c
  match = getenv(trash_env_name);
  if(!match){
    predefined_trash_flag = 0;
  }
  else{
    //predefined trash path contained in "match" variable
    predefined_trash_flag = 1;
  }
  //end code from samples/env.c  
  
  
  //from http://web.cs.wpi.edu/~cs4513/d14/samples/get-opt.c
  opterr = 1; /* set to 0 to disable error message */
  while ((c = getopt (argc, argv, "ht:i:")) != EOF) {
    switch (c) {
    case 'h':
      usage();
      break;
    case 't':
      custom_trash_flag++;
      custom_trash_path = optarg;
      break;
	case 'i':
	entity_to_undelete = optarg;
	process_filename(predefined_trash_flag, match, custom_trash_flag, custom_trash_path, entity_to_undelete);
	num_files_to_undelete++;
    }
  }
    //end code from samples/get-opt.c
} //end main
Beispiel #3
0
int main(int argc, char **argv)
{
    iENTER;
    //FSTREAM_READER_STATE    *preader_state = NULL;
    //FSTREAM_WRITER_STATE    *pwriter_state = NULL;
    ION_STREAM              *output_stream = NULL;
    ION_STREAM              *input_stream = NULL;
    hWRITER                  hwriter = 0;
    hREADER                  hreader = 0;
    
    ION_STRING               temp;
    char                    *name = NULL;
    ION_TYPE                 t = (ION_TYPE)999;
    int32_t                  symbol_table_count = 0;
    int                      ii, non_argc = 0;
    char                   **non_argv = NULL;


    ION_STRING_INIT(&temp);

    // read the command line for any instruction the caller might have
    non_argv = (char**)malloc(argc * sizeof(char*));
    process_args(argc, argv, non_argv, &non_argc);
    if (g_print_help) SUCCEED();

    // clear the option structs and set them appropriately
    memset(&g_reader_options, 0, sizeof(g_reader_options));
    memset(&g_writer_options, 0, sizeof(g_writer_options));
    g_writer_options.pretty_print     = TRUE;
    
    // set up our debug options
    if (g_dump_args) dump_arg_globals();

    if (g_timer) {
        start_timing();
    }

    // read in the catalog, if there is one
    if (g_catalogs) {
        CHECK( load_catalog_list(&g_hcatalog), "load a catalog file" );
        CHECK(ion_catalog_get_symbol_table_count(g_hcatalog, &symbol_table_count), "get the symbol table count from the loaded catalog");
        fprintf(stderr, "Catalog loaded %d symbol tables\n", symbol_table_count);
    }
    else {
        CHECK( ion_catalog_open( &g_hcatalog ), "open empty catalog" );
    }
    g_reader_options.pcatalog = (ION_CATALOG *)g_hcatalog; // HACK - TODO - HOW SHOULD WE HANDLE THIS? - either the options
    g_writer_options.pcatalog = (ION_CATALOG *)g_hcatalog; // HACK - TODO - should have an hcatalog or we need a h to p fn


    // if we're updating an existing catalog load it
    if (g_update_symtab) {
        // load specified symbol table
        CHECK( load_symbol_table(&g_hsymtab, g_update_symtab), "load symbol table to update");
    }
    else {
        // othwerwise we need to init a symbol table to update
        CHECK( initialize_new_symbol_table(&g_hsymtab), "initialize a new (empty) symbol table to fill" );
    }

    // open the output stream writer attached to stdout
    // TODO: allow caller to specify the output file on the command line
    CHECK( ion_stream_open_stdout( &output_stream ), "ion stream open stdout failed");
    CHECK( ion_writer_open( &hwriter, output_stream, &g_writer_options), "ion writer open failed");
    //CHECK( ion_writer_open_fstream(&pwriter_state, stdout, &g_writer_options), "writer open failed");

    // now, do we process from stdin or from file names on the command line
    if (non_argc > 0) {
        // file names
        for (ii=0; ii<non_argc; ii++) {
            // open our input and output streams (reader and writer)
            CHECK( process_filename(non_argv[ii], &g_reader_options), "process filename failed" );
        }
    }
    else {
        // from stdin
        // open our input and output streams (reader and writer)
        CHECK( ion_stream_open_stdin( &input_stream ), "open stdin as an ION_STREAM failed");
        CHECK( ion_reader_open(&hreader, input_stream, &g_reader_options), "open stdin as an ion reader failed");
        //CHECK( ion_reader_open_fstream(&preader_state, stdin, &g_reader_options), "reader open stdin failed");
        CHECKREADER( process_input_reader(hreader), "process stdin", hreader );
        CHECK( ion_reader_close( hreader ), "closing the ion reader");
        CHECK( ion_stream_close( input_stream), "closing the input stream");
        // CHECK( ion_reader_close_fstream( preader_state ), "closing the reader");
    }

    // if we're emitting a symbol table we need to actually output the 
    // table now (we only collected the symbols from the input sources 
    // during the pass above
    CHECK( symbol_table_write( hwriter ), "emit the new symbol table we've built up" );

    // close up
    //CHECK( ion_writer_close_fstream( pwriter_state ), "closing the writer");
    CHECK( ion_writer_close( hwriter ), "closing the ion writer");
    CHECK( ion_stream_close( output_stream ), "closing the ion output stream");

    if (g_hsymtab)  CHECK(ion_symbol_table_close(g_hsymtab), "closing the temp symbol table");
    if (g_hcatalog) CHECK(ion_catalog_close(g_hcatalog), "closing the catalog");
    SUCCEED();
    
fail:// this is iRETURN expanded so I can set a break point on it
    if (g_debug) {
        fprintf(stderr, "\nionsymbols finished, returning err [%d] = \"%s\", %d\n", err, ion_error_to_str(err), (intptr_t)t);
    }

    if (g_timer) {
        stop_timing();
    }

    if (non_argv) free(non_argv);
    return err;
}