static void buffer_reject_message(char* data, char* buf, int buflen) { int len = strlen(data); char* t = data + len; int newline = 0; while(t > data && isspace(*(t - 1))) { t--; if(*t == '\n') newline = 1; } /* No valid line */ if(t > data) { if(newline) *t = 0; t = strrchr(data, '\n'); if(t == NULL) { t = trim_start(data); /* * Basically if we already have a newline at the end * then we need to start a new line */ if(buf[strlen(buf) - 1] == '\n') buf[0] = 0; } else { t = trim_start(t); /* Start a new line */ buf[0] = 0; } /* t points to a valid line */ strlcat(buf, t, buflen); } /* Always append if we found a newline */ if(newline) strlcat(buf, "\n", buflen); }
void mainLoop() { char* line; char* orig_line; Command* command; int exit_code; while(1) { line = getLine(); orig_line = line; if(line == NULL) { break; } trim_start(&line); if (strlen(line) > 0) { command = parser(line); exit_code = execute(command); printf("(%d) ", exit_code); //For now, so the compiler don't complains } free(orig_line); } free(line); printf("\n"); exit(EXIT_SUCCESS); }
std::string trim(const std::string &str) { return trim_start(trim_end(str)); }
char* trim_space(char* data) { data = (char*)trim_start(data); return trim_end(data); }