/* @(#)txtfile.c 17.1.1.1 (ES0-DMD) 01/25/02 17:39:12 */ /*=========================================================================== Copyright (C) 1995 European Southern Observatory (ESO) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Massachusetss Ave, Cambridge, MA 02139, USA. Corresponding concerning ESO-MIDAS should be addressed as follows: Internet e-mail: midas@eso.org Postal address: European Southern Observatory Data Management Division Karl-Schwarzschild-Strasse 2 D 85748 Garching bei Muenchen GERMANY ===========================================================================*/ /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ .COPYRIGHT (c) 1993 European Southern Observatory .IDENT txtfile.c .LAUGUAGE C .AUTHOR P.Grosbol ESO/IPG .KEYWORDS ASCII text, files .COMMENT Create and write to ASCII text files .VERSION 1.0 1991-Mar-15 : Creation, PJG .VERSION 1.1 1993-Oct-26 : Update to new SC/TC/OS + prototypes, PJG .VERSION 1.2 1997-Jan-08 : Check/count non-ASCII characters, PJG ---------------------------------------------------------------------*/ #include #include #define MXBUF 512 /* max char's in line buffer */ static char *buf; /* pointer to character buffer */ static int tfd = -1; /* text-file descriptor no. */ static int n = 0; /* no. char. in buffer */ static int sc = 0; /* special character */ text_open(name,mode) /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ .PURPOSE initiate ASCII text file .RETURN status, 0:created OK, 1:error ---------------------------------------------------------------------*/ char *name; /* IN: name of text-file to create */ int mode; /* IN: open mode of file */ { if (0<=tfd) return 1; buf = (char *)osmmget(MXBUF); /* allocate buffer */ if (!buf) return 1; *buf = '\0'; tfd = osaopen(name,mode); /* open text file */ if (tfd<0) return 1; return 0; } text_put(line) /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ .PURPOSE put text into ASCII text file .RETURN status, 0:OK, 1:error ---------------------------------------------------------------------*/ char *line; /* IN: text-line to be added */ { int nc, err; char *pc, c; err = 0; if (tfd<0) return 1; pc = &buf[n]; while ((c = *line++) && n