Back to index

cell-binutils  2.17cvs20070401
Classes | Defines | Functions | Variables
input-file.c File Reference
#include "as.h"
#include "input-file.h"
#include "safe-ctype.h"

Go to the source code of this file.

Classes

struct  saved_file

Defines

#define BUFFER_SIZE   (32 * 1024)

Functions

static int input_file_get (char *, int)
void input_file_begin (void)
void input_file_end (void)
unsigned int input_file_buffer_size (void)
char * input_file_push (void)
void input_file_pop (char *arg)
void input_file_open (char *filename, int pre)
void input_file_close (void)
char * input_file_give_next_buffer (char *where)

Variables

int preprocess = 0
static FILE * f_in
static char * file_name

Class Documentation

struct saved_file

Definition at line 52 of file input-file.c.

Class Members
char * app_save
FILE * f_in
char * file_name
int preprocess

Define Documentation

#define BUFFER_SIZE   (32 * 1024)

Definition at line 44 of file input-file.c.


Function Documentation

void input_file_begin ( void  )

Definition at line 63 of file input-file.c.

{
  f_in = (FILE *) 0;
}

Here is the caller graph for this function:

Definition at line 75 of file input-file.c.

{
  return (BUFFER_SIZE);
}

Here is the caller graph for this function:

void input_file_close ( void  )

Definition at line 196 of file input-file.c.

{
  /* Don't close a null file pointer.  */
  if (f_in != NULL)
    fclose (f_in);

  f_in = 0;
}

Here is the caller graph for this function:

void input_file_end ( void  )

Definition at line 69 of file input-file.c.

{
}

Here is the caller graph for this function:

static int input_file_get ( char *  buf,
int  buflen 
) [static]

Definition at line 208 of file input-file.c.

{
  int size;

  size = fread (buf, sizeof (char), buflen, f_in);
  if (size < 0)
    {
      as_bad (_("can't read from %s: %s"), file_name, xstrerror (errno));
      size = 0;
    }
  return size;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* input_file_give_next_buffer ( char *  where)

Definition at line 224 of file input-file.c.

{
  char *return_value;              /* -> Last char of what we read, + 1.  */
  register int size;

  if (f_in == (FILE *) 0)
    return 0;
  /* fflush (stdin); could be done here if you want to synchronise
     stdin and stdout, for the case where our input file is stdin.
     Since the assembler shouldn't do any output to stdout, we
     don't bother to synch output and input.  */
  if (preprocess)
    size = do_scrub_chars (input_file_get, where, BUFFER_SIZE);
  else
    size = fread (where, sizeof (char), BUFFER_SIZE, f_in);
  if (size < 0)
    {
      as_bad (_("can't read from %s: %s"), file_name, xstrerror (errno));
      size = 0;
    }
  if (size)
    return_value = where + size;
  else
    {
      if (fclose (f_in))
       as_warn (_("can't close %s: %s"), file_name, xstrerror (errno));

      f_in = (FILE *) 0;
      return_value = 0;
    }

  return return_value;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void input_file_open ( char *  filename,
int  pre 
)

Definition at line 119 of file input-file.c.

{
  int c;
  char buf[80];

  preprocess = pre;

  assert (filename != 0);   /* Filename may not be NULL.  */
  if (filename[0])
    {
      f_in = fopen (filename, FOPEN_RT);
      file_name = filename;
    }
  else
    {
      /* Use stdin for the input file.  */
      f_in = stdin;
      /* For error messages.  */
      file_name = _("{standard input}");
    }

  if (f_in == NULL)
    {
      as_bad (_("can't open %s for reading: %s"),
             file_name, xstrerror (errno));
      return;
    }

  c = getc (f_in);

  if (ferror (f_in))
    {
      as_bad (_("can't read from %s: %s"),
             file_name, xstrerror (errno));

      fclose (f_in);
      f_in = NULL;
      return;
    }

  if (c == '#')
    {
      /* Begins with comment, may not want to preprocess.  */
      c = getc (f_in);
      if (c == 'N')
       {
         if (fgets (buf, sizeof (buf), f_in)
             && !strncmp (buf, "O_APP", 5) && ISSPACE (buf[5]))
           preprocess = 0;
         if (!strchr (buf, '\n'))
           ungetc ('#', f_in);     /* It was longer.  */
         else
           ungetc ('\n', f_in);
       }
      else if (c == 'A')
       {
         if (fgets (buf, sizeof (buf), f_in)
             && !strncmp (buf, "PP", 2) && ISSPACE (buf[2]))
           preprocess = 1;
         if (!strchr (buf, '\n'))
           ungetc ('#', f_in);
         else
           ungetc ('\n', f_in);
       }
      else if (c == '\n')
       ungetc ('\n', f_in);
      else
       ungetc ('#', f_in);
    }
  else
    ungetc (c, f_in);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void input_file_pop ( char *  arg)

Definition at line 103 of file input-file.c.

{
  register struct saved_file *saved = (struct saved_file *) arg;

  input_file_end ();        /* Close out old file.  */

  f_in = saved->f_in;
  file_name = saved->file_name;
  preprocess = saved->preprocess;
  if (preprocess)
    app_pop (saved->app_save);

  free (arg);
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* input_file_push ( void  )

Definition at line 84 of file input-file.c.

{
  register struct saved_file *saved;

  saved = (struct saved_file *) xmalloc (sizeof *saved);

  saved->f_in = f_in;
  saved->file_name = file_name;
  saved->preprocess = preprocess;
  if (preprocess)
    saved->app_save = app_push ();

  /* Initialize for new file.  */
  input_file_begin ();

  return (char *) saved;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

FILE* f_in [static]

Definition at line 48 of file input-file.c.

char* file_name [static]

Definition at line 49 of file input-file.c.

Definition at line 36 of file input-file.c.