tico 0.1
Mechanical Watch Terminal Timegrapher
Functions
parseargs.c File Reference
#include "parseargs.h"
#include "config.h"
#include "printing.h"
#include <errno.h>
#include <getopt.h>
#include <limits.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h>
Include dependency graph for parseargs.c:

Functions

int checkUIntArg (int name, unsigned int *value, const char *optArg)
 Checks if the provided argument is a valid integer and parses it. More...
 
int checkFileArg (int name, FILE **filePtr, const char *optArg, const char *mode)
 Parses command line arguments and fills the CapConfig struct. More...
 
void parseArguments (int argc, char *argv[], CapConfig *cfg)
 Parses command line arguments and fills the CapConfig struct. More...
 
int getInt (char *ptr)
 Parses an integer from a string. More...
 
double getDouble (char *ptr)
 Parses a double from a string. More...
 
int getDoublesFromStdin (size_t maxCount, double *arr)
 Reads one line from stdin and parses up to maxCount doubles into array. More...
 
int getIntsFromFile (size_t maxCount, int *arr, FILE *file)
 Reads integers from file until EOF or maxCount is reached. More...
 

Function Documentation

◆ checkFileArg()

int checkFileArg ( int  name,
FILE **  filePtr,
const char *  optArg,
const char *  mode 
)

Parses command line arguments and fills the CapConfig struct.

Also provides utility functions for checking and parsing arguments.

Checks if the provided argument is a valid file and opens it.

Parameters
nameThe name of the argument (for error messages).
filePtrPointer to a FILE* that will be set to the opened file.
optArgThe argument string to check (should be a filename).
modeThe mode to open the file (e.g., "r" for read, "w" for write).
Returns
0 on success, non-zero on failure.

◆ checkUIntArg()

int checkUIntArg ( int  name,
unsigned int *  value,
const char *  optArg 
)

Checks if the provided argument is a valid integer and parses it.

Parameters
nameThe name of the argument (for error messages).
valuePointer to an int that will be set to the parsed value.
optArgThe argument string to check (should be an integer).
Returns
0 on success, non-zero on failure.

◆ getDouble()

double getDouble ( char *  ptr)

Parses a double from a string.

Parameters
ptrThe string to parse.
Returns
The parsed double value.

◆ getDoublesFromStdin()

int getDoublesFromStdin ( size_t  maxCount,
double *  arr 
)

Reads one line from stdin and parses up to maxCount doubles into array.

Reads doubles from standard input until EOF or maxCount is reached.

Returns the number of doubles stored (>=0), or -1 on I/O/memory error.

◆ getInt()

int getInt ( char *  ptr)

Parses an integer from a string.

Parameters
ptrThe string to parse.
Returns
The parsed integer value.

◆ getIntsFromFile()

int getIntsFromFile ( size_t  maxCount,
int *  arr,
FILE *  file 
)

Reads integers from file until EOF or maxCount is reached.

Parameters
maxCountThe maximum number of integers to read.
arrPointer to an array where the read integers will be stored.
filePointer to read integers from
Returns
The number of integers successfully read.

◆ parseArguments()

void parseArguments ( int  argc,
char *  argv[],
CapConfig cfg 
)

Parses command line arguments and fills the CapConfig struct.

Parameters
argcThe number of command line arguments.
argvThe array of command line argument strings.
cfgPointer to a CapConfig struct that will be filled with the parsed configuration.