VistaIOIdentifyFiles(3)
π VistaIOIdentifyFiles(3) β the "where do my files even come from" decoder ring π
okay bestie, welcome to VistaIOIdentifyFiles(3) from the Library Functions Manual. this one is lowkey the stage manager of your whole program's file handling and she does NOT get enough credit. let's get into it π
β¨ NAME β¨
VistaIOIdentifyFiles β identify files specified by command line arguments π¦
πΈ SYNOPSIS πΈ
#include <vistaio.h>
VistaIOBoolean VistaIOIdentifyFiles (noptions, options, keyword, argc, argv, fd)
int noptions;
VistaIOOptionDescRec options[noptions];
VistaIOStringConst keyword;
int *argc;
char *argv;
int fd;
π ARGUMENTS π
noptionsβ how many entries live in your table of option descriptors. yes, it's literally just a count, she's humble.optionsβ where that table of option descriptors actually is. show me the address bestie.keywordβ the option keyword used on the command line to specify filenames. no-prefix, we're not doing that here.argcβ in: how many command line arguments to parse. out: how many arguments were not recognized as valid filenames. she does both directions, main character energy fr fr.argvβ in: a vector of command line arguments to parse. out: a vector of the arguments that were not recognized as valid filenames.fdβ may specify an open file descriptor that should be checked to make sure it corresponds to a file or pipe, but only if no filenames were explicitly given by command line arguments. or it can be-1to say "nah, skip that check." your call π
π¦ DESCRIPTION π¦
okay so by convention, a Vista program that reads one or more files can be told about those files in any of three ways:
(a) the filenames can be supplied as arguments to a command line option (e.g., vxview -in file1 file2 ...);
(b) the filenames can be supplied as command line arguments not associated with any particular option (e.g., vxview file1 file2 ...); or
(c) a file can be directed to the program's standard input stream (e.g., vxview < file1).
and the way this is parsed? these alternatives are considered in order. like a queue at the club, no skipping. first the program looks for an appropriate command line option (e.g., -in). if no such option has been specified, it checks for command line arguments not associated with any option. if those are also absent, it tries to read its file from the standard input stream. iconic behavior honestly β¨
similarly, an output file may be specified using a command line option (e.g., vconvolve -out file1), or, by omitting the option and directing the program's standard output stream (e.g., vconvolve > file1).
VistaIOIdentifyFiles identifies a program's input files or output files according to this convention. it gets called after VistaIOParseCommand(3) has parsed any command line arguments that can be identified as options, leaving the remaining arguments in *argc and argv. then VistaIOIdentifyFiles is called once to identify any input files, and maybe again to identify an output file. she's flexible like that π
the noptions and options parameters specify the table used earlier by VistaIOParseCommand to parse command line options. (peep VistaIOoption(3) for the details, iykyk.) the argc and argv parameters specify a list of command line arguments that VistaIOParseCommand has returned as unparsed β including the program's name, which should be first in this list, don't forget her. the keyword parameter specifies the command line option that may be used to specify filenames (e.g., in or out), absent any - prefix. and here's the requirement bestie, the entry in the option table for the option specified by keyword must:
- (a) refer to a
foundflag thatVistaIOParseCommandcan use to record whether or not the option is present on the command line, and - (b) refer to a location where the option's arguments can be stored.
so VistaIOIdentifyFiles consults the found flag to determine whether the option was present on the command line. if it was, VistaIOIdentifyFiles returns immediately β no thoughts, head empty, we're done. otherwise, it then examines *argc to determine whether an appropriate number of unparsed command line arguments exist. if there are a sufficient number of arguments present, they are interpreted as filenames and stored at the location indicated by the option table entry.
finally, if no filenames are found either as arguments to a -keyword option or as additional command line arguments, VistaIOIdentifyFiles considers the possibility that a file has been attached to a file descriptor such as the standard input or output stream. you may wish to ensure that a file is allowed to default to one of these streams only if the stream has been associated with a file or pipe, and not a terminal. in that case, pass as fd the file descriptor that will serve as the default source or destination of the file, and VistaIOIdentifyFiles will check that it is indeed associated with a file or pipe. otherwise, pass -1 for fd and it will not perform this check. periodt.
π RETURN VALUES π
VistaIOIdentifyFiles returns TRUE if it finds one or more files specified on the command line, and if the number of files specified is compatible with the number field of the option table entry. it returns FALSE if:
- no files were specified,
- the wrong number of files were specified, or
- the file would default to a file descriptor but the file descriptor
fdis not associated with a file or pipe.
on successful return, VistaIOIdentifyFiles will have eliminated, from the list represented by *argc and argv, any command line arguments that it identified as filenames. also, the filenames found will be stored at the location indicated by the option table entry for keyword. and a default to the standard input or output stream will be identified by a filename of -. (yes, a single dash. she's tiny but she's doing so much π₯Ή)
π EXAMPLE π
the following fragment is drawn from a program that reads one or more files and writes a single file. the input files may be specified with a -in option, as extra command line arguments, or by being directed to the standard input stream. the output file may be specified with a -out option, and, if that option is not present, the file will be written to the standard output stream regardless of whether it is associated with a file or a terminal.
VistaIOArgVector in_filenames;
VistaIOStringConst out_filename;
VistaIOBoolean in_found, out_found;
VistaIOOptionDescRec options[] = {
{ "in", VistaIOStringRepn, 0, & in_filenames, & in_found,
NULL, "Input file(s)" },
{ "out", VistaIOStringRepn, 1, & out_filename, & out_found,
NULL, "Output file" }
};
main (int argc, char *argv)
{
/* Parse command line options: */
if (! VistaIOParseCommand (VistaIONumber (options), options,
& argc, argv)) {
Usage: VistaIOReportUsage (argv[0], VistaIONumber (options), options,
"file1 file2...");
exit (1);
}
/* Identify input file(s): */
if (! VistaIOIdentifyFiles (VistaIONumber (options), options, "in",
& argc, argv, 0))
goto Usage;
/* Any remaining unparsed arguments are erroneous: */
if (argc > 1) {
VistaIOReportBadArgs (argc, argv);
goto Usage;
}
/* Identify output file: */
if (! VistaIOIdentifyFiles (VistaIONumber (options), options, "out",
& argc, argv, -1))
goto Usage;
/* Open and process each input file: */
for (i = 0; i < in_filenames.number; i++) {
filename = ((VistaIOStringConst *) in_filename.vector)[i];
if (strcmp (filename, "-") != 0) {
f = fopen (filename, "r");
if (f == NULL)
VistaIOError ("Unable to open file \"%s\"", filename);
} else f = stdin;
...
}
}
π SEE ALSO π
VistaIOOpenFile(3), VistaIOParseCommand(3), VistaIOReportBadArgs(3), VistaIOReportUsage(3), VistaIOoption(3),
π DIAGNOSTICS π
VistaIOIdentifyFiles reports errors in command line options by printing directly to the standard error stream. error reports include the program name obtained from argv[0]. the following messages may be produced:
n files must be specified by -keyword or extra command argumentsthe program requires that n files be specified (n > 1). neither a-keywordoption was present on the command line, nor were there at least n unparsed arguments that could be interpreted as filenames.No file specified by -keyword, extra command argument, or <the program requires that at least one file be specified, and it can be specified in any of three ways. however, it wasn't specified in any form. (ma'am. ma'am where is the file. π)
in addition, VistaIOIdentifyFiles may invoke VistaIOError with the following messages:
Option -keyword not defined in option tablethekeywordparameter specified a keyword not defined in the option table.No value storage for option -keywordthekeywordparameter specifies an option table entry whose value field isNULL.No "found" flag for option -keywordthekeywordparameter specifies an option table entry whose found field doesn't point to a dedicatedVistaIOBooleanvariable.Failed to fstat() fd fdanfstat()call failed on the supplied file descriptor,fd.
π«Ά AUTHOR π«Ά
Art Pope <pope@cs.ubc.ca>
Adaption to vistaio: Gert Wollny <gw.fossdev@gmail.com>
and that's the whole page bestie, you ate it UP π β¨ this was VistaIO Version 1.2.14, dated 24 April 1993 β yes she's a vintage queen and she still runs the group chat. go identify some files, you've got this ππ¦π
π¦ where this page comes from
- debian bookworm: libvistaio-dev 1.2.19-3 Β· libvista-orig
- debian trixie: libvistaio-dev 1.2.19-3+b2 Β· libvista-orig
- ubuntu jammy: libvistaio-dev 1.2.19-3 Β· libvista-orig
- ubuntu noble: libvistaio-dev 1.2.19-3 Β· libvista-orig
- ubuntu questing: libvistaio-dev 1.2.19-4
- ubuntu resolute: libvistaio-dev 1.2.19-4build1 Β· libvista-orig
- ubuntu stonking: libvistaio-dev 1.2.19-4build1 Β· libvista-orig
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms