So this patch will be necessary for the autotooling of ksh (or at least the
updating of it then the subsequent autotooling), as ksh no longer provides its
hashing library this will be necessary if we want to update it (which would
also end it's dependency on ksh, and in the future we could even work on not
depending on ksh whatsoever). This can be applied to either
autotools-conversion or master, as long as it finds its way into
autotools-conversion afterwards. POSIX ksh didnt suit our uses, it can't handle
more than one hash table per program and it also can't operate on hash tables
except for basic lookups and entries. Side note, there is an entirely unused
hash table in DtSvc/DtUtil2 but it is undocumented and I will probably remove
it at some point once Dtksh is done.
Thank you for your time,
-Chase
From 49a8598fad096f955b17a68912874bfd5da6d8ff Mon Sep 17 00:00:00 2001
From: Chase <nicetry...@protonmail.ch>
Date: Sun, 26 Jan 2020 19:27:31 -0600
Subject: [PATCH] dtksh: replace AST hash for Dt hash
---
cde/programs/dtksh/dtkcmds.c | 10 +++----
cde/programs/dtksh/dtkcvt.c | 6 ++--
cde/programs/dtksh/userinit.c | 2 +-
cde/programs/dtksh/widget.c | 55 ++++++++++++++++++-----------------
cde/programs/dtksh/xmcmds.c | 3 +-
cde/programs/dtksh/xmcvt.c | 2 +-
cde/programs/dtksh/xmdtksym.c | 2 +-
7 files changed, 40 insertions(+), 40 deletions(-)
diff --git a/cde/programs/dtksh/dtkcmds.c b/cde/programs/dtksh/dtkcmds.c
index b47ee160..68adeff6 100644
--- a/cde/programs/dtksh/dtkcmds.c
+++ b/cde/programs/dtksh/dtkcmds.c
@@ -55,7 +55,7 @@
#include <Dt/Print.h>
#include <Tt/tttk.h>
#include <Tt/tt_c.h>
-#include "hash.h"
+#include <Dt/DtHash.h>
#include "stdio.h"
#define NO_AST
#include "dtksh.h"
@@ -3103,14 +3103,14 @@ ConvertTypeToString(
char *nam;
char * errmsg;
- if ((nam = hashget((Hash_table_t*)class->res, resource)) == NULL) {
+ if ((nam = _DtUtilFindHash((DtHashTbl)class->res, resource)) == NULL) {
/* If we didn't find it in this widget's class record,
* see if the parent is a constraint widget class, and
* if so then see if we can find the class there.
*/
if (parent == NULL || parent->wclass == NULL ||
parent->wclass->con == NULL ||
- (nam = hashget((Hash_table_t*)parent->wclass->con, resource))
+ (nam = _DtUtilFindHash((DtHashTbl)parent->wclass->con, resource))
== NULL)
{
errmsg = strdup(GetSharedMsg(DT_UNDEF_RESOURCE));
@@ -3183,14 +3183,14 @@ ConvertStringToType(
DTKSHConversionResource = resource; /* needed by callback converter */
DTKSHConversionWidget = w; /* needed by callback converter */
- if ((nam = hashget((Hash_table_t*)class->res, resource)) == NULL) {
+ if ((nam = _DtUtilFindHash((DtHashTbl)class->res, resource)) == NULL) {
/* If we didn't find it in this widget's class record,
* see if the parent is a constraint widget class, and
* if so then see if we can find the class there.
*/
if (parent == NULL || parent->wclass == NULL ||
parent->wclass->con == NULL ||
- (nam = hashget((Hash_table_t*)parent->wclass->con,
+ (nam = _DtUtilFindHash((DtHashTbl)parent->wclass->con,
resource)) == NULL)
{
errmsg = strdup(GetSharedMsg(DT_UNDEF_RESOURCE));
diff --git a/cde/programs/dtksh/dtkcvt.c b/cde/programs/dtksh/dtkcvt.c
index 04a69594..fe92a8da 100644
--- a/cde/programs/dtksh/dtkcvt.c
+++ b/cde/programs/dtksh/dtkcvt.c
@@ -53,7 +53,7 @@
#include <Dt/Help.h>
#include <Dt/EnvControlP.h>
#include <Dt/Print.h>
-#include "hash.h"
+#include <Dt/DtHash.h>
#include "stdio.h"
#define NO_AST
#include "dtksh.h"
@@ -67,7 +67,7 @@
#include "xmwidgets.h"
#include "msgs.h"
-extern Hashtab_t * Wclasses;
+extern DtHashTbl Wclasses;
@@ -707,7 +707,7 @@ DtkshCvtStringToWidgetClass(
}
wcName = (char *)(fval->addr);
- if ((hashInfo = hashget(Wclasses, wcName)) != NULL)
+ if ((hashInfo = _DtUtilFindHash(Wclasses, wcName)) != NULL)
{
classtab = (classtab_t *)hashInfo;
wc = classtab->class;
diff --git a/cde/programs/dtksh/userinit.c b/cde/programs/dtksh/userinit.c
index de269e46..fe0943c3 100644
--- a/cde/programs/dtksh/userinit.c
+++ b/cde/programs/dtksh/userinit.c
@@ -39,7 +39,7 @@
#include <ctype.h>
#include <Xm/Xm.h>
#include <Xm/Protocols.h>
-#include "hash.h"
+#include <Dt/DtHash.h>
#include "stdio.h"
#define NO_AST
#include "dtksh.h"
diff --git a/cde/programs/dtksh/widget.c b/cde/programs/dtksh/widget.c
index 8ef221e8..2601850d 100644
--- a/cde/programs/dtksh/widget.c
+++ b/cde/programs/dtksh/widget.c
@@ -40,7 +40,7 @@
#include <Xm/Xm.h>
#include <Xm/XmStrDefs.h>
#include <Xm/DialogS.h>
-#include "hash.h"
+#include <Dt/DtHash.h>
#include "stdio.h"
#define NO_AST
#include "dtksh.h"
@@ -55,6 +55,7 @@
/* values for the flags field of the W array */
+#define MAXHASHSIZE 67
#define RESOURCE_HASHSIZE 64
#define CLASS_HASHSIZE 32
#define WIDGETALLOC 16 /* Will realloc the widget array in this increment */
@@ -68,14 +69,14 @@ int Wtab_free = 0; /* A count of how many table entries have been freed */
/* CONSTANTS */
char str_0123456789[] = "0123456789";
-Hashtab_t *Wclasses;
+DtHashTbl Wclasses;
static void fixupresources(
char *name,
- Hash_table_t *res,
+ DtHashTbl res,
resfixup_t *fixups) ;
static int rescompare(
XtResource **r1,
@@ -124,10 +125,10 @@ init_widgets( void )
toolkit_init_widgets();
- Wclasses = hashalloc(NULL, 0);
+ Wclasses = _DtUtilMakeHash(MAXHASHSIZE);
for (i = 0; C[i].cname != NULL; i++) {
- if ((nam = hashput(Wclasses, C[i].cname, (char *)(&C[i]))) == NULL)
+ if ((nam = (char *)_DtUtilGetHash(Wclasses, C[i].cname)) != NULL)
{
errhdr = strdup(GetSharedMsg(DT_ERROR));
errmsg = strdup(GETMESSAGE(14,1,
@@ -183,7 +184,7 @@ str_to_class(
return(w->wclass);
}
- if ((nam = hashget(Wclasses, s)) != NULL)
+ if ((nam = (char *)_DtUtilFindHash(Wclasses, s)) != NULL)
{
ret = (classtab_t *)nam;
if (ret->res == NULL)
@@ -196,7 +197,7 @@ str_to_class(
* be initialized, it's resources read and
* hashed.
*/
- ret->res = (char *)hashalloc(NULL, 0);
+ ret->res = (char *)_DtUtilMakeHash(MAXHASHSIZE);
/*
* Have to force the class init
@@ -210,8 +211,8 @@ str_to_class(
XtGetResourceList(ret->class, &resources, &numresources);
for (i = 0; i < numresources; i++)
{
- if ((nam = (char *)hashput((Hash_table_t*)ret->res,
- resources[i].resource_name, (char *)&resources[i])) == NULL)
+ if ((nam = (char *)_DtUtilGetHash((DtHashTbl)ret->res,
+ resources[i].resource_name)) != NULL)
{
errhdr = strdup(GetSharedMsg(DT_ERROR));
errmsg=strdup(GetSharedMsg( DT_HASHING_FAILURE));
@@ -247,9 +248,9 @@ str_to_class(
{
for (j = 0; j < blockArray[i]->num_resources; j++)
{
- if ((nam = (char *)hashput((Hash_table_t*)ret->res,
- blockArray[i]->resources[j].resource_name,
- (char *)&(blockArray[i]->resources[j]))) == NULL)
+ if ((nam = (char *)_DtUtilGetHash((DtHashTbl)ret->res,
+ blockArray[i]->resources[j].resource_name))
+ != NULL)
{
errhdr = strdup(GetSharedMsg(DT_ERROR));
errmsg=strdup(GetSharedMsg( DT_HASHING_FAILURE));
@@ -271,7 +272,7 @@ str_to_class(
}
/* Perform any special resource fixing up */
- fixupresources(s, (Hash_table_t *)ret->res,
+ fixupresources(s, (DtHashTbl)ret->res,
(resfixup_t *)&ret->resfix[0]);
/*
@@ -280,21 +281,21 @@ str_to_class(
XtGetConstraintResourceList(ret->class, &resources, &numresources);
if (resources != NULL)
{
- ret->con = (char *)hashalloc(NULL, 0);
+ ret->con = (char *)_DtUtilMakeHash(MAXHASHSIZE);
for (i = 0; i < numresources; i++)
{
- if ((nam = (char *)hashput((Hash_table_t*)ret->con,
- resources[i].resource_name, &resources[i])) == NULL)
+ if ((nam = (char *)_DtUtilGetHash((DtHashTbl)ret->con,
+ resources[i].resource_name)) != NULL)
{
- errhdr =strdup(GetSharedMsg(DT_ERROR));
- errmsg=strdup(GetSharedMsg(DT_HASHING_FAILURE));
+ errhdr = strdup(GetSharedMsg(DT_ERROR));
+ errmsg = strdup(GetSharedMsg(DT_HASHING_FAILURE));
printerrf(errhdr, errmsg, resources[i].resource_name,
ret->cname, NULL, NULL, NULL, NULL, NULL, NULL);
free(errhdr);
free(errmsg);
}
}
- fixupresources(s, (Hash_table_t *)ret->con,
+ fixupresources(s, (DtHashTbl)ret->con,
(resfixup_t *)&ret->confix[0]);
}
else
@@ -541,7 +542,7 @@ get_new_wtab(
static void
fixupresources(
char *name,
- Hash_table_t *res,
+ DtHashTbl res,
resfixup_t *fixups )
{
XtResource *resource;
@@ -552,7 +553,7 @@ fixupresources(
return;
for (i = 0; fixups[i].name != NULL; i++) {
- resource = (XtResource *)hashget(res, fixups[i].name);
+ resource = (XtResource *)_DtUtilFindHash(res, fixups[i].name);
/*
* We could be either adding a new resource or
* modifying an old one.
@@ -574,7 +575,7 @@ fixupresources(
resource->resource_class = (String)fixups[i].class;
resource->resource_type = (String)fixups[i].type;
resource->resource_size = fixups[i].size;
- hashput(res, fixups[i].name, (char *)resource);
+ _DtUtilGetHash(res, fixups[i].name);
}
}
@@ -615,7 +616,7 @@ do_DtLoadWidget(
memset(classtab, '\0', sizeof(classtab_t));
classtab->cname = (char *)strdup(argv[1]);
classtab->class = ((WidgetClass *)address)[0];
- if ((nam = hashput(Wclasses, classtab->cname, (char *)classtab)) == NULL)
+ if ((nam = (char *)_DtUtilGetHash(Wclasses, classtab->cname)) != NULL)
{
errhdr = strdup(GetSharedMsg(DT_ERROR));
errmsg= strdup(GETMESSAGE(14,7,
@@ -704,10 +705,10 @@ _pr_resource(
Nres = 0;
- hashwalk((Hash_table_t*)(Show_constraint ? c->con : c->res), 0, (int (*)())gather_resource_list, NULL);
+ _DtUtilOperateHash((DtHashTbl)(Show_constraint ? c->con : c->res), (int (*)())gather_resource_list, NULL);
if (!Show_constraint && w && w->parent != NULL &&
XtIsConstraint(w->parent->w)) {
- hashwalk((Hash_table_t *)w->parent->wclass->con, 0, (int (*)())gather_resource_list, NULL);
+ _DtUtilOperateHash((DtHashTbl)w->parent->wclass->con, (int (*)())gather_resource_list, NULL);
}
@@ -859,7 +860,7 @@ do_DtWidgetInfo(
strcmp(argv[1], "-R") == 0) {
/* print all the resources in each widget or class */
if (argc == 2) {
- hashwalk((Hash_table_t *)Wclasses, 0,
+ _DtUtilOperateHash((DtHashTbl)Wclasses,
(int (*)())pr_resource, 0);
return(0);
} else {
@@ -883,7 +884,7 @@ do_DtWidgetInfo(
* class is available
*/
if (argc == 2) {
- hashwalk((Hash_table_t *)Wclasses, 0, (int (*)())pr_class, 0);
+ _DtUtilOperateHash((DtHashTbl)Wclasses, (int (*)())pr_class, 0);
} else {
for (i = 2; i < argc; i++) {
if ((c = str_to_class(argv[0], argv[i])) != NULL)
diff --git a/cde/programs/dtksh/xmcmds.c b/cde/programs/dtksh/xmcmds.c
index e3f1e8bd..bf8ae753 100644
--- a/cde/programs/dtksh/xmcmds.c
+++ b/cde/programs/dtksh/xmcmds.c
@@ -45,7 +45,6 @@
#include <ctype.h>
#include <Xm/Xm.h>
#include <Xm/Protocols.h>
-#include "hash.h"
#include "stdio.h"
#define NO_AST
#include "dtksh.h"
@@ -105,7 +104,7 @@
#include <Dt/HelpQuickD.h>
#include <Dt/Print.h>
#include <Dt/PrintDlgMgrP.h>
-
+#include <Dt/DtHash.h>
static int _xmcreatefunc(
diff --git a/cde/programs/dtksh/xmcvt.c b/cde/programs/dtksh/xmcvt.c
index 61299e79..dc972600 100644
--- a/cde/programs/dtksh/xmcvt.c
+++ b/cde/programs/dtksh/xmcvt.c
@@ -53,7 +53,7 @@
#include <Dt/Help.h>
#include <Dt/EnvControlP.h>
#include <Tt/tttk.h>
-#include "hash.h"
+#include <Dt/DtHash.h>
#include "stdio.h"
#define NO_AST
#include "dtksh.h"
diff --git a/cde/programs/dtksh/xmdtksym.c b/cde/programs/dtksh/xmdtksym.c
index 2e45b21e..a2f61fd2 100644
--- a/cde/programs/dtksh/xmdtksym.c
+++ b/cde/programs/dtksh/xmdtksym.c
@@ -42,7 +42,7 @@
#include <Dt/HourGlass.h>
#include <Dt/Help.h>
#include <Dt/EnvControlP.h>
-#include "hash.h"
+#include <Dt/DtHash.h>
#include "stdio.h"
#define NO_AST
#include "dtksh.h"
--
2.17.1
_______________________________________________
cdesktopenv-devel mailing list
cdesktopenv-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cdesktopenv-devel