📄 libi77
字号:
-#undef max-#include "stdlib.h"-#endif-#endif--/*global definitions*/-unit f__units[MXUNIT]; /*unit table*/-flag f__init; /*0 on entry, 1 after initializations*/-cilist *f__elist; /*active external io list*/-flag f__reading; /*1 if reading, 0 if writing*/-flag f__cplus,f__cblank;-char *f__fmtbuf;-flag f__external; /*1 if external io, 0 if internal */-#ifdef KR_headers-int (*f__doed)(),(*f__doned)();-int (*f__doend)(),(*f__donewrec)(),(*f__dorevert)();-int (*f__getn)(),(*f__putn)(); /*for formatted io*/-#else-int (*f__getn)(void),(*f__putn)(int); /*for formatted io*/-int (*f__doed)(struct syl*, char*, ftnlen),(*f__doned)(struct syl*);-int (*f__dorevert)(void),(*f__donewrec)(void),(*f__doend)(void);-#endif-flag f__sequential; /*1 if sequential io, 0 if direct*/-flag f__formatted; /*1 if formatted io, 0 if unformatted*/-FILE *f__cf; /*current file*/-unit *f__curunit; /*current unit*/-int f__recpos; /*place in current record*/-int f__cursor,f__scale;--/*error messages*/-char *F_err[] =-{- "error in format", /* 100 */- "illegal unit number", /* 101 */- "formatted io not allowed", /* 102 */- "unformatted io not allowed", /* 103 */- "direct io not allowed", /* 104 */- "sequential io not allowed", /* 105 */- "can't backspace file", /* 106 */- "null file name", /* 107 */- "can't stat file", /* 108 */- "unit not connected", /* 109 */- "off end of record", /* 110 */- "truncation failed in endfile", /* 111 */- "incomprehensible list input", /* 112 */- "out of free space", /* 113 */- "unit not connected", /* 114 */- "read unexpected character", /* 115 */- "bad logical input field", /* 116 */- "bad variable type", /* 117 */- "bad namelist name", /* 118 */- "variable not in namelist", /* 119 */- "no end record", /* 120 */- "variable count incorrect", /* 121 */- "subscript for scalar variable", /* 122 */- "invalid array section", /* 123 */- "substring out of bounds", /* 124 */- "subscript out of bounds", /* 125 */- "can't read file", /* 126 */- "can't write file", /* 127 */- "'new' file exists", /* 128 */- "can't append to file" /* 129 */-};-#define MAXERR (sizeof(F_err)/sizeof(char *)+100)--#ifdef KR_headers-f__canseek(f) FILE *f; /*SYSDEP*/-#else-f__canseek(FILE *f) /*SYSDEP*/-#endif-{-#ifdef NON_UNIX_STDIO- return !isatty(fileno(f));-#else- struct stat x;-- if (fstat(fileno(f),&x) < 0)- return(0);-#ifdef S_IFMT- switch(x.st_mode & S_IFMT) {- case S_IFDIR:- case S_IFREG:- if(x.st_nlink > 0) /* !pipe */- return(1);- else- return(0);- case S_IFCHR:- if(isatty(fileno(f)))- return(0);- return(1);-#ifdef S_IFBLK- case S_IFBLK:- return(1);-#endif- }-#else-#ifdef S_ISDIR- /* POSIX version */- if (S_ISREG(x.st_mode) || S_ISDIR(x.st_mode)) {- if(x.st_nlink > 0) /* !pipe */- return(1);- else- return(0);- }- if (S_ISCHR(x.st_mode)) {- if(isatty(fileno(f)))- return(0);- return(1);- }- if (S_ISBLK(x.st_mode))- return(1);-#else- Help! How does fstat work on this system?-#endif-#endif- return(0); /* who knows what it is? */-#endif-}-- void-#ifdef KR_headers-f__fatal(n,s) char *s;-#else-f__fatal(int n, char *s)-#endif-{- if(n<100 && n>=0) perror(s); /*SYSDEP*/- else if(n >= (int)MAXERR || n < -1)- { fprintf(stderr,"%s: illegal error number %d\n",s,n);- }- else if(n == -1) fprintf(stderr,"%s: end of file\n",s);- else- fprintf(stderr,"%s: %s\n",s,F_err[n-100]);- if (f__curunit) {- fprintf(stderr,"apparent state: unit %d ",f__curunit-f__units);- fprintf(stderr, f__curunit->ufnm ? "named %s\n" : "(unnamed)\n",- f__curunit->ufnm);- }- else- fprintf(stderr,"apparent state: internal I/O\n");- if (f__fmtbuf)- fprintf(stderr,"last format: %s\n",f__fmtbuf);- fprintf(stderr,"lately %s %s %s %s",f__reading?"reading":"writing",- f__sequential?"sequential":"direct",f__formatted?"formatted":"unformatted",- f__external?"external":"internal");- sig_die(" IO", 1);-}-/*initialization routine*/- VOID-f_init(Void)-{ unit *p;-- f__init=1;- p= &f__units[0];- p->ufd=stderr;- p->useek=f__canseek(stderr);-#ifdef NON_UNIX_STDIO- setbuf(stderr, (char *)malloc(BUFSIZ));-#else- stderr->_flag &= ~_IONBF;-#endif- p->ufmt=1;- p->uwrt=1;- p = &f__units[5];- p->ufd=stdin;- p->useek=f__canseek(stdin);- p->ufmt=1;- p->uwrt=0;- p= &f__units[6];- p->ufd=stdout;- p->useek=f__canseek(stdout);- p->ufmt=1;- p->uwrt=1;-}-#ifdef KR_headers-f__nowreading(x) unit *x;-#else-f__nowreading(unit *x)-#endif-{- long loc;- int ufmt;- extern char *f__r_mode[];-- if (!x->ufnm)- goto cantread;- ufmt = x->ufmt;- loc=ftell(x->ufd);- if(freopen(x->ufnm,f__r_mode[ufmt],x->ufd) == NULL) {- cantread:- errno = 126;- return(1);- }- x->uwrt=0;- (void) fseek(x->ufd,loc,SEEK_SET);- return(0);-}-#ifdef KR_headers-f__nowwriting(x) unit *x;-#else-f__nowwriting(unit *x)-#endif-{- long loc;- int ufmt;- extern char *f__w_mode[];-#ifndef NON_UNIX_STDIO- int k;-#endif-- if (!x->ufnm)- goto cantwrite;- ufmt = x->ufmt;-#ifdef NON_UNIX_STDIO- ufmt |= 2;-#endif- if (x->uwrt == 3) { /* just did write, rewind */-#ifdef NON_UNIX_STDIO- if (!(f__cf = x->ufd =- freopen(x->ufnm,f__w_mode[ufmt],x->ufd)))-#else- if (close(creat(x->ufnm,0666)))-#endif- goto cantwrite;- }- else {- loc=ftell(x->ufd);-#ifdef NON_UNIX_STDIO- if (!(f__cf = x->ufd =- freopen(x->ufnm, f__w_mode[ufmt], x->ufd)))-#else- if (fclose(x->ufd) < 0- || (k = x->uwrt == 2 ? creat(x->ufnm,0666)- : open(x->ufnm,O_WRONLY)) < 0- || (f__cf = x->ufd = fdopen(k,f__w_mode[ufmt])) == NULL)-#endif- {- x->ufd = NULL;- cantwrite:- errno = 127;- return(1);- }- (void) fseek(x->ufd,loc,SEEK_SET);- }- x->uwrt = 1;- return(0);-}-- int-#ifdef KR_headers-err__fl(f, m, s) int f, m; char *s;-#else-err__fl(int f, int m, char *s)-#endif-{- if (!f)- f__fatal(m, s);- if (f__doend)- (*f__doend)();- return errno = m;- }//GO.SYSIN DD libI77/err.cecho libI77/fio.h 1>&2sed >libI77/fio.h <<'//GO.SYSIN DD libI77/fio.h' 's/^-//'-#include "stdio.h"-#include "errno.h"-#ifndef NULL-/* ANSI C */-#include "stddef.h"-#endif--#ifndef SEEK_SET-#define SEEK_SET 0-#define SEEK_CUR 1-#define SEEK_END 2-#endif--#ifdef MSDOS-#ifndef NON_UNIX_STDIO-#define NON_UNIX_STDIO-#endif-#endif--#ifdef UIOLEN_int-typedef int uiolen;-#else-typedef long uiolen;-#endif--/*units*/-typedef struct-{ FILE *ufd; /*0=unconnected*/- char *ufnm;-#ifndef MSDOS- long uinode;- int udev;-#endif- int url; /*0=sequential*/- flag useek; /*true=can backspace, use dir, ...*/- flag ufmt;- flag uprnt;- flag ublnk;- flag uend;- flag uwrt; /*last io was write*/- flag uscrtch;-} unit;--extern flag f__init;-extern cilist *f__elist; /*active external io list*/-extern flag f__reading,f__external,f__sequential,f__formatted;-#undef Void-#ifdef KR_headers-#define Void /*void*/-extern int (*f__getn)(),(*f__putn)(); /*for formatted io*/-extern long f__inode();-extern VOID sig_die();-extern int (*f__donewrec)(), t_putc(), x_wSL();-extern int c_sfe(), err__fl(), xrd_SL();-#else-#define Void void-#ifdef __cplusplus-extern "C" {-#endif-extern int (*f__getn)(void),(*f__putn)(int); /*for formatted io*/-extern long f__inode(char*,int*);-extern void sig_die(char*,int);-extern void f__fatal(int,char*);-extern int t_runc(alist*);-extern int f__nowreading(unit*), f__nowwriting(unit*);-extern int fk_open(int,int,ftnint);-extern int en_fio(void);-extern void f_init(void);-extern int (*f__donewrec)(void), t_putc(int), x_wSL(void);-extern void b_char(char*,char*,ftnlen), g_char(char*,ftnlen,char*);-extern int c_sfe(cilist*), z_rnew(void);-extern int isatty(int);-extern int err__fl(int,int,char*);-extern int xrd_SL(void);-#ifdef __cplusplus- }-#endif-#endif-extern int (*f__doend)(Void);-extern FILE *f__cf; /*current file*/-extern unit *f__curunit; /*current unit*/-extern unit f__units[];-#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)--/*Table sizes*/-#define MXUNIT 100--extern int f__recpos; /*position in current record*/-extern int f__cursor; /* offset to move to */-extern int f__hiwater; /* so TL doesn't confuse us */--#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)//GO.SYSIN DD libI77/fio.hecho libI77/fmt.c 1>&2sed >libI77/fmt.c <<'//GO.SYSIN DD libI77/fmt.c' 's/^-//'-#include "f2c.h"-#include "fio.h"-#include "fmt.h"-#define skip(s) while(*s==' ') s++-#ifdef interdata-#define SYLMX 300-#endif-#ifdef pdp11-#define SYLMX 300-#endif-#ifdef vax-#define SYLMX 300-#endif-#ifndef SYLMX-#define SYLMX 300-#endif-#define GLITCH '\2'- /* special quote character for stu */-extern int f__cursor,f__scale;-extern flag f__cblank,f__cplus; /*blanks in I and compulsory plus*/-struct syl f__syl[SYLMX];-int f__parenlvl,f__pc,f__revloc;--#ifdef KR_headers-char *ap_end(s) char *s;-#else-char *ap_end(char *s)-#endif-{ char quote;- quote= *s++;- for(;*s;s++)- { if(*s!=quote) continue;- if(*++s!=quote) return(s);- }- if(f__elist->cierr) {- errno = 100;- return(NULL);- }- f__fatal(100, "bad string");- /*NOTREACHED*/ return 0;-}-#ifdef KR_headers-op_gen(a,b,c,d)-#else-op_gen(int a, int b, int c, int d)-#endif-{ struct syl *p= &f__syl[f__pc];- if(f__pc>=SYLMX)- { fprintf(stderr,"format too complicated:\n");- sig_die(f__fmtbuf, 1);- }- p->op=a;- p->p1=b;- p->p2=c;- p->p3=d;- return(f__pc++);-}-#ifdef KR_headers-char *f_list();-char *gt_num(s,n) char *s; int *n;-#else-char *f_list(char*);-char *gt_num(char *s, int *n)-#endif-{ int m=0,f__cnt=0;- char c;- for(c= *s;;c = *s)- { if(c==' ')- { s++;- continue;- }- if(c>'9' || c<'0') break;- m=10*m+c-'0';- f__cnt++;- s++;- }- if(f__cnt==0) *n=1;- else *n=m;- return(s);-}-#ifdef KR_headers-char *f_s(s,curloc) char *s;-#else-char *f_s(char *s, int curloc)-#endif-{- skip(s);- if(*s++!='(')- {- return(NULL);- }- if(f__parenlvl++ ==1) f__revloc=curloc;- if(op_gen(RET1,curloc,0,0)<0 ||- (s=f_list(s))==NULL)- {- return(NULL);- }- skip(s);- return(s);-}-#ifdef KR_headers-ne_d(s,p) char *s,**p;-#else-ne_d(char *s, char **p)-#endif-{ int n,x,sign=0;- struct syl *sp;- switch(*s)- {- default:- return(0);- case ':': (void) op_gen(COLON,0,0,0); break;- case '$':- (void) op_gen(NONL, 0, 0, 0); break;- case 'B':- case 'b':- if(*++s=='z' || *s == 'Z') (void) op_gen(BZ,0,0,0);- else (void) op_gen(BN,0,0,0);- break;- case 'S':- case 's':- if(*(s+1)=='s' || *(s+1) == 'S')- { x=SS;- s++;- }- else if(*(s+1)=='p' || *(s+1) == 'P')- { x=SP;- s++;- }- else x=S;- (void) op_gen(x,0,0,0);- break;- case '/': (void) op_gen(SLASH,0,0,0); break;- case '-': sign=1;- case '+': s++; /*OUTRAGEOUS CODING TRICK*/- case '0': case '1': case '2': case '3': case '4':- case '5': case '6': case '7': case '8': case '9':- s=gt_num(s,&n);- switch(*s)- {- default:- return(0);- case 'P':- case 'p': if(sign) n= -n; (void) op_gen(P,n,0,0); break;- case 'X':- case 'x': (void) op_gen(X,n,0,0); break;- case 'H':- case 'h':- sp = &f__syl[op_gen(H,n,0,0)];- *(char **)&sp->p2 = s + 1;- s+=n;- break;- }- break;- case GLITCH:- case '"':- case '\'':- sp = &f__syl[op_gen(APOS,0,0,0)];- *(char **)&sp->p2 = s;- if((*p = ap_end(s)) == NULL)- return(0);- return(1);- case 'T':- case 't':- if(*(s+1)=='l' || *(s+1) == 'L')- { x=TL;- s++;- }- else if(*(s+1)=='r'|| *(s+1) == 'R')- { x=TR;- s++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -