| 1 |
/*=========================================================================== |
| 2 |
Copyright (C) 1995-2007 European Southern Observatory (ESO) |
| 3 |
|
| 4 |
This program is free software; you can redistribute it and/or |
| 5 |
modify it under the terms of the GNU General Public License as |
| 6 |
published by the Free Software Foundation; either version 2 of |
| 7 |
the License, or (at your option) any later version. |
| 8 |
|
| 9 |
This program is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public |
| 15 |
License along with this program; if not, write to the Free |
| 16 |
Software Foundation, Inc., 675 Massachusetts Ave, Cambridge, |
| 17 |
MA 02139, USA. |
| 18 |
|
| 19 |
Correspondence concerning ESO-MIDAS should be addressed as follows: |
| 20 |
Internet e-mail: [email protected] |
| 21 |
Postal address: European Southern Observatory |
| 22 |
Data Management Division |
| 23 |
Karl-Schwarzschild-Strasse 2 |
| 24 |
D 85748 Garching bei Muenchen |
| 25 |
GERMANY |
| 26 |
===========================================================================*/ |
| 27 |
|
| 28 |
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 29 |
.LANGUAGE C |
| 30 |
|
| 31 |
.COPYRIGHT (C) 1998,2004 European Southern Observatory |
| 32 |
.IDENT MIDAS Monitor module pipe_message() |
| 33 |
.KEYWORDS Put a formatted string to stdout and MIDAS log |
| 34 |
.OUTPUT terminal and MIDAS-log output |
| 35 |
.RETURN -1: the message identifier is wrong |
| 36 |
0: no error occured |
| 37 |
.PURPOSE Put a formatted string to stdout. The message identifier |
| 38 |
controls the format of the messagetext: |
| 39 |
|
| 40 |
id | format | BELL |
| 41 |
----+--------------------------+----- |
| 42 |
1 | ERROR [prgname]: text | ON |
| 43 |
2 | WARNING [prgname]: text | OFF |
| 44 |
3 | INFO [prgname]: text | OFF |
| 45 |
4 | INFO [prgname]: text | OFF |
| 46 |
|
| 47 |
In case the identifier is the negative compliment then |
| 48 |
NO \n will be appended to the text. |
| 49 |
Following printf() may continue at that point. |
| 50 |
.ALGORITHM The string passed through messagetext will be formatted and |
| 51 |
send to stdout (printf()). Furthermore this messagetext will |
| 52 |
be logged in the standard MIDAS log. |
| 53 |
The format of the messagetext depends on the message |
| 54 |
identifier id. |
| 55 |
.ENVIRON MIDAS |
| 56 |
.LANGUAGE C |
| 57 |
.AUTHOR original pipe_message(): Sebastian Wolf, ESO-DMO |
| 58 |
.COMMENT The message may contain special characters to format your |
| 59 |
text: \n, \r, \t |
| 60 |
|
| 61 |
.VERSION 1.0 1998.01.05 created. |
| 62 |
moved into the Midas library (with bleeding heart...) KB |
| 63 |
070525 last modif KB |
| 64 |
|
| 65 |
-----------------------------------------------------------------------------*/ |
| 66 |
|
| 67 |
#include <fileexts.h> |
| 68 |
#include <proto_st.h> |
| 69 |
|
| 70 |
#include <stdlib.h> |
| 71 |
#include <stdio.h> |
| 72 |
#include <string.h> |
| 73 |
|
| 74 |
|
| 75 |
#define BELL 0x7 |
| 76 |
#define MXID 5 |
| 77 |
#define MXLN 12 |
| 78 |
#define MAX_TBUF 120 |
| 79 |
#define MAX_TEXT MAX_TBUF + 4 |
| 80 |
#define MAXPLEN 16 |
| 81 |
#define MAXP MAXPLEN + 3 |
| 82 |
#define OFFSET MAXPLEN + MXLN |
| 83 |
|
| 84 |
|
| 85 |
int indent = 0; |
| 86 |
|
| 87 |
char *Mtyp[MXID] = |
| 88 |
{" ","ERROR ","WARNING ","INFO ","INFO "}; |
| 89 |
|
| 90 |
/* |
| 91 |
|
| 92 |
*/ |
| 93 |
|
| 94 |
int check_special(inbuf,outbuf) |
| 95 |
char *inbuf, *outbuf; |
| 96 |
|
| 97 |
{ |
| 98 |
int i, j, n, jj; |
| 99 |
|
| 100 |
char mybuf[MAX_TEXT]; |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
n = (int) strlen(inbuf); |
| 105 |
if (n > MAX_TBUF) |
| 106 |
{ |
| 107 |
SCTPUT("MID_message: strlen(message-text) > 120, message truncated!"); |
| 108 |
(void) strncpy(mybuf,inbuf,MAX_TBUF); |
| 109 |
mybuf[MAX_TBUF] = '\0'; |
| 110 |
inbuf = mybuf, |
| 111 |
n = MAX_TBUF; |
| 112 |
} |
| 113 |
|
| 114 |
i = 0; |
| 115 |
j = 0; |
| 116 |
while(j < n) |
| 117 |
{ |
| 118 |
outbuf[i] = inbuf[j]; |
| 119 |
if (inbuf[j] == '\\') |
| 120 |
{ |
| 121 |
jj = j + 1; |
| 122 |
if (inbuf[jj] == 't') |
| 123 |
{ |
| 124 |
outbuf[i] = '\t'; |
| 125 |
j ++; |
| 126 |
} |
| 127 |
else if (inbuf[jj] == 'n') |
| 128 |
{ |
| 129 |
outbuf[i++] = '\n'; |
| 130 |
outbuf[i] = '\0'; |
| 131 |
return (jj); |
| 132 |
} |
| 133 |
else if (inbuf[jj] == 'r') |
| 134 |
{ |
| 135 |
outbuf[i++] = '\r'; |
| 136 |
outbuf[i] = '\0'; |
| 137 |
return (jj); |
| 138 |
} |
| 139 |
} |
| 140 |
i++, j++; |
| 141 |
} |
| 142 |
|
| 143 |
outbuf[i] = '\0'; |
| 144 |
return (0); |
| 145 |
} |
| 146 |
/* |
| 147 |
|
| 148 |
*/ |
| 149 |
|
| 150 |
/* +++ new_message +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 151 |
|
| 152 |
.IDENT new_message() |
| 153 |
.KEYWORDS Put a formatted string to stdout and MIDAS-log |
| 154 |
.USAGE message(messlevel, id, prgname, messagetext) |
| 155 |
.INPUT id (int) message identifier |
| 156 |
( 1: ERROR, 2: WARNING, 3,4: INFO) |
| 157 |
negative id has the same meaning except that |
| 158 |
NO \n will be append at the end of the |
| 159 |
message text! |
| 160 |
*prgname (char) name of the calling program |
| 161 |
*messagetext (char) message text |
| 162 |
.OUTPUT terminal and MIDAS-log output |
| 163 |
.RETURN -1: the message identifier is wrong |
| 164 |
0: no error occured |
| 165 |
.PURPOSE Put a formatted string to stdout. The message identifier |
| 166 |
controls the format of the messagetext: |
| 167 |
|
| 168 |
id | format | BELL |
| 169 |
----+--------------------------+----- |
| 170 |
1 | ERROR [prgname]: text | ON |
| 171 |
2 | WARNING [prgname]: text | OFF |
| 172 |
3 | INFO [prgname]: text | OFF |
| 173 |
4 | INFO [prgname]: text | OFF |
| 174 |
|
| 175 |
.ALGORITHM The string passed through messagetext will be formatted and |
| 176 |
send to stdout (printf()). Furthermore this messagetext will |
| 177 |
be logged in the standard MIDAS log. |
| 178 |
The format of the messagetext depends on the message |
| 179 |
identifier id. |
| 180 |
.COMMENT The message may contain special characters to format your |
| 181 |
text: \n, \r, \t, \b |
| 182 |
---------------------------------------------------------------------------- */ |
| 183 |
|
| 184 |
|
| 185 |
static int new_message(id, pnam, line) |
| 186 |
int id; |
| 187 |
char *pnam, *line; |
| 188 |
|
| 189 |
{ |
| 190 |
char bell, *myptr; |
| 191 |
char txt[MAX_TEXT+MAXPLEN+20], mes[MAX_TEXT]; |
| 192 |
|
| 193 |
int n, k, mm, plen; |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
plen = (int)strlen(pnam); |
| 200 |
if (plen>MAXPLEN) |
| 201 |
{ |
| 202 |
pnam[MAXPLEN] = '\0'; /* cut program name if too long */ |
| 203 |
plen = MAXPLEN; |
| 204 |
} |
| 205 |
k = plen + 9; |
| 206 |
|
| 207 |
myptr = line; /* point to begin of message buffer */ |
| 208 |
mm = check_special(myptr,mes); /* look for \t, \n, \r */ |
| 209 |
|
| 210 |
if (id == 1) /* for errors we beep! */ |
| 211 |
{ |
| 212 |
bell = BELL; |
| 213 |
n = snprintf(txt,MAX_TEXT+MAXPLEN+20, |
| 214 |
"%-8s[%-19s%s%c",Mtyp[id],pnam,mes,bell); |
| 215 |
} |
| 216 |
else |
| 217 |
n = snprintf(txt,MAX_TEXT+MAXPLEN+20, |
| 218 |
"%-8s[%-19s%s",Mtyp[id],pnam,mes); |
| 219 |
|
| 220 |
txt[k++] = ']'; |
| 221 |
txt[k] = ':'; |
| 222 |
(void) printf("%s",txt); |
| 223 |
|
| 224 |
if (mm > 0) |
| 225 |
{ |
| 226 |
txt[--n] = '\0'; /* remove special chars */ |
| 227 |
MID_LOG('G',txt,n); |
| 228 |
} |
| 229 |
else |
| 230 |
{ |
| 231 |
MID_LOG('G',txt,n); |
| 232 |
printf("\n"); |
| 233 |
return (0); |
| 234 |
} |
| 235 |
|
| 236 |
|
| 237 |
replace_loop: |
| 238 |
myptr += (mm+1); |
| 239 |
if (*myptr != '\0') |
| 240 |
{ |
| 241 |
mm = check_special(myptr,mes); |
| 242 |
memset((void *)txt,32,(size_t)(OFFSET+indent)); |
| 243 |
(void) strcpy(&txt[OFFSET+indent],mes); |
| 244 |
(void) printf("%s",txt); |
| 245 |
n = (int) strlen(txt); |
| 246 |
if (mm > 0) |
| 247 |
{ |
| 248 |
txt[--n] = '\0'; /* remove special chars */ |
| 249 |
MID_LOG('G',txt,n); |
| 250 |
goto replace_loop; |
| 251 |
} |
| 252 |
|
| 253 |
MID_LOG('G',txt,n); |
| 254 |
printf("\n"); |
| 255 |
} |
| 256 |
|
| 257 |
return(0); |
| 258 |
} |
| 259 |
/* |
| 260 |
|
| 261 |
*/ |
| 262 |
|
| 263 |
/* +++++++++++++++++++++++++++++++++++++++++++++++++ |
| 264 |
|
| 265 |
wrapper for new_message() to handle the "extern int indent" |
| 266 |
|
| 267 |
+++++++++++++++++++++++++++++++++++++++++++++++++ */ |
| 268 |
|
| 269 |
int MID_message(id,nam,buf,indnt) |
| 270 |
int id, indnt; |
| 271 |
char *nam, *buf; |
| 272 |
|
| 273 |
{ |
| 274 |
indent = indnt; /* needed to get same behaviour |
| 275 |
as before with extenal `indent' */ |
| 276 |
return (new_message(id,nam,buf)); |
| 277 |
} |
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
/* ----------------------------------- */ |
| 284 |
/* interface for old pipeline programs */ |
| 285 |
/* ----------------------------------- */ |
| 286 |
|
| 287 |
int messout(messlevel,id,nam,buf) |
| 288 |
int id, messlevel; |
| 289 |
char *nam, *buf; |
| 290 |
|
| 291 |
{ |
| 292 |
id = abs(id); |
| 293 |
if (id > messlevel) |
| 294 |
return(-1); |
| 295 |
else |
| 296 |
return (new_message(id,nam,buf)); |
| 297 |
} |
| 298 |
|