Skip to content

Unconventional patch for sorting out empty output lines (produced by … #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion cocomm/cocomm.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,24 @@ int main (int argc, char *argv[]) {

while(fgets(commBuf, BUF_SIZE, fp) != NULL) {
size_t len = strlen(commBuf);
if (len < 1) continue;
if (len < 2) continue; // Sort out lines like "\n".
if (commBuf[0] == '#') continue; // Sort out lines starting with '#'.
if (commBuf[0] == 'P') {
// Pause script execution for given time [ms] in case line starts with 'P' followed by an unsigned integer.
uint32_t millis = 1;
uint8_t p = '\0';
uint32_t result = sscanf(commBuf, "%c %u", &p, &millis);
fprintf(errStream, "result = %u\n", result);
if (2 != result) {
fprintf(errStream, "syntax error on 'P'ause command\n");
fflush(errStream);
exit(EXIT_FAILURE);
}
fprintf(stdout, "pause %u msec...\n", millis);
fflush(stdout);
usleep(millis * 1000);
continue;
}

// send command
if (write(fd_gtw, commBuf, len) != len) { /* blocking function */
Expand Down