예제 #1
0
파일: xml-writer.c 프로젝트: waytai/wicked
int
xml_node_print_fn(const xml_node_t *node, void (*writefn)(const char *, void *), void *user_data)
{
	char *membuf = NULL;
	size_t memsz = 0;
	FILE *memf;
	int rv;

	memf = open_memstream(&membuf, &memsz);
	rv = xml_node_print(node, memf);
	fclose(memf);

	if (rv >= 0) {
		char *s, *t;

		for (s = membuf; s; s = t) {
			if ((t = strchr(s, '\n')) != NULL)
				*t++ = '\0';
			writefn(s, user_data);
		}
	}

	free(membuf);
	return rv;
}
예제 #2
0
/*
 * writeListBoxContents
 */
static BOOL writeListBoxContents( void (*writefn)( FILE * ), char *fname, HWND listbox )
{
    WORD        i;
    LRESULT     count;
    FILE        *f;
    char        str[256];

    f = fopen( fname, "w" );
    if( f == NULL ) {
        return( FALSE );
    }
    if( writefn != NULL ) {
        writefn( f );
    }
    count = SendMessage( listbox, LB_GETCOUNT, 0, 0L );
    if( count == LB_ERR ) {
        fclose( f );
        return( FALSE );
    }
    for( i = 0; i < count; i++ ) {
        SendMessage( listbox, LB_GETTEXT, i, (LPARAM)str );
        fprintf( f, "%s\n", str );
    }
    fclose( f );
    return( TRUE );

} /* writeListBoxContents */