Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / pcc / dist / pcc-libs / libI77 / dfe.c
blobfecbaa9c7c2894e0007bf1c3b50be5bc94fe0cfb
1 /* $Id: dfe.c,v 1.1.1.1 2008/08/24 05:34:47 gmcgarry Exp $ */
2 /*
3 * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
9 * Redistributions of source code and documentation must retain the above
10 * copyright notice, this list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditionsand the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed or owned by Caldera
17 * International, Inc.
18 * Neither the name of Caldera International, Inc. nor the names of other
19 * contributors may be used to endorse or promote products derived from
20 * this software without specific prior written permission.
22 * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
23 * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE
27 * FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT,
31 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
35 #include "fio.h"
36 #include "fmt.h"
37 static int y_getc(void), y_putc(int), y_rev(void), y_err(void);
38 static int c_dfe(cilist *a, int flag);
40 int
41 s_rdfe(cilist *a)
43 int n;
44 if(!init) f_init();
45 if((n=c_dfe(a,READ)))return(n);
46 reading=1;
47 if(curunit->uwrt) nowreading(curunit);
48 getn = y_getc;
49 doed = rd_ed;
50 doned = rd_ned;
51 dorevert = donewrec = y_err;
52 doend = y_rev;
53 if(pars_f(fmtbuf)<0)
54 err(a->cierr,100,"startio");
55 fmt_bg();
56 return(0);
59 int
60 s_wdfe(cilist *a)
62 int n;
63 if(!init) f_init();
64 if((n=c_dfe(a,WRITE))) return(n);
65 reading=0;
66 if(!curunit->uwrt) nowwriting(curunit);
67 putn = y_putc;
68 doed = w_ed;
69 doned= w_ned;
70 dorevert = donewrec = y_err;
71 doend = y_rev;
72 if(pars_f(fmtbuf)<0)
73 err(a->cierr,100,"startwrt");
74 fmt_bg();
75 return(0);
78 int
79 e_rdfe()
81 en_fio();
82 return(0);
85 int
86 e_wdfe()
88 en_fio();
89 return(0);
92 int
93 c_dfe(cilist *a, int flag)
95 sequential=0;
96 formatted=external=1;
97 elist=a;
98 cursor=scale=recpos=0;
99 if(a->ciunit>MXUNIT || a->ciunit<0)
100 err(a->cierr,101,"startchk");
101 curunit = &units[a->ciunit];
102 if(curunit->ufd==NULL && fk_open(flag,DIR,FMT,a->ciunit))
103 err(a->cierr,104,"dfe");
104 cf=curunit->ufd;
105 if(!curunit->ufmt) err(a->cierr,102,"dfe")
106 if(!curunit->useek) err(a->cierr,104,"dfe")
107 fmtbuf=a->cifmt;
108 fseek(cf,(long)curunit->url * (a->cirec-1),0);
109 curunit->uend = 0;
110 return(0);
114 y_getc()
116 int ch;
117 if(curunit->uend) return(-1);
118 if((ch=getc(cf))!=EOF)
120 recpos++;
121 if(curunit->url>=recpos ||
122 curunit->url==1)
123 return(ch);
124 else return(' ');
126 if(feof(cf))
128 curunit->uend=1;
129 errno=0;
130 return(-1);
132 err(elist->cierr,errno,"readingd");
136 y_putc(int c)
138 recpos++;
139 if(recpos <= curunit->url || curunit->url==1)
140 putc(c,cf);
141 else
142 err(elist->cierr,110,"dout");
143 return(0);
147 y_rev()
148 { /*what about work done?*/
149 if(curunit->url==1 || recpos==curunit->url)
150 return(0);
151 while(recpos<curunit->url)
152 (*putn)(' ');
153 recpos=0;
154 return(0);
158 y_err()
160 err(elist->cierr, 110, "dfe");
161 return 0; /* XXX */