]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - progs/tparm_type.c
ncurses 6.4 - patch 20240420
[ncurses.git] / progs / tparm_type.c
index 26eee698806b7c6e0aa99a938c1e89ce71046d9b..4fed96a534400dfaf9833a6fe14b4a8f4b57d966 100644 (file)
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 1998-2012,2013 Free Software Foundation, Inc.              *
+ * Copyright 2020,2023 Thomas E. Dickey                                     *
+ * Copyright 2014,2015 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            *
@@ -32,7 +33,7 @@
 
 #include <tparm_type.h>
 
-MODULE_ID("$Id: tparm_type.c,v 1.1 2014/05/21 16:50:57 tom Exp $")
+MODULE_ID("$Id: tparm_type.c,v 1.5 2023/04/08 15:57:01 tom Exp $")
 
 /*
  * Lookup the type of call we should make to tparm().  This ignores the actual
@@ -42,18 +43,26 @@ MODULE_ID("$Id: tparm_type.c,v 1.1 2014/05/21 16:50:57 tom Exp $")
 TParams
 tparm_type(const char *name)
 {
-#define TD(code, longname, ti, tc) {code,longname},{code,ti},{code,tc}
+#define TD(code, longname, ti, tc) \
+       {code, {longname} }, \
+       {code, {ti} }, \
+       {code, {tc} }
+#define XD(code, onlyname) TD(code, onlyname, onlyname, onlyname)
     TParams result = Numbers;
     /* *INDENT-OFF* */
     static const struct {
        TParams code;
-       const char *name;
+       const char name[12];
     } table[] = {
        TD(Num_Str,     "pkey_key",     "pfkey",        "pk"),
        TD(Num_Str,     "pkey_local",   "pfloc",        "pl"),
        TD(Num_Str,     "pkey_xmit",    "pfx",          "px"),
        TD(Num_Str,     "plab_norm",    "pln",          "pn"),
        TD(Num_Str_Str, "pkey_plab",    "pfxl",         "xl"),
+#if NCURSES_XNAMES
+       XD(Str,         "Cs"),
+       XD(Str_Str,     "Ms"),
+#endif
     };
     /* *INDENT-ON* */
 
@@ -66,3 +75,35 @@ tparm_type(const char *name)
     }
     return result;
 }
+
+TParams
+guess_tparm_type(int nparam, char **p_is_s)
+{
+    TParams result = Other;
+    switch (nparam) {
+    case 0:
+    case 1:
+       if (!p_is_s[0])
+           result = Numbers;
+       if (p_is_s[0])
+           result = Str;
+       break;
+    case 2:
+       if (!p_is_s[0] && !p_is_s[1])
+           result = Numbers;
+       if (!p_is_s[0] && p_is_s[1])
+           result = Num_Str;
+       if (p_is_s[0] && p_is_s[1])
+           result = Str_Str;
+       break;
+    case 3:
+       if (!p_is_s[0] && !p_is_s[1] && !p_is_s[2])
+           result = Numbers;
+       if (!p_is_s[0] && p_is_s[1] && p_is_s[2])
+           result = Num_Str_Str;
+       break;
+    default:
+       break;
+    }
+    return result;
+}