diff options
author | Matthias-Christian Ott <ott@enolink.de> | 2008-06-10 17:56:57 +0200 |
---|---|---|
committer | Matthias-Christian Ott <ott@enolink.de> | 2008-06-10 17:56:57 +0200 |
commit | 5f287254715dd91f2c508a2a6b9853f0ef4ed785 (patch) | |
tree | d9c93f4d89197a5339f6e979b0cbd67519f37f0b | |
parent | 05ebee60843f24201f3e7c5c76ff94b6b5e868b2 (diff) | |
download | st-5f287254715dd91f2c508a2a6b9853f0ef4ed785.tar.gz st-5f287254715dd91f2c508a2a6b9853f0ef4ed785.zip |
source utility functions out to util.c
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | pty.c | 1 | ||||
-rw-r--r-- | st.c | 1 | ||||
-rw-r--r-- | std.c | 39 | ||||
-rw-r--r-- | util.c | 37 | ||||
-rw-r--r-- | util.h | 5 |
6 files changed, 46 insertions, 39 deletions
@@ -3,7 +3,7 @@ | |||
3 | 3 | ||
4 | include config.mk | 4 | include config.mk |
5 | 5 | ||
6 | SRC = st.c std.c | 6 | SRC = st.c std.c util.c pty.c |
7 | OBJ = ${SRC:.c=.o} | 7 | OBJ = ${SRC:.c=.o} |
8 | 8 | ||
9 | all: options st | 9 | all: options st |
@@ -1,4 +1,5 @@ | |||
1 | /* See LICENSE file for copyright and license details. */ | 1 | /* See LICENSE file for copyright and license details. */ |
2 | #include "util.h" | ||
2 | #include <sys/types.h> | 3 | #include <sys/types.h> |
3 | #include <sys/stat.h> | 4 | #include <sys/stat.h> |
4 | #include <fcntl.h> | 5 | #include <fcntl.h> |
@@ -1,4 +1,5 @@ | |||
1 | /* See LICENSE file for copyright and license details. */ | 1 | /* See LICENSE file for copyright and license details. */ |
2 | #include "util.h" | ||
2 | #include <stdio.h> | 3 | #include <stdio.h> |
3 | 4 | ||
4 | int | 5 | int |
@@ -1,12 +1,8 @@ | |||
1 | /* See LICENSE file for copyright and license details. */ | 1 | /* See LICENSE file for copyright and license details. */ |
2 | #include <sys/ioctl.h> | 2 | #include "util.h" |
3 | #include <sys/select.h> | ||
4 | #include <sys/stat.h> | ||
5 | #include <sys/types.h> | 3 | #include <sys/types.h> |
6 | #include <sys/wait.h> | 4 | #include <sys/wait.h> |
7 | #include <ctype.h> | 5 | #include <ctype.h> |
8 | #include <errno.h> | ||
9 | #include <fcntl.h> | ||
10 | #include <signal.h> | 6 | #include <signal.h> |
11 | #include <stdarg.h> | 7 | #include <stdarg.h> |
12 | #include <stdio.h> | 8 | #include <stdio.h> |
@@ -20,9 +16,6 @@ | |||
20 | 16 | ||
21 | void buffer(char c); | 17 | void buffer(char c); |
22 | void cmd(const char *cmdstr, ...); | 18 | void cmd(const char *cmdstr, ...); |
23 | void *emallocz(unsigned int size); | ||
24 | void eprint(const char *errstr, ...); | ||
25 | void eprintn(const char *errstr, ...); | ||
26 | void getpty(void); | 19 | void getpty(void); |
27 | void movea(int x, int y); | 20 | void movea(int x, int y); |
28 | void mover(int x, int y); | 21 | void mover(int x, int y); |
@@ -68,36 +61,6 @@ cmd(const char *cmdstr, ...) { | |||
68 | va_end(ap); | 61 | va_end(ap); |
69 | } | 62 | } |
70 | 63 | ||
71 | void * | ||
72 | emallocz(unsigned int size) { | ||
73 | void *res = calloc(1, size); | ||
74 | |||
75 | if(!res) | ||
76 | eprint("fatal: could not malloc() %u bytes\n", size); | ||
77 | return res; | ||
78 | } | ||
79 | |||
80 | void | ||
81 | eprint(const char *errstr, ...) { | ||
82 | va_list ap; | ||
83 | |||
84 | va_start(ap, errstr); | ||
85 | vfprintf(stderr, errstr, ap); | ||
86 | va_end(ap); | ||
87 | exit(EXIT_FAILURE); | ||
88 | } | ||
89 | |||
90 | void | ||
91 | eprintn(const char *errstr, ...) { | ||
92 | va_list ap; | ||
93 | |||
94 | va_start(ap, errstr); | ||
95 | vfprintf(stderr, errstr, ap); | ||
96 | va_end(ap); | ||
97 | fprintf(stderr, ": %s\n", strerror(errno)); | ||
98 | exit(EXIT_FAILURE); | ||
99 | } | ||
100 | |||
101 | void | 64 | void |
102 | movea(int x, int y) { | 65 | movea(int x, int y) { |
103 | x = MAX(x, cols); | 66 | x = MAX(x, cols); |
@@ -0,0 +1,37 @@ | |||
1 | /* See LICENSE file for copyright and license details. */ | ||
2 | #include "util.h" | ||
3 | #include <errno.h> | ||
4 | #include <stdarg.h> | ||
5 | #include <stdio.h> | ||
6 | #include <stdlib.h> | ||
7 | #include <string.h> | ||
8 | |||
9 | void * | ||
10 | emallocz(unsigned int size) { | ||
11 | void *res = calloc(1, size); | ||
12 | |||
13 | if(!res) | ||
14 | eprint("fatal: could not malloc() %u bytes\n", size); | ||
15 | return res; | ||
16 | } | ||
17 | |||
18 | void | ||
19 | eprint(const char *errstr, ...) { | ||
20 | va_list ap; | ||
21 | |||
22 | va_start(ap, errstr); | ||
23 | vfprintf(stderr, errstr, ap); | ||
24 | va_end(ap); | ||
25 | exit(EXIT_FAILURE); | ||
26 | } | ||
27 | |||
28 | void | ||
29 | eprintn(const char *errstr, ...) { | ||
30 | va_list ap; | ||
31 | |||
32 | va_start(ap, errstr); | ||
33 | vfprintf(stderr, errstr, ap); | ||
34 | va_end(ap); | ||
35 | fprintf(stderr, ": %s\n", strerror(errno)); | ||
36 | exit(EXIT_FAILURE); | ||
37 | } | ||
@@ -0,0 +1,5 @@ | |||
1 | /* See LICENSE file for copyright and license details. */ | ||
2 | |||
3 | void *emallocz(unsigned int size); | ||
4 | void eprint(const char *errstr, ...); | ||
5 | void eprintn(const char *errstr, ...); | ||