Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* ----------------------------------------------------------------------- *
- *
- * Copyright 2011 Mariano Street
- * Copyright 2009 Intel Corporation; author: H. Peter Anvin
- * Copyright 2009 Erwan Velu - All Rights Reserved
- *
- * This file is based on kbdmap.c and ifcpu.c.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * ----------------------------------------------------------------------- */
- #include <alloca.h>
- #include <stdio.h>
- #include <string.h>
- #include <console.h>
- #include <syslinux/boot.h>
- #include <syslinux/loadfile.h>
- #include <syslinux/keyboard.h>
- static inline void error(const char *msg)
- {
- fputs(msg, stderr);
- }
- static inline int load_keymap(char *file)
- {
- const struct syslinux_keyboard_map *const kmap = syslinux_keyboard_map();
- size_t map_size;
- void *kbdmap;
- if (kmap->version != 1) {
- error("Syslinux core version mismatch\n");
- return 1;
- }
- if (loadfile(file, &kbdmap, &map_size)) {
- error("Keyboard map file load error\n");
- return 1;
- }
- if (map_size != kmap->length) {
- error("Keyboard map file format error\n");
- return 1;
- }
- memcpy(kmap->map, kbdmap, map_size);
- return 0;
- }
- inline static void boot_args(char **args)
- {
- // Join strings from an array into a single string.
- int len = 0, a = 0;
- char **pp;
- const char *p;
- char c, *q, *str;
- for (pp = args; *pp; pp++)
- len += strlen(*pp) + 1;
- q = str = alloca(len);
- for (pp = args; *pp; pp++) {
- p = *pp;
- while (c = *p++)
- *q++ = c;
- *q++ = ' ';
- a = 1;
- }
- q -= a;
- *q = '\0';
- if (!str[0])
- syslinux_run_default();
- else
- syslinux_run_command(str);
- }
- int main(int argc, char *argv[])
- {
- openconsole(&dev_null_r, &dev_stdcon_w);
- if (argc < 3) {
- error("Usage: kbdmap <mapfile> <command> [<command parameters>]\n");
- return 1;
- }
- if (load_keymap(argv[1]) == 1)
- return 1;
- boot_args(&argv[2]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment