static void tune_in(void) { int selfd; //logmsg("[%s: tune_in(...)] *** ENTER ***", __FILE__); init_signals(); //logmsg("[%s: tune_in(...)] Signals initialized", __FILE__); //lock_ourselves(); init_regexps(); //logmsg("[%s: tune_in(...)] Regexps initialized", __FILE__); // BEGIN HERE if (fifo_exists(ZTEBLADEFM_PIPE_CMD)) { int rv = mkfifo(ZTEBLADEFM_PIPE_CMD, 0666); if (rv < 0) { // handle condition here.. panic("[%s:tune_in(...) @ %d] - Could not mkfifo %s.", __FILE__, __LINE__, ZTEBLADEFM_PIPE_CMD); } } if (fifo_exists(ZTEBLADEFM_PIPE_STATUS)) { int rv = mkfifo(ZTEBLADEFM_PIPE_STATUS, 0666); if (rv < 0) { // handle condition here.. panic("[%s:tune_in(...) @ %d] - Could not mkfifo %s.", __FILE__, __LINE__, ZTEBLADEFM_PIPE_STATUS); } } #if __t0mm13b_defiant__ int rv = mkfifo(ZTEBLADEFM_PIPE_CMD, 0666); if (rv < 0) { // handle condition here.. panic("[%s:tune_in(...) @ %d] - Could not mkfifo %s.", __FILE__, __LINE__, ZTEBLADEFM_PIPE_CMD); } rv = mkfifo(ZTEBLADEFM_PIPE_STATUS, 0666); if (rv < 0) { // handle condition here.. panic("[%s:tune_in(...) @ %d] - Could not mkfifo %s.", __FILE__, __LINE__, ZTEBLADEFM_PIPE_STATUS); } #else g_rdfmdev = open(FM_DEV, O_RDONLY); #endif // init_open_statuspipe(); init_open_commandpipe(); // logic routine from here ... http://stackoverflow.com/questions/1735781/non-blocking-pipe-using-popen while (g_keepRunning) { selfd = select(FD_SETSIZE, &g_fdset_r, (fd_set*)0, (fd_set*)0,NULL); if (selfd < 0) panic("Could not select..."); if (selfd > 0) { check_select(); } } if (g_fprdcmdpipe != NULL) fclose(g_fprdcmdpipe); if (g_fpwrstatpipe != NULL) fclose(g_fpwrstatpipe); #ifdef __t0mm13b_defiant__ ; #else close(g_rdfmdev); #endif cleanup_regexps(); // END HERE }
/* * Parse the string in 'line' using the CSV format from the problem spec. * Assumes 'line' is a proper C string ('\0' terminated). * * Returns true iff the string is sytactically correct. */ int parse_line(char line[]) { int nmatches = 0 ; // assume no matches. init_regexps() ; if( regexec(&parse_5, line, MAX_MATCHES, matches, 0) == 0 ) { nmatches = 5 ; } else if( regexec(&parse_4, line, MAX_MATCHES, matches, 0) == 0 ) { nmatches = 4 ; } if( nmatches != 0) { last_reading.room_id = get_int_field(line, matches[1]) ; last_reading.event.sensor = get_int_field(line, matches[2]) ; get_time_string_field(last_reading.event.time_stamp, line, matches[3]) ; last_reading.event.event_id = get_int_field(line, matches[4]) ; last_reading.event.event_info = (nmatches == 5) ? get_int_field(line, matches[5]) : -1 ; } return nmatches != 0; }