?? nodes.c
字號:
#include <stdio.h>#include <string.h>#include <stdlib.h>#include <sys/stat.h>#include <sys/types.h>#include "y.tab.h"#include "nodes.h"#include "x_malloc.h"extern int map_file (const char *path, unsigned long **bmap);extern dev_t get_dev (const char *path);extern struct node *config_node;extern char *boot_dev;struct compressed_node *cnode = NULL;int num_cnodes;/* * compress parser nodes into kernel image nodes, * and do some error checking on the parser nodes. * Also calculates how many kernel images are listed. */int compress_nodes (void){ struct compressed_node *cnodes = NULL, **nodep = &cnode; struct node *node = config_node, *prevnode; struct node *sub, *prevsub; int len; num_cnodes = 0; while (node) { prevnode = node; switch (node->type) { case KERNEL: cnodes = xmalloc (sizeof (struct compressed_node)); num_cnodes += 1; cnodes->type = KERNEL; sub = node->u.n; while (sub) { prevsub = sub; switch (sub->type) { case ARGS: cnodes->args = sub->u.string; sub = sub->next; break; case FLAGS: cnodes->flags = sub->u.flags; sub = sub->next; break; case NAME: if (cnodes->name) { fprintf (stderr, "KERNEL has multiple names\n"); exit (1); } cnodes->name = sub->u.string; sub = sub->next; break; case INITRD: if (cnodes->initrd) { fprintf (stderr, "KERNEL has multiple initrds\n"); exit (1); } cnodes->initrd_path = sub->u.string; len = map_file(cnodes->initrd_path, &cnodes->initrd); if (len < 0) { free (cnodes); cnodes = NULL; } cnodes->initrd_size = len; sub = sub->next; break; case PASSWORD: if (cnodes->passwd) { fprintf (stderr, "KERNEL has multiple passwords\n"); exit (1); } cnodes->passwd = sub->u.string; sub = sub->next; break; case PATH: if (cnodes->path) { fprintf (stderr, "KERNEL has multiple paths\n"); exit (1); } cnodes->path = sub->u.string; len = map_file(cnodes->path, &cnodes->bmap); if (len < 0) { free (cnodes); cnodes = NULL; } cnodes->bmap_size = len; sub = sub->next; break; case RAMDISK: cnodes->ramdisk_size = sub->u.size; sub = sub->next; break; case RDSTART: cnodes->rdstart = sub->u.offset; sub = sub->next; break; case ROOT: cnodes->root = get_dev(sub->u.string); sub = sub->next; break; default: abort (); } free (prevsub); if (!cnodes) return -1; } if (cnodes) { *nodep = cnodes; nodep = &cnodes->next; } break; case RISCOS: cnodes = xmalloc (sizeof (struct compressed_node)); num_cnodes += 1; *nodep = cnodes; nodep = &cnodes->next; cnodes->type = RISCOS; sub = node->u.n; while (sub) { prevsub = sub; switch (sub->type) { case NAME: if (cnodes->name) { fprintf (stderr, "RISCOS has multiple names\n"); exit (1); } cnodes->name = sub->u.string; sub = sub->next; break; case ARGS: cnodes->args = sub->u.string; sub = sub->next; break; default: abort (); } free (prevsub); } break; case CONFIG: sub = node->u.n; while (sub) { prevsub = sub; switch (sub->type) { case ROOT: boot_dev = sub->u.string; sub = sub->next; break; default: abort (); } free (prevsub); } break; } node = node->next; free (prevnode); } return 0;} void dump_cnode (struct compressed_node *node){ if (boot_dev) printf("Boot device: %s\n", boot_dev); while (node) { switch (node->type) { case KERNEL: printf ("Kernel:\n"); if (node->name) printf(" Name: %s\n", node->name); if (node->path) printf(" Path: %s\n", node->path); if (node->args) printf(" Args: %s\n", node->args); if (node->initrd) printf(" Initrd: %s\n", node->initrd); if (node->root) printf(" Root: %x\n", node->root); printf(" Flags: %lx\n", node->flags); printf("Ramdisk: %lx\n", node->ramdisk_size); break; case RISCOS: printf ("RiscOS:\n"); if (node->name) printf(" Name: %s\n", node->name); if (node->path) printf(" Path: %s\n", node->path); if (node->args) printf(" Args: %s\n", node->args); break; } node = node->next; }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -