8367695cff
* genkernsyms.sh: Updated copyright information. * genmk.rb: Likewise. * genmodsrc.sh: Likewise. * gensymlist.sh: Likewise. * boot/i386/pc/boot.S: Likewise. * boot/i386/pc/diskboot.S: Likewise. * disk/i386/pc/biosdisk.c: Likewise. * disk/i386/pc/partition.c: Likewise. * font/manager.c: Likewise. * fs/ext2.c: Likewise. * fs/fat.c: Likewise. * include/pupa/boot.h: Likewise. * include/pupa/device.h: Likewise. * include/pupa/disk.h: Likewise. * include/pupa/dl.h: Likewise. * include/pupa/elf.h: Likewise. * include/pupa/err.h: Likewise. * include/pupa/file.h: Likewise. * include/pupa/font.h: Likewise. * include/pupa/fs.h: Likewise. * include/pupa/kernel.h: Likewise. * include/pupa/loader.h: Likewise. * include/pupa/misc.h: Likewise. * include/pupa/mm.h: Likewise. * include/pupa/net.h: Likewise. * include/pupa/normal.h: Likewise. * include/pupa/rescue.h: Likewise. * include/pupa/setjmp.h: Likewise. * include/pupa/symbol.h: Likewise. * include/pupa/term.h: Likewise. * include/pupa/types.h: Likewise. * include/pupa/i386/setjmp.h: Likewise. * include/pupa/i386/types.h: Likewise. * include/pupa/i386/pc/biosdisk.h: Likewise. * include/pupa/i386/pc/boot.h: Likewise. * include/pupa/i386/pc/console.h: Likewise. * include/pupa/i386/pc/init.h: Likewise. * include/pupa/i386/pc/kernel.h: Likewise. * include/pupa/i386/pc/linux.h: Likewise. * include/pupa/i386/pc/loader.h: Likewise. * include/pupa/i386/pc/memory.h: Likewise. * include/pupa/i386/pc/multiboot.h: Likewise. * include/pupa/i386/pc/partition.h: Likewise. * include/pupa/i386/pc/time.h: Likewise. * include/pupa/i386/pc/vga.h: Likewise. * include/pupa/i386/pc/util/biosdisk.h: Likewise. * include/pupa/util/getroot.h: Likewise. * include/pupa/util/misc.h: Likewise. * include/pupa/util/resolve.h: Likewise. * kern/device.c: Likewise. * kern/disk.c: Likewise. * kern/dl.c: Likewise. * kern/err.c: Likewise. * kern/file.c: Likewise. * kern/fs.c: Likewise. * kern/loader.c: Likewise. * kern/main.c: Likewise. * kern/misc.c: Likewise. * kern/mm.c: Likewise. * kern/rescue.c: Likewise. * kern/term.c: Likewise. * kern/i386/dl.c: Likewise. * kern/i386/pc/init.c: Likewise. * kern/i386/pc/lzo1x.S: Likewise. * kern/i386/pc/startup.S: Likewise. * loader/i386/pc/chainloader.c: Likewise. * loader/i386/pc/linux.c: Likewise. * loader/i386/pc/multiboot.c: Likewise. * normal/cmdline.c: Likewise. * normal/command.c: Likewise. * normal/main.c: Likewise. * normal/menu.c: Likewise. * normal/i386/setjmp.S: Likewise. * term/i386/pc/console.c: Likewise. * term/i386/pc/vga.c: Likewise. * util/console.c: Likewise. * util/genmoddep.c: Likewise. * util/misc.c: Likewise. * util/pupa-emu.c: Likewise. * util/resolve.c: Likewise. * util/unifont2pff.rb: Likewise. * util/i386/pc/biosdisk.c: Likewise. * util/i386/pc/getroot.c: Likewise. * util/i386/pc/pupa-mkimage.c: Likewise. * util/i386/pc/pupa-setup.c: Likewise.
279 lines
4.8 KiB
C
279 lines
4.8 KiB
C
/*
|
|
* PUPA -- Preliminary Universal Programming Architecture for GRUB
|
|
* Copyright (C) 2002 Free Software Foundation, Inc.
|
|
*
|
|
* 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 2 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, write to the Free Software
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <stdarg.h>
|
|
|
|
#define BUF_SIZE 1024
|
|
#define SYMTAB_SIZE 509
|
|
|
|
struct symbol
|
|
{
|
|
const char *name;
|
|
const char *mod;
|
|
struct symbol *next;
|
|
};
|
|
|
|
struct module
|
|
{
|
|
const char *name;
|
|
struct module *next;
|
|
};
|
|
|
|
static char buf[BUF_SIZE];
|
|
static struct symbol *symtab[SYMTAB_SIZE];
|
|
|
|
static void
|
|
err (const char *fmt, ...)
|
|
{
|
|
va_list ap;
|
|
|
|
fprintf (stderr, "genmoddep: error: ");
|
|
|
|
va_start (ap, fmt);
|
|
vfprintf (stderr, fmt, ap);
|
|
va_end (ap);
|
|
|
|
fputc ('\n', stderr);
|
|
exit (1);
|
|
}
|
|
|
|
static void *
|
|
xmalloc (size_t size)
|
|
{
|
|
void *p;
|
|
|
|
p = malloc (size);
|
|
if (! p)
|
|
err ("out of memory");
|
|
|
|
return p;
|
|
}
|
|
|
|
static char *
|
|
xstrdup (const char *str)
|
|
{
|
|
char *s;
|
|
size_t len;
|
|
|
|
len = strlen (str);
|
|
s = (char *) xmalloc (len + 1);
|
|
memcpy (s, str, len + 1);
|
|
|
|
return s;
|
|
}
|
|
|
|
static void
|
|
chomp (char *str)
|
|
{
|
|
int end;
|
|
|
|
end = strlen (str) - 1;
|
|
if (end < 0)
|
|
err ("empty string");
|
|
|
|
if (str[end] == '\n')
|
|
str[end] = '\0';
|
|
}
|
|
|
|
static unsigned
|
|
symbol_hash (const char *s)
|
|
{
|
|
unsigned key = 0;
|
|
|
|
while (*s)
|
|
key = key * 65599 + *s++;
|
|
|
|
return (key + (key >> 5)) % SYMTAB_SIZE;
|
|
}
|
|
|
|
static struct symbol *
|
|
get_symbol (const char *name)
|
|
{
|
|
unsigned k;
|
|
struct symbol *sym;
|
|
|
|
k = symbol_hash (name);
|
|
for (sym = symtab[k]; sym; sym = sym->next)
|
|
if (strcmp (sym->name, name) == 0)
|
|
return sym;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void
|
|
add_symbol (const char *name, const char *mod)
|
|
{
|
|
unsigned k;
|
|
struct symbol *sym;
|
|
|
|
if (get_symbol (name))
|
|
err ("duplicated symbol: %s", name);
|
|
|
|
sym = (struct symbol *) xmalloc (sizeof (*sym));
|
|
sym->name = xstrdup (name);
|
|
sym->mod = xstrdup (mod);
|
|
|
|
k = symbol_hash (name);
|
|
sym->next = symtab[k];
|
|
symtab[k] = sym;
|
|
}
|
|
|
|
static void
|
|
free_symbols (void)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < SYMTAB_SIZE; i++)
|
|
{
|
|
struct symbol *p, *q;
|
|
|
|
p = symtab[i];
|
|
while (p)
|
|
{
|
|
q = p->next;
|
|
free ((void *) p->name);
|
|
free ((void *) p->mod);
|
|
free (p);
|
|
p = q;
|
|
}
|
|
}
|
|
}
|
|
|
|
static void
|
|
read_defined_symbols (FILE *fp)
|
|
{
|
|
while (fgets (buf, sizeof (buf), fp))
|
|
{
|
|
char *p;
|
|
|
|
if (! *buf)
|
|
err ("empty symbol name: %s", buf);
|
|
|
|
p = strchr (buf, ' ');
|
|
if (! p)
|
|
err ("invalid line format: %s", buf);
|
|
|
|
p++;
|
|
|
|
if (! *p)
|
|
err ("empty module name: %s", buf);
|
|
|
|
*(p - 1) = '\0';
|
|
chomp (p);
|
|
|
|
add_symbol (buf, p);
|
|
}
|
|
}
|
|
|
|
static void
|
|
add_module (struct module **head, const char *name)
|
|
{
|
|
struct module *mod;
|
|
|
|
for (mod = *head; mod; mod = mod->next)
|
|
if (strcmp (mod->name, name) == 0)
|
|
return;
|
|
|
|
mod = (struct module *) xmalloc (sizeof (*mod));
|
|
mod->name = xstrdup (name);
|
|
|
|
mod->next = *head;
|
|
*head = mod;
|
|
}
|
|
|
|
static void
|
|
free_modules (struct module *head)
|
|
{
|
|
struct module *next;
|
|
|
|
while (head)
|
|
{
|
|
next = head->next;
|
|
free ((void *) head->name);
|
|
free (head);
|
|
head = next;
|
|
}
|
|
}
|
|
|
|
static void
|
|
find_dependencies (FILE *fp)
|
|
{
|
|
char *mod_name;
|
|
struct module *mod_list = 0;
|
|
struct module *mod;
|
|
|
|
if (! fgets (buf, sizeof (buf), fp) || buf[0] == '\n' || buf[0] == '\0')
|
|
err ("no module name");
|
|
|
|
chomp (buf);
|
|
mod_name = xstrdup (buf);
|
|
|
|
while (fgets (buf, sizeof (buf), fp))
|
|
{
|
|
struct symbol *sym;
|
|
|
|
chomp (buf);
|
|
sym = get_symbol (buf);
|
|
if (! sym)
|
|
err ("%s in %s is not defined", buf, mod_name);
|
|
|
|
add_module (&mod_list, sym->mod);
|
|
}
|
|
|
|
printf ("%s:", mod_name);
|
|
|
|
for (mod = mod_list; mod; mod = mod->next)
|
|
if (strcmp (mod->name, "kernel") != 0)
|
|
printf (" %s", mod->name);
|
|
|
|
putchar ('\n');
|
|
|
|
free_modules (mod_list);
|
|
}
|
|
|
|
int
|
|
main (int argc, char *argv[])
|
|
{
|
|
int i;
|
|
|
|
/* First, get defined symbols. */
|
|
read_defined_symbols (stdin);
|
|
|
|
/* Second, find the dependecies. */
|
|
for (i = 1; i < argc; i++)
|
|
{
|
|
FILE *fp;
|
|
|
|
fp = fopen (argv[i], "r");
|
|
if (! fp)
|
|
err ("cannot open %s", argv[i]);
|
|
|
|
find_dependencies (fp);
|
|
|
|
fclose (fp);
|
|
}
|
|
|
|
/* Last, free memory. */
|
|
free_symbols ();
|
|
|
|
return 0;
|
|
}
|