|
|
@ -531,19 +531,21 @@ cur_user( void ) |
|
|
|
|
|
|
|
|
|
|
|
/* Return value: 0 = ok, -1 = out found in arg, -2 = in found in arg but no out specified */ |
|
|
|
/* Return value: 0 = ok, -1 = out found in arg, -2 = in found in arg but no out specified */ |
|
|
|
int |
|
|
|
int |
|
|
|
map_name( const char *arg, char **result, uint reserve, const char *in, const char *out ) |
|
|
|
map_name( const char *arg, int l, char **result, uint reserve, const char *in, const char *out ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
char *p; |
|
|
|
char *p; |
|
|
|
uint i, l, ll, num, inl, outl; |
|
|
|
int i, ll, num, inl, outl; |
|
|
|
|
|
|
|
|
|
|
|
assert( arg ); |
|
|
|
assert( arg ); |
|
|
|
|
|
|
|
if (l < 0) |
|
|
|
l = strlen( arg ); |
|
|
|
l = strlen( arg ); |
|
|
|
assert( in ); |
|
|
|
assert( in ); |
|
|
|
inl = strlen( in ); |
|
|
|
inl = strlen( in ); |
|
|
|
if (!inl) { |
|
|
|
if (!inl) { |
|
|
|
copy: |
|
|
|
copy: |
|
|
|
*result = nfmalloc( reserve + l + 1 ); |
|
|
|
*result = nfmalloc( reserve + l + 1 ); |
|
|
|
memcpy( *result + reserve, arg, l + 1 ); |
|
|
|
memcpy( *result + reserve, arg, l ); |
|
|
|
|
|
|
|
(*result)[reserve + l] = 0; |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
assert( out ); |
|
|
|
assert( out ); |
|
|
@ -551,6 +553,8 @@ map_name( const char *arg, char **result, uint reserve, const char *in, const ch |
|
|
|
if (equals( in, (int)inl, out, outl )) |
|
|
|
if (equals( in, (int)inl, out, outl )) |
|
|
|
goto copy; |
|
|
|
goto copy; |
|
|
|
for (num = 0, i = 0; i < l; ) { |
|
|
|
for (num = 0, i = 0; i < l; ) { |
|
|
|
|
|
|
|
if (i + inl > l) |
|
|
|
|
|
|
|
goto fout; |
|
|
|
for (ll = 0; ll < inl; ll++) |
|
|
|
for (ll = 0; ll < inl; ll++) |
|
|
|
if (arg[i + ll] != in[ll]) |
|
|
|
if (arg[i + ll] != in[ll]) |
|
|
|
goto fout; |
|
|
|
goto fout; |
|
|
@ -559,6 +563,8 @@ map_name( const char *arg, char **result, uint reserve, const char *in, const ch |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
fout: |
|
|
|
fout: |
|
|
|
if (outl) { |
|
|
|
if (outl) { |
|
|
|
|
|
|
|
if (i + outl > l) |
|
|
|
|
|
|
|
goto fnexti; |
|
|
|
for (ll = 0; ll < outl; ll++) |
|
|
|
for (ll = 0; ll < outl; ll++) |
|
|
|
if (arg[i + ll] != out[ll]) |
|
|
|
if (arg[i + ll] != out[ll]) |
|
|
|
goto fnexti; |
|
|
|
goto fnexti; |
|
|
@ -574,6 +580,8 @@ map_name( const char *arg, char **result, uint reserve, const char *in, const ch |
|
|
|
*result = nfmalloc( reserve + l + num * (outl - inl) + 1 ); |
|
|
|
*result = nfmalloc( reserve + l + num * (outl - inl) + 1 ); |
|
|
|
p = *result + reserve; |
|
|
|
p = *result + reserve; |
|
|
|
for (i = 0; i < l; ) { |
|
|
|
for (i = 0; i < l; ) { |
|
|
|
|
|
|
|
if (i + inl > l) |
|
|
|
|
|
|
|
goto rnexti; |
|
|
|
for (ll = 0; ll < inl; ll++) |
|
|
|
for (ll = 0; ll < inl; ll++) |
|
|
|
if (arg[i + ll] != in[ll]) |
|
|
|
if (arg[i + ll] != in[ll]) |
|
|
|
goto rnexti; |
|
|
|
goto rnexti; |
|
|
|