Ignore:
Timestamp:
Aug 16, 2003, 6:59:22 PM (22 years ago)
Author:
bird
Message:

binutils v2.14 - offical sources.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/binutils/gas/input-file.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* input_file.c - Deal with Input Files -
    2    Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1999, 2000
     2   Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1999, 2000, 2001
    33   Free Software Foundation, Inc.
    44
     
    2020   02111-1307, USA.  */
    2121
    22 /*
    23  * Confines all details of reading source bytes to this module.
    24  * All O/S specific crocks should live here.
    25  * What we lose in "efficiency" we gain in modularity.
    26  * Note we don't need to #include the "as.h" file. No common coupling!
    27  */
     22/* Confines all details of reading source bytes to this module.
     23   All O/S specific crocks should live here.
     24   What we lose in "efficiency" we gain in modularity.
     25   Note we don't need to #include the "as.h" file. No common coupling!  */
    2826
    2927#include <stdio.h>
    3028#include <string.h>
    31 
    3229#include "as.h"
    3330#include "input-file.h"
     31#include "safe-ctype.h"
    3432
    3533static int input_file_get PARAMS ((char *, int));
    3634
    3735/* This variable is non-zero if the file currently being read should be
    38    preprocessed by app.  It is zero if the file can be read straight in.
    39    */
     36   preprocessed by app.  It is zero if the file can be read straight in.  */
    4037int preprocess = 0;
    4138
    42 /*
    43  * This code opens a file, then delivers BUFFER_SIZE character
    44  * chunks of the file on demand.
    45  * BUFFER_SIZE is supposed to be a number chosen for speed.
    46  * The caller only asks once what BUFFER_SIZE is, and asks before
    47  * the nature of the input files (if any) is known.
    48  */
     39/* This code opens a file, then delivers BUFFER_SIZE character
     40   chunks of the file on demand.
     41   BUFFER_SIZE is supposed to be a number chosen for speed.
     42   The caller only asks once what BUFFER_SIZE is, and asks before
     43   the nature of the input files (if any) is known.  */
    4944
    5045#define BUFFER_SIZE (32 * 1024)
    5146
    52 /*
    53  * We use static data: the data area is not sharable.
    54  */
     47/* We use static data: the data area is not sharable.  */
    5548
    5649static FILE *f_in;
     
    5851
    5952/* Struct for saving the state of this module for file includes.  */
    60 struct saved_file {
    61   FILE *f_in;
    62   char *file_name;
    63   int preprocess;
    64   char *app_save;
    65 };
     53struct saved_file
     54  {
     55    FILE * f_in;
     56    char * file_name;
     57    int    preprocess;
     58    char * app_save;
     59  };
    6660
    6761
     
    9488/* Push the state of our input, returning a pointer to saved info that
    9589   can be restored with input_file_pop ().  */
     90
    9691char *
    9792input_file_push ()
     
    107102    saved->app_save = app_push ();
    108103
    109   input_file_begin ();          /* Initialize for new file */
     104  /* Initialize for new file.  */
     105  input_file_begin ();
    110106
    111107  return (char *) saved;
     
    118114  register struct saved_file *saved = (struct saved_file *) arg;
    119115
    120   input_file_end ();            /* Close out old file */
     116  input_file_end ();            /* Close out old file. */
    121117
    122118  f_in = saved->f_in;
     
    143139  if (filename[0])
    144140    {                           /* We have a file name. Suck it and see.  */
    145       f_in = fopen (filename, "r");
     141      f_in = fopen (filename, FOPEN_RT);
    146142      file_name = filename;
    147143    }
     
    153149  if (f_in == (FILE *) 0)
    154150    {
    155       as_bad (_("Can't open %s for reading."), file_name);
     151      as_bad (_("can't open %s for reading"), file_name);
    156152      as_perror ("%s", file_name);
    157153      return;
     
    160156  c = getc (f_in);
    161157  if (c == '#')
    162     {                           /* Begins with comment, may not want to preprocess */
     158    {
     159      /* Begins with comment, may not want to preprocess.  */
    163160      c = getc (f_in);
    164161      if (c == 'N')
    165162        {
    166163          fgets (buf, 80, f_in);
    167           if (!strcmp (buf, "O_APP\n"))
     164          if (!strncmp (buf, "O_APP", 5) && ISSPACE (buf[5]))
    168165            preprocess = 0;
    169166          if (!strchr (buf, '\n'))
    170             ungetc ('#', f_in); /* It was longer */
     167            ungetc ('#', f_in); /* It was longer.  */
     168          else
     169            ungetc ('\n', f_in);
     170        }
     171      else if (c == 'A')
     172        {
     173          fgets (buf, 80, f_in);
     174          if (!strncmp (buf, "PP", 2) && ISSPACE (buf[2]))
     175            preprocess = 1;
     176          if (!strchr (buf, '\n'))
     177            ungetc ('#', f_in);
    171178          else
    172179            ungetc ('\n', f_in);
     
    182189
    183190/* Close input file.  */
     191
    184192void
    185193input_file_close ()
    186194{
     195  /* Don't close a null file pointer.  */
    187196  if (f_in != NULL)
    188     {
    189       fclose (f_in);
    190     }                           /* don't close a null file pointer */
     197    fclose (f_in);
     198
    191199  f_in = 0;
    192200}
     
    221229  if (f_in == (FILE *) 0)
    222230    return 0;
    223   /*
    224    * fflush (stdin); could be done here if you want to synchronise
    225    * stdin and stdout, for the case where our input file is stdin.
    226    * Since the assembler shouldn't do any output to stdout, we
    227    * don't bother to synch output and input.
    228    */
     231  /* fflush (stdin); could be done here if you want to synchronise
     232     stdin and stdout, for the case where our input file is stdin.
     233     Since the assembler shouldn't do any output to stdout, we
     234     don't bother to synch output and input.  */
    229235  if (preprocess)
    230236    size = do_scrub_chars (input_file_get, where, BUFFER_SIZE);
     
    245251      return_value = 0;
    246252    }
    247   return (return_value);
    248 }
     253
     254  return return_value;
     255}
Note: See TracChangeset for help on using the changeset viewer.