92 #define STR(x) vstring_str(x)
103 if (*cp ==
'#' || *cp == 0) {
120 if ((cp = pcf_find_cf_info(buf, dst)) != 0)
128 static void pcf_gobble_cf_line(
VSTRING *full_entry_buf,
VSTRING *line_buf,
137 if ((ch !=
'#' && !
ISSPACE(ch))
141 if (pcf_find_cf_info(line_buf, dst))
164 struct cvalue *cvalue;
174 while ((cp = *argv++) != 0) {
175 if (strchr(cp,
'\n') != 0)
176 msg_fatal(
"-e, -X, or -# accepts no multi-line input");
180 msg_fatal(
"-e, -X, or -# accepts no comment input");
186 msg_fatal(
"-X or -# requires non-blank parameter names");
187 if (strchr(cp,
'=') != 0)
188 msg_fatal(
"-X or -# requires parameter names without value");
193 msg_panic(
"pcf_edit_main: unknown mode %d", mode);
195 cvalue = (
struct cvalue *)
mymalloc(
sizeof(*cvalue));
196 cvalue->value = edit_value;
217 msg_fatal(
"open %s for reading: %m", path);
224 #define STR(x) vstring_str(x)
227 while ((cp = pcf_next_cf_line(buf, src, dst, (
int *) 0)) != 0) {
230 if (interesting == 0)
239 if ((interesting = !!cvalue) != 0) {
240 if (cvalue->found++ == 1)
241 msg_warn(
"%s: multiple entries for \"%s\"", path,
STR(key));
256 for (ht_info = ht =
htable_list(table); *ht; ht++) {
257 cvalue = (
struct cvalue *) ht[0]->value;
258 if (cvalue->found == 0)
298 const char *myname =
"pcf_edit_master";
310 int service_name_type_matched;
315 const char *edit_opts =
"-Me, -Fe, -Pe, -X, or -#";
323 msg_panic(
"%s: empty argument list", myname);
329 for (req = edit_reqs; *argv != 0; req++, argv++) {
333 if (strchr(cp,
'\n') != 0)
334 msg_fatal(
"%s accept no multi-line input", edit_opts);
338 msg_fatal(
"%s accept no comment input", edit_opts);
346 msg_fatal(
"whitespace in parameter value: \"%s\"",
350 if (strchr(cp,
'=') != 0)
351 msg_fatal(
"-X or -# requires names without value");
356 msg_panic(
"%s: unknown mode %d", myname, mode);
359 #define PCF_MASTER_MASK (PCF_MASTER_ENTRY | PCF_MASTER_FLD | PCF_MASTER_PARAM)
368 msg_fatal(
"-Me, -MX or -M# requires service_name/type");
373 msg_fatal(
"-Fe or -FX requires service_name/type/field_name");
377 msg_fatal(
"-Fe does not accept wild-card field name");
378 if ((mode & PCF_EDIT_CONF)
381 msg_fatal(
"-Fe does not accept whitespace in non-command field");
386 msg_fatal(
"-Pe or -PX requires service_name/type/parameter");
389 msg_fatal(
"-Pe does not accept wild-card parameter name");
390 if ((mode & PCF_EDIT_CONF)
392 msg_fatal(
"-Pe does not accept whitespace in parameter value");
395 msg_panic(
"%s: unknown edit mode %d", myname, mode);
415 msg_fatal(
"open %s for reading: %m", path);
422 service_name_type_matched = 0;
425 while ((cp = pcf_next_cf_line(parse_buf, src, dst, &lineno)) != 0) {
431 if (cp >
STR(parse_buf)) {
432 if (service_name_type_matched == 0)
442 service_name_type_matched = 0;
449 msg_fatal(
"file %s: line %d: specify service name and type "
450 "on the same line", path, lineno);
451 if (strchr(service_name,
'='))
452 msg_fatal(
"file %s: line %d: service name syntax \"%s\" is "
453 "unsupported with %s", path, lineno, service_name,
455 if (service_type[strcspn(service_type,
"=/")] != 0)
457 "service type syntax \"%s\" is unsupported with %s",
458 path, lineno, service_type, edit_opts);
463 for (req = edit_reqs; req < edit_reqs + num_reqs; req++) {
467 service_name_type_matched = 1;
482 case PCF_MASTER_PARAM:
483 if (new_entry == 0) {
485 pcf_gobble_cf_line(full_entry_buf, line_buf,
490 STR(full_entry_buf))) != 0)
518 msg_panic(
"%s: unknown edit mode %d", myname, mode);
531 }
else if (service_name_type_matched == 0) {
544 for (req = edit_reqs; req < edit_reqs + num_reqs; req++) {
552 }
else if ((mode & PCF_MASTER_ENTRY) == 0) {
573 for (req = edit_reqs; req < edit_reqs + num_reqs; req++) {
577 myfree((
void *) edit_reqs);
void htable_free(HTABLE *table, void(*free_fn)(void *))
char * mystrdup(const char *str)
void pcf_edit_master_field(PCF_MASTER_ENT *, int, const char *)
ARGV * argv_free(ARGV *argvp)
NORETURN msg_panic(const char *fmt,...)
ARGV * pcf_parse_service_pattern(const char *, int, int)
void pcf_edit_master(int mode, int argc, char **argv)
int vstring_get(VSTRING *vp, VSTREAM *fp)
const char * param_pattern
char * mystrtok(char **src, const char *sep)
const char * split_nameval(char *buf, char **name, char **value)
VSTRING * vstring_strcpy(VSTRING *vp, const char *src)
void pcf_print_master_entry(VSTREAM *, int, PCF_MASTER_ENT *)
VSTREAM * vstream_fopen(const char *path, int flags, mode_t mode)
void pcf_free_master_entry(PCF_MASTER_ENT *)
HTABLE * htable_create(ssize_t size)
HTABLE_INFO ** htable_list(HTABLE *table)
#define PCF_MATCH_SERVICE_PATTERN(pat, name, type)
#define PCF_IS_MAGIC_PARAM_PATTERN(pat)
VSTREAM * vstream_fprintf(VSTREAM *stream, const char *fmt,...)
#define PCF_MASTER_FLD_CMD
#define vstream_ungetc(vp, ch)
int vstream_fclose(VSTREAM *stream)
void msg_warn(const char *fmt,...)
VSTRING * vstring_alloc(ssize_t len)
void * htable_find(HTABLE *table, const char *key)
void pcf_edit_main(int mode, int argc, char **argv)
int pcf_parse_field_pattern(const char *)
int edit_file_close(EDIT_FILE *ep)
char * trimblanks(char *, ssize_t)
NORETURN msg_fatal(const char *fmt,...)
char * concatenate(const char *arg0,...)
#define pcf_is_magic_field_pattern(pat)
VSTRING * vstring_free(VSTRING *vp)
void pcf_set_config_dir(void)
void pcf_edit_master_param(PCF_MASTER_ENT *, int, const char *, const char *)
const char * pcf_parse_master_entry(PCF_MASTER_ENT *, const char *)
VSTRING * vstring_strncpy(VSTRING *vp, const char *src, ssize_t len)
VSTRING * vstring_strcat(VSTRING *vp, const char *src)
EDIT_FILE * edit_file_open(const char *path, int flags, mode_t mode)
#define PCF_MASTER_BLANKS
void * mymalloc(ssize_t len)
int vstream_fputs(const char *str, VSTREAM *stream)
HTABLE_INFO * htable_enter(HTABLE *table, const char *key, void *value)