~ubuntu-branches/ubuntu/trusty/grub2/trusty-updates

« back to all changes in this revision

Viewing changes to grub-core/script/lexer.c

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-09-13 18:02:04 UTC
  • mfrom: (1.17.15 upstream)
  • mto: (17.6.27 experimental)
  • mto: This revision was merged to the branch mainline in revision 145.
  • Revision ID: package-import@ubuntu.com-20120913180204-mojnmocbimlom4im
Tags: upstream-2.00
ImportĀ upstreamĀ versionĀ 2.00

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <grub/misc.h>
24
24
#include <grub/mm.h>
25
25
#include <grub/script_sh.h>
 
26
#include <grub/i18n.h>
26
27
 
 
28
#define yytext_ptr char *
27
29
#include "grub_script.tab.h"
28
30
#include "grub_script.yy.h"
29
31
 
106
108
  if (lexer->recordpos + len + 1 > lexer->recordlen)
107
109
    {
108
110
      old = lexer->recording;
109
 
      lexer->recordlen = grub_max (len, lexer->recordlen) * 2;
 
111
      if (lexer->recordlen < len)
 
112
        lexer->recordlen = len;
 
113
      lexer->recordlen *= 2;
110
114
      lexer->recording = grub_realloc (lexer->recording, lexer->recordlen);
111
115
      if (!lexer->recording)
112
116
        {
126
130
grub_script_lexer_yywrap (struct grub_parser_param *parserstate,
127
131
                          const char *input)
128
132
{
129
 
  int len = 0;
 
133
  grub_size_t len = 0;
130
134
  char *p = 0;
131
135
  char *line = 0;
132
136
  YY_BUFFER_STATE buffer;
137
141
 
138
142
  if (! lexerstate->getline && ! input)
139
143
    {
140
 
      grub_script_yyerror (parserstate, "unexpected end of file");
 
144
      grub_script_yyerror (parserstate, N_("unexpected end of file"));
141
145
      return 1;
142
146
    }
143
147
 
147
151
  else
148
152
    line = grub_strdup (input);
149
153
 
 
154
  if (! line)
 
155
    {
 
156
      grub_script_yyerror (parserstate, N_("out of memory"));
 
157
      return 1;
 
158
    }
 
159
 
 
160
  len = grub_strlen (line);
 
161
 
150
162
  /* Ensure '\n' at the end.  */
151
 
  if (line && line[0] == '\0')
 
163
  if (line[0] == '\0')
152
164
    {
153
165
      grub_free (line);
154
166
      line = grub_strdup ("\n");
155
167
    }
156
 
 
157
 
  if (line && (len = grub_strlen(line)) && line[len - 1] != '\n')
 
168
  else if (len && line[len - 1] != '\n')
158
169
    {
159
170
      p = grub_realloc (line, len + 2);
160
171
      if (p)
167
178
 
168
179
  if (! line)
169
180
    {
170
 
      grub_script_yyerror (parserstate, "out of memory");
 
181
      grub_script_yyerror (parserstate, N_("out of memory"));
171
182
      return 1;
172
183
    }
173
184
 
205
216
 
206
217
struct grub_lexer_param *
207
218
grub_script_lexer_init (struct grub_parser_param *parser, char *script,
208
 
                        grub_reader_getline_t getline)
 
219
                        grub_reader_getline_t arg_getline)
209
220
{
210
221
  struct grub_lexer_param *lexerstate;
211
222
 
221
232
      return 0;
222
233
    }
223
234
 
224
 
  lexerstate->getline = getline;        /* rest are all zeros already */
 
235
  lexerstate->getline = arg_getline;    /* rest are all zeros already */
225
236
  if (yylex_init (&lexerstate->yyscanner))
226
237
    {
227
238
      grub_free (lexerstate->text);