⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 添加系统调用。。。在LINUX下添加一个新的系统调用。在文件中添加自己的系统调用的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
        token = profile_end;        for (; *profile_end && !is_space(*profile_end) && *profile_end != '\n';             profile_end++);        /* If we run out of buffer space, read a new chunk */        if (!*profile_end) {                unsigned int token_size;                gsize bytes_read;                /* If we are out of space and we are not on the first or                   the last byte, then we have run out of things to read */                if (profile_end > profile_buf &&                    profile_end < profile_buf + sizeof (profile_buf) - 1) {                        profile_swap = 0;                        return "";                }                /* Move what we have of the token to the start of the buffer,                   fill the rest of the buffer with new data and start reading                   from the beginning */                token_size = profile_end - token;                if (token_size >= sizeof (profile_buf) - 1) {                        g_warning("Oversize token in profile");                        return "";                }                memmove(profile_buf, token, token_size);                g_io_channel_read_chars(channel, profile_buf + token_size,                                        sizeof (profile_buf) - token_size - 1,                                        &bytes_read, &error);                if (error) {                        g_warning("Read error: %s", error->message);                        return "";                }                if (bytes_read < 1) {                        profile_swap = 0;                        return "";                }                profile_end = profile_buf;                profile_buf[token_size + bytes_read] = 0;                goto seek_profile_end;        }        profile_swap = *profile_end;        *profile_end = 0;        return token;}int profile_read_next(void)/* Skip to the next line   FIXME should skip multiple blank lines */{        const char *s;        do {                s = profile_read();        } while (s[0]);        if (profile_swap == '\n') {                profile_swap = ' ';                return TRUE;        }        return FALSE;}int profile_write(const char *str)/* Write a string to the open profile */{        GError *error = NULL;        gsize bytes_written;        if (profile_read_only || !str)                return 0;        if (!channel)                return 1;        g_io_channel_write_chars(channel, str, strlen(str), &bytes_written,                                 &error);        if (error) {                g_warning("Write error: %s", error->message);                return 1;        }        return 0;}int profile_sync_int(int *var)/* Read or write an integer variable depending on the profile mode */{        if (profile_read_only) {                const char *s;                int n;                s = profile_read();                if (s[0]) {                        n = atoi(s);                        if (n || (s[0] == '0' && !s[1])) {                                *var = n;                                return 0;                        }                }        } else                return profile_write(va(" %d", *var));        return 1;}int profile_sync_short(short *var)/* Read or write a short integer variable depending on the profile mode */{        int value = *var;        if (profile_sync_int(&value))                return 1;        if (!profile_read_only)                return 0;        *var = (short)value;        return 0;}void version_read(void){        int version;        version = atoi(profile_read());        if (version != 0)                g_warning("Loading a profile with incompatible version %d "                          "(expected %d)", version, PROFILE_VERSION);}/*        Main and signal handling*/#define NUM_PROFILE_CMDS (sizeof (profile_cmds) / sizeof (*profile_cmds))int profile_line, log_level = 3;static char *log_filename = NULL;static FILE *log_file = NULL;/* Profile commands table */static struct {        const char *name;        void (*read_func)(void);        void (*write_func)(void);} profile_cmds[] = {        { "version",      version_read,      NULL               },        { "window",       window_sync,       window_sync        },        { "options",      options_sync,      options_sync       },        { "recognize",    recognize_sync,    recognize_sync     },        { "blocks",       blocks_sync,       blocks_sync        },        { "bad_keycodes", bad_keycodes_read, bad_keycodes_write },        { "sample",       sample_read,       samples_write      },};/* Command line arguments */static GOptionEntry command_line_opts[] = {        { "log-level", 0, 0, G_OPTION_ARG_INT, &log_level,          "Log threshold (0=silent, 7=debug)", "4" },        { "log-file", 0, 0, G_OPTION_ARG_STRING, &log_filename,          "Log file to use instead of stdout", PACKAGE ".log" },        { "xid", 0, 0, G_OPTION_ARG_NONE, &window_embedded,          "Embed the main window (XEMBED)", NULL },        { "show-window", 0, 0, G_OPTION_ARG_NONE, &window_force_show,          "Show the main window", NULL },        { "hide-window", 0, 0, G_OPTION_ARG_NONE, &window_force_hide,          "Don't show the main window", NULL },        { "window-x", 0, 0, G_OPTION_ARG_INT, &window_force_x,          "Horizontal window position", "512" },        { "window-y", 0, 0, G_OPTION_ARG_INT, &window_force_y,          "Vertical window position", "768" },        { "dock-window", 0, 0, G_OPTION_ARG_INT, &window_force_docked,          "Docking (0=off, 1=top, 2=bottom)", "0" },        { "window-struts", 0, 0, G_OPTION_ARG_NONE, &window_struts,          "Reserve space when docking, see manpage", NULL },        { "keyboard-only", 0, 0, G_OPTION_ARG_NONE, &keyboard_only,          "Show on-screen keyboard only", NULL },        { "profile", 0, 0, G_OPTION_ARG_STRING, &force_profile,          "Full path to profile file to load", "profile" },        { "read-only", 0, 0, G_OPTION_ARG_NONE, &force_read_only,          "Do not save changes to the profile", NULL },        { "disable-overwrite", 0, 0, G_OPTION_ARG_NONE, &key_disable_overwrite,          "Do not modify the keymap", NULL },        /* Sentinel */        { NULL, 0, 0, 0, NULL, NULL, NULL }};/* If any of these things happen, try to save and exit cleanly -- gdb is not   affected by any of these signals being caught */static int catch_signals[] = {	SIGSEGV,	SIGHUP,	SIGINT,	SIGTERM,	SIGQUIT,	SIGALRM,        -1};void cleanup(void){        static int finished;        /* Run once */        if (finished) {                g_debug("Cleanup already called");                return;        }        finished = TRUE;        g_message("Cleaning up");        /* Explicit cleanup */        cell_widget_cleanup();        window_cleanup();        key_event_cleanup();        if (!window_embedded)                single_instance_cleanup();        /* Save profile */        if (!window_embedded && profile_open_write()) {                unsigned int i;                profile_write(va("version %d\n", PROFILE_VERSION));                for (i = 0; i < NUM_PROFILE_CMDS; i++)                        if (profile_cmds[i].write_func)                                profile_cmds[i].write_func();                if (profile_close())                        g_debug("Profile saved");        }        /* Close log file */        if (log_file)                fclose(log_file);}static void catch_sigterm(int sig)/* Terminated by shutdown */{        g_warning("Caught signal %d, cleaning up", sig);        cleanup();        exit(1);}static void hook_signals(void)/* Setup signal catchers */{        sigset_t sigset;        int *ps;        sigemptyset(&sigset);        ps = catch_signals;        while (*ps != -1) {                signal(*ps, catch_sigterm);                sigaddset(&sigset, *(ps++));        }        if (sigprocmask(SIG_UNBLOCK, &sigset, NULL) == -1)                log_errno("Failed to set signal blocking mask");}void log_print(const char *format, ...)/* Print to the log file or stderr */{        FILE *file;        va_list va;        file = log_file;        if (!file) {                if (window_embedded)                        return;                file = stderr;        }        va_start(va, format);        vfprintf(file, format, va);        va_end(va);}void log_func(const gchar *domain, GLogLevelFlags level, const gchar *message){        const char *prefix = "", *postfix = "\n", *pmsg;        if (level > log_level)                goto skip_print;        /* Do not print empty messages */        for (pmsg = message; *pmsg <= ' '; pmsg++)                if (!*pmsg)                        goto skip_print;        /* Format the message */        switch (level & G_LOG_LEVEL_MASK) {        case G_LOG_LEVEL_DEBUG:                prefix = "| ";                break;        case G_LOG_LEVEL_INFO:        case G_LOG_LEVEL_MESSAGE:                if (log_level > G_LOG_LEVEL_INFO) {                        prefix = "\n";                        postfix = ":\n";                }                break;        case G_LOG_LEVEL_WARNING:                if (log_level > G_LOG_LEVEL_INFO)                        prefix = "* ";                else if (log_level > G_LOG_LEVEL_WARNING)                        prefix = "WARNING: ";                else                        prefix = PACKAGE ": ";                break;        case G_LOG_LEVEL_CRITICAL:        case G_LOG_LEVEL_ERROR:                if (log_level > G_LOG_LEVEL_INFO)                        prefix = "* ERROR! ";                else if (log_level > G_LOG_LEVEL_WARNING)                        prefix = "ERROR: ";                else                        prefix = PACKAGE ": ERROR! ";                break;        default:                break;        }        if (domain)                log_print("%s[%s] %s%s", prefix, domain, message, postfix);        else                log_print("%s%s%s", prefix, message, postfix);skip_print:        if (level & G_LOG_FLAG_FATAL || level & G_LOG_LEVEL_ERROR)                abort();}void trace_full(const char *file, const char *func, const char *format, ...){        char buf[256];        va_list va;        if (LOG_LEVEL_TRACE > log_level)                return;        va_start(va, format);        vsnprintf(buf, sizeof(buf), format, va);        va_end(va);        log_print(": %s:%s() %s\n", file, func, buf);}void log_errno(const char *string){        log_func(NULL, G_LOG_LEVEL_WARNING,                 va("%s: %s", string, strerror(errno)));}static void second_instance(char *str){        g_debug("Received '%s' from fifo", str);        if (str[0] == '0' || str[0] == 'H' || str[0] == 'h')                window_hide();        else if (str[0] == '1' || str[0] == 'S' || str[0] == 's')                window_show();        else if (str[0] == 'T' || str[0] == 't')                window_toggle();}int main(int argc, char *argv[]){        GError *error;        const char *token;        /* Initialize GTK+ */        error = NULL;        if (!gtk_init_with_args(&argc, &argv,                                "grid-entry handwriting input panel",                                command_line_opts, NULL, &error))                return 0;        /* Try to open the log-file */        if (log_filename)                log_file = fopen(log_filename, "w");        /* Setup log handler */        log_level = 1 << log_level;        g_log_set_handler(NULL, -1, (GLogFunc)log_func, NULL);        /* See if the program is already running */        g_message("Starting " PACKAGE_STRING);        create_user_dir();        if (!window_embedded &&            single_instance_init((SingleInstanceFunc)second_instance,                                 window_force_hide ? "0" : "1")) {                gdk_notify_startup_complete();                g_message(PACKAGE_NAME " already running, quitting");                return 0;        }#ifdef HAVE_GNOME        /* Initialize GNOME for the Help button */        gnome_program_init(PACKAGE, VERSION, LIBGNOME_MODULE,                           argc, argv, NULL);#endif        /* Component initilization */        if (key_event_init()) {                GtkWidget *dialog;                dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,                                                GTK_MESSAGE_ERROR,                                                GTK_BUTTONS_OK,                                                "Xtest extension not "                                                "supported");                gtk_window_set_title(GTK_WINDOW(dialog), "Initilization Error");                gtk_message_dialog_format_secondary_text(                        GTK_MESSAGE_DIALOG(dialog),                        "Your Xserver does not support the Xtest extension. "                        PACKAGE_NAME " cannot generate keystrokes without it.");                gtk_dialog_run(GTK_DIALOG(dialog));                gtk_widget_destroy(dialog);        }        recognize_init();        /* Read profile */        if (profile_open_read()) {                profile_line = 1;                g_message("Parsing profile");                do {                        unsigned int i;                        token = profile_read();                        if (!token[0]) {                                if (profile_read_next())                                        continue;                                break;                        }                        for (i = 0; i < NUM_PROFILE_CMDS; i++)                                if (!g_ascii_strcasecmp(profile_cmds[i].name,                                                        token)) {                                        if (profile_cmds[i].read_func)                                                profile_cmds[i].read_func();                                        break;                                }                        if (i == NUM_PROFILE_CMDS)                                g_warning("Unrecognized profile command '%s'",                                          token);                        profile_line++;                } while (profile_read_next());                profile_close();                g_debug("Parsed %d commands", profile_line - 1);        }        /* After loading samples and block enabled/disabled information,           update the samples */        update_enabled_samples();        /* Ensure that if there is a crash, data is saved properly */        hook_signals();        atexit(cleanup);        /* Initialize the interface */        g_message("Running interface");        window_create();        /* Startup notification is sent when the first window shows but in if           the window was closed during last start, it won't show at all so           we need to do this manually */        gdk_notify_startup_complete();        /* Run the interface */        if (!samples_loaded() && !keyboard_only)                startup_splash_show();        gtk_main();        cleanup();        /* Session statistics */        if (characters && inputs && log_level >= G_LOG_LEVEL_DEBUG) {                g_message("Session statistics --");                g_debug("Average strength: %d%%", strength_sum / inputs);                g_debug("Rewrites: %d out of %d inputs (%d%%)",                        rewrites, inputs, rewrites * 100 / inputs);                g_debug("Corrections: %d out of %d characters (%d%%)",                        corrections, characters,                        corrections * 100 / characters);                g_debug("KeyCodes overwrites: %d out of %d uses (%d%%)",                        key_overwrites, key_overwrites + key_recycles,                        key_recycles + key_overwrites ? key_overwrites * 100 /                        (key_recycles + key_overwrites) : 0);        }        return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -