/* @(#)pipe_message.c 17.1.1.1 (ESO-DMD) 01/25/02 17:37:45 */ /*=========================================================================== 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 Massachusetts Ave, Cambridge, MA 02139, USA. Correspondence 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 ===========================================================================*/ /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ .LANGUAGE C .COPYRIGHT (C) 1998 European Southern Observatory .IDENT MIDAS Monitor module pipe_message() .KEYWORDS Put a formatted string to stdout and MIDAS log .RETURN -1: the message identifier is wrong 0: no error occured .PURPOSE implement the pipeline commands MESS/OUT and APPEND/OUT .ALGORITM Put a formatted string to stdout using MID_message which in turn calls the message() function developed by S. Wolf for the FORS pipeline .VERSION 020122 last modif KB -----------------------------------------------------------------------------*/ #include #include #define MAX_CBUF 8000 /* */ void pipe_mess(actio) char actio; { char pnam[8], ktyp[20]; static char *bigbuf; int id, mess_level; int indent, null, unit; int bytelem, noelem, iav, kentry; long int modtim; static int cmapped = 0, clen = 0; float rbuf; double dbuf; if (cmapped == 0) /* allocate once */ { bigbuf = (char*) malloc( (size_t)MAX_CBUF); if (bigbuf == (char *) NULL) { (void) SCTPUT("could not allocat memory for MESS_CBUF.."); return; } cmapped = 1; clen = 0; } /* if actio = A, we do APPEND/MESS */ if (actio == 'A') { pnam[0] = TOKEN[2].STR[0]; /* get CLRF */ iav = TOKEN[1].LEN; /* process message */ if ((TOKEN[1].STR[0] == '"') && (TOKEN[1].STR[iav-1] == '"')) { iav -= 2; (void) memcpy(TOKEN[1].STR,&TOKEN[1].STR[1],(size_t) iav); TOKEN[1].STR[iav] = '\0'; } if ((pnam[0] == 'Y') || (pnam[0] == 'y')) { TOKEN[1].STR[iav++] = '\n'; TOKEN[1].STR[iav] = '\0'; } if ((clen + iav) >= MAX_CBUF) { (void) SCTPUT("overflow of pipeline message buffer..."); return; } (void) memcpy(bigbuf+clen,TOKEN[1].STR,(size_t)iav); clen += iav; bigbuf[clen] = '\0'; return; } /* here for MESSAGE/OUT ... */ id = 0; (void) CGN_CNVT(TOKEN[1].STR,1,1,&id,&rbuf,&dbuf); if (id == 0) return; (void) SCKRDI("MESS_LEVEL",1,1,&iav,&mess_level,&unit,&null); if (id < 0) id = -id; if (id > mess_level) goto end_of_it; /* clear message buffer */ indent = 0; if (TOKEN[4].STR[0] != '?') (void) CGN_CNVT(TOKEN[4].STR,1,1,&indent,&rbuf,&dbuf); iav = TOKEN[3].LEN; /* process message */ if ((TOKEN[3].STR[0] != '?') && (TOKEN[3].STR[0] != '+')) { if ((TOKEN[3].STR[0] == '"') && (TOKEN[3].STR[iav-1] == '"')) { iav -= 2; (void) memcpy(bigbuf,&TOKEN[3].STR[1],(size_t)iav); } else (void) memcpy(bigbuf,TOKEN[3].STR, (size_t)iav); clen = iav; bigbuf[clen] = '\0'; } /* process + display the message */ iav = MID_message(id,TOKEN[2].STR,bigbuf,indent); if (iav < 0) printf("`message' returned %d\n",iav); end_of_it: clen = 0; /* clear buffer again */ bigbuf[0] = '\0'; }