Back to index

glibc  2.9
Defines | Functions | Variables
rpc_util.c File Reference
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <unistd.h>
#include "rpc_scan.h"
#include "rpc_parse.h"
#include "rpc_util.h"
#include "proto.h"

Go to the source code of this file.

Defines

#define ARGEXT   "argument"
#define NFILES   7
#define TABSIZE   4

Functions

static int findit (const definition *def, const char *type)
static const char * fixit (const char *type, const char *orig)
static int typedefed (const definition *def, const char *type)
static const char * toktostr (tok_kind kind)
static void printbuf (void)
static void printwhere (void)
void reinitialize (void)
int streq (const char *a, const char *b)
definition * findval (list *lst, const char *val, int(*cmp)(const definition *, const char *))
void storeval (list **lstp, definition *val)
const char * fixtype (const char *type)
const char * stringfix (const char *type)
void ptype (const char *prefix, const char *type, int follow)
int isvectordef (const char *type, relation rel)
char * locase (const char *str)
void pvname_svc (const char *pname, const char *vnum)
void pvname (const char *pname, const char *vnum)
void error (const char *msg)
void crash (void)
void record_open (const char *file)
void expected1 (tok_kind exp1)
void expected2 (tok_kind exp1, tok_kind exp2)
void expected3 (tok_kind exp1, tok_kind exp2, tok_kind exp3)
void tabify (FILE *f, int tab)
char * make_argname (const char *pname, const char *vname)
void add_type (int len, const char *type)
bas_type * find_type (const char *type)

Variables

char curline [MAXLINESIZE]
const char * where = curline
int linenum = 0
const char * infilename
const char * outfiles [NFILES]
int nfiles
FILEfout
FILEfin
listdefined
static char expectbuf [100]
static const token tokstrings []
bas_type * typ_list_h
bas_type * typ_list_t

Define Documentation

#define ARGEXT   "argument"

Definition at line 47 of file rpc_util.c.

#define NFILES   7

Definition at line 55 of file rpc_util.c.

#define TABSIZE   4

Function Documentation

void add_type ( int  len,
const char *  type 
)

Definition at line 481 of file rpc_util.c.

{
  bas_type *ptr;


  if ((ptr = malloc (sizeof (bas_type))) == NULL)
    {
      fprintf (stderr, "failed in malloc");
      exit (1);
    }

  ptr->name = type;
  ptr->length = len;
  ptr->next = NULL;
  if (typ_list_t == NULL)
    {

      typ_list_t = ptr;
      typ_list_h = ptr;
    }
  else
    {

      typ_list_t->next = ptr;
      typ_list_t = ptr;
    }

}

Here is the call graph for this function:

Here is the caller graph for this function:

void crash ( void  )

Definition at line 288 of file rpc_util.c.

{
  int i;

  for (i = 0; i < nfiles; i++)
    {
      unlink (outfiles[i]);
    }
  exit (1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void error ( const char *  msg)

Definition at line 275 of file rpc_util.c.

{
  printwhere ();
  f_print (stderr, "%s, line %d: ", infilename, linenum);
  f_print (stderr, "%s\n", msg);
  crash ();
}

Here is the call graph for this function:

void expected1 ( tok_kind  exp1)

Definition at line 319 of file rpc_util.c.

{
  s_print (expectbuf, "expected '%s'",
          toktostr (exp1));
  error (expectbuf);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void expected2 ( tok_kind  exp1,
tok_kind  exp2 
)

Definition at line 330 of file rpc_util.c.

{
  s_print (expectbuf, "expected '%s' or '%s'",
          toktostr (exp1),
          toktostr (exp2));
  error (expectbuf);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void expected3 ( tok_kind  exp1,
tok_kind  exp2,
tok_kind  exp3 
)

Definition at line 342 of file rpc_util.c.

{
  s_print (expectbuf, "expected '%s', '%s' or '%s'",
          toktostr (exp1),
          toktostr (exp2),
          toktostr (exp3));
  error (expectbuf);
}

Here is the call graph for this function:

Here is the caller graph for this function:

bas_type* find_type ( const char *  type)

Definition at line 512 of file rpc_util.c.

{
  bas_type *ptr;

  ptr = typ_list_h;


  while (ptr != NULL)
    {
      if (strcmp (ptr->name, type) == 0)
       return ptr;
      else
       ptr = ptr->next;
    };
  return NULL;
}

Here is the caller graph for this function:

static int findit ( const definition *  def,
const char *  type 
) [static]

Definition at line 128 of file rpc_util.c.

{
  return streq (def->def_name, type);
}

Here is the call graph for this function:

Here is the caller graph for this function:

definition* findval ( list lst,
const char *  val,
int(*)(const definition *, const char *)  cmp 
)

Definition at line 96 of file rpc_util.c.

{

  for (; lst != NULL; lst = lst->next)
    {
      if (cmp (lst->val, val))
       {
         return lst->val;
       }
    }
  return NULL;
}

Here is the caller graph for this function:

static const char * fixit ( const char *  type,
const char *  orig 
) [static]

Definition at line 134 of file rpc_util.c.

{
  definition *def;

  def = findval (defined, type, findit);
  if (def == NULL || def->def_kind != DEF_TYPEDEF)
    {
      return orig;
    }
  switch (def->def.ty.rel)
    {
    case REL_VECTOR:
      if (streq (def->def.ty.old_type, "opaque"))
       return ("char");
      else
       return (def->def.ty.old_type);
    case REL_ALIAS:
      return (fixit (def->def.ty.old_type, orig));
    default:
      return orig;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

const char* fixtype ( const char *  type)

Definition at line 158 of file rpc_util.c.

{
  return fixit (type, type);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int isvectordef ( const char *  type,
relation  rel 
)

Definition at line 218 of file rpc_util.c.

{
  definition *def;

  for (;;)
    {
      switch (rel)
       {
       case REL_VECTOR:
         return !streq (type, "string");
       case REL_ARRAY:
         return 0;
       case REL_POINTER:
         return 0;
       case REL_ALIAS:
         def = findval (defined, type, typedefed);
         if (def == NULL)
           {
             return 0;
           }
         type = def->def.ty.old_type;
         rel = def->def.ty.rel;
       }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* locase ( const char *  str)

Definition at line 245 of file rpc_util.c.

{
  char c;
  static char buf[100];
  char *p = buf;

  while ((c = *str++) != 0)
    {
      *p++ = (c >= 'A' && c <= 'Z') ? (c - 'A' + 'a') : c;
    }
  *p = 0;
  return buf;
}

Here is the caller graph for this function:

char* make_argname ( const char *  pname,
const char *  vname 
)

Definition at line 463 of file rpc_util.c.

{
  char *name;

  name = malloc (strlen (pname) + strlen (vname) + strlen (ARGEXT) + 3);
  if (!name)
    {
      fprintf (stderr, "failed in malloc");
      exit (1);
    }
  sprintf (name, "%s_%s_%s", locase (pname), vname, ARGEXT);
  return name;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void printbuf ( void  ) [static]

Definition at line 409 of file rpc_util.c.

{
  char c;
  int i;
  int cnt;

#define TABSIZE 4

  for (i = 0; (c = curline[i]) != 0; i++)
    {
      if (c == '\t')
       {
         cnt = 8 - (i % TABSIZE);
         c = ' ';
       }
      else
       {
         cnt = 1;
       }
      while (cnt--)
       {
         (void) fputc (c, stderr);
       }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void printwhere ( void  ) [static]

Definition at line 436 of file rpc_util.c.

{
  int i;
  char c;
  int cnt;

  printbuf ();
  for (i = 0; i < where - curline; i++)
    {
      c = curline[i];
      if (c == '\t')
       {
         cnt = 8 - (i % TABSIZE);
       }
      else
       {
         cnt = 1;
       }
      while (cnt--)
       {
         (void) fputc ('^', stderr);
       }
    }
  (void) fputc ('\n', stderr);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void ptype ( const char *  prefix,
const char *  type,
int  follow 
)

Definition at line 177 of file rpc_util.c.

{
  if (prefix != NULL)
    {
      if (streq (prefix, "enum"))
       {
         f_print (fout, "enum ");
       }
      else
       {
         f_print (fout, "struct ");
       }
    }
  if (streq (type, "bool"))
    {
      f_print (fout, "bool_t ");
    }
  else if (streq (type, "string"))
    {
      f_print (fout, "char *");
    }
  else
    {
      f_print (fout, "%s ", follow ? fixtype (type) : type);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pvname ( const char *  pname,
const char *  vnum 
)

Definition at line 266 of file rpc_util.c.

{
  f_print (fout, "%s_%s", locase (pname), vnum);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pvname_svc ( const char *  pname,
const char *  vnum 
)

Definition at line 260 of file rpc_util.c.

{
  f_print (fout, "%s_%s_svc", locase (pname), vnum);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void record_open ( const char *  file)

Definition at line 300 of file rpc_util.c.

{
  if (nfiles < NFILES)
    {
      outfiles[nfiles++] = file;
    }
  else
    {
      f_print (stderr, "too many files!\n");
      crash ();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void reinitialize ( void  )

Definition at line 75 of file rpc_util.c.

Here is the caller graph for this function:

void storeval ( list **  lstp,
definition *  val 
)

Definition at line 114 of file rpc_util.c.

{
  list **l;
  list *lst;


  for (l = lstp; *l != NULL; l = (list **) & (*l)->next);
  lst = ALLOC (list);
  lst->val = val;
  lst->next = NULL;
  *l = lst;
}
int streq ( const char *  a,
const char *  b 
)

Definition at line 87 of file rpc_util.c.

{
  return strcmp (a, b) == 0;
}

Here is the caller graph for this function:

const char* stringfix ( const char *  type)

Definition at line 164 of file rpc_util.c.

{
  if (streq (type, "string"))
    {
      return "wrapstring";
    }
  else
    {
      return type;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void tabify ( FILE f,
int  tab 
)

Definition at line 352 of file rpc_util.c.

{
  while (tab--)
    {
      (void) fputc ('\t', f);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static const char * toktostr ( tok_kind  kind) [static]

Definition at line 400 of file rpc_util.c.

{
  const token *sp;

  for (sp = tokstrings; sp->kind != TOK_EOF && sp->kind != kind; sp++);
  return sp->str;
}

Here is the caller graph for this function:

static int typedefed ( const definition *  def,
const char *  type 
) [static]

Definition at line 205 of file rpc_util.c.

{
  if (def->def_kind != DEF_TYPEDEF || def->def.ty.old_prefix != NULL)
    {
      return 0;
    }
  else
    {
      return streq (def->def_name, type);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 49 of file rpc_util.c.

Definition at line 62 of file rpc_util.c.

char expectbuf[100] [static]

Definition at line 313 of file rpc_util.c.

Definition at line 60 of file rpc_util.c.

Definition at line 59 of file rpc_util.c.

Definition at line 53 of file rpc_util.c.

int linenum = 0

Definition at line 51 of file rpc_util.c.

Definition at line 57 of file rpc_util.c.

Definition at line 56 of file rpc_util.c.

const token tokstrings[] [static]

Definition at line 361 of file rpc_util.c.

bas_type* typ_list_h

Definition at line 477 of file rpc_util.c.

bas_type* typ_list_t

Definition at line 478 of file rpc_util.c.

const char* where = curline

Definition at line 50 of file rpc_util.c.