]> git.ozlabs.org Git - ccan/blob - ccan/argcheck/_info
ccan: Correct some poor conventions in _info includes
[ccan] / ccan / argcheck / _info
1 #include "config.h"
2 #include <stdio.h>
3 #include <string.h>
4
5 /**
6  * argcheck - macros to check arguments at runtime
7  *
8  * This code provides some macros to check arguments for valid value ranges.
9  * Consider this a mild version of assert(3), because all it does is to log
10  * a message and continue.
11  *
12  * These macros don't replace error handling, but they are useful in
13  * situations where an error is unexpected but not common, i.e.
14  * "this shouldn't happen but if it does let me know".
15  *
16  * argcheck's error messages can be disabled by defining
17  * ARGCHECK_DISABLE_LOGGING before including the header file. The conditions
18  * will continue to evaluate but no error messages will be generated. It is thus
19  * safe to use argcheck macros inside if conditions.
20  *
21  * By default, argcheck prints to fprintf(stderr). That can be changed by
22  * defining argcheck_log to a custom log function. See argcheck_log_() for the
23  * function signature. If ARGCHECK_DISABLE_LOGGING is defined, the custom log
24  * function is not called.
25  *
26  * Example:
27  *      #include <stdio.h>
28  *      #include <ccan/argcheck/argcheck.h>
29  *
30  *      enum state { S1, S2, S3 };
31  *
32  *      static int some_state_machine(enum state s) {
33  *          int b;
34  *
35  *          argcheck_int_range(s, S1, S3);
36  *
37  *          switch(s) {
38  *              case S1: b = 8; break;
39  *              case S2: b = 9; break;
40  *              case S3: b = 88; break;
41  *              default:
42  *                      break;
43  *          }
44  *
45  *          return b;
46  *      }
47  *
48  *      int main(int argc, char *argv[]) {
49  *          int a = S1;
50  *
51  *          if (!argcheck_int_gt(argc, 1))
52  *              return 1;
53  *
54  *          return some_state_machine(a);
55  *      }
56  *
57  * Author: Peter Hutterer <peter.hutterer@who-t.net>
58  * Maintainer: Peter Hutterer <peter.hutterer@who-t.net>
59  * License: BSD-MIT
60  */
61
62 int main(int argc, char *argv[])
63 {
64         /* Expect exactly one argument */
65         if (argc != 2)
66                 return 1;
67
68         if (strcmp(argv[1], "depends") == 0) {
69                 printf("ccan/likely\n");
70                 printf("ccan/compiler\n");
71                 return 0;
72         }
73
74         return 1;
75 }