]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/base/lib_driver.c
ncurses 5.9 - patch 20121117
[ncurses.git] / ncurses / base / lib_driver.c
index 1be9903fae6818d906ecdfd3b20a559ddbf844b9..6301a5887d64281eb822c03f12b5b1f1cbbc89e1 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2008,2009 Free Software Foundation, Inc.                   *
+ * Copyright (c) 2008-2010,2012 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -33,7 +33,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_driver.c,v 1.1 2009/02/21 15:11:29 juergen Exp $")
+MODULE_ID("$Id: lib_driver.c,v 1.4 2012/09/22 19:32:46 tom Exp $")
 
 typedef struct DriverEntry {
     const char *name;
@@ -43,25 +43,40 @@ typedef struct DriverEntry {
 static DRIVER_ENTRY DriverTable[] =
 {
 #ifdef __MINGW32__
-    {"win", &_nc_WIN_DRIVER},
+    {"win32con", &_nc_WIN_DRIVER},
 #endif
-    {"tinfo", &_nc_TINFO_DRIVER}
+    {"tinfo", &_nc_TINFO_DRIVER}       /* must be last */
 };
 
-#define NUM_DRIVERS (int)(sizeof(DriverTable)/sizeof(DRIVER_ENTRY))
-
 NCURSES_EXPORT(int)
 _nc_get_driver(TERMINAL_CONTROL_BLOCK * TCB, const char *name, int *errret)
 {
     int code = ERR;
-    int i;
+    size_t i;
     TERM_DRIVER *res = (TERM_DRIVER *) 0;
     TERM_DRIVER *use = 0;
 
+    T((T_CALLED("_nc_get_driver(%p, %s, %p)"),
+       (void *) TCB, NonNull(name), (void *) errret));
+
     assert(TCB != 0);
 
-    for (i = 0; i < NUM_DRIVERS; i++) {
+    for (i = 0; i < SIZEOF(DriverTable); i++) {
        res = DriverTable[i].driver;
+       /*
+        * Use "#" (a character which cannot begin a terminal's name) to
+        * select specific driver from the table.
+        *
+        * In principle, we could have more than one non-terminfo driver,
+        * e.g., "win32gui".
+        */
+       if (name != 0 && *name == '#') {
+           size_t n = strlen(name + 1);
+           if (n != 0
+               && strncmp(name + 1, DriverTable[i].name, n)) {
+               continue;
+           }
+       }
        if (res->CanHandle(TCB, name, errret)) {
            use = res;
            break;
@@ -71,13 +86,13 @@ _nc_get_driver(TERMINAL_CONTROL_BLOCK * TCB, const char *name, int *errret)
        TCB->drv = use;
        code = OK;
     }
-    return (code);
+    returnCode(code);
 }
 
 NCURSES_EXPORT(int)
 NCURSES_SP_NAME(has_key) (SCREEN *sp, int keycode)
 {
-    T((T_CALLED("has_key(%p, %d)"), sp, keycode));
+    T((T_CALLED("has_key(%p, %d)"), (void *) sp, keycode));
     returnCode(IsValidTIScreen(sp) ? CallDriver_1(sp, kyExist, keycode) : FALSE);
 }
 
@@ -108,7 +123,7 @@ NCURSES_SP_NAME(doupdate) (SCREEN *sp)
 {
     int code = ERR;
 
-    T((T_CALLED("doupdate(%p)"), sp));
+    T((T_CALLED("doupdate(%p)"), (void *) sp));
 
     if (IsValidScreen(sp))
        code = CallDriver(sp, update);
@@ -127,7 +142,7 @@ NCURSES_SP_NAME(mvcur) (SCREEN *sp, int yold, int xold, int ynew, int xnew)
 {
     int code = ERR;
     TR(TRACE_CALLS | TRACE_MOVE, (T_CALLED("mvcur(%p,%d,%d,%d,%d)"),
-                                 sp, yold, xold, ynew, xnew));
+                                 (void *) sp, yold, xold, ynew, xnew));
     if (HasTerminal(sp)) {
        code = CallDriver_4(sp, hwcur, yold, xold, ynew, xnew);
     }