123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- #ifndef __MYARGP__
- #define __MYARGP__
- #include <argp.h>
- #include <igraph.h>
- #include "io.h"
- #include "operations.h"
- #include "graph.h"
- /* This structure is used by main to communicate with parse_opt. */
- struct arguments {
- char **args;
- long int ngraphs;
- void (*oper)(graph_t *result, igraph_vector_ptr_t *glist);
- void (*ofmt)(graph_t *g); /* Output format flag */
- void (*ifmt)(igraph_t *g, FILE *ist); /* Input format flag */
- char *outfile; /* Argument for -o */
- };
- /*
- OPTIONS. Field 1 in ARGP.
- Order of fields: {NAME, KEY, ARG, FLAGS, DOC}.
- */
- static struct argp_option options[] = {
- {"output", 'o', "OUTFILE", 0, "Output to OUTFILE instead of to standard output"},
- {"operation", 'w', "OPERATION", 0, "Select OPERATION from union, intersection, xor. (Required.)"},
- {"output_format", 'f', "FORMAT", 0,
- "Select output format from dot (default), graphml, gml, pajek, edgelist, ncol, lgl, dimacs."},
- {"input_format", 'i', "FORMAT", 0,
- "Select input format from graphml, gml, pajek, edgelist, ncol, lgl, dimacs, graphdb, dl. (Required.)"},
- {0}
- };
- /*
- PARSER. Field 2 in ARGP.
- Order of parameters: KEY, ARG, STATE.
- */
- static error_t parse_opt (int key, char *arg, struct argp_state *state) {
- struct arguments *arguments = state->input;
- switch (key) {
- case 'o':
- arguments->outfile = arg;
- ost = fopen(arg, "w");
- break;
- case 'f':
- if(strcmp(arg, "graphml") == 0) {
- arguments->ofmt = print_graphml;
- } else if(strcmp(arg, "gml") == 0) {
- arguments->ofmt = print_gml;
- } else if(strcmp(arg, "pajek") == 0) {
- arguments->ofmt = print_pajek;
- } else if(strcmp(arg, "edgelist") == 0) {
- arguments->ofmt = print_edgelist;
- } else if(strcmp(arg, "ncol") == 0) {
- arguments->ofmt = print_ncol;
- } else if(strcmp(arg, "lgl") == 0) {
- arguments->ofmt = print_lgl;
- } else if(strcmp(arg, "dot") == 0) {
- arguments->ofmt = print_dot;
- } else {
- arguments->ofmt = print_error;
- }
- break;
- case 'i':
- if(strcmp(arg, "graphml") == 0) {
- arguments->ifmt = read_graphml;
- } else if(strcmp(arg, "gml") == 0) {
- arguments->ifmt = read_gml;
- } else if(strcmp(arg, "pajek") == 0) {
- arguments->ifmt = read_pajek;
- } else if(strcmp(arg, "edgelist") == 0) {
- arguments->ifmt = read_edgelist;
- } else if(strcmp(arg, "ncol") == 0) {
- arguments->ifmt = read_ncol;
- } else if(strcmp(arg, "lgl") == 0) {
- arguments->ifmt = read_lgl;
- } else if(strcmp(arg, "cl") == 0) {
- arguments->ifmt = read_dl;
- } else if(strcmp(arg, "graphdb") == 0) {
- arguments->ifmt = read_graphdb;
- } else {
- arguments->ifmt = read_error;
- }
- break;
- case 'w':
- if(strcmp(arg, "union") == 0) {
- arguments->oper = graph_union;
- } else if(strcmp(arg, "intersection") == 0) {
- arguments->oper = graph_intersection;
- } else if(strcmp(arg, "xor") == 0) {
- arguments->oper = graph_xor;
- } else {
- arguments->oper = graph_operation_error;
- }
- break;
- case ARGP_KEY_ARG:
- arguments->args = &state->argv[--state->next];
- state->next = state->argc;
- ++arguments->ngraphs;
- //arguments->args[state->arg_num] = arg;
- break;
- case ARGP_KEY_END:
- if(state->arg_num < 2) { // Too few arguments.
- argp_usage(state);
- }
- break;
- default:
- return ARGP_ERR_UNKNOWN;
- }
- return 0;
- }
- /*
- ARGS_DOC. Field 3 in ARGP.
- A description of the non-option command-line arguments
- that we accept.
- */
- static char args_doc[] = "FILE1 FILE2 ... FILEN";
- /*
- DOC. Field 4 in ARGP.
- Program documentation.
- */
- static char doc[] = "Ganesha -- perform operations on graphs.";
- /*
- The ARGP structure itself.
- */
- static struct argp argp = {options, parse_opt, args_doc, doc};
- #endif
|