Back to index

glibc  2.9
Classes | Defines | Typedefs | Functions
linereader.h File Reference
#include <ctype.h>
#include <libintl.h>
#include <stdint.h>
#include <stdio.h>
#include "charmap.h"
#include "error.h"
#include "locfile-token.h"
#include "repertoire.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  token
struct  linereader
union  token.val
struct  token.val.str
struct  token.val.charcode

Defines

#define lr_error(lr, fmt, args...)   WITH_CUR_LOCALE (error_at_line (0, 0, lr->fname, lr->lineno, fmt, ## args))

Typedefs

typedef struct keyword_t *(* kw_hash_fct_t )(const char *, unsigned int)

Functions

struct linereaderlr_open (const char *fname, kw_hash_fct_t hf)
struct linereaderlr_create (FILE *fp, const char *fname, kw_hash_fct_t hf)
int lr_eof (struct linereader *lr)
void lr_close (struct linereader *lr)
int lr_next (struct linereader *lr)
struct tokenlr_token (struct linereader *lr, const struct charmap_t *charmap, struct localedef_t *locale, const struct repertoire_t *repertoire, int verbose)
void lr_ignore_rest (struct linereader *lr, int verbose)
static int __attribute ((always_inline)) lr_getc(struct linereader *lr)

Class Documentation

struct token

Definition at line 37 of file linereader.h.

Class Members
tok_kind kind
const char * str
enum token_t union token val
struct linereader

Definition at line 62 of file linereader.h.

Collaboration diagram for linereader:
Class Members
char * buf
size_t bufact
size_t bufsize
char comment_char
char escape_char
const char * fname
FILE * fp
kw_hash_fct_t hash_fct
size_t idx
size_t lineno
int return_widestr
int translate_strings
union token.val

Definition at line 40 of file linereader.h.

Class Members
val charcode
unsigned long int num
val str
uint32_t ucs4
struct token.val.str

Definition at line 42 of file linereader.h.

Class Members
size_t lenmb
size_t lenwc
char * startmb
uint32_t * startwc
struct token.val.charcode

Definition at line 50 of file linereader.h.

Class Members
unsigned char bytes
int nbytes

Define Documentation

#define lr_error (   lr,
  fmt,
  args... 
)    WITH_CUR_LOCALE (error_at_line (0, 0, lr->fname, lr->lineno, fmt, ## args))

Definition at line 100 of file linereader.h.


Typedef Documentation

typedef struct keyword_t*(* kw_hash_fct_t)(const char *, unsigned int)

Definition at line 33 of file linereader.h.


Function Documentation

static int __attribute ( (always_inline)  ) [inline, static]

Definition at line 106 of file linereader.h.

{
  if (lr->idx == lr->bufact)
    {
      if (lr->bufact != 0)
       if (lr_next (lr) < 0)
         return EOF;

      if (lr->bufact == 0)
       return EOF;
    }

  return lr->buf[lr->idx] == '\32' ? EOF : lr->buf[lr->idx++];
}

Here is the call graph for this function:

void lr_close ( struct linereader lr)

Definition at line 143 of file linereader.c.

{
  fclose (lr->fp);
  free (lr->buf);
  free (lr);
}

Here is the call graph for this function:

Here is the caller graph for this function:

struct linereader* lr_create ( FILE fp,
const char *  fname,
kw_hash_fct_t  hf 
) [read]

Definition at line 66 of file linereader.c.

{
  struct linereader *result;
  int n;

  result = (struct linereader *) xmalloc (sizeof (*result));

  result->fp = fp;
  result->fname = xstrdup (fname);
  result->buf = NULL;
  result->bufsize = 0;
  result->lineno = 1;
  result->idx = 0;
  result->comment_char = '#';
  result->escape_char = '\\';
  result->translate_strings = 1;
  result->return_widestr = 0;

  n = getdelim (&result->buf, &result->bufsize, '\n', result->fp);
  if (n < 0)
    {
      int save = errno;
      fclose (result->fp);
      free ((char *) result->fname);
      free (result);
      errno = save;
      return NULL;
    }

  if (n > 1 && result->buf[n - 2] == '\\' && result->buf[n - 1] == '\n')
    n -= 2;

  result->buf[n] = '\0';
  result->bufact = n;
  result->hash_fct = hf;

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int lr_eof ( struct linereader lr)

Definition at line 107 of file linereader.c.

{
  return lr->bufact = 0;
}
void lr_ignore_rest ( struct linereader lr,
int  verbose 
)

Definition at line 114 of file linereader.c.

{
  if (verbose)
    {
      while (isspace (lr->buf[lr->idx]) && lr->buf[lr->idx] != '\n'
            && lr->buf[lr->idx] != lr->comment_char)
       if (lr->buf[lr->idx] == '\0')
         {
           if (lr_next (lr) < 0)
             return;
         }
       else
         ++lr->idx;

      if (lr->buf[lr->idx] != '\n' && ! feof (lr->fp)
         && lr->buf[lr->idx] != lr->comment_char)
       lr_error (lr, _("trailing garbage at end of line"));
    }

  /* Ignore continued line.  */
  while (lr->bufact > 0 && lr->buf[lr->bufact - 1] != '\n')
    if (lr_next (lr) < 0)
      break;

  lr->idx = lr->bufact;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int lr_next ( struct linereader lr)

Definition at line 152 of file linereader.c.

{
  int n;

  n = getdelim (&lr->buf, &lr->bufsize, '\n', lr->fp);
  if (n < 0)
    return -1;

  ++lr->lineno;

  if (n > 1 && lr->buf[n - 2] == lr->escape_char && lr->buf[n - 1] == '\n')
    {
#if 0
      /* XXX Is this correct?  */
      /* An escaped newline character is substituted with a single <SP>.  */
      --n;
      lr->buf[n - 1] = ' ';
#else
      n -= 2;
#endif
    }

  lr->buf[n] = '\0';
  lr->bufact = n;
  lr->idx = 0;

  return 0;
}

Here is the caller graph for this function:

struct linereader* lr_open ( const char *  fname,
kw_hash_fct_t  hf 
) [read]

Definition at line 49 of file linereader.c.

{
  FILE *fp;

  if (fname == NULL || strcmp (fname, "-") == 0
      || strcmp (fname, "/dev/stdin") == 0)
    return lr_create (stdin, "<stdin>", hf);
  else
    {
      fp = fopen (fname, "rm");
      if (fp == NULL)
       return NULL;
      return lr_create (fp, fname, hf);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

struct token* lr_token ( struct linereader lr,
const struct charmap_t charmap,
struct localedef_t locale,
const struct repertoire_t repertoire,
int  verbose 
) [read]

Definition at line 192 of file linereader.c.

{
  int ch;

  while (1)
    {
      do
       {
         ch = lr_getc (lr);

         if (ch == EOF)
           {
             lr->token.tok = tok_eof;
             return &lr->token;
           };

         if (ch == '\n')
           {
             lr->token.tok = tok_eol;
             return &lr->token;
           }
       }
      while (isspace (ch));

      if (ch != lr->comment_char)
       break;

      /* Is there an newline at the end of the buffer?  */
      if (lr->buf[lr->bufact - 1] != '\n')
       {
         /* No.  Some people want this to mean that only the line in
            the file not the logical, concatenated line is ignored.
            Let's try this.  */
         lr->idx = lr->bufact;
         continue;
       }

      /* Ignore rest of line.  */
      lr_ignore_rest (lr, 0);
      lr->token.tok = tok_eol;
      return &lr->token;
    }

  /* Match escape sequences.  */
  if (ch == lr->escape_char)
    return get_toplvl_escape (lr);

  /* Match ellipsis.  */
  if (ch == '.')
    {
      if (strncmp (&lr->buf[lr->idx], "...(2)....", 10) == 0)
       {
         int cnt;
         for (cnt = 0; cnt < 10; ++cnt)
           lr_getc (lr);
         lr->token.tok = tok_ellipsis4_2;
         return &lr->token;
       }
      if (strncmp (&lr->buf[lr->idx], "...", 3) == 0)
       {
         lr_getc (lr);
         lr_getc (lr);
         lr_getc (lr);
         lr->token.tok = tok_ellipsis4;
         return &lr->token;
       }
      if (strncmp (&lr->buf[lr->idx], "..", 2) == 0)
       {
         lr_getc (lr);
         lr_getc (lr);
         lr->token.tok = tok_ellipsis3;
         return &lr->token;
       }
      if (strncmp (&lr->buf[lr->idx], ".(2)..", 6) == 0)
       {
         int cnt;
         for (cnt = 0; cnt < 6; ++cnt)
           lr_getc (lr);
         lr->token.tok = tok_ellipsis2_2;
         return &lr->token;
       }
      if (lr->buf[lr->idx] == '.')
       {
         lr_getc (lr);
         lr->token.tok = tok_ellipsis2;
         return &lr->token;
       }
    }

  switch (ch)
    {
    case '<':
      return get_symname (lr);

    case '0' ... '9':
      lr->token.tok = tok_number;
      lr->token.val.num = ch - '0';

      while (isdigit (ch = lr_getc (lr)))
       {
         lr->token.val.num *= 10;
         lr->token.val.num += ch - '0';
       }
      if (isalpha (ch))
       lr_error (lr, _("garbage at end of number"));
      lr_ungetn (lr, 1);

      return &lr->token;

    case ';':
      lr->token.tok = tok_semicolon;
      return &lr->token;

    case ',':
      lr->token.tok = tok_comma;
      return &lr->token;

    case '(':
      lr->token.tok = tok_open_brace;
      return &lr->token;

    case ')':
      lr->token.tok = tok_close_brace;
      return &lr->token;

    case '"':
      return get_string (lr, charmap, locale, repertoire, verbose);

    case '-':
      ch = lr_getc (lr);
      if (ch == '1')
       {
         lr->token.tok = tok_minus1;
         return &lr->token;
       }
      lr_ungetn (lr, 2);
      break;
    }

  return get_ident (lr);
}

Here is the call graph for this function:

Here is the caller graph for this function: