char *delim = " =\t";
char *str = strdup (line);
char *save_ptr;
- char *pt = str;
+ char *ptr = str;
while (1) {
- char *var = strtok_r (pt, delim, &save_ptr);
- pt = NULL;
+ char *var = strtok_r (ptr, delim, &save_ptr);
+ ptr = NULL;
if (!var) break;
char *val = strtok_r (NULL, delim, &save_ptr);
if (!var) break;
comm_t comm_list[MAXCOMMS] = {0};
/* get basename */
- char *pt = progname = argv[0];
- while (*pt) {
- if ((*pt == '/') || (*pt == '\\')) {
- progname = pt + 1;
+ char *ptr = progname = argv[0];
+ while (*ptr) {
+ if ((*ptr == '/') || (*ptr == '\\')) {
+ progname = ptr + 1;
}
- pt++;
+ ptr++;
}
/* process argument */
return -1;
}
}
+ char *script = read_stream (fid, NULL);
+ if (fid != stdin) {
+ fclose (fid);
+ }
+ if (script == NULL) {
+ VERBOSE (morep, ERROR, PRINTF ("no script read\n"));
+ return -1;
+ }
/* signals */
signal(SIGINT, sig_handler);
/* main loop */
int rc = 0;
- while (!feof (fid)) {
+ ptr = script;
+ while (*ptr != '\0') {
/* read line */
- char line[BUFMAX] = {0};
- int i = 0;
+ char *line = ptr;
do {
- fread (line + i, 1, 1, fid);
- if ((line[i] == '\n') || (line[i] == '\r')) {
- line[i] = 0;
+ if ((*ptr == '\n') || (*ptr == '\r')) {
+ *ptr = 0;
}
- } while ((line[i] != 0) && (++i < (int)sizeof (line) - 1));
+ } while (*ptr++ != '\0');
/* clean line */
- char *pt = line;
- while ((*pt == ' ') || (*pt == '\t')) {
- if (*pt == '\0') {
+ while ((*line == ' ') || (*line == '\t')) {
+ if (*line == '\0') {
break;
}
- pt++;
+ line++;
}
- if ((*pt == '\0') || (*pt == '#')) {
+ if ((*line == '\0') || (*line == '#')) {
continue;
}
/* analyse line */
mode = -1;
- if (*pt == 'R') {
+ if (*line == 'R') {
mode = 0;
- } else if (*pt == 'T') {
+ } else if (*line == 'T') {
mode = 1;
- } else if (strncmp (pt, "SLEEP", 5) == 0) {
- int duration = atoi (pt + 5);
+ } else if (strncmp (line, "SLEEP", 5) == 0) {
+ int duration = atoi (line + 5);
VERBOSE (morep, INFO, PRINTF ("sleep %dms\n", duration));
usleep (duration * 1000);
continue;
}
/* find ethertype */
- pt++;
comm_t *comm = NULL;
+ int offset = 1;
+ int i;
for (i = 0; i < nbcomms; i++) {
comm_t *c = comm_list + i;
VERBOSE (morep, TRACE, PRINTF ("test %c[%s]\n", c->mode ? 'T' : 'R', c->etype));
- if ((strncmp (pt, c->etype, strlen (c->etype)) == 0) && (c->mode == mode)) {
+ if ((strncmp (line + offset, c->etype, strlen (c->etype)) == 0) && (c->mode == mode)) {
comm = c;
- pt += strlen (c->etype);
+ offset += strlen (c->etype);
break;
}
}
/* get values */
uint8_t msgtype = 0;
int len = 0;
- uint8_t *payload = parse_line (pt, &msgtype, &len);
+ uint8_t *payload = parse_line (line + offset, &msgtype, &len);
if (len < 0) {
VERBOSE (morep, WARNING, PRINTF ("can't parse line '%s'\n", line));
continue;
}
/* cleaning */
- if (fid != stdin) {
- fclose (fid);
- }
+ free (script);
while (nbcomms) {
MOREP_Close (--nbcomms);
}