#include "strbuf.h"

This page has information from files strbuf.h and strbuf.c.

Contents


Public Routines in File strbuf.c

Index

fprint_sbp_sbsb_append_intsb_to_malloc_string
fprint_strbuf_memp_strbuf_memsb_catsb_to_string
get_string_bufreverse_charssb_cat_copystr_to_int
init_string_bufsb_appendsb_charzap_string_buf
itoasb_append_charsb_size

Details


void fprint_sb(FILE *fp, String_buf sb);
This routine prints String_buf sb to FILE *fp.
void fprint_strbuf_mem(FILE *fp, BOOL heading);
This routine prints (to FILE *fp) memory usage statistics for data types associated with the strbuf package. The Boolean argument heading tells whether to print a heading on the table.
String_buf get_string_buf(void);

String_buf init_string_buf(char *s);
This routine allocates and returns a String_buf, initialized to string s. Don't forget to call zap_string_buf(sb) when finished with it. Also see get_string_buf().
char *itoa(int n, char *s);
This routine converts an integer to a string (in decimal form). The character array s must be large enough to hold the string. The string is returned.
void p_sb(String_buf sb);
This routine prints String_buf sb, followed by '\n' and fflush, to stdout. If you don't want the newline, use fprint_sb() instead.
void p_strbuf_mem();
This routine prints (to stdout) memory usage statistics for data types associated with the strbuf package.
void reverse_chars(char *s, int start, int end);
This routine reverses an array of characters. You must give the starting and ending positions.
void sb_append(String_buf sb, char *s);
This routine appends string s to String_buf sb. The NULL character that marks the end of s does not go into the String_buf.
void sb_append_char(String_buf sb, char c);
This routine appends character c to String_buf sb.
void sb_append_int(String_buf sb, int i);
Convert an integer to a string and append the string to a String_buf.
void sb_cat(String_buf sb1, String_buf sb2);
This routine appends a copy of sb2 to sb1, then deallocates sb2. Do not refer to sb2 after calling this rouine because it won't exist. You can use sb_cat_copy() instead if you need to save sb2.
void sb_cat_copy(String_buf sb1, String_buf sb2);
This routine appends a copy of sb2 to sb1. String_buf sb2 is not changed. You can use sb_cat() instead if you won't be needing sb2.
char sb_char(String_buf sb, int n);
This routine returns the n-th character (counting from 0) of String_buf sb. If index n is out of range, the NULL character '\0' is returned.
int sb_size(String_buf sb);

char *sb_to_malloc_string(String_buf sb);
This routine returns a new, ordinary C string corresponding to the String_buf argument sb. WARNING: the new string, say s, is dynamically allocated (malloced), so don't forget to call free(s) when you are finished with the string. (This routine is not intended for printing String_bufs; use fprint_sb() instead.)

String_bufs do not have a NULL character marking the end; instead, they keep a count of the number of characters. (Of course the result of this routine is terminated with NULL.)


char *sb_to_string(String_buf sb);
This routine returns string corresponding to the String_buf argument sb. You should call free_mem(s, CEILING(strlen(s) + 1, BYTES_POINTER)); if you wish to free the string.

String_bufs do not have a NULL character marking the end; instead, they keep a count of the number of characters. (Of course the result of this routine is terminated with NULL.)


BOOL str_to_int(char *str, int *ip);
This routine tries to convert a string into an integer (using strtol()). If successful, TRUE is returned and *ip is set to the integer. If failure, FALSE is returned.
void zap_string_buf(String_buf sb);
This routine deallocates a String_buf and frees all memory associated with it.

Public Definitions in File strbuf.h

typedef struct string_buf * String_buf;


Introduction

A String_buf is a kind of string that can grow as big as you need. This is implemented as a list of dynamically allocated character arrays of fixed size. The only problem with using String_bufs is that you have to remember to free a String_buf when you are finished with it.

This is similar to the StringBuffer class in Java, and the cstrings of our old theorem prover LMA/ITP. We didn't have anything like this in Otter, but there were times when I wish we had, so here it is.


These activities are projects of the Mathematics and Computer Science Division of Argonne National Laboratory.