#include "dk4conf.h" #include "dk4types.h" #include "dk4mem.h" #include "dk4opt.h" $!trace-include /** Command line options for program. */ static dk4_option_t options[] = { { { dkT('i'), dkT("interactive"), DK4_OPT_ARG_NONE }, { NULL }, 0}, { { dkT('s'), dkT("socket"), DK4_OPT_ARG_STRING }, { NULL }, 0}, { { dkT('h'), dkT("host"), DK4_OPT_ARG_STRING }, { NULL }, 0}, { { dkT('p'), dkT("port"), DK4_OPT_ARG_UNSIGNED }, { NULL }, 0} }; static const size_t szoptions = sizeof(options)/sizeof(dk4_option_t); /** Main function. @param argc Number of command line arguments. @param argv Command line arguments array. @return 0 on success, all other values indicate errors. */ #if DK4_CHAR_SIZE > 1 int wmain(int argc, wchar_t *argv[]) #else int main(int argc, char *argv[]) #endif { dkChar *filenames[32]; size_t szfn = DK4_SIZEOF(filenames,DK4_PDKCHAR); int res; $!trace-init test-opt.deb $? "+ main" res = dk4opt_process_argv( options, szoptions, argc, argv, filenames, &szfn, 1, 1, NULL ); if (0 != res) { if (0 != options[0].found) { fputs("Option -i found.\n", stdout); } if (0 != options[1].found) { fputs("Option -s found.\nArgument: ", stdout); if (NULL != options[1].val.t) { fputs(options[1].val.t, stdout); } fputc('\n', stdout); fflush(stdout); } if (0 != options[2].found) { fputs("Option -h found.\n", stdout); if (NULL != options[2].val.t) { fputs(options[2].val.t, stdout); } fputc('\n', stdout); fflush(stdout); } if (0 != options[3].found) { fputs("Option -p found.\n", stdout); fprintf(stdout, "Argument: %ju\n", options[3].val.u); fflush(stdout); } } $? "- main" $!trace-end exit(0); return 0; }