Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1672 tullio 1
#include <stdio.h>
2
#include <stdlib.h>
3
#include "lparser.h"
4
#include "common/time.h"
5
 
6
int dos_preload(char *file_name, long max_size, void **start_file, void **end_file)
7
{
8
  FILE      *file;
9
  void      *buf;
10
  long      rd;
11
 
12
 
13
  file = fopen(file_name,"r");
14
  if (file == NULL) return -1;
15
 
16
  buf = malloc(max_size);
17
  *start_file = buf;
18
 
19
  while(((rd = fread(buf, 1, 2048, file)) == 2048) &&
20
        ((buf - *start_file + rd) < (max_size-2048))) {
21
        buf += rd;
22
  }
23
 
24
  *end_file = buf + rd;
25
 
26
  fclose(file);
27
  return(0);
28
 
29
}
30
 
31
int line_reader(void *start_file, void *end_file, struct timespec *total,
32
                struct loader_task **start_loader_task, struct loader_contract **start_loader_contract)
33
{
34
 
35
  char *pbuf = start_file;
36
  int res,line_num,total_loader_task,total_loader_contract;
37
  struct loader_task *current_t = NULL;
38
  struct loader_contract *current_c = NULL;
39
 
40
  NULL_TIMESPEC(total);
41
 
42
  line_num = 0;
43
  total_loader_task = 0;
44
  total_loader_contract = 0;
45
 
46
  while ((void *)(pbuf) < end_file) {
47
 
48
    line_num++;
49
 
50
    if (*start_loader_contract == NULL)
51
      res = line_parser_contract(&pbuf, line_num, total, &current_c);
52
    else
53
      res = line_parser_contract(&pbuf, line_num, total, &current_c->next);
54
 
55
    if (res == 2) {
56
      total_loader_contract++;
57
      if (*start_loader_contract == NULL)
58
        *start_loader_contract = current_c;
59
      else
60
        current_c = current_c->next;
61
    }
62
 
63
    if (res == 3) break;
64
 
65
  }
66
 
67
  while ((void *)(pbuf) < end_file) {
68
 
69
    line_num++;
70
 
71
    if (*start_loader_task == NULL)
72
      res = line_parser_task(&pbuf, line_num, &current_t);
73
    else
74
      res = line_parser_task(&pbuf, line_num, &current_t->next);
75
 
76
    if (res == 2) {
77
      total_loader_task++;
78
      if (*start_loader_task == NULL)
79
        *start_loader_task = current_t;
80
      else
81
        current_t = current_t->next;
82
    }
83
 
84
    if (res == 3) break;
85
 
86
  }
87
 
88
  printf("Total decoded lines %d\n",line_num);
89
  printf("Total loader contract %d\n",total_loader_contract);
90
  printf("Total loader task %d\n",total_loader_task);
91
  printf("Simulation time sec = %ld usec = %ld\n",total->tv_sec,total->tv_nsec/1000);
92
 
93
  return 0;
94
 
95
}