Skip to content

Not possible to "quit" the C example: replxx-example-c-api #162

Description

@greenonline

The source file, c-api.c, is missing a code block to handle quitting. As ^C is also captured, and the output displayed, the only way of quitting is to ^Z to stick the program in the background and the kill it.

Note: This happens on macOS Catalina. I have not tested it on other platforms, but it obviously will be present.

Note that it is possible to quit the cxx version.

The corresponding quit code block in the cxx version, cxx-api.cxx is:

		} else if (input.compare(0, 5, ".quit") == 0 || input.compare(0, 5, ".exit") == 0) {
			// exit the repl

			rx.history_add(input);
			break;

Solution

Add the following code block

		} else if (!strncmp(result, "/quit", 6)) {
			printf("\n");
			break;

into the while loop, like so:

  while (1) {
    char const* result = NULL;
    do {
      result = replxx_input( replxx, prompt );
    } while ( ( result == NULL ) && ( errno == EAGAIN ) );

    /* For history2 - start */
		if (result == NULL) {
			printf("\n");
			break;
		} else if (!strncmp(result, "/quit", 6)) {                       // quit code block - begin
			printf("\n");
			break;                                                                  // quit code block - end
		} else if (!strncmp(result, "/history", 9)) {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions