/* * 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. */ #include "pg_config.h" IDENT("@(#) Delimiters.cc (Gunther Schadow) 12/19/96"); #pragma implementation #include "Delimiters.h" #include #include "logfile.h" #include "exception.h" #include "xios.h" Delimiters::Delimiters() : PGObject(PGObject::delimiters, 0) { _seg=seg_def; _fld=fld_def; _rep=rep_def; _cmp=cmp_def; _scm=scm_def; _esc=esc_def; __eos=0; } Delimiters::Delimiters(char fld, char rep, char cmp, char scm, char esc) : PGObject(PGObject::delimiters, 0) { _seg=seg_def; _fld=fld; _rep=rep; _cmp=cmp; _scm=scm; _esc=esc; __eos=0; } void Delimiters::reset() { _fld=fld_def; _rep=rep_def; _cmp=cmp_def; _scm=scm_def; _esc=esc_def; } result Delimiters::input(istream& is) { if(ishl7er(is)) { is >> _fld >> _cmp >> _rep >> _esc >> _scm ; } else if(isastmer(is)) { is >> _fld >> _rep >> _cmp >> _esc ; } return SUCCESS; } /* * Make control characters readable */ static ostream& rdbl(ostream& os, char c) { if(iscntrl(c)) os << hex << "0x" << (int)c; else os << DSBQUO << c << DSEQUO; return os; } void Delimiters::output(ostream& os) const { if(ishl7er(os)) { os << _fld << _cmp << _rep << _esc << _scm ; } else if(isastmer(os)) { os << _fld << _rep << _cmp << _esc ; } else if (isdebug(os)) { os << DSBGR0 "Delimiters" DSBGR1 DSFRST DSBGR0 "segment" DSBGR1; rdbl(os,_seg) << DSEGRP DSSEPR DSBGR0 "field" DSBGR1; rdbl(os,_fld) << DSEGRP DSSEPR DSBGR0 "repeat" DSBGR1; rdbl(os,_rep) << DSEGRP DSSEPR DSBGR0 "component" DSBGR1; rdbl(os,_cmp) << DSEGRP DSSEPR DSBGR0 "sub-component" DSBGR1; rdbl(os,_scm) << DSEGRP DSSEPR DSBGR0 "escape" DSBGR1; rdbl(os,_esc) << DSEGRP DSEGRP; } } /* * Unfortunately this function is way outdated. The level mechanism * is not as generally applicable as it was originally intended. * * ARGUMENT 2 RETURN VALUE STRING * -------------------- ------------------------------- ----------- * esclevel all delimiters including ESC "\&^~|" * botlevel(*) " " " " "\&^~|" * (not supplied) all delimiters except ESC "&^~|" * lowlevel(*) " " " " "&^~|" * scmlevel " " " " "&^~|" * cmplevel depending on stream level: 0 "^~|" * " " " " " : -1 "&^~|" * replevel starting from REP "~|" * fldlevel starting from FLD "|" * seglevel starting from SEG "" * msglevel(*) empty string "" * toplevel(*) empty string "" * * NOTE: (*) do not use this! * * This is certainly not very intelligent, and has to be cleaned up * sometimes! FIXME! */ const char *Delimiters::getdel(level_t level, level_t offset) const { switch(offset) { case botlevel: // == case esclevel: return &_esc; case lowlevel: // == case scmlevel: return &_scm; case cmplevel: if(level == -2) FATAL("level %d out of range", offset); else return ( level == 0 ? &_cmp : &_scm ); case replevel: return &_rep; case fldlevel: return &_fld; case seglevel: return &_seg; case msglevel: // == case toplevel: return &__eos; default: FATAL("level %d out of range", offset); /* no, FATAL does not return! */ } } Delimiters::level_t Delimiters::levelof(char d) const { int i; const char *p; for(i = Delimiters::toplevel, p = &__eos; i >= Delimiters::botlevel; i--, p--) { if(*p==d) return (level_t)i; } return Delimiters::invalid; }