comparison pwm.c @ 29:00d782cb45fa

Read configuration file on startup
author Guido Berhoerster <guido+pwm@berhoerster.name>
date Thu, 28 Sep 2017 10:06:59 +0200
parents e3db02d7f1f4
children 2552eec9b913
comparison
equal deleted inserted replaced
28:e3db02d7f1f4 29:00d782cb45fa
42 #include "pwm.h" 42 #include "pwm.h"
43 #include "cmd.h" 43 #include "cmd.h"
44 #include "io.h" 44 #include "io.h"
45 #include "macro.h" 45 #include "macro.h"
46 #include "pwfile.h" 46 #include "pwfile.h"
47 #include "pwmrc.h"
47 #include "tok.h" 48 #include "tok.h"
48 #include "util.h" 49 #include "util.h"
49 50
50 static void 51 static void
51 usage(void) 52 usage(void)
363 goto out; 364 goto out;
364 } 365 }
365 366
366 ctx.is_interactive = isatty(STDIN_FILENO); 367 ctx.is_interactive = isatty(STDIN_FILENO);
367 368
369 macro_init(&ctx.macro_head);
370
368 while (!errflag && (c = getopt(argc, argv, "P:Rh")) != -1) { 371 while (!errflag && (c = getopt(argc, argv, "P:Rh")) != -1) {
369 switch (c) { 372 switch (c) {
370 case 'P': 373 case 'P':
371 master_password_filename = optarg; 374 master_password_filename = optarg;
372 break; 375 break;
415 fprintf(stderr, "master password file must be specified when " 418 fprintf(stderr, "master password file must be specified when "
416 "running non-interactively\n"); 419 "running non-interactively\n");
417 goto out; 420 goto out;
418 } 421 }
419 422
423 /* read ~/.pwm/pwmrc */
424 if (pwmrc_read(&ctx) != 0) {
425 goto out;
426 }
427
420 pwfile_init(&ctx); 428 pwfile_init(&ctx);
421 macro_init(&ctx.macro_head);
422
423 fp = fopen(ctx.filename, "r"); 429 fp = fopen(ctx.filename, "r");
424 if ((fp == NULL) && (errno != ENOENT)) { 430 if ((fp == NULL) && (errno != ENOENT)) {
425 warn("failed to open password database"); 431 warn("failed to open password database");
426 goto out; 432 goto out;
427 } 433 }