GETALLARGS(3)

πŸ“¦
version 2022.10.16 Β· 2 versions
, in opensuse-leap 16.0

πŸŽ€ GETALLARGS(3) πŸŽ€

okay bestie, so this is a page from SchilyΒ΄s LIBRARY FUNCTIONS, section 3 of the manual. Yes we're in the library functions section, and yes this one is about options β€” get comfy πŸ’…


✨ NAME ✨

getallargs() β€” it parses, like, all the flag-type arguments. every single one. no cap πŸ”₯


πŸ¦‹ 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 */

πŸ’– DESCRIPTION πŸ’–

so getallargs() is part of the advanced option parsing interface, and it runs with its besties β€” the getargs() and getfiles() family. the whole squad 🫢

getallargs() parses all the flag (option) arguments, and it does them anywhere on the command line β€” not just at the front, iykyk. it literally does not return until all the arguments have been parsed correctly (which returns 0), or an error has occurred (which returns something < 0). it's committed. main character energy πŸ‘‘

getlallargs() is similar to getallargs() but it implements an additional ga_props parameter that must be initialized with getarginit() before it is passed. don't skip that step bestie, it's giving undefined behaviour otherwise πŸ™ˆ

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

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 (&/~)   */
};

and how do you know you've hit the end? 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.

if you want a more detailed description of the parameter matching, go see getargs() β€” she explains it all πŸ’…


🌸 RETURNS 🌸

  • NOARGS β†’ 0 β€” all arguments have been successfully examined. slay ✨
  • BADFLAG β†’ -1 β€” a bad flag (option) argument was supplied to the program. and *pav contains the offending command line argument, so you can point right at the culprit πŸ’€
  • BADFMT β†’ -2 β€” a bad format descriptor string has been detected. and ngl this one means an error in the calling program, not a user input data error. so that's on you, not them 🫣

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.
🚨 important: flag and file arg processing should be terminated after getting a return code <= 0. like, stop there. periodt.

🧚 SEE ALSO 🧚

getargs(3), getargerror(3), getfiles(3).


πŸ“ NOTES πŸ“

okay this bit matters, so listen up bestie 🎧

getallargs() must be called with the address of a count of items in the vector and the address of a pointer to the vector. and both addresses must already have been properly treated in order to skip over the first parameter, which is the name of the program β€” like --ac; ++av, for example πŸ’…

since getallargs() will destroy these values, copies should be made for later use in the program 😭 (yes, really, make the copies). and if an error occurs, av[0] points to the unmatched argument.

the special argument -- is ignored, but the following argument in the command line is treated as a literal filename argument. that's the whole trick that lets filenames beginning with -, +, or containing = be passed to the routine. iconic ✨


πŸ’€ BUGS πŸ’€

none currently known. we love a clean record 🌈

mail bugs and suggestions to schilytools@mlists.in-berlin.de or open a ticket at https://codeberg.org/schilytools/schilytools/issues β€” the devs are lovely, 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.


okay that's the whole page babes πŸ’œ quick sign-off so you have the deets: this gem is by Joerg Schilling, dated 2022/09/09, and it comes from that GETALLARGS(3) source β€” go parse some args, you're gonna eat πŸŽ€

πŸ“¦ where this page comes from