static int ProcessLine (char *line) { /* Process a line (or part of a line) of valid code. If at the end of the line, we are still in a region of valid code, then return 1; otherwise, return 0. */ char *p, *rest; int code; p = strstr (line, "\\endcode"); /* search for "\endcode" */ if (p) { /* if found */ *p = '\0'; /* code ends here */ rest = p + L2; /* step over "\endcode" */ p = strstr (rest, "\\code"); /* search for "\code" */ if (p) { p += L1; /* step over "\code" */ rest = calloc (MaxChar, sizeof (char)); strncpy (rest, p, MaxChar); ProcessCode (line); code = ProcessLine (rest); free (rest); return code; } else { ProcessCode (line); return 0; } } else { ProcessCode (line); return 1; } }
void CLirc::Process() { m_profileId = CServiceBroker::GetProfileManager().GetCurrentProfileId(); m_irTranslator.Load("Lircmap.xml"); // make sure work-around (CheckDaemon) uses the same socket path as lirc_init const char* socket_path = getenv("LIRC_SOCKET_PATH"); socket_path = socket_path ? socket_path : "/var/run/lirc/lircd"; setenv("LIRC_SOCKET_PATH", socket_path, 0); while (!m_bStop) { { CSingleLock lock(m_critSection); // lirc_client is buggy because it does not close socket, if connect fails // work around by checking if daemon is running before calling lirc_init if (!CheckDaemon()) { CSingleExit lock(m_critSection); Sleep(1000); continue; } m_fd = lirc_init(const_cast<char*>("kodi"), 0); if (m_fd <= 0) { CSingleExit lock(m_critSection); Sleep(1000); continue; } } char *code; while (!m_bStop) { int ret = lirc_nextcode(&code); if (ret < 0) { lirc_deinit(); Sleep(1000); break; } if (code != nullptr) { if (m_profileId != CServiceBroker::GetProfileManager().GetCurrentProfileId()) { m_profileId = CServiceBroker::GetProfileManager().GetCurrentProfileId(); m_irTranslator.Load("Lircmap.xml"); } ProcessCode(code); free(code); } } } lirc_deinit(); }