Codebase list kbd / e25dbc5
Initialize the kbdfile context internally if necessary Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com> Alexey Gladkov 4 years ago
21 changed file(s) with 50 addition(s) and 135 deletion(s). Raw diff Collapse all Expand all
1111 1. Find a git server that can be reached from anywhere in internet anonymously.
1212 Github is for example a popular choice.
1313
14 2. Create your own util-linux contributor repository, and push a upstream clone
14 2. Create your own kbd contributor repository, and push a upstream clone
1515 to there.
1616
1717 3. In these instructions the upstream remote repository is called 'origin' and
2626
2727 struct kbdfile {
2828 struct kbdfile_ctx *ctx;
29 int flags;
2930 FILE *fd;
30 int pipe;
3131 char pathname[MAXPATHLEN];
3232 };
33
34 #define KBDFILE_CTX_INITIALIZED 0x01
35 #define KBDFILE_PIPE 0x02
3336
3437 #define kbdfile_log_cond(ctx, level, arg...) \
3538 do { \
3636
3737 fp->ctx = ctx;
3838
39 if (!fp->ctx) {
40 fp->ctx = kbdfile_context_new();
41 if (!fp->ctx)
42 return NULL;
43 fp->flags |= KBDFILE_CTX_INITIALIZED;
44 }
45
3946 return fp;
4047 }
4148
4451 {
4552 if (!fp)
4653 return;
54 if (fp->flags & KBDFILE_CTX_INITIALIZED)
55 kbdfile_context_free(fp->ctx);
4756 kbdfile_close(fp);
4857 free(fp);
4958 }
8392 {
8493 if (!fp || !fp->fd)
8594 return;
86 if (fp->pipe)
95 if (fp->flags & KBDFILE_PIPE)
8796 pclose(fp->fd);
8897 else
8998 fclose(fp->fd);
102111
103112 sprintf(pipe_cmd, "%s %s", dc->cmd, fp->pathname);
104113
105 fp->fd = popen(pipe_cmd, "r");
106 fp->pipe = 1;
114 fp->fd = popen(pipe_cmd, "r");
115 fp->flags |= KBDFILE_PIPE;
107116
108117 free(pipe_cmd);
109118
137146 }
138147 }
139148
140 fp->pipe = 0;
149 fp->flags &= ~KBDFILE_PIPE;
141150
142151 if ((fp->fd = fopen(fp->pathname, "r")) == NULL) {
143152 char buf[200];
151160 }
152161
153162 static int
154 findfile_by_fullname(const char *fnam, const char *const *suffixes, struct kbdfile *fp)
163 findfile_by_fullname(const char *fnam, char **suffixes, struct kbdfile *fp)
155164 {
156165 int i;
157166 struct stat st;
158167 struct decompressor *dc;
159168 size_t fnam_len, sp_len;
160169
161 fp->pipe = 0;
170 fp->flags &= ~KBDFILE_PIPE;
162171 fnam_len = strlen(fnam);
163172
164173 for (i = 0; suffixes[i]; i++) {
190199 }
191200
192201 static int
193 filecmp(const char *fname, char *name, const char *const *suf, unsigned int *index, struct decompressor **d)
202 filecmp(const char *fname, char *name, char **suf, unsigned int *index, struct decompressor **d)
194203 {
195204 /* Does d_name start right? */
196205 char *p = name;
232241 }
233242
234243 static int
235 findfile_in_dir(const char *fnam, const char *dir, const int recdepth, const char *const *suf, struct kbdfile *fp)
244 findfile_in_dir(const char *fnam, const char *dir, const int recdepth, char **suf, struct kbdfile *fp)
236245 {
237246 char errbuf[200];
238247 char *ff, *fdir, *path;
239248 int rc = 1, secondpass = 0;
240249 size_t dir_len;
241250
242 fp->fd = NULL;
243 fp->pipe = 0;
251 fp->fd = NULL;
252 fp->flags &= ~KBDFILE_PIPE;
244253
245254 dir_len = strlen(dir);
246255
334343 snprintf(fp->pathname, sizeof(fp->pathname), "%s/%s%s%s", dir, fnam, suf[index], (dc ? dc->ext : ""));
335344
336345 if (!dc) {
337 fp->pipe = 0;
346 fp->flags &= ~KBDFILE_PIPE;
338347 fp->fd = fopen(fp->pathname, "r");
339348
340349 if (!(fp->fd)) {
370379 }
371380
372381 int
373 kbdfile_find(char *fnam, const char *const *dirpath, const char *const *suffixes, struct kbdfile *fp)
382 kbdfile_find(char *fnam, char **dirpath, char **suffixes, struct kbdfile *fp)
374383 {
375384 int rc, i;
376385
379388 return -1;
380389 }
381390
382 fp->pipe = 0;
391 fp->flags &= ~KBDFILE_PIPE;
383392
384393 /* Try explicitly given name first */
385394 strncpy(fp->pathname, fnam, sizeof(fp->pathname));
433442 struct kbdfile *
434443 kbdfile_open(struct kbdfile_ctx *ctx, const char *filename)
435444 {
436 struct kbdfile *fp = calloc(1, sizeof(struct kbdfile));
445 struct kbdfile *fp = kbdfile_new(ctx);
437446
438447 if (!fp)
439448 return NULL;
440449
441 fp->ctx = ctx;
442 strncpy(fp->pathname, filename, sizeof(fp->pathname));
450 kbdfile_set_pathname(fp, filename);
443451
444452 if (maybe_pipe_open(fp) < 0) {
445453 kbdfile_free(fp);
3636 struct kbdfile *kbdfile_open(struct kbdfile_ctx *ctx, const char *filename);
3737 void kbdfile_close(struct kbdfile *fp);
3838
39 int kbdfile_find(char *fnam, const char *const *dirpath, const char *const *suffixes, struct kbdfile *fp);
39 int kbdfile_find(char *fnam, char **dirpath, char **suffixes, struct kbdfile *fp);
4040
4141 char *kbdfile_get_pathname(struct kbdfile *fp);
4242 int kbdfile_set_pathname(struct kbdfile *fp, const char *pathname);
9696 char *console = NULL;
9797 char *ev;
9898 struct kbdfile *fp;
99 struct kbdfile_ctx *kbdfile_ctx;
10099
101100 set_progname(argv[0]);
102101 setuplocale();
106105 exit(EXIT_FAILURE);
107106 }
108107
109 if ((kbdfile_ctx = kbdfile_context_new()) == NULL)
110 nomem();
111
112 if ((fp = kbdfile_new(kbdfile_ctx)) == NULL)
108 if ((fp = kbdfile_new(NULL)) == NULL)
113109 nomem();
114110
115111 while ((c = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) {
256252 fail:
257253 lk_free(ctx);
258254 kbdfile_free(fp);
259 kbdfile_context_free(kbdfile_ctx);
260255
261256 if (fd >= 0)
262257 close(fd);
265265 char buffer[65536];
266266 char *p;
267267 struct kbdfile *fp;
268 struct kbdfile_ctx *kbdfile_ctx;
269
270 if ((kbdfile_ctx = kbdfile_context_new()) == NULL)
271 nomem();
272
273 if ((fp = kbdfile_new(kbdfile_ctx)) == NULL)
268
269 if ((fp = kbdfile_new(NULL)) == NULL)
274270 nomem();
275271
276272 if (kbdfile_find((char *) tblname, unidirpath, unisuffixes, fp)) {
292288 }
293289
294290 kbdfile_free(fp);
295 kbdfile_context_free(kbdfile_ctx);
296291
297292 if (listct == 0 && !force) {
298293 fprintf(stderr,
127127 int u = 0;
128128 int lineno = 0;
129129 struct kbdfile *fp;
130 struct kbdfile_ctx *kbdfile_ctx;
131
132 if ((kbdfile_ctx = kbdfile_context_new()) == NULL)
133 nomem();
134
135 if ((fp = kbdfile_new(kbdfile_ctx)) == NULL)
130
131 if ((fp = kbdfile_new(NULL)) == NULL)
136132 nomem();
137133
138134 if (kbdfile_find(mfil, mapdirpath, mapsuffixes, fp)) {
181177 }
182178 }
183179 kbdfile_free(fp);
184 kbdfile_context_free(kbdfile_ctx);
185180 return u;
186181 }
187182
114114 char tty[12], cmd[80], infile[1024];
115115 const char *defaultfont;
116116 struct kbdfile *fp;
117 struct kbdfile_ctx *kbdfile_ctx;
118117
119118 set_progname(argv[0]);
120119 setuplocale();
148147 usage();
149148 }
150149
151 if ((kbdfile_ctx = kbdfile_context_new()) == NULL)
152 nomem();
153
154 if ((fp = kbdfile_new(kbdfile_ctx)) == NULL)
150 if ((fp = kbdfile_new(NULL)) == NULL)
155151 nomem();
156152
157153 if (mode == MODE_RESTORETEXTMODE) {
277273 }
278274
279275 kbdfile_free(fp);
280 kbdfile_context_free(kbdfile_ctx);
281276
282277 /*
283278 * for i in /dev/tty[0-9] /dev/tty[0-9][0-9]
396396 struct unicode_list *uclistheads;
397397 int i;
398398 struct kbdfile *fp;
399 struct kbdfile_ctx *kbdfile_ctx;
400
401399
402400 if (ifilct == 1) {
403401 loadnewfont(fd, ifiles[0], iunit, hwunit, no_m, no_u);
404402 return;
405403 }
406404
407 if ((kbdfile_ctx = kbdfile_context_new()) == NULL)
408 nomem();
409
410 if ((fp = kbdfile_new(kbdfile_ctx)) == NULL)
405 if ((fp = kbdfile_new(NULL)) == NULL)
411406 nomem();
412407
413408 /* several fonts that must be merged */
437432 "must be psf fonts - %s isn't\n"),
438433 kbdfile_get_pathname(fp));
439434 kbdfile_free(fp);
440 kbdfile_context_free(kbdfile_ctx);
441435 exit(EX_DATAERR);
442436 }
443437
444438 kbdfile_free(fp); // avoid zombies, jw@suse.de (#88501)
445 kbdfile_context_free(kbdfile_ctx);
446439
447440 bytewidth = (width + 7) / 8;
448441 height = fontbuflth / (bytewidth * fontsize);
484477 loadnewfont(int fd, char *ifil, int iunit, int hwunit, int no_m, int no_u)
485478 {
486479 struct kbdfile *fp;
487 struct kbdfile_ctx *kbdfile_ctx;
488480
489481 char defname[20];
490482 int height, width, bytewidth, def = 0;
492484 int inputlth, fontbuflth, fontsize, offset;
493485 struct unicode_list *uclistheads;
494486
495
496 if ((kbdfile_ctx = kbdfile_context_new()) == NULL)
497 nomem();
498
499 if ((fp = kbdfile_new(kbdfile_ctx)) == NULL)
487 if ((fp = kbdfile_new(NULL)) == NULL)
500488 nomem();
501489
502490 if (!*ifil) {
540528 &width, &fontsize, 0,
541529 no_u ? NULL : &uclistheads) == 0) {
542530 kbdfile_free(fp);
543 kbdfile_context_free(kbdfile_ctx);
544531
545532 /* we've got a psf font */
546533 bytewidth = (width + 7) / 8;
557544 return;
558545 }
559546 kbdfile_free(fp); // avoid zombies, jw@suse.de (#88501)
560 kbdfile_context_free(kbdfile_ctx);
561547
562548 /* instructions to combine fonts? */
563549 {
88 int
99 main(void)
1010 {
11 struct kbdfile_ctx *ctx = kbdfile_context_new();
12 if (!ctx)
13 error(EXIT_FAILURE, 0, "unable to create context");
14
15 struct kbdfile *fp = kbdfile_new(ctx);
11 struct kbdfile *fp = kbdfile_new(NULL);
1612 if (!fp)
1713 error(EXIT_FAILURE, 0, "unable to create kbdfile");
18
1914 kbdfile_free(fp);
20 kbdfile_context_free(ctx);
21
2215 return EXIT_SUCCESS;
2316 }
88 int
99 main(void)
1010 {
11 struct kbdfile_ctx *ctx = kbdfile_context_new();
12 if (!ctx)
13 error(EXIT_FAILURE, 0, "unable to create context");
14
15 struct kbdfile *fp = kbdfile_new(ctx);
11 struct kbdfile *fp = kbdfile_new(NULL);
1612 if (!fp)
1713 error(EXIT_FAILURE, 0, "unable to create kbdfile");
1814
3228 error(EXIT_FAILURE, 0, "unexpected file: %s (expected %s)", kbdfile_get_pathname(fp), expect);
3329
3430 kbdfile_free(fp);
35 kbdfile_context_free(ctx);
3631
3732 return EXIT_SUCCESS;
3833 }
88 int
99 main(void)
1010 {
11 struct kbdfile_ctx *ctx = kbdfile_context_new();
12 if (!ctx)
13 error(EXIT_FAILURE, 0, "unable to create context");
14
15 struct kbdfile *fp = kbdfile_new(ctx);
11 struct kbdfile *fp = kbdfile_new(NULL);
1612 if (!fp)
1713 error(EXIT_FAILURE, 0, "unable to create kbdfile");
1814
3026 error(EXIT_FAILURE, 0, "unexpected file: %s (expected %s)", kbdfile_get_pathname(fp), expect);
3127
3228 kbdfile_free(fp);
33 kbdfile_context_free(ctx);
3429
3530 return EXIT_SUCCESS;
3631 }
88 int
99 main(void)
1010 {
11 struct kbdfile_ctx *ctx = kbdfile_context_new();
12 if (!ctx)
13 error(EXIT_FAILURE, 0, "unable to create context");
14
15 struct kbdfile *fp = kbdfile_new(ctx);
11 struct kbdfile *fp = kbdfile_new(NULL);
1612 if (!fp)
1713 error(EXIT_FAILURE, 0, "unable to create kbdfile");
1814
2925 error(EXIT_FAILURE, 0, "unexpected file: %s (expected %s)", kbdfile_get_pathname(fp), expect);
3026
3127 kbdfile_free(fp);
32 kbdfile_context_free(ctx);
3328
3429 return EXIT_SUCCESS;
3530 }
88 int
99 main(void)
1010 {
11 struct kbdfile_ctx *ctx = kbdfile_context_new();
12 if (!ctx)
13 error(EXIT_FAILURE, 0, "unable to create context");
14
15 struct kbdfile *fp = kbdfile_new(ctx);
11 struct kbdfile *fp = kbdfile_new(NULL);
1612 if (!fp)
1713 error(EXIT_FAILURE, 0, "unable to create kbdfile");
1814
3026 error(EXIT_FAILURE, 0, "unexpected file: %s (expected %s)", kbdfile_get_pathname(fp), expect);
3127
3228 kbdfile_free(fp);
33 kbdfile_context_free(ctx);
3429
3530 return EXIT_SUCCESS;
3631 }
88 int
99 main(void)
1010 {
11 struct kbdfile_ctx *ctx = kbdfile_context_new();
12 if (!ctx)
13 error(EXIT_FAILURE, 0, "unable to create context");
14
15 struct kbdfile *fp = kbdfile_new(ctx);
11 struct kbdfile *fp = kbdfile_new(NULL);
1612 if (!fp)
1713 error(EXIT_FAILURE, 0, "unable to create kbdfile");
1814
3026 error(EXIT_FAILURE, 0, "unexpected file: %s (expected %s)", kbdfile_get_pathname(fp), expect);
3127
3228 kbdfile_free(fp);
33 kbdfile_context_free(ctx);
3429
3530 return EXIT_SUCCESS;
3631 }
88 int
99 main(void)
1010 {
11 struct kbdfile_ctx *ctx = kbdfile_context_new();
12 if (!ctx)
13 error(EXIT_FAILURE, 0, "unable to create context");
14
15 struct kbdfile *fp = kbdfile_new(ctx);
11 struct kbdfile *fp = kbdfile_new(NULL);
1612 if (!fp)
1713 error(EXIT_FAILURE, 0, "unable to create kbdfile");
1814
3026 error(EXIT_FAILURE, 0, "unexpected file: %s (expected %s)", kbdfile_get_pathname(fp), expect);
3127
3228 kbdfile_free(fp);
33 kbdfile_context_free(ctx);
3429
3530 return EXIT_SUCCESS;
3631 }
88 int
99 main(void)
1010 {
11 struct kbdfile_ctx *ctx = kbdfile_context_new();
12 if (!ctx)
13 error(EXIT_FAILURE, 0, "unable to create context");
14
15 struct kbdfile *fp = kbdfile_new(ctx);
11 struct kbdfile *fp = kbdfile_new(NULL);
1612 if (!fp)
1713 error(EXIT_FAILURE, 0, "unable to create kbdfile");
1814
3228 error(EXIT_FAILURE, 0, "unexpected file: %s (expected %s)", kbdfile_get_pathname(fp), expect);
3329
3430 kbdfile_free(fp);
35 kbdfile_context_free(ctx);
3631
3732 return EXIT_SUCCESS;
3833 }
88 int
99 main(void)
1010 {
11 struct kbdfile_ctx *ctx = kbdfile_context_new();
12 if (!ctx)
13 error(EXIT_FAILURE, 0, "unable to create context");
14
15 struct kbdfile *fp = kbdfile_open(ctx, DATADIR "/findfile/test_0/keymaps/i386/qwerty/test0.map");
11 struct kbdfile *fp = kbdfile_open(NULL, DATADIR "/findfile/test_0/keymaps/i386/qwerty/test0.map");
1612 if (!fp)
1713 error(EXIT_FAILURE, 0, "unable to create kbdfile");
1814
2117 error(EXIT_FAILURE, 0, "unexpected file: %s (expected %s)", kbdfile_get_pathname(fp), expect);
2218
2319 kbdfile_free(fp);
24 kbdfile_context_free(ctx);
2520
2621 return EXIT_SUCCESS;
2722 }
88 int
99 main(void)
1010 {
11 struct kbdfile_ctx *ctx = kbdfile_context_new();
12 if (!ctx)
13 error(EXIT_FAILURE, 0, "unable to create context");
14
15 struct kbdfile *fp = kbdfile_open(ctx, DATADIR "/findfile/test_0/keymaps/i386/qwerty/test0");
11 struct kbdfile *fp = kbdfile_open(NULL, DATADIR "/findfile/test_0/keymaps/i386/qwerty/test0");
1612 if (fp)
1713 error(EXIT_FAILURE, 0, "unexpected kbdfile");
1814
1915 kbdfile_free(fp);
20 kbdfile_context_free(ctx);
2116
2217 return EXIT_SUCCESS;
2318 }
88 int
99 main(void)
1010 {
11 struct kbdfile_ctx *ctx = kbdfile_context_new();
12 if (!ctx)
13 error(EXIT_FAILURE, 0, "unable to create context");
14
15 struct kbdfile *fp = kbdfile_new(ctx);
11 struct kbdfile *fp = kbdfile_new(NULL);
1612 if (!fp)
1713 error(EXIT_FAILURE, 0, "unable to create kbdfile");
1814
3228 error(EXIT_FAILURE, 0, "unexpected file: %s (expected %s)", kbdfile_get_pathname(fp), expect);
3329
3430 kbdfile_free(fp);
35 kbdfile_context_free(ctx);
3631
3732 return EXIT_SUCCESS;
3833 }
88 int
99 main(void)
1010 {
11 struct kbdfile_ctx *ctx = kbdfile_context_new();
12 if (!ctx)
13 error(EXIT_FAILURE, 0, "unable to create context");
14
15 struct kbdfile *fp = kbdfile_new(ctx);
11 struct kbdfile *fp = kbdfile_new(NULL);
1612 if (!fp)
1713 error(EXIT_FAILURE, 0, "unable to create kbdfile");
1814
3228 error(EXIT_FAILURE, 0, "unexpected file: %s (expected %s)", kbdfile_get_pathname(fp), expect);
3329
3430 kbdfile_free(fp);
35 kbdfile_context_free(ctx);
3631
3732 return EXIT_SUCCESS;
3833 }