/* * 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("@(#) Timebase.cc (Gunther Schadow) 12/19/96"); #pragma implementation #include "Timebase.h" #include #include "misc.h" #include "xios.h" #include "ioext.h" #include "logfile.h" #include "exception.h" #include #include #include "ParseTrace.h" void Timebase::set(int &n, int val, int min, int max) { check_range(val, min, max); n = val; Primtype::set(); } result Timebase::input_number(int &n, istream &is, int m, int min, int max) { int val = 0; char d; if(strchr(getdel(is),is.peek())) // fails if we are at the end of the field return FAIL; for(; m > 0; m--) { if(isdigit(d = is.peek())) { is.get(); val = val * 10 + (d - '0'); } else TIMEBASE_SYNTAX_ERROR(is); } set(n, val, min, max); return SUCCESS; } /* Check for not present or null */ bool Timebase::no_value(istream& is) { u_int i; bool touched = FALSE; char c = is.peek(); if(strchr(getdel(is),c)) { unset(); return TRUE; } for(i=0; i < ( sizeof(NULLVAL) - 1 ); i++) { if ((c = is.peek()) == NULLVAL[i]) { is.get(); touched = TRUE; } else { if(!touched) return FALSE; else TIMEBASE_SYNTAX_ERROR(is); } } nullify(); return TRUE; } void Timebase::check_range(int& n, int min, int max) { if( (n < min) || (max < n) ) { record_parse_error("range error at %d [%d .. %d]", n, min, max); EPARSE("range error at %d [%d .. %d]", n, min, max); } }