X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flibpspp%2Fargv-parser.c;h=97ec02834a43d02baf4598c9b5c05d8832960c8b;hb=52c296b2b56751899e9d9fb8772135a5073d7168;hp=b3dc46134a81653a9698269a7da8b0ceec033058;hpb=0d3402b7f5f8649a5f6da491c7da88a7a05d3d3a;p=pspp diff --git a/src/libpspp/argv-parser.c b/src/libpspp/argv-parser.c index b3dc46134a..97ec02834a 100644 --- a/src/libpspp/argv-parser.c +++ b/src/libpspp/argv-parser.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,14 +16,14 @@ #include -#include +#include "libpspp/argv-parser.h" #include -#include -#include +#include "libpspp/assertion.h" +#include "libpspp/str.h" -#include "xalloc.h" +#include "gl/xalloc.h" struct argv_option_plus { @@ -78,6 +78,7 @@ argv_parser_add_options (struct argv_parser *ap, ap->options = x2nrealloc (ap->options, &ap->allocated_options, sizeof *ap->options); + assert (src->long_name != NULL || src->short_name != 0); dst = &ap->options[ap->n_options++]; dst->base = *src; dst->cb = cb; @@ -127,11 +128,11 @@ argv_parser_run (struct argv_parser *ap, int argc, char **argv) if (shortopt_ptrs[c] == NULL) { shortopt_ptrs[c] = aop; - ds_put_char (&shortopts, aop->base.short_name); + ds_put_byte (&shortopts, aop->base.short_name); if (aop->base.has_arg != no_argument) - ds_put_char (&shortopts, ':'); + ds_put_byte (&shortopts, ':'); if (aop->base.has_arg == optional_argument) - ds_put_char (&shortopts, ':'); + ds_put_byte (&shortopts, ':'); } else { @@ -161,7 +162,7 @@ argv_parser_run (struct argv_parser *ap, int argc, char **argv) retval = false; break; } - else if (c >= LONGOPT_VAL_BASE && c < LONGOPT_VAL_BASE + n_longopts) + else if (c >= LONGOPT_VAL_BASE && c < LONGOPT_VAL_BASE + n_longopts + 1) { struct argv_option_plus *aop = &ap->options[c - LONGOPT_VAL_BASE]; aop->cb (aop->base.id, aop->aux);