Ejemplo n.º 1
0
static void popup_any_cb(ExplorerUI *eui, int type)
{
    TreeItemList items;
    int count, i;
    Quark *qnew = NULL;
    Quark *q;
    GProject *gp;

    int gpcount = 0;
    GProject **gplist;
    
    TreeGetHighlighted(eui->tree, &items);
    count = items.count;

    if (!count) {
        xfree(items.items);
        return;
    }

    gplist = xmalloc(gapp->gpcount*sizeof(GProject));
    if (!gplist) {
        return;
    }
    
    for (i = 0; i < count; i++) {
        
        q = TreeGetQuark(items.items[i]);
        gp = gproject_from_quark(q);
        add_to_list(gplist, &gpcount, gp);
        
        switch (type) {
        case HIDE_CB:
            quark_set_active(q, FALSE);
            break;
        case SHOW_CB:
            quark_set_active(q, TRUE);
            break;
        case DELETE_CB:
            quark_free(q);
            break;
        case DUPLICATE_CB:
            quark_copy(q);
            break;
        case ADD_FRAME_CB:
            qnew = frame_new(q);
            break;
        case ADD_GRAPH_CB:
            qnew = graph_new(q);
            break;
        case ADD_SSD_CB:
            qnew = gapp_ssd_new(q);
            break;
        case ADD_SET_CB:
            qnew = gapp_set_new(q);
            break;
        case ADD_AXISGRID_CB:
            qnew = axisgrid_new(q);
            break;
        case ADD_AXIS_CB:
            qnew = axis_new(q);
            break;
        case ADD_LINE_CB:
            qnew = object_new_complete(q, DO_LINE);
            break;
        case ADD_BOX_CB:
            qnew = object_new_complete(q, DO_BOX);
            break;
        case ADD_ARC_CB:
            qnew = object_new_complete(q, DO_ARC);
            break;
        case ADD_TEXT_CB:
            qnew = atext_new(q);
            break;
        }
    }
    xfree(items.items);
    
    for (i = 0; i < gpcount; i++) {
        explorer_snapshot(gapp, gplist[i], TRUE);
    }
    xfree(gplist);

    if (qnew) {
        select_quark_explorer(qnew);
    }
}
Ejemplo n.º 2
0
int uniread(Quark *pr, FILE *fp,
    DataParser parse_cb, DataStore store_cb, void *udata)
{
    int nrows, nrows_allocated;
    int ok, readerror;
    Quark *q = NULL;
    char *linebuf = NULL;
    int linebuflen = 0;
    int linecount;

    linecount = 0;
    readerror = 0;
    nrows = 0;
    nrows_allocated = 0;
    
    ok = TRUE;
    while (ok) {
        char *s;
	int maybe_data;
        int ncols, nncols, nscols;
        int *formats;
        
        if (read_long_line(fp, &linebuf, &linebuflen) == RETURN_SUCCESS) {
            linecount++;
            s = linebuf;

	    /* skip leading whitespaces */
            while (*s == ' ' || *s == '\t') {
                s++;
            }

	    /* skip comments */
            if (*s == '#') {
                continue;
            }

            /*     EOL           EOD    */
            if (*s == '\n' || *s == '\0') {
                maybe_data = FALSE;
            } else
            if (parse_cb && parse_cb(s, udata) == RETURN_SUCCESS) {
                maybe_data = FALSE;
            } else {
                maybe_data = TRUE;
            }
        } else {
            ok = FALSE;
            maybe_data = FALSE;
        }
        
        if (maybe_data) {
	    if (!nrows) {
		/* parse the data line */
                if (parse_ss_row(pr, s, &nncols, &nscols, &formats) != RETURN_SUCCESS) {
		    errmsg("Can't parse data");
		    xfree(linebuf);
		    return RETURN_FAILURE;
                }
                ncols = nncols + nscols;

                /* init the SSD */
                q = gapp_ssd_new(pr);
                if (!q || ssd_set_ncols(q, ncols, formats) != RETURN_SUCCESS) {
		    errmsg("Malloc failed in uniread()");
		    quark_free(q);
                    xfree(formats);
		    xfree(linebuf);
                    return RETURN_FAILURE;
                }
                xfree(formats);
	    }
            
	    if (nrows >= nrows_allocated) {
		if (!nrows_allocated) {
                    nrows_allocated = BUFSIZE;
                } else {
                    nrows_allocated *= 2;
                }
                if (ssd_set_nrows(q, nrows_allocated) != RETURN_SUCCESS) {
		    errmsg("Malloc failed in uniread()");
                    quark_free(q);
		    xfree(linebuf);
		    return RETURN_FAILURE;
                }
	    }

            if (insert_data_row(q, nrows, s) != RETURN_SUCCESS) {
                char tbuf[128];
                
                sprintf(tbuf, "Error parsing line %d, skipped", linecount);
                errmsg(tbuf);
                readerror++;
                if (readerror > MAXERR) {
                    if (yesno("Lots of errors, abort?", NULL, NULL, NULL)) {
                        quark_free(q);
		        xfree(linebuf);
                        return RETURN_FAILURE;
                    } else {
                        readerror = 0;
                    }
                }
            } else {
	        nrows++;
            }
	} else
        if (nrows) {
            /* free excessive storage */
            ssd_set_nrows(q, nrows);

            /* store accumulated data */
            if (store_cb && store_cb(q, udata) != RETURN_SUCCESS) {
		quark_free(q);
                xfree(linebuf);
                return RETURN_FAILURE;
            }

            /* reset state registers */
            nrows = 0;
            nrows_allocated = 0;
            readerror = 0;
        }
    }

    xfree(linebuf);
    
    return RETURN_SUCCESS;
}