-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpinotify.c
84 lines (76 loc) · 1.64 KB
/
pinotify.c
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
76
77
78
79
80
81
82
83
84
/*
* $Id: pinotify.c,v 1.1 2024-04-22 08:03:39+05:30 Cprogrammer Exp mbhangui $
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#include "substdio.h"
#include "stralloc.h"
#include "lcdPrint.h"
#include "subprintf.h"
#include "str.h"
static char ssoutbuf[512], sserrbuf[512];
static substdio ssout = SUBSTDIO_FDBUF(write, 1, ssoutbuf, sizeof ssoutbuf);
static substdio sserr = SUBSTDIO_FDBUF(write, 2, sserrbuf, sizeof(sserrbuf));
stralloc summary = { 0 }, message = { 0 };
static void
flush()
{
if (substdio_flush(&sserr))
_exit (111);
else
if (substdio_flush(&ssout))
_exit (111);
}
void
die_nomem()
{
if (subprintf(&sserr, "out of memory\n") == -1)
_exit(111);
flush();
_exit(111);
}
void
usage()
{
if (subprintf(&sserr, "USAGE: pinotify summary arg1 [arg2 ...]\n") == -1)
_exit (111);
flush();
_exit(100);
}
int
main(int argc, char **argv)
{
int i;
if (argc < 3)
usage();
for (i = 2; i < argc; i++) {
if (!stralloc_catb(&message, "body:", 5) ||
!stralloc_catb(&message, argv[i], str_len(argv[i])) ||
!stralloc_append(&message, "\n"))
die_nomem();
}
if (!stralloc_catb(&message, "end:\n", 5) ||
!stralloc_0(&message))
die_nomem();
message.len--;
if (!stralloc_copyb(&summary, "summary:", 8) ||
!stralloc_cats(&summary, argv[1]) ||
!stralloc_append(&summary, "\n") ||
!stralloc_0(&summary))
die_nomem();
summary.len--;
return (sendMsg(&sserr, summary.s, message.len ? message.s : 0));
}
/*
* $Log: pinotify.c,v $
* Revision 1.1 2024-04-22 08:03:39+05:30 Cprogrammer
* Initial revision
*
*/