var-expand.c revision 1036d2db2b718bdc5b10f0773dd01d62638e9ba9
/* Copyright (C) 2003-2004 Timo Sirainen */
#include "lib.h"
#include "md5.h"
#include "hash.h"
#include "hex-binary.h"
#include "str.h"
#include "strescape.h"
#include "var-expand.h"
#include <stdlib.h>
struct var_expand_context {
};
struct var_expand_modifier {
char key;
const char *(*func)(const char *, struct var_expand_context *);
};
static const char *
{
return t_str_lcase(str);
}
static const char *
{
return t_str_ucase(str);
}
static const char *
{
return str_escape(str);
}
static const char *
{
unsigned long long l;
return t_strdup_printf("%llx", l);
}
static const char *
{
char *p, *rev;
*p-- = *str;
return rev;
}
{
}
}
{
unsigned char digest[16];
}
#define MAX_MODIFIER_COUNT 10
static const struct var_expand_modifier modifiers[] = {
{ 'L', m_str_lcase },
{ 'U', m_str_ucase },
{ 'E', m_str_escape },
{ 'X', m_str_hex },
{ 'R', m_str_reverse },
{ 'H', m_str_hash },
{ 'M', m_str_md5 },
{ '\0', NULL }
};
const struct var_expand_table *table)
{
const struct var_expand_modifier *m;
const struct var_expand_table *t;
const char *var;
struct var_expand_context ctx;
const char *(*modifier[MAX_MODIFIER_COUNT])
(const char *, struct var_expand_context *);
unsigned int i, modifier_count;
bool zero_padding = FALSE;
if (*str != '%')
else {
str++;
/* [<offset>.]<width>[<modifiers>]<variable> */
if (*str == '0') {
zero_padding = TRUE;
str++;
}
str++;
}
if (*str != '.')
else {
str++;
str++;
}
}
modifier_count = 0;
while (modifier_count < MAX_MODIFIER_COUNT) {
/* @UNSAFE */
m->func;
str++;
break;
}
}
break;
}
if (*str == '\0')
break;
break;
}
}
/* not found */
if (*str == '%')
var = "%";
}
for (i = 0; i < modifier_count; i++)
var++;
}
else if (!zero_padding)
else {
/* %05d -like padding */
}
}
}
}
}
}
char var_get_key(const char *str)
{
const struct var_expand_modifier *m;
/* [<offset>.]<width>[<modifiers>]<variable> */
str++;
if (*str == '.') {
str++;
str++;
}
do {
str++;
break;
}
}
} while (m->key != '\0');
return *str;
}