[go: up one dir, main page]

File: simfilex.C

package info (click to toggle)
sabre 0.2.3-3
  • links: PTS
  • area: main
  • in suites: slink
  • size: 4,876 kB
  • ctags: 5,106
  • sloc: cpp: 25,581; ansic: 7,439; sh: 2,063; makefile: 92
file content (113 lines) | stat: -rw-r--r-- 2,447 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
    SABRE Fighter Plane Simulator 
    Copyright (c) 1997 Dan Hammer
    Portions Donated By Antti Barck

    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 1, 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "simfile.h"
#include "simfilex.h"

int simfileX::readint(istream &is, char tok0, char tok1)
{
  int result;
  char c;
  if (tok0)
    {
      READ_TOKI(tok0,is,c)
    }
  is >> result;
  if (tok1)
    {
      READ_TOK(tok1,is,c)
    }
  return (result);
}

int simfileX::readstr(istream &is, char *buff, int maxlen, char tok0, char tok1)
{
  char c,c0;
  int l = 0;
  char lbuff[BUFSIZ];

  if (tok0)
    {
      READ_TOKI(tok0,is,c);
    }
  is >> lbuff;
  if (strlen(lbuff) > (unsigned) (maxlen - 1))
    lbuff[maxlen-1] = 0;
  strcpy(buff,lbuff);
  if (tok1)
    {
      if (c0 != tok1)
	{
	  READ_TOK(tok1,is,c0)
	}
    }
  l = strlen(buff);
  return (l);
}

int simfileX::isstringinput(char *buff)
{
  char c;
  while ((c = *buff++) != '\0')
    if (!isdigit(c))
      return(1);
  return (0);
}

int simfileX::readinput(istream &is, char *buff, int maxlen, int &i, 
	      char tok0 = 0,
	      char tok1 = 0)
{
  int result = INT_INPUT;
  readstr(is,buff,maxlen,tok0,tok1);
  if (isstringinput(buff))
    result = STR_INPUT;
  else
    i = atoi(buff);
  return (result);
}

int simfileX::readdictinput(istream &is, char *buff, int maxlen, int &val,
			dict *d, int d_cnt,
			char tok0 = 0,
			char tok1 = 0)
{
  if (readinput(is,buff,maxlen,val,tok0,tok1) == INT_INPUT)
    return(INT_INPUT);
  else 
    return(dictfind(buff,d,d_cnt,val));
}

int simfileX::dictfind(char *buff, dict *d, int d_cnt, int &val)
{
  for (int i=0;i<d_cnt;i++)
    if (!strcmp(buff,d[i].str))
      {
	val = d[i].val;
	return(DICT_STR);
      }
  return (DICT_STR_NF);
}