Пример #1
1
int workspace_choose (char * ws) {
    char * buf = (char *) malloc (25 + strlen (ws));
    sprintf (buf, "Opening workspace %s...\n", ws);
    interface_log (buf);
    free (buf);
#ifdef WITH_SQLITE3
    sqlite3_stmt * stmt;
    if (sqlite3_prepare (db, "SELECT id FROM workspace WHERE name=?;", -1, &stmt, 0) != SQLITE_OK) {
        interface_error ("Failed to SELECT\n");
        return -1;
    }
    if (sqlite3_bind_text (stmt, 1, (const char *) ws, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
        interface_error ("Failed to bind\n");
        return -1;
    }
    if (sqlite3_step (stmt) == SQLITE_DONE) {
        sqlite3_finalize (stmt);
        if (sqlite3_prepare (db, "INSERT INTO workspace (name) VALUES (?);", -1, &stmt, 0) != SQLITE_OK) {
            interface_error ("Failed to INSERT\n");
            return -1;
        }
        if (sqlite3_bind_text (stmt, 1, (const char *) ws, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
            interface_error ("Failed to bind\n");
            return -1;
        }
        sqlite3_step (stmt);
        sqlite3_finalize (stmt);
        workspace_choose (ws);
        workspace_log ("Workspace created");
        return 0;
    }
    workspace_id = sqlite3_column_int (stmt, 0);
    sqlite3_finalize (stmt);
    workspace = ws;
    return 0;
#else
    if (file) {
        fclose (file);
        file = NULL;
    }
    workspace_file = (char *) malloc (strlen (workspace_dir) + strlen (ws) + 6);
    sprintf (workspace_file, "%s/%s.wsp", workspace_dir, ws);
    file = fopen (workspace_file, "a");
    if (file == NULL) {
        char * buf = (char *) malloc (27 + strlen (workspace_file) + strlen (strerror (errno)));
        sprintf (buf, "Could not fopen(2) %s: %s\n", workspace_file, strerror (errno));
        interface_error (buf);
        free (buf);
        return -1;
    }
    workspace = ws;
    return 0;
#endif
}
Пример #2
0
void workspace_init () {
    // Get path to workspace (~/.boef)
    workspace_home = getpwuid (getuid ()) -> pw_dir;
    workspace_dir = (char *) malloc (strlen (workspace_home) + 7);
    sprintf (workspace_dir, "%s/.boef", workspace_home);
    char * buf1 = (char *) malloc (28 + strlen (workspace_dir));
    sprintf (buf1, "Opening workspace in %s...\n", workspace_dir);
    interface_log (buf1);
    free (buf1);

    // Check whether it exists and create it if it doesn't
    struct stat buf;
    if (stat ((const char *) workspace_dir, &buf) == -1) {
        if (errno == ENOENT) {
            if (mkdir (workspace_dir, S_IRWXU | S_IRGRP | S_IROTH) == -1) {
                char * buf = (char *) malloc (27 + strlen (workspace_dir) + strlen (strerror (errno)));
                sprintf (buf, "Could not mkdir(2) %s: %s\n", workspace_dir, strerror (errno));
                interface_error (buf);
                free (buf);
                exit (1);
            }
        }
        else {
            char * buf = (char *) malloc (27 + strlen (workspace_dir) + strlen (strerror (errno)));
            sprintf (buf, "Could not stat(2) %s: %s\n", workspace_dir, strerror (errno));
            interface_error (buf);
            free (buf);
            exit (1);
        }
    }

#ifdef WITH_SQLITE3
    // Open database
    workspace_db = (char *) malloc (strlen (workspace_dir) + 7);
    sprintf (workspace_db, "%s/db.sl3", workspace_dir);
    if (sqlite3_open (workspace_db, &db)) {
        interface_error ("Failed to open SQLite database\n");
        exit (1);
    }

    int error = sqlite3_exec (db, "CREATE TABLE IF NOT EXISTS workspace(id INTEGER PRIMARY KEY ASC, name TEXT);", 0, 0, 0)
                | sqlite3_exec (db, "CREATE TABLE IF NOT EXISTS log(workspace_id INTEGER, value TEXT);", 0, 0, 0)
                | sqlite3_exec (db, "CREATE TABLE IF NOT EXISTS option(workspace_id INTEGER, name TEXT, value TEXT);", 0, 0, 0)
                | sqlite3_exec (db, "DELETE FROM option WHERE workspace_id=1;", 0, 0, 0);
    if (error != SQLITE_OK) {
        interface_error ("Failed to update database\n");
        exit (1);
    }
#endif
}
Пример #3
0
void themes_switch_theme (const char *file)
{
	if (has_colors()) {
		reset_colors_table ();
		if (!load_color_theme(file, 0)) {
			interface_error ("Error loading theme!");
			reset_colors_table ();
		}

		set_default_colors ();
	}
}
Пример #4
0
char * workspace_getoption (char * option) {
#ifdef WITH_SQLITE3
    sqlite3_stmt * stmt;
    if (sqlite3_prepare (db, "SELECT value FROM option WHERE name=? AND workspace_id=?;", -1, &stmt, 0) != SQLITE_OK) {
        interface_error ("Failed to SELECT\n");
        return NULL;
    }
    if (sqlite3_bind_text (stmt, 1, (const char *) option, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
        interface_error ("Failed to bind\n");
        return NULL;
    }
    if (sqlite3_bind_int (stmt, 2, workspace_id) != SQLITE_OK) {
        interface_error ("Failed to bind\n");
        return NULL;
    }
    if (sqlite3_step (stmt) == SQLITE_DONE) {
        return NULL;
    }
    char * ret = (char *) sqlite3_column_text (stmt, 0);
    sqlite3_finalize (stmt);
    return ret;
#endif
}
Пример #5
0
int workspace_setoption (char * option, char * value) {
#ifdef WITH_SQLITE3
    sqlite3_stmt * stmt;
    if (workspace_getoption (option) == NULL) {
        if (sqlite3_prepare (db, "INSERT INTO option (workspace_id, name,value) VALUES (?,?,?);", -1, &stmt, 0) != SQLITE_OK) {
            interface_error ("Failed to INSERT\n");
            return -1;
        }
        if (sqlite3_bind_int (stmt, 1, workspace_id) != SQLITE_OK) {
            interface_error ("Failed to bind\n");
            return NULL;
        }
        if (sqlite3_bind_text (stmt, 2, (const char *) option, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
            interface_error ("Failed to bind\n");
            return -1;
        }
        if (sqlite3_bind_text (stmt, 3, (const char *) value, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
            interface_error ("Failed to bind\n");
            return -1;
        }
        sqlite3_step (stmt);
        sqlite3_finalize (stmt);
        return 0;
    }
    else {
        if (sqlite3_prepare (db, "UPDATE option set value=? WHERE name=? AND workspace_id=?;", -1, &stmt, 0) != SQLITE_OK) {
            interface_error ("Failed to INSERT\n");
            return -1;
        }
        if (sqlite3_bind_text (stmt, 1, (const char *) value, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
            interface_error ("Failed to bind\n");
            return -1;
        }
        if (sqlite3_bind_text (stmt, 2, (const char *) option, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
            interface_error ("Failed to bind\n");
            return -1;
        }
        if (sqlite3_bind_int (stmt, 3, workspace_id) != SQLITE_OK) {
            interface_error ("Failed to bind\n");
            return NULL;
        }
        sqlite3_step (stmt);
        sqlite3_finalize (stmt);
        return 0;
    }
#endif
}
Пример #6
0
void error (const char *format, ...)
{
	va_list va;
	char msg[256];
	
	va_start (va, format);
	vsnprintf (msg, sizeof(msg), format, va);
	msg[sizeof(msg) - 1] = 0;
	va_end (va);
	
	if (im_server)
		server_error (msg);
	else
		interface_error (msg);
}
Пример #7
0
void internal_error (const char *file, int line, const char *function,
                     const char *format, ...)
{
	int saved_errno = errno;
	va_list va;
	char *msg;

	va_start (va, format);
	msg = format_msg_va (format, va);
	va_end (va);

	if (im_server)
		server_error (file, line, function, msg);
	else
		interface_error (msg);

	free (msg);

	errno = saved_errno;
}