glibc - In C, how would I tell argp what to do if no option is passed? -


mods, please not shoot down, have been searching in every nook , cranny of google solution in free time on past week or , have still come nothing.

i've been working on learning c. can find entire project pertaining question here, although many other programs may want able have answaer well:

https://github.com/christoffen-corporation/logo-generator

but question concerns file main.c. here's source:

#include <stdio.h> #include <argp.h> #include <cairo.h> #include "include.h" const char *argp_program_version = "the christoffen corporation logo generator v2.0.1"; const char *argp_program_bug_address = "m. gage morgan <gage@christoffen.com>"; static char doc[] = "generates of logo, or some.";  static int parse_opt (int key, char *arg, struct argp_state *state) {  switch (key) {  case 'c':   colored_nologo();   break;  case 'c':  colored_all();  break;  case 'o':  outlined_nologo();  break;  case 'o':  outlined_all();  break;  case 'f':  frankenlogos();  break;  case 'a':   all_imgs();  }  return 0; }  int main (int argc, char **argv) { struct argp_option options[] =  {  { "colored-no-logo", 'c', 0, 0, "generate colored triangles, except logo\n"},  { "colored-all", 'c', 0, 0, "generate colored triangles, , logo\n"},  { "outlined-no-logo", 'o', 0, 0, "generate outlined triangles, except logo\n"},  { "outlined-all", 'o', 0, 0, "generate outlined triangles, , logo\n"},   { "frankenlogos", 'f', 0, 0, "generate frankenlogos (don't ask; do)\n"},   { "all-images", 'a', 0, 0, "generate images: outlines, colors, , logos.\n"},  { 0 }  };  struct argp argp = { options, parse_opt, 0, 0 };  return argp_parse (&argp, argc, argv, 0, 0, 0);  } 

i have looked everywhere, , either i'm missing right in front of me, or there no way argp have "fallback" if no option specified.

any program has command line options should able have fallback if none specified. in case, example, wanted able either generate 7 triangles , logo ("./logo-generator -c" or "./logo-generator -o"), or possible if nothing specified option ("./logo-generator")

i have function titled all_imgs() i'd program fallback on when no options specified. know sounds simple , @ first felt stupid not knowing, 1.5 pages 14 different google queries, realized wasn't going crazy , there no "if nothing specified this" example.

by having source available , scenario, hope specific enough 1 of here @ figure out. if there other information left out, please ask , glad give you. also, if absolutely need know functions i'm using in main.c, can found in options.c, can found in github repo above (<10 reputation disables me putting here, mean no harm, swear).

i'm not asking re-write main.c and/or other files. specifically, problem in main.c , no other files affecting it. compiles fine, i'm looking minimal change, not entire re-write, of main.c. i'm asking simplest solution problem.

i appreciate time.

--mgage

edit: i've added source in requested. i've checked link added "user options," don't want use arguments, , don't understand hard that. options. need user able specify option if want generate portion of images, , if not, generate everything. again, don't want re-write main.

final edit: don't know why didn't realize sooner, answer marked correct helpful. apologize making difficult. result add conditional if before function started, give desired function argc, , use else stick desired part of argp wanted program. demonstrate, here's final result (and works!):

#include <stdio.h> #include <argp.h> #include <cairo.h> #include "include.h" const char *argp_program_version = "the christoffen corporation logo generator v2.0.1"; const char *argp_program_bug_address = "m. gage morgan <gage@christoffen.com>"; static char doc[] = "generates of logo, or some.";  static int parse_opt (int key, char *arg, struct argp_state *state) {  switch (key) {  case 'c':   colored_nologo();   break;  case 'c':  colored_all();  break;  case 'o':  outlined_nologo();  break;  case 'o':  outlined_all();  break;  case 'f':  frankenlogos();  break;  }  return 0; }  int main (int argc, char **argv) { if (argc == 1) { all_imgs(); } else {  struct argp_option options[] =  {  { "colored-no-logo", 'c', 0, 0, "generate colored triangles, except logo\n"},  { "colored-all", 'c', 0, 0, "generate colored triangles, , logo\n"},  { "outlined-no-logo", 'o', 0, 0, "generate outlined triangles, except logo\n"},  { "outlined-all", 'o', 0, 0, "generate outlined triangles, , logo\n"},   { "frankenlogos", 'f', 0, 0, "generate frankenlogos (don't ask; do)\n"},   { 0 }  };  struct argp argp = { options, parse_opt, 0, 0 };  return argp_parse (&argp, argc, argv, 0, 0, 0);    } } 

thanks, everyone. know lot of reading got frustrated boneheadedness.

you know argc number of arguments passed, right? don't need library count them. first argument name of program, looking case argc == 1.

int main(int argc, char **argv) {   if (argc == 1) {     /* there no arguments, handle case */   } else {     /* there arguments, proceed parse , handle them */   } }