~ubuntu-branches/ubuntu/lucid/grub2/lucid

« back to all changes in this revision

Viewing changes to normal/function.c

  • Committer: Bazaar Package Importer
  • Author(s): Otavio Salvador
  • Date: 2006-01-05 15:20:40 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060105152040-1ab076d4n3y2o5yf
Tags: 1.92-1
* New upstream release.
  - Add support for GPT partition table format.
  - Add a new command "play" to play an audio file on PC.
  - Add support for Linux/ADFS partition table format.
  - Add support for BASH-like scripting.
  - Add support for Apple HFS+ filesystems.
* 01_fix_grub-install.patch: Added. Fix grub-install to use
  /bin/grub-mkimage instead of /sbin/grub-mkimage. Closes: #338824
* Do not use CDBS tarball mode anymore. Closes: #344272  

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* script.c */
 
2
/*
 
3
 *  GRUB  --  GRand Unified Bootloader
 
4
 *  Copyright (C) 2005  Free Software Foundation, Inc.
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; either version 2 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with this program; if not, write to the Free Software
 
18
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
19
 */
 
20
 
 
21
#include <grub/misc.h>
 
22
#include <grub/script.h>
 
23
#include <grub/parser.h>
 
24
#include <grub/mm.h>
 
25
 
 
26
static grub_script_function_t grub_script_function_list;
 
27
 
 
28
grub_script_function_t
 
29
grub_script_function_create (char *functionname, struct grub_script *cmd)
 
30
{
 
31
  grub_script_function_t func;
 
32
  grub_script_function_t *p;
 
33
  
 
34
  func = (grub_script_function_t) grub_malloc (sizeof (*func));
 
35
  if (! func)
 
36
    return 0;
 
37
 
 
38
  func->name = grub_strdup (functionname);
 
39
  if (! func->name)
 
40
    {
 
41
      grub_free (func);
 
42
      return 0;
 
43
    }
 
44
  
 
45
  func->func = cmd;
 
46
 
 
47
  /* Keep the list sorted for simplicity.  */
 
48
  p = &grub_script_function_list;
 
49
  while (*p)
 
50
    {
 
51
      if (grub_strcmp ((*p)->name, functionname) >= 0)
 
52
        break;
 
53
 
 
54
      p = &((*p)->next);
 
55
    }
 
56
 
 
57
  /* If the function already exists, overwrite the old function.  */
 
58
  if (*p && grub_strcmp ((*p)->name, functionname) == 0)
 
59
    {
 
60
      grub_script_function_t q;
 
61
 
 
62
      q = *p;
 
63
      grub_script_free (q->func);
 
64
      q->func = cmd;
 
65
      grub_free (func);
 
66
      func = q;
 
67
    }
 
68
  else
 
69
    {
 
70
      func->next = *p;
 
71
      *p = func;
 
72
    }
 
73
 
 
74
  return func;
 
75
}
 
76
 
 
77
void
 
78
grub_script_function_remove (const char *name)
 
79
{
 
80
  grub_script_function_t *p, q;
 
81
 
 
82
  for (p = &grub_script_function_list, q = *p; q; p = &(q->next), q = q->next)
 
83
    if (grub_strcmp (name, q->name) == 0)
 
84
      {
 
85
        *p = q->next;
 
86
        grub_free (q->name);
 
87
        grub_script_free (q->func);
 
88
        grub_free (q);
 
89
        break;
 
90
      }
 
91
}
 
92
 
 
93
grub_script_function_t
 
94
grub_script_function_find (char *functionname)
 
95
{
 
96
  grub_script_function_t func;
 
97
 
 
98
  for (func = grub_script_function_list; func; func = func->next)
 
99
    if (grub_strcmp (functionname, func->name) == 0)
 
100
      break;
 
101
 
 
102
  if (! func)
 
103
    grub_error (GRUB_ERR_UNKNOWN_COMMAND, "unknown command `%s'", functionname);
 
104
 
 
105
  return func;
 
106
}
 
107
 
 
108
int
 
109
grub_script_function_iterate (int (*iterate) (grub_script_function_t))
 
110
{
 
111
  grub_script_function_t func;
 
112
  
 
113
  for (func = grub_script_function_list; func; func = func->next)
 
114
    if (iterate (func))
 
115
      return 1;
 
116
  
 
117
  return 0;
 
118
}
 
119
 
 
120
int
 
121
grub_script_function_call (grub_script_function_t func,
 
122
                           int argc __attribute__((unused)),
 
123
                           char **args __attribute__((unused)))
 
124
{
 
125
  /* XXX: Arguments are not supported yet.  */
 
126
  return grub_script_execute (func->func);
 
127
}