MCPcopy Create free account
hub / github.com/F-Stack/f-stack / db_inputchar

Function db_inputchar

freebsd/ddb/db_input.c:118–308  ·  view source on GitHub ↗

returns true at end-of-line */

(c)

Source from the content-addressed store, hash-verified

116
117/* returns true at end-of-line */
118static int
119db_inputchar(c)
120 int c;
121{
122 static int escstate;
123
124 if (escstate == 1) {
125 /* ESC seen, look for [ or O */
126 if (c == '[' || c == 'O')
127 escstate++;
128 else
129 escstate = 0; /* re-init state machine */
130 return (0);
131 } else if (escstate == 2) {
132 escstate = 0;
133 /*
134 * If a valid cursor key has been found, translate
135 * into an emacs-style control key, and fall through.
136 * Otherwise, drop off.
137 */
138 switch (c) {
139 case 'A': /* up */
140 c = CTRL('p');
141 break;
142 case 'B': /* down */
143 c = CTRL('n');
144 break;
145 case 'C': /* right */
146 c = CTRL('f');
147 break;
148 case 'D': /* left */
149 c = CTRL('b');
150 break;
151 default:
152 return (0);
153 }
154 }
155
156 switch (c) {
157 case CTRL('['):
158 escstate = 1;
159 break;
160 case CTRL('b'):
161 /* back up one character */
162 if (db_lc > db_lbuf_start) {
163 cnputc(BACKUP);
164 db_lc--;
165 }
166 break;
167 case CTRL('f'):
168 /* forward one character */
169 if (db_lc < db_le) {
170 cnputc(*db_lc);
171 db_lc++;
172 }
173 break;
174 case CTRL('a'):
175 /* beginning of line */

Callers 1

db_readlineFunction · 0.85

Calls 5

cnputcFunction · 0.85
db_deleteFunction · 0.85
db_putstringFunction · 0.85
db_putncharsFunction · 0.85
strchrFunction · 0.85

Tested by

no test coverage detected