main.c (view raw)
1/* Copyright (c) 2021, la-ninpre
2 *
3 * Permission to use, copy, modify, and/or distribute this software for any
4 * purpose with or without fee is hereby granted, provided that the above
5 * copyright notice and this permission notice appear in all copies.
6 *
7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14 *
15 * **********************************************************************
16 *
17 * this file contains main code for nimisewi as commandline utility
18 * that throws it's phrases to stdout.
19 *
20 * should be obvious :)
21 */
22
23#include <config.h>
24#include <err.h>
25#include <stdio.h>
26#include <stdlib.h>
27#include <unistd.h>
28#include <string.h>
29
30#include "nimisewi.h"
31
32#define NIMISEWI_MAMA 0x01
33#define NIMISEWI_IKE 0x02
34
35static void
36pana_sona_pali(void)
37{
38 printf("nimisewi [-v|-i]\n");
39 exit(EXIT_SUCCESS);
40}
41
42static void
43pana_sona_mama(void)
44{
45 printf("%s\n", PACKAGE_STRING);
46 printf("%s\n", PACKAGE_DESCRIPTION);
47 printf("compiled on %s %s using %s (%ld-bit)\n",
48 __DATE__, __TIME__, COMPILER_NAME, sizeof(void*)*8);
49#ifdef HAVE_PLEDGE
50 printf("HAVE_PLEDGE\n");
51#endif
52#ifdef HAVE_STRLCAT
53 printf("HAVE_STRLCAT\n");
54#endif
55#ifdef HAVE_ARC4RANDOM_UNIFORM
56 printf("HAVE_ARC4RANDOM_UNIFORM\n");
57#endif
58 /*return EXIT_SUCCESS;*/
59}
60
61static void
62nimisewi_pona(void)
63{
64 char *ns;
65 ns = nimi_sewi(6);
66 printf("%s\n", ns);
67 weka_e_nimi_sewi(ns);
68}
69
70static void
71nimisewi_pi_pilin_ike(void)
72{
73 char *ns;
74 ns = nimi_sewi(3);
75 printf("%s mute li lon\n"
76 "tan pi %s sin li seme?\n", ns, ns);
77 weka_e_nimi_sewi(ns);
78}
79
80int
81main(int argc, char *argv[])
82{
83 int ch, f;
84#ifdef HAVE_PLEDGE
85 if (pledge("stdio", NULL) == -1) {
86 err(EXIT_FAILURE, "pledge");
87 }
88#endif
89 f = 0;
90 while ((ch = getopt(argc, argv, "vi")) != -1) {
91 switch (ch) {
92 case 'v':
93 f |= NIMISEWI_MAMA;
94 break;
95 case 'i':
96 f |= NIMISEWI_IKE;
97 break;
98 default:
99 pana_sona_pali();
100 }
101 }
102 argc -= optind;
103 argv += optind;
104
105 if (f & NIMISEWI_MAMA)
106 pana_sona_mama();
107
108 if (f & NIMISEWI_IKE)
109 nimisewi_pi_pilin_ike();
110 else
111 nimisewi_pona();
112
113 return EXIT_SUCCESS;
114}
115