GETFILES(3)
π GETFILES(3) β schily's library functions, bestie edition π
okay so this is a page from SchilyΒ΄s LIBRARY FUNCTIONS (yes, with the fancy acute accent, we respect the branding β¨) and it's all about getfiles() and its two glow-up siblings. buckle up, it's actually kind of a vibe.
β¨ NAME β¨
getfiles() β literally just gets the next non flag-type argument. that's it. that's the whole job. π
π¦ SYNOPSIS π¦
#include <schily/getargs.h>
int getfiles(pac, pav, fmt)
int *pac; /* pointer to arg count */
char *(*pav)[]; /* pointer to address of arg vector */
char *fmt; /* format string */
int getlfiles(pac, pav, props, fmt)
int *pac; /* pointer to arg count */
char *(*pav)[]; /* pointer to address of arg vector */
struct ga_props *props; /* control properties */
char *fmt; /* format string */
int getvfiles(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 all those pointers. it's giving pointer-to-pointer-to-array-of-char-pointers. main character energy fr fr π«Ά
πΈ DESCRIPTION πΈ
so getfiles() is part of the advanced option parsing interface β it runs with the getargs() and getallrgs() family (yes, getallrgs, that's not a typo, that's the real name, don't come for me π). what it does is skip options until a file type argument shows up. it's like a bouncer at the club, but for argv. π
getfiles() returns with a value of +1 (NOTAFLAG) or +2 (FLAGDELIM) whenever a non-flag type argument is encountered. flag-type (option) arguments, along with their values, get straight-up ignored. the filename lives at *pav[0]. and here's the important bit, bestie β the caller must increment *pav and decrement *pac before calling getfiles() again. don't forget, or you'll be stuck in a loop staring at the same filename forever π
getlfiles() is similar to getfiles() but it implements an additional ga_props parameter that must be initialized with getarginit() before it is passed. no skipping that step, it's not a suggestion, it's the law β¨
getvfiles() is similar to getlfiles() 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:
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 this array is terminated by an element with ga_format == NULL. for a ga_format that does not expect a function pointer, ga_funcp is NULL. so don't go leaving garbage in there, the NULL sentinel is iconic and load-bearing π
π₯ RETURNS π₯
okay this is the part where you actually pay attention, bestie.
FLAGDELIM 2β the command line argument"--"stopped flag processing. slay, the double dash did its thing.NOTAFLAG 1β the argument*pavdoes not appear to be a flag. so it's a file. periodt.NOARGS 0β all arguments have been successfully examined. we're done here πBADFLAG -1β a bad flag (option) argument was supplied to the program. the argument*pavcontains the offending command line argument. π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... it's you. it's your bug. no cap.
β 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
and listen β flag and file arg processing should be terminated after getting a return code <= 0. like, wrap it up, the party's over, go home π§
π SEE ALSO π
the whole friend group, honestly. go read all of them π
π NOTES π
initially, *pav must point to the first argument (not the program name) and *pac must not count the program name. and before calling getfiles() again, decrement *pac and increment *pav β otherwise the same name will be pointed to by *pav. bestie. i'm begging you. remember this one. π
π BUGS π
none currently known β¨ (iconic behaviour, honestly)
mail bugs and suggestions to schilytools@mlists.in-berlin.de or open a ticket at https://codeberg.org/schilytools/schilytools/issues.
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, truly π«Ά
quick vibe check reminder: every*pacand*pavin here is load-bearing, so don't get cute with them in your actual code. mwah π
okay that's the whole page, ily, go parse some arguments responsibly!! πΈ
β brought to you by the Joerg Schilling era, dated 2022/09/09, from GETFILES(3) in SchilyΒ΄s library functions. catch you on the next man page, bestie πππ¦
π¦ where this page comes from
- opensuse-leap 16.0: libschily-devel-doc 2022.10.16-160000.2.2 Β· CDDL-1.0
- Copyright 1985-2020 J. Schilling
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms