AutoXDR - NFSv4 Example Enum translator

Main
AutoGen
Pages

Home
Announce
FAQ
docs
XML Defs
testimonials
downloads

Automated
Options

AutoOpts
Comparison
Man example
Redistribute
Licensing
local use
using getopt

GCC's
Fixincludes

fixincludes

Automated
FSM

description
example
usagefsm

Addons
addon

Project GNU
Home Page

Automated
XDR

xdr project
  definitions
  XDR

  client
  clt. head
  server
  srv. head

  enums

  debug
  test code

i

This code translates enumerations into strings and back. It can be used on either the client or server side, but the interface is declared in the client header.

/*
 *  DO NOT EDIT THIS FILE   (nfsv4-enum.c)
 *  
 *  It has been AutoGen-ed  March  1, 2010 at 02:26:41 PM by AutoGen 5.10.1
 *  From the definitions    nfsv4.def
 *  and the template file   autoxdr.tpl
 *
 *  This file has been generated by the AutoXDR AutoGen template suite.
 *
 *  These files are compatible with:
 *  RFC1831 - Remote Procedure Call Protocol Specification Version 2
 *  RFC1832 - External Data Representation Standard
 *  and are intended to be used as a layer on top of the ONC IDL
 *  in conjunction with RPCGEN.
 *
 */
#include <stdio.h>
#include "nfsv4-clhdr.h"
#include "nfsv4.h"

static char const enum_text[224] =
    "`%d' is not in NFS4's %s enumeration\n\0"
    "`%s' is not in NFS4's %s enumeration\n\0"
    "OK\0"
    "successful completion\0"
    "PERM\0"
    "caller is either not privileged or not owner\0"
    "NOENT\0"
    "No such file or directory\0"
    "OMITTED\0"
    "operation omitted\0"
    "status\0"
    "ACCESS4\0";

static char zOops[ 101 ];

typedef struct enum_info {
  int           eid;
  char const*   pz_name;
  char const*   pz_info;
  int           unused;
} enum_info_t;

/*
 *  NFS4's status enumeration conversions
 */
static enum_info_t a_nfs4_status_info[] = {
  {   0, enum_text+ 76, enum_text+ 79, 0 },
  {   1, enum_text+101, enum_text+106, 0 },
  {   2, enum_text+151, enum_text+157, 0 },
  { 256, enum_text+183, enum_text+191, 0 }
};



char const*
info_nfs4_status( nfs4_status eid )
{
  int lo = 0;
  int hi = 3;
  int av = (lo + hi)/2;

  for (;;)
    {
      int c = (int)eid - a_nfs4_status_info[ av ].eid;
      if (c == 0)
        return a_nfs4_status_info[ av ].pz_info;
      if (c < 0)
        hi = av - 1;
      else
        lo = av + 1;

      if (hi < lo)
        break;
      av = (lo + hi)/2;
    }

  snprintf( zOops, 101, enum_text+  0, eid, enum_text+209 );
  return zOops;
}


char const*
name_nfs4_status( nfs4_status eid )
{
  int lo = 0;
  int hi = 3;
  int av = (lo + hi)/2;

  for (;;)
    {
      int c = (int)eid - a_nfs4_status_info[ av ].eid;
      if (c == 0)
        return a_nfs4_status_info[ av ].pz_name;
      if (c < 0)
        hi = av - 1;
      else
        lo = av + 1;

      if (hi < lo)
        break;
      av = (lo + hi)/2;
    }

  snprintf( zOops, 101, enum_text+  0, eid, enum_text+209 );
  return zOops;
}

nfs4_status
nfs4_status_enum( char const* pz_name )
{
  int i = 0;
  do
    {
      char const* pz = a_nfs4_status_info[i].pz_name;
      if ((pz != NULL) && (strcmp( pz, pz_name ) == 0))
        return a_nfs4_status_info[i].eid;
    }
  while (++i < 4);
  fprintf( stderr, enum_text+ 38, pz_name, enum_text+209 );
  return (nfs4_status)-1;
}

char const*
name_nfs4_compound_ops( nfs4_compound_ops op )
{
  static char const * const apz_op_names[] = {
    enum_text+216 };
  int idx = (int)op - 3;
  if ((unsigned)idx > 0)
    return (char const*)NULL;
  return apz_op_names[ idx ];
}

top  Viewable With Any Browser  Valid XHTML 1.0!


AutoGen, AutoOpts, columns, getdefs, AutoFSM, AutoXDR and these web pages copyright (c) 1999-2012 Bruce Korb, all rights reserved.

AutoXDR copyright (c) 2000-2012 Bruce Korb, all rights reserved.
Return to GNU's home page.

Please send FSF & GNU inquiries & questions to gnu@gnu.org. There are also other ways to contact the FSF.

Please send comments on these web pages to webmasters@www.gnu.org, send other questions to gnu@gnu.org.

This article, Copyright © 2000-2002 by Bruce Korb

Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved. Last modified: Sat Aug 30 11:01:52 PDT 2014