/* * Copyright (c) 1995, 1996 Gunther Schadow. All rights reserved. * * 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 Mass Ave, Cambridge, MA 02139, USA. */ /* * Translate operator ID strings to names etc. * * The operator data is fetched indirectly from the carevue system * via a shell script which in turn issues a remore shell job to * CareVue's idb. */ #pragma implementation "operinfo.h" #include "operinfo.h" #include #ifdef USE_PROCBUF # include #else # include # include #endif #include #include #include #include #define OPER_BY_NUM PGETC "/OperByNum" operinfo::operinfo(const char *s) { *this = operinfo( s==NULL || *s=='\0' ? -1 : atoi(s) ); } operinfo::operinfo(int opid) { operator_id = opid; int nostrings = ( (void **)&given_name - (void **)&family_name ) + 1; char **strings = &family_name; for(int i = 0; i < nostrings; i++) strings[i] = NULL; line = NULL; if(operator_id == -1) { LOGINFO("OPID: not present"); return; } else LOGINFO("OPID: %d", operator_id); /* construct the call "OperByNum " */ char *cmd = (char *)alloca(sizeof(OPER_BY_NUM " ") + 20 + 1); sprintf(cmd, OPER_BY_NUM " %d", operator_id); /* create the pipe now */ #ifdef USE_PROCBUF procbuf pipe(cmd, ios::in); istream is(&pipe); if(is.ipfx(1)) is.gets(&line); if(!is) ERROS("error on pipe: `%s'", cmd); else ERROS("can't open pipe: `%s'", cmd); #else { char buf[1024]; FILE* pipe = popen(cmd, "r"); if(pipe == NULL) ERROS("popen `%s'", cmd); int len = read(fileno(pipe), buf, 1024); if(len == -1) ERROS("error on pipe: `%s'", cmd); else if(len == 0) line = NULL; else { line = new char[len + 1]; strncpy(line,buf,len); line[len] = '\0'; } pclose(pipe); } #endif if(line == NULL) { LOGWARNING("unable to resolve operator_id %d", operator_id); return; } /* analyze the input */ char *p = line; for(int i = 0; i < nostrings; i++) { char del; if( *p == '"') { del = '"'; p++; } else del = '\t'; strings[i] = p; while(*p != del) p++; *p++ = '\0'; if(del == '\t' && strcmp(strings[i], "NULL") == 0) strings[i] = NULL; if(del == '"' && *p == '\t') p++; if(*p == '\n') break; } } operinfo::~operinfo() { if(line!=NULL) delete [] line; }