This leads to easy to read code and fewer things for the caller to think about.
I think this should probably become the default pattern for agxbuf usage for the
cases where the data you are printing is unpredictable or you are unsure.
const char* opacity, SparseMatrix A, FILE* f) {
/* if graph object exist, we just modify some attributes, otherwise we dump the whole graph */
bool plot_polyQ = true;
- agxbuf sbuff;
-
- agxbinit(&sbuff, 0, NULL);
+ agxbuf sbuff = {0};
if (!r || !g || !b) plot_polyQ = false;
(void)user_data;
FILE *output_file = NULL;
- agxbuf xbuf;
+ agxbuf xbuf = {0};
GtkTextBuffer *gtkbuf; /*GTK buffer from glade GUI */
char *bf2;
GtkTextIter startit;
GtkTextIter endit;
- agxbinit(&xbuf, SMALLBUF, NULL);
/*file name should be returned in xbuf */
if (savefiledlg(0, NULL, &xbuf)) {
output_file = fopen(agxbuse(&xbuf), "w");
#define XML_STATUS_ERROR 0
#endif
-#define SMALLBUF 1000
#define NAMEBUF 100
#define GRAPHML_ATTR "_graphml_"
static userdata_t *genUserdata(char* dfltname)
{
userdata_t *user = gv_alloc(sizeof(*user));
- agxbinit(&(user->xml_attr_name), NAMEBUF, 0);
- agxbinit(&(user->xml_attr_value), SMALLBUF, 0);
- agxbinit(&(user->composite_buffer), SMALLBUF, 0);
user->listen = FALSE;
user->elements = (gv_stack_t){0};
user->closedElementType = TAG_NONE;
static userdata_t *genUserdata(void)
{
- userdata_t *user = malloc(sizeof(userdata_t));
+ userdata_t *user = calloc(1, sizeof(userdata_t));
if (user == NULL)
return NULL;
- agxbinit(&(user->xml_attr_name), NAMEBUF, 0);
- agxbinit(&(user->xml_attr_value), SMALLBUF, 0);
- agxbinit(&(user->composite_buffer), SMALLBUF, 0);
user->listen = FALSE;
user->elements = (gv_stack_t){0};
user->closedElementType = TAG_NONE;
{
#ifdef HAVE_EXPAT
state.xb = xb;
- agxbinit (&state.lb, SMALLBUF, NULL);
+ state.lb = (agxbuf){0};
state.ptr = src;
state.mode = 0;
state.warn = 0;
int isEdge = 0;
textlabel_t *tl;
port pt;
- agxbuf buf;
/* prepare substitution strings */
switch (agobjkind(obj)) {
}
/* allocate a dynamic buffer that we will use to construct the result */
- agxbinit(&buf, 0, NULL);
+ agxbuf buf = {0};
/* assemble new string */
for (s = str; (c = *s++);) {
}
}
- if (xb.buf == NULL)
- agxbinit (&xb, 0, NULL);
-
agxbputc (&xb, LPAREN);
s = base;
while (*s) {
static graph_t* lastg;
static bool warned;
char* ns;
- agxbuf xb;
unsigned char c;
unsigned int v;
warned = false;
}
- agxbinit(&xb, 0, NULL);
+ agxbuf xb = {0};
while ((c = *(unsigned char*)s++)) {
if (c < 0xC0)
char* latin1ToUTF8 (char* s)
{
char* ns;
- agxbuf xb;
+ agxbuf xb = {0};
unsigned int v;
- agxbinit(&xb, 0, NULL);
-
/* Values are either a byte (<= 256) or come from htmlEntity, whose
* values are all less than 0x07FF, so we need at most 3 bytes.
*/
utf8ToLatin1 (char* s)
{
char* ns;
- agxbuf xb;
+ agxbuf xb = {0};
unsigned char c;
unsigned char outc;
- agxbinit(&xb, 0, NULL);
-
while ((c = *(unsigned char*)s++)) {
if (c < 0x7F)
agxbputc(&xb, (char)c);
*/
char *gvplugin_list(GVC_t * gvc, api_t api, const char *str)
{
- static int first = 1;
const gvplugin_available_t *pnext, *plugin;
char *bp;
bool new = true;
if (!str)
return NULL;
- if (first) {
- agxbinit(&xb, 0, 0);
- first = 0;
- }
-
/* does str have a :path modifier? */
const strview_t strv = strview(str, ':');
{
Sfio_t *sp;
int c;
- agxbuf tmps;
char *line;
if (fd < 0 || fd >= elementsof(ex->file) || !((sp = ex->file[fd]))) {
exerror("readL: %d: invalid descriptor", fd);
return "";
}
- agxbinit(&tmps, 0, NULL);
+
+ agxbuf tmps = {0};
while ((c = sfgetc(sp)) > 0 && c != '\n')
agxbputc(&tmps, (char)c);
if (c == '\n')
constant.value.integer);
if (!ptr) {
agxbuf xb = {0};
- agxbinit(&xb, 0, NULL);
exerror("null reference %s in expression %s.%s",
ref->symbol->name, ref->symbol->name, deparse(pgm, x, &xb));
agxbfree(&xb);
objp = deref(pgm, node, ref, 0, state);
if (!objp) {
agxbuf xb = {0};
- agxbinit(&xb, 0, NULL);
exerror("null reference in expression %s", deparse(pgm, node, &xb));
agxbfree(&xb);
}
objp = state->curobj;
if (!objp) {
agxbuf xb = {0};
- agxbinit(&xb, 0, NULL);
exerror("current object $ not defined as reference for %s",
deparse(pgm, node, &xb));
agxbfree(&xb);
if (objp) {
if (lookup(pgm, objp, sym, &v, state)) {
agxbuf xb = {0};
- agxbinit(&xb, 0, NULL);
exerror("in expression %s", deparse(pgm, node, &xb));
agxbfree(&xb);
v.integer = 0;
objp = deref(pgm, x, ref, 0, state);
if (!objp) {
agxbuf xb = {0};
- agxbinit(&xb, 0, NULL);
exerror("in expression %s.%s", ref->symbol->name, deparse(pgm, x, &xb));
agxbfree(&xb);
return -1;
objp = state->curobj;
if (!objp) {
agxbuf xb = {0};
- agxbinit(&xb, 0, NULL);
exerror("current object $ undefined in expression %s",
deparse(pgm, x, &xb));
agxbfree(&xb);
} else {
if (!typeChkExp(ref, sym)) {
agxbuf xb = {0};
- agxbinit(&xb, 0, NULL);
exerror("type error using %s", deparse(pgm, node, &xb));
agxbfree(&xb);
}
char *cp;
char c;
char *fname = 0;
- agxbuf fp;
char *pathp = NULL;
size_t sz;
path = DFLT_GVPRPATH;
if (Verbose)
fprintf (stderr, "PATH: %s\n", path);
- agxbinit(&fp, 0, NULL);
+ agxbuf fp = {0};
while (*path && !fname) {
if (*path == LISTSEP) { /* skip colons */
{
case_t kind;
- agxbuf buf;
- agxbinit(&buf, 0, NULL);
+ agxbuf buf = {0};
kind = parseKind(str);
switch (kind) {
*/
static void put_escaping_backslashes(Agobj_t* n, Agsym_t *sym, const char *value)
{
- agxbuf buf;
-
- /* create a temporary buffer */
- agxbinit(&buf, 0, NULL);
+ agxbuf buf = {0};
/* print the given string to the buffer, escaping as we go */
for (; *value != '\0'; ++value) {