Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1663 pj 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
8
 * Authors     :
9
 *   Paolo Gai           <pj@gandalf.sssup.it>
10
 *   (see the web pages for full authors list)
11
 *
12
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
13
 *
14
 * http://www.sssup.it
15
 * http://retis.sssup.it
16
 * http://shark.sssup.it
17
 */
18
 
19
/**
20
 ------------
21
 CVS :        $Id: dosfs.c,v 1.1 2004-07-05 14:17:13 pj Exp $
22
 
23
 File:        $File$
24
 Revision:    $Revision: 1.1 $
25
 Last update: $Date: 2004-07-05 14:17:13 $
26
 ------------
27
**/
28
 
29
/*
30
 * Copyright (C) 2001 Paolo Gai
31
 *
32
 * This program is free software; you can redistribute it and/or modify
33
 * it under the terms of the GNU General Public License as published by
34
 * the Free Software Foundation; either version 2 of the License, or
35
 * (at your option) any later version.
36
 *
37
 * This program is distributed in the hope that it will be useful,
38
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
39
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
40
 * GNU General Public License for more details.
41
 *
42
 * You should have received a copy of the GNU General Public License
43
 * along with this program; if not, write to the Free Software
44
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
45
 *
46
 */
47
 
48
#include <kernel/kern.h>
49
#include <ll/i386/x-dos.h>
50
#include <ctype.h>
51
#include "crunch.h"
52
 
53
 
54
#define FILEBUF_DIM 1000000
55
 
56
/*
57
 *
58
 * Read functions
59
 *
60
 */
61
 
62
/* This is the buffer used by read_myfile */
63
char myfilebuf[FILEBUF_DIM];
64
 
65
/* This is the number of bytes read by read_myfile */
66
int myfilebuf_length;
67
 
68
/* This function read myfile.txt (up to 1000 chars) */
69
void read_myfile(char *name)
70
{
71
  /* DOS file descriptor */
72
  DOS_FILE *f;
73
 
74
  /* Error code */
75
  int err;
76
 
77
  /* open the DOS file for reading  (you can specify only "r" or "w") */
78
  f = DOS_fopen(name,"r");
79
 
80
  /* check for open errors */
81
  if (!f) {
82
    /* error!! */
83
    err = DOS_error();
84
 
85
    /* note that if you call DOS_error() here, it return 0!!! */
86
    cprintf("Error %d opening %s...\n", err, name);
87
    myfilebuf_length = 0;
88
    return;
89
  }
90
 
91
  /* read up to 1000 chars */
92
  myfilebuf_length = DOS_fread(&myfilebuf,1,FILEBUF_DIM,f);
93
 
94
  /* check for errors */
95
  err = DOS_error();
96
 
97
  cprintf("Read %d bytes from %s...\n", myfilebuf_length, name);
98
 
99
  if (err) {
100
    cprintf("Error %d reading %s...\n", err, name);
101
    myfilebuf_length = 0;
102
   /* there is not return because I want to close the file! */
103
  }
104
 
105
  /* Close the file */
106
  DOS_fclose(f);
107
}
108
 
109
/*
110
 *
111
 * Parsing functions
112
 *
113
 */
114
 
115
 
116
int geti(char *b, int *pos, int maxpos);
117
 
118
/*
119
 * This function crunches the buffer that contains the configuration file.
120
 * m is the maximum size of the t array...
121
 */
122
void crunch_file(struct task_struct *t, int *curr_table_dim, int m)
123
{
124
  int curr_filepos = 0;
125
  int max_task_pos;
126
  int i = 0;
127
 
128
  // read the number of tasks into the data file
129
  max_task_pos = geti(myfilebuf, &curr_filepos, myfilebuf_length);
130
  if (max_task_pos == -1) {
131
    cprintf("Error parsing configuration file...\n");
132
    *curr_table_dim = 0;
133
  }
134
 
135
  for (i=0; i<max_task_pos; i++) {
136
      // read the seven datas
137
      t[i].index      = i;
138
      t[i].time       = geti(myfilebuf, &curr_filepos, myfilebuf_length);
139
      t[i].type       = geti(myfilebuf, &curr_filepos, myfilebuf_length);
140
      t[i].reldline   = geti(myfilebuf, &curr_filepos, myfilebuf_length);
141
      t[i].wcet       = geti(myfilebuf, &curr_filepos, myfilebuf_length);
142
      t[i].iterations = geti(myfilebuf, &curr_filepos, myfilebuf_length);
143
      t[i].value      = geti(myfilebuf, &curr_filepos, myfilebuf_length);
144
      t[i].penalty    = geti(myfilebuf, &curr_filepos, myfilebuf_length);
145
 
146
      // check the last one for an error
147
      if (t[i].penalty == -1) {
148
        cprintf("Error parsing task %d...\n",i);
149
        break;
150
      }
151
  }
152
 
153
  *curr_table_dim = i;
154
}
155
 
156
/* the buffer b is scannedc to search for numbers
157
   at the first non-number the function stops */
158
int geti(char *b, int *pos, int maxpos)
159
{
160
  int res = 0;
161
 
162
  // skip first chars
163
  while (!isdigit(b[*pos])) {
164
    (*pos)++;
165
    if (*pos == maxpos) return -1;  // Error!!!
166
  }
167
 
168
 
169
  // read the numbers
170
  do {
171
    res = (res * 10) + b[*pos] - '0';
172
    (*pos)++;
173
  } while (isdigit(b[*pos]));
174
 
175
  return res;
176
}
177