int main(int argc, char **argv) { char *str; int ret; /* read a string from the user */ str = calloc(MAX_INPUT+1, 1); if(str == NULL) { printf("Unable to allocate string storage space.\n"); return 1; } printf("Please enter a URI:\n"); fgets(str, MAX_INPUT, stdin); printf("Processing %d byte string...\n", (int)strlen(str)); /* process string through FSM */ ret = run_fsm(uri_reference_fsm, &str, NULL, NULL, NULL); if(ret < 0) { printf("Unable to execute FSM on string: %s\n", str); return EXIT_FAILURE; } printf("\nFSM Done - processed %d characters.\n", ret); return 0; }
/** * MAIN */ int main(void) { timer sensor_time = timer_msec; sei(); /* global interrupt enable */ /* start timing function */ timer0_init_1khz(); lcd_init(LCD_DISP_ON); CANMSG("CAN senzor"); init_fsm(&fsm_sensor,&fsm_sensor_init); while(1) { if (timer_msec >= (sensor_time + 100)) { sensor_time = timer_msec; debug(1,timer_msec); /* run fsm every x ms*/ run_fsm(&fsm_sensor); } /* if new msg recived, configure sensor according to new parameters */ if (rx_msg.status == NEW) { rx_msg.status = NONE; sensor_config(&rx_msg,&fsm_sensor); } } return 0; }
static void check_host_is_ip(char **uri_string, int ip_length, void *global_context, void *local_context) { int ret; ret = run_fsm(ipv4address_fsm, uri_string, NULL, NULL, NULL); if(ret == ip_length) { set_host_is_ip(uri_string, ip_length, global_context, local_context); } }
int main(int argc, char **argv) { char *str, *ostr; int ret; uri *parsed_uri; /* initialize the URI structure - this needs pointers set to NULL to be correct! */ parsed_uri = malloc(sizeof(uri)); if(parsed_uri == NULL) { fprintf(stderr, "Unable to allocate space on the heap for a URI\n"); } parsed_uri->host_is_ip = 0; parsed_uri->port = -1; parsed_uri->scheme = NULL; parsed_uri->userinfo = NULL; parsed_uri->host = NULL; parsed_uri->path = NULL; parsed_uri->query = NULL; parsed_uri->fragment = NULL; /* read a string from the user */ str = ostr = calloc(MAX_INPUT+1, 1); if(str == NULL) { printf("Unable to allocate string storage space.\n"); return 1; } printf("Please enter a URI:\n"); fgets(str, MAX_INPUT, stdin); printf("Processing %d byte string...\n", (int)strlen(str)); ret = run_fsm(uri_reference_fsm, &str, (void**)&parsed_uri, duplicate_uri, free_uri); if(ret < 0) { printf("Unable to execute FSM on string: %s\n", str); } else { printf("URI scheme: %s\n", parsed_uri->scheme); printf("URI userinfo: %s\n", parsed_uri->userinfo); printf("URI host: %s\n", parsed_uri->host); printf(" Is host an IP address?: %s\n", (parsed_uri->host_is_ip) ? "yes" : "no"); printf("URI port: %d\n", parsed_uri->port); printf("URI path: %s\n", parsed_uri->path); printf("URI query: %s\n", parsed_uri->query); printf("URI fragment: %s\n", parsed_uri->fragment); printf("\nFSM Done - processed %d characters: \"%.*s\".\n", ret, ret, ostr); } free_uri(parsed_uri); free(ostr); return 0; }