/** * @brief OUTPUT handler for stdout * @ingroup io */ int revm_output(char *str) { char *tmp; char c; int ret; PROFILER_IN(__FILE__, __FUNCTION__, __LINE__); revm_log(str); /* No -- more -- output breaks in non-interactive, non embedded, remote modes */ if ((world.state.revm_mode != REVM_STATE_INTERACTIVE && world.state.revm_mode != REVM_STATE_EMBEDDED) || world.curjob->ws.io.type == REVM_IO_DUMP || !world.curjob->ws.io.outcache.lines || world.curjob->curscope || !(int)config_get_data(REVM_CONFIG_USEMORE)) PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, (world.curjob->ws.io.output(str))); /* Discard outputs */ if (world.curjob->ws.io.outcache.ignore) PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, -1); /* Counts lines */ tmp = strchr(str, '\n'); while (tmp) { world.curjob->ws.io.outcache.nblines--; if (*tmp == '\0') break; tmp ++; tmp = strchr(tmp, '\n'); } /* Do the output */ ret = world.curjob->ws.io.output(str); /* Is there any lines remaining ? */ if (world.curjob->ws.io.outcache.nblines < 0) { revm_flush(); tmp = "-- press enter for more ('q/n' to quit / next) --\n"; world.curjob->ws.io.output(tmp); /* We decided to discard further output (until next revm_flush) */ if ((read(world.curjob->ws.io.input_fd, &c, 1) == 1) && (c == 'q' || c == 'n')) { if (c == 'q') world.curjob->ws.io.outcache.ignore = 1; world.curjob->ws.io.output("\n"); revm_log("\n"); PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, (c == 'q' ? -1 : -2)); } } PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, ret); }
/** * @brief Read a new line, avoiding comments and void lines */ char *revm_getln() { char *buf; char *sav; NOPROFILER_IN(); do { buf = world.curjob->ws.io.input(); if (buf == ((char *) REVM_INPUT_VOID)) NOPROFILER_ROUT((char *) REVM_INPUT_VOID); if (buf == NULL) NOPROFILER_ROUT(NULL); if (!*buf) { XFREE(__FILE__, __FUNCTION__, __LINE__,buf); NOPROFILER_ROUT(NULL); } sav = buf; while (IS_BLANK(*sav)) sav++; if (!*sav || *sav == REVM_COMMENT_START) { revm_log(sav); revm_log("\n"); revm_buffer_free(buf); if (world.state.revm_mode == REVM_STATE_INTERACTIVE || world.state.revm_mode == REVM_STATE_EMBEDDED) NOPROFILER_ROUT((char*) REVM_INPUT_VOID); buf = NULL; if (*sav) continue; } if (world.state.revm_mode != REVM_STATE_SCRIPT) { revm_output_nolog("\n"); /* avoid looping with readline */ if (revm_is_enabled() && buf == NULL) NOPROFILER_ROUT((char *) REVM_INPUT_VOID); if (revm_is_enabled()) break; } } while (buf == NULL); NOPROFILER_ROUT(buf); }
/** * @brief ERR output function (stderr) * @ingroup io */ int revm_outerr(char *str) { revm_log(str); fprintf(stderr, "%s", str); return (0); }