misc
Description
misc (code/jonnyb/misc.c) is Jonathan Beaudoinβs boilerplate C command-line skeleton used as a starting point when writing new OMG command-line utilities. It initializes the global ARGC and ARGV variables required by support.h (usage(), error(), warning()), parses -in <infile> and -out <outfile> arguments, validates that both files can be opened for reading and writing respectively, and cleanly closes both file handles.
Usage
misc -in <infile> -out <outfile>
Example
# Copy misc.c as a starting template for a new OMG utility:
cp code/jonnyb/misc.c code/jonnyb/gom_stuff/my_new_tool.c
Arguments
| Option | Description | Default |
|---|---|---|
-in <infile> | Input file path (opened with fopen(inname, "r")). | Required |
-out <outfile> | Output file path (opened with fopen(outname, "w")). | Required |
Code Structure (code/jonnyb/misc.c)
- Global Error-Reporting Setup: Assigns
ARGC = argc; ARGV = argv;so thatusage()anderror()fromsupport.hprint the program name andUSAGEstring on invalid arguments. - Argument Loop: Iterates over
while (*(++argv))matching-inand-out. - File Handle Validation: Verifies
if (!inname || !outname) usage("Must specify input/output file");, opens both files, checks forNULLpointers viaerror(), and closes both streams before returning0.