// XXX no control for max length here?!?! R_API int r_cons_fgets(char *buf, int len, int argc, const char **argv) { #define RETURN(x) { ret=x; goto beach; } RCons *cons = r_cons_singleton (); int ret = 0, color = cons->pal.input && *cons->pal.input; if (cons->echo) { r_cons_set_raw (0); r_cons_show_cursor (1); } #if 0 int mouse = r_cons_enable_mouse (false); r_cons_enable_mouse (false); r_cons_flush (); #endif if (cons->user_fgets) { RETURN (cons->user_fgets (buf, len)); } printf ("%s", cons->line->prompt); fflush (stdout); *buf = '\0'; fflush (cons->fdin); if (color) { const char *p = cons->pal.input; int len = p? strlen (p): 0; if (len>0) fwrite (p, len, 1, stdout); fflush (stdout); } if (!fgets (buf, len, cons->fdin)) { if (color) { printf (Color_RESET); fflush (stdout); } RETURN (-1); } if (feof (cons->fdin)) { if (color) { printf (Color_RESET); } RETURN (-2); } buf[strlen (buf)-1] = '\0'; if (color) printf (Color_RESET); ret = strlen (buf); beach: #if __UNIX__ if (errno == EINTR) { ret = 0; } #endif //r_cons_enable_mouse (mouse); return ret; }
// XXX no control for max length here?!?! R_API int r_cons_fgets(char *buf, int len, int argc, const char **argv) { RCons *cons = r_cons_singleton (); if (cons->user_fgets) return cons->user_fgets (buf, len); *buf = '\0'; fflush (cons->fdin); if (fgets (buf, len, cons->fdin) == NULL) return -1; if (feof (cons->fdin)) return -2; buf[strlen (buf)-1] = '\0'; return strlen (buf); }
// XXX no control for max length here?!?! R_API int r_cons_fgets(char *buf, int len, int argc, const char **argv) { #define RETURN(x) { ret=x; goto beach; } RCons *cons = r_cons_singleton (); int ret = 0, color = cons->pal.input && *cons->pal.input; #if 0 int mouse = r_cons_enable_mouse (R_FALSE); r_cons_enable_mouse (R_FALSE); r_cons_flush (); #endif if (cons->user_fgets) { RETURN (cons->user_fgets (buf, len)); } *buf = '\0'; fflush (cons->fdin); if (color) { const char *p = cons->pal.input; int len = p? strlen (p): 0; if (len>0) fwrite (p, len, 1, stdout); fflush (stdout); } if (fgets (buf, len, cons->fdin) == NULL) { if (color) { printf (Color_RESET); fflush (stdout); } RETURN (-1); } if (feof (cons->fdin)) { if (color) printf (Color_RESET); RETURN (-2); } buf[strlen (buf)-1] = '\0'; if (color) printf (Color_RESET); ret = strlen (buf); beach: //r_cons_enable_mouse (mouse); return ret; }