1 /**************************************************************************** 2 * Copyright 2018,2020 Thomas E. Dickey * 3 * Copyright 2009-2012,2014 Free Software Foundation, Inc. * 4 * * 5 * Permission is hereby granted, free of charge, to any person obtaining a * 6 * copy of this software and associated documentation files (the * 7 * "Software"), to deal in the Software without restriction, including * 8 * without limitation the rights to use, copy, modify, merge, publish, * 9 * distribute, distribute with modifications, sublicense, and/or sell * 10 * copies of the Software, and to permit persons to whom the Software is * 11 * furnished to do so, subject to the following conditions: * 12 * * 13 * The above copyright notice and this permission notice shall be included * 14 * in all copies or substantial portions of the Software. * 15 * * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 23 * * 24 * Except as contained in this notice, the name(s) of the above copyright * 25 * holders shall not be used in advertising or otherwise to promote the * 26 * sale, use or other dealings in this Software without prior written * 27 * authorization. * 28 ****************************************************************************/ 29 30 /**************************************************************************** 31 * Author: Juergen Pfeifer * 32 * * 33 ****************************************************************************/ 34 35 #include <curses.priv.h> 36 37 MODULE_ID("$Id: lib_driver.c,v 1.8 2020/02/02 23:34:34 tom Exp $") 38 39 typedef struct DriverEntry { 40 const char *name; 41 TERM_DRIVER *driver; 42 } DRIVER_ENTRY; 43 44 static DRIVER_ENTRY DriverTable[] = 45 { 46 #ifdef _WIN32 47 {"win32console", &_nc_WIN_DRIVER}, 48 #endif 49 {"tinfo", &_nc_TINFO_DRIVER} /* must be last */ 50 }; 51 52 NCURSES_EXPORT(int) 53 _nc_get_driver(TERMINAL_CONTROL_BLOCK * TCB, const char *name, int *errret) 54 { 55 int code = ERR; 56 size_t i; 57 TERM_DRIVER *res = (TERM_DRIVER *) 0; 58 TERM_DRIVER *use = 0; 59 60 T((T_CALLED("_nc_get_driver(%p, %s, %p)"), 61 (void *) TCB, NonNull(name), (void *) errret)); 62 63 assert(TCB != 0); 64 65 for (i = 0; i < SIZEOF(DriverTable); i++) { 66 res = DriverTable[i].driver; 67 if (strcmp(DriverTable[i].name, res->td_name(TCB)) == 0) { 68 if (res->td_CanHandle(TCB, name, errret)) { 69 use = res; 70 break; 71 } 72 } 73 } 74 if (use != 0) { 75 TCB->drv = use; 76 code = OK; 77 } 78 returnCode(code); 79 } 80 81 NCURSES_EXPORT(int) 82 NCURSES_SP_NAME(has_key) (SCREEN *sp, int keycode) 83 { 84 T((T_CALLED("has_key(%p, %d)"), (void *) sp, keycode)); 85 returnCode(IsValidTIScreen(sp) ? CallDriver_1(sp, td_kyExist, keycode) : FALSE); 86 } 87 88 NCURSES_EXPORT(int) 89 has_key(int keycode) 90 { 91 return NCURSES_SP_NAME(has_key) (CURRENT_SCREEN, keycode); 92 } 93 94 NCURSES_EXPORT(int) 95 NCURSES_SP_NAME(_nc_mcprint) (SCREEN *sp, char *data, int len) 96 { 97 int code = ERR; 98 99 if (0 != TerminalOf(sp)) 100 code = CallDriver_2(sp, td_print, data, len); 101 return (code); 102 } 103 104 NCURSES_EXPORT(int) 105 mcprint(char *data, int len) 106 { 107 return NCURSES_SP_NAME(_nc_mcprint) (CURRENT_SCREEN, data, len); 108 } 109 110 NCURSES_EXPORT(int) 111 NCURSES_SP_NAME(doupdate) (SCREEN *sp) 112 { 113 int code = ERR; 114 115 T((T_CALLED("doupdate(%p)"), (void *) sp)); 116 117 if (IsValidScreen(sp)) 118 code = CallDriver(sp, td_update); 119 120 returnCode(code); 121 } 122 123 NCURSES_EXPORT(int) 124 doupdate(void) 125 { 126 return NCURSES_SP_NAME(doupdate) (CURRENT_SCREEN); 127 } 128 129 NCURSES_EXPORT(int) 130 NCURSES_SP_NAME(mvcur) (SCREEN *sp, int yold, int xold, int ynew, int xnew) 131 { 132 int code = ERR; 133 TR(TRACE_CALLS | TRACE_MOVE, (T_CALLED("mvcur(%p,%d,%d,%d,%d)"), 134 (void *) sp, yold, xold, ynew, xnew)); 135 if (HasTerminal(sp)) { 136 code = CallDriver_4(sp, td_hwcur, yold, xold, ynew, xnew); 137 } 138 returnCode(code); 139 } 140 141 NCURSES_EXPORT(int) 142 mvcur(int yold, int xold, int ynew, int xnew) 143 /* optimized cursor move from (yold, xold) to (ynew, xnew) */ 144 { 145 return NCURSES_SP_NAME(mvcur) (CURRENT_SCREEN, yold, xold, ynew, xnew); 146 } 147