GETALLARGS(3)

πŸ“¦ version 2022.10.16, in opensuse-leap 16.0

πŸ’… GETALLARGS(3) β€” SchilyΒ΄s LIBRARY FUNCTIONS, bestie edition πŸŽ€

okay so this page lives in section 3 of Schily´s LIBRARY FUNCTIONS and it's literally all about letting getallargs() do the flag-wrangling for you. it's giving "let the library handle the boring part" energy and honestly? we love that for us ✨


🌸 NAME 🌸

getallargs() β€” parses all the flag-type arguments. that's it, that's the vibe. πŸ¦‹


✨ SYNOPSIS ✨

#include <schily/getargs.h>

int getallargs(pac, pav, fmt, a1, ..., an)
     int *pac;       /* pointer to arg count */
     char *(*pav)[]; /* pointer to address of arg vector */
     char *fmt;      /* format string */
     type *a1;       /* pointer to result 1 */
                     /* (corresponding to the */
                     /* first descriptor in fmt) */
     type *an;       /* pointer to result n */
                     /* (corresponding to the */
                     /* nth descriptor in fmt) */

int getlallargs(pac, pav, props, fmt, a1, ..., an)
     int *pac;       /* pointer to arg count */
     char *(*pav)[]; /* pointer to address of arg vector */
     struct ga_props *props; /* control properties */
     char *fmt;      /* format string */
     type *a1;       /* pointer to result 1 */
                     /* (corresponding to the */
                     /* first descriptor in fmt) */
     type *an;       /* pointer to result n */
                     /* (corresponding to the */
                     /* nth descriptor in fmt) */

int getvallargs(pac, pav, props, vfmt)
     int *pac;       /* pointer to arg count */
     char *(*pav)[]; /* pointer to address of arg vector */
     struct ga_props *props; /* control properties */
     struct ga_flags *vfmt;  /* array of formats and args */

like, look at those three siblings. iconic family lineup fr fr πŸ‘‘


πŸ’– DESCRIPTION πŸ’–

getallargs() is part of the advanced option parsing interface β€” it's literally in the same friend group as the getargs() and getfiles() family 🫢

getallargs() parses all flag (option) arguments, and bestie, "anywhere on the command line" means anywhere. it does not return until all the arguments have been parsed correctly (returning 0), or an error has occurred (returning < 0). no half-jobs, no "ehh close enough" β€” it commits to the bit πŸ’…

getlallargs() is similar to getallargs() but it implements an additional ga_props parameter that must be initialized with getarginit() before it is passed. like, do not skip that step, that's the whole point πŸ™ˆ

getvallargs() is similar to getlallargs() but uses a structure ga_flags instead of a format string and a variable arg list with pointers. here's the array of structures ga_flags in all its glory:

struct ga_flags {
   const char  *ga_format; /* Comma separated list for one flag */
   void        *ga_arg;    /* Ptr. to variable to fill for flag */
   getpargfun  ga_funcp;   /* Ptr. for function to call (&/~)   */
};

the array is terminated by an element with ga_format == NULL. and for a ga_format that does not expect a function pointer, ga_funcp is NULL. no cap, that's how you know it's done πŸŽ€

if you want a more detailed description of the parameter matching, go see getargs() β€” it's the lore drop you're looking for πŸ“–


🌈 RETURNS 🌈

  • NOARGS 0 β€” all arguments have been successfully examined. slay πŸ’–
  • BADFLAG -1 β€” a bad flag (option) argument was supplied to the program. the argument *pav contains the offending command line argument. (rude of it, but ok πŸ’€)
  • BADFMT -2 β€” a bad format descriptor string has been detected. this means an error in the calling program, not a user input data error. so like… that one's on you, bestie 😭

⭐ general rules for the return code ⭐

  • > 0 β€” a file type argument was found.
  • 0 β€” all arguments have been parsed.
  • < 0 β€” an error occurred or not a file type argument.
flag and file arg processing should be terminated after getting a return code <= 0. like, that's your cue to stop. take the hint πŸ›‘

πŸ¦‹ SEE ALSO πŸ¦‹

getargs(3), getargerror(3), getfiles(3). the whole squad, go read them πŸ’œ


πŸ“ NOTES πŸ“

getallargs() must be called with the address of a count of items in the vector and the address of a pointer to the vector. both addresses must already have been properly treated in order to skip over the first parameter which is the name of the program. e.g. --ac; ++av β€” yes, exactly like that ✨

since getallargs() will destroy these values, copies should be made for later use in the program. and if an error occurs, av[0] points to the unmatched argument. so keep your receipts, bestie 🧾

the special argument, "--", is ignored, but the following argument in the command line is treated as a literal filename argument. this way, filenames beginning with '-', '+', or containing '=' can be passed to the routine. literally the escape hatch for chaotic filenames, and we're obsessed 🌸


πŸ™ˆ BUGS πŸ™ˆ

none currently known. flawless behavior, we stan 😌

mail bugs and suggestions to schilytools@mlists.in-berlin.de or open a ticket at https://codeberg.org/schilytools/schilytools/issues. they genuinely want to hear from you, fr fr πŸ’Œ

the mailing list archive may be found at:

https://mlists.in-berlin.de/mailman/listinfo/schilytools-mlists-in-berlin.de


πŸ‘‘ AUTHOR πŸ‘‘

Joerg Schilling and the schilytools project authors. legends, honestly 🌟


and that's the whole page, bestie!! this little masterpiece was written by Joerg Schilling, dated 2022/09/09, and it lives at GETALLARGS(3) β€” go forth and parse those flags, you gorgeous main character πŸ’–βœ¨πŸŽ€πŸ¦‹πŸ’…

πŸ“¦ where this page comes from