-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make xbuf public so it can be used in main code, not just lesskey_parse.
- Loading branch information
Showing
7 changed files
with
67 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include "less.h" | ||
#include "xbuf.h" | ||
|
||
/* | ||
* Initialize an expandable text buffer. | ||
*/ | ||
public void | ||
xbuf_init(xbuf) | ||
struct xbuffer *xbuf; | ||
{ | ||
xbuf->data = NULL; | ||
xbuf->size = xbuf->end = 0; | ||
} | ||
|
||
public void | ||
xbuf_reset(xbuf) | ||
struct xbuffer *xbuf; | ||
{ | ||
if (xbuf->data != NULL) | ||
free(xbuf->data); | ||
xbuf_init(xbuf); | ||
} | ||
|
||
/* | ||
* Add a char to an expandable text buffer. | ||
*/ | ||
public void | ||
xbuf_add(xbuf, ch) | ||
struct xbuffer *xbuf; | ||
char ch; | ||
{ | ||
if (xbuf->end >= xbuf->size) | ||
{ | ||
char *data; | ||
xbuf->size = (xbuf->size == 0) ? 16 : xbuf->size * 2; | ||
data = ecalloc(xbuf->size, sizeof(char)); | ||
if (xbuf->data != NULL) | ||
{ | ||
memcpy(data, xbuf->data, xbuf->end); | ||
free(xbuf->data); | ||
} | ||
xbuf->data = data; | ||
} | ||
xbuf->data[xbuf->end++] = ch; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef XBUF_H_ | ||
#define XBUF_H_ | ||
|
||
struct xbuffer | ||
{ | ||
char *data; | ||
int end; | ||
int size; | ||
}; | ||
|
||
void xbuf_init(struct xbuffer *xbuf); | ||
void xbuf_reset(struct xbuffer *xbuf); | ||
void xbuf_add(struct xbuffer *xbuf, char ch); | ||
|
||
#endif |