double *list;
};
-static struct sub_sect_1 sec1 = { {}, "Charlie", "WBAFC", { 0, -1}, DYN_ALLOC(double, 3, 1e4, -1e-4, 8) };
+static struct sub_sect_1 sec1 = { {}, "Charlie", "WBAFC", { 0, -1}, DARY_ALLOC(double, 3, 1e4, -1e-4, 8) };
static byte *
init_sec_1(struct sub_sect_1 *s)
{
if (s == &sec1) { // this is a static variable; skip clearing
- DYN_LEN(sec1.list) = 3; // XXX: fix for the bug in DYN_ALLOC()
+ DARY_LEN(sec1.list) = 3; // XXX: fix for the bug in DARY_ALLOC()
return NULL;
}
s->name = "unknown";
};
static uns nr1 = 15;
-static int *nrs1 = DYN_ALLOC(int, 5, 5, 4, 3, 2, 1);
+static int *nrs1 = DARY_ALLOC(int, 5, 5, 4, 3, 2, 1);
static int nrs2[5];
static byte *str1 = "no worries";
-static byte **str2 = DYN_ALLOC(byte *, 2, "Alice", "Bob");
+static byte **str2 = DARY_ALLOC(byte *, 2, "Alice", "Bob");
static u64 u1 = 0xCafeBeefDeadC00ll;
static double d1 = -1.1;
static struct clist secs;
\n\
Options:\n"
CF_USAGE
-"-v\t\tBe verbose\n\
+"-v\t\t\tBe verbose\n\
";
static void NONRET
journal_new_section(uns new_pool)
{
if (new_pool)
- cf_pool = mp_new(1<<14);
+ cf_pool = mp_new(1<<10);
struct journal_item *oldj = journal;
journal = NULL;
return oldj;
}
static byte *
-interpret_add_dynamic(struct cf_item *item, int number, byte **pars, int *processed, void **ptr, enum operation op)
+interpret_add_dynamic(struct cf_item *item, int number, byte **pars, int *processed, void **ptr, enum cf_operation op)
{
enum cf_type type = item->u.type;
void *old_p = *ptr;
}
static void
-add_to_list(struct cnode *where, struct cnode *new_node, enum operation op)
+add_to_list(struct cnode *where, struct cnode *new_node, enum cf_operation op)
{
switch (op)
{
}
static byte *
-interpret_add_list(struct cf_item *item, int number, byte **pars, int *processed, void *ptr, enum operation op)
+interpret_add_list(struct cf_item *item, int number, byte **pars, int *processed, void *ptr, enum cf_operation op)
{
if (op >= OP_REMOVE)
return cf_printf("You have to open a block for operation %s", op_names[op]);
static struct item_stack {
struct cf_section *sec; // nested section
void *base_ptr; // because original pointers are often relative
- enum operation op; // it is performed when a closing brace is encountered
+ enum cf_operation op; // it is performed when a closing brace is encountered
void *list; // list the operations should be done on
u32 mask; // bit array of selectors searching in a list
struct cf_item *item; // cf_item of the list
static uns level;
static byte *
-opening_brace(struct cf_item *item, void *ptr, enum operation op)
+opening_brace(struct cf_item *item, void *ptr, enum cf_operation op)
{
if (level >= MAX_STACK_SIZE-1)
return "Too many nested sections";
}
static byte *
-closing_brace(struct item_stack *st, enum operation op, int number, byte **pars)
+closing_brace(struct item_stack *st, enum cf_operation op, int number, byte **pars)
{
if (st->op == OP_CLOSE) // top-level
- return "Unmatched } parenthese";
+ return "Unmatched } parenthesis";
if (!st->sec) { // dummy run on unknown section
if (!(op & OP_OPEN))
level--;
return NULL;
}
- enum operation pure_op = st->op & OP_MASK;
+ enum cf_operation pure_op = st->op & OP_MASK;
if (st->op & OP_1ST)
{
st->list = find_list_node(st->list, st->base_ptr, st->sec, st->mask);
}
static byte *
-interpret_line(byte *name, enum operation op, int number, byte **pars)
+interpret_line(byte *name, enum cf_operation op, int number, byte **pars)
{
byte *msg;
if ((op & OP_MASK) == OP_CLOSE)
else if (item->cls == CC_LIST)
msg = interpret_add_list(item, number, pars, &taken, ptr, op);
else
- return cf_printf("Operation %s not supported on attribute class %d", op_names[op], item->cls);
+ return cf_printf("Operation %s not supported on attribute %s", op_names[op], name);
if (msg)
return msg;
if (taken < number)
}
byte *
-cf_write_item(struct cf_item *item, enum operation op, int number, byte **pars)
+cf_write_item(struct cf_item *item, enum cf_operation op, int number, byte **pars)
{
byte *msg;
int taken;
/* Text file parser */
+static byte *name_parse_fb;
static struct fastbuf *parse_fb;
static uns line_num;
return NULL;
}
if (!*line || *line == '#')
- log(L_WARN, "The line following the backslash is empty");
+ log(L_WARN, "The line %s:%d following a backslash is empty", name_parse_fb, line_num);
} else {
split_grow(&word_buf, words+1);
uns start = copied;
parse_fastbuf(byte *name_fb, struct fastbuf *fb, uns depth)
{
byte *msg;
+ name_parse_fb = name_fb;
parse_fb = fb;
line_num = 0;
line = line_buf;
line_num = ll;
parse_fb = fb;
}
- enum operation op;
+ enum cf_operation op;
byte *c = strchr(name, ':');
if (!c)
op = strcmp(name, "}") ? OP_SET : OP_CLOSE;
struct cf_section {
uns size; // 0 for a global block, sizeof(struct) for a section
- cf_hook *init; // fills in default values (otherwise 0's are used)
+ cf_hook *init; // fills in default values (no need to bzero)
cf_hook *commit; // verifies parsed data (optional)
struct cf_item *cfg; // CC_END-terminated array of items
uns flags; // for internal use only
#define CF_STRING_ARY(n,p,c) CF_STATIC(n,p,STRING,byte*,c)
#define CF_STRING_DYN(n,p,c) CF_DYNAMIC(n,p,STRING,byte*,c)
-#define DYN_LEN(a) *(uns*)(a-1)
+#define DARY_LEN(a) *(uns*)(a-1)
// length of a dynamic array
-#define DYN_ALLOC(type,len,val...) (type[]) { (type)len, ##val } + 1
+#define DARY_ALLOC(type,len,val...) (type[]) { (type)len, ##val } + 1
// creates a static instance of a dynamic array
// FIXME: overcast doesn't work for the double type
* Sections can be used with SET.
* Lists can be used with everything. */
#define T(x) OP_##x,
-enum operation { CF_OPERATIONS };
+enum cf_operation { CF_OPERATIONS };
#undef T
struct fastbuf;
byte *cf_find_item(byte *name, struct cf_item *item);
-byte *cf_write_item(struct cf_item *item, enum operation op, int number, byte **pars);
+byte *cf_write_item(struct cf_item *item, enum cf_operation op, int number, byte **pars);
void cf_dump_sections(struct fastbuf *fb);
/*
* override it manually before calling cf_get_opt().
*/
-#define CF_SHORT_OPTS "S:C:"
-#define CF_LONG_OPTS {"set", 1, 0, 'S'}, {"config", 1, 0, 'C'},
+#define CF_SHORT_OPTS "C:S:"
+#define CF_LONG_OPTS {"config", 1, 0, 'C'}, {"set", 1, 0, 'S'},
#define CF_NO_LONG_OPTS (const struct option []) { CF_LONG_OPTS { NULL, 0, 0, 0 } }
#ifndef CF_USAGE_TAB
#define CF_USAGE_TAB ""
#endif
#define CF_USAGE \
-"-S, --set sec.item=val\t" CF_USAGE_TAB "Manual setting of a configuration item\n\
--C, --config filename\t" CF_USAGE_TAB "Overwrite default configuration file\n"
+"-C, --config filename\t" CF_USAGE_TAB "Override the default configuration file\n\
+-S, --set sec.item=val\t" CF_USAGE_TAB "Manual setting of a configuration item\n"
struct option;
int cf_get_opt(int argc, char * const argv[], const char *short_opts, const struct option *long_opts, int *long_index);
the best' "\
" qu'est-ce que c'est?
u1 0xbadcafebadbeefc0
+ str2:prepend prepended
+ str2:append appended
d1 7%
d1 -1.14e-25
firsttime ; secondtime 56