Blame |
Last modification |
View Log
| RSS feed
#include <stdio.h>
#include <stdlib.h>
#include "lparser.h"
#include "common/time.h"
int dos_preload
(char *file_name
, long max_size
, void **start_file
, void **end_file
)
{
FILE
*file
;
void *buf
;
long rd
;
file
= fopen(file_name
,"r");
if (file
== NULL
) return -1;
buf
= malloc(max_size
);
*start_file
= buf
;
while(((rd
= fread(buf
, 1, 2048, file
)) == 2048) &&
((buf
- *start_file
+ rd
) < (max_size
-2048))) {
buf
+= rd
;
}
*end_file
= buf
+ rd
;
fclose(file
);
return(0);
}
int line_reader
(void *start_file
, void *end_file
, struct timespec
*total
,
struct loader_task
**start_loader_task
, struct loader_contract
**start_loader_contract
)
{
char *pbuf
= start_file
;
int res
,line_num
,total_loader_task
,total_loader_contract
;
struct loader_task
*current_t
= NULL
;
struct loader_contract
*current_c
= NULL
;
NULL_TIMESPEC
(total
);
line_num
= 0;
total_loader_task
= 0;
total_loader_contract
= 0;
while ((void *)(pbuf
) < end_file
) {
line_num
++;
if (*start_loader_contract
== NULL
)
res
= line_parser_contract
(&pbuf
, line_num
, total
, ¤t_c
);
else
res
= line_parser_contract
(&pbuf
, line_num
, total
, ¤t_c
->next
);
if (res
== 2) {
total_loader_contract
++;
if (*start_loader_contract
== NULL
)
*start_loader_contract
= current_c
;
else
current_c
= current_c
->next
;
}
if (res
== 3) break;
}
while ((void *)(pbuf
) < end_file
) {
line_num
++;
if (*start_loader_task
== NULL
)
res
= line_parser_task
(&pbuf
, line_num
, ¤t_t
);
else
res
= line_parser_task
(&pbuf
, line_num
, ¤t_t
->next
);
if (res
== 2) {
total_loader_task
++;
if (*start_loader_task
== NULL
)
*start_loader_task
= current_t
;
else
current_t
= current_t
->next
;
}
if (res
== 3) break;
}
printf("Total decoded lines %d\n",line_num
);
printf("Total loader contract %d\n",total_loader_contract
);
printf("Total loader task %d\n",total_loader_task
);
printf("Simulation time sec = %ld usec = %ld\n",total
->tv_sec
,total
->tv_nsec
/1000);
return 0;
}