📄 libi77
字号:
# to unbundle, sh this file (in an empty directory)mkdir libI77echo libI77/Notice 1>&2sed >libI77/Notice <<'//GO.SYSIN DD libI77/Notice' 's/^-//'-/****************************************************************-Copyright 1990 - 1994 by AT&T Bell Laboratories and Bellcore.--Permission to use, copy, modify, and distribute this software-and its documentation for any purpose and without fee is hereby-granted, provided that the above copyright notice appear in all-copies and that both that the copyright notice and this-permission notice and warranty disclaimer appear in supporting-documentation, and that the names of AT&T Bell Laboratories or-Bellcore or any of their entities not be used in advertising or-publicity pertaining to distribution of the software without-specific, written prior permission.--AT&T and Bellcore disclaim all warranties with regard to this-software, including all implied warranties of merchantability-and fitness. In no event shall AT&T or Bellcore be liable for-any special, indirect or consequential damages or any damages-whatsoever resulting from loss of use, data or profits, whether-in an action of contract, negligence or other tortious action,-arising out of or in connection with the use or performance of-this software.-****************************************************************/-//GO.SYSIN DD libI77/Noticeecho libI77/README 1>&2sed >libI77/README <<'//GO.SYSIN DD libI77/README' 's/^-//'-If your compiler does not recognize ANSI C headers,-compile with KR_headers defined: either add -DKR_headers-to the definition of CFLAGS in the makefile, or insert--#define KR_headers--at the top of f2c.h and fmtlib.c .---If you have a really ancient K&R C compiler that does not understand-void, add -Dvoid=int to the definition of CFLAGS in the makefile.--If you use a C++ compiler, first create a local f2c.h by appending-f2ch.add to the usual f2c.h, e.g., by issuing the command- make f2c.h-which assumes f2c.h is installed in /usr/include .--If your system lacks /usr/include/fcntl.h , then you-should simply create an empty fcntl.h in this directory.-If your compiler then complains about creat and open not-having a prototype, compile with OPEN_DECL defined.-On many systems, open and creat are declared in fcntl.h .--If your system has /usr/include/fcntl.h, you may need to add--D_POSIX_SOURCE to the makefile's definition of CFLAGS.--If your system's sprintf does not work the way ANSI C-specifies -- specifically, if it does not return the-number of characters transmitted -- then insert the line--#define USE_STRLEN--at the end of fmt.h . This is necessary with-at least some versions of Sun and DEC software.--If your system's fopen does not like the ANSI binary-reading and writing modes "rb" and "wb", then you should-compile open.c with NON_ANSI_RW_MODES #defined.--If you get error messages about references to cf->_ptr-and cf->_base when compiling wrtfmt.c and wsfe.c or to-stderr->_flag when compiling err.c, then insert the line--#define NON_UNIX_STDIO--at the beginning of fio.h, and recompile everything (or-at least those modules that contain NON_UNIX_STDIO).--Unformatted sequential records consist of a length of record-contents, the record contents themselves, and the length of-record contents again (for backspace). Prior to 17 Oct. 1991,-the length was of type int; now it is of type long, but you-can change it back to int by inserting--#define UIOLEN_int--at the beginning of fio.h. This affects only sue.c and uio.c .--On VAX, Cray, or Research Tenth-Edition Unix systems, you may-need to add -DVAX, -DCRAY, or -DV10 (respectively) to CFLAGS-to make fp.h work correctly. Alternatively, you may need to-edit fp.h to suit your machine.--You may need to supply the following non-ANSI routines:-- fstat(int fileds, struct stat *buf) is similar-to stat(char *name, struct stat *buf), except that-the first argument, fileds, is the file descriptor-returned by open rather than the name of the file.-fstat is used in the system-dependent routine-canseek (in the libI77 source file err.c), which-is supposed to return 1 if it's possible to issue-seeks on the file in question, 0 if it's not; you may-need to suitably modify err.c . On non-UNIX systems,-you can avoid references to fstat and stat by compiling-with NON_UNIX_STDIO defined; in that case, you may need-to supply access(char *Name,0), which is supposed to-return 0 if file Name exists, nonzero otherwise.-- char * mktemp(char *buf) is supposed to replace the-6 trailing X's in buf with a unique number and then-return buf. The idea is to get a unique name for-a temporary file.--On non-UNIX systems, you may need to change a few other,-e.g.: the form of name computed by mktemp() in endfile.c and-open.c; the use of the open(), close(), and creat() system-calls in endfile.c, err.c, open.c; and the modes in calls on-fopen() and fdopen() (and perhaps the use of fdopen() itself--- it's supposed to return a FILE* corresponding to a given-an integer file descriptor) in err.c and open.c (component ufmt-of struct unit is 1 for formatted I/O -- text mode on some systems--- and 0 for unformatted I/O -- binary mode on some systems).-Compiling with -DNON_UNIX_STDIO omits all references to creat()-and almost all references to open() and close(), the exception-being in the function f__isdev() (in open.c).--For MS-DOS, compile all of libI77 with -DMSDOS (which implies--DNON_UNIX_STDIO). You may need to make other compiler-dependent-adjustments; for example, for Turbo C++ you need to adjust the mktemp-invocations and to #undef ungetc in lread.c and rsne.c .--If you want to be able to load against libI77 but not libF77,-then you will need to add sig_die.o (from libF77) to libI77.--If you wish to use translated Fortran that has funny notions-of record length for direct unformatted I/O (i.e., that assumes-RECL= values in OPEN statements are not bytes but rather counts-of some other units -- e.g., 4-character words for VMS), then you-should insert an appropriate #define for url_Adjust at the-beginning of open.c . For VMS Fortran, for example,-#define url_Adjust(x) x *= 4-would suffice.--To check for transmission errors, issue the command- make check-This assumes you have the xsum program whose source, xsum.c,-is distributed as part of "all from f2c/src". If you do not-have xsum, you can obtain xsum.c by sending the following E-mail-message to netlib@research.att.com- send xsum.c from f2c/src--The makefile assumes you have installed f2c.h in a standard-place (and does not cause recompilation when f2c.h is changed);-f2c.h comes with "all from f2c" (the source for f2c) and is-available separately ("f2c.h from f2c").--By default, Fortran I/O units 5, 6, and 0 are pre-connected to-stdin, stdout, and stderr, respectively. You can change this-behavior by changing f_init() in err.c to suit your needs.-Note that f2c assumes READ(*... means READ(5... and WRITE(*...-means WRITE(6... . Moreover, an OPEN(n,... statement that does-not specify a file name (and does not specify STATUS='SCRATCH')-assumes FILE='fort.n' . You can change this by editing open.c-and endfile.c suitably.--Lines protected from compilation by #ifdef Allow_TYQUAD-are for a possible extension to 64-bit integers in which-integer = int = 32 bits and longint = long = 64 bits.--Extensions (Feb. 1993) to NAMELIST processing:- 1. Reading a ? instead of &name (the start of a namelist) causes-the namelist being sought to be written to stdout (unit 6);-to omit this feature, compile rsne.c with -DNo_Namelist_Questions.- 2. Reading the wrong namelist name now leads to an error message-and an attempt to skip input until the right namelist name is found;-to omit this feature, compile rsne.c with -DNo_Bad_Namelist_Skip.- 3. Namelist writes now insert newlines before each variable; to omit-this feature, compile xwsne.c with -DNo_Extra_Namelist_Newlines.--Nonstandard extension (Feb. 1993) to open: for sequential files,-ACCESS='APPEND' (or access='anything else starting with "A" or "a"')-causes the file to be positioned at end-of-file, so a write will-append to the file.--Some buggy Fortran programs use unformatted direct I/O to write-an incomplete record and later read more from that record than-they have written. For records other than the last, the unwritten-portion of the record reads as binary zeros. The last record is-a special case: attempting to read more from it than was written-gives end-of-file -- which may help one find a bug. Some other-Fortran I/O libraries treat the last record no differently than-others and thus give no help in finding the bug of reading more-than was written. If you wish to have this behavior, compile-uio.c with -DPad_UDread .--If you want to be able to catch write failures (e.g., due to a-disk being full) with an ERR= specifier, compile dfe.c, due.c,-sfe.c, sue.c, and wsle.c with -DALWAYS_FLUSH. This will lead to-slower execution and more I/O, but should make ERR= work as-expected, provided fflush returns an error return when its-physical write fails.---Carriage controls are meant to be interpreted by the UNIX col-program (or a similar program). Sometimes it's convenient to use-only ' ' as the carriage control character (normal single spacing).-If you compile lwrite.c and wsfe.c with -DOMIT_BLANK_CC, formatted-external output lines will have an initial ' ' quietly omitted,-making use of the col program unnecessary with output that only-has ' ' for carriage control.//GO.SYSIN DD libI77/READMEecho libI77/Version.c 1>&2sed >libI77/Version.c <<'//GO.SYSIN DD libI77/Version.c' 's/^-//'-static char junk[] = "\n@(#) LIBI77 VERSION pjw,dmg-mods 2 Nov. 1994\n";--/*-2.01 $ format added-2.02 Coding bug in open.c repaired-2.03 fixed bugs in lread.c (read * with negative f-format) and lio.c- and lio.h (e-format conforming to spec)-2.04 changed open.c and err.c (fopen and freopen respectively) to- update to new c-library (append mode)-2.05 added namelist capability-2.06 allow internal list and namelist I/O-*/--/*-close.c:- allow upper-case STATUS= values-endfile.c- create fort.nnn if unit nnn not open;- else if (file length == 0) use creat() rather than copy;- use local copy() rather than forking /bin/cp;- rewind, fseek to clear buffer (for no reading past EOF)-err.c- use neither setbuf nor setvbuf; make stderr buffered-fio.h- #define _bufend-inquire.c- upper case responses;- omit byfile test from SEQUENTIAL=- answer "YES" to DIRECT= for unopened file (open to debate)-lio.c- flush stderr, stdout at end of each stmt- space before character strings in list output only at line start-lio.h- adjust LEW, LED consistent with old libI77-lread.c- use atof()- allow "nnn*," when reading complex constants-open.c- try opening for writing when open for read fails, with- special uwrt value (2) delaying creat() to first write;- set curunit so error messages don't drop core;- no file name ==> fort.nnn except for STATUS='SCRATCH'-rdfmt.c- use atof(); trust EOF == end-of-file (so don't read past- end-of-file after endfile stmt)-sfe.c- flush stderr, stdout at end of each stmt-wrtfmt.c:- use upper case- put wrt_E and wrt_F into wref.c, use sprintf()- rather than ecvt() and fcvt() [more accurate on VAX]-*/--/* 16 Oct. 1988: uwrt = 3 after write, rewind, so close won't zap the file. */--/* 10 July 1989: change _bufend to buf_end in fio.h, wsfe.c, wrtfmt.c */--/* 28 Nov. 1989: corrections for IEEE and Cray arithmetic */-/* 29 Nov. 1989: change various int return types to long for f2c */-/* 30 Nov. 1989: various types from f2c.h */-/* 6 Dec. 1989: types corrected various places */-/* 19 Dec. 1989: make iostat= work right for internal I/O */-/* 8 Jan. 1990: add rsne, wsne -- routines for handling NAMELIST */-/* 28 Jan. 1990: have NAMELIST read treat $ as &, general white- space as blank */-/* 27 Mar. 1990: change an = to == in rd_L(rdfmt.c) so formatted reads- of logical values reject letters other than fFtT;- have nowwriting reset cf */-/* 14 Aug. 1990: adjust lread.c to treat tabs as spaces in list input */-/* 17 Aug. 1990: adjust open.c to recognize blank='Z...' as well as- blank='z...' when reopening an open file */-/* 30 Aug. 1990: prevent embedded blanks in list output of complex values;- omit exponent field in list output of values of- magnitude between 10 and 1e8; prevent writing stdin- and reading stdout or stderr; don't close stdin, stdout,- or stderr when reopening units 5, 6, 0. */-/* 18 Sep. 1990: add component udev to unit and consider old == new file- iff uinode and udev values agree; use stat rather than- access to check existence of file (when STATUS='OLD')*/-/* 2 Oct. 1990: adjust rewind.c so two successive rewinds after a write- don't clobber the file. */-/* 9 Oct. 1990: add #include "fcntl.h" to endfile.c, err.c, open.c;- adjust g_char in util.c for segmented memories. */-/* 17 Oct. 1990: replace abort() and _cleanup() with calls on- sig_die(...,1) (defined in main.c). */-/* 5 Nov. 1990: changes to open.c: complain if new= is specified and the- file already exists; allow file= to be omitted in open stmts- and allow status='replace' (Fortran 90 extensions). */-/* 11 Dec. 1990: adjustments for POSIX. */-/* 15 Jan. 1991: tweak i_ungetc in rsli.c to allow reading from- strings in read-only memory. */-/* 25 Apr. 1991: adjust namelist stuff to work with f2c -i2 */-/* 26 Apr. 1991: fix some bugs with NAMELIST read of multi-dim. arrays */-/* 16 May 1991: increase LEFBL in lio.h to bypass NeXT bug */-/* 17 Oct. 1991: change type of length field in sequential unformatted- records from int to long (for systems where sizeof(int)- can vary, depending on the compiler or compiler options). */-/* 14 Nov. 1991: change uint to Uint in fmt.h, rdfmt.c, wrtfmt.c.-/* 25 Nov. 1991: change uint to Uint in lwrite.c; change sizeof(int) to- sizeof(uioint) in fseeks in sue.c (missed on 17 Oct.). */-/* 1 Dec. 1991: uio.c: add test for read failure (seq. unformatted reads);- adjust an error return from EOF to off end of record */-/* 12 Dec. 1991: rsli.c: fix bug with internal list input that caused- the last character of each record to be ignored.- iio.c: adjust error message in internal formatted- input from "end-of-file" to "off end of record" if- the format specifies more characters than the- record contains. */-/* 17 Jan. 1992: lread.c, rsne.c: in list and namelist input,- treat "r* ," and "r*," alike (where r is a- positive integer constant), and fix a bug in- handling null values following items with repeat- counts (e.g., 2*1,,3); for namelist reading- of a numeric array, allow a new name-value subsequence- to terminate the current one (as though the current- one ended with the right number of null values).- lio.h, lwrite.c: omit insignificant zeros in- list and namelist output. To get the old- behavior, compile with -DOld_list_output . */-/* 18 Jan. 1992: make list output consistent with F format by- printing .1 rather than 0.1 (introduced yesterday). */-/* 3 Feb. 1992: rsne.c: fix namelist read bug that caused the- character following a comma to be ignored. */-/* 19 May 1992: adjust iio.c, ilnw.c, rdfmt.c and rsli.c to make err=- work with internal list and formatted I/O. */-/* 18 July 1992: adjust rsne.c to allow namelist input to stop at- an & (e.g. &end). */-/* 23 July 1992: switch to ANSI prototypes unless KR_headers is #defined ;- recognize Z format (assuming 8-bit bytes). */-/* 14 Aug. 1992: tweak wrt_E in wref.c to avoid -NaN */-/* 23 Oct. 1992: Supply missing l_eof = 0 assignment to s_rsne() in rsne.c- (so end-of-file on other files won't confuse namelist- reads of external files). Prepend f__ to external- names that are only of internal interest to lib[FI]77. */-/* 1 Feb. 1993: backspace.c: fix bug that bit when last char of 2nd- buffer == '\n'.- endfile.c: guard against tiny L_tmpnam; close and reopen- files in t_runc().- lio.h: lengthen LINTW (buffer size in lwrite.c).- err.c, open.c: more prepending of f__ (to [rw]_mode). */-/* 5 Feb. 1993: tweaks to NAMELIST: rsne.c: ? prints the namelist being- sought; namelists of the wrong name are skipped (after- an error message; xwsne.c: namelist writes have a- newline before each new variable.- open.c: ACCESS='APPEND' positions sequential files- at EOF (nonstandard extension -- that doesn't require- changing data structures). */-/* 9 Feb. 1993: Change some #ifdef MSDOS lines to #ifdef NON_UNIX_STDIO.- err.c: under NON_UNIX_STDIO, avoid close(creat(name,0666))- when the unit has another file descriptor for name. */-/* 4 March 1993: err.c, open.c: take declaration of fdopen from rawio.h;- open.c: always give f__w_mode[] 4 elements for use- in t_runc (in endfile.c -- for change of 1 Feb. 1993). */-/* 6 March 1993: uio.c: adjust off-end-of-record test for sequential- unformatted reads to respond to err= rather than end=. */-/* 12 March 1993: various tweaks for C++ */-/* 6 April 1993: adjust error returns for formatted inputs to flush- the current input line when err=label is specified.- To restore the old behavior (input left mid-line),- either adjust the #definition of errfl in fio.h or- omit the invocation of f__doend in err__fl (in err.c). */-/* 23 June 1993: iio.c: fix bug in format reversions for internal writes. */-/* 5 Aug. 1993: lread.c: fix bug in handling repetition counts for- logical data (during list or namelist input).- Change struct f__syl to struct syl (for buggy compilers). */-/* 7 Aug. 1993: lread.c: fix bug in namelist reading of incomplete- logical arrays. */-/* 9 Aug. 1993: lread.c: fix bug in namelist reading of an incomplete- array of numeric data followed by another namelist- item whose name starts with 'd', 'D', 'e', or 'E'. */-/* 8 Sept. 1993: open.c: protect #include "sys/..." with- #ifndef NON_UNIX_STDIO; Version date not changed. */-/* 10 Nov. 1993: backspace.c: add nonsense for #ifdef MSDOS */-/* 8 Dec. 1993: iio.c: adjust internal formatted reads to treat- short records as though padded with blanks- (rather than causing an "off end of record" error). */-/* 22 Feb. 1994: lread.c: check that realloc did not return NULL. */-/* 6 June 1994: Under NON_UNIX_STDIO, use binary mode for direct- formatted files (avoiding any confusion regarding \n). */-/* 5 July 1994: Fix bug (introduced 6 June 1994?) in reopening files- under NON_UNIX_STDIO. */-/* 6 July 1994: wref.c: protect with #ifdef GOOD_SPRINTF_EXPONENT an- optimization that requires exponents to have 2 digits- when 2 digits suffice.- lwrite.c wsfe.c (list and formatted external output):- omit ' ' carriage-control when compiled with- -DOMIT_BLANK_CC . Off-by-one bug fixed in character- count for list output of character strings.- Omit '.' in list-directed printing of Nan, Infinity. */-/* 12 July 1994: wrtfmt.c: under G11.4, write 0. as " .0000 " rather- than " .0000E+00". */-/* 3 Aug. 1994: lwrite.c: do not insert a newline when appending an- oversize item to an empty line. */-/* 12 Aug. 1994: rsli.c rsne.c: fix glitch (reset nml_read) that kept- ERR= (in list- or format-directed input) from working- after a NAMELIST READ. */-/* 7 Sept. 1994: typesize.c: adjust to allow types LOGICAL*1, LOGICAL*2,- INTEGER*1, and (under -DAllow_TYQUAD) INTEGER*8- in NAMELISTs. */-/* 6 Oct. 1994: util.c: omit f__mvgbt, as it is never used. */-/* 2 Nov. 1994: add #ifdef ALWAYS_FLUSH logic *///GO.SYSIN DD libI77/Version.cecho libI77/backspace.c 1>&2sed >libI77/backspace.c <<'//GO.SYSIN DD libI77/backspace.c' 's/^-//'-#include "f2c.h"-#include "fio.h"-#ifdef KR_headers-integer f_back(a) alist *a;-#else-integer f_back(alist *a)-#endif-{ unit *b;- int i, n, ndec;-#ifdef MSDOS- int j, k;- long w, z;-#endif- long x, y;- char buf[32];- if(a->aunit >= MXUNIT || a->aunit < 0)- err(a->aerr,101,"backspace")- b= &f__units[a->aunit];- if(b->useek==0) err(a->aerr,106,"backspace")- if(b->ufd==NULL) {- fk_open(1, 1, a->aunit);- return(0);- }- if(b->uend==1)- { b->uend=0;- return(0);- }- if(b->uwrt) {- (void) t_runc(a);- if (f__nowreading(b))- err(a->aerr,errno,"backspace")- }- if(b->url>0)- {- x=ftell(b->ufd);- y = x % b->url;- if(y == 0) x--;- x /= b->url;- x *= b->url;- (void) fseek(b->ufd,x,SEEK_SET);- return(0);- }-- if(b->ufmt==0)- { (void) fseek(b->ufd,-(long)sizeof(int),SEEK_CUR);- (void) fread((char *)&n,sizeof(int),1,b->ufd);- (void) fseek(b->ufd,-(long)n-2*sizeof(int),SEEK_CUR);- return(0);- }-#ifdef MSDOS- w = -1;-#endif- for(ndec = 2;; ndec = 1)- {- y = x=ftell(b->ufd);- if(x<sizeof(buf)) x=0;- else x -= sizeof(buf);- (void) fseek(b->ufd,x,SEEK_SET);- n=fread(buf,1,(int)(y-x), b->ufd);- for(i=n-ndec;i>=0;i--)- {- if(buf[i]!='\n') continue;-#ifdef MSDOS- for(j = k = 0; j <= i; j++)- if (buf[j] == '\n')- k++;- fseek(b->ufd,x,SEEK_SET);- do {- if (getc(b->ufd) == '\n') {- --k;- if ((z = ftell(b->ufd)) >= y) {- if (w == -1)- goto break2;- break;- }- w = z;- }- } while(k > 0);- fseek(b->ufd, w, SEEK_SET);-#else- fseek(b->ufd,(long)(i+1-n),SEEK_CUR);-#endif- return(0);- }-#ifdef MSDOS- break2:-#endif- if(x==0)- {- (void) fseek(b->ufd, 0L, SEEK_SET);- return(0);- }- else if(n<=0) err(a->aerr,(EOF),"backspace")- (void) fseek(b->ufd, x, SEEK_SET);- }-}//GO.SYSIN DD libI77/backspace.cecho libI77/close.c 1>&2sed >libI77/close.c <<'//GO.SYSIN DD libI77/close.c' 's/^-//'-#include "f2c.h"-#include "fio.h"-#ifdef KR_headers-integer f_clos(a) cllist *a;-#else-#undef abs-#undef min-#undef max-#include "stdlib.h"-#ifdef NON_UNIX_STDIO-#ifndef unlink-#define unlink remove-#endif-#else-#ifdef MSDOS-#include "io.h"-#else-#ifdef __cplusplus-extern "C" int unlink(const char*);-#else-extern int unlink(const char*);-#endif-#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -