Lines Matching refs:buf

187 static void refreshLine(int fd, const char *prompt, char *buf, size_t len, size_t pos, size_t cols) {
192 buf++;
205 if (write(fd,buf,len) == -1) return;
214 static int linenoisePrompt(int fd, char *buf, size_t buflen, const char *prompt) {
221 buf[0] = '\0';
250 memmove(buf+pos-1,buf+pos,len-pos);
253 buf[len] = '\0';
254 refreshLine(fd,prompt,buf,len,pos,cols);
259 int aux = buf[pos-1];
260 buf[pos-1] = buf[pos];
261 buf[pos] = aux;
263 refreshLine(fd,prompt,buf,len,pos,cols);
284 refreshLine(fd,prompt,buf,len,pos,cols);
291 refreshLine(fd,prompt,buf,len,pos,cols);
300 history[history_len-1-history_index] = strdup(buf);
310 strncpy(buf,history[history_len-1-history_index],buflen);
311 buf[buflen] = '\0';
312 len = pos = strlen(buf);
313 refreshLine(fd,prompt,buf,len,pos,cols);
320 buf[pos] = c;
323 buf[len] = '\0';
329 refreshLine(fd,prompt,buf,len,pos,cols);
332 memmove(buf+pos+1,buf+pos,len-pos);
333 buf[pos] = c;
336 buf[len] = '\0';
337 refreshLine(fd,prompt,buf,len,pos,cols);
342 buf[0] = '\0';
344 refreshLine(fd,prompt,buf,len,pos,cols);
347 buf[pos] = '\0';
349 refreshLine(fd,prompt,buf,len,pos,cols);
353 refreshLine(fd,prompt,buf,len,pos,cols);
357 refreshLine(fd,prompt,buf,len,pos,cols);
364 static int linenoiseRaw(char *buf, size_t buflen, const char *prompt) {
373 if (fgets(buf, buflen, stdin) == NULL) return -1;
374 count = strlen(buf);
375 if (count && buf[count-1] == '\n') {
377 buf[count] = '\0';
381 count = linenoisePrompt(fd, buf, buflen, prompt);
388 char buf[LINENOISE_MAX_LINE];
396 if (fgets(buf,LINENOISE_MAX_LINE,stdin) == NULL) return NULL;
397 len = strlen(buf);
398 while(len && (buf[len-1] == '\n' || buf[len-1] == '\r')) {
400 buf[len] = '\0';
402 return strdup(buf);
404 count = linenoiseRaw(buf,LINENOISE_MAX_LINE,prompt);
406 return strdup(buf);