4,7 → 4,7 |
#include <stdio.h> |
#include "parser.h" |
|
//#define PARSER_DEBUG |
#define PARSER_DEBUG |
|
static int find_break(char **buf, int find_type, struct timespec *time, int *val) |
{ |
13,18 → 13,31 |
char str[20]; |
|
i = 0; |
while (((char *)(*buf))[i] == ' ' || ((char *)(*buf))[i] == ':') i++; |
while (((char *)(*buf))[i] == ' ' || ((char *)(*buf))[i] == ':' || |
((char *)(*buf))[i] == '\n' || ((char *)(*buf))[i] == '\r') i++; |
*buf += i; |
|
if (!strncmp(*buf,"END",3) && find_type == PAR_NOTHING) { |
*buf += 5; |
return PAR_END; |
} |
|
i = 0; |
if (((char *)(*buf))[0] == '#' && find_type == PAR_NOTHING) { |
while (((char *)(*buf))[i] != '\n' && ((char *)(*buf))[i] != '\r') i++; |
*buf += i; |
return PAR_FOUND; |
} |
|
switch (find_type) { |
|
case PAR_NOTHING: |
if (((char *)(*buf))[0] == '#' || |
((char *)(*buf))[0] == ';' || |
((char *)(*buf))[0] == 0 || |
((char *)(*buf))[0] == '\n' || |
((char *)(*buf))[0] == '\r') return PAR_FOUND; |
break; |
if (((char *)(*buf))[0] == ';' || |
((char *)(*buf))[0] < 32) { |
*buf += 1; |
return PAR_FOUND; |
} |
break; |
|
case PAR_TOTAL_EXEC_TIME: |
if (!strncmp(*buf, "TOTAL_EXEC_TIME:",16)) { |
146,6 → 159,20 |
return PAR_ERROR; |
break; |
|
case PAR_CRIT_SESSION: |
if (!strncmp(*buf,"NO_CRIT",7)) { |
*buf += 7; |
*val = PAR_NO_CRIT; |
return PAR_FOUND; |
} |
if (!strncmp(*buf,"CRIT(",5)) { |
*buf += 5; |
*val = PAR_CRIT; |
return PAR_FOUND; |
} |
return PAR_ERROR; |
break; |
|
} |
|
return PAR_ERROR; |
164,21 → 191,22 |
* 0 -> nothing |
* 1 -> total |
* 2 -> new task-loader |
* 3 -> end file |
*/ |
int line_parser(char *buf, int line_num, struct timespec *total, struct loader_task **last) |
int line_parser(char **pbuf, int line_num, struct timespec *total, struct loader_task **last) |
{ |
char *pbuf = buf; |
struct timespec time; |
struct loader_task *ld = NULL; |
int val, res; |
|
res = find_break(&pbuf, PAR_NOTHING, &time, &val); |
res = find_break(pbuf, PAR_NOTHING, &time, &val); |
if (res == PAR_FOUND) return 0; |
if (res == PAR_END) return 3; |
|
res = find_break(&pbuf,PAR_TOTAL_EXEC_TIME, &time, &val); |
res = find_break(pbuf,PAR_TOTAL_EXEC_TIME, &time, &val); |
if (res == PAR_FOUND) { |
NULL_TIMESPEC(total); |
res = find_break(&pbuf, PAR_TIME, &time, &val); |
res = find_break(pbuf, PAR_TIME, &time, &val); |
if (res == PAR_FOUND) { |
TIMESPEC_ASSIGN(total,&time); |
#ifdef PARSER_DEBUG |
188,7 → 216,7 |
} else par_error(line_num); |
} |
|
res = find_break(&pbuf,PAR_TASK_TYPE, &time, &val); |
res = find_break(pbuf,PAR_TASK_TYPE, &time, &val); |
if (res == PAR_FOUND) { |
#ifdef PARSER_DEBUG |
cprintf("TASK TYPE = %d\n",val); |
204,7 → 232,7 |
|
} else par_error(line_num); |
|
res = find_break(&pbuf,PAR_TASK_NUMBER, &time, &val); |
res = find_break(pbuf,PAR_TASK_NUMBER, &time, &val); |
if (res == PAR_FOUND) { |
#ifdef PARSER_DEBUG |
cprintf("TASK LEVEL = %d\n",val); |
214,7 → 242,7 |
|
} else par_error(line_num); |
|
res = find_break(&pbuf,PAR_TASK_NUMBER, &time, &val); |
res = find_break(pbuf,PAR_TASK_NUMBER, &time, &val); |
if (res == PAR_FOUND) { |
#ifdef PARSER_DEBUG |
cprintf("TASK NUMBER = %d\n",val); |
224,7 → 252,7 |
|
} else par_error(line_num); |
|
res = find_break(&pbuf,PAR_ACT_TYPE, &time, &val); |
res = find_break(pbuf,PAR_ACT_TYPE, &time, &val); |
if (res == PAR_FOUND) { |
#ifdef PARSER_DEBUG |
cprintf("ACTIVATION TYPE: %d (",val); |
232,7 → 260,7 |
|
ld->act_type = val; |
|
res = find_break(&pbuf,PAR_TIME, &time, &val); |
res = find_break(pbuf,PAR_TIME, &time, &val); |
if (res == PAR_FOUND) { |
#ifdef PARSER_DEBUG |
cprintf("[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
241,7 → 269,7 |
} else par_error(line_num); |
|
if (ld->act_type != PAR_ACT_SINGLE) { |
res = find_break(&pbuf,PAR_TIME, &time, &val); |
res = find_break(pbuf,PAR_TIME, &time, &val); |
if (res == PAR_FOUND) { |
#ifdef PARSER_DEBUG |
cprintf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
251,7 → 279,7 |
} |
|
if (ld->act_type != PAR_ACT_SINGLE && ld->act_type != PAR_ACT_PERIODIC) { |
res = find_break(&pbuf,PAR_TIME, &time, &val); |
res = find_break(pbuf,PAR_TIME, &time, &val); |
if (res == PAR_FOUND) { |
#ifdef PARSER_DEBUG |
cprintf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
262,7 → 290,7 |
|
if (ld->act_type != PAR_ACT_SINGLE && ld->act_type != PAR_ACT_PERIODIC && |
ld->act_type != PAR_ACT_MEAN && ld->act_type != PAR_ACT_GAUSS) { |
res = find_break(&pbuf,PAR_TIME, &time, &val); |
res = find_break(pbuf,PAR_TIME, &time, &val); |
if (res == PAR_FOUND) { |
#ifdef PARSER_DEBUG |
cprintf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
277,7 → 305,7 |
|
} else par_error(line_num); |
|
res = find_break(&pbuf,PAR_TIME, &time, &val); |
res = find_break(pbuf,PAR_TIME, &time, &val); |
if (res == PAR_FOUND) { |
#ifdef PARSER_DEBUG |
cprintf("DEADLINE: [%ld][%ld]\n",time.tv_sec,time.tv_nsec/1000); |
285,7 → 313,7 |
TIMESPEC_ASSIGN(&ld->deadline,&time); |
} else par_error(line_num); |
|
res = find_break(&pbuf,PAR_TIME, &time, &val); |
res = find_break(pbuf,PAR_TIME, &time, &val); |
if (res == PAR_FOUND) { |
#ifdef PARSER_DEBUG |
cprintf("WCET: [%ld][%ld]\n",time.tv_sec,time.tv_nsec/1000); |
293,13 → 321,13 |
TIMESPEC_ASSIGN(&ld->wcet,&time); |
} else par_error(line_num); |
|
res = find_break(&pbuf,PAR_EXEC_TYPE, &time, &val); |
res = find_break(pbuf,PAR_EXEC_TYPE, &time, &val); |
if (res == PAR_FOUND) { |
#ifdef PARSER_DEBUG |
cprintf("EXEC TYPE: %d (",val); |
#endif |
ld->exec_type = val; |
res = find_break(&pbuf,PAR_TIME, &time, &val); |
res = find_break(pbuf,PAR_TIME, &time, &val); |
if (res == PAR_FOUND) { |
#ifdef PARSER_DEBUG |
cprintf("[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
308,7 → 336,7 |
} else par_error(line_num); |
|
if (ld->exec_type != PAR_EXEC_CONST) { |
res = find_break(&pbuf,PAR_TIME, &time, &val); |
res = find_break(pbuf,PAR_TIME, &time, &val); |
if (res == PAR_FOUND) { |
#ifdef PARSER_DEBUG |
cprintf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
319,7 → 347,7 |
|
if (ld->exec_type != PAR_EXEC_CONST && ld->exec_type != PAR_EXEC_MEAN && |
ld->exec_type != PAR_EXEC_GAUSS) { |
res = find_break(&pbuf,PAR_TIME, &time, &val); |
res = find_break(pbuf,PAR_TIME, &time, &val); |
if (res == PAR_FOUND) { |
#ifdef PARSER_DEBUG |
cprintf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
334,6 → 362,57 |
|
} else par_error(line_num); |
|
res = find_break(pbuf,PAR_CRIT_SESSION, &time, &val); |
if (res == PAR_FOUND) { |
#ifdef PARSER_DEBUG |
cprintf("CRITITCAL SESSION: %d (",val); |
#endif |
ld->crit_type = val; |
if (ld->crit_type == PAR_CRIT) { |
res = find_break(pbuf,PAR_TASK_NUMBER, &time, &val); |
if (res == PAR_FOUND) { |
#ifdef PARSER_DEBUG |
cprintf("[%d]",val); |
#endif |
ld->resource = val; |
} else par_error(line_num); |
res = find_break(pbuf,PAR_TIME, &time, &val); |
if (res == PAR_FOUND) { |
#ifdef PARSER_DEBUG |
cprintf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
#endif |
TIMESPEC_ASSIGN(&ld->crit_par_1,&time); |
} else par_error(line_num); |
res = find_break(pbuf,PAR_TIME, &time, &val); |
if (res == PAR_FOUND) { |
#ifdef PARSER_DEBUG |
cprintf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
#endif |
TIMESPEC_ASSIGN(&ld->crit_par_2,&time); |
} else par_error(line_num); |
res = find_break(pbuf,PAR_TIME, &time, &val); |
if (res == PAR_FOUND) { |
#ifdef PARSER_DEBUG |
cprintf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
#endif |
TIMESPEC_ASSIGN(&ld->crit_par_3,&time); |
} else par_error(line_num); |
res = find_break(pbuf,PAR_TIME, &time, &val); |
if (res == PAR_FOUND) { |
#ifdef PARSER_DEBUG |
cprintf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
#endif |
TIMESPEC_ASSIGN(&ld->crit_par_4,&time); |
} else par_error(line_num); |
|
} |
|
#ifdef PARSER_DEBUG |
cprintf(")\n"); |
#endif |
|
} else par_error(line_num); |
|
return 2; |
|
} |