Commit 1af08a00 authored by Niels Möller's avatar Niels Möller
Browse files

Changed definition of %A. Added modifier f, %fS to free the string

after it is copied.

Rev: src/format.c:1.8
Rev: src/format.h:1.8
parent 68008aed
......@@ -43,6 +43,9 @@ UINT32 ssh_vformat_length(char *f, va_list args)
literal = 1;
f++;
}
if (*f == 'f')
f++;
switch(*f)
{
default:
......@@ -110,8 +113,24 @@ UINT32 ssh_vformat_length(char *f, va_list args)
if (!literal)
length += 4;
f++;
break;
}
break;
case 'A':
{
int *atom = va_arg(args, int *);
while (*atom > 0)
length += get_atom_length(atom++) + 1;
/* One ','-character less than the number of atoms */
length--;
if (!literal)
length += 4;
f++;
break;
}
#if 0
case 'A':
{
int atom;
......@@ -125,8 +144,9 @@ UINT32 ssh_vformat_length(char *f, va_list args)
if (!literal)
length += 4;
f++;
break;
}
break;
#endif
case 'n':
{
bignum *n = va_arg(args, bignum *);
......@@ -157,12 +177,18 @@ void ssh_vformat(char *f, UINT8 *buffer, va_list args)
if (*f == '%')
{
int literal = 0;
int do_free = 0;
f++;
if (*f == 'l')
{
literal = 1;
f++;
}
if (*f == 'f')
{
do_free = 1;
f++;
}
switch(*f)
{
default:
......@@ -214,6 +240,9 @@ void ssh_vformat(char *f, UINT8 *buffer, va_list args)
memcpy(buffer, s->data, s->length);
buffer += s->length;
if (do_free)
lsh_string_free(s);
f++;
break;
}
......@@ -299,8 +328,43 @@ void ssh_vformat(char *f, UINT8 *buffer, va_list args)
WRITE_UINT32(start, total);
}
f++;
break;
}
break;
#if 0
case 'A':
{
int *atom = va_arg(args, int *);
UINT8 *start = buffer; /* Where to store the length */
if (!literal)
buffer += 4;
if (*atom > 0)
{
UINT32 length = get_atom_length(*atom);
memcpy(buffer, get_atom_name(*atom), length);
buffer += length;
atom ++;
while (*atom > 0)
{
*buffer++ = ',';
length = get_atom_length(atom);
memcpy(buffer, get_atom_name(atom), length);
buffer += length;
atom++;
}
}
if (!literal)
{
UINT32 total = buffer - start - 4;
WRITE_UINT32(start, total);
}
f++;
break;
}
#endif
case 'n':
{
bignum *n = va_arg(args, bignum *);
......
......@@ -31,14 +31,21 @@
* %a Insert a string containing one atom.
*
* %A Insert a string containing a list of atoms. The corresponding
* argument sublist should be terminated with a zero.
* argument sublist should be a int* pointing to a list of atoms,
* terminated with -1.
*
* %X Insert a string containing a list of atoms. The corresponding
* argument sublist should be terminated with a zero. (Not used)
*
* %n Insert a string containing a bignum.
*
* There is one valid modifier:
* There are two valid modifiers:
*
* "l" (as in literal). It is applicable to the s, a, A, n and r
* specifiers, and outputs strings *without* a length field. */
* specifiers, and outputs strings *without* a length field.
*
* "f" (as in free). Frees the input sting after it has been copied.
* Applicable to %S only. */
UINT32 ssh_vformat_length(char *format, va_list args);
void ssh_vformat(char *format, UINT8 *buffer, va_list args);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment