Subversion Repositories shark

Rev

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

Rev Author Line No. Line
1237 giacomo 1
#include <stdio.h>
2
#include <stdlib.h>
1238 giacomo 3
#include "lparser.h"
1237 giacomo 4
#include "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, struct loader_task **start_loader_task)
32
{
33
 
34
  char *pbuf = start_file;
35
  int res,line_num,total_loader_task;
36
  struct loader_task *current = NULL;
37
 
38
  NULL_TIMESPEC(total);
39
 
40
  line_num = 0;
41
  total_loader_task = 0;
42
  while ((void *)(pbuf) < end_file) {
43
 
44
    line_num++;
45
 
46
    if (*start_loader_task == NULL)
47
      res = line_parser(&pbuf, line_num, total, &current);
48
    else
49
      res = line_parser(&pbuf, line_num, total, &current->next);
50
 
51
    if (res == 2) {
52
      total_loader_task++;
53
      if (*start_loader_task == NULL)
54
        *start_loader_task = current;
55
      else
56
        current = current->next;
57
    }
58
 
59
    if (res == 3) break;
60
 
61
  }
62
 
63
  printf("Total decoded lines %d\n",line_num);
64
  printf("Total loader task %d\n",total_loader_task);
65
  printf("Simulation time sec = %ld usec = %ld\n",total->tv_sec,total->tv_nsec/1000);
66
 
67
  return 0;
68
 
69
}