File: xdrfuns.c

package info (click to toggle)
gcl 2.6.7%2Bdfsga-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 84,796 kB
  • sloc: ansic: 452,686; lisp: 156,133; asm: 111,405; sh: 29,299; cpp: 18,599; perl: 5,602; makefile: 5,201; tcl: 3,181; sed: 469; yacc: 378; lex: 174; fortran: 48; awk: 30; csh: 23
file content (175 lines) | stat: -rwxr-xr-x 3,879 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
 Copyright (C) 1994  W. Schelter

This file is part of GNU Common Lisp, herein referred to as GCL

GCL is free software; you can redistribute it and/or modify it under
the terms of the GNU LIBRARY GENERAL PUBLIC LICENSE as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

GCL is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public 
License for more details.

*/

#ifdef HAVE_XDR

#ifdef AIX3
#include <sys/select.h>
#endif
#include <rpc/rpc.h>

extern short aet_sizes[];
static object
FFN(siGxdr_open)(f)
     object f;
{ XDR *xdrs;
  object ar= alloc_simple_string(sizeof(XDR));
  array_allocself(ar,1,0);
  xdrs= (XDR *) ar->a.a_self;
  if (f->sm.sm_fp == 0) FEerror("stream not ok for xdr io",0);
  xdrstdio_create(xdrs, f->sm.sm_fp,
		  (f->sm.sm_mode == smm_input ?  XDR_DECODE :
		   f->sm.sm_mode == smm_output ?  XDR_ENCODE :
		   (FEerror("stream not input or output",0),XDR_ENCODE)))
		   ;
  return ar;
}

static object
FFN(siGxdr_write)(object str,object elt) {

  XDR *xdrp= (XDR *) str->ust.ust_self;
  xdrproc_t e;

  switch (type_of(elt)) {
  case t_fixnum:
    if(!xdr_long(xdrp,(long *)&fix(elt))) goto error;
    break;
  case t_longfloat:
    if(!xdr_double(xdrp,&lf(elt))) goto error;
    break;
  case t_shortfloat:
    if(!xdr_float(xdrp,&sf(elt))) goto error;
    break;
  case t_vector:
    
    switch(elt->v.v_elttype) {
    case aet_lf:
      e=(xdrproc_t)xdr_double;
      break;
    case aet_sf:
      e=(xdrproc_t)xdr_float;
      break;
    case aet_fix:
      e=(xdrproc_t)xdr_long;
      break;
    case aet_short:
      e=(xdrproc_t)xdr_short;
      break;
    default:
      FEerror("unsupported xdr size",0);
      goto error;
      break;
    }
    {
      u_int tmp=elt->v.v_fillp;
      if (tmp!=elt->v.v_fillp)
	goto error;
      if(!xdr_array(xdrp,(void *)&elt->v.v_self,
		    &tmp,
		    elt->v.v_dim,
		    aet_sizes[elt->v.v_elttype],
		    e))
	goto error;
    }
    break;
  default:
    FEerror("unsupported xdr ~a",1,elt);
    break;
  }
  return elt;
 error:
  FEerror("bad xdr read",0);
  return elt;
}

static object
FFN(siGxdr_read)(object str,object elt) {

  XDR *xdrp= (XDR *) str->ust.ust_self;
  xdrproc_t e;

  switch (type_of(elt)) { 
  case t_fixnum:
    {fixnum l;
      if(!xdr_long(xdrp,(long *)&l)) goto error;
    return make_fixnum(l);}
    break;
  case t_longfloat:
    {double x;
    if(!xdr_double(xdrp,&x)) goto error;
    return make_longfloat(x);}
  case t_shortfloat:
    {float x;
    if(!xdr_float(xdrp,&x)) goto error;
    return make_shortfloat(x);}
  case t_vector:
    switch(elt->v.v_elttype) {
    case aet_lf:
      e=(xdrproc_t)xdr_double;
      break;
    case aet_sf:
      e=(xdrproc_t)xdr_float;
      break;
    case aet_fix:
      e=(xdrproc_t)xdr_long;
      break;
    case aet_short:
      e=(xdrproc_t)xdr_short;
      break;
    default:
      FEerror("unsupported xdr size",0);
      goto error;
      break;
    }

    {
      u_int tmp=elt->v.v_fillp;
      if (tmp!=elt->v.v_fillp)
	goto error;
      if(!xdr_array(xdrp,(void *)&elt->v.v_self,
		    &tmp,
		    elt->v.v_dim,
		    aet_sizes[elt->v.v_elttype],
		    e))
	goto error;
    }
    return elt;
    break;
  default:
    FEerror("unsupported xdr ~a",1,elt);
    return elt;
    break;
  }
 error:
  FEerror("bad xdr read",0);
  return elt;
}
static void
gcl_init_xdrfuns()
{ make_si_sfun("XDR-WRITE",siGxdr_write,
	       ARGTYPE2(f_object,f_object)|RESTYPE(f_object));

  make_si_sfun("XDR-READ",siGxdr_read,
	       ARGTYPE2(f_object,f_object)|RESTYPE(f_object));
  make_si_sfun("XDR-OPEN",siGxdr_open,
	       ARGTYPE1(f_object)|RESTYPE(f_object));
  
}
#else
static void gcl_init_xdrfuns(void) {;}
#endif