]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - GRUB2/MOD_SRC/grub-2.04/grub-core/commands/echo.c
update Japanese translation (#2077)
[Ventoy.git] / GRUB2 / MOD_SRC / grub-2.04 / grub-core / commands / echo.c
1 /* echo.c - Command to display a line of text */
2 /*
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2006,2007,2010 Free Software Foundation, Inc.
5 *
6 * GRUB 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 3 of the License, or
9 * (at your option) any later version.
10 *
11 * GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include <grub/dl.h>
21 #include <grub/misc.h>
22 #include <grub/extcmd.h>
23 #include <grub/i18n.h>
24 #include <grub/term.h>
25
26 GRUB_MOD_LICENSE ("GPLv3+");
27
28 extern const char *ventoy_get_vmenu_title(const char *vMenu);
29
30 static const struct grub_arg_option options[] =
31 {
32 {0, 'n', 0, N_("Do not output the trailing newline."), 0, 0},
33 {0, 'e', 0, N_("Enable interpretation of backslash escapes."), 0, 0},
34 {0, 'v', 0, N_("ventoy menu language."), 0, 0},
35 {0, 'V', 0, N_("ventoy menu language with pre-newline."), 0, 0},
36 {0, 0, 0, 0, 0, 0}
37 };
38
39 static grub_err_t
40 grub_cmd_echo (grub_extcmd_context_t ctxt, int argc, char **args)
41 {
42 struct grub_arg_list *state = ctxt->state;
43 char ch;
44 int vtmenu = 0;
45 int newline = 1;
46 int i;
47
48 /* Check if `-n' was used. */
49 if (state[0].set)
50 newline = 0;
51
52 if (state[2].set || state[3].set)
53 vtmenu = 1;
54
55 for (i = 0; i < argc; i++)
56 {
57 char *arg = *args;
58 /* Unescaping results in a string no longer than the original. */
59 char *unescaped = grub_malloc (grub_strlen (arg) + 1);
60 char *p = unescaped;
61 args++;
62
63 if (!unescaped)
64 return grub_errno;
65
66 while (*arg)
67 {
68 /* In case `-e' is used, parse backslashes. */
69 if (*arg == '\\' && state[1].set)
70 {
71 arg++;
72 if (*arg == '\0')
73 break;
74
75 switch (*arg)
76 {
77 case '\\':
78 *p++ = '\\';
79 break;
80
81 case 'a':
82 *p++ = '\a';
83 break;
84
85 case 'c':
86 newline = 0;
87 break;
88
89 case 'f':
90 *p++ = '\f';
91 break;
92
93 case 'n':
94 *p++ = '\n';
95 break;
96
97 case 'r':
98 *p++ = '\r';
99 break;
100
101 case 't':
102 *p++ = '\t';
103 break;
104
105 case 'v':
106 *p++ = '\v';
107 break;
108 }
109 arg++;
110 continue;
111 }
112
113 /* This was not an escaped character, or escaping is not
114 enabled. */
115 *p++ = *arg;
116 arg++;
117 }
118
119 *p = '\0';
120
121 if (vtmenu && grub_strncmp(unescaped, "VTMENU_", 7) == 0)
122 {
123 p = unescaped;
124 while ((*p >= 'A' && *p <= 'Z') || *p == '_')
125 {
126 p++;
127 }
128
129 ch = *p;
130 *p = 0;
131 if (state[3].set)
132 {
133 grub_xputs("\n");
134 }
135 grub_xputs(ventoy_get_vmenu_title(unescaped));
136
137 *p = ch;
138 grub_xputs(p);
139 }
140 else
141 {
142 grub_xputs (unescaped);
143 }
144
145 grub_free (unescaped);
146
147 /* If another argument follows, insert a space. */
148 if ((0 == vtmenu) && (i != argc - 1))
149 grub_printf (" " );
150 }
151
152 if (newline)
153 grub_printf ("\n");
154
155 grub_refresh ();
156
157 return 0;
158 }
159
160 static grub_extcmd_t cmd;
161 \f
162 GRUB_MOD_INIT(echo)
163 {
164 cmd = grub_register_extcmd ("echo", grub_cmd_echo,
165 GRUB_COMMAND_ACCEPT_DASH
166 | GRUB_COMMAND_OPTIONS_AT_START,
167 N_("[-e|-n] STRING"), N_("Display a line of text."),
168 options);
169 }
170
171 GRUB_MOD_FINI(echo)
172 {
173 grub_unregister_extcmd (cmd);
174 }