Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

fio.h File Reference

#include "stdio.h"
#include "errno.h"
#include "stddef.h"

Go to the source code of this file.


Data Structures

struct  unit

Defines

#define __THROW
#define KILL__THROW
#define SEEK_SET   0
#define SEEK_CUR   1
#define SEEK_END   2
#define Void   void
#define err(f, m, s)   {if(f) errno= m; else f__fatal(m,s); return(m);}
#define errfl(f, m, s)   return err__fl((int)f,m,s)
#define MXUNIT   100
#define WRITE   1
#define READ   2
#define SEQ   3
#define DIR   4
#define FMT   5
#define UNF   6
#define EXT   7
#define INT   8
#define buf_end(x)   (x->_flag & _IONBF ? x->_ptr : x->_base + BUFSIZ)

Typedefs

typedef long uiolen

Functions

long f__inode (char *, int *)
void sig_die (char *, int)
void f__fatal (int, char *)
int t_runc (alist *)
int f__nowreading (unit *)
int f__nowwriting (unit *)
int fk_open (int, int, ftnint)
int en_fio (void)
void f_init (void)
void b_char (char *, char *, ftnlen)
void g_char (char *, ftnlen, char *)
int c_sfe (cilist *)
int z_rnew (void)
int isatty (int) __THROW
int err__fl (int, int, char *)
int xrd_SL (void)

Variables

flag f__init
cilistf__elist
flag f__reading
flag f__external
flag f__sequential
flag f__formatted
int(* f__getn )(void)
int(*)(*) f__putn (int)
int(* f__donewrec )(void)
int(* t_putc )(int)
int(* x_wSL )(void)
int(* f__doend )(Void)
FILE * f__cf
unitf__curunit
unit f__units []
int f__recpos
int f__cursor
int f__hiwater

Define Documentation

#define __THROW
 

Definition at line 12 of file fio.h.

#define buf_end      (x->_flag & _IONBF ? x->_ptr : x->_base + BUFSIZ)
 

Definition at line 111 of file fio.h.

Referenced by mv_cur(), and x_putc().

#define DIR   4
 

Definition at line 105 of file fio.h.

Referenced by c_dfe(), c_due(), fk_open(), and glob3().

#define err f,
m,
     {if(f) errno= m; else f__fatal(m,s); return(m);}
 

Definition at line 92 of file fio.h.

Referenced by addrlit(), analyz(), badchleng(), c_dfe(), c_due(), c_le(), c_sfe(), c_si(), c_sue(), cktype(), compgoto_out(), conspower(), convci(), crunch(), data_value(), dataval(), dclerr(), do_fio(), do_init_data(), do_p1_addr(), do_p1_charp(), do_p1_comp_goto(), do_p1_const(), do_p1_expr(), do_p1_extern(), do_p1_goto(), do_p1_head(), do_p1_ident(), do_p1_label(), do_p1_list(), do_p1_literal(), do_p1_name_pointer(), do_p1_set_line(), do_ud(), do_us(), doentry(), dofclose(), dofinquire(), dofmove(), dofopen(), doio(), doiolist(), e_rdue(), e_wdue(), e_wsfe(), e_wsle(), e_wsue(), endioctl(), endproc(), erri(), errl(), errstr(), exarif(), exasgoto(), exassign(), exdo(), execerr(), execlab(), exenddo(), exequals(), expr_out(), exreturn(), f_back(), f_end(), f_open(), f_rew(), fixexpr(), fixtype(), getname(), gettok(), hexcheck(), i_ungetc(), intovfl(), ioclause(), iosetc(), l_C(), l_L(), l_read(), lencat(), lengtype(), list_arg_types(), mkbitcon(), mkcxcon(), mkfunct(), mkpower(), mkstfunct(), mktmpn(), mv_cur(), new_endif(), nextdata(), opconv(), out_asgoto(), out_call(), primchk(), putcall(), putif(), putwhile(), rd_ed(), s_rdfe(), s_rdue(), s_rsfe(), s_rsle(), s_rsne(), s_rsue(), s_wdfe(), s_wdue(), s_wsfe(), s_wsle(), s_wsne(), s_wsue(), sameconst(), set_externs(), setbound(), setdata(), setimpl(), start_formatting(), startrw(), stfcall(), t_runc(), wr_char_len(), wr_one_init(), wr_struct(), write_char_init(), x_rsne(), y_err(), y_getc(), y_putc(), yyerror(), yyparse(), z_getc(), and z_putc().

#define errfl f,
m,
     return err__fl((int)f,m,s)
 

Definition at line 93 of file fio.h.

Referenced by do_fio(), getname(), l_C(), l_CHAR(), l_L(), l_R(), l_read(), and x_rsne().

#define EXT   7
 

Definition at line 108 of file fio.h.

#define FMT   5
 

Definition at line 106 of file fio.h.

Referenced by c_dfe(), c_le(), c_sfe(), and fk_open().

#define INT   8
 

Definition at line 109 of file fio.h.

#define KILL__THROW
 

Definition at line 14 of file fio.h.

#define MXUNIT   100
 

Definition at line 96 of file fio.h.

Referenced by c_dfe(), c_due(), c_le(), c_sfe(), c_sue(), f_back(), f_clos(), f_end(), f_exit(), f_inqu(), f_open(), f_rew(), flush_(), and unit_chk().

#define READ   2
 

Definition at line 103 of file fio.h.

#define SEEK_CUR   1
 

Definition at line 19 of file fio.h.

#define SEEK_END   2
 

Definition at line 20 of file fio.h.

#define SEEK_SET   0
 

Definition at line 18 of file fio.h.

#define SEQ   3
 

Definition at line 104 of file fio.h.

#define UNF   6
 

Definition at line 107 of file fio.h.

Referenced by c_due(), and c_sue().

#define Void   void
 

Definition at line 65 of file fio.h.

#define WRITE   1
 

Definition at line 102 of file fio.h.


Typedef Documentation

typedef long uiolen
 

Definition at line 32 of file fio.h.

Referenced by e_rsue(), e_wsue(), s_rsue(), and s_wsue().


Function Documentation

void b_char char *   ,
char *   ,
ftnlen   
 

Definition at line 34 of file util.c.

00036 {       int i;
00037         for(i=0;i<blen && *a!=0;i++) *b++= *a++;
00038         for(;i<blen;i++) *b++=' ';
00039 }

int c_sfe cilist  
 

Definition at line 20 of file sfe.c.

00022 {       unit *p;
00023         if(a->ciunit >= MXUNIT || a->ciunit<0)
00024                 err(a->cierr,101,"startio");
00025         p = &f__units[a->ciunit];
00026         if(p->ufd==NULL && fk_open(SEQ,FMT,a->ciunit)) err(a->cierr,114,"sfe")
00027         if(!p->ufmt) err(a->cierr,102,"sfe")
00028         return(0);
00029 }

int en_fio void   
 

Referenced by e_rdfe(), e_rsfe(), e_rsfi(), e_wdfe(), e_wsfe(), and e_wsfi().

int err__fl int   ,
int   ,
char *   
 

Definition at line 270 of file err.c.

References f__fatal().

00272 {
00273         if (!f)
00274                 f__fatal(m, s);
00275         if (f__doend)
00276                 (*f__doend)();
00277         return errno = m;
00278         }

void f__fatal int   ,
char *   
 

Definition at line 141 of file err.c.

References f__external, f__fmtbuf, f__formatted, f__reading, f__sequential, F_err, MAXERR, sig_die(), and unit::ufnm.

Referenced by ap_end(), err__fl(), l_write(), and unit_chk().

00143 {
00144         if(n<100 && n>=0) perror(s); /*SYSDEP*/
00145         else if(n >= (int)MAXERR || n < -1)
00146         {       fprintf(stderr,"%s: illegal error number %d\n",s,n);
00147         }
00148         else if(n == -1) fprintf(stderr,"%s: end of file\n",s);
00149         else
00150                 fprintf(stderr,"%s: %s\n",s,F_err[n-100]);
00151         if (f__curunit) {
00152                 fprintf(stderr,"apparent state: unit %d ",f__curunit-f__units);
00153                 fprintf(stderr, f__curunit->ufnm ? "named %s\n" : "(unnamed)\n",
00154                         f__curunit->ufnm);
00155                 }
00156         else
00157                 fprintf(stderr,"apparent state: internal I/O\n");
00158         if (f__fmtbuf)
00159                 fprintf(stderr,"last format: %s\n",f__fmtbuf);
00160         fprintf(stderr,"lately %s %s %s %s",f__reading?"reading":"writing",
00161                 f__sequential?"sequential":"direct",f__formatted?"formatted":"unformatted",
00162                 f__external?"external":"internal");
00163         sig_die(" IO", 1);
00164 }

long f__inode char *   ,
int *   
 

Referenced by f_inqu(), and f_open().

int f__nowreading unit  
 

Referenced by f_back(), s_rdfe(), s_rdue(), s_rsfe(), s_rsle(), s_rsne(), and s_rsue().

int f__nowwriting unit  
 

Definition at line 218 of file err.c.

References close(), f__cf, fdopen(), O_WRONLY, unit::ufd, unit::ufmt, unit::ufnm, and unit::uwrt.

Referenced by s_wdfe(), s_wdue(), s_wsfe(), s_wsle(), s_wsne(), and s_wsue().

00220 {
00221         long loc;
00222         int ufmt;
00223         extern char *f__w_mode[];
00224 #ifndef NON_UNIX_STDIO
00225         int k;
00226 #endif
00227 
00228         if (!x->ufnm)
00229                 goto cantwrite;
00230         ufmt = x->ufmt;
00231 #ifdef NON_UNIX_STDIO
00232         ufmt |= 2;
00233 #endif
00234         if (x->uwrt == 3) { /* just did write, rewind */
00235 #ifdef NON_UNIX_STDIO
00236                 if (!(f__cf = x->ufd =
00237                                 freopen(x->ufnm,f__w_mode[ufmt],x->ufd)))
00238 #else
00239                 if (close(creat(x->ufnm,0666)))
00240 #endif
00241                         goto cantwrite;
00242                 }
00243         else {
00244                 loc=ftell(x->ufd);
00245 #ifdef NON_UNIX_STDIO
00246                 if (!(f__cf = x->ufd =
00247                         freopen(x->ufnm, f__w_mode[ufmt], x->ufd)))
00248 #else
00249                 if (fclose(x->ufd) < 0
00250                 || (k = x->uwrt == 2 ? creat(x->ufnm,0666)
00251                                      : open(x->ufnm,O_WRONLY)) < 0
00252                 || (f__cf = x->ufd = fdopen(k,f__w_mode[ufmt])) == NULL)
00253 #endif
00254                         {
00255                         x->ufd = NULL;
00256  cantwrite:
00257                         errno = 127;
00258                         return(1);
00259                         }
00260                 (void) fseek(x->ufd,loc,SEEK_SET);
00261                 }
00262         x->uwrt = 1;
00263         return(0);
00264 }

void f_init void   
 

Referenced by c_due(), c_le(), f_open(), main(), nl_init(), s_rdfe(), s_rsfe(), s_rsue(), s_wdfe(), s_wsfe(), and s_wsue().

int fk_open int   ,
int   ,
ftnint   
 

Definition at line 228 of file open.c.

References a, DIR, f_open(), FMT, olist::oacc, olist::oblnk, olist::oerr, olist::ofm, olist::ofnm, olist::ofnmlen, olist::orl, olist::osta, and olist::ounit.

Referenced by c_dfe(), c_due(), c_le(), c_sfe(), c_sue(), and f_back().

00230 {       char nbuf[10];
00231         olist a;
00232         (void) sprintf(nbuf,"fort.%ld",n);
00233         a.oerr=1;
00234         a.ounit=n;
00235         a.ofnm=nbuf;
00236         a.ofnmlen=strlen(nbuf);
00237         a.osta=NULL;
00238         a.oacc= seq==SEQ?"s":"d";
00239         a.ofm = fmt==FMT?"f":"u";
00240         a.orl = seq==DIR?1:0;
00241         a.oblnk=NULL;
00242         return(f_open(&a));
00243 }

void g_char char *   ,
ftnlen   ,
char *   
 

Definition at line 12 of file util.c.

References a.

Referenced by f_inqu(), and f_open().

00014 {
00015         char *x = a + alen, *y = b + alen;
00016 
00017         for(;; y--) {
00018                 if (x <= a) {
00019                         *b = 0;
00020                         return;
00021                         }
00022                 if (*--x != ' ')
00023                         break;
00024                 }
00025         *y-- = 0;
00026         do *y-- = *x;
00027                 while(x-- > a);
00028         }

int isatty int   
 

void sig_die char *   ,
int   
 

int t_runc alist  
 

Definition at line 113 of file endfile.c.

References a, close(), copy(), err, f__r_mode, f__w_mode, L, L_tmpnam, mktemp(), unit::ufd, unit::ufmt, unit::ufnm, unlink, unit::url, unit::useek, and unit::uwrt.

Referenced by f_back(), f_clos(), f_end(), and f_rew().

00115 {
00116         char nm[L_tmpnam+12];   /* extra space in case L_tmpnam is tiny */
00117         long loc, len;
00118         unit *b;
00119 #ifdef NON_UNIX_STDIO
00120         FILE *bf, *tf;
00121 #else
00122         FILE *bf;
00123 #endif
00124         int rc = 0;
00125 
00126         b = &f__units[a->aunit];
00127         if(b->url)
00128                 return(0);      /*don't truncate direct files*/
00129         loc=ftell(bf = b->ufd);
00130         fseek(bf,0L,SEEK_END);
00131         len=ftell(bf);
00132         if (loc >= len || b->useek == 0 || b->ufnm == NULL)
00133                 return(0);
00134 #ifdef NON_UNIX_STDIO
00135         fclose(b->ufd);
00136 #else
00137         rewind(b->ufd); /* empty buffer */
00138 #endif
00139         if (!loc) {
00140 #ifdef NON_UNIX_STDIO
00141                 if (!(bf = fopen(b->ufnm, f__w_mode[b->ufmt])))
00142 #else
00143                 if (close(creat(b->ufnm,0666)))
00144 #endif
00145                         rc = 1;
00146                 if (b->uwrt)
00147                         b->uwrt = 1;
00148                 goto done;
00149                 }
00150 #ifdef _POSIX_SOURCE
00151         tmpnam(nm);
00152 #else
00153         strcpy(nm,"tmp.FXXXXXX");
00154         mktemp(nm);
00155 #endif
00156 #ifdef NON_UNIX_STDIO
00157         if (!(bf = fopen(b->ufnm, f__r_mode[0]))) {
00158  bad:
00159                 rc = 1;
00160                 goto done;
00161                 }
00162         if (!(tf = fopen(nm, f__w_mode[0])))
00163                 goto bad;
00164         if (copy(bf, loc, tf)) {
00165  bad1:
00166                 rc = 1;
00167                 goto done1;
00168                 }
00169         if (!(bf = freopen(b->ufnm, f__w_mode[0], bf)))
00170                 goto bad1;
00171         if (!(tf = freopen(nm, f__r_mode[0], tf)))
00172                 goto bad1;
00173         if (copy(tf, loc, bf))
00174                 goto bad1;
00175         if (f__w_mode[0] != f__w_mode[b->ufmt]) {
00176                 if (!(bf = freopen(b->ufnm, f__w_mode[b->ufmt|2], bf)))
00177                         goto bad1;
00178                 fseek(bf, loc, SEEK_SET);
00179                 }
00180 done1:
00181         fclose(tf);
00182         unlink(nm);
00183 done:
00184         f__cf = b->ufd = bf;
00185 #else
00186         if (copy(b->ufnm, loc, nm)
00187          || copy(nm, loc, b->ufnm))
00188                 rc = 1;
00189         unlink(nm);
00190         fseek(b->ufd, loc, SEEK_SET);
00191 done:
00192 #endif
00193         if (rc)
00194                 err(a->aerr,111,"endfile");
00195         return 0;
00196         }

int xrd_SL void   
 

Referenced by x_endp(), and x_rev().

int z_rnew void   
 

Referenced by i_getc(), x_rsne(), and z_wSL().


Variable Documentation

FILE* f__cf
 

Definition at line 89 of file fio.h.

Referenced by f__nowwriting().

int f__cursor
 

Definition at line 99 of file fio.h.

unit* f__curunit
 

Definition at line 90 of file fio.h.

int(* f__doend)(Void)
 

Definition at line 88 of file fio.h.

int(* f__donewrec)(void)
 

cilist* f__elist
 

Definition at line 54 of file fio.h.

flag f__external
 

Definition at line 55 of file fio.h.

Referenced by f__fatal().

flag f__formatted
 

Definition at line 55 of file fio.h.

Referenced by f__fatal().

int(* f__getn)(void)
 

int f__hiwater
 

Definition at line 100 of file fio.h.

flag f__init
 

Definition at line 53 of file fio.h.

Referenced by f_init().

int(*)(*) f__putn(int)
 

Definition at line 69 of file fio.h.

flag f__reading
 

Definition at line 55 of file fio.h.

Referenced by f__fatal().

int f__recpos
 

Definition at line 98 of file fio.h.

flag f__sequential
 

Definition at line 55 of file fio.h.

Referenced by f__fatal().

unit f__units[]
 

Definition at line 91 of file fio.h.

int(* t_putc)(int)
 

int(* x_wSL)(void)
 

Definition at line 78 of file fio.h.

 

Powered by Plone

This site conforms to the following standards: