void app_main() { copy_static(); /* Need to do this before I/O init */ usart_list[0].usart = DBGU; /* Use the debug unit for serial IO */ usart_list[0].baud = 115200; usart_list[0].flags = UF_BREAK | /* Interrupt on break from terminal */ UF_CR; /* Allow CR as end of line */ usart_init( usart_list, USARTS ); ad53_dac[0].pio = PIOA; ad53_dac[0].sclk = bit(10); ad53_dac[0].sync = bit(4); ad53_dac[0].din = bit(9); init_pit( PIT, TICK_HZ ); on_tick = blink; lse_init(); /* build application primitives here */ build_primitive( msec, "msec" ); build_primitive( to_led, ">LED" ); build_primitive( hard_reset, "RESET" ); tc_primitives(); pulsar_spi_primitives(); pulsar_spi_init( SPI0 ); ad53_primitives(); tc_start(); /* go live on raw clock and PPS */ lse_main(); }
int urlparse ( const char *str, url_t *url ) { regmatch_t m[16]; char buf[16]; if (str == NULL || url == NULL) return -1; urlreset(url); /* Create regexp */ if (!urlparse_exp) { urlparse_exp = calloc(1, sizeof(regex_t)); if (regcomp(urlparse_exp, URL_RE, REG_ICASE | REG_EXTENDED)) { tvherror("url", "failed to compile regexp"); exit(1); } } /* Execute */ if (regexec(urlparse_exp, str, ARRAY_SIZE(m), m, 0)) return -1; /* Extract data */ #define copy(x, i)\ {\ x = strndup(str+m[i].rm_so, m[i].rm_eo - m[i].rm_so);\ }(void)0 #define copy_static(x, i)\ {\ int len = m[i].rm_eo - m[i].rm_so;\ if (len >= sizeof(x) - 1)\ len = sizeof(x) - 1;\ memcpy(x, str+m[i].rm_so, len);\ x[len] = 0;\ }(void)0 copy(url->scheme, 1); copy(url->user, 3); copy(url->pass, 5); copy(url->host, 6); copy(url->path, 9); copy_static(buf, 8); url->port = atoi(buf); copy(url->query, 11); copy(url->frag, 13); url->raw = strdup(str); return 0; }