-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathargs.h
60 lines (53 loc) · 1.94 KB
/
args.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef NEWLINE_ARGS_H
#define NEWLINE_ARGS_H
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#ifdef _WIN32
#include <wchar.h>
typedef wchar_t arg_char;
#define arg_strcmp wcscmp
#define arg_strncmp wcsncmp
#define arg_stricmp _wcsicmp
#define arg_strlen wcslen
#define arg_s(val) L##val
#define arg_f "%ls"
#define arg_fc "%lc"
#define arg_print(fmt, ...) wprintf(fmt L"\n", ##__VA_ARGS__)
#define arg_printerr(fmt, ...) fwprintf(stderr, fmt "\n", ##__VA_ARGS__)
#define arg_strerror _wcserror
#else
typedef char arg_char;
#define arg_strcmp strcmp
#define arg_strncmp strncmp
int arg_stricmp(const char* lhs, const char* rhs);
#define arg_strlen strlen
#define arg_s(val) val
#define arg_f "%s"
#define arg_fc "%c"
#define arg_print(fmt, ...) printf(fmt "\n", ##__VA_ARGS__)
#define arg_printerr(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)
#define arg_strerror strerror
#endif // _WIN32
enum NewlineType {
LF,
CRLF,
CR,
KEEP
};
struct Arguments {
enum NewlineType newline_type; // -t, --type
bool trailing_newline; // !(--no-newline)
bool strip_whitespace; // !(--no-strip)
bool verbose; // -v, --verbose
bool valid; // Set to true if arguments were valid
size_t num_filenames; // Number of files in 'filenames'
size_t filenames_capacity; // Capacity of 'filenames'
const arg_char** filenames; // Array of filenames
};
/* Parses the command line arguments given to the program, retuning an
Arguments struct describing the options and arguments given. */
struct Arguments parse_args(int argc, arg_char** argv);
/* Releases memory allocated by parse_args. */
void free_args(struct Arguments* args);
#endif // NEWLINE_ARGS_H