54 lines
1 KiB
Markdown
54 lines
1 KiB
Markdown
# validator.c
|
|
|
|
Validate command-line arguments.
|
|
|
|
---
|
|
|
|
## Includes
|
|
```c
|
|
#include <stddef.h>
|
|
|
|
#include "validator.h"
|
|
#include "utils.h"
|
|
```
|
|
|
|
---
|
|
|
|
## Function Description
|
|
|
|
### `validator_validate_args`
|
|
|
|
Checks and validates the content of the `t_args` structure, ensuring required
|
|
file input and extension arguments are consistent.
|
|
|
|
#### Parameter
|
|
- `args`: Pointer to a `t_args` structure containing command-line arguments.
|
|
|
|
#### Return Codes
|
|
|
|
| Code | Meaning |
|
|
|------|-----------------------------------------------------------------|
|
|
| 0 | Arguments are valid |
|
|
| 1 | Both input file and extension are missing |
|
|
| 2 | Extension is missing and cannot be inferred from input filename |
|
|
|
|
#### Implementation
|
|
```c
|
|
int8_t
|
|
validator_validate_args(t_args *args)
|
|
{
|
|
if (NULL == args->input)
|
|
{
|
|
if (NULL == args->ext)
|
|
return (1);
|
|
return (0);
|
|
}
|
|
if (NULL == args->ext)
|
|
{
|
|
args->ext = infer_ext_from_filename(args->input);
|
|
if (NULL == args->ext)
|
|
return (2);
|
|
}
|
|
return (0);
|
|
}
|
|
```
|