Subversion Repositories Kolibri OS

Rev

Rev 5222 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5222 Rev 6324
Line 1... Line 1...
1
/* input_scrub.c - Break up input buffers into whole numbers of lines.
1
/* input_scrub.c - Break up input buffers into whole numbers of lines.
2
   Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-
 
3
   2000, 2001, 2003, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
-
 
4
   Free Software Foundation, Inc.
2
   Copyright (C) 1987-2015 Free Software Foundation, Inc.
Line 5... Line 3...
5
 
3
 
Line 6... Line 4...
6
   This file is part of GAS, the GNU Assembler.
4
   This file is part of GAS, the GNU Assembler.
7
 
5
 
Line 137... Line 135...
137
   area, which can be restored by passing it to input_scrub_pop().  */
135
   area, which can be restored by passing it to input_scrub_pop().  */
Line 138... Line 136...
138
 
136
 
139
static struct input_save *
137
static struct input_save *
140
input_scrub_push (char *saved_position)
138
input_scrub_push (char *saved_position)
141
{
139
{
Line 142... Line 140...
142
  register struct input_save *saved;
140
  struct input_save *saved;
Line 143... Line 141...
143
 
141
 
144
  saved = (struct input_save *) xmalloc (sizeof *saved);
142
  saved = (struct input_save *) xmalloc (sizeof *saved);
Line 164... Line 162...
164
  logical_input_file = (char *) NULL;
162
  logical_input_file = (char *) NULL;
165
  buffer_length = input_file_buffer_size ();
163
  buffer_length = input_file_buffer_size ();
166
  sb_index = -1;
164
  sb_index = -1;
Line 167... Line 165...
167
 
165
 
168
  buffer_start = (char *) xmalloc ((BEFORE_SIZE + buffer_length
166
  buffer_start = (char *) xmalloc ((BEFORE_SIZE + buffer_length
169
                                    + buffer_length + AFTER_SIZE));
167
                                    + buffer_length + AFTER_SIZE + 1));
Line 170... Line 168...
170
  memcpy (buffer_start, BEFORE_STRING, (int) BEFORE_SIZE);
168
  memcpy (buffer_start, BEFORE_STRING, (int) BEFORE_SIZE);
171
 
169
 
Line 209... Line 207...
209
  input_file_begin ();
207
  input_file_begin ();
Line 210... Line 208...
210
 
208
 
Line 211... Line 209...
211
  buffer_length = input_file_buffer_size ();
209
  buffer_length = input_file_buffer_size ();
212
 
210
 
213
  buffer_start = (char *) xmalloc ((BEFORE_SIZE + buffer_length
211
  buffer_start = (char *) xmalloc ((BEFORE_SIZE + buffer_length
Line 214... Line 212...
214
                                    + buffer_length + AFTER_SIZE));
212
                                    + buffer_length + AFTER_SIZE + 1));
215
  memcpy (buffer_start, BEFORE_STRING, (int) BEFORE_SIZE);
213
  memcpy (buffer_start, BEFORE_STRING, (int) BEFORE_SIZE);
216
 
214
 
Line 311... Line 309...
311
}
309
}
Line 312... Line 310...
312
 
310
 
313
char *
311
char *
314
input_scrub_next_buffer (char **bufp)
312
input_scrub_next_buffer (char **bufp)
315
{
313
{
Line 316... Line 314...
316
  register char *limit;		/*->just after last char of buffer.  */
314
  char *limit;		/*->just after last char of buffer.  */
317
 
315
 
318
  if (sb_index != (size_t) -1)
316
  if (sb_index != (size_t) -1)
319
    {
317
    {
Line 329... Line 327...
329
	      md_macro_end ();
327
	      md_macro_end ();
330
#endif
328
#endif
331
	    }
329
	    }
332
	  --macro_nest;
330
	  --macro_nest;
333
	  partial_where = NULL;
331
	  partial_where = NULL;
-
 
332
	  partial_size = 0;
334
	  if (next_saved_file != NULL)
333
	  if (next_saved_file != NULL)
335
	    *bufp = input_scrub_pop (next_saved_file);
334
	    *bufp = input_scrub_pop (next_saved_file);
336
	  return partial_where;
335
	  return partial_where;
337
	}
336
	}
Line 341... Line 340...
341
      *bufp = from_sb.ptr + sb_index;
340
      *bufp = from_sb.ptr + sb_index;
342
      sb_index = from_sb.len;
341
      sb_index = from_sb.len;
343
      return partial_where;
342
      return partial_where;
344
    }
343
    }
Line 345... Line -...
345
 
-
 
346
  *bufp = buffer_start + BEFORE_SIZE;
-
 
347
 
344
 
348
  if (partial_size)
345
  if (partial_size)
349
    {
346
    {
350
      memmove (buffer_start + BEFORE_SIZE, partial_where,
347
      memmove (buffer_start + BEFORE_SIZE, partial_where,
351
	       (unsigned int) partial_size);
348
	       (unsigned int) partial_size);
352
      memcpy (buffer_start + BEFORE_SIZE, save_source, AFTER_SIZE);
349
      memcpy (buffer_start + BEFORE_SIZE, save_source, AFTER_SIZE);
353
    }
-
 
354
  limit = input_file_give_next_buffer (buffer_start
-
 
355
				       + BEFORE_SIZE
-
 
356
				       + partial_size);
-
 
357
  if (limit)
-
 
358
    {
-
 
359
      register char *p;		/* Find last newline.  */
-
 
360
      /* Terminate the buffer to avoid confusing TC_EOL_IN_INSN.  */
-
 
361
      *limit = '\0';
-
 
362
      for (p = limit - 1; *p != '\n' || TC_EOL_IN_INSN (p); --p)
-
 
363
	;
-
 
Line 364... Line 350...
364
      ++p;
350
    }
365
 
351
 
366
      while (p <= buffer_start + BEFORE_SIZE)
352
  while (1)
Line 367... Line -...
367
	{
-
 
368
	  int limoff;
-
 
369
 
-
 
370
	  limoff = limit - buffer_start;
-
 
371
	  buffer_length += input_file_buffer_size ();
-
 
372
	  buffer_start = (char *) xrealloc (buffer_start,
-
 
373
                                            (BEFORE_SIZE
353
    {
374
                                             + 2 * buffer_length
354
      char *p;
375
                                             + AFTER_SIZE));
-
 
-
 
355
 
-
 
356
      *bufp = buffer_start + BEFORE_SIZE;
376
	  *bufp = buffer_start + BEFORE_SIZE;
357
  limit = input_file_give_next_buffer (buffer_start
377
	  limit = input_file_give_next_buffer (buffer_start + limoff);
358
				       + BEFORE_SIZE
378
 
-
 
379
	  if (limit == NULL)
359
				       + partial_size);
380
	    {
-
 
381
	      as_warn (_("partial line at end of file ignored"));
-
 
382
	      partial_where = NULL;
-
 
383
	      if (next_saved_file)
360
      if (!limit)
Line -... Line 361...
-
 
361
    {
-
 
362
	  if (partial_size == 0)
-
 
363
	    break;
-
 
364
 
-
 
365
	  as_warn (_("end of file not at end of a line; newline inserted"));
-
 
366
	  p = buffer_start + BEFORE_SIZE + partial_size;
-
 
367
	  *p++ = '\n';
384
		*bufp = input_scrub_pop (next_saved_file);
368
	  limit = p;
385
	      return NULL;
369
	}
-
 
370
      else
-
 
371
	{
386
	    }
372
	  /* Terminate the buffer to avoid confusing TC_EOL_IN_INSN.  */
387
 
373
	  *limit = '\0';
388
	  /* Terminate the buffer to avoid confusing TC_EOL_IN_INSN.  */
374
 
389
	  *limit = '\0';
375
	  /* Find last newline.  */
Line -... Line 376...
-
 
376
	  for (p = limit - 1; *p != '\n' || TC_EOL_IN_INSN (p); --p)
-
 
377
	    ;
390
	  for (p = limit - 1; *p != '\n' || TC_EOL_IN_INSN (p); --p)
378
	  ++p;
391
	    ;
379
	}
392
	  ++p;
380
 
393
	}
381
      if (p != buffer_start + BEFORE_SIZE)
-
 
382
	{
394
 
383
      partial_where = p;
395
      partial_where = p;
-
 
396
      partial_size = limit - p;
384
      partial_size = limit - p;
397
      memcpy (save_source, partial_where, (int) AFTER_SIZE);
385
      memcpy (save_source, partial_where, (int) AFTER_SIZE);
398
      memcpy (partial_where, AFTER_STRING, (int) AFTER_SIZE);
386
      memcpy (partial_where, AFTER_STRING, (int) AFTER_SIZE);
399
    }
-
 
400
  else
387
	  return partial_where;
-
 
388
    }
-
 
389
 
-
 
390
      partial_size = limit - (buffer_start + BEFORE_SIZE);
401
    {
391
      buffer_length += input_file_buffer_size ();
Line 402... Line 392...
402
      partial_where = 0;
392
      buffer_start = (char *) xrealloc (buffer_start,
403
      if (partial_size > 0)
393
					(BEFORE_SIZE
Line 404... Line 394...
404
	{
394
					 + 2 * buffer_length
-
 
395
					 + AFTER_SIZE + 1));
405
	  as_warn (_("partial line at end of file ignored"));
396
	}
406
	}
-
 
407
 
397
 
408
      /* Tell the listing we've finished the file.  */
-
 
409
      LISTING_EOF ();
398
      /* Tell the listing we've finished the file.  */
410
 
-
 
411
      /* If we should pop to another file at EOF, do it.  */
399
      LISTING_EOF ();
412
      if (next_saved_file)
400
 
413
	{
401
      /* If we should pop to another file at EOF, do it.  */
414
	  *bufp = input_scrub_pop (next_saved_file);	/* Pop state */
402
  partial_where = NULL;
415
	  /* partial_where is now correct to return, since we popped it.  */
403
      if (next_saved_file)