getstr.c (1.26) | getstr.c (1.27) |
---|---|
1/* $NetBSD: getstr.c,v 1.26 2019/05/20 22:17:41 blymn Exp $ */ | 1/* $NetBSD: getstr.c,v 1.27 2019/06/09 07:40:14 blymn Exp $ */ |
2 3/* 4 * Copyright (c) 1981, 1993, 1994 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: --- 20 unchanged lines hidden (view full) --- 30 */ 31 32#include <assert.h> 33#include <sys/cdefs.h> 34#ifndef lint 35#if 0 36static char sccsid[] = "@(#)getstr.c 8.2 (Berkeley) 5/4/94"; 37#else | 2 3/* 4 * Copyright (c) 1981, 1993, 1994 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: --- 20 unchanged lines hidden (view full) --- 30 */ 31 32#include <assert.h> 33#include <sys/cdefs.h> 34#ifndef lint 35#if 0 36static char sccsid[] = "@(#)getstr.c 8.2 (Berkeley) 5/4/94"; 37#else |
38__RCSID("$NetBSD: getstr.c,v 1.26 2019/05/20 22:17:41 blymn Exp $"); | 38__RCSID("$NetBSD: getstr.c,v 1.27 2019/06/09 07:40:14 blymn Exp $"); |
39#endif 40#endif /* not lint */ 41 42#include <ctype.h> 43#include "curses.h" 44#include "curses_private.h" 45 46#ifndef _CURSES_USE_MACROS --- 46 unchanged lines hidden (view full) --- 93/* 94 * mvwgetnstr -- 95 * Get a string (of maximum n) characters from the given window starting 96 * at (y, x). 97 */ 98int 99mvwgetnstr(WINDOW *win, int y, int x, char *str, int n) 100{ | 39#endif 40#endif /* not lint */ 41 42#include <ctype.h> 43#include "curses.h" 44#include "curses_private.h" 45 46#ifndef _CURSES_USE_MACROS --- 46 unchanged lines hidden (view full) --- 93/* 94 * mvwgetnstr -- 95 * Get a string (of maximum n) characters from the given window starting 96 * at (y, x). 97 */ 98int 99mvwgetnstr(WINDOW *win, int y, int x, char *str, int n) 100{ |
101 if (_cursesi_wmove(win, y, x, 0) == ERR) | 101 if (wmove(win, y, x) == ERR) |
102 return ERR; 103 104 return wgetnstr(win, str, n); 105} 106 107/* 108 * mvwgetstr -- 109 * Get a string from the given window starting at (y, x). 110 */ 111__warn_references(mvgetstr, 112 "warning: this program uses mvgetstr(), which is unsafe."); 113int 114mvwgetstr(WINDOW *win, int y, int x, char *str) 115{ | 102 return ERR; 103 104 return wgetnstr(win, str, n); 105} 106 107/* 108 * mvwgetstr -- 109 * Get a string from the given window starting at (y, x). 110 */ 111__warn_references(mvgetstr, 112 "warning: this program uses mvgetstr(), which is unsafe."); 113int 114mvwgetstr(WINDOW *win, int y, int x, char *str) 115{ |
116 if (_cursesi_wmove(win, y, x, 0) == ERR) | 116 if (wmove(win, y, x) == ERR) |
117 return ERR; 118 119 return wgetstr(win, str); 120} 121 122#endif 123 124/* --- 58 unchanged lines hidden (view full) --- 183 *str = '\0'; 184 if (str != ostr) { 185 if ((char) c == ec) { 186 mvwaddch(win, win->cury, xpos, ' '); 187 if (xpos > oldx) 188 mvwaddch(win, win->cury, 189 xpos - 1, ' '); 190 if (win->curx > xpos - 1) | 117 return ERR; 118 119 return wgetstr(win, str); 120} 121 122#endif 123 124/* --- 58 unchanged lines hidden (view full) --- 183 *str = '\0'; 184 if (str != ostr) { 185 if ((char) c == ec) { 186 mvwaddch(win, win->cury, xpos, ' '); 187 if (xpos > oldx) 188 mvwaddch(win, win->cury, 189 xpos - 1, ' '); 190 if (win->curx > xpos - 1) |
191 _cursesi_wmove(win, win->cury, xpos - 1, 1); | 191 wmove(win, win->cury, xpos - 1); |
192 xpos--; 193 } 194 if (c == KEY_BACKSPACE || c == KEY_LEFT) { 195 /* getch() displays the key sequence */ 196 mvwaddch(win, win->cury, win->curx, 197 ' '); 198 mvwaddch(win, win->cury, win->curx - 1, 199 ' '); 200 if (win->curx > xpos) | 192 xpos--; 193 } 194 if (c == KEY_BACKSPACE || c == KEY_LEFT) { 195 /* getch() displays the key sequence */ 196 mvwaddch(win, win->cury, win->curx, 197 ' '); 198 mvwaddch(win, win->cury, win->curx - 1, 199 ' '); 200 if (win->curx > xpos) |
201 _cursesi_wmove(win, win->cury, xpos - 1, 1); | 201 wmove(win, win->cury, xpos - 1); |
202 xpos--; 203 } 204 str--; 205 if (n != -1) { 206 /* We're counting chars */ 207 remain++; 208 } 209 } else { /* str == ostr */ 210 /* getch() displays the other keys */ 211 if (win->curx > oldx) 212 mvwaddch(win, win->cury, win->curx - 1, 213 ' '); | 202 xpos--; 203 } 204 str--; 205 if (n != -1) { 206 /* We're counting chars */ 207 remain++; 208 } 209 } else { /* str == ostr */ 210 /* getch() displays the other keys */ 211 if (win->curx > oldx) 212 mvwaddch(win, win->cury, win->curx - 1, 213 ' '); |
214 _cursesi_wmove(win, win->cury, oldx, 1); | 214 wmove(win, win->cury, oldx); |
215 xpos = oldx; 216 } 217 } else if (c == kc) { 218 *str = '\0'; 219 if (str != ostr) { 220 /* getch() displays the kill character */ 221 mvwaddch(win, win->cury, win->curx - 1, ' '); 222 /* Clear the characters from screen and str */ 223 while (str != ostr) { 224 mvwaddch(win, win->cury, win->curx - 1, 225 ' '); | 215 xpos = oldx; 216 } 217 } else if (c == kc) { 218 *str = '\0'; 219 if (str != ostr) { 220 /* getch() displays the kill character */ 221 mvwaddch(win, win->cury, win->curx - 1, ' '); 222 /* Clear the characters from screen and str */ 223 while (str != ostr) { 224 mvwaddch(win, win->cury, win->curx - 1, 225 ' '); |
226 _cursesi_wmove(win, win->cury, win->curx - 1, 1); | 226 wmove(win, win->cury, win->curx - 1); |
227 str--; 228 if (n != -1) 229 /* We're counting chars */ 230 remain++; 231 } 232 mvwaddch(win, win->cury, win->curx - 1, ' '); | 227 str--; 228 if (n != -1) 229 /* We're counting chars */ 230 remain++; 231 } 232 mvwaddch(win, win->cury, win->curx - 1, ' '); |
233 _cursesi_wmove(win, win->cury, win->curx - 1, 1); | 233 wmove(win, win->cury, win->curx - 1); |
234 } else 235 /* getch() displays the kill character */ 236 mvwaddch(win, win->cury, oldx, ' '); | 234 } else 235 /* getch() displays the kill character */ 236 mvwaddch(win, win->cury, oldx, ' '); |
237 _cursesi_wmove(win, win->cury, oldx, 1); | 237 wmove(win, win->cury, oldx); |
238 } else if (c >= KEY_MIN && c <= KEY_MAX) { 239 /* getch() displays these characters */ 240 mvwaddch(win, win->cury, xpos, ' '); | 238 } else if (c >= KEY_MIN && c <= KEY_MAX) { 239 /* getch() displays these characters */ 240 mvwaddch(win, win->cury, xpos, ' '); |
241 _cursesi_wmove(win, win->cury, xpos, 1); | 241 wmove(win, win->cury, xpos); |
242 } else { 243 if (remain) { 244 if (iscntrl((unsigned char)c)) 245 mvwaddch(win, win->cury, xpos, ' '); 246 str++; 247 xpos++; 248 remain--; 249 } else 250 mvwaddch(win, win->cury, xpos, ' '); | 242 } else { 243 if (remain) { 244 if (iscntrl((unsigned char)c)) 245 mvwaddch(win, win->cury, xpos, ' '); 246 str++; 247 xpos++; 248 remain--; 249 } else 250 mvwaddch(win, win->cury, xpos, ' '); |
251 _cursesi_wmove(win, win->cury, xpos, 1); | 251 wmove(win, win->cury, xpos); |
252 } 253 } 254 255 if (c == ERR) { 256 *str = '\0'; 257 return ERR; 258 } 259 *str = '\0'; 260 return OK; 261} | 252 } 253 } 254 255 if (c == ERR) { 256 *str = '\0'; 257 return ERR; 258 } 259 *str = '\0'; 260 return OK; 261} |