{
if (regexec (&rule->rx, line, 0, NULL, 0) == 0)
{
+ if (rule->atime != (time_t) -1)
+ time (&rule->atime);
+
rxpd_buffer_printf (&self->out, "%s\n", rule->string);
break;
}
LLIST_FOREACH (&self->file->rules, n)
{
struct rxpd_rule* rule = (struct rxpd_rule*)n;
- rxpd_buffer_printf (&self->out, "%s\n", rule->string);
+ if (rule->atime != (time_t)-1)
+ rxpd_buffer_printf (&self->out, "%ld:%s\n", rule->atime, rule->string);
+ else if (*rule->string != '#')
+ rxpd_buffer_printf (&self->out, ":%s\n", rule->string);
+ else
+ rxpd_buffer_printf (&self->out, "%s\n", rule->string);
}
}
LLIST_FOREACH (&self->rules, n)
{
struct rxpd_rule* node = (struct rxpd_rule*)n;
- fprintf (f, "%s\n", node->string);
+ if (node->atime != (time_t)-1)
+ fprintf (f, "%ld:%s\n", node->atime, node->string);
+ else if (*node->string != '#')
+ fprintf (f, ":%s\n", node->string);
+ else
+ fprintf (f, "%s\n", node->string);
}
fclose (f);
if (*buf != '#')
{
int err;
- char* rxstart = strchr (buf, ':');
+ char* namestart = strchr (buf, ':');
+ char* rxstart = namestart? strchr (namestart+1, ':') : NULL;
if (!rxstart)
self->string = rxpd_strdup ("#ERROR: Syntax error, line was neither a comment nor a rule");
else
{
+ if (namestart == buf)
+ /* No atime given */
+ self->atime = (time_t)-1;
+ else
+ {
+ /* atime given */
+ self->atime = atoi (buf);
+ if (!self->atime)
+ /* atime was zero or not set */
+ self->atime = time (NULL)-1;
+ }
+
// TODO regflags from base
err = regcomp (&self->rx, rxstart+1, REG_EXTENDED|REG_ICASE|REG_NOSUB);
if (!err)
- self->string = rxpd_strdup (buf);
+ self->string = rxpd_strdup (namestart+1);
else
{
regfree (&self->rx);
char ebuf[256];
size_t len = regerror (err, NULL, ebuf, 256);
- self->string = rxpd_malloc (len + strlen(buf) + 14);
+ self->string = rxpd_malloc (len + strlen(namestart+1) + 14);
strcpy (self->string, "#ERROR: ");
strcat (self->string, ebuf);
strcat (self->string, " in '");
- strcat (self->string, buf);
+ strcat (self->string, namestart+1);
strcat (self->string, "'");
}
}
}
else
- self->string = rxpd_strdup (buf);
+ {
+ self->atime = (time_t)-1;
+ self->string = rxpd_strdup (buf);
+ }
return self;
}