]> git.ozlabs.org Git - ccan/blob - ccan/tal/str/_info
take, tal, tal/path, tal/str, tal/talloc: annotate APIs with TAKES.
[ccan] / ccan / tal / str / _info
1 #include "config.h"
2 #include <stdio.h>
3 #include <string.h>
4
5 /**
6  * tal/str - string helper routines which use tal
7  *
8  * This is a grab bag of functions for string operations, designed to enhance
9  * the standard string.h; these are separated from the non-tal-needing
10  * string utilities in "str.h".
11  *
12  * Example:
13  *      #include <ccan/tal/str/str.h>
14  *      #include <ccan/tal/grab_file/grab_file.h>
15  *      #include <err.h>
16  *
17  *      // Dumb demo program to double-linespace a file.
18  *      int main(int argc, char *argv[])
19  *      {
20  *              char *textfile;
21  *              char **lines;
22  *
23  *              if (argc > 2)
24  *                      errx(1, "Takes 0 or 1 arguments");
25  *              // Grab lines in file.
26  *              textfile = grab_file(NULL, argv[1]);
27  *              if (!textfile)
28  *                      err(1, "Failed reading %s", argv[1]);
29  *              lines = tal_strsplit(textfile, textfile, "\n", STR_EMPTY_OK);
30  *
31  *              // Join them back together with two linefeeds.
32  *              printf("%s", tal_strjoin(textfile, lines, "\n\n", STR_TRAIL));
33  *
34  *              // Free everything, just because we can.
35  *              tal_free(textfile);
36  *              return 0;
37  *      }
38  *
39  * License: BSD-MIT
40  * Author: Rusty Russell <rusty@rustcorp.com.au>
41  */
42 int main(int argc, char *argv[])
43 {
44         if (argc != 2)
45                 return 1;
46
47         if (strcmp(argv[1], "depends") == 0) {
48                 printf("ccan/str\n");
49 #ifdef TAL_USE_TALLOC
50                 printf("ccan/tal/talloc\n");
51 #else
52                 printf("ccan/tal\n");
53 #endif
54                 printf("ccan/take\n");
55                 return 0;
56         }
57
58         return 1;
59 }