/*++ /* NAME /* vstring 3 /* SUMMARY /* arbitrary-length string manager /* SYNOPSIS /* #include <vstring.h> /* /* VSTRING *vstring_alloc(len) /* ssize_t len; /* /* vstring_ctl(vp, type, value, ..., VSTRING_CTL_END) /* VSTRING *vp; /* int type; /* /* VSTRING *vstring_free(vp) /* VSTRING *vp; /* /* char *vstring_str(vp) /* VSTRING *vp; /* /* ssize_t VSTRING_LEN(vp) /* VSTRING *vp; /* /* char *vstring_end(vp) /* VSTRING *vp; /* /* void VSTRING_ADDCH(vp, ch) /* VSTRING *vp; /* int ch; /* /* int VSTRING_SPACE(vp, len) /* VSTRING *vp; /* ssize_t len; /* /* ssize_t vstring_avail(vp) /* VSTRING *vp; /* /* VSTRING *vstring_truncate(vp, len) /* VSTRING *vp; /* ssize_t len; /* /* VSTRING *vstring_set_payload_size(vp, len) /* VSTRING *vp; /* ssize_t len; /* /* void VSTRING_RESET(vp) /* VSTRING *vp; /* /* void VSTRING_TERMINATE(vp) /* VSTRING *vp; /* /* void VSTRING_SKIP(vp) /* VSTRING *vp; /* /* VSTRING *vstring_strcpy(vp, src) /* VSTRING *vp; /* const char *src; /* /* VSTRING *vstring_strncpy(vp, src, len) /* VSTRING *vp; /* const char *src; /* ssize_t len; /* /* VSTRING *vstring_strcat(vp, src) /* VSTRING *vp; /* const char *src; /* /* VSTRING *vstring_strncat(vp, src, len) /* VSTRING *vp; /* const char *src; /* ssize_t len; /* /* VSTRING *vstring_memcpy(vp, src, len) /* VSTRING *vp; /* const char *src; /* ssize_t len; /* /* VSTRING *vstring_memcat(vp, src, len) /* VSTRING *vp; /* const char *src; /* ssize_t len; /* /* char *vstring_memchr(vp, ch) /* VSTRING *vp; /* int ch; /* /* VSTRING *vstring_insert(vp, start, src, len) /* VSTRING *vp; /* ssize_t start; /* const char *src; /* ssize_t len; /* /* VSTRING *vstring_prepend(vp, src, len) /* VSTRING *vp; /* const char *src; /* ssize_t len; /* /* VSTRING *vstring_sprintf(vp, format, ...) /* VSTRING *vp; /* const char *format; /* /* VSTRING *vstring_sprintf_append(vp, format, ...) /* VSTRING *vp; /* const char *format; /* /* VSTRING *vstring_sprintf_prepend(vp, format, ...) /* VSTRING *vp; /* const char *format; /* /* VSTRING *vstring_vsprintf(vp, format, ap) /* VSTRING *vp; /* const char *format; /* va_list ap; /* /* VSTRING *vstring_vsprintf_append(vp, format, ap) /* VSTRING *vp; /* const char *format; /* va_list ap; /* AUXILIARY FUNCTIONS /* char *vstring_export(vp) /* VSTRING *vp; /* /* VSTRING *vstring_import(str) /* char *str; /* DESCRIPTION /* The functions and macros in this module implement arbitrary-length /* strings and common operations on those strings. The strings do not /* need to be null terminated and may contain arbitrary binary data. /* Operations that expect a null-terminated string as input will /* process only the input that precedes the first null byte. /* The strings manage their own memory and grow automatically when full. /* The optional string null terminator does not add to the string length. /* /* vstring_alloc() allocates storage for a variable-length string /* of at least "len" bytes. The minimal length is 1. The result /* is a null-terminated string of length zero. /* /* vstring_ctl() gives additional control over VSTRING behavior. /* The function takes a VSTRING pointer and a list of zero or /* more macros with zer or more arguments, terminated with /* CA_VSTRING_CTL_END which has none.A_VSTRING_CTL_END. /* .IP "CA_VSTRING_CTL_MAXLEN(ssize_t len)" /* Specifies a hard upper limit on a string's length. When the /* length would be exceeded, the program simulates a memory /* allocation problem (i.e. it terminates through msg_fatal()). /* This functionality is currently unimplemented. /* .IP "CA_VSTRING_CTL_EXACT (no argument)" /* Allocate the requested amounts, instead of rounding up. /* This should be used for tests only. /* .IP "CA_VSTRING_CTL_END (no argument)" /* Specifies the end of the argument list. Forgetting to terminate /* the argument list may cause the program to crash. /* .PP /* VSTRING_SPACE() ensures that the named string has room for /* "len" more characters. VSTRING_SPACE() is an unsafe macro /* that either returns zero or never returns. /* /* vstring_avail() returns the number of bytes that can be placed /* into the buffer before the buffer would need to grow. /* /* vstring_free() reclaims storage for a variable-length string. /* It conveniently returns a null pointer. /* /* vstring_str() is a macro that returns the string value /* of a variable-length string. It is a safe macro that /* evaluates its argument only once. /* /* VSTRING_LEN() is a macro that returns the current length of /* its argument (i.e. the distance from the start of the string /* to the current write position). VSTRING_LEN() is an unsafe macro /* that evaluates its argument more than once. /* /* vstring_end() is a macro that returns the current write position of /* its argument. It is a safe macro that evaluates its argument only once. /* /* VSTRING_ADDCH() adds a character to a variable-length string /* and extends the string if it fills up. \fIvs\fP is a pointer /* to a VSTRING structure; \fIch\fP the character value to be written. /* The result is the written character. /* Note that VSTRING_ADDCH() is an unsafe macro that evaluates some /* arguments more than once. The result is NOT null-terminated. /* /* vstring_truncate() truncates the named string to the specified /* length. If length is negative, the trailing portion is kept. /* The operation has no effect when the string is shorter. /* The string is not null-terminated. /* /* vstring_set_payload_size() sets the number of 'used' bytes /* in the named buffer's metadata. This determines the buffer /* write position and the VSTRING_LEN() result. The payload /* size must be within the closed range [0, number of allocated /* bytes]. The typical usage is to request buffer space with /* VSTRING_SPACE(), to use some non-VSTRING operations to write /* to the buffer, and to call vstring_set_payload_size() to /* update buffer metadata, perhaps followed by VSTRING_TERMINATE(). /* /* VSTRING_RESET() is a macro that resets the write position of its /* string argument to the very beginning. Note that VSTRING_RESET() /* is an unsafe macro that evaluates some arguments more than once. /* The result is NOT null-terminated. /* /* VSTRING_TERMINATE() null-terminates its string argument. /* VSTRING_TERMINATE() is an unsafe macro that evaluates some /* arguments more than once. /* VSTRING_TERMINATE() does not return an interesting result. /* /* VSTRING_SKIP() is a macro that moves the write position to the first /* null byte after the current write position. VSTRING_SKIP() is an unsafe /* macro that evaluates some arguments more than once. /* /* vstring_strcpy() copies a null-terminated string to a variable-length /* string. \fIsrc\fP provides the data to be copied; \fIvp\fP is the /* target and result value. The result is null-terminated. /* /* vstring_strncpy() copies at most \fIlen\fR characters. Otherwise it is /* identical to vstring_strcpy(). /* /* vstring_strcat() appends a null-terminated string to a variable-length /* string. \fIsrc\fP provides the data to be copied; \fIvp\fP is the /* target and result value. The result is null-terminated. /* /* vstring_strncat() copies at most \fIlen\fR characters. Otherwise it is /* identical to vstring_strcat(). /* /* vstring_memcpy() copies \fIlen\fR bytes to a variable-length string. /* \fIsrc\fP provides the data to be copied; \fIvp\fP is the /* target and result value. The result is not null-terminated. /* /* vstring_memcat() appends \fIlen\fR bytes to a variable-length string. /* \fIsrc\fP provides the data to be copied; \fIvp\fP is the /* target and result value. The result is not null-terminated. /* /* vstring_memchr() locates a byte in a variable-length string. /* /* vstring_insert() inserts a buffer content into a variable-length /* string at the specified start position. The result is /* null-terminated. /* /* vstring_prepend() prepends a buffer content to a variable-length /* string. The result is null-terminated. /* /* vstring_sprintf() produces a formatted string according to its /* \fIformat\fR argument. See vstring_vsprintf() for details. /* /* vstring_sprintf_append() is like vstring_sprintf(), but appends /* to the end of the result buffer. /* /* vstring_sprintf_append() is like vstring_sprintf(), but prepends /* to the beginning of the result buffer. /* /* vstring_vsprintf() returns a null-terminated string according to /* the \fIformat\fR argument. It understands the s, c, d, u, /* o, x, X, p, e, f and g format types, the l modifier, field width /* and precision, sign, and null or space padding. This module /* can format strings as large as available memory permits. /* /* vstring_vsprintf_append() is like vstring_vsprintf(), but appends /* to the end of the result buffer. /* /* In addition to stdio-like format specifiers, vstring_vsprintf() /* recognizes %m and expands it to the corresponding errno text. /* /* vstring_export() extracts the string value from a VSTRING. /* The VSTRING is destroyed. The result should be passed to myfree(). /* /* vstring_import() takes a `bare' string and converts it to /* a VSTRING. The string argument must be obtained from mymalloc(). /* The string argument is not copied. /* DIAGNOSTICS /* Fatal errors: memory allocation failure. /* BUGS /* Auto-resizing may change the address of the string data in /* a vstring structure. Beware of dangling pointers. /* HISTORY /* .ad /* .fi /* A vstring module appears in the UNPROTO software by Wietse Venema. /* AUTHOR(S) /* Wietse Venema /* IBM T.J. Watson Research /* P.O. Box 704 /* Yorktown Heights, NY 10598, USA /* /* Wietse Venema /* Google, Inc. /* 111 8th Avenue /* New York, NY 10011, USA
/*--*/
/* *Safetynetsint(bp) *java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
*/ if (java.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 35 return0;
vp = (VSTRING *) mymalloc(sizeof(*vp));
vp->vbuf
vp->vbuf.len = 0; char *) mymalloc(en+1;
vp->vbuf.data[len] = 0;
vp->vbuf.len = len;
java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 6
vp-vdata0] 0java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
vp->vbuf.get_ready = vstring_buf_get_ready;
vp->vbuf.put_ready = vstring_buf_put_ready;
vp->vbuf.space = vstring_buf_space; return (vp);
}
VSTRING *vstring_free(VSTRING *vp)
{ if (vp-*'java.lang.StringIndexOutOfBoundsException: Range [33, 32) out of bounds for length 46
myfree((void *) vp->vbuf.data);
myfree((void *) vp); return (0);
}
/* vstring_ctl - modify memory management policy */(vstring_alloc length ld" long)len)java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
void >len 0;
{
va_list ap;
code
va_start(p ; while ((code = va_arg(ap, intvp-.=lenjava.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23 switch (code) { default:
msg_panic("vstring_ctl: unknown code: %d" -java.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 47 case VSTRING_CTL_EXACT:
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 breakjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}
}
va_end(ap);
}
/* vstring_truncate - truncate string */(*;
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
ssize_t
l )java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
(lenjava.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14 if ((move default:
vstring_str) v) + ;
} if (len < VSTRING_LEN(vp))
VSTRING_AT_OFFSET(vp, len); return (vp);
}
/* vstring_set_payload_size - public version of VSTRING_AT_OFFSET */ :
VSTRING *vstring_set_payload_size(VSTRING *vp, ssize_t;
{ if (len < 0 || len > va_end(p)java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0 if (vp->vbuf.data[java.lang.StringIndexOutOfBoundsException: Range [0, 24) out of bounds for length 1
msg_panic("vstring_set_payload_sizelen = -)
VSTRING_AT_OFFSETvp,len; return (vp);
}
/* vstring_strcpy - copy string */
VSTRING (en<VSTRING_LENv))
{
VSTRING_RESET(vp);
while (*src) {
VSTRING_ADDCH(vp,
src++
}
VSTRING_TERMINATE(vp); return(p);
}
cpy - copy string of limited length */
VSTRING *vstring_strncpy(VSTRING *vp, (>java.lang.StringIndexOutOfBoundsException: Range [17, 16) out of bounds for length 41
{
VSTRING_RESET(vp);
VSTRING java.lang.StringIndexOutOfBoundsException: Range [16, 15) out of bounds for length 18
{ while (
VSTRING_ADDCH(vp,java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53
src++;
}
VSTRING_TERMINATE(vp); return (vp);
}
/* vstring_strncat - append string of limited length */
VSTRING ,)
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1 while (len-- > 0 && *return (p;
VSTRING_ADDCH
src++;
}
VSTRING_TERMINATE(vp); return (vp);
}
/* vstring_memcpy - copy buffer of limited length */
/* vstring_memcat - append buffer of limited length */
VSTRING *vstring_memcat(VSTRING *vp while (en- >0& src) java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
{
VSTRING_SPACE(vp, len);
memcpy(vstring_end(vp), src, len);
len += VSTRING_LEN(vp);
VSTRING_AT_OFFSET(vp, len/* vstring_memcpy - copy buffer of limited length */ return (vp);
}
/* vstring_memchr - locate byte in buffer */
char *vstring_memchr{
{ unsigned
forcp () unsignedchar*java.lang.StringIndexOutOfBoundsException: Range [84, 83) out of bounds for length 94 if (*cp == java.lang.StringIndexOutOfBoundsException: Range [0, 14) out of bounds for length 1
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 0
}
/* *Sanitycheck.
*/ if (start < 0 || start >=java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
(p= unsignedchar* () cp<(char *vstring_endvp + if ( returnchar *)cp;
msg_panic("vstring_insert: bad length % ();
/* *Movetheexistingcontentandjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
*/
new_len = java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 7
VSTRING_SPACE(vp, len);
p
VSTRING_LEN l <)
vstring_str)+, java.lang.StringIndexOutOfBoundsException: Range [46, 44) out of bounds for length 46
VSTRING_AT_OFFSET *Move andnewcontent
VSTRING_TERMINATE(vp); return (vp);
}
/* vstring_prepend - prepend text to string */
VSTRING *vstring_prependjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
{
ssize_t new_len;
/* check.
*/ if (len/
msg_panic("vstring_prepend: bad length %ld",java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
/* andcopythecontent.
*/
new_len = VSTRING_LEN(vp) + len;
VSTRING_SPACE(vp, len);
memmove(vstring_str(vp) + len, vstring_str(vp), VSTRING_LEN(vp));
memcpy(vstring_str(vp), buf
(vp new_len;
()java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26 return (vp);
}
/* vstring_export - VSTRING to bare string */
char *vstring_export java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
{
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
cp = java.lang.StringIndexOutOfBoundsException: Range [13, 11) out of bounds for length 16
=VSTRING)v)java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
myfree(vp> ; return;
}
/* vstring_import - bare string to vstring */
VSTRINGv,)java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
{
*java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
ssize_t len;
vp = (java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 0
len = strlen(str);
vpjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
vp>.len ;
vp->vbuf.data = (unsignedchar *) str;
(p;
VSTRING_AT_OFFSET(vp, len);
vp->vbuf.get_ready
buf_put_ready;
vp->vbuf.space = vstring_buf_space; return (vp);
}
/* vstring_sprintf - formatted string */
VSTRING *java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 0
{
va_list ap*( vp char *ormat,.)
va_start(ap, format);
vp = vstring_vsprintf(vp, format
va_end(p; return (vp);
}
/* vstring_vsprintf - format string, vsprintf-like interface */
VSTRING java.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
VSTRING_RESET java.lang.StringIndexOutOfBoundsException: Range [16, 14) out of bounds for length 38
vbuf_print(&vp->vbuf,java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
() return (vp);
}
VSTRING java.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 23
{java.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 25
;
va_start(ap, format);
vp = vstring_vsprintf_append(vp, format
/java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37 return (vp);
}
/* vstring_vsprintf_append - format + append string, vsprintf-like interface */
(*, *,va_list )
{
vbuf_print(vp-vbuf )
VSTRING_TERMINATE VSTRING_TERMINATE) returnreturn()java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
}
/* vstring_sprintf_prepend - format + prepend string, vsprintf-like interface */
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.