/*=========================================================================== Copyright (C) 1995-2010 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 ===========================================================================*/ /*+++++++++++++++++++++ Module MIDKEYA +++++++++++++++++++++++++++++++++++++++ .LANGUAGE C .IDENTIFICATION Module MIDKEYA .AUTHOR Klaus Banse ESO - Garching .KEYWORDS Midas keyword utility routines. .ENVIRONMENT VMS and UNIX .COMMENT holds IPROMPT, RPROMPT, CPROMPT, DPROMPT KEYFILE .VERSION [3.00] 920129: split off original midkey.c 100616 last modif ------------------------------------------------------------------------*/ #include #include #include #include /* */ int MID_CPROMPT(p_string,noval,carray,nullo) /*++++++++++++++++++++++++++++++++++++++++++++++++++ .PURPOSE display a prompt string on the terminal + read the user input .ALGORITHM use MID_TPRO to display prompt string + get user input as character string convert this string to relevant data via CGN_CNVT .RETURNS status: I*4 return status --------------------------------------------------*/ char *p_string /* IN : prompt string (null terminated) */; int *noval /* IO : length of expected input */; char *carray /* OUT: input data for type = 3 */; int *nullo /* OUT: no. of null values in input */; { int save_val, count; register int nr; char work[96], prombuf[96]; save_val = *noval; /* save noval */ *noval = 0; /* init to 0 ... */ /* store prompt string in logfile */ (void) MID_LOG('G',p_string,(int)strlen(p_string)); /* cut off trailing blanks of prompt + read a line from the terminal */ CGN_CUTOFF(p_string,prombuf); MID_TPRO(prombuf,work,80); count = (int) strlen(work); /* test, if something came in */ if (count <= 0) return ERR_NODATA; /* do not pass more values than required */ (void) MID_LOG('G',work,count); if (save_val <= count) count = save_val; else memset((void *)carray,32,(size_t)save_val); /* fill first with blanks */ *noval = count; *nullo = 0; for (nr=0; nr= 0) { if ( (type[0] != k_type[0]) || (bytelem != sbytelem) ) { printf("wrong keytype - line %d skipped...\n",nc); goto read_loop; } } else { slen = noelem + first - 1; m = MID_DEFKEY(keyname,' ',type,slen,&unit); if (stat != ERR_NORMAL) { printf("problem creating keyword - line %d skipped...\n",nc); goto read_loop; } } if (type[0] == 'I') nb = 1; else if (type[0] == 'R') nb = 2; else if (type[0] == 'C') nb = 3; else nb = 4; CGN_strcpy(buff,&buff[cl+1]); slen = (int) strlen(buff); for (nr=0; nr 0) CGN_strcpy(buff,&buff[nr]); /* printf("data: %s\nnb = %d, first = %d, noelem = %d\n",buff,nb,first,noelem); */ if (nb != 3) { m = CGN_CNVT(buff,nb,noelem,ibuf,rbuf,dbuf); if (m > noelem) m = noelem; if (nb == 1) stat = SCKWRI(keyname,ibuf,first,m,&unit); else if (nb == 2) stat = SCKWRR(keyname,rbuf,first,m,&unit); else stat = SCKWRD(keyname,dbuf,first,m,&unit); } else { m = noelem * bytelem; /* total size */ if (m > 200) { printf("data overflow (> 200) - line %d skipped...\n",nc); goto read_loop; } slen = (int) strlen(buff) - 1; if ( (buff[0] == '"') && (slen > 1) && (buff[slen] == '"') ) { cbuf = &buff[1]; buff[slen--] = '\0'; } else { cbuf = &buff[0]; slen++; } if (slen < m) { for (nr=slen; nr