From 59837e385cd5e1857d61cb21fde7e38719742298 Mon Sep 17 00:00:00 2001 From: Landon Curt Noll Date: Tue, 10 Apr 2001 16:00:53 -0700 Subject: [PATCH] Release calc version 2.11.5t2.1 --- CHANGES | 31 ++++++++++- Makefile | 8 +-- blkcpy.c | 10 ++-- cal/intfile.cal | 12 ++-- cal/regress.cal | 28 +++++----- cal/test4600.cal | 107 ++++++++++++----------------------- calc.c | 22 +++++++- calc.man | 9 +-- calcerr.tbl | 8 +-- file.c | 142 +++++++++++++++++++++++++++++------------------ file.h | 8 +-- func.c | 41 +++++++++----- help/fopen | 40 +++++++++++-- version.c | 6 +- win32.mkdef | 58 +++++++++++++++++++ win32/calcerr.c | 4 +- win32/calcerr.h | 4 +- 17 files changed, 342 insertions(+), 196 deletions(-) create mode 100644 win32.mkdef diff --git a/CHANGES b/CHANGES index af8270f..eebfabb 100644 --- a/CHANGES +++ b/CHANGES @@ -5,6 +5,33 @@ The following are the changes from calc version 2.11.5t2 to date: interactive mode. Fixed a bug that sometimes left the terminal in a non-echoing state when calc exited. + Renamed error codes E_FGETWORD1 and E_FGETWORD2 symbols to + E_FGETFIELD1 and E_FGETFIELD2. + + Made a minor format change to the top of the calc man page. + + The findid() function in file.c 2nd argument changed. The argument + is now mostly a writable flag. This function now finds the file + I/O structure for the specified file id, and verifies that + it is opened in the required manner (0 for reading or 1 for writing). + If the 2nd argument is -1, then no open checks are made at all and + NULL is then returned if the id represents a closed file. + + The calc builtin function, fopen(), now allows one to specify + opening files in binary modes. On POSIX / Linux / Un*x-like systems, + text file is the same as a binary file and so 'b' to an fopen has + no effect and is ignored. However on systems such as MS Windoz + the 'b' / binary mode has meaning. See 'help fopen' for details. + + On systems (such as MS Windoz), calc will produce a different error + message when it attempts to open /dev/tty. This will condition + will occur in things like calc scripts when they switch from ``batch + processing'' commands from and want to start interactive mode. + + Regression tests fopen in binary mode in a few places where a + difference between text and binary string lengths matter. + The intfile calc resource file also uses binary mode. + The following are the changes from calc version 2.11.5t0 to date: @@ -5172,8 +5199,8 @@ Following is a list of visible changes to calc from version 1.24.7 to 1.26.1: ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## -## @(#) $Revision: 29.27 $ -## @(#) $Id: CHANGES,v 29.27 2001/04/08 22:05:40 chongo Exp $ +## @(#) $Revision: 29.28 $ +## @(#) $Id: CHANGES,v 29.28 2001/04/10 22:13:40 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/RCS/CHANGES,v $ ## ## Under source code control: 1993/06/02 18:12:57 diff --git a/Makefile b/Makefile index c108148..40dd114 100644 --- a/Makefile +++ b/Makefile @@ -20,8 +20,8 @@ # received a copy with calc; if not, write to Free Software Foundation, Inc. # 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. # -MAKEFILE_REV= $$Revision: 29.19 $$ -# @(#) $Id: Makefile.ship,v 29.19 2001/04/08 10:54:22 chongo Exp $ +MAKEFILE_REV= $$Revision: 29.21 $$ +# @(#) $Id: Makefile.ship,v 29.21 2001/04/10 22:52:05 chongo Exp $ # @(#) $Source: /usr/local/src/cmd/calc/RCS/Makefile.ship,v $ # # Under source code control: 1990/02/15 01:48:41 @@ -1080,7 +1080,7 @@ UTIL_C_SRC= align32.c endian.c longbits.c have_newstr.c have_uid_t.c \ # and BUILD_C_SRC # UTIL_MISC_SRC= calcerr_h.sed calcerr_h.awk calcerr_c.sed calcerr_c.awk \ - calcerr.tbl check.awk + calcerr.tbl check.awk win32.mkdef # these .o files may get built in the process of building BUILD_H_SRC # @@ -2564,7 +2564,7 @@ win32_hsrc: ${MAKE_FILE} win32.mkdef ${Q}rm -rf win32 ${Q}mkdir win32 ${Q}cp ${UTIL_C_SRC} win32 - ${Q}cp ${UTIL_MISC_SRC} win32.mkdef Makefile win32 + ${Q}cp ${UTIL_MISC_SRC} Makefile win32 ${Q}(cd win32; \ echo "cd win32"; \ echo "$(MAKE) hsrc `cat win32.mkdef`"; \ diff --git a/blkcpy.c b/blkcpy.c index 6172fce..05149f6 100644 --- a/blkcpy.c +++ b/blkcpy.c @@ -19,8 +19,8 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * - * @(#) $Revision: 29.2 $ - * @(#) $Id: blkcpy.c,v 29.2 2000/06/07 14:02:13 chongo Exp $ + * @(#) $Revision: 29.3 $ + * @(#) $Id: blkcpy.c,v 29.3 2001/04/10 22:06:46 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/blkcpy.c,v $ * * Under source code control: 1997/04/18 20:41:26 @@ -581,7 +581,7 @@ copyblk2file(BLOCK *sblk, long ssi, long num, FILEID id, long dsi) if (num == 0) return 0; - fiop = findid(id, 'w'); + fiop = findid(id, TRUE); if (fiop == NULL) return E_COPYF1; fp = fiop->fp; @@ -618,7 +618,7 @@ copyfile2blk(FILEID id, long ssi, long num, BLOCK *dblk, long dsi, BOOL noreloc) if (id < 3) /* excludes copying from stdin */ return E_COPYF1; - fiop = findid(id, 'r'); + fiop = findid(id, FALSE); if (fiop == NULL) return E_COPYF1; @@ -690,7 +690,7 @@ copystr2file(STRING *str, long ssi, long num, FILEID id, long dsi) return 0; if ((USB32) ssi + num > len) return E_COPY5; /* Insufficient memory in str */ - fiop = findid(id, 'w'); + fiop = findid(id, TRUE); if (fiop == NULL) return E_COPYF1; fp = fiop->fp; diff --git a/cal/intfile.cal b/cal/intfile.cal index 936b881..ecc12af 100644 --- a/cal/intfile.cal +++ b/cal/intfile.cal @@ -17,8 +17,8 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * - * @(#) $Revision: 29.4 $ - * @(#) $Id: intfile.cal,v 29.4 2001/04/08 08:13:10 chongo Exp $ + * @(#) $Revision: 29.5 $ + * @(#) $Id: intfile.cal,v 29.5 2001/04/10 22:09:34 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/intfile.cal,v $ * * Under source code control: 2001/03/31 08:13:11 @@ -56,7 +56,7 @@ define file2be(filename) /* * open the file for reading */ - fd = fopen(filename, "r"); + fd = fopen(filename, "rb"); if (!isfile(fd)) quit "file2be: cannot open file for reading"; /* @@ -98,7 +98,7 @@ define file2le(filename) /* * open the file for reading */ - fd = fopen(filename, "r"); + fd = fopen(filename, "rb"); if (!isfile(fd)) quit "file2le: cannot open file for reading"; /* @@ -150,7 +150,7 @@ define be2file(v, filename) /* * open the file for writing */ - fd = fopen(filename, "w"); + fd = fopen(filename, "wb"); if (!isfile(fd)) quit "be2file: cannot open file for writing"; /* @@ -199,7 +199,7 @@ define le2file(v, filename) /* * open the file for writing */ - fd = fopen(filename, "w"); + fd = fopen(filename, "wb"); if (!isfile(fd)) quit "le2file: cannot open file for writing"; /* diff --git a/cal/regress.cal b/cal/regress.cal index 76245cd..c345ac4 100644 --- a/cal/regress.cal +++ b/cal/regress.cal @@ -17,8 +17,8 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * - * @(#) $Revision: 29.7 $ - * @(#) $Id: regress.cal,v 29.7 2001/04/08 10:09:39 chongo Exp $ + * @(#) $Revision: 29.8 $ + * @(#) $Id: regress.cal,v 29.8 2001/04/10 22:08:20 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/regress.cal,v $ * * Under source code control: 1990/02/15 01:50:36 @@ -5118,15 +5118,15 @@ define test_is() a = assoc(); print '5901: a = assoc()'; if (config("windows")) { - ofd = fopen("NUL:", "r"); - print '5902: ofd = fopen("NUL:", "r")'; - cfd = fopen("NUL:", "r"); - print '5903: cfd = fopen("NUL:", "r")'; + ofd = fopen("NUL:", "rb"); + print '5902: ofd = fopen("NUL:", "rb")'; + cfd = fopen("NUL:", "rb"); + print '5903: cfd = fopen("NUL:", "rb")'; } else { - ofd = fopen("/dev/null", "r"); - print '5902: ofd = fopen("/dev/null", "r")'; - cfd = fopen("/dev/null", "r"); - print '5903: cfd = fopen("/dev/null", "r")'; + ofd = fopen("/dev/null","rb"); + print '5902: ofd = fopen("/dev/null","rb")'; + cfd = fopen("/dev/null","rb"); + print '5903: cfd = fopen("/dev/null","rb")'; } fclose(cfd); print '5904: fclose(cfd)'; @@ -6305,8 +6305,8 @@ define test_blkcpy() /* blkcpy the last 5 octets of B1 to a new block C */ - blkcpy(C = blk(), B1, 5, ,100); - print '6821: blkcpy(C = blk(), B1, 5, ,100);'; + blkcpy(C = blk(), B1,5,,100); + print '6821: blkcpy(C = blk(), B1,5,,100);'; vrfy(C == A, '6822: C == A'); /* blkcpy to and from a file */ @@ -6322,8 +6322,8 @@ define test_blkcpy() blkcpy(fs, A, ,100); print '6828: blkcpy(fs, A, ,100);'; vrfy(size(fs) == 105, '6829: size(f) == 105'); - blkcpy(C = blk(), fs, 2, ,100); - print '6830: blkcpy(C = blk(), fs, 2, ,100)'; + blkcpy(C = blk(), fs,2,,100); + print '6830: blkcpy(C = blk(), fs,2,,100)'; vrfy(C == (blk() = {1,2}), '6831: C == (blk() = {1,2}'); /* blkcpy string to a block */ diff --git a/cal/test4600.cal b/cal/test4600.cal index 48388c9..400d119 100644 --- a/cal/test4600.cal +++ b/cal/test4600.cal @@ -19,8 +19,8 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * - * @(#) $Revision: 29.3 $ - * @(#) $Id: test4600.cal,v 29.3 2001/04/08 10:09:39 chongo Exp $ + * @(#) $Revision: 29.4 $ + * @(#) $Id: test4600.cal,v 29.4 2001/04/10 22:09:02 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/test4600.cal,v $ * * Under source code control: 1996/07/02 20:04:40 @@ -53,10 +53,10 @@ define stest(str, verbose) /* * do file operations */ - f = fopen("junk4600", "w"); + f = fopen("junk4600", "wb"); if (iserror(f)) { print 'failed'; - print '**** fopen("junk4600", "w") failed'; + print '**** fopen("junk4600", "wb") failed'; return 1; } if (iserror(fputs(f, @@ -67,9 +67,9 @@ define stest(str, verbose) print '**** fputs(f, "Fourscore ... failed'; return 1; } - if (iserror(freopen(f, "r"))) { + if (iserror(freopen(f, "rb"))) { print 'failed'; - print '**** iserror(freopen(f, "r")) failed'; + print '**** iserror(freopen(f, "rb")) failed'; return 1; } if (iserror(rewind(f))) { @@ -87,68 +87,35 @@ define stest(str, verbose) print '**** ftell(f) != 13 failed'; return 1; } - if (config("windows")) { - if (search(f, "and") != 110) { - print 'failed'; - print '**** search(f, "and") != 110 failed'; - return 1; - } - if (ftell(f) != 113) { - print 'failed'; - print '**** ftell(f) != 113 failed'; - return 1; - } - if (!isnull(search(f, "and"))) { - print 'failed'; - print '**** !isnull(search(f, "and")) failed'; - return 1; - } - if (ftell(f) != 174) { - print 'failed'; - print '**** ftell(f) != 174 failed'; - return 1; - } - if (rsearch(f, "and") != 110) { - print 'failed'; - print '**** rsearch(f, "and") != 110 failed'; - return 1; - } - if (ftell(f) != 112) { - print 'failed'; - print '**** ftell(f) != 112 failed'; - return 1; - } - } else { - if (search(f, "and") != 109) { - print 'failed'; - print '**** search(f, "and") != 109 failed'; - return 1; - } - if (ftell(f) != 112) { - print 'failed'; - print '**** ftell(f) != 112 failed'; - return 1; - } - if (!isnull(search(f, "and"))) { - print 'failed'; - print '**** !isnull(search(f, "and")) failed'; - return 1; - } - if (ftell(f) != 172) { - print 'failed'; - print '**** ftell(f) != 172 failed'; - return 1; - } - if (rsearch(f, "and") != 109) { - print 'failed'; - print '**** rsearch(f, "and") != 109 failed'; - return 1; - } - if (ftell(f) != 111) { - print 'failed'; - print '**** ftell(f) != 111 failed'; - return 1; - } + if (search(f, "and") != 109) { + print 'failed'; + print '**** search(f, "and") != 109 failed'; + return 1; + } + if (ftell(f) != 112) { + print 'failed'; + print '**** ftell(f) != 112 failed'; + return 1; + } + if (!isnull(search(f, "and"))) { + print 'failed'; + print '**** !isnull(search(f, "and")) failed'; + return 1; + } + if (ftell(f) != 172) { + print 'failed'; + print '**** ftell(f) != 172 failed'; + return 1; + } + if (rsearch(f, "and") != 109) { + print 'failed'; + print '**** rsearch(f, "and") != 109 failed'; + return 1; + } + if (ftell(f) != 111) { + print 'failed'; + print '**** ftell(f) != 111 failed'; + return 1; } if (iserror(fseek(f, -4, 1))) { print 'failed'; @@ -206,7 +173,7 @@ define ttest(str, m, n, verbose) print str:":",:; } i = rm("-f", "junk4600"); - f = fopen("junk4600", "w"); + f = fopen("junk4600", "wb"); if (isnull(n)) n = 4; @@ -231,7 +198,7 @@ define ttest(str, m, n, verbose) fflush(f); if (verbose > 1) printf("File has size %d\n", pos[i]); - freopen(f, "r"); + freopen(f, "rb"); if (size(f) != pos[i]) { print 'failed'; printf("**** Failure 1 for file size\n"); diff --git a/calc.c b/calc.c index a6a8b1e..125a787 100644 --- a/calc.c +++ b/calc.c @@ -19,8 +19,8 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * - * @(#) $Revision: 29.7 $ - * @(#) $Id: calc.c,v 29.7 2001/03/17 21:31:47 chongo Exp $ + * @(#) $Revision: 29.8 $ + * @(#) $Id: calc.c,v 29.8 2001/04/10 22:03:13 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/calc.c,v $ * * Under source code control: 1990/02/15 01:48:11 @@ -625,9 +625,18 @@ main(int argc, char **argv) if (!p_flag && i_flag && !stdin_tty) { closeinput(); if(!freopen("/dev/tty", "r", stdin)) { +#if defined (_WIN32) + fprintf(stderr, + "/dev/tty does not exist on " + "this operating system. " + "Change operating systems\n" + "or don't use this calc mode " + "in the future, sorry!\n"); +#else /* Windoz free systems */ fprintf(stderr, "Unable to associate stdin" " with /dev/tty"); +#endif /* Windoz free systems */ set_run_state(RUN_EXIT_WITH_ERROR); break; } @@ -646,9 +655,18 @@ main(int argc, char **argv) !p_flag && (!havecommands||i_flag)) { closeinput(); if(!freopen("/dev/tty", "r", stdin)) { +#if defined (_WIN32) + fprintf(stderr, + "/dev/tty does not exist on " + "this operating system. " + "Change operating systems\n" + "or don't use this calc mode " + "in the future, sorry!\n"); +#else /* Windoz free systems */ fprintf(stderr, "Unable to associate stdin" " with /dev/tty"); +#endif /* Windoz free systems */ set_run_state(RUN_EXIT_WITH_ERROR); break; } diff --git a/calc.man b/calc.man index 6c1f16d..668b688 100644 --- a/calc.man +++ b/calc.man @@ -15,8 +15,8 @@ .\" received a copy with calc; if not, write to Free Software Foundation, Inc. .\" 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. .\" -.\" @(#) $Revision: 29.5 $ -.\" @(#) $Id: calc.man,v 29.5 2000/06/07 14:02:13 chongo Exp $ +.\" @(#) $Revision: 29.6 $ +.\" @(#) $Id: calc.man,v 29.6 2001/04/10 21:48:46 chongo Exp $ .\" @(#) $Source: /usr/local/src/cmd/calc/RCS/calc.man,v $ .\" .\" Under source code control: 1991/07/23 05:48:26 @@ -36,20 +36,21 @@ calc \- arbitrary precision calculator .RB [ \-c ] .RB [ \-C ] .RB [ \-d ] -.RB [ -D\ \&calc_debug[:resource_debug[:user_debug]] ] .br .in +5n +.RB [ -D\ \&calc_debug[:resource_debug[:user_debug]] ] +.br .RB [ \-e ] .RB [ \-h ] .RB [ \-i ] .RB [ \-m\ \&mode ] .RB [ \-n ] +.br .RB [ \-p ] .RB [ \-q ] .RB [ \-s ] .RB [ \-u ] .RB [ \-v ] -.br .RB [ calc_cmd\ \&.\|.\|. ] .in -5n .sp diff --git a/calcerr.tbl b/calcerr.tbl index 4255872..6ab0292 100644 --- a/calcerr.tbl +++ b/calcerr.tbl @@ -17,8 +17,8 @@ # received a copy with calc; if not, write to Free Software Foundation, Inc. # 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. # -# @(#) $Revision: 29.3 $ -# @(#) $Id: calcerr.tbl,v 29.3 2000/07/17 15:35:49 chongo Exp $ +# @(#) $Revision: 29.4 $ +# @(#) $Id: calcerr.tbl,v 29.4 2001/04/10 22:06:46 chongo Exp $ # @(#) $Source: /usr/local/src/cmd/calc/RCS/calcerr.tbl,v $ # # Under source code control: 1996/05/23 17:38:44 @@ -108,8 +108,8 @@ E_FGETSTR1 Non-file first argument for fgetstr E_FGETSTR2 File not open for reading for fgetstr E_FGETLINE1 Non-file argument for fgetline E_FGETLINE2 File not open for reading for fgetline -E_FGETWORD1 Non-file argument for fgetword -E_FGETWORD2 File not open for reading for fgetword +E_FGETFIELD1 Non-file argument for fgetfield +E_FGETFIELD2 File not open for reading for fgetfield E_REWIND1 Non-file argument for rewind E_FILES Non-integer argument for files E_PRINTF1 Non-string fmt argument for fprint diff --git a/file.c b/file.c index 513a3a6..c62627d 100644 --- a/file.c +++ b/file.c @@ -19,8 +19,8 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * - * @(#) $Revision: 29.6 $ - * @(#) $Id: file.c,v 29.6 2001/03/17 21:31:47 chongo Exp $ + * @(#) $Revision: 29.7 $ + * @(#) $Id: file.c,v 29.7 2001/04/10 22:06:46 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/file.c,v $ * * Under source code control: 1991/07/20 00:21:56 @@ -158,7 +158,7 @@ file_init(void) } else { fp = (FILE *) fdopen(i, "w"); if (fp) { - strcpy(files[idnum].mode, "w?"); + strcpy(files[idnum].mode, "w"); files[idnum].reading = FALSE; } else @@ -207,7 +207,7 @@ openid(char *name, char *mode) int i; if (idnum >= MAXFILES) - return -77; + return -E_FOPEN3; fiop = &files[3]; for (i = 3; i < MAXFILES; fiop++,i++) { @@ -243,11 +243,32 @@ openid(char *name, char *mode) fiop->reading = TRUE; fiop->writing = TRUE; fiop->action = 0; - if (mode[1] == '\0') { - if (*mode == 'r') + + /* + * determine file open mode + * + * While a leading 'r' is for reading and a leading 'w' is + * for writing, the presense of a '+' in the string means + * both reading and writing. A leading 'a' means append + * which is writing. + */ + if (mode[0] == 'r') { + fiop->reading = TRUE; + if (strchr(mode, '+') == NULL) { fiop->writing = FALSE; - else + } else { + fiop->writing = TRUE; + } + } else if (mode[0] == 'w' || mode[0] == 'a') { + fiop->writing = TRUE; + if (strchr(mode, '+') == NULL) { fiop->reading = FALSE; + } else { + fiop->reading = TRUE; + } + } else { + fiop->reading = FALSE; + fiop->writing = FALSE; } strcpy(fiop->mode, mode); return id; @@ -346,11 +367,32 @@ reopenid(FILEID id, char *mode, char *name) fiop->reading = TRUE; fiop->writing = TRUE; fiop->action = 0; - if (mode[1] == '\0') { - if (*mode == 'r') + + /* + * determine file open mode + * + * While a leading 'r' is for reading and a leading 'w' is + * for writing, the presense of a '+' in the string means + * both reading and writing. A leading 'a' means append + * which is writing. + */ + if (mode[0] == 'r') { + fiop->reading = TRUE; + if (strchr(mode, '+') == NULL) { fiop->writing = FALSE; - else + } else { + fiop->writing = TRUE; + } + } else if (mode[0] == 'w' || mode[0] == 'a') { + fiop->writing = TRUE; + if (strchr(mode, '+') == NULL) { fiop->reading = FALSE; + } else { + fiop->reading = TRUE; + } + } else { + fiop->reading = FALSE; + fiop->writing = FALSE; } strcpy(fiop->mode, mode); return id; @@ -358,13 +400,13 @@ reopenid(FILEID id, char *mode, char *name) /* - * Find the file I/O structure for the specified file id, and verify that - * it is opened in the required manner ('r' for reading or 'w' for writing). - * If mode is 0, then no open checks are made at all, and NULL is then + * Find the file I/O structure for the specified file id, and verifies that + * it is opened in the required manner (0 for reading or 1 for writing). + * If writable is -1, then no open checks are made at all and NULL is then * returned if the id represents a closed file. */ FILEIO * -findid(FILEID id, int mode) +findid(FILEID id, int writable) { FILEIO *fiop; /* file structure */ int i; @@ -383,21 +425,11 @@ findid(FILEID id, int mode) if (i == idnum) return NULL; - switch (mode) { - case 'r': - if (!fiop->reading) - return NULL; - break; - case 'w': - if (!fiop->writing) - return NULL; - break; - case 0: - break; - default: - /* This should not happen */ - math_error("Unknown findid mode"); - /*NOTREACHED*/ + if (writable >= 0) { + if ((writable && !fiop->writing) || + (!writable && !fiop->reading)) { + return NULL; + } } return fiop; } @@ -409,7 +441,7 @@ findid(FILEID id, int mode) BOOL validid(FILEID id) { - return (findid(id, 0) != NULL); + return (findid(id, -1) != NULL); } @@ -505,7 +537,7 @@ errorid(FILEID id) { FILEIO *fiop; /* file structure */ - fiop = findid(id, 0); + fiop = findid(id, -1); if (fiop == NULL) return EOF; return (ferror(fiop->fp) != 0); @@ -520,7 +552,7 @@ eofid(FILEID id) { FILEIO *fiop; /* file structure */ - fiop = findid(id, 0); + fiop = findid(id, -1); if (fiop == NULL) return EOF; return (feof(fiop->fp) != 0); @@ -535,7 +567,7 @@ flushid(FILEID id) { FILEIO *fiop; /* file structure */ - fiop = findid(id, 0); + fiop = findid(id, -1); if (fiop == NULL) return 0; if (!fiop->writing || fiop->action == 'r') @@ -598,7 +630,7 @@ readid(FILEID id, int flags, char **retptr) totlen = 0; str = NULL; - fiop = findid(id, 'r'); + fiop = findid(id, FALSE); if (fiop == NULL) return 1; nlstop = (flags & 1); @@ -679,7 +711,7 @@ getcharid(FILEID id) FILEIO *fiop; FILEPOS fpos; - fiop = findid(id, 'r'); + fiop = findid(id, FALSE); if (fiop == NULL) return -2; if (fiop->action == 'w') { @@ -710,7 +742,7 @@ printid(FILEID id, int flags) /* * filewall - file is closed */ - fiop = findid(id, 0); + fiop = findid(id, -1); if (fiop == NULL) { if (flags & PRINT_UNAMBIG) math_fmt("FILE %d closed", id); @@ -787,7 +819,7 @@ idprintf(FILEID id, char *fmt, int count, VALUE **vals) BOOL printstring; BOOL printchar; - fiop = findid(id, 'w'); + fiop = findid(id, TRUE); if (fiop == NULL) return 1; if (fiop->action == 'r') { @@ -1014,7 +1046,7 @@ idfputc(FILEID id, int ch) FILEPOS fpos; /* get the file info pointer */ - fiop = findid(id, 'w'); + fiop = findid(id, TRUE); if (fiop == NULL) return 1; if (fiop->action == 'r') { @@ -1049,7 +1081,7 @@ idungetc(FILEID id, int ch) { FILEIO *fiop; - fiop = findid(id, 'r'); + fiop = findid(id, FALSE); if (fiop == NULL) return -2; if (fiop->action != 'r') @@ -1072,7 +1104,7 @@ idfputs(FILEID id, char *str) FILEPOS fpos; /* get the file info pointer */ - fiop = findid(id, 'w'); + fiop = findid(id, TRUE); if (fiop == NULL) return 1; @@ -1110,7 +1142,7 @@ idfputstr(FILEID id, char *str) FILEPOS fpos; /* get the file info pointer */ - fiop = findid(id, 'w'); + fiop = findid(id, TRUE); if (fiop == NULL) return 1; @@ -1140,7 +1172,7 @@ int rewindid(FILEID id) { FILEIO *fiop; - fiop = findid(id, 0); + fiop = findid(id, -1); if (fiop == NULL) return 1; rewind(fiop->fp); @@ -1328,7 +1360,7 @@ getloc(FILEID id, ZVALUE *res) /* * convert id to stream */ - fiop = findid(id, 0); + fiop = findid(id, -1); if (fiop == NULL) { /* file not open */ return -1; @@ -1353,7 +1385,7 @@ ftellid(FILEID id, ZVALUE *res) FILEPOS fpos; /* current file position */ /* get FILEIO */ - fiop = findid(id, 0); + fiop = findid(id, -1); if (fiop == NULL) return -2; @@ -1376,7 +1408,7 @@ fseekid(FILEID id, ZVALUE offset, int whence) int ret = 0; /* return code */ /* setup */ - fiop = findid(id, 0); + fiop = findid(id, -1); if (fiop == NULL) return -2; @@ -1501,7 +1533,7 @@ setloc(FILEID id, ZVALUE zpos) /* * convert id to stream */ - fiop = findid(id, 0); + fiop = findid(id, -1); if (fiop == NULL) { /* file not open */ return -1; @@ -1669,7 +1701,7 @@ getsize(FILEID id, ZVALUE *res) /* * convert id to stream */ - fiop = findid(id, 0); + fiop = findid(id, -1); if (fiop == NULL) { /* file not open */ return 1; @@ -1705,7 +1737,7 @@ get_device(FILEID id, ZVALUE *dev) /* * convert id to stream */ - fiop = findid(id, 0); + fiop = findid(id, -1); if (fiop == NULL) { /* file not open */ return -1; @@ -1738,7 +1770,7 @@ get_inode(FILEID id, ZVALUE *inode) /* * convert id to stream */ - fiop = findid(id, 0); + fiop = findid(id, -1); if (fiop == NULL) { /* file not open */ return -1; @@ -1774,7 +1806,7 @@ zfilesize(FILEID id) ZVALUE ret; /* file size as a ZVALUE return value */ /* file FILEIO */ - fiop = findid(id, 0); + fiop = findid(id, -1); if (fiop == NULL) { /* return neg value for non-file error */ itoz(-1, &ret); @@ -2144,7 +2176,7 @@ fscanfid(FILEID id, char *fmt, int count, VALUE **vals) FILE *fp; FILEPOS fpos; - fiop = findid(id, 'r'); + fiop = findid(id, FALSE); if (fiop == NULL) return -2; @@ -2408,7 +2440,7 @@ isattyid(FILEID id) { FILEIO *fiop; - fiop = findid(id, 0); + fiop = findid(id, -1); if (fiop == NULL) return -2; return isatty(fileno(fiop->fp)); @@ -2445,7 +2477,7 @@ fsearch(FILEID id, char *str, ZVALUE start, ZVALUE end, ZVALUE *res) long k = 0; /* get FILEIO */ - fiop = findid(id, 'r'); + fiop = findid(id, FALSE); if (fiop == NULL) return -2; @@ -2564,7 +2596,7 @@ frsearch(FILEID id, char *str, ZVALUE first, ZVALUE last, ZVALUE *res) char *s; /* str comparison pointer */ /* get FILEIO */ - fiop = findid(id, 'r'); + fiop = findid(id, FALSE); if (fiop == NULL) return -2; @@ -2641,7 +2673,7 @@ findfname(FILEID id) { FILEIO *fiop; - fiop = findid(id, 0); + fiop = findid(id, -1); if (fiop == NULL) return NULL; diff --git a/file.h b/file.h index e59ed82..181e802 100644 --- a/file.h +++ b/file.h @@ -19,8 +19,8 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * - * @(#) $Revision: 29.2 $ - * @(#) $Id: file.h,v 29.2 2000/06/07 14:02:13 chongo Exp $ + * @(#) $Revision: 29.3 $ + * @(#) $Id: file.h,v 29.3 2001/04/10 22:06:46 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/file.h,v $ * * Under source code control: 1996/05/24 05:55:58 @@ -50,7 +50,7 @@ typedef struct { BOOL reading; /* TRUE if opened for reading */ BOOL writing; /* TRUE if opened for writing */ char action; /* most recent use for 'r', 'w' or 0 */ - char mode[3]; /* open mode */ + char mode[sizeof("rb+")];/* open mode */ } FILEIO; @@ -85,7 +85,7 @@ typedef struct { /* * external functions */ -extern FILEIO * findid(FILEID id, int mode); +extern FILEIO * findid(FILEID id, int writable); extern int fgetposid(FILEID id, FILEPOS *ptr); extern int fsetposid(FILEID id, FILEPOS *ptr); extern int get_open_siz(FILE *fp, ZVALUE *res); diff --git a/func.c b/func.c index 66278df..845e41a 100644 --- a/func.c +++ b/func.c @@ -19,8 +19,8 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * - * @(#) $Revision: 29.8 $ - * @(#) $Id: func.c,v 29.8 2001/04/08 10:06:56 chongo Exp $ + * @(#) $Revision: 29.9 $ + * @(#) $Id: func.c,v 29.9 2001/04/10 22:06:46 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/func.c,v $ * * Under source code control: 1990/02/15 01:48:15 @@ -4987,24 +4987,31 @@ f_fopen(VALUE *v1, VALUE *v2) /* initialize VALUE */ result.v_subtype = V_NOSUBTYPE; + /* check for a valid mode [rwa][b+\0][b+\0] */ if (v1->v_type != V_STR || v2->v_type != V_STR) return error_value(E_FOPEN1); mode = v2->v_str->s_str; - if ((*mode != 'r') && (*mode != 'w') && (*mode != 'a')) return error_value(E_FOPEN2); if (mode[1] != '\0') { - if (mode[1] != '+') - return error_value(E_FOPEN2); - if (mode[2] != '\0') + if (mode[1] != '+' && mode[1] != 'b') return error_value(E_FOPEN2); + if (mode[2] != '\0') { + if ((mode[2] != '+' && mode[2] != 'b') || + mode[1] == mode[2]) + return error_value(E_FOPEN2); + if (mode[3] != '\0') + return error_value(E_FOPEN2); + } } + + /* try to open */ errno = 0; id = openid(v1->v_str->s_str, v2->v_str->s_str); if (id == FILEID_NONE) return error_value(errno); if (id < 0) - return error_value(E_FOPEN3); + return error_value(-id); result.v_type = V_FILE; result.v_file = id; return result; @@ -5021,21 +5028,27 @@ f_freopen(int count, VALUE **vals) /* initialize VALUE */ result.v_subtype = V_NOSUBTYPE; + /* check for a valid mode [rwa][b+\0][b+\0] */ if (vals[0]->v_type != V_FILE) return error_value(E_FREOPEN1); if (vals[1]->v_type != V_STR) return error_value(E_FREOPEN2); - mode = vals[1]->v_str->s_str; - if ((*mode != 'r') && (*mode != 'w') && (*mode != 'a')) return error_value(E_FREOPEN2); if (mode[1] != '\0') { - if (mode[1] != '+') - return error_value(E_FREOPEN2); - if (mode[2] != '\0') + if (mode[1] != '+' && mode[1] != 'b') return error_value(E_FREOPEN2); + if (mode[2] != '\0') { + if ((mode[2] != '+' && mode[2] != 'b') || + mode[1] == mode[2]) + return error_value(E_FOPEN2); + if (mode[3] != '\0') + return error_value(E_FREOPEN2); + } } + + /* try to reopen */ errno = 0; if (count == 2) { id = reopenid(vals[0]->v_file, mode, NULL); @@ -6141,10 +6154,10 @@ f_fgetfield(VALUE *vp) result.v_subtype = V_NOSUBTYPE; if (vp->v_type != V_FILE) - return error_value(E_FGETWORD1); + return error_value(E_FGETFIELD1); i = readid(vp->v_file, 14, &str); if (i > 0) - return error_value(E_FGETWORD2); + return error_value(E_FGETFIELD2); result.v_type = V_NULL; if (i == 0) { result.v_type = V_STR; diff --git a/help/fopen b/help/fopen index 8adee56..66cb1ad 100644 --- a/help/fopen +++ b/help/fopen @@ -15,9 +15,39 @@ DESCRIPTION opened for either reading, writing, or appending. The mode is controlled by the mode flag as follows: - "r" reading - "w" writing - "a" appending + allow allow file is positioned file(*) + mode reading writing truncated at mode + ---- ------- ------- --------- --------- ---- + r Y N N beginning text + rb Y N N beginning binary + r+ Y N N beginning text + r+b Y N N beginning binary + rb+ Y N N beginning binary + + w N Y Y beginning text + wb N Y Y beginning binary + w+ Y Y Y beginning text + w+b Y Y Y beginning binary + wb+ Y Y Y beginning binary + + a N Y Y end text + ab N Y Y end binary + a+ Y Y Y end text + a+b Y Y Y end binary + ab+ Y Y Y end binary + + (*) NOTE on 'b' / binary/text mode: + + The 'b' or fopen binary mode has no effect on POSIX / Linux + / Un*x-like systems. On those systems a text file is the + same as a binary file (as it should be for any modern-day + operating system). Adding 'b' to an fopen has no effect + and is ignored. + + Some non-POSIX systems sucn as MS Windoz treat text files + and binary files differently. In text mode MS Windoz consider + "\r\n" and end-of-line character. On an Apple MAC, the + text mode end-of-line character is "\r". Names of files are subject to ~ expansion just like the C or Korn shell. For example, the file name: @@ -90,8 +120,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## -## @(#) $Revision: 29.2 $ -## @(#) $Id: fopen,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: fopen,v 29.3 2001/04/10 21:46:45 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fopen,v $ ## ## Under source code control: 1994/10/27 03:04:17 diff --git a/version.c b/version.c index 1ab62b3..89df24f 100644 --- a/version.c +++ b/version.c @@ -19,8 +19,8 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * - * @(#) $Revision: 29.22 $ - * @(#) $Id: version.c,v 29.22 2001/04/08 22:05:40 chongo Exp $ + * @(#) $Revision: 29.23 $ + * @(#) $Id: version.c,v 29.23 2001/04/10 22:13:40 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/version.c,v $ * * Under source code control: 1990/05/22 11:00:58 @@ -43,7 +43,7 @@ static char *program; #define MAJOR_VER 2 /* major version */ #define MINOR_VER 11 /* minor version */ #define MAJOR_PATCH 5 /* patch level or 0 if no patch */ -#define MINOR_PATCH "2" /* test number or empty string if no patch */ +#define MINOR_PATCH "2.1" /* test number or empty string if no patch */ /* * calc version constants diff --git a/win32.mkdef b/win32.mkdef new file mode 100644 index 0000000..86c45ee --- /dev/null +++ b/win32.mkdef @@ -0,0 +1,58 @@ +TERMCONTROL=-DUSE_WIN32 +HAVE_VSPRINTF=-UDONT_HAVE_VSPRINTF +BYTE_ORDER=-DLITTLE_ENDIAN +LONG_BITS=32 +LONGLONG_BITS=0 +HAVE_FPOS=-DHAVE_NO_FPOS +HAVE_FPOS_POS=-DHAVE_NO_FPOS_POS +FPOS_POS_BITS=-UFPOS_POS_BITS +FPOS_BITS=-DFPOS_BITS=64 +OFF_T_BITS=-DOFF_T_BITS=32 +DEV_BITS=-DDEV_BITS=32 +INODE_BITS=-DINODE_BITS=16 +HAVE_OFFSCL=-UOFF_T_NON_SCALAR +HAVE_POSSCL=-UFILEPOS_NON_SCALAR +HAVE_CONST=-UHAVE_NO_CONST +HAVE_UID_T=-DHAVE_NO_UID_T +HAVE_NEWSTR=-UHAVE_NO_NEWSTR +HAVE_MEMMOVE=-UHAVE_NO_MEMMOVE +HAVE_USTAT=-DHAVE_NO_USTAT +HAVE_GETSID=-DHAVE_NO_GETSID +HAVE_GETPGID=-DHAVE_NO_GETPGID +HAVE_GETTIME=-DHAVE_NO_GETTIME +HAVE_GETPRID=-DHAVE_NO_GETPRID +HAVE_URANDOM_H=NO +HAVE_GETRUSAGE=-DHAVE_NO_GETRUSAGE +HAVE_STRDUP=-UHAVE_NO_STRDUP +ALIGN32=-UMUST_ALIGN32 +HAVE_MALLOC_H=YES +HAVE_STDLIB_H=YES +HAVE_STRING_H=YES +HAVE_TIMES_H=NO +HAVE_SYS_TIMES_H=NO +HAVE_TIME_H=YES +HAVE_SYS_TIME_H=NO +HAVE_UNISTD_H=NO + +LIBDIR=/lib/calc +HELPDIR=/lib/calc/help +INCDIRCALC=/include/calc +CUSTOMLIBDIR=/lib/calc/custom +CUSTOMHELPDIR=/lib/calc/help/custhelp +SCRIPTDIR=/lib/calc/cscript +MANDIR= +CATDIR= +MANEXT= +CATEXT= +NROFF= +NROFF_ARG= +MANMAKE= +MANMODE= +CALCPATH=./cal +CALCRC='/lib/calc/startup:~/.calcrc:./.calcinit' +USE_READLINE= +READLINE_LIB= +READLINE_INCLUDE= +CALCPAGER= + +ECHO= diff --git a/win32/calcerr.c b/win32/calcerr.c index 98ca401..675498e 100644 --- a/win32/calcerr.c +++ b/win32/calcerr.c @@ -90,8 +90,8 @@ CONST char *error_table[E__COUNT+2] = { "File not open for reading for fgetstr", "Non-file argument for fgetline", "File not open for reading for fgetline", - "Non-file argument for fgetword", - "File not open for reading for fgetword", + "Non-file argument for fgetfield", + "File not open for reading for fgetfield", "Non-file argument for rewind", "Non-integer argument for files", "Non-string fmt argument for fprint", diff --git a/win32/calcerr.h b/win32/calcerr.h index 9f057df..e764cbf 100644 --- a/win32/calcerr.h +++ b/win32/calcerr.h @@ -87,8 +87,8 @@ #define E_FGETSTR2 10074 /* File not open for reading for fgetstr */ #define E_FGETLINE1 10075 /* Non-file argument for fgetline */ #define E_FGETLINE2 10076 /* File not open for reading for fgetline */ -#define E_FGETWORD1 10077 /* Non-file argument for fgetword */ -#define E_FGETWORD2 10078 /* File not open for reading for fgetword */ +#define E_FGETFIELD1 10077 /* Non-file argument for fgetfield */ +#define E_FGETFIELD2 10078 /* File not open for reading for fgetfield */ #define E_REWIND1 10079 /* Non-file argument for rewind */ #define E_FILES 10080 /* Non-integer argument for files */ #define E_PRINTF1 10081 /* Non-string fmt argument for fprint */