Example #1
0
File: ui.c Project: Alok/neovim-1
void ui_putc(uint8_t c)
{
  uint8_t buf[2] = {c, 0};
  ui_puts(buf);
}
Example #2
0
int main(int argc, char **argv)
{
    struct gopherus g;
    struct url start_url;
    char start_url_str[] = "gopher://#welcome";

    memset(&g, '\0', sizeof g);

    /* Load configuration (or defaults) */
    loadcfg(&g.cfg);

    ui_init();

    parse_url(start_url_str, &start_url);

    if (history_add(&g.history, &start_url) != 0) {
        ui_puts("Out of memory.");
        return 2;
    }

    if (argc > 1) { /* if some params have been received, parse them */
        int i;
        int goturl = 0;

        for (i = 1; i < argc; i++) {
            struct url next_url;

            if ((argv[i][0] == '/') || (argv[i][0] == '-')) { /* unknown parameter */
                ui_puts("Gopherus v" VERSION " Copyright (C) Mateusz Viste " DATE);
                ui_puts("");
                ui_puts("Usage: gopherus [url]");
                ui_puts("");
                return 1;
            }
            if (goturl != 0) {
                ui_puts("Invalid parameters list.");
                return 1;
            }
            if (parse_url(argv[1], &next_url) != 0) {
                ui_puts("Invalid URL!");
                return 1;
            }
            goturl = 1;
            history_add(&g.history, &next_url);
            if (g.history == NULL) {
                ui_puts("Out of memory.");
                return 2;
            }
        }
    }

    g.buf = malloc(buffersize);

    if (g.buf == NULL) {
        char message[128];
        sprintf(message, "Out of memory. Could not allocate buffer of %d bytes.", buffersize);
        ui_puts(message);
        return 2;
    }

    if (net_init() != 0) {
        ui_puts("Network subsystem initialization failed!");
        free(g.buf);
        return 3;
    }

    ui_cursor_hide();
    ui_cls();

    mainloop(&g);

    ui_cls();
    ui_cursor_show();

    if (g.statusbar[0] != 0)
        ui_puts(g.statusbar); /* we might have here an error message to show */

    /* Free the main buffer */
    free(g.buf);
    /* unallocate all the history */
    history_flush(g.history);

    return 0;
}