/* @(#)midmessage.c 17.1.1.1 (ESO-DMD) 01/25/02 17:36:29 */ /*=========================================================================== 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 .INPUT ID (int) message identifier ( 1: ERROR, 2: WARNING, 3,4: INFO) negative id has the same meaning except that NO \n will be append at the end of the message text! PNAM (char) name of the calling program PLEN (int) length of PNAM CBUF (char) message text CLEN (int) length of CBUF .OUTPUT terminal and MIDAS-log output .RETURN -1: the message identifier is wrong 0: no error occured .PURPOSE Put a formatted string to stdout. The message identifier controls the format of the messagetext: id | format | BELL ----+--------------------------+----- 1 | ERROR [prgname]: text | ON 2 | WARNING [prgname]: text | OFF 3 | INFO [prgname]: text | OFF 4 | INFO [prgname]: text | OFF In case the identifier is the negative compliment then NO \n will be appended to the text. Following printf() may continue at that point. .ALGORITHM The string passed through messagetext will be formatted and send to stdout (printf()). Furthermore this messagetext will be logged in the standard MIDAS log. The format of the messagetext depends on the message identifier id. .ENVIRON MIDAS .LANGUAGE C .AUTHOR Sebastian Wolf, ESO-DMO .VERSION 1.0 1998.01.05 created. moved into the Midas library (with bleeding heart...) KB 020122 last modif KB .COMMENT The message may contain special characters to format your text: \n, \r, \t, \b -----------------------------------------------------------------------------*/ #include #include #define BELL 0x7 #define MXID 5 #define MXLN 12 #define MAX_TBUF 1000 #define MAXPLEN 16 #define MAXP MAXPLEN + 3 #define OFFSET MAXPLEN + 3 + 1 + MXLN int indent = 0; int tmapped = 0; char *txt, *mes; char Mtyp[MXID][MXLN] = {"","ERROR ","WARNING ","INFO ","INFO "}; /* */ /* +++++++++++++++++++++++++++++++++++++++++++++++++ wrapper for message() to handle the "extern int indent" +++++++++++++++++++++++++++++++++++++++++++++++++ */ int MID_message(id,nam,buf,indnt) int id, indnt; char *nam, *buf; { indent = indnt; /* needed to get same behaviour as before with extenal `indent' */ return (message(id,nam,buf)); } /*+++ message +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ .IDENT message() .KEYWORDS Put a formatted string to stdout and MIDAS-log .USAGE message(messlevel, id, prgname, messagetext) .INPUT id (int) message identifier ( 1: ERROR, 2: WARNING, 3,4: INFO) negative id has the same meaning except that NO \n will be append at the end of the message text! *prgname (char) name of the calling program *messagetext (char) message text .OUTPUT terminal and MIDAS-log output .RETURN -1: the message identifier is wrong 0: no error occured .PURPOSE Put a formatted string to stdout. The message identifier controls the format of the messagetext: id | format | BELL ----+--------------------------+----- 1 | ERROR [prgname]: text | ON 2 | WARNING [prgname]: text | OFF 3 | INFO [prgname]: text | OFF 4 | INFO [prgname]: text | OFF In case the identifier is the negative compliment then NO \n will be appended to the text. Following printf() may continue at that point. .ALGORITHM The string passed through messagetext will be formatted and send to stdout (printf()). Furthermore this messagetext will be logged in the standard MIDAS log. The format of the messagetext depends on the message identifier id. .COMMENT The message may contain special characters to format your text: \n, \r, \t, \b -----------------------------------------------------------------------------*/ int message(id, pnam, line) int id; char *pnam, *line; { char bell, CR; int mm, plen; if (tmapped == 0) /* allocate once */ { txt = (char*) malloc( (size_t)MAX_TBUF); if (txt == (char *) NULL) { SCTPUT("message: could not allocate memory for message buffer..."); return (-1); } mes = (char*) malloc( (size_t)MAX_TBUF); if (mes == (char *) NULL) { free(txt); SCTPUT("message: could not allocate memory for message buffers..."); return (-1); } tmapped = 1; } check_special(line,mes); if (id < 0) { id = -id; CR = '\0'; } else CR = '\n'; if (id == 1) bell = BELL; else bell = '\0'; plen = (int)strlen(pnam); if (plen>MAXPLEN) { pnam[MAXPLEN] = '\0'; /* cut program name if too long */ plen = MAXPLEN; } (void) sprintf(txt,"%-8s[%-19s%s%c",&Mtyp[id],pnam,mes,bell); txt[plen+9] = ']'; txt[plen+10] = ':'; (void) printf("%s%c",txt,CR); mm = (int) strlen(txt); MID_LOG('G',txt,mm); return(0); } int check_special(cbuf,ccbuf) char *cbuf, *ccbuf; { int i, j, num, numc, ioff; int newlin_set; char *chb; num = (int) strlen(cbuf); i = 0; for (j=0;j messlevel) return(-1); else return (message(id,nam,buf)); }