Update of /cvsroot/dhcp-agent/dhcp-agent
In directory usw-pr-cvs1:/tmp/cvs-serv28582
Modified Files:
dhcp-stringbuffer.c
Log Message:
fixed up stringbuffer
Index: dhcp-stringbuffer.c
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-stringbuffer.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** dhcp-stringbuffer.c 17 Jun 2002 13:23:08 -0000 1.4
--- dhcp-stringbuffer.c 18 Jun 2002 23:24:30 -0000 1.5
***************
*** 123,126 ****
--- 123,127 ----
}
+ /* clear a string. */
void stringbuffer_clear(stringbuffer *sb)
{
***************
*** 132,136 ****
void stringbuffer_append_c(stringbuffer *sb, char c)
{
! if(sb->capacity <= (1 + sb->capacity)) {
sb->buf = extend_string(sb->buf, sb->len, 1);
sb->len++;
--- 133,137 ----
void stringbuffer_append_c(stringbuffer *sb, char c)
{
! if(sb->capacity <= (1 + sb->len)) {
sb->buf = extend_string(sb->buf, sb->len, 1);
sb->len++;
***************
*** 177,188 ****
/* we do have whitespace in the beginning so find the end. */
! for(end = &sb->buf[sb->len -1];
*end == ' ' || *end == '\t';
end--);
!
! len = (sb->len + 1); /* save old length. */
/* create a new string */
! newbuf = xmalloc(len * sizeof(char));
ptr = newbuf;
--- 178,188 ----
/* we do have whitespace in the beginning so find the end. */
! for(end = &sb->buf[sb->len];
*end == ' ' || *end == '\t';
end--);
! len = sb->len; /* save old length. */
/* create a new string */
! newbuf = allocate_string(len);
ptr = newbuf;
***************
*** 210,214 ****
/* get the last occurance of a specific character. useful for slicing. */
-
char *stringbuffer_get_last_occurance(stringbuffer *sb, char c)
{
--- 210,213 ----
***************
*** 250,253 ****
--- 249,253 ----
}
+ /* set a string into a stringbuffer */
void stringbuffer_set(stringbuffer *dest, const char *s)
{
***************
*** 256,259 ****
--- 256,260 ----
}
+ /* copy a stringbuffer into another stringbuffer */
void stringbuffer_copy(stringbuffer *dest, stringbuffer *src)
{
***************
*** 261,264 ****
--- 262,284 ----
}
+ /* replace in stringbuffer occurances of c with replace */
+ void stringbuffer_replace_c(stringbuffer *sb, char c, char replace)
+ {
+ char *ptr;
+
+ for(ptr = sb->buf; *ptr != 0; ptr++) {
+ if(*ptr == c)
+ *ptr = replace;
+ }
+ }
+
+ /* zap newlines by placing spaces in their place.
+ * we use this before aligning. */
+ static void stringbuffer_zap_newline(stringbuffer *sb)
+ {
+
+ stringbuffer_replace_c(sb, '\n', ' ');
+ stringbuffer_replace_c(sb, '\r', ' ');
+ }
/* align a stringbuffer on begin and end columns. */
***************
*** 269,272 ****
--- 289,294 ----
int len, i;
+
+ stringbuffer_zap_newline(sb);
aligned_string = create_stringbuffer();
|