MCPcopy Create free account
hub / github.com/cgsecurity/testdisk / get_string

Function get_string

src/intrfn.c:86–149  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84static int wgetch_nodelay(WINDOW *window);
85
86int get_string(WINDOW *window, char *str, const int len, const char *def)
87{
88 int c;
89 int i = 0;
90 int x, y;
91 int use_def = FALSE;
92 curs_set(1);
93 getyx(window, y, x);
94 str[0] = 0;
95
96 if (def != NULL) {
97 mvwaddstr(window,y, x, def);
98 wmove(window,y, x);
99 use_def = TRUE;
100 }
101
102 wrefresh(window);
103 while ((c = wgetch(window)) != '\n' && c != key_CR
104#ifdef PADENTER
105 && c!= PADENTER
106#endif
107 )
108 {
109 switch (c) {
110 /* escape is generated by enter from keypad */
111 /*
112 case key_ESC:
113 wmove(window,y, x);
114 wclrtoeol(window);
115 curs_set(0);
116 wrefresh(window);
117 return GS_key_ESCAPE;
118 */
119 case KEY_DC:
120 case KEY_BACKSPACE:
121 if (i > 0) {
122 str[--i] = 0;
123 mvwaddch(window, y, x+i, ' ');
124 wmove(window,y, x+i);
125 } else if (use_def) {
126 wclrtoeol(window);
127 use_def = FALSE;
128 }
129 break;
130 default:
131 if (i < len && isprint(c)) {
132 mvwaddch(window, y, x+i, c);
133 if (use_def) {
134 wclrtoeol(window);
135 use_def = FALSE;
136 }
137 str[i++] = c;
138 str[i] = 0;
139 }
140 }
141 wrefresh(window);
142 }
143 curs_set(0);

Callers 7

ask_numberFunction · 0.85
ask_log_locationFunction · 0.85
ask_int_ncursesFunction · 0.85
ask_string_ncursesFunction · 0.85
change_geometry_ncursesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected