1*c7ef0cfcSnicm#!/bin/sh 2*c7ef0cfcSnicm############################################################################## 3*c7ef0cfcSnicm# Copyright 2019,2020 Thomas E. Dickey # 4*c7ef0cfcSnicm# # 5*c7ef0cfcSnicm# Permission is hereby granted, free of charge, to any person obtaining a # 6*c7ef0cfcSnicm# copy of this software and associated documentation files (the "Software"), # 7*c7ef0cfcSnicm# to deal in the Software without restriction, including without limitation # 8*c7ef0cfcSnicm# the rights to use, copy, modify, merge, publish, distribute, distribute # 9*c7ef0cfcSnicm# with modifications, sublicense, and/or sell copies of the Software, and to # 10*c7ef0cfcSnicm# permit persons to whom the Software is furnished to do so, subject to the # 11*c7ef0cfcSnicm# following conditions: # 12*c7ef0cfcSnicm# # 13*c7ef0cfcSnicm# The above copyright notice and this permission notice shall be included in # 14*c7ef0cfcSnicm# all copies or substantial portions of the Software. # 15*c7ef0cfcSnicm# # 16*c7ef0cfcSnicm# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # 17*c7ef0cfcSnicm# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # 18*c7ef0cfcSnicm# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # 19*c7ef0cfcSnicm# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # 20*c7ef0cfcSnicm# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # 21*c7ef0cfcSnicm# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # 22*c7ef0cfcSnicm# DEALINGS IN THE SOFTWARE. # 23*c7ef0cfcSnicm# # 24*c7ef0cfcSnicm# Except as contained in this notice, the name(s) of the above copyright # 25*c7ef0cfcSnicm# holders shall not be used in advertising or otherwise to promote the sale, # 26*c7ef0cfcSnicm# use or other dealings in this Software without prior written # 27*c7ef0cfcSnicm# authorization. # 28*c7ef0cfcSnicm############################################################################## 29*c7ef0cfcSnicm# $Id: MKuserdefs.sh,v 1.1 2023/10/17 09:52:09 nicm Exp $ 30*c7ef0cfcSnicmAWK=${1-awk}; shift 1 31*c7ef0cfcSnicmOPT1=${1-0}; shift 1 32*c7ef0cfcSnicm 33*c7ef0cfcSnicmcat <<EOF 34*c7ef0cfcSnicm/* 35*c7ef0cfcSnicm * generated by $0 36*c7ef0cfcSnicm */ 37*c7ef0cfcSnicm 38*c7ef0cfcSnicmEOF 39*c7ef0cfcSnicm 40*c7ef0cfcSnicmcat <<'EOF' 41*c7ef0cfcSnicm/* 42*c7ef0cfcSnicm * comp_userdefs.c -- The names of widely used user-defined capabilities 43*c7ef0cfcSnicm * indexed via a hash table for the compiler. 44*c7ef0cfcSnicm * 45*c7ef0cfcSnicm */ 46*c7ef0cfcSnicm 47*c7ef0cfcSnicm#include <curses.priv.h> 48*c7ef0cfcSnicm#include <tic.h> 49*c7ef0cfcSnicm#include <hashsize.h> 50*c7ef0cfcSnicm 51*c7ef0cfcSnicm#if NCURSES_XNAMES 52*c7ef0cfcSnicmEOF 53*c7ef0cfcSnicm 54*c7ef0cfcSnicmcat "$@" | ./make_hash 1 user $OPT1 55*c7ef0cfcSnicm 56*c7ef0cfcSnicmcat <<EOF 57*c7ef0cfcSnicm 58*c7ef0cfcSnicm#define USERTABSIZE SIZEOF(user_names_data) 59*c7ef0cfcSnicm 60*c7ef0cfcSnicm#if $OPT1 61*c7ef0cfcSnicmstatic void 62*c7ef0cfcSnicmnext_string(const char *strings, unsigned *offset) 63*c7ef0cfcSnicm{ 64*c7ef0cfcSnicm *offset += (unsigned) strlen(strings + *offset) + 1; 65*c7ef0cfcSnicm} 66*c7ef0cfcSnicm 67*c7ef0cfcSnicmstatic const struct user_table_entry * 68*c7ef0cfcSnicm_nc_build_names(struct user_table_entry **actual, 69*c7ef0cfcSnicm const user_table_data *source, 70*c7ef0cfcSnicm const char *strings) 71*c7ef0cfcSnicm{ 72*c7ef0cfcSnicm if (*actual == 0) { 73*c7ef0cfcSnicm *actual = typeCalloc(struct user_table_entry, USERTABSIZE); 74*c7ef0cfcSnicm if (*actual != 0) { 75*c7ef0cfcSnicm unsigned n; 76*c7ef0cfcSnicm unsigned len = 0; 77*c7ef0cfcSnicm for (n = 0; n < USERTABSIZE; ++n) { 78*c7ef0cfcSnicm (*actual)[n].ute_name = strings + len; 79*c7ef0cfcSnicm (*actual)[n].ute_type = (int) source[n].ute_type; 80*c7ef0cfcSnicm (*actual)[n].ute_argc = source[n].ute_argc; 81*c7ef0cfcSnicm (*actual)[n].ute_args = source[n].ute_args; 82*c7ef0cfcSnicm (*actual)[n].ute_index = source[n].ute_index; 83*c7ef0cfcSnicm (*actual)[n].ute_link = source[n].ute_link; 84*c7ef0cfcSnicm next_string(strings, &len); 85*c7ef0cfcSnicm } 86*c7ef0cfcSnicm } 87*c7ef0cfcSnicm } 88*c7ef0cfcSnicm return *actual; 89*c7ef0cfcSnicm} 90*c7ef0cfcSnicm 91*c7ef0cfcSnicm#define build_names(root) _nc_build_names(&_nc_##root##_table, \\ 92*c7ef0cfcSnicm root##_names_data, \\ 93*c7ef0cfcSnicm root##_names_text) 94*c7ef0cfcSnicm#else 95*c7ef0cfcSnicm#define build_names(root) _nc_ ## root ## _table 96*c7ef0cfcSnicm#endif 97*c7ef0cfcSnicm 98*c7ef0cfcSnicmNCURSES_EXPORT(const struct user_table_entry *) _nc_get_userdefs_table (void) 99*c7ef0cfcSnicm{ 100*c7ef0cfcSnicm return build_names(user) ; 101*c7ef0cfcSnicm} 102*c7ef0cfcSnicm 103*c7ef0cfcSnicmstatic HashValue 104*c7ef0cfcSnicminfo_hash(const char *string) 105*c7ef0cfcSnicm{ 106*c7ef0cfcSnicm long sum = 0; 107*c7ef0cfcSnicm 108*c7ef0cfcSnicm DEBUG(9, ("hashing %s", string)); 109*c7ef0cfcSnicm while (*string) { 110*c7ef0cfcSnicm sum += (long) (*string + (*(string + 1) << 8)); 111*c7ef0cfcSnicm string++; 112*c7ef0cfcSnicm } 113*c7ef0cfcSnicm 114*c7ef0cfcSnicm DEBUG(9, ("sum is %ld", sum)); 115*c7ef0cfcSnicm return (HashValue) (sum % HASHTABSIZE); 116*c7ef0cfcSnicm} 117*c7ef0cfcSnicm 118*c7ef0cfcSnicmstatic int 119*c7ef0cfcSnicmcompare_info_names(const char *a, const char *b) 120*c7ef0cfcSnicm{ 121*c7ef0cfcSnicm return !strcmp(a, b); 122*c7ef0cfcSnicm} 123*c7ef0cfcSnicm 124*c7ef0cfcSnicmstatic const HashData hash_data[] = { 125*c7ef0cfcSnicm { HASHTABSIZE, _nc_user_hash_table, info_hash, compare_info_names } 126*c7ef0cfcSnicm}; 127*c7ef0cfcSnicm 128*c7ef0cfcSnicmNCURSES_EXPORT(const HashData *) _nc_get_hash_user (void) 129*c7ef0cfcSnicm{ 130*c7ef0cfcSnicm return hash_data; 131*c7ef0cfcSnicm} 132*c7ef0cfcSnicm 133*c7ef0cfcSnicm#if NO_LEAKS 134*c7ef0cfcSnicmNCURSES_EXPORT(void) _nc_comp_userdefs_leaks(void) 135*c7ef0cfcSnicm{ 136*c7ef0cfcSnicm#if $OPT1 137*c7ef0cfcSnicm FreeIfNeeded(_nc_user_table); 138*c7ef0cfcSnicm#endif 139*c7ef0cfcSnicm} 140*c7ef0cfcSnicm#endif /* NO_LEAKS */ 141*c7ef0cfcSnicm 142*c7ef0cfcSnicm#else /*! NCURSES_XNAMES */ 143*c7ef0cfcSnicmNCURSES_EXPORT(void) _nc_comp_userdefs(void); 144*c7ef0cfcSnicmNCURSES_EXPORT(void) _nc_comp_userdefs(void) { } 145*c7ef0cfcSnicm#endif /* NCURSES_XNAMES */ 146*c7ef0cfcSnicmEOF 147