Esempio n. 1
0
/*
 * Warn about a possible bug displaying the passed message, try to save
 * any unsaved work and abort
 */
void emergency_exit(GraceApp *gapp, int is_my_bug, char *msg)
{
/*
 *  Since we got so far, memory is probably corrupted so it's better to use
 *  a static storage
 */
    static char buf[GR_MAXPATHLEN];
    int i;
    
    if (gapp->rt->emergency_save != FALSE) {
        /* don't mind signals anymore: we're in emergency save mode already */
        gapp->rt->interrupts++;
        if (gapp->rt->interrupts > 10) {
            fprintf(stderr, "oh, no luck :-(\n");
            please_report_the_bug();
            abort();
        }
        return;
    } else {
        gapp->rt->emergency_save = TRUE;
        gapp->rt->interrupts = 0;
        fprintf(stderr, "\a\nOops! %s\n", msg);

        for (i = 0; i < gapp->gpcount; i++) {
            if (gapp->gplist[i] && quark_dirtystate_get(gproject_get_top(gapp->gplist[i]))) {
                strcpy(buf, gproject_get_docname(gapp->gplist[i]));
                strcat(buf, "$");
                fprintf(stderr, "Trying to save your work into file \"%s\"... ", buf);
                fflush(stderr);
                gapp->gui->noask = TRUE;
                if (save_project(gapp->gplist[i], buf) == RETURN_SUCCESS) {
                    fprintf(stderr, "ok!\n");
                } else {
                    fprintf(stderr, "oh, no luck :-(\n");
                }
            }
        }
        if (is_my_bug) {
            please_report_the_bug();
        }
        abort();
    }
}
Esempio n. 2
0
int save_project(GProject *gp, char *fn)
{
    GrFILE *grf;
    Quark *project = gproject_get_top(gp);
    GUI *gui = gui_from_quark(project);
    int noask_save;
    static int save_unsupported = FALSE;
    int retval;

    if (!project || !fn) {
        return RETURN_FAILURE;
    }
    
    if (fn && strstr(fn, ".agr")) {
        errmsg("Cowardly refusing to overwrite an agr file");
        return RETURN_FAILURE;
    }
    if (!save_unsupported &&
        !yesno("The current format may be unsupported by the final release. Continue?",
            "Yeah, I'm brave!", NULL, "doc/UsersGuide.html#unsupported_format")) {
        return RETURN_FAILURE;
    }
    save_unsupported = TRUE;

    noask_save = gui->noask;
    if (strings_are_equal(gproject_get_docname(gp), fn)) {
        /* If saving under the same name, don't warn about overwriting */
        gui->noask = TRUE;
    }
    
    grf = grfile_openw(fn);
    if (!grf) {
        return RETURN_FAILURE;
    }
    
    gui->noask = noask_save;

    retval = gproject_save(gp, grf);

    grfile_free(grf);
    
    return retval;
}
Esempio n. 3
0
int gproject_render(const GProject *gp)
{
    int res;
    
    Grace *grace = grace_from_gproject(gp);
    
    if (!grace) {
        return RETURN_FAILURE;
    }
    
    canvas_set_udata(grace->canvas, (GProject *) gp);
    
    canvas_set_docname(grace->canvas, gproject_get_docname(gp));
    
    res = drawgraph(grace->canvas, grace->graal, gp->q);
    
    canvas_set_udata(grace->canvas, NULL);
    
    return res;
}