Subversion Repositories shark

Rev

Rev 1201 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1200 giacomo 1
#include <kernel/kern.h>
2
#include <stdlib.h>
3
#include "parser.h"
4
 
5
int dos_preload(char *file_name, long max_size, void **start, void **end)
6
{
7
  DOS_FILE* file;
8
  void      *buf;
9
  long      rd;
10
 
11
 
12
  file = DOS_fopen(file_name,"r");
13
  if (file == NULL) return -1;
14
 
15
  buf = malloc(max_size);
16
  *start = buf;
17
 
18
  while(((rd = DOS_fread(buf, sizeof(BYTE), 2048, file)) == 2048) &&
19
        ((buf - *start + rd) < (max_size-2048))) {
20
        buf += rd;
21
  }
22
 
23
  *end = buf + rd;
24
 
25
  DOS_fclose(file);
26
  return(0);
27
 
28
}
29
 
1201 giacomo 30
int line_reader(void *start, void *end, struct timespec *total, struct loader_task **start_loader_task)
1200 giacomo 31
{
32
 
33
  char line_buf[1000];
34
  char *pbuf = start;
35
  int i,res,line_num,total_loader_task;
1201 giacomo 36
  struct loader_task *current = NULL;
1200 giacomo 37
 
38
  NULL_TIMESPEC(total);
39
 
40
  line_num = 0;
41
  total_loader_task = 0;
42
  while ((void *)(pbuf) < end) {
43
    i = 0;
44
    line_num++;
45
    while ((char)(pbuf[i]) != '\n') {
46
      line_buf[i] = pbuf[i];
47
      i++;
48
    }
49
    pbuf += i+1;
50
    line_buf[i] = 0;
1203 giacomo 51
 
52
    if (*start_loader_task == NULL)
53
      res = line_parser(line_buf, line_num, total, &current);
54
    else
55
      res = line_parser(line_buf, line_num, total, &current->next);
56
 
1200 giacomo 57
    if (res == 2) {
58
      total_loader_task++;
1203 giacomo 59
      if (*start_loader_task == NULL)
60
        *start_loader_task = current;
61
      else
62
        current = current->next;
1200 giacomo 63
    }
64
  }
65
 
66
  cprintf("Total decoded lines %d\n",line_num);
67
  cprintf("Total loader task %d\n",total_loader_task);
68
  cprintf("Simulation time sec = %ld usec = %ld\n",total->tv_sec,total->tv_nsec/1000);
69
 
70
  return 0;
71
 
72
}