aboutsummaryrefslogtreecommitdiffstats
path: root/src/actionparser.h
blob: d3c97c456098fdb7bbc367dc34377fea73b37d3a (plain) (blame)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* actionparser.h - Action parser for ck -------------------------------*- C -*-
 *
 * This file is part of ck, the config keeper
 *
 * -----------------------------------------------------------------------------
 *
 * Copyright (C) 2018  Anastasis Grammenos
 * GPLv3 (see LICENCE for the full notice)
 *
 * -----------------------------------------------------------------------------
 *
 * The code here and in actionparser.c is responsible for parsing 
 * the user's input from the command line and return a struct
 * of the user's options ready to be handled by the rest of the 
 * procedures.
 *
 * -------------------------------------------------------------------------- */
#ifndef ACTIONPARSER_H
#define ACTIONPARSER_H

#include "cklist.h"

#define CK_ACTIONS                                                   \
  X(INIT)                                                            \
  X(ADD)                                                             \
  X(DEL)                                                             \
  X(EDIT)                                                            \
  X(LIST)                                                            \
  X(SEARCH)                                                          \
  X(HELP)

enum ParseErrors {
  PERR_NOERR = 0,
#define X(ACTION)                               \
  PERR_##ACTION##_WRONG,
  CK_ACTIONS
#undef X
  PERR_UNKNOWN_ACTION,
};
typedef enum ParseErrors ParseError;

enum CkActions {
  CK_WRONG_ACTION,
#define X(ACTION)                               \
  CKA_##ACTION,
  CK_ACTIONS
#undef X
};
typedef enum CkActions CkAction;

enum ActionParserResults {
  APR_OK,
  APR_ERR,
  APR_HELP,
  APR_VERSION
};
typedef enum ActionParserResults ActionParseResult;

typedef struct UserOptions UserOpt;
struct UserOptions {
  ParseError err;
  CkAction action;
  char *confDir;
  cklist *args;
};


/* Parse cli args, fill UserOpt struct
 * and return the result enum */
extern int parse_action(int argc, const char **argv, UserOpt *opt);
extern CkAction parser_get_action(const char *name, char *actionName);
extern void get_possible_action_strings(char *dest, CkAction ckAction);
extern void free_user_opt(UserOpt *opt);

#endif // ACTIONPARSER_H