From ce6018836c422c86a729ba39fe5433ec11b87b02 Mon Sep 17 00:00:00 2001 From: Greg Hudson Date: Sun, 14 Sep 1997 18:12:16 +0000 Subject: Pull in sources from zephyr locker. See /mit/zephyr/repository for detailed change information. --- zwgc/Dictionary/Imakefile | 32 ---- zwgc/Dictionary/dictionary.c | 261 ------------------------------- zwgc/Dictionary/dictionary.h | 111 -------------- zwgc/Dictionary/string_dictionary_aux.c | 101 ------------ zwgc/Dictionary/string_dictionary_aux.h | 58 ------- zwgc/Imakefile | 117 -------------- zwgc/Makefile.in | 140 +++++++++++++++++ zwgc/Memory/Imakefile | 19 --- zwgc/Memory/new_memory.c | 252 ------------------------------ zwgc/Memory/new_memory.h | 86 ----------- zwgc/String/Imakefile | 22 --- zwgc/String/new_string.c | 197 ------------------------ zwgc/String/new_string.c.old | 197 ------------------------ zwgc/String/new_string.h | 136 ----------------- zwgc/X_driver.c | 36 ++--- zwgc/X_fonts.c | 10 +- zwgc/X_gram.c | 34 ++--- zwgc/browser.c | 3 +- zwgc/buffer.c | 4 +- zwgc/character_class.c | 4 +- zwgc/dictionary.c | 263 ++++++++++++++++++++++++++++++++ zwgc/dictionary.h | 111 ++++++++++++++ zwgc/display.c | 11 +- zwgc/error.c | 4 +- zwgc/eval.c | 8 +- zwgc/exec.c | 9 +- zwgc/file.c | 7 +- zwgc/formatter.c | 52 ++++++- zwgc/generate_instance | 42 ----- zwgc/instantiate | 39 +++++ zwgc/lexer.c | 6 +- zwgc/main.c | 39 +++-- zwgc/main.h | 6 +- zwgc/mux.c | 12 +- zwgc/new_memory.c | 244 +++++++++++++++++++++++++++++ zwgc/new_memory.h | 86 +++++++++++ zwgc/new_string.c | 196 ++++++++++++++++++++++++ zwgc/new_string.h | 136 +++++++++++++++++ zwgc/node.c | 6 +- zwgc/node.h | 93 +++++------ zwgc/notice.c | 6 +- zwgc/parser.y | 8 +- zwgc/port.c | 47 ++---- zwgc/regexp.c | 30 ++-- zwgc/standard_ports.c | 22 +-- zwgc/string_dictionary_aux.c | 102 +++++++++++++ zwgc/string_dictionary_aux.h | 58 +++++++ zwgc/subscriptions.c | 3 +- zwgc/substitute.c | 1 + zwgc/text_operations.c | 4 +- zwgc/tty_filter.c | 71 ++++----- zwgc/ulong.h | 24 --- zwgc/unsigned_long.h | 5 + zwgc/variables.c | 6 +- zwgc/xcut.c | 11 +- zwgc/xerror.c | 10 +- zwgc/xerror.h | 2 +- zwgc/xmark.c | 8 +- zwgc/xrevstack.c | 12 +- zwgc/xselect.c | 10 +- zwgc/xshow.c | 10 +- zwgc/zephyr.c | 60 +++----- zwgc/zephyr.vars | 23 --- zwgc/zephyr.vars.in | 23 +++ zwgc/zwgc.1 | 31 ++-- zwgc/zwgc.desc | 18 ++- 66 files changed, 1803 insertions(+), 1992 deletions(-) delete mode 100644 zwgc/Dictionary/Imakefile delete mode 100644 zwgc/Dictionary/dictionary.c delete mode 100644 zwgc/Dictionary/dictionary.h delete mode 100644 zwgc/Dictionary/string_dictionary_aux.c delete mode 100644 zwgc/Dictionary/string_dictionary_aux.h delete mode 100644 zwgc/Imakefile create mode 100644 zwgc/Makefile.in delete mode 100644 zwgc/Memory/Imakefile delete mode 100644 zwgc/Memory/new_memory.c delete mode 100644 zwgc/Memory/new_memory.h delete mode 100644 zwgc/String/Imakefile delete mode 100644 zwgc/String/new_string.c delete mode 100644 zwgc/String/new_string.c.old delete mode 100644 zwgc/String/new_string.h create mode 100644 zwgc/dictionary.c create mode 100644 zwgc/dictionary.h delete mode 100755 zwgc/generate_instance create mode 100755 zwgc/instantiate create mode 100644 zwgc/new_memory.c create mode 100644 zwgc/new_memory.h create mode 100644 zwgc/new_string.c create mode 100644 zwgc/new_string.h create mode 100644 zwgc/string_dictionary_aux.c create mode 100644 zwgc/string_dictionary_aux.h delete mode 100644 zwgc/ulong.h create mode 100644 zwgc/unsigned_long.h delete mode 100644 zwgc/zephyr.vars create mode 100644 zwgc/zephyr.vars.in (limited to 'zwgc') diff --git a/zwgc/Dictionary/Imakefile b/zwgc/Dictionary/Imakefile deleted file mode 100644 index 2bae6c7..0000000 --- a/zwgc/Dictionary/Imakefile +++ /dev/null @@ -1,32 +0,0 @@ -/**/# Copyright 1988, 1993 Massachusetts Institute of Technology. -/**/# -/**/# For copying and distribution information, see the file -/**/# "mit-copyright.h". -/**/# -/**/# $Id$ - -OBJS = string_dictionary_aux.o int_dictionary.o string_dictionary.o -SRCS = string_dictionary_aux.c int_dictionary.c string_dictionary.c - -XDEFS = -I../String -I../Memory - -all:: string_dictionary.h dictionary_spec $(OBJS) -depend:: $(SRCS) - -/**/# Automatically generate a spec file from the template include file: -dictionary_spec: dictionary.h - cat dictionary.h | grep "^.\*" | grep -v "^ \*/" | sed 's/.\*//' > dictionary_spec - -/**/# Generate a int dictionary instance: -int_dictionary.c int_dictionary.h: dictionary.c dictionary.h - ../generate_instance . dictionary int - -/**/# Generate a string dictionary instance: -string_dictionary.c string_dictionary.h: dictionary.c dictionary.h - ../generate_instance . dictionary string new_string.h - -clean:: - $(RM) $(OBJS) dictionary_spec int_dictionary.c string_dictionary.c \ - int_dictionary.h string_dictionary.h - -string_dictionary_aux.o: string_dictionary.h diff --git a/zwgc/Dictionary/dictionary.c b/zwgc/Dictionary/dictionary.c deleted file mode 100644 index f9962f3..0000000 --- a/zwgc/Dictionary/dictionary.c +++ /dev/null @@ -1,261 +0,0 @@ -/* This file is part of the Project Athena Zephyr Notification System. - * It is one of the source files comprising zwgc, the Zephyr WindowGram - * client. - * - * Created by: Marc Horowitz - * - * $Source$ - * $Author$ - * - * Copyright (c) 1989 by the Massachusetts Institute of Technology. - * For copying and distribution information, see the file - * "mit-copyright.h". - */ - -#if (!defined(lint) && !defined(SABER)) -static char rcsid_dictionary_c[] = "$Id$"; -#endif - -/* - * dictionary - a module implementing a generic dictionary. That is, - * any type can be used for the values that keys are bound to. - * Keys are always strings. - * - * Overview: - * - * A dictionary is a set of bindings which bind values of some - * type (this type is the generic parameter of the dictionary) to - * strings. At most one value can be bound to any one string. - * The value that a string is bound to can be changed later. - * Bindings can also be deleted later. It is also possible to - * enumerate all of the bindings in a dictionary. Dictionarys - * are heap based and must be created & destroyed accordingly. - * - * Note: This module assumes that malloc NEVER returns 0 for reasonable - * requests. It is the users responsibility to either ensure that - * this happens or supply a version of malloc with error - * handling. - * - * Dictionarys are mutable. - * - * Implementation: - * - * A standard chaining hash table is used to implement dictionarys. - * Each dictionary has an associated size (# of slots), allowing - * different size dictionaries as needed. - */ - -#include "TYPE_T_dictionary.h" -#include "new_string.h" -#include "new_memory.h" - -#ifndef NULL -#define NULL 0 -#endif - -/* - * TYPE_T_dictionary TYPE_T_dictionary_Create(int size): - * Requires: size > 0 - * Effects: Returns a new empty dictionary containing no bindings. - * The returned dictionary must be destroyed using - * TYPE_T_dictionary_Destroy. Size is a time vs space - * parameter. For this implementation, space used is - * proportional to size and time used is proportional - * to number of bindings divided by size. It is preferable - * that size is a prime number. - */ - -TYPE_T_dictionary TYPE_T_dictionary_Create(size) - int size; -{ - int i; - TYPE_T_dictionary result; - - result = (TYPE_T_dictionary)malloc(sizeof(struct _TYPE_T_dictionary)); - result->size = size; - result->slots = (TYPE_T_dictionary_binding **)malloc( - size*sizeof(TYPE_T_dictionary_binding *)); - - for (i=0; islots[i] = NULL; - - return(result); -} - -/* - * void TYPE_T_dictionary_Destroy(TYPE_T_dictionary d): - * Requires: d is a non-destroyed TYPE_T_dictionary - * Modifies: d - * Effects: Destroys dictionary d freeing up the space it consumes. - * Dictionary d should never be referenced again. Note that - * free is NOT called on the values of the bindings. If - * this is needed, the client must do this first using - * TYPE_T_dictionary_Enumerate. - */ - -void TYPE_T_dictionary_Destroy(d) - TYPE_T_dictionary d; -{ - int i; - TYPE_T_dictionary_binding *binding_ptr, *new_binding_ptr; - - for (i=0; isize; i++) { - binding_ptr = d->slots[i]; - while (binding_ptr) { - new_binding_ptr = binding_ptr->next; - free(binding_ptr->key); - free(binding_ptr); - binding_ptr = new_binding_ptr; - } - } - free(d->slots); - free(d); -} - -/* - * void TYPE_T_dictionary_Enumerate(TYPE_T_dictionary d; void (*proc)()): - * Requires: proc is a void procedure taking 1 argument, a - * TYPE_T_dictionary_binding pointer, which does not - * make any calls using dictionary d. - * Effects: Calls proc once with each binding in dictionary d. - * Order of bindings passed is undefined. Note that - * only the value field of the binding should be considered - * writable by proc. - */ - -void TYPE_T_dictionary_Enumerate(d, proc) - TYPE_T_dictionary d; - void (*proc)(/* TYPE_T_dictionary_binding *b */); -{ - int i; - TYPE_T_dictionary_binding *binding_ptr; - - for (i=0; isize; i++) { - binding_ptr = d->slots[i]; - while (binding_ptr) { - proc(binding_ptr); - binding_ptr = binding_ptr->next; - } - } -} - -/* - * Private routine: - * - * unsigned int dictionary__hash(char *s): - * Effects: Hashs s to an unsigned integer. This number mod the - * hash table size is supposed to roughly evenly distribute - * keys over the table's slots. - */ - -static unsigned int dictionary__hash(s) - char *s; -{ - unsigned int result = 0; - - if (!s) - return(result); - - while (s[0]) { - result <<= 1; - result += s[0]; - s++; - } - - return(result); -} - -/* - * TYPE_T_dictionary_binding *TYPE_T_dictionary_Lookup(TYPE_T_dictionary d, - * char *key): - * Effects: If key is not bound in d, returns 0. Othersize, - * returns a pointer to the binding that binds key. - * Note the access restrictions on bindings... - */ - -TYPE_T_dictionary_binding *TYPE_T_dictionary_Lookup(d, key) - TYPE_T_dictionary d; - char *key; -{ - TYPE_T_dictionary_binding *binding_ptr; - - binding_ptr = d->slots[dictionary__hash(key)%(d->size)]; - while (binding_ptr) { - if (string_Eq(key, binding_ptr->key)) - return(binding_ptr); - binding_ptr = binding_ptr->next; - } - - return(NULL); -} - -/* - * TYPE_T_dictionary_binding *TYPE_T_dictionary_Define(TYPE_T_dictionary d, - * char *key, - * int *already_existed): - * Modifies: d - * Effects: If key is bound in d, returns a pointer to the binding - * that binds key. Otherwise, adds a binding of key to - * d and returns its address. If already_existed is non-zero - * then *already_existed is set to 0 if key was not - * previously bound in d and 1 otherwise. - * Note the access restrictions on bindings... Note also - * that the value that key is bounded to if a binding is - * created is undefined. The caller should set the value - * in this case. - */ - -TYPE_T_dictionary_binding *TYPE_T_dictionary_Define(d, key, already_existed) - TYPE_T_dictionary d; - char *key; - int *already_existed; -{ - TYPE_T_dictionary_binding **ptr_to_the_slot, *binding_ptr; - - ptr_to_the_slot = &(d->slots[dictionary__hash(key)%(d->size)]); - - binding_ptr = *ptr_to_the_slot; - while (binding_ptr) { - if (string_Eq(binding_ptr->key, key)) { - if (already_existed) - *already_existed = 1; - return(binding_ptr); - } - binding_ptr = binding_ptr->next; - } - - if (already_existed) - *already_existed = 0; - binding_ptr = (TYPE_T_dictionary_binding *)malloc( - sizeof(TYPE_T_dictionary_binding)); - binding_ptr->next = *ptr_to_the_slot; - binding_ptr->key = string_Copy(key); - *ptr_to_the_slot = binding_ptr; - return(binding_ptr); -} - -/* - * void TYPE_T_dictionary_Delete(TYPE_T_dictionary d, - * TYPE_T_dictionary_binding *b): - * Requires: *b is a binding in d. - * Modifies: d - * Effects: Removes the binding *b from d. Note that if - * b->value needs to be freed, it should be freed - * before making this call. - */ - -void TYPE_T_dictionary_Delete(d, b) - TYPE_T_dictionary d; - TYPE_T_dictionary_binding *b; -{ - TYPE_T_dictionary_binding **ptr_to_binding_ptr; - - ptr_to_binding_ptr = &(d->slots[dictionary__hash(b->key)%(d->size)]); - - while (*ptr_to_binding_ptr != b) - ptr_to_binding_ptr = &((*ptr_to_binding_ptr)->next); - - *ptr_to_binding_ptr = b->next; - free(b->key); - free(b); -} diff --git a/zwgc/Dictionary/dictionary.h b/zwgc/Dictionary/dictionary.h deleted file mode 100644 index 3299825..0000000 --- a/zwgc/Dictionary/dictionary.h +++ /dev/null @@ -1,111 +0,0 @@ -/* This file is part of the Project Athena Zephyr Notification System. - * It is one of the source files comprising zwgc, the Zephyr WindowGram - * client. - * - * Created by: Marc Horowitz - * - * $Source$ - * $Author$ - * $Id$ - * - * Copyright (c) 1989 by the Massachusetts Institute of Technology. - * For copying and distribution information, see the file - * "mit-copyright.h". - */ - -#ifndef TYPE_T_dictionary_TYPE -#define TYPE_T_dictionary_TYPE - -typedef struct _TYPE_T_dictionary_binding { - struct _TYPE_T_dictionary_binding *next; /* PRIVATE */ - char *key; /* READ-ONLY */ - TYPE_T value; -} TYPE_T_dictionary_binding; - -typedef struct _TYPE_T_dictionary { /* PRIVATE */ - int size; - TYPE_T_dictionary_binding **slots; -} *TYPE_T_dictionary; - -/* - * TYPE_T_dictionary TYPE_T_dictionary_Create(int size): - * Requires: size > 0 - * Effects: Returns a new empty dictionary containing no bindings. - * The returned dictionary must be destroyed using - * TYPE_T_dictionary_Destroy. Size is a time vs space - * parameter. For this implementation, space used is - * proportional to size and time used is proportional - * to number of bindings divided by size. It is preferable - * that size is a prime number. - */ - -extern TYPE_T_dictionary TYPE_T_dictionary_Create(/* int size */); - -/* - * void TYPE_T_dictionary_Destroy(TYPE_T_dictionary d): - * Requires: d is a non-destroyed TYPE_T_dictionary - * Modifies: d - * Effects: Destroys dictionary d freeing up the space it consumes. - * Dictionary d should never be referenced again. Note that - * free is NOT called on the values of the bindings. If - * this is needed, the client must do this first using - * TYPE_T_dictionary_Enumerate. - */ - -extern void TYPE_T_dictionary_Destroy(/* TYPE_T_dictionary d */); - -/* - * void TYPE_T_dictionary_Enumerate(TYPE_T_dictionary d; void (*proc)()): - * Requires: proc is a void procedure taking 1 argument, a - * TYPE_T_dictionary_binding pointer, which does not - * make any calls using dictionary d. - * Effects: Calls proc once with each binding in dictionary d. - * Order of bindings passed is undefined. Note that - * only the value field of the binding should be considered - * writable by proc. - */ - -extern void TYPE_T_dictionary_Enumerate(/* TYPE_T_dictionary d, - void (*proc)() */); - -/* - * TYPE_T_dictionary_binding *TYPE_T_dictionary_Lookup(TYPE_T_dictionary d, - * char *key): - * Effects: If key is not bound in d, returns 0. Othersize, - * returns a pointer to the binding that binds key. - * Note the access restrictions on bindings... - */ - -extern TYPE_T_dictionary_binding *TYPE_T_dictionary_Lookup(/* d, key */); - -/* - * TYPE_T_dictionary_binding *TYPE_T_dictionary_Define(TYPE_T_dictionary d, - * char *key, - * int *already_existed): - * Modifies: d - * Effects: If key is bound in d, returns a pointer to the binding - * that binds key. Otherwise, adds a binding of key to - * d and returns its address. If already_existed is non-zero - * then *already_existed is set to 0 if key was not - * previously bound in d and 1 otherwise. - * Note the access restrictions on bindings... Note also - * that the value that key is bounded to if a binding is - * created is undefined. The caller should set the value - * in this case. - */ - -extern TYPE_T_dictionary_binding *TYPE_T_dictionary_Define(); - -/* - * void TYPE_T_dictionary_Delete(TYPE_T_dictionary d, - * TYPE_T_dictionary_binding *b): - * Requires: *b is a binding in d. - * Modifies: d - * Effects: Removes the binding *b from d. Note that if - * b->value needs to be freed, it should be freed - * before making this call. - */ - -extern void TYPE_T_dictionary_Delete(); - -#endif diff --git a/zwgc/Dictionary/string_dictionary_aux.c b/zwgc/Dictionary/string_dictionary_aux.c deleted file mode 100644 index c17c157..0000000 --- a/zwgc/Dictionary/string_dictionary_aux.c +++ /dev/null @@ -1,101 +0,0 @@ -/* This file is part of the Project Athena Zephyr Notification System. - * It is one of the source files comprising zwgc, the Zephyr WindowGram - * client. - * - * Created by: Marc Horowitz - * - * $Source$ - * $Author$ - * - * Copyright (c) 1989 by the Massachusetts Institute of Technology. - * For copying and distribution information, see the file - * "mit-copyright.h". - */ - -#if (!defined(lint) && !defined(SABER)) -static char rcsid_string_dictionary_aux_c[] = "$Id$"; -#endif - -/* - * string_dictionary_aux - a module implementing convenience routines for use - * with string_dictionarys - * - * Overview: - * - * This module implements Fetch and Set operations on - * string_dictionaries which take the place of Define and Lookup for - * most uses. The importance difference between them and Define and - * Lookup is that they maintain the invariant that all the value strings - * in a string_dictionary are on the heap. In particular, they do - * free's and string_Copy's whenever needed. Also implemented is - * SafeDestroy which does a Destroy after freeing all the value strings - * in a string_dictionary. - */ - -#include "new_memory.h" -#include "string_dictionary.h" - -/* - * void string_dictionary_Set(string_dictionary d, string key,string value): - * Modifies: d - * Effects: Binds key to value in d. Automatically free's the - * previous value of key, if any. Value is copied on the - * heap. - */ - -void string__dictionary_Set(d, key, value) - string_dictionary d; - string key; - string value; -{ - string_dictionary_binding *binding; - int already_exists; - - binding = string_dictionary_Define(d, key, &already_exists); - if (already_exists) - free(binding->value); - - binding->value = string_Copy(value); -} - -/* - * char *string_dictionary_Fetch(string_dictionary d, string key) - * Effects: If key is not bound in d, returns 0. Otherwise, - * returns the value that key is bound to. - * Note that the returned string if any should not be - * freed or modified in any way. Note also that it may - * disappear later if key is rebound. - */ - -char *string_dictionary_Fetch(d, key) - string_dictionary d; - string key; -{ - string_dictionary_binding *binding; - - binding = string_dictionary_Lookup(d, key); - if (!binding) - return(0); - - return(binding->value); -} - -/* - * void string_dictionary_SafeDestroy(string_dictionary d) - * Modifies: d - * Effects: Like string_dictionary_Destroy except first frees - * all value's in the dictionary. - */ - -static void free_value_of_binding(b) - string_dictionary_binding *b; -{ - free(b->value); -} - -void string_dictionary_SafeDestroy(d) - string_dictionary d; -{ - string_dictionary_Enumerate(d, free_value_of_binding); - string_dictionary_Destroy(d); -} diff --git a/zwgc/Dictionary/string_dictionary_aux.h b/zwgc/Dictionary/string_dictionary_aux.h deleted file mode 100644 index 2098095..0000000 --- a/zwgc/Dictionary/string_dictionary_aux.h +++ /dev/null @@ -1,58 +0,0 @@ -/* This file is part of the Project Athena Zephyr Notification System. - * It is one of the source files comprising zwgc, the Zephyr WindowGram - * client. - * - * Created by: Marc Horowitz - * - * $Source$ - * $Author$ - * $Id$ - * - * Copyright (c) 1989 by the Massachusetts Institute of Technology. - * For copying and distribution information, see the file - * "mit-copyright.h". - */ - -#ifndef string_dictionary_aux_MODULE -#define string_dictionary_aux_MODULE - -#include "new_memory.h" -#include "string_dictionary.h" - -/* - * void string_dictionary_Set(string_dictionary d, string key,string value): - * Modifies: d - * Effects: Binds key to value in d. Automatically free's the - * previous value of key, if any. Value is copied on the - * heap. - */ - -extern void string__dictionary_Set(); -#ifdef DEBUG_MEMORY -#define string_dictionary_Set(a,b,c) (set_module(__FILE__,__LINE__),\ - string__dictionary_Set(a,b,c)) -#else -#define string_dictionary_Set(a,b,c) string__dictionary_Set(a,b,c) -#endif - -/* - * char *string_dictionary_Fetch(string_dictionary d, string key) - * Effects: If key is not bound in d, returns 0. Otherwise, - * returns the value that key is bound to. - * Note that the returned string if any should not be - * freed or modified in any way. Note also that it may - * disappear later if key is rebound. - */ - -extern char *string_dictionary_Fetch(); - -/* - * void string_dictionary_SafeDestroy(string_dictionary d) - * Modifies: d - * Effects: Like string_dictionary_Destroy except first frees - * all value's in the dictionary. - */ - -extern void string_dictionary_SafeDestroy(); - -#endif diff --git a/zwgc/Imakefile b/zwgc/Imakefile deleted file mode 100644 index 21dca3a..0000000 --- a/zwgc/Imakefile +++ /dev/null @@ -1,117 +0,0 @@ -/**/# Copyright 1988, 1993 Massachusetts Institute of Technology. -/**/# -/**/# For copying and distribution information, see the file -/**/# "mit-copyright.h". -/**/# -/**/# $Id$ - -#ifdef _AIX -TERMCAP = -lcurses -#else -TERMCAP = -ltermcap -#endif - -#ifdef macII -OSLIBS = -lc -lPW -#endif -#ifdef SOLARIS -OSLIBS = -lgen -#endif - -#ifdef __NetBSD__ -OSDEFS=-DPOSIX_REGEXP -#endif - -LIBS = $(ZLIB) $(LIB_X) $(TERMCAP) $(OSLIBS) $(OSLIBS) - -SRCS = port_dictionary.c pointer_dictionary.c ulong_dictionary.c \ - parser.y lexer.c node.c exec.c buffer.c main.c zephyr.c X_driver.c\ - substitute.c port.c xshow.c \ - mux.c eval.c subscriptions.c notice.c xcut.c regexp.c\ - character_class.c text_operations.c file.c error.c variables.c\ - formatter.c X_fonts.c X_gram.c tty_filter.c standard_ports.c\ - xselect.c xmark.c xrevstack.c xerror.c - -OBJS = parser.o lexer.o node.o exec.o buffer.o main.o zephyr.o X_driver.o\ - substitute.o port_dictionary.o port.o xshow.o pointer_dictionary.o\ - mux.o eval.o subscriptions.o notice.o xcut.o regexp.o\ - character_class.o text_operations.o file.o error.o variables.o\ - formatter.o X_fonts.o X_gram.o tty_filter.o standard_ports.o\ - xselect.o xmark.o xrevstack.o xerror.o ulong_dictionary.o \ - $(LIBRARIES) - -LIBRARIES = ./String/new_string.o\ - ./Dictionary/string_dictionary.o\ - ./Dictionary/string_dictionary_aux.o\ - ./Dictionary/int_dictionary.o\ - ./Memory/new_memory.o - -GENSRCS= port_dictionary.c pointer_dictionary.c ulong_dictionary.c - -GENERATED= $(GENSRCS) \ - port_dictionary.h pointer_dictionary.h ulong_dictionary.h \ - char_stack.h string_stack.h xmode_stack.h \ - y.tab.h - -XDEFS = -I./Memory -I./String -I./Dictionary -DREVSTACK \ - -DDEFDESC=\"$(ZLIBDIR)/zwgc.desc\" \ - -DAPPDEFDATABASE=\"$(ZLIBDIR)/zwgc_resources\" \ - -DZWGCPATH=\"$(ATHBINDIR)/zwgc\" \ - -DSGI_DESKS $(OSDEFS) - -SUBDIRS = Memory String Dictionary - -do_subdirs_imakefile($(SUBDIRS)) -foreach_subdirs(clean,$(SUBDIRS)) -foreach_subdirs(all,$(SUBDIRS)) -foreach_subdirs(depend,$(SUBDIRS)) - -zprogram(zwgc,$(LIBS)) -install_man(zwgc.1,zwgc.1) - -install_file(zwgc.desc,$(ZLIBDIR)) -install_file(zwgc_resources,$(ZLIBDIR)) -install_file(zephyr.vars,$(ATHCONFDIR)) - -YFLAGS=-d - -/**/# use implicit yacc rule for the following: -parser.o: parser.y -y.tab.h: parser.o - -/**/# How to generate a port dictionary: -port_dictionary.c port_dictionary.h: Dictionary/dictionary.c Dictionary/dictionary.h - ./generate_instance ./Dictionary dictionary port port.h - -/**/# How to generate a pointer dictionary: -pointer_dictionary.c pointer_dictionary.h: Dictionary/dictionary.c Dictionary/dictionary.h - ./generate_instance ./Dictionary dictionary pointer pointer.h - -/**/# How to generate a ulong dictionary: -ulong_dictionary.c ulong_dictionary.h: Dictionary/dictionary.c Dictionary/dictionary.h - ./generate_instance ./Dictionary dictionary ulong ulong.h - -/**/# How to generate a char stack: -char_stack.h: stack.h - ./generate_instance . stack char - -/**/# How to generate a string stack: -string_stack.h: stack.h - ./generate_instance . stack string - -/**/# How to generate a xmode stack: -xmode_stack.h: stack.h - ./generate_instance . stack xmode - -clean:: - $(RM) $(GENERATED) - -eval.c eval.o: port.h string_stack.h -exec.c exec.o: port.h string_stack.h -lexer.c: y.tab.h -main.c main.o: port.h string_stack.h -port.c port.o: port_dictionary.h -standard_ports.c standard_ports.o: port.h string_stack.h -text_operations.c text_operations.o: char_stack.h -xshow.c xshow.o: pointer_dictionary.h xmode_stack.h -X_driver.c X_driver.o: ulong_dictionary.h diff --git a/zwgc/Makefile.in b/zwgc/Makefile.in new file mode 100644 index 0000000..a7e55cb --- /dev/null +++ b/zwgc/Makefile.in @@ -0,0 +1,140 @@ +SHELL = /bin/sh + +prefix=@prefix@ +exec_prefix=@exec_prefix@ +datadir=@datadir@ +confdir=@confdir@ +sbindir=@sbindir@ +lsbindir=@lsbindir@ + +includedir=${prefix}/include +mandir=${prefix}/man +libdir=${exec_prefix}/lib +bindir=${exec_prefix}/bin + +srcdir=@srcdir@ +top_srcdir=@top_srcdir@ +BUILDTOP=../.. +VPATH=@srcdir@ +CC=@CC@ +YACC=@YACC@ +INSTALL=@INSTALL@ +INSTANTIATE=${srcdir}/instantiate + +DEBUG=-O +CFLAGS=${DEBUG} -DDATADIR=\"${datadir}\" -I${top_srcdir}/h \ + -I${BUILDTOP}/h -I${srcdir} -I. @X_CFLAGS@ @CPPFLAGS@ +YFLAGS=-d +LDFLAGS=${DEBUG} -L${BUILDTOP}/lib/zephyr @ET_LDFLAGS@ @X_LIBS@ @LDFLAGS@ +LIBS=-lzephyr @LIBS@ -lcom_err @X_PRE_LIBS@ @ZWGC_LIBX11@ @X_EXTRA_LIBS@ \ + @TLIB@ @RLIB@ + +OBJS= port_dictionary.o pointer_dictionary.o unsigned_long_dictionary.o \ + string_dictionary.o int_dictionary.o string_dictionary_aux.o \ + parser.o lexer.o node.o exec.o buffer.o main.o zephyr.o X_driver.o \ + substitute.o port.o xshow.o mux.o eval.o subscriptions.o notice.o \ + xcut.o regexp.o character_class.o text_operations.o file.o error.o \ + variables.o formatter.o X_fonts.o X_gram.o tty_filter.o \ + standard_ports.o xselect.o xmark.o xrevstack.o xerror.o \ + new_string.o new_memory.o + +all: zwgc + +zwgc: ${OBJS} ${BUILDTOP}/lib/zephyr/libzephyr.a @ETDEP@ + ${CC} ${LDFLAGS} -o $@ ${OBJS} ${LIBS} + +port_dictionary.c port_dictionary.h: dictionary.c dictionary.h + ${INSTANTIATE} ${srcdir} dictionary port port.h + +pointer_dictionary.c pointer_dictionary.h: dictionary.c dictionary.h + ${INSTANTIATE} ${srcdir} dictionary pointer pointer.h + +unsigned_long_dictionary.c unsigned_long_dictionary.h: dictionary.c \ + dictionary.h + ${INSTANTIATE} ${srcdir} dictionary unsigned_long unsigned_long.h + +string_dictionary.c string_dictionary.h: dictionary.c dictionary.h + ${INSTANTIATE} ${srcdir} dictionary string new_string.h + +int_dictionary.c int_dictionary.h: dictionary.c dictionary.h + ${INSTANTIATE} ${srcdir} dictionary int + +char_stack.h: stack.h + ${INSTANTIATE} ${srcdir} stack char + +string_stack.h: stack.h + ${INSTANTIATE} ${srcdir} stack string + +xmode_stack.h: stack.h + ${INSTANTIATE} ${srcdir} stack xmode + +check: + +install: zwgc + ${INSTALL} -m 755 -s zwgc ${DESTDIR}${bindir} + ${INSTALL} -m 644 ${srcdir}/zwgc.1 ${DESTDIR}${mandir}/man1 + ${INSTALL} -m 644 ${srcdir}/zwgc.desc ${DESTDIR}${datadir} + ${INSTALL} -m 644 ${srcdir}/zwgc_resources ${DESTDIR}${datadir} + ${INSTALL} -m 644 zephyr.vars ${DESTDIR}${confdir} + +clean: + rm -f ${OBJS} zwgc port_dictionary.[ch] pointer_dictionary.[ch] + rm -f unsigned_long_dictionary.[ch] string_dictionary.[ch] + rm -f int_dictionary.[ch] char_stack.h string_stack.h xmode_stack.h + +${OBJS}: ${top_srcdir}/h/sysdep.h ${BUILDTOP}/h/config.h +zephyr.o: ${BUILDTOP}/h/zephyr/zephyr.h ${BUILDTOP}/h/zephyr/zephyr_err.h + +port_dictionary.o: port.h string_stack.h new_string.h new_memory.h +pointer_dictionary.o: pointer.h new_string.h new_memory.h +unsigned_long_dictionary.o: new_string.h new_memory.h +string_dictionary.o: new_string.h new_memory.h +int_dictionary.o: new_string.h new_memory.h +X_driver.o: X_driver.h new_memory.h formatter.h mux.h variables.h error.h +X_driver.o: X_gram.h xselect.h unsigned_long_dictionary.h +X_fonts.o: X_fonts.h new_memory.h new_string.h error.h pointer_dictionary.h +X_fonts.o: zwgc.h +X_gram.o: X_gram.h xmark.h zwgc.h X_driver.h X_fonts.h error.h new_string.h +X_gram.o: xrevstack.h xerror.h xselect.h +browser.o: zwgc.h +buffer.o: new_memory.h buffer.h +character_class.o: character_class.h +display.o: new_memory.h new_string.h variables.h display.h +eval.o: new_memory.h node.h eval.h substitute.h port.h buffer.h regexp.h +eval.o: text_operations.h zwgc.h variables.h +exec.o: new_memory.h exec.h eval.h node.h buffer.h port.h variables.h notice.h +file.o: new_memory.h new_string.h error.h +formatter.o: new_memory.h char_stack.h string_dictionary.h formatter.h +formatter.o: text_operations.h +lexer.o: new_memory.h new_string.h int_dictionary.h lexer.h parser.h y.tab.h +main.o: new_memory.h zwgc.h parser.h node.h exec.h zephyr.h notice.h +main.o: subscriptions.h file.h mux.h port.h variables.h main.h +mux.o: mux.h error.h zwgc.h pointer.h +new_memory.o: new_memory.h int_dictionary.h +new_string.o: new_memory.h +node.o: new_memory.h node.h +notice.o: new_memory.h error.h variables.h notice.h +port.o: new_string.h port_dictionary.h port.h notice.h variables.h +regexp.o: regexp.h +standard_ports.o: new_memory.h port.h variables.h error.h main.h +string_dictionary_aux.o: new_memory.h string_dictionary.h +subscriptions.o: new_memory.h new_string.h int_dictionary.h zwgc.h +subscriptions.o: subscriptions.h error.h file.h main.h +substitute.o: new_memory.h lexer.h substitute.h +text_operations.o: new_memory.h text_operations.h char_stack.h +tty_filter.o: new_memory.h new_string.h string_dictionary_aux.h formatter.h +tty_filter.o: zwgc.h error.h +variables.o: new_memory.h notice.h string_dictionary_aux.h variables.h +xcut.o: new_memory.h new_string.h X_gram.h zwgc.h xselect.h xmark.h error.h +xcut.o: xrevstack.h +xerror.o: mux.h +xmark.o: X_gram.h X_fonts.h xmark.h new_string.h +xrevstack.o: X_gram.h zwgc.h +xselect.o: new_string.h xselect.h +xshow.o: pointer_dictionary.h new_memory.h formatter.h variables.h zwgc.h +xshow.o: X_fonts.h X_gram.h xmode_stack.h +zephyr.o: new_string.h zephyr.h error.h mux.h subscriptions.h variables.h +zephyr.o: pointer.h X_driver.h + +.PHONY: all check install clean + diff --git a/zwgc/Memory/Imakefile b/zwgc/Memory/Imakefile deleted file mode 100644 index 5d01802..0000000 --- a/zwgc/Memory/Imakefile +++ /dev/null @@ -1,19 +0,0 @@ -/**/# Copyright 1988, 1993 Massachusetts Institute of Technology. -/**/# -/**/# For copying and distribution information, see the file -/**/# "mit-copyright.h". -/**/# -/**/# $Id$ - -OBJS = new_memory.o -SRCS = new_memory.c - -all:: memory_spec $(OBJS) - -/**/# Automatically generate a spec file from the template include file: -memory_spec: new_memory.h - cat new_memory.h | grep "^.\*" | grep -v "^ \*/" | sed 's/.\*//' > memory_spec - -clean:: - $(RM) $(OBJS) memory_spec - diff --git a/zwgc/Memory/new_memory.c b/zwgc/Memory/new_memory.c deleted file mode 100644 index 7fb2732..0000000 --- a/zwgc/Memory/new_memory.c +++ /dev/null @@ -1,252 +0,0 @@ -/* This file is part of the Project Athena Zephyr Notification System. - * It is one of the source files comprising zwgc, the Zephyr WindowGram - * client. - * - * Created by: Marc Horowitz - * - * $Source$ - * $Author$ - * - * Copyright (c) 1989 by the Massachusetts Institute of Technology. - * For copying and distribution information, see the file - * "mit-copyright.h". - */ - -#if !defined(SABER) && (defined(DEBUG) || defined(MEMORY_DEBUG)) - -#if (!defined(lint) && !defined(SABER)) -static char rcsid_new_memory_c[] = "$Id$"; -#endif - -/* - * memory - module wrapping debugging code around normal malloc/free/etc. - * routines. - * - * Overview: - * - * ... - */ - -#define memory__PROVIDER -#include "new_memory.h" - -/* - * - */ -extern char *malloc(); -extern char *realloc(); -char *calloc(); -extern int free(); - -/* - * - */ -#ifdef DEBUG -#define assert(x) if (!(x)) abort() -#else -#define assert(x) -#endif - -/* - * - */ -#ifdef DEBUG_MEMORY - -#include - -extern void record_request(); -char *current_module = 0; -int current_line = -1; - -#endif - -/* - * string string_CreateFromData(char *data, int length): - * Requires: data[0], data[1], ..., data[length-1] != 0 - * Effects: Takes the first length characters at data and - * creates a string containing them. The returned string - * is on the heap & must be freed eventually. - * I.e., if passed "foobar" and 3, it would return - * string_Copy("foo"). - */ - -char *memory__malloc(size) - unsigned size; -{ - char *result; - - result = malloc(size + memory__size_of_header); - if (!result) - abort(); /* <<<>>> */ - -#ifdef DEBUG_MEMORY - ((memory_block_header *)result)->size = size; - ((memory_block_header *)result)->creating_module = current_module; - ((memory_block_header *)result)->line_number_in_creating_module = - current_line; - ((memory_block_header *)result)->check_field = CHECK_FIELD_VALUE; - result += memory__size_of_header; - - record_request(current_module, current_line, 1, size); -#endif - - return(result); -} - -char *memory__realloc(ptr, size) - char *ptr; - unsigned size; -{ - char *result; - - assert(ptr); - -#ifdef DEBUG_MEMORY - if (!memory__on_heap_p(ptr)) { - printf("realloced non-memory block in %s on line %d!\n", - current_module, current_line); - fflush(stdout); - return(realloc(ptr, size)); - } -#endif - - result = realloc(ptr-memory__size_of_header, size+memory__size_of_header); - if (!result) - abort(); /* <<<>>> */ - - return(result+memory__size_of_header); -} - -char *memory__calloc(nelem, elsize) - unsigned nelem; - unsigned elsize; -{ - char *result; - -#ifdef DEBUG_MEMORY - printf("in calloc\n"); fflush(stdout); -#endif - - abort(); - -#ifdef FRED - result = calloc(nelem, elsize); - if (!result) - abort(); - - record_request(1); -#endif - - return(result); -} - -void memory__free(ptr) - char *ptr; -{ - assert(ptr); - -#ifdef DEBUG_MEMORY - if (!memory__on_heap_p(ptr)) { - printf("freed non-memory block in %s on line %d!\n", current_module, - current_line); - fflush(stdout); - (void)free(ptr); - return; - } - - record_request(memory__get_header(ptr)->creating_module, - memory__get_header(ptr)->line_number_in_creating_module, - -1, - memory__get_header(ptr)->size); -#endif - - (void)free(ptr-memory__size_of_header); -} - -#ifdef DEBUG_MEMORY - -#include "../Dictionary/int_dictionary.h" - -static int request_off = 0; -static int_dictionary requests = 0; -static int outstanding_requests = 0; -static int outstanding_memory = 0; - -void record_request(module, line_number, dir, size) - char *module; - int line_number; - int dir; - unsigned int size; -{ - int_dictionary_binding *binding; - int already_exists; -#ifdef LINE - char buffer[20]; -#endif - - if (request_off) - return; - request_off = 1; - - if (!requests) - requests = int_dictionary_Create(101); - -#ifdef LINE - module = string_Concat(module, ":"); - sprintf(buffer, "%d", line_number); - module = string_Concat2(module, buffer); -#endif - - binding = int_dictionary_Define(requests, module, &already_exists); - if (!already_exists) - binding->value = 0; - -#ifdef LINE - free(module); -#endif - - binding->value += dir; - outstanding_requests += dir; - outstanding_memory += size*dir; - - request_off = 0; -} - -void proc(binding) - int_dictionary_binding *binding; -{ - if (binding->value) - printf(" %-30s %6d blocks allocated\n", binding->key, binding->value); -} - -void report_memory_usage() -{ - printf("\n# of blocks on the heap = %d\n", outstanding_requests); - printf("Total heap space in use: %d bytes\n", outstanding_memory); - - printf("\nHeap Allocations by module:\n"); - int_dictionary_Enumerate(requests, proc); - printf("\n"); - - fflush(stdout); -} - -void set_module(file, line) - char *file; - int line; -{ - if (request_off) - return; - - if (!strcmp(file, "new_string.c")) - return; - if (!strcmp(file, "string_dictionary_aux.c")) - return; - - current_line = line; - current_module = file; -} - -#endif - -#endif /* SABER */ diff --git a/zwgc/Memory/new_memory.h b/zwgc/Memory/new_memory.h deleted file mode 100644 index 5c213b7..0000000 --- a/zwgc/Memory/new_memory.h +++ /dev/null @@ -1,86 +0,0 @@ -/* This file is part of the Project Athena Zephyr Notification System. - * It is one of the source files comprising zwgc, the Zephyr WindowGram - * client. - * - * Created by: Marc Horowitz - * - * $Source$ - * $Author$ - * $Id$ - * - * Copyright (c) 1989 by the Massachusetts Institute of Technology. - * For copying and distribution information, see the file - * "mit-copyright.h". - */ - -/* This entire module goes out the window in saber */ -#if !defined(SABER) && (defined(DEBUG) || defined(DEBUG_MEMORY)) - -#ifndef memory_MODULE -#define memory_MODULE - -extern char *memory__malloc(); /* PRIVATE */ -extern char *memory__realloc(); /* PRIVATE */ -extern char *memory__calloc(); /* PRIVATE */ -extern void memory__free(); /* PRIVATE */ - -#ifdef DEBUG_MEMORY - -#define CHECK_FIELD_VALUE 0xe5e7e3e9 - -typedef struct _memory_block_header { - unsigned size; - char *creating_module; - int line_number_in_creating_module; - unsigned int check_field; -} memory_block_header; - -#define memory__size_of_header (sizeof(struct _memory_block_header)) - -#define memory__get_header(block) \ - ((struct _memory_block_header *)((block)-memory__size_of_header)) - -#define memory__on_heap_p(block) \ - (memory__get_header(block)->check_field==CHECK_FIELD_VALUE) - -#else - -#define memory__size_of_header 0 - -#define memory__on_heap_p(block) 1 - -#endif - -/* - * int string_Length(string s): - * Effects: Returns the number of non-null characters in s. - */ - -#ifndef memory__PROVIDER -#ifdef DEBUG_MEMORY - -extern char *current_module; -extern void set_module(); - -#define malloc(size) (set_module(__FILE__,__LINE__),\ - memory__malloc(size)) -#define realloc(ptr, size) (set_module(__FILE__,__LINE__),\ - memory__realloc((char *) ptr, size)) -#define calloc(nelem, elsize) (set_module(__FILE__,__LINE__),\ - memory__calloc(nelem, elsize)) -#define free(ptr) (set_module(__FILE__,__LINE__),\ - memory__free((char *) ptr)) -#else - -#define malloc(size) memory__malloc(size) -#define realloc(ptr, size) memory__realloc((char *) ptr, size) -#define calloc(nelem, elsize) memory__calloc(nelem, elsize) -#define free(ptr) memory__free((char *) ptr) - -#endif /* DEBUG_MEMORY */ - -#endif /* memory__PROVIDER */ - -#endif /* memory_MODULE */ - -#endif /* SABER */ diff --git a/zwgc/String/Imakefile b/zwgc/String/Imakefile deleted file mode 100644 index e47f681..0000000 --- a/zwgc/String/Imakefile +++ /dev/null @@ -1,22 +0,0 @@ -/**/# Copyright 1988, 1993 Massachusetts Institute of Technology. -/**/# -/**/# For copying and distribution information, see the file -/**/# "mit-copyright.h". -/**/# -/**/# $Id$ - - -OBJS = new_string.o -SRCS = new_string.c - -XDEFS= -I../Memory - -all:: string_spec $(OBJS) - -/**/# Automatically generate a spec file from the template include file: -string_spec: new_string.h - cat new_string.h | grep "^.\*" | grep -v "^ \*/" | sed 's/.\*//' > string_spec - -clean:: - $(RM) $(OBJS) string_spec - diff --git a/zwgc/String/new_string.c b/zwgc/String/new_string.c deleted file mode 100644 index aca7746..0000000 --- a/zwgc/String/new_string.c +++ /dev/null @@ -1,197 +0,0 @@ -/* This file is part of the Project Athena Zephyr Notification System. - * It is one of the source files comprising zwgc, the Zephyr WindowGram - * client. - * - * Created by: Marc Horowitz - * - * $Source$ - * $Author$ - * - * Copyright (c) 1989 by the Massachusetts Institute of Technology. - * For copying and distribution information, see the file - * "mit-copyright.h". - */ - -#if (!defined(lint) && !defined(SABER)) -static char rcsid_new_string_c[] = "$Id$"; -#endif - -/* - * string - a module providing operations on C strings. (i.e., char *'s) - * - * Overview: - * - * A string is a standard C string. I.e., a char pointer to a - * null-terminated sequence of characters. 0 is NOT considered a valid - * string! Various operations are available. See the string_spec file - * for details. - * - * Note: This module assumes that malloc NEVER returns 0 for reasonable - * requests. It is the users responsibility to either ensure that - * this happens or supply a version of malloc with error - * handling. - * - * Some strings are mutable. - */ - -#ifdef DEBUG -#define assert(x) if (!(x)) abort() -#else -#define assert(x) -#endif - -#include -#include "new_memory.h" - -#include - -#define string_Length(s) strlen(s) -typedef char *string; - -/* - * string string_CreateFromData(char *data, int length): - * Requires: data[0], data[1], ..., data[length-1] != 0 - * Effects: Takes the first length characters at data and - * creates a string containing them. The returned string - * is on the heap & must be freed eventually. - * I.e., if passed "foobar" and 3, it would return - * string_Copy("foo"). - */ - -string string__CreateFromData(data, length) - char *data; - int length; -{ - string result; - - assert(length>=0); - - result = (string)malloc(length+1); - assert(result); - - (void) memcpy(result, data, length); - result[length] = 0; - - return(result); -} - -/* - * string string_Copy(string s): - * Effects: Returns a copy of s on the heap. The copy must be - * freed eventually. - */ - -string string__Copy(s) - string s; -{ - int length; - string result; - - assert(s); - - length = string_Length(s)+1; - result = (string)malloc(length); - assert(result); - - (void) memcpy(result, s, length); - return(result); -} - -/* - * string string_Concat(string a, b): - * Effects: Returns a string equal to a concatenated to b. - * The returned string is on the heap and must be - * freed eventually. I.e., given "abc" and "def", - * returns string_Copy("abcdef"). - */ - -string string__Concat(a, b) - string a, b; -{ - string result; - int a_length, b_size, result_size; - - a_length = string_Length(a); - b_size = string_Length(b)+1; - result_size = a_length+b_size; - result = (string)malloc(result_size); - assert(result); - - (void) memcpy(result, a, a_length); - (void) memcpy(result+a_length, b, b_size); - - return(result); -} - -/* - * string string_Concat2(string a, b): - * Modifies: a - * Requires: a is on the heap, b does not point into a. - * Effects: Equivalent to: - * string temp; - * temp = string_Concat(a,b); - * free(a); - * return(temp); - * only faster. I.e., uses realloc instead of malloc+memcpy. - */ - -string string__Concat2(a, b) - string a, b; -{ - int a_length = string_Length(a); - int b_size = string_Length(b)+1; - -#ifdef DEBUG_MEMORY - assert(memory__on_heap_p(a)); -#endif - - a = (string)realloc(a, a_length+b_size); - assert(a); - (void) memcpy(a+a_length, b, b_size); - - return(a); -} - -/* - * string string_Downcase(string s): - * Modifies: s - * Effects: Modifies s by changing every uppercase character in s - * to the corresponding lowercase character. Nothing else - * is changed. I.e., "FoObAr19." is changed to "foobar19.". - * S is returned as a convenience. - */ - -string string_Downcase(s) - string s; -{ - char *ptr; - - for (ptr=s; *ptr; ptr++) { - if (isupper(*ptr)) - *ptr = tolower(*ptr); - } - - return(s); -} - -/* - * string string_Upcase(string s): - * Modifies: s - * Effects: Modifies s by changing every lowercase character in s - * to the corresponding uppercase character. Nothing else - * is changed. I.e., "FoObAr19." is changed to "FOOBAR19.". - * S is returned as a convenience. - */ - -string string_Upcase(s) - string s; -{ - char *ptr; - - for (ptr=s; *ptr; ptr++) { - if (islower(*ptr)) - *ptr = toupper(*ptr); - } - - return(s); -} diff --git a/zwgc/String/new_string.c.old b/zwgc/String/new_string.c.old deleted file mode 100644 index 5009b06..0000000 --- a/zwgc/String/new_string.c.old +++ /dev/null @@ -1,197 +0,0 @@ -/* This file is part of the Project Athena Zephyr Notification System. - * It is one of the source files comprising zwgc, the Zephyr WindowGram - * client. - * - * Created by: Marc Horowitz - * - * $Source$ - * $Author$ - * - * Copyright (c) 1989 by the Massachusetts Institute of Technology. - * For copying and distribution information, see the file - * "mit-copyright.h". - */ - -#if (!defined(lint) && !defined(SABER)) -static char rcsid_new_string_c[] = "$Id$"; -#endif - -/* - * string - a module providing operations on C strings. (i.e., char *'s) - * - * Overview: - * - * A string is a standard C string. I.e., a char pointer to a - * null-terminated sequence of characters. 0 is NOT considered a valid - * string! Various operations are available. See the string_spec file - * for details. - * - * Note: This module assumes that malloc NEVER returns 0 for reasonable - * requests. It is the users responsibility to either ensure that - * this happens or supply a version of malloc with error - * handling. - * - * Some strings are mutable. - */ - -#ifdef DEBUG -#define assert(x) if (!(x)) abort() -#else -#define assert(x) -#endif - -#include -#include "new_memory.h" - -#include - -#define string_Length(s) strlen(s) -typedef char *string; - -/* - * string string_CreateFromData(char *data, int length): - * Requires: data[0], data[1], ..., data[length-1] != 0 - * Effects: Takes the first length characters at data and - * creates a string containing them. The returned string - * is on the heap & must be freed eventually. - * I.e., if passed "foobar" and 3, it would return - * string_Copy("foo"). - */ - -string string__CreateFromData(data, length) - char *data; - int length; -{ - string result; - - assert(length>=0); - - result = (string)malloc(length+1); - assert(result); - - (void) memcpy(result, data, length); - result[length] = 0; - - return(result); -} - -/* - * string string_Copy(string s): - * Effects: Returns a copy of s on the heap. The copy must be - * freed eventually. - */ - -string string__Copy(s) - string s; -{ - int length; - string result; - - assert(s); - - length = string_Length(s)+1; - result = (string)malloc(length); - assert(result); - - (void) memcpy(result, s, length); - return(result); -} - -/* - * string string_Concat(string a, b): - * Effects: Returns a string equal to a concatenated to b. - * The returned string is on the heap and must be - * freed eventually. I.e., given "abc" and "def", - * returns string_Copy("abcdef"). - */ - -string string__Concat(a, b) - string a, b; -{ - string result; - int a_length, b_size, result_size; - - a_length = string_Length(a); - b_size = string_Length(b)+1; - result_size = a_length+b_size; - result = (string)malloc(result_size); - assert(result); - - (void) memcpy(result, a, a_length); - (void) memcpy(result+a_length, b, b_size); - - return(result); -} - -/* - * string string_Concat2(string a, b): - * Modifies: a - * Requires: a is on the heap, b does not point into a. - * Effects: Equivalent to: - * string temp; - * temp = string_Concat(a,b); - * free(a); - * return(temp); - * only faster. I.e., uses realloc instead of malloc+memcpy. - */ - -string string__Concat2(a, b) - string a, b; -{ - int a_length = string_Length(a); - int b_size = string_Length(b)+1; - -#ifdef DEBUG_MEMORY - assert(memory__on_heap_p(a)); -#endif - - a = (string)realloc(a, a_length+b_size); - assert(a); - (void) memcpy(a+a_length, b, b_size); - - return(a); -} - -/* - * string string_Downcase(string s): - * Modifies: s - * Effects: Modifies s by changing every uppercase character in s - * to the corresponding lowercase character. Nothing else - * is changed. I.e., "FoObAr19." is changed to "foobar19.". - * S is returned as a convenience. - */ - -string string_Downcase(s) - string s; -{ - char *ptr; - - for (ptr=s; *ptr; ptr++) { - if (isupper(*ptr)) - *ptr = tolower(*ptr); - } - - return(s); -} - -/* - * string string_Upcase(string s): - * Modifies: s - * Effects: Modifies s by changing every lowercase character in s - * to the corresponding uppercase character. Nothing else - * is changed. I.e., "FoObAr19." is changed to "FOOBAR19.". - * S is returned as a convenience. - */ - -string string_Upcase(s) - string s; -{ - char *ptr; - - for (ptr=s; *ptr; ptr++) { - if (islower(*ptr)) - *ptr = toupper(*ptr); - } - - return(s); -} diff --git a/zwgc/String/new_string.h b/zwgc/String/new_string.h deleted file mode 100644 index 3b5eae9..0000000 --- a/zwgc/String/new_string.h +++ /dev/null @@ -1,136 +0,0 @@ -/* This file is part of the Project Athena Zephyr Notification System. - * It is one of the source files comprising zwgc, the Zephyr WindowGram - * client. - * - * Created by: Marc Horowitz - * - * $Source$ - * $Author$ - * $Id$ - * - * Copyright (c) 1989 by the Massachusetts Institute of Technology. - * For copying and distribution information, see the file - * "mit-copyright.h". - */ - -#ifndef string_TYPE -#define string_TYPE - -#include -#include "new_memory.h" - -typedef char *string; - -/* - * int string_Length(string s): - * Effects: Returns the number of non-null characters in s. - */ - -#define string_Length(s) strlen(s) - -/* - * int string_Eq(string a, b): - * Effects: Returns true iff strings a & b are equal. I.e., have the - * same character contents. - */ - -#define string_Eq(a,b) (!strcmp(a,b)) - -/* - * int string_Neq(string a, b): - * Effects: Returns true iff strings a & b are not equal. - */ - -#define string_Neq(a,b) (strcmp(a,b)) - -/* - * string string_CreateFromData(char *data, int length): - * Requires: data[0], data[1], ..., data[length-1] != 0 - * Effects: Takes the first length characters at data and - * creates a string containing them. The returned string - * is on the heap & must be freed eventually. - * I.e., if passed "foobar" and 3, it would return - * string_Copy("foo"). - */ - -extern string string__CreateFromData(); -#ifdef DEBUG_MEMORY -#define string_CreateFromData(data,length) (set_module(__FILE__,__LINE__),\ - string__CreateFromData(data,length)) -#else -#define string_CreateFromData(data,length) string__CreateFromData(data,length) -#endif - -/* - * string string_Copy(string s): - * Effects: Returns a copy of s on the heap. The copy must be - * freed eventually. - */ - -extern string string__Copy(/* string s */); -#ifdef DEBUG_MEMORY -#define string_Copy(data) (set_module(__FILE__,__LINE__),\ - string__Copy(data)) -#else -#define string_Copy(data) string__Copy(data) -#endif - -/* - * string string_Concat(string a, b): - * Effects: Returns a string equal to a concatenated to b. - * The returned string is on the heap and must be - * freed eventually. I.e., given "abc" and "def", - * returns string_Copy("abcdef"). - */ - -extern string string__Concat(/* string a, b */); -#ifdef DEBUG_MEMORY -#define string_Concat(a,b) (set_module(__FILE__,__LINE__),\ - string__Concat(a,b)) -#else -#define string_Concat(a,b) string__Concat(a,b) -#endif - -/* - * string string_Concat2(string a, b): - * Modifies: a - * Requires: a is on the heap, b does not point into a. - * Effects: Equivalent to: - * string temp; - * temp = string_Concat(a,b); - * free(a); - * return(temp); - * only faster. I.e., uses realloc instead of malloc+bcopy. - */ - -extern string string__Concat2(/* string a, b */); -#ifdef DEBUG_MEMORY -#define string_Concat2(a,b) (set_module(__FILE__,__LINE__),\ - string__Concat2(a,b)) -#else -#define string_Concat2(a,b) string__Concat2(a,b) -#endif - -/* - * string string_Downcase(string s): - * Modifies: s - * Effects: Modifies s by changing every uppercase character in s - * to the corresponding lowercase character. Nothing else - * is changed. I.e., "FoObAr19." is changed to "foobar19.". - * S is returned as a convenience. - */ - -extern string string_Downcase(); - -/* - * string string_Upcase(string s): - * Modifies: s - * Effects: Modifies s by changing every lowercase character in s - * to the corresponding uppercase character. Nothing else - * is changed. I.e., "FoObAr19." is changed to "FOOBAR19.". - * S is returned as a convenience. - */ - -extern string string_Upcase(); - -#endif diff --git a/zwgc/X_driver.c b/zwgc/X_driver.c index 96aa2c1..ba118b7 100644 --- a/zwgc/X_driver.c +++ b/zwgc/X_driver.c @@ -12,8 +12,10 @@ * "mit-copyright.h". */ +#include + #if (!defined(lint) && !defined(SABER)) -static char rcsid_X_driver_c[] = "$Id$"; +static const char rcsid_X_driver_c[] = "$Id$"; #endif #include @@ -24,7 +26,8 @@ static char rcsid_X_driver_c[] = "$Id$"; /* */ /****************************************************************************/ -#include +#ifndef X_DISPLAY_MISSING + #include "X_driver.h" #include #include "new_memory.h" @@ -34,7 +37,7 @@ static char rcsid_X_driver_c[] = "$Id$"; #include "error.h" #include "X_gram.h" #include "xselect.h" -#include "ulong_dictionary.h" +#include "unsigned_long_dictionary.h" char *app_instance; @@ -50,14 +53,6 @@ Display *dpy = NULL; /* */ /****************************************************************************/ -/* - * - */ - -#ifndef APPDEFDATABASE -#define APPDEFDATABASE "/usr/athena/lib/zephyr/zwgc_resources" -#endif - /* * */ @@ -158,7 +153,7 @@ int get_bool_resource(name, class, default_value) return(result); } -static ulong_dictionary color_dict = NULL; +static unsigned_long_dictionary color_dict = NULL; /* Requires: name points to color name or hex string. name must be free'd * eventually by the caller. @@ -175,14 +170,14 @@ unsigned long x_string_to_color(name,def) char *name; unsigned long def; { - ulong_dictionary_binding *binding; + unsigned_long_dictionary_binding *binding; int exists; XColor xc; if (name == NULL) return(def); - binding = ulong_dictionary_Define(color_dict,name,&exists); + binding = unsigned_long_dictionary_Define(color_dict,name,&exists); if (exists) { return((unsigned long) binding->value); @@ -192,7 +187,7 @@ unsigned long x_string_to_color(name,def) if (XAllocColor(dpy, DefaultColormapOfScreen(DefaultScreenOfDisplay(dpy)), &xc)) { - binding->value = (ulong) xc.pixel; + binding->value = (unsigned long) xc.pixel; return(xc.pixel); } else { ERROR2("Error in XAllocColor on \"%s\": using default color\n", @@ -202,7 +197,7 @@ unsigned long x_string_to_color(name,def) ERROR2("Error in XParseColor on \"%s\": using default color\n", name); } - ulong_dictionary_Delete(color_dict,binding); + unsigned_long_dictionary_Delete(color_dict,binding); return(def); } /*NOTREACHED*/ @@ -248,6 +243,7 @@ int open_display_and_load_resources(pargc, argv) { XrmDatabase temp_db1, temp_db2, temp_db3; char *filename, *res, *xdef; + char dbasename[128]; extern char *getenv(); /* Initialize X resource manager: */ @@ -269,7 +265,8 @@ int open_display_and_load_resources(pargc, argv) return(1); /* Read in our application-specific resources: */ - temp_db1 = XrmGetFileDatabase(APPDEFDATABASE); + sprintf(dbasename, "%s/zwgc_resources", DATADIR); + temp_db1 = XrmGetFileDatabase(dbasename); /* * Get resources from the just opened display: @@ -371,7 +368,7 @@ int X_driver_init(drivername, notfirst, pargc, argv) app_instance=string_Copy(temp?temp+1:argv[0]); - color_dict = ulong_dictionary_Create(37); + color_dict = unsigned_long_dictionary_Create(37); xshowinit(); x_gram_init(dpy); @@ -408,3 +405,6 @@ char *X_driver(text) free_desc(desc); return(NULL); } + +#endif /* X_DISPLAY_MISSING */ + diff --git a/zwgc/X_fonts.c b/zwgc/X_fonts.c index 23b9cc1..51647d8 100644 --- a/zwgc/X_fonts.c +++ b/zwgc/X_fonts.c @@ -12,8 +12,10 @@ * "mit-copyright.h". */ +#include + #if (!defined(lint) && !defined(SABER)) -static char rcsid_X_fonts_c[] = "$Id$"; +static const char rcsid_X_fonts_c[] = "$Id$"; #endif #include @@ -24,7 +26,8 @@ static char rcsid_X_fonts_c[] = "$Id$"; /* */ /****************************************************************************/ -#include +#ifndef X_DISPLAY_MISSING + #include "X_fonts.h" #include "new_memory.h" #include "new_string.h" @@ -297,3 +300,6 @@ XFontStruct *get_font(dpy,style,substyle,size,face) exit(1); #endif } + +#endif /* X_DISPLAY_MISSING */ + diff --git a/zwgc/X_gram.c b/zwgc/X_gram.c index 79586cd..8b8a5af 100644 --- a/zwgc/X_gram.c +++ b/zwgc/X_gram.c @@ -12,17 +12,20 @@ * "mit-copyright.h". */ +#include + #if (!defined(lint) && !defined(SABER)) -static char rcsid_X_gram_c[] = "$Id$"; +static const char rcsid_X_gram_c[] = "$Id$"; #endif #include +#ifndef X_DISPLAY_MISSING + #include "X_gram.h" #include "xmark.h" #include #include -#include #include "zwgc.h" #include "X_driver.h" #include "X_fonts.h" @@ -52,10 +55,6 @@ static int border_width = 1; static int cursor_code = XC_sailboat; static int set_transient; static int enable_delete; -#ifdef SGI_DESKS -static int global_4dwm; -static Atom desks_hints, desks_always_global; -#endif static char *title_name,*icon_name; static Cursor cursor; static Window group_leader; /* In order to have transient windows, @@ -144,18 +143,6 @@ void x_gram_init(dpy) set_transient = get_bool_resource("transient", "Transient", 0); enable_delete = get_bool_resource("enableDelete", "EnableDelete", 1); -#ifdef SGI_DESKS - global_4dwm = get_bool_resource("global", "Global", 1); - - if (global_4dwm) - { - desks_hints = XInternAtom(dpy, "_SGI_DESKS_HINTS", False); - - desks_always_global = XInternAtom(dpy, "_SGI_DESKS_ALWAYS_GLOBAL", - False); - } -#endif - temp = get_string_resource("borderWidth", "BorderWidth"); /* <<<>>> */ if (temp && atoi(temp)>=0) @@ -324,13 +311,7 @@ void x_gram_create(dpy, gram, xalign, yalign, xpos, ypos, xsize, ysize, x_set_icccm_hints(dpy,w,title_name,icon_name,&sizehints,&wmhints,0); } - -#ifdef SGI_DESKS - if (global_4dwm) - (void)XChangeProperty(dpy, w, - desks_hints, XA_ATOM, 32, PropModeAppend, - (char *)&desks_always_global, 1); -#endif + XSaveContext(dpy, w, desc_context, (caddr_t)gram); @@ -501,3 +482,6 @@ void x_gram_expose(dpy,w,gram,event) XDestroyRegion(region); } } + +#endif /* X_DISPLAY_MISSING */ + diff --git a/zwgc/browser.c b/zwgc/browser.c index 5d94644..4fb7dcc 100644 --- a/zwgc/browser.c +++ b/zwgc/browser.c @@ -18,8 +18,7 @@ static char rcsid_browser_c[] = "$Header$"; #include -#include -#include +#include #include #include #include "zwgc.h" diff --git a/zwgc/buffer.c b/zwgc/buffer.c index adf6803..f6d5db3 100644 --- a/zwgc/buffer.c +++ b/zwgc/buffer.c @@ -12,8 +12,10 @@ * "mit-copyright.h". */ +#include + #if (!defined(lint) && !defined(SABER)) -static char rcsid_buffer_c[] = "$Id$"; +static const char rcsid_buffer_c[] = "$Id$"; #endif #include diff --git a/zwgc/character_class.c b/zwgc/character_class.c index 2a3f2c6..3a99286 100644 --- a/zwgc/character_class.c +++ b/zwgc/character_class.c @@ -12,8 +12,10 @@ * "mit-copyright.h". */ +#include + #if (!defined(lint) && !defined(SABER)) -static char rcsid_character_class_c[] = "$Id$"; +static const char rcsid_character_class_c[] = "$Id$"; #endif #include diff --git a/zwgc/dictionary.c b/zwgc/dictionary.c new file mode 100644 index 0000000..6474a82 --- /dev/null +++ b/zwgc/dictionary.c @@ -0,0 +1,263 @@ +/* This file is part of the Project Athena Zephyr Notification System. + * It is one of the source files comprising zwgc, the Zephyr WindowGram + * client. + * + * Created by: Marc Horowitz + * + * $Source$ + * $Author$ + * + * Copyright (c) 1989 by the Massachusetts Institute of Technology. + * For copying and distribution information, see the file + * "mit-copyright.h". + */ + +#include + +#if (!defined(lint) && !defined(SABER)) +static const char rcsid_dictionary_c[] = "$Id$"; +#endif + +/* + * dictionary - a module implementing a generic dictionary. That is, + * any type can be used for the values that keys are bound to. + * Keys are always strings. + * + * Overview: + * + * A dictionary is a set of bindings which bind values of some + * type (this type is the generic parameter of the dictionary) to + * strings. At most one value can be bound to any one string. + * The value that a string is bound to can be changed later. + * Bindings can also be deleted later. It is also possible to + * enumerate all of the bindings in a dictionary. Dictionarys + * are heap based and must be created & destroyed accordingly. + * + * Note: This module assumes that malloc NEVER returns 0 for reasonable + * requests. It is the users responsibility to either ensure that + * this happens or supply a version of malloc with error + * handling. + * + * Dictionarys are mutable. + * + * Implementation: + * + * A standard chaining hash table is used to implement dictionarys. + * Each dictionary has an associated size (# of slots), allowing + * different size dictionaries as needed. + */ + +#include "TYPE_T_dictionary.h" +#include "new_string.h" +#include "new_memory.h" + +#ifndef NULL +#define NULL 0 +#endif + +/* + * TYPE_T_dictionary TYPE_T_dictionary_Create(int size): + * Requires: size > 0 + * Effects: Returns a new empty dictionary containing no bindings. + * The returned dictionary must be destroyed using + * TYPE_T_dictionary_Destroy. Size is a time vs space + * parameter. For this implementation, space used is + * proportional to size and time used is proportional + * to number of bindings divided by size. It is preferable + * that size is a prime number. + */ + +TYPE_T_dictionary TYPE_T_dictionary_Create(size) + int size; +{ + int i; + TYPE_T_dictionary result; + + result = (TYPE_T_dictionary)malloc(sizeof(struct _TYPE_T_dictionary)); + result->size = size; + result->slots = (TYPE_T_dictionary_binding **)malloc( + size*sizeof(TYPE_T_dictionary_binding *)); + + for (i=0; islots[i] = NULL; + + return(result); +} + +/* + * void TYPE_T_dictionary_Destroy(TYPE_T_dictionary d): + * Requires: d is a non-destroyed TYPE_T_dictionary + * Modifies: d + * Effects: Destroys dictionary d freeing up the space it consumes. + * Dictionary d should never be referenced again. Note that + * free is NOT called on the values of the bindings. If + * this is needed, the client must do this first using + * TYPE_T_dictionary_Enumerate. + */ + +void TYPE_T_dictionary_Destroy(d) + TYPE_T_dictionary d; +{ + int i; + TYPE_T_dictionary_binding *binding_ptr, *new_binding_ptr; + + for (i=0; isize; i++) { + binding_ptr = d->slots[i]; + while (binding_ptr) { + new_binding_ptr = binding_ptr->next; + free(binding_ptr->key); + free(binding_ptr); + binding_ptr = new_binding_ptr; + } + } + free(d->slots); + free(d); +} + +/* + * void TYPE_T_dictionary_Enumerate(TYPE_T_dictionary d; void (*proc)()): + * Requires: proc is a void procedure taking 1 argument, a + * TYPE_T_dictionary_binding pointer, which does not + * make any calls using dictionary d. + * Effects: Calls proc once with each binding in dictionary d. + * Order of bindings passed is undefined. Note that + * only the value field of the binding should be considered + * writable by proc. + */ + +void TYPE_T_dictionary_Enumerate(d, proc) + TYPE_T_dictionary d; + void (*proc)(/* TYPE_T_dictionary_binding *b */); +{ + int i; + TYPE_T_dictionary_binding *binding_ptr; + + for (i=0; isize; i++) { + binding_ptr = d->slots[i]; + while (binding_ptr) { + proc(binding_ptr); + binding_ptr = binding_ptr->next; + } + } +} + +/* + * Private routine: + * + * unsigned int dictionary__hash(char *s): + * Effects: Hashs s to an unsigned integer. This number mod the + * hash table size is supposed to roughly evenly distribute + * keys over the table's slots. + */ + +static unsigned int dictionary__hash(s) + char *s; +{ + unsigned int result = 0; + + if (!s) + return(result); + + while (s[0]) { + result <<= 1; + result += s[0]; + s++; + } + + return(result); +} + +/* + * TYPE_T_dictionary_binding *TYPE_T_dictionary_Lookup(TYPE_T_dictionary d, + * char *key): + * Effects: If key is not bound in d, returns 0. Othersize, + * returns a pointer to the binding that binds key. + * Note the access restrictions on bindings... + */ + +TYPE_T_dictionary_binding *TYPE_T_dictionary_Lookup(d, key) + TYPE_T_dictionary d; + char *key; +{ + TYPE_T_dictionary_binding *binding_ptr; + + binding_ptr = d->slots[dictionary__hash(key)%(d->size)]; + while (binding_ptr) { + if (string_Eq(key, binding_ptr->key)) + return(binding_ptr); + binding_ptr = binding_ptr->next; + } + + return(NULL); +} + +/* + * TYPE_T_dictionary_binding *TYPE_T_dictionary_Define(TYPE_T_dictionary d, + * char *key, + * int *already_existed): + * Modifies: d + * Effects: If key is bound in d, returns a pointer to the binding + * that binds key. Otherwise, adds a binding of key to + * d and returns its address. If already_existed is non-zero + * then *already_existed is set to 0 if key was not + * previously bound in d and 1 otherwise. + * Note the access restrictions on bindings... Note also + * that the value that key is bounded to if a binding is + * created is undefined. The caller should set the value + * in this case. + */ + +TYPE_T_dictionary_binding *TYPE_T_dictionary_Define(d, key, already_existed) + TYPE_T_dictionary d; + char *key; + int *already_existed; +{ + TYPE_T_dictionary_binding **ptr_to_the_slot, *binding_ptr; + + ptr_to_the_slot = &(d->slots[dictionary__hash(key)%(d->size)]); + + binding_ptr = *ptr_to_the_slot; + while (binding_ptr) { + if (string_Eq(binding_ptr->key, key)) { + if (already_existed) + *already_existed = 1; + return(binding_ptr); + } + binding_ptr = binding_ptr->next; + } + + if (already_existed) + *already_existed = 0; + binding_ptr = (TYPE_T_dictionary_binding *)malloc( + sizeof(TYPE_T_dictionary_binding)); + binding_ptr->next = *ptr_to_the_slot; + binding_ptr->key = string_Copy(key); + *ptr_to_the_slot = binding_ptr; + return(binding_ptr); +} + +/* + * void TYPE_T_dictionary_Delete(TYPE_T_dictionary d, + * TYPE_T_dictionary_binding *b): + * Requires: *b is a binding in d. + * Modifies: d + * Effects: Removes the binding *b from d. Note that if + * b->value needs to be freed, it should be freed + * before making this call. + */ + +void TYPE_T_dictionary_Delete(d, b) + TYPE_T_dictionary d; + TYPE_T_dictionary_binding *b; +{ + TYPE_T_dictionary_binding **ptr_to_binding_ptr; + + ptr_to_binding_ptr = &(d->slots[dictionary__hash(b->key)%(d->size)]); + + while (*ptr_to_binding_ptr != b) + ptr_to_binding_ptr = &((*ptr_to_binding_ptr)->next); + + *ptr_to_binding_ptr = b->next; + free(b->key); + free(b); +} diff --git a/zwgc/dictionary.h b/zwgc/dictionary.h new file mode 100644 index 0000000..3299825 --- /dev/null +++ b/zwgc/dictionary.h @@ -0,0 +1,111 @@ +/* This file is part of the Project Athena Zephyr Notification System. + * It is one of the source files comprising zwgc, the Zephyr WindowGram + * client. + * + * Created by: Marc Horowitz + * + * $Source$ + * $Author$ + * $Id$ + * + * Copyright (c) 1989 by the Massachusetts Institute of Technology. + * For copying and distribution information, see the file + * "mit-copyright.h". + */ + +#ifndef TYPE_T_dictionary_TYPE +#define TYPE_T_dictionary_TYPE + +typedef struct _TYPE_T_dictionary_binding { + struct _TYPE_T_dictionary_binding *next; /* PRIVATE */ + char *key; /* READ-ONLY */ + TYPE_T value; +} TYPE_T_dictionary_binding; + +typedef struct _TYPE_T_dictionary { /* PRIVATE */ + int size; + TYPE_T_dictionary_binding **slots; +} *TYPE_T_dictionary; + +/* + * TYPE_T_dictionary TYPE_T_dictionary_Create(int size): + * Requires: size > 0 + * Effects: Returns a new empty dictionary containing no bindings. + * The returned dictionary must be destroyed using + * TYPE_T_dictionary_Destroy. Size is a time vs space + * parameter. For this implementation, space used is + * proportional to size and time used is proportional + * to number of bindings divided by size. It is preferable + * that size is a prime number. + */ + +extern TYPE_T_dictionary TYPE_T_dictionary_Create(/* int size */); + +/* + * void TYPE_T_dictionary_Destroy(TYPE_T_dictionary d): + * Requires: d is a non-destroyed TYPE_T_dictionary + * Modifies: d + * Effects: Destroys dictionary d freeing up the space it consumes. + * Dictionary d should never be referenced again. Note that + * free is NOT called on the values of the bindings. If + * this is needed, the client must do this first using + * TYPE_T_dictionary_Enumerate. + */ + +extern void TYPE_T_dictionary_Destroy(/* TYPE_T_dictionary d */); + +/* + * void TYPE_T_dictionary_Enumerate(TYPE_T_dictionary d; void (*proc)()): + * Requires: proc is a void procedure taking 1 argument, a + * TYPE_T_dictionary_binding pointer, which does not + * make any calls using dictionary d. + * Effects: Calls proc once with each binding in dictionary d. + * Order of bindings passed is undefined. Note that + * only the value field of the binding should be considered + * writable by proc. + */ + +extern void TYPE_T_dictionary_Enumerate(/* TYPE_T_dictionary d, + void (*proc)() */); + +/* + * TYPE_T_dictionary_binding *TYPE_T_dictionary_Lookup(TYPE_T_dictionary d, + * char *key): + * Effects: If key is not bound in d, returns 0. Othersize, + * returns a pointer to the binding that binds key. + * Note the access restrictions on bindings... + */ + +extern TYPE_T_dictionary_binding *TYPE_T_dictionary_Lookup(/* d, key */); + +/* + * TYPE_T_dictionary_binding *TYPE_T_dictionary_Define(TYPE_T_dictionary d, + * char *key, + * int *already_existed): + * Modifies: d + * Effects: If key is bound in d, returns a pointer to the binding + * that binds key. Otherwise, adds a binding of key to + * d and returns its address. If already_existed is non-zero + * then *already_existed is set to 0 if key was not + * previously bound in d and 1 otherwise. + * Note the access restrictions on bindings... Note also + * that the value that key is bounded to if a binding is + * created is undefined. The caller should set the value + * in this case. + */ + +extern TYPE_T_dictionary_binding *TYPE_T_dictionary_Define(); + +/* + * void TYPE_T_dictionary_Delete(TYPE_T_dictionary d, + * TYPE_T_dictionary_binding *b): + * Requires: *b is a binding in d. + * Modifies: d + * Effects: Removes the binding *b from d. Note that if + * b->value needs to be freed, it should be freed + * before making this call. + */ + +extern void TYPE_T_dictionary_Delete(); + +#endif diff --git a/zwgc/display.c b/zwgc/display.c index 27ce268..0631326 100644 --- a/zwgc/display.c +++ b/zwgc/display.c @@ -24,7 +24,7 @@ static char rcsid_display_c[] = "$Header$"; /* */ /****************************************************************************/ -#include +#include #include "new_memory.h" #include "new_string.h" #include "variables.h" @@ -34,21 +34,26 @@ static char rcsid_display_c[] = "$Header$"; * driver_table - <<<>>> */ -extern void X_driver(); extern void tty_driver(); extern void plain_driver(); extern void raw_driver(); -extern int X_driver_init(); extern int tty_driver_init(); +#ifndef X_DISPLAY_MISSING +extern int X_driver_init(); +extern void X_driver(); +#endif + static struct driver_info { string driver_name; void (*driver)(); int (*driver_init)(); void (*driver_reset)(); } driver_table[] = { +#ifndef X_DISPLAY_MISSING {"X", X_driver, X_driver_init, X_driver_reset}, +#endif {"tty", tty_driver, tty_driver_init, NULL}, {"plain", plain_driver, NULL, NULL}, {"raw", raw_driver, NULL, NULL}, diff --git a/zwgc/error.c b/zwgc/error.c index f24e97a..2ade086 100644 --- a/zwgc/error.c +++ b/zwgc/error.c @@ -12,8 +12,10 @@ * "mit-copyright.h". */ +#include + #if (!defined(lint) && !defined(SABER)) -static char rcsid_error_c[] = "$Id$"; +static const char rcsid_error_c[] = "$Id$"; #endif #include diff --git a/zwgc/eval.c b/zwgc/eval.c index 650838b..ab59a61 100644 --- a/zwgc/eval.c +++ b/zwgc/eval.c @@ -12,8 +12,10 @@ * "mit-copyright.h". */ +#include + #if (!defined(lint) && !defined(SABER)) -static char rcsid_eval_c[] = "$Id$"; +static const char rcsid_eval_c[] = "$Id$"; #endif #include @@ -139,6 +141,7 @@ string eval_expr(expr) case SUBSTITUTE_OPCODE: case PROTECT_OPCODE: case VERBATIM_OPCODE: + case STYLESTRIP_OPCODE: case GETENV_OPCODE: case UPCASE_OPCODE: case DOWNCASE_OPCODE: @@ -162,6 +165,9 @@ string eval_expr(expr) case VERBATIM_OPCODE: return(verbatim(first,0)); + case STYLESTRIP_OPCODE: + return(stylestrip(first)); + case GETENV_OPCODE: result = getenv(first); if (!result) diff --git a/zwgc/exec.c b/zwgc/exec.c index 27ff1d5..7fac477 100644 --- a/zwgc/exec.c +++ b/zwgc/exec.c @@ -12,8 +12,10 @@ * "mit-copyright.h". */ +#include + #if (!defined(lint) && !defined(SABER)) -static char rcsid_exec_c[] = "$Id$"; +static const char rcsid_exec_c[] = "$Id$"; #endif #include @@ -34,10 +36,6 @@ static char rcsid_exec_c[] = "$Id$"; #include "variables.h" #include "notice.h" -#if !defined(__STDC__) && !defined(const) -#define const -#endif - static int exec_subtree(), exec_fields(); /****************************************************************************/ @@ -371,6 +369,7 @@ static struct _Opstuff { { exec_noop }, /* substitute */ { exec_noop }, /* protect */ { exec_noop }, /* verbatim */ + { exec_noop }, /* stylestrip */ { exec_noop }, /* getenv */ { exec_noop }, /* upcase */ { exec_noop }, /* downcase */ diff --git a/zwgc/file.c b/zwgc/file.c index 2f048dd..39067cf 100644 --- a/zwgc/file.c +++ b/zwgc/file.c @@ -12,15 +12,14 @@ * "mit-copyright.h". */ +#include + #if (!defined(lint) && !defined(SABER)) -static char rcsid_file_c[] = "$Id$"; +static const char rcsid_file_c[] = "$Id$"; #endif #include -#include -#include -#include #include #include "new_memory.h" #include "new_string.h" diff --git a/zwgc/formatter.c b/zwgc/formatter.c index 03ee3d0..c74bc7d 100644 --- a/zwgc/formatter.c +++ b/zwgc/formatter.c @@ -12,16 +12,15 @@ * "mit-copyright.h". */ +#include + #if (!defined(lint) && !defined(SABER)) -static char rcsid_formatter_c[] = "$Id$"; +static const char rcsid_formatter_c[] = "$Id$"; #endif #include #include -#include -#include -#include #include "new_memory.h" #include "char_stack.h" #include "string_dictionary.h" @@ -375,6 +374,51 @@ string protect(str) return(temp); } +/* str points to a string. return value is another string + which is the original with all styles removed. */ +string stylestrip(str) + string str; +{ + int templen = 0, otherchar; + char *temp = (char *) malloc(string_Length(str) + 1); + char_stack chs; + string ostr = str; + + chs = char_stack_create(); + + while (*str) { + if (*str == '@') { + int len = env_length(str + 1); + if (len != -1) { + otherchar = 0; + if ((len == 4 && !strncasecmp(str + 1, "font", 4)) + || (len == 5 && !strncasecmp(str + 1, "color", 5))) + otherchar = 0x80; + otherchar |= otherside(str[len + 1]); + char_stack_push(chs, otherchar); + str += len + 2; + continue; + } + } + if (!char_stack_empty(chs) && *str == (char_stack_top(chs) & 0x7f)) { + char_stack_pop(chs); + str++; + continue; + } + if (!char_stack_empty(chs) && (char_stack_top(chs) & 0x80)) + str++; + else + temp[templen++] = *str++; + } + temp[templen] = 0; + + while (!char_stack_empty(chs)) + char_stack_pop(chs); + free(ostr); + + return(temp); +} + void free_desc(desc) desctype *desc; { diff --git a/zwgc/generate_instance b/zwgc/generate_instance deleted file mode 100755 index 0a42621..0000000 --- a/zwgc/generate_instance +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/sh - - -# This file is part of the Project Athena Zephyr Notification System. -# It is one of the source files comprising zwgc, the Zephyr WindowGram -# client. -# -# $Id$ -# -# Copyright (c) 1989,1993 by the Massachusetts Institute of Technology. -# For copying and distribution information, see the file -# "mit-copyright.h". -# - -if [ "$1" = "" ]; then - echo "Usage: generate_instance []" - exit 1 -fi - -source=$1 -type=$2 -name=$3 -incfile=$4 - -if [ ! -f ${source}/${type}.h ]; then - echo "$0: unable to open ${source}/${type}.h" - exit 2 -fi - -case $type in -dictionary) - if [ ! -f ${source}/${type}.c ]; then - echo "$0: unable to open ${source}/${type}.c" - exit 2 - fi - sed "s/TYPE_T/$name/g" ${source}/${type}.c > ${name}_${type}.c - ;; -esac - -if [ "$incfile" != "" ]; then - echo "#include \"$incfile\"" > ${name}_${type}.h -fi -sed "s/TYPE_T/$name/g" ${source}/${type}.h >> ${name}_${type}.h diff --git a/zwgc/instantiate b/zwgc/instantiate new file mode 100755 index 0000000..dae134d --- /dev/null +++ b/zwgc/instantiate @@ -0,0 +1,39 @@ +#!/bin/sh - + +# This file is part of the Project Athena Zephyr Notification System. +# It is one of the source files comprising zwgc, the Zephyr WindowGram +# client. +# +# $Id$ +# +# Copyright (c) 1989,1993 by the Massachusetts Institute of Technology. +# For copying and distribution information, see the file +# "mit-copyright.h". +# + +if [ "$1" = "" ]; then + echo "Usage: generate_instance []" + exit 1 +fi + +source=$1 +type=$2 +name=$3 +incfile=$4 + +if [ "$type" != "stack" ]; then + if [ ! -f ${source}/${type}.c ]; then + echo "$0: unable to open ${source}/${type}.c" + exit 2 + fi + sed "s/TYPE_T/$name/g" ${source}/${type}.c > ${name}_${type}.c +fi + +if [ "$incfile" != "" ]; then + echo "#include \"$incfile\"" > ${name}_${type}.h +fi +if [ ! -f ${source}/${type}.h ]; then + echo "$0: unable to open ${source}/${type}.h" + exit 2 +fi +sed "s/TYPE_T/$name/g" ${source}/${type}.h >> ${name}_${type}.h diff --git a/zwgc/lexer.c b/zwgc/lexer.c index 5ee3f81..23276e9 100644 --- a/zwgc/lexer.c +++ b/zwgc/lexer.c @@ -12,8 +12,10 @@ * "mit-copyright.h". */ +#include + #if (!defined(lint) && !defined(SABER)) -static char rcsid_lexer_c[] = "$Id$"; +static const char rcsid_lexer_c[] = "$Id$"; #endif #include @@ -24,7 +26,6 @@ static char rcsid_lexer_c[] = "$Id$"; /* */ /****************************************************************************/ -#include #include "new_memory.h" #include "new_string.h" #include "int_dictionary.h" @@ -158,6 +159,7 @@ static struct keyword_info keywords[] = { { "rspan", RSPAN }, { "set", SET }, { "show", SHOW }, + { "stylestrip", STYLESTRIP }, { "substitute", SUBSTITUTE }, { "then", THEN }, { "upcase", UPCASE }, diff --git a/zwgc/main.c b/zwgc/main.c index 52be870..1b842cb 100644 --- a/zwgc/main.c +++ b/zwgc/main.c @@ -12,15 +12,16 @@ * "mit-copyright.h". */ +#include + #if (!defined(lint) && !defined(SABER)) -static char rcsid_main_c[] = "$Id$"; +static const char rcsid_main_c[] = "$Id$"; #endif +#include #include #include -#include -#include #include "new_memory.h" #include "zwgc.h" #include "parser.h" @@ -36,7 +37,7 @@ static char rcsid_main_c[] = "$Id$"; #include "main.h" extern void notice_handler(); -static void setup_signals(), detach(); +static void setup_signals(), detach(), signal_exit(); /* * Global zwgc-wide variables: @@ -46,7 +47,7 @@ static void setup_signals(), detach(); int zwgc_debug = 0; #endif -static char *zwgc_version_string = "0.4.7"; +static char *zwgc_version_string = "1.0"; /* * description_filename_override - <<<>>> @@ -54,6 +55,12 @@ static char *zwgc_version_string = "0.4.7"; static char *description_filename_override = NULL; +/* + * progname - <<<>>> export! + */ + +char *progname = NULL; + /* * subscriptions_filename_override - <<<>>> export! */ @@ -109,10 +116,12 @@ static void fake_startup_packet() static void read_in_description_file() { FILE *input_file; + char defdesc[128]; /* var_clear_all_variables(); <<<>>> */ - input_file = locate_file(description_filename_override, USRDESC, DEFDESC); + sprintf(defdesc, "%s/%s", DATADIR, DEFDESC); + input_file = locate_file(description_filename_override, USRDESC, defdesc); if (input_file) program = parse_file(input_file); else @@ -192,6 +201,8 @@ int main(argc, argv) register char **current; int dofork = 1; + progname = argv[0]; + /* * Process "-f ", "-subfile ", "-nofork", * "-reenter" (which is ignored) and (if DEBUG) "-debug" @@ -309,6 +320,8 @@ void notice_handler(notice) free(class); free(instance); free(recipient); + } else if (!strcasecmp(control_opcode, USER_EXIT)) { + signal_exit(); } else printf("zwgc: unknown control opcode %s.\n", control_opcode); @@ -347,15 +360,11 @@ static void signal_exit() mux_end_loop_p = 1; } -#include -#include -#include - /* clean up ALL the waiting children, in case we get hit with multiple SIGCHLD's at once, and don't process in time. */ -static void signal_child() +static RETSIGTYPE signal_child() { -#ifdef POSIX +#ifdef HAVE_WAITPID int status; #else union wait status; @@ -364,7 +373,7 @@ static void signal_child() int pid, old_errno = errno; do { -#ifdef POSIX +#ifdef HAVE_WAITPID pid = waitpid(-1, &status, WNOHANG); #else pid = wait3(&status, WNOHANG, (struct rusage *)0); @@ -376,7 +385,7 @@ static void signal_child() static void setup_signals(dofork) int dofork; { -#ifdef POSIX +#ifdef _POSIX_VERSION struct sigaction sa; sigemptyset(&sa.sa_mask); @@ -433,7 +442,7 @@ static void detach() register int i; /* to try to get SIGHUP on user logout */ -#if defined(POSIX) && !defined(ultrix) +#if defined(_POSIX_VERSION) && !defined(ultrix) (void) setpgid(0, tcgetpgrp(1)); #else (void) setpgrp(0, getpgrp(getppid())); diff --git a/zwgc/main.h b/zwgc/main.h index 73b49eb..0af201e 100644 --- a/zwgc/main.h +++ b/zwgc/main.h @@ -19,6 +19,7 @@ #ifndef main_MODULE #define main_MODULE +extern char *progname; extern char *subscriptions_filename_override; /* @@ -34,10 +35,11 @@ extern void usage(); #define USRDESC ".zwgc.desc" -/* DEFDESC points to where the system default description is stored */ +/* DEFDESC points to a file (relative to the data directory) which has the + * system default description file */ #ifndef DEFDESC -#define DEFDESC "/usr/athena/lib/zephyr/zwgc.desc" +#define DEFDESC "zwgc.desc" #endif #endif diff --git a/zwgc/mux.c b/zwgc/mux.c index a682267..221ae8b 100644 --- a/zwgc/mux.c +++ b/zwgc/mux.c @@ -12,8 +12,10 @@ * "mit-copyright.h". */ +#include + #if (!defined(lint) && !defined(SABER)) -static char rcsid_mux_c[] = "$Id$"; +static const char rcsid_mux_c[] = "$Id$"; #endif /****************************************************************************/ @@ -22,12 +24,6 @@ static char rcsid_mux_c[] = "$Id$"; /* */ /****************************************************************************/ -#include -#include -#include -#include -#include -#include #include #include "mux.h" #include "error.h" @@ -201,7 +197,7 @@ static int check_tty() if (tty < 0) return 0; -#if defined(POSIX) || defined(SUNOS) +#if defined(_POSIX_VERSION) result = ( ((pgrp = tcgetpgrp(tty)) < 0) ? 0 : 1 ); #else result = ( (ioctl(tty, TIOCGPGRP, &pgrp) < 0) ? 0 : 1 ); diff --git a/zwgc/new_memory.c b/zwgc/new_memory.c new file mode 100644 index 0000000..541712a --- /dev/null +++ b/zwgc/new_memory.c @@ -0,0 +1,244 @@ +/* This file is part of the Project Athena Zephyr Notification System. + * It is one of the source files comprising zwgc, the Zephyr WindowGram + * client. + * + * Created by: Marc Horowitz + * + * $Source$ + * $Author$ + * + * Copyright (c) 1989 by the Massachusetts Institute of Technology. + * For copying and distribution information, see the file + * "mit-copyright.h". + */ + +#include + +#if (!defined(lint) && !defined(SABER)) +static const char rcsid_new_memory_c[] = "$Id$"; +#endif + +#if !defined(SABER) && (defined(DEBUG) || defined(MEMORY_DEBUG)) + +/* + * memory - module wrapping debugging code around normal malloc/free/etc. + * routines. + * + * Overview: + * + * ... + */ + +#define memory__PROVIDER +#include "new_memory.h" + +/* + * + */ +#ifdef DEBUG +#define assert(x) if (!(x)) abort() +#else +#define assert(x) +#endif + +/* + * + */ +#ifdef DEBUG_MEMORY + +extern void record_request(); +char *current_module = 0; +int current_line = -1; + +#endif + +/* + * string string_CreateFromData(char *data, int length): + * Requires: data[0], data[1], ..., data[length-1] != 0 + * Effects: Takes the first length characters at data and + * creates a string containing them. The returned string + * is on the heap & must be freed eventually. + * I.e., if passed "foobar" and 3, it would return + * string_Copy("foo"). + */ + +char *memory__malloc(size) + unsigned size; +{ + char *result; + + result = malloc(size + memory__size_of_header); + if (!result) + abort(); /* <<<>>> */ + +#ifdef DEBUG_MEMORY + ((memory_block_header *)result)->size = size; + ((memory_block_header *)result)->creating_module = current_module; + ((memory_block_header *)result)->line_number_in_creating_module = + current_line; + ((memory_block_header *)result)->check_field = CHECK_FIELD_VALUE; + result += memory__size_of_header; + + record_request(current_module, current_line, 1, size); +#endif + + return(result); +} + +char *memory__realloc(ptr, size) + char *ptr; + unsigned size; +{ + char *result; + + assert(ptr); + +#ifdef DEBUG_MEMORY + if (!memory__on_heap_p(ptr)) { + printf("realloced non-memory block in %s on line %d!\n", + current_module, current_line); + fflush(stdout); + return(realloc(ptr, size)); + } +#endif + + result = realloc(ptr-memory__size_of_header, size+memory__size_of_header); + if (!result) + abort(); /* <<<>>> */ + + return(result+memory__size_of_header); +} + +char *memory__calloc(nelem, elsize) + unsigned nelem; + unsigned elsize; +{ + char *result; + +#ifdef DEBUG_MEMORY + printf("in calloc\n"); fflush(stdout); +#endif + + abort(); + +#ifdef FRED + result = calloc(nelem, elsize); + if (!result) + abort(); + + record_request(1); +#endif + + return(result); +} + +void memory__free(ptr) + char *ptr; +{ + assert(ptr); + +#ifdef DEBUG_MEMORY + if (!memory__on_heap_p(ptr)) { + printf("freed non-memory block in %s on line %d!\n", current_module, + current_line); + fflush(stdout); + (void)free(ptr); + return; + } + + record_request(memory__get_header(ptr)->creating_module, + memory__get_header(ptr)->line_number_in_creating_module, + -1, + memory__get_header(ptr)->size); +#endif + + (void)free(ptr-memory__size_of_header); +} + +#ifdef DEBUG_MEMORY + +#include "int_dictionary.h" + +static int request_off = 0; +static int_dictionary requests = 0; +static int outstanding_requests = 0; +static int outstanding_memory = 0; + +void record_request(module, line_number, dir, size) + char *module; + int line_number; + int dir; + unsigned int size; +{ + int_dictionary_binding *binding; + int already_exists; +#ifdef LINE + char buffer[20]; +#endif + + if (request_off) + return; + request_off = 1; + + if (!requests) + requests = int_dictionary_Create(101); + +#ifdef LINE + module = string_Concat(module, ":"); + sprintf(buffer, "%d", line_number); + module = string_Concat2(module, buffer); +#endif + + binding = int_dictionary_Define(requests, module, &already_exists); + if (!already_exists) + binding->value = 0; + +#ifdef LINE + free(module); +#endif + + binding->value += dir; + outstanding_requests += dir; + outstanding_memory += size*dir; + + request_off = 0; +} + +void proc(binding) + int_dictionary_binding *binding; +{ + if (binding->value) + printf(" %-30s %6d blocks allocated\n", binding->key, binding->value); +} + +void report_memory_usage() +{ + printf("\n# of blocks on the heap = %d\n", outstanding_requests); + printf("Total heap space in use: %d bytes\n", outstanding_memory); + + printf("\nHeap Allocations by module:\n"); + int_dictionary_Enumerate(requests, proc); + printf("\n"); + + fflush(stdout); +} + +void set_module(file, line) + char *file; + int line; +{ + if (request_off) + return; + + if (!strcmp(file, "new_string.c")) + return; + if (!strcmp(file, "string_dictionary_aux.c")) + return; + + current_line = line; + current_module = file; +} + +#endif + +#endif /* SABER */ diff --git a/zwgc/new_memory.h b/zwgc/new_memory.h new file mode 100644 index 0000000..5c213b7 --- /dev/null +++ b/zwgc/new_memory.h @@ -0,0 +1,86 @@ +/* This file is part of the Project Athena Zephyr Notification System. + * It is one of the source files comprising zwgc, the Zephyr WindowGram + * client. + * + * Created by: Marc Horowitz + * + * $Source$ + * $Author$ + * $Id$ + * + * Copyright (c) 1989 by the Massachusetts Institute of Technology. + * For copying and distribution information, see the file + * "mit-copyright.h". + */ + +/* This entire module goes out the window in saber */ +#if !defined(SABER) && (defined(DEBUG) || defined(DEBUG_MEMORY)) + +#ifndef memory_MODULE +#define memory_MODULE + +extern char *memory__malloc(); /* PRIVATE */ +extern char *memory__realloc(); /* PRIVATE */ +extern char *memory__calloc(); /* PRIVATE */ +extern void memory__free(); /* PRIVATE */ + +#ifdef DEBUG_MEMORY + +#define CHECK_FIELD_VALUE 0xe5e7e3e9 + +typedef struct _memory_block_header { + unsigned size; + char *creating_module; + int line_number_in_creating_module; + unsigned int check_field; +} memory_block_header; + +#define memory__size_of_header (sizeof(struct _memory_block_header)) + +#define memory__get_header(block) \ + ((struct _memory_block_header *)((block)-memory__size_of_header)) + +#define memory__on_heap_p(block) \ + (memory__get_header(block)->check_field==CHECK_FIELD_VALUE) + +#else + +#define memory__size_of_header 0 + +#define memory__on_heap_p(block) 1 + +#endif + +/* + * int string_Length(string s): + * Effects: Returns the number of non-null characters in s. + */ + +#ifndef memory__PROVIDER +#ifdef DEBUG_MEMORY + +extern char *current_module; +extern void set_module(); + +#define malloc(size) (set_module(__FILE__,__LINE__),\ + memory__malloc(size)) +#define realloc(ptr, size) (set_module(__FILE__,__LINE__),\ + memory__realloc((char *) ptr, size)) +#define calloc(nelem, elsize) (set_module(__FILE__,__LINE__),\ + memory__calloc(nelem, elsize)) +#define free(ptr) (set_module(__FILE__,__LINE__),\ + memory__free((char *) ptr)) +#else + +#define malloc(size) memory__malloc(size) +#define realloc(ptr, size) memory__realloc((char *) ptr, size) +#define calloc(nelem, elsize) memory__calloc(nelem, elsize) +#define free(ptr) memory__free((char *) ptr) + +#endif /* DEBUG_MEMORY */ + +#endif /* memory__PROVIDER */ + +#endif /* memory_MODULE */ + +#endif /* SABER */ diff --git a/zwgc/new_string.c b/zwgc/new_string.c new file mode 100644 index 0000000..6c3896b --- /dev/null +++ b/zwgc/new_string.c @@ -0,0 +1,196 @@ +/* This file is part of the Project Athena Zephyr Notification System. + * It is one of the source files comprising zwgc, the Zephyr WindowGram + * client. + * + * Created by: Marc Horowitz + * + * $Source$ + * $Author$ + * + * Copyright (c) 1989 by the Massachusetts Institute of Technology. + * For copying and distribution information, see the file + * "mit-copyright.h". + */ + +#include + +#if (!defined(lint) && !defined(SABER)) +static const char rcsid_new_string_c[] = "$Id$"; +#endif + +/* + * string - a module providing operations on C strings. (i.e., char *'s) + * + * Overview: + * + * A string is a standard C string. I.e., a char pointer to a + * null-terminated sequence of characters. 0 is NOT considered a valid + * string! Various operations are available. See the string_spec file + * for details. + * + * Note: This module assumes that malloc NEVER returns 0 for reasonable + * requests. It is the users responsibility to either ensure that + * this happens or supply a version of malloc with error + * handling. + * + * Some strings are mutable. + */ + +#ifdef DEBUG +#define assert(x) if (!(x)) abort() +#else +#define assert(x) +#endif + +#include "new_memory.h" + +#define string_Length(s) strlen(s) +typedef char *string; + +/* + * string string_CreateFromData(char *data, int length): + * Requires: data[0], data[1], ..., data[length-1] != 0 + * Effects: Takes the first length characters at data and + * creates a string containing them. The returned string + * is on the heap & must be freed eventually. + * I.e., if passed "foobar" and 3, it would return + * string_Copy("foo"). + */ + +string string__CreateFromData(data, length) + char *data; + int length; +{ + string result; + + assert(length>=0); + + result = (string)malloc(length+1); + assert(result); + + (void) memcpy(result, data, length); + result[length] = 0; + + return(result); +} + +/* + * string string_Copy(string s): + * Effects: Returns a copy of s on the heap. The copy must be + * freed eventually. + */ + +string string__Copy(s) + string s; +{ + int length; + string result; + + assert(s); + + length = string_Length(s)+1; + result = (string)malloc(length); + assert(result); + + (void) memcpy(result, s, length); + return(result); +} + +/* + * string string_Concat(string a, b): + * Effects: Returns a string equal to a concatenated to b. + * The returned string is on the heap and must be + * freed eventually. I.e., given "abc" and "def", + * returns string_Copy("abcdef"). + */ + +string string__Concat(a, b) + string a, b; +{ + string result; + int a_length, b_size, result_size; + + a_length = string_Length(a); + b_size = string_Length(b)+1; + result_size = a_length+b_size; + result = (string)malloc(result_size); + assert(result); + + (void) memcpy(result, a, a_length); + (void) memcpy(result+a_length, b, b_size); + + return(result); +} + +/* + * string string_Concat2(string a, b): + * Modifies: a + * Requires: a is on the heap, b does not point into a. + * Effects: Equivalent to: + * string temp; + * temp = string_Concat(a,b); + * free(a); + * return(temp); + * only faster. I.e., uses realloc instead of malloc+memcpy. + */ + +string string__Concat2(a, b) + string a, b; +{ + int a_length = string_Length(a); + int b_size = string_Length(b)+1; + +#ifdef DEBUG_MEMORY + assert(memory__on_heap_p(a)); +#endif + + a = (string)realloc(a, a_length+b_size); + assert(a); + (void) memcpy(a+a_length, b, b_size); + + return(a); +} + +/* + * string string_Downcase(string s): + * Modifies: s + * Effects: Modifies s by changing every uppercase character in s + * to the corresponding lowercase character. Nothing else + * is changed. I.e., "FoObAr19." is changed to "foobar19.". + * S is returned as a convenience. + */ + +string string_Downcase(s) + string s; +{ + char *ptr; + + for (ptr=s; *ptr; ptr++) { + if (isupper(*ptr)) + *ptr = tolower(*ptr); + } + + return(s); +} + +/* + * string string_Upcase(string s): + * Modifies: s + * Effects: Modifies s by changing every lowercase character in s + * to the corresponding uppercase character. Nothing else + * is changed. I.e., "FoObAr19." is changed to "FOOBAR19.". + * S is returned as a convenience. + */ + +string string_Upcase(s) + string s; +{ + char *ptr; + + for (ptr=s; *ptr; ptr++) { + if (islower(*ptr)) + *ptr = toupper(*ptr); + } + + return(s); +} diff --git a/zwgc/new_string.h b/zwgc/new_string.h new file mode 100644 index 0000000..3b5eae9 --- /dev/null +++ b/zwgc/new_string.h @@ -0,0 +1,136 @@ +/* This file is part of the Project Athena Zephyr Notification System. + * It is one of the source files comprising zwgc, the Zephyr WindowGram + * client. + * + * Created by: Marc Horowitz + * + * $Source$ + * $Author$ + * $Id$ + * + * Copyright (c) 1989 by the Massachusetts Institute of Technology. + * For copying and distribution information, see the file + * "mit-copyright.h". + */ + +#ifndef string_TYPE +#define string_TYPE + +#include +#include "new_memory.h" + +typedef char *string; + +/* + * int string_Length(string s): + * Effects: Returns the number of non-null characters in s. + */ + +#define string_Length(s) strlen(s) + +/* + * int string_Eq(string a, b): + * Effects: Returns true iff strings a & b are equal. I.e., have the + * same character contents. + */ + +#define string_Eq(a,b) (!strcmp(a,b)) + +/* + * int string_Neq(string a, b): + * Effects: Returns true iff strings a & b are not equal. + */ + +#define string_Neq(a,b) (strcmp(a,b)) + +/* + * string string_CreateFromData(char *data, int length): + * Requires: data[0], data[1], ..., data[length-1] != 0 + * Effects: Takes the first length characters at data and + * creates a string containing them. The returned string + * is on the heap & must be freed eventually. + * I.e., if passed "foobar" and 3, it would return + * string_Copy("foo"). + */ + +extern string string__CreateFromData(); +#ifdef DEBUG_MEMORY +#define string_CreateFromData(data,length) (set_module(__FILE__,__LINE__),\ + string__CreateFromData(data,length)) +#else +#define string_CreateFromData(data,length) string__CreateFromData(data,length) +#endif + +/* + * string string_Copy(string s): + * Effects: Returns a copy of s on the heap. The copy must be + * freed eventually. + */ + +extern string string__Copy(/* string s */); +#ifdef DEBUG_MEMORY +#define string_Copy(data) (set_module(__FILE__,__LINE__),\ + string__Copy(data)) +#else +#define string_Copy(data) string__Copy(data) +#endif + +/* + * string string_Concat(string a, b): + * Effects: Returns a string equal to a concatenated to b. + * The returned string is on the heap and must be + * freed eventually. I.e., given "abc" and "def", + * returns string_Copy("abcdef"). + */ + +extern string string__Concat(/* string a, b */); +#ifdef DEBUG_MEMORY +#define string_Concat(a,b) (set_module(__FILE__,__LINE__),\ + string__Concat(a,b)) +#else +#define string_Concat(a,b) string__Concat(a,b) +#endif + +/* + * string string_Concat2(string a, b): + * Modifies: a + * Requires: a is on the heap, b does not point into a. + * Effects: Equivalent to: + * string temp; + * temp = string_Concat(a,b); + * free(a); + * return(temp); + * only faster. I.e., uses realloc instead of malloc+bcopy. + */ + +extern string string__Concat2(/* string a, b */); +#ifdef DEBUG_MEMORY +#define string_Concat2(a,b) (set_module(__FILE__,__LINE__),\ + string__Concat2(a,b)) +#else +#define string_Concat2(a,b) string__Concat2(a,b) +#endif + +/* + * string string_Downcase(string s): + * Modifies: s + * Effects: Modifies s by changing every uppercase character in s + * to the corresponding lowercase character. Nothing else + * is changed. I.e., "FoObAr19." is changed to "foobar19.". + * S is returned as a convenience. + */ + +extern string string_Downcase(); + +/* + * string string_Upcase(string s): + * Modifies: s + * Effects: Modifies s by changing every lowercase character in s + * to the corresponding uppercase character. Nothing else + * is changed. I.e., "FoObAr19." is changed to "FOOBAR19.". + * S is returned as a convenience. + */ + +extern string string_Upcase(); + +#endif diff --git a/zwgc/node.c b/zwgc/node.c index ede0187..b44aacf 100644 --- a/zwgc/node.c +++ b/zwgc/node.c @@ -12,13 +12,14 @@ * "mit-copyright.h". */ +#include + #if (!defined(lint) && !defined(SABER)) -static char rcsid_node_c[] = "$Id$"; +static const char rcsid_node_c[] = "$Id$"; #endif #include -#include #include "new_memory.h" #include "node.h" @@ -267,6 +268,7 @@ static string how_to_print[] = { "substitute(%1)", "protect(%1)", "verbatim(%1)", + "stylestrip(%1)", "getenv(%1)", "upcase(%1)", "downcase(%1)", diff --git a/zwgc/node.h b/zwgc/node.h index 35ac013..c98433d 100644 --- a/zwgc/node.h +++ b/zwgc/node.h @@ -40,52 +40,53 @@ #define SUBSTITUTE_OPCODE 12 #define PROTECT_OPCODE 13 #define VERBATIM_OPCODE 14 -#define GETENV_OPCODE 15 -#define UPCASE_OPCODE 16 -#define DOWNCASE_OPCODE 17 -#define ZVAR_OPCODE 18 -#define GET_OPCODE 19 - -#define LANY_OPCODE 20 -#define RANY_OPCODE 21 -#define LBREAK_OPCODE 22 -#define RBREAK_OPCODE 23 -#define LSPAN_OPCODE 24 -#define RSPAN_OPCODE 25 - -#define LAST_EXPR_OPCODE 25 - -#define NOOP_OPCODE 26 -#define SET_OPCODE 27 -#define FIELDS_OPCODE 28 - -#define PRINT_OPCODE 29 -#define CLEARBUF_OPCODE 30 - -#define APPENDPORT_OPCODE 31 -#define EXECPORT_OPCODE 32 -#define INPUTPORT_OPCODE 33 -#define OUTPUTPORT_OPCODE 34 -#define PUT_OPCODE 35 -#define CLOSEINPUT_OPCODE 36 -#define CLOSEOUTPUT_OPCODE 37 -#define CLOSEPORT_OPCODE 38 - -#define EXEC_OPCODE 39 - -#define IF_STMT_OPCODE 40 -#define CASE_OPCODE 41 -#define WHILE_OPCODE 42 -#define BREAK_OPCODE 43 -#define EXIT_OPCODE 44 - -#define IF_OPCODE 45 -#define ELSEIF_OPCODE 46 -#define ELSE_OPCODE 47 -#define MATCHLIST_OPCODE 48 -#define DEFAULT_OPCODE 49 - -#define NUMBER_OF_OPCODES 50 +#define STYLESTRIP_OPCODE 15 +#define GETENV_OPCODE 16 +#define UPCASE_OPCODE 17 +#define DOWNCASE_OPCODE 18 +#define ZVAR_OPCODE 19 +#define GET_OPCODE 20 + +#define LANY_OPCODE 21 +#define RANY_OPCODE 22 +#define LBREAK_OPCODE 23 +#define RBREAK_OPCODE 24 +#define LSPAN_OPCODE 25 +#define RSPAN_OPCODE 26 + +#define LAST_EXPR_OPCODE 26 + +#define NOOP_OPCODE 27 +#define SET_OPCODE 28 +#define FIELDS_OPCODE 29 + +#define PRINT_OPCODE 30 +#define CLEARBUF_OPCODE 31 + +#define APPENDPORT_OPCODE 32 +#define EXECPORT_OPCODE 33 +#define INPUTPORT_OPCODE 34 +#define OUTPUTPORT_OPCODE 35 +#define PUT_OPCODE 36 +#define CLOSEINPUT_OPCODE 37 +#define CLOSEOUTPUT_OPCODE 38 +#define CLOSEPORT_OPCODE 39 + +#define EXEC_OPCODE 40 + +#define IF_STMT_OPCODE 41 +#define CASE_OPCODE 42 +#define WHILE_OPCODE 43 +#define BREAK_OPCODE 44 +#define EXIT_OPCODE 45 + +#define IF_OPCODE 46 +#define ELSEIF_OPCODE 47 +#define ELSE_OPCODE 48 +#define MATCHLIST_OPCODE 49 +#define DEFAULT_OPCODE 50 + +#define NUMBER_OF_OPCODES 51 typedef struct _Node { int opcode; /* Read-only */ diff --git a/zwgc/notice.c b/zwgc/notice.c index 543f272..4e14946 100644 --- a/zwgc/notice.c +++ b/zwgc/notice.c @@ -12,8 +12,10 @@ * "mit-copyright.h". */ +#include + #if (!defined(lint) && !defined(SABER)) -static char rcsid_notice_c[] = "$Id$"; +static const char rcsid_notice_c[] = "$Id$"; #endif #include @@ -308,7 +310,7 @@ char *decode_notice(notice) * Convert host notice sent from to ascii: */ if (notice->z_sender_addr.s_addr) { - fromhost = gethostbyaddr(&(notice->z_sender_addr), + fromhost = gethostbyaddr((char *) &(notice->z_sender_addr), sizeof(struct in_addr), AF_INET); var_set_variable("fromhost", fromhost ? fromhost->h_name : inet_ntoa(notice->z_sender_addr)); diff --git a/zwgc/parser.y b/zwgc/parser.y index 31d21db..22b8a47 100644 --- a/zwgc/parser.y +++ b/zwgc/parser.y @@ -13,8 +13,10 @@ * "mit-copyright.h". */ +#include + #if (!defined(lint) && !defined(SABER)) -static char rcsid_parser_y[] = "$Id$"; +static const char rcsid_parser_y[] = "$Id$"; #endif #include @@ -56,7 +58,7 @@ static Node *the_program; %token ELSE ELSEIF ENDCASE ENDIF ENDWHILE EXEC EXECPORT EXIT %token FIELDS GET GETENV IF INPUTPORT LANY LBREAK LSPAN %token MATCH NOOP NOT OUTPUTPORT PRINT PROTECT VERBATIM PUT RANY RBREAK -%token RSPAN SET SHOW SUBSTITUTE THEN UPCASE WHILE ZVAR +%token RSPAN SET SUBSTITUTE THEN UPCASE WHILE ZVAR STYLESTRIP %type expr varname string %type exprlist comma_exprlist varnamelist @@ -132,6 +134,8 @@ expr : '(' expr ')' { $$ = node_create_unary(ZVAR_OPCODE, $3); } | GET '(' expr ')' { $$ = node_create_unary(GET_OPCODE, $3); } + | STYLESTRIP '(' expr ')' + { $$ = node_create_unary(STYLESTRIP_OPCODE, $3); } | LANY '(' expr ',' expr ')' { $$ = node_create_binary(LANY_OPCODE, $3, $5 ); } diff --git a/zwgc/port.c b/zwgc/port.c index c30bfad..6ed3919 100644 --- a/zwgc/port.c +++ b/zwgc/port.c @@ -12,8 +12,10 @@ * "mit-copyright.h". */ +#include + #if (!defined(lint) && !defined(SABER)) -static char rcsid_port_c[] = "$Id$"; +static const char rcsid_port_c[] = "$Id$"; #endif #include @@ -24,41 +26,12 @@ static char rcsid_port_c[] = "$Id$"; /* */ /****************************************************************************/ -#include -#include #include "new_string.h" #include "port_dictionary.h" #include "port.h" #include "notice.h" #include "variables.h" -/* - * <<<>>> - */ - -#if defined(SUNOS) || defined(vax) -extern int errno, sys_nerr; -extern char *sys_errlist[]; - -string perror_to_string(errno) - int errno; -{ - if (errno>=0 && errno>> */ - return("illegal error number returned in errno!"); -} -#else -#include - -string perror_to_string(errno) - int errno; -{ - return(strerror(errno)); -} -#endif - /****************************************************************************/ /* */ /* Port methods (internal): */ @@ -369,7 +342,7 @@ static string get_file(p, error_p) errno = 0; if (!fgets(buffer, 9999, p->data.file.input_connector)) { if (errno) - *error_p = perror_to_string(errno); + *error_p = strerror(errno); else *error_p = "Attempt to read past end of file"; @@ -393,7 +366,7 @@ static char *put_file(p, text, length) fflush(p->data.file.output_connector); if (errno) - return(perror_to_string(errno)); + return(strerror(errno)); return(NULL); } @@ -408,7 +381,7 @@ static char *close_file_input(p) } if (errno) - return(perror_to_string(errno)); + return(strerror(errno)); return(NULL); } @@ -423,7 +396,7 @@ static char *close_file_output(p) } if (errno) - return(perror_to_string(errno)); + return(strerror(errno)); return(NULL); } @@ -518,7 +491,7 @@ void create_file_append_port(name, filename) out = fopen(filename, "a"); (void) umask(oumask); if (out == NULL) { - var_set_variable("error", perror_to_string(errno)); + var_set_variable("error", strerror(errno)); return; } @@ -534,7 +507,7 @@ void create_file_input_port(name, filename) errno = 0; in = fopen(filename, "r"); if (in == NULL) { - var_set_variable("error", perror_to_string(errno)); + var_set_variable("error", strerror(errno)); return; } @@ -554,7 +527,7 @@ void create_file_output_port(name, filename) out = fopen(filename, "w"); (void) umask(oumask); if (out == NULL) { - var_set_variable("error", perror_to_string(errno)); + var_set_variable("error", strerror(errno)); return; } diff --git a/zwgc/regexp.c b/zwgc/regexp.c index f6f5854..f874e45 100644 --- a/zwgc/regexp.c +++ b/zwgc/regexp.c @@ -12,19 +12,19 @@ * "mit-copyright.h". */ +#include + #if (!defined(lint) && !defined(SABER)) -static char rcsid_regexp_c[] = "$Id$"; +static const char rcsid_regexp_c[] = "$Id$"; #endif -#include -#include "regexp.h" - #ifdef SOLARIS #include #endif -#ifdef POSIX_REGEXP -#include +#include "regexp.h" + +#ifdef HAVE_REGCOMP #include int ed_regexp_match_p(test_string, pattern) @@ -35,13 +35,14 @@ int ed_regexp_match_p(test_string, pattern) int retval; char errbuf[512]; - if (retval = regcomp(&RE, pattern, REG_EXTENDED|REG_NOSUB)) { + retval = regcomp(&RE, pattern, REG_NOSUB); + if (retval != 0) { regerror(retval, &RE, errbuf, sizeof(errbuf)); fprintf(stderr,"%s in regcomp %s\n",errbuf,pattern); return(0); } retval = regexec(&RE, test_string, 0, NULL, 0); - if (retval && retval != REG_NOMATCH) { + if (retval != 0 && retval != REG_NOMATCH) { regerror(retval, &RE, errbuf, sizeof(errbuf)); fprintf(stderr,"%s in regexec %s\n",errbuf,pattern); regfree(&RE); @@ -52,8 +53,8 @@ int ed_regexp_match_p(test_string, pattern) } #else -extern char *re_comp(); -extern int re_exec(); +char *re_comp(); +int re_exec(); int ed_regexp_match_p(test_string, pattern) string test_string; @@ -75,12 +76,11 @@ int ed_regexp_match_p(test_string, pattern) } #endif -/* - * This is for AUX. - * It is a wrapper around the C library regexp functions. - */ +#if !defined(HAVE_RE_COMP) && !defined(HAVE_REGCOMP) -#if defined(_AUX_SOURCE) || defined(SOLARIS) +#ifdef HAVE_LIBGEN_H +#include +#endif static char *re; diff --git a/zwgc/standard_ports.c b/zwgc/standard_ports.c index 72c6206..d0664dd 100644 --- a/zwgc/standard_ports.c +++ b/zwgc/standard_ports.c @@ -12,8 +12,10 @@ * "mit-copyright.h". */ +#include + #if (!defined(lint) && !defined(SABER)) -static char rcsid_standard_ports_c[] = "$Id$"; +static const char rcsid_standard_ports_c[] = "$Id$"; #endif #include @@ -24,22 +26,20 @@ static char rcsid_standard_ports_c[] = "$Id$"; /* */ /****************************************************************************/ -#include #include "new_memory.h" #include "port.h" #include "variables.h" #include "error.h" +#include "main.h" #include -#ifndef ZWGCPATH -#define ZWGCPATH "/usr/etc/zwgc" -#endif - extern string tty_filter(); -extern char *X_driver(); +extern int tty_filter_init(); +#ifndef X_DISPLAY_MISSING +extern char *X_driver(); extern int X_driver_init(); -extern int tty_filter_init(); +#endif extern void usage(); @@ -128,8 +128,12 @@ static struct standard_port_info { char *(*function)(); int setup_arg; } standard_port_info_table[] = { +#ifndef X_DISPLAY_MISSING { "X", DEFAULT_OK, X_driver_init, OUTPUT_PROC, X_driver, 0}, { "tty", DEFAULT_NOTOK, tty_filter_init, OUTPUT_PROC, tty_driver, 0}, +#else +{ "tty", DEFAULT_OK, tty_filter_init, OUTPUT_PROC, tty_driver, 0}, +#endif { "plain", DEFAULT_NOTOK, tty_filter_init, OUTPUT_PROC, plain_driver, 0}, { "stdout", DEFAULT_NOTOK, NULL, OUTPUT_DESC, NULL, 1}, { "stderr", DEFAULT_NOTOK, NULL, OUTPUT_DESC, NULL, 2}, @@ -281,7 +285,7 @@ void init_standard_ports(pargc, argv) if (fallback == -1) /* complain, since indeterminate */ ERROR2( "To receive Zephyrgrams, (type `%s -ttymode').\n", - ZWGCPATH); + progname); exit(1); } } else diff --git a/zwgc/string_dictionary_aux.c b/zwgc/string_dictionary_aux.c new file mode 100644 index 0000000..b257397 --- /dev/null +++ b/zwgc/string_dictionary_aux.c @@ -0,0 +1,102 @@ +/* This file is part of the Project Athena Zephyr Notification System. + * It is one of the source files comprising zwgc, the Zephyr WindowGram + * client. + * + * Created by: Marc Horowitz + * + * $Source$ + * $Author$ + * + * Copyright (c) 1989 by the Massachusetts Institute of Technology. + * For copying and distribution information, see the file + * "mit-copyright.h". + */ + +#if (!defined(lint) && !defined(SABER)) +static char rcsid_string_dictionary_aux_c[] = "$Id$"; +#endif + +/* + * string_dictionary_aux - a module implementing convenience routines for use + * with string_dictionarys + * + * Overview: + * + * This module implements Fetch and Set operations on + * string_dictionaries which take the place of Define and Lookup for + * most uses. The importance difference between them and Define and + * Lookup is that they maintain the invariant that all the value strings + * in a string_dictionary are on the heap. In particular, they do + * free's and string_Copy's whenever needed. Also implemented is + * SafeDestroy which does a Destroy after freeing all the value strings + * in a string_dictionary. + */ + +#include +#include "new_memory.h" +#include "string_dictionary.h" + +/* + * void string_dictionary_Set(string_dictionary d, string key,string value): + * Modifies: d + * Effects: Binds key to value in d. Automatically free's the + * previous value of key, if any. Value is copied on the + * heap. + */ + +void string__dictionary_Set(d, key, value) + string_dictionary d; + string key; + string value; +{ + string_dictionary_binding *binding; + int already_exists; + + binding = string_dictionary_Define(d, key, &already_exists); + if (already_exists) + free(binding->value); + + binding->value = string_Copy(value); +} + +/* + * char *string_dictionary_Fetch(string_dictionary d, string key) + * Effects: If key is not bound in d, returns 0. Otherwise, + * returns the value that key is bound to. + * Note that the returned string if any should not be + * freed or modified in any way. Note also that it may + * disappear later if key is rebound. + */ + +char *string_dictionary_Fetch(d, key) + string_dictionary d; + string key; +{ + string_dictionary_binding *binding; + + binding = string_dictionary_Lookup(d, key); + if (!binding) + return(0); + + return(binding->value); +} + +/* + * void string_dictionary_SafeDestroy(string_dictionary d) + * Modifies: d + * Effects: Like string_dictionary_Destroy except first frees + * all value's in the dictionary. + */ + +static void free_value_of_binding(b) + string_dictionary_binding *b; +{ + free(b->value); +} + +void string_dictionary_SafeDestroy(d) + string_dictionary d; +{ + string_dictionary_Enumerate(d, free_value_of_binding); + string_dictionary_Destroy(d); +} diff --git a/zwgc/string_dictionary_aux.h b/zwgc/string_dictionary_aux.h new file mode 100644 index 0000000..2098095 --- /dev/null +++ b/zwgc/string_dictionary_aux.h @@ -0,0 +1,58 @@ +/* This file is part of the Project Athena Zephyr Notification System. + * It is one of the source files comprising zwgc, the Zephyr WindowGram + * client. + * + * Created by: Marc Horowitz + * + * $Source$ + * $Author$ + * $Id$ + * + * Copyright (c) 1989 by the Massachusetts Institute of Technology. + * For copying and distribution information, see the file + * "mit-copyright.h". + */ + +#ifndef string_dictionary_aux_MODULE +#define string_dictionary_aux_MODULE + +#include "new_memory.h" +#include "string_dictionary.h" + +/* + * void string_dictionary_Set(string_dictionary d, string key,string value): + * Modifies: d + * Effects: Binds key to value in d. Automatically free's the + * previous value of key, if any. Value is copied on the + * heap. + */ + +extern void string__dictionary_Set(); +#ifdef DEBUG_MEMORY +#define string_dictionary_Set(a,b,c) (set_module(__FILE__,__LINE__),\ + string__dictionary_Set(a,b,c)) +#else +#define string_dictionary_Set(a,b,c) string__dictionary_Set(a,b,c) +#endif + +/* + * char *string_dictionary_Fetch(string_dictionary d, string key) + * Effects: If key is not bound in d, returns 0. Otherwise, + * returns the value that key is bound to. + * Note that the returned string if any should not be + * freed or modified in any way. Note also that it may + * disappear later if key is rebound. + */ + +extern char *string_dictionary_Fetch(); + +/* + * void string_dictionary_SafeDestroy(string_dictionary d) + * Modifies: d + * Effects: Like string_dictionary_Destroy except first frees + * all value's in the dictionary. + */ + +extern void string_dictionary_SafeDestroy(); + +#endif diff --git a/zwgc/subscriptions.c b/zwgc/subscriptions.c index ff18c06..c3d8c10 100644 --- a/zwgc/subscriptions.c +++ b/zwgc/subscriptions.c @@ -22,9 +22,8 @@ static char rcsid_subscriptions_c[] = "$Id$"; /* */ /****************************************************************************/ -#include +#include #include -#include #include #include "new_memory.h" #include "new_string.h" diff --git a/zwgc/substitute.c b/zwgc/substitute.c index 92805d9..03d619e 100644 --- a/zwgc/substitute.c +++ b/zwgc/substitute.c @@ -18,6 +18,7 @@ static char rcsid_substitute_c[] = "$Id$"; #include +#include #include "new_memory.h" #include "lexer.h" #include "substitute.h" diff --git a/zwgc/text_operations.c b/zwgc/text_operations.c index 2ebd170..7eba386 100644 --- a/zwgc/text_operations.c +++ b/zwgc/text_operations.c @@ -12,8 +12,10 @@ * "mit-copyright.h". */ +#include + #if (!defined(lint) && !defined(SABER)) -static char rcsid_text_operations_c[] = "$Id$"; +static const char rcsid_text_operations_c[] = "$Id$"; #endif #include diff --git a/zwgc/tty_filter.c b/zwgc/tty_filter.c index 25221f8..a75f082 100644 --- a/zwgc/tty_filter.c +++ b/zwgc/tty_filter.c @@ -12,8 +12,10 @@ * "mit-copyright.h". */ +#include + #if (!defined(lint) && !defined(SABER)) -static char rcsid_tty_filter_c[] = "$Id$"; +static const char rcsid_tty_filter_c[] = "$Id$"; #endif #include @@ -24,9 +26,6 @@ static char rcsid_tty_filter_c[] = "$Id$"; /* */ /****************************************************************************/ -#include -#include -#include #include "new_memory.h" #include "new_string.h" #include "string_dictionary_aux.h" @@ -68,11 +67,14 @@ static char code_buf[10240], *code_buf_pos = code_buf, *code; @u "us"/"ue" termcap entry. */ -#define TD_SET(k,v) (string_dictionary_Define(termcap_dict,(k),&ex)->value = (v)) -#define EAT_PADDING(var) (code = code_buf_pos, tputs(var, 1, tty_outc), *code_buf_pos++ = 0, var = code) +#define TD_SET(k,v) (string_dictionary_Define(termcap_dict, (k), &ex)->value \ + = (v)) +#define EXPAND(k) (code = code_buf_pos, tputs(tmp, 1, tty_outc), \ + *code_buf_pos++ = 0, TD_SET(k, code)) -static int tty_outc(c) -int c; +static int +tty_outc(c) + int c; { *code_buf_pos++ = c; return 0; @@ -90,9 +92,15 @@ char **argv; int ex; string_dictionary_binding *b; int isrealtty = string_Eq(drivername, "tty"); +#ifdef HAVE_TERMIOS_H struct termios tbuf; - ospeed = (tcgetattr(0, &tbuf) == 0) ? cfgetospeed(&tbuf) : 2400; + ospeed = (tcgetattr(STDIN_FILENO, &tbuf) == 0) ? cfgetospeed(&tbuf) : 2400; +#else + struct sgttyb sgttyb; + + ospeed = (ioctl(0, TIOCGETP, &sgttyb) == 0) ? sgttyb.sg_ospeed : 2400; +#endif if (termcap_dict == (string_dictionary) NULL) termcap_dict = string_dictionary_Create(7); @@ -119,46 +127,39 @@ char **argv; /* Step 1: get all of {rv,bold,u,bell,blink} that are available. */ + /* We cheat here, and ignore the padding (if any) specified for + the mode-change strings (it's a real pain to do "right") */ + tmp = tgetstr("pc", &p); PC = (tmp) ? *tmp : 0; if (tmp = tgetstr("md",&p)) { /* bold ? */ - EAT_PADDING(tmp); - TD_SET("B.bold",tmp); + EXPAND("B.bold"); tmp = tgetstr("me",&p); - EAT_PADDING(tmp); - TD_SET("E.bold",tmp); + EXPAND("E.bold"); } if (tmp = tgetstr("mr",&p)) { /* reverse video? */ - EAT_PADDING(tmp); - TD_SET("B.rv",tmp); + EXPAND("B.rw"); tmp = tgetstr("me",&p); - EAT_PADDING(tmp); - TD_SET("E.rv",tmp); + EXPAND("E.rw"); } if (tmp = tgetstr("bl",&p)) { /* Bell ? */ - TD_SET("B.bell",tmp); - TD_SET("E.bell",NULL); + EXPAND("B.bell"); + TD_SET("E.bell", NULL); } if (tmp = tgetstr("mb",&p)) { /* Blink ? */ - EAT_PADDING(tmp); - TD_SET("B.blink",tmp); + EXPAND("B.blink"); tmp = tgetstr("me",&p); - EAT_PADDING(tmp); - TD_SET("E.blink",tmp); + EXPAND("E.blink"); } if (tmp = tgetstr("us",&p)) { /* Underline ? */ - EAT_PADDING(tmp); - TD_SET("B.u",tmp); + EXPAND("B.u"); tmp = tgetstr("ue",&p); - EAT_PADDING(tmp); - TD_SET("E.u", tmp); + EXPAND("E.u"); } if (tmp = tgetstr("so",&p)) { /* Standout ? */ - EAT_PADDING(tmp); - TD_SET("B.so",tmp); + EXPAND("B.so"); tmp = tgetstr("se",&p); - EAT_PADDING(tmp); - TD_SET("E.so", tmp); + EXPAND("E.so"); } } /* Step 2: alias others to the nearest substitute */ @@ -388,6 +389,8 @@ static int calc_max_line_width(info) int right = 0; for (; info; info=info->next) { + if (info->ignore) + continue; switch (info->alignment) { case 'l': left += info->len; @@ -434,11 +437,11 @@ string tty_filter(text, use_fonts) desctype *desc; int number_of_strs; int number_of_lines; - tty_str_info *info; + tty_str_info *info, *info_head; int max_line_width; desc = disp_get_cmds(text_copy, &number_of_strs, &number_of_lines); - info = convert_desc_to_tty_str_info(desc); + info_head = info = convert_desc_to_tty_str_info(desc); free_desc(desc); #ifdef DEBUG @@ -537,7 +540,7 @@ string tty_filter(text, use_fonts) } } - free_info(info); + free_info(info_head); free(text_copy); if (number_of_lines && (result_so_far[string_Length(result_so_far)-1] != '\n')) diff --git a/zwgc/ulong.h b/zwgc/ulong.h deleted file mode 100644 index 95269a5..0000000 --- a/zwgc/ulong.h +++ /dev/null @@ -1,24 +0,0 @@ -/* This file is part of the Project Athena Zephyr Notification System. - * It is one of the source files comprising zwgc, the Zephyr WindowGram - * client. - * - * Created by: Marc Horowitz - * - * $Source$ - * $Author$ - * $Id$ - * - * Copyright (c) 1989 by the Massachusetts Institute of Technology. - * For copying and distribution information, see the file - * "mit-copyright.h". - */ -#ifndef ulong_MODULE -#define ulong_MODULE - -#include - -#if defined(ultrix) || defined(vax) || defined(SUNOS) || defined(__NetBSD__) -typedef unsigned long ulong; -#endif - -#endif diff --git a/zwgc/unsigned_long.h b/zwgc/unsigned_long.h new file mode 100644 index 0000000..a9a74f1 --- /dev/null +++ b/zwgc/unsigned_long.h @@ -0,0 +1,5 @@ +/* $Id$ + * $Source$ + */ + +#define unsigned_long unsigned long diff --git a/zwgc/variables.c b/zwgc/variables.c index 2f9f13c..99b18d0 100644 --- a/zwgc/variables.c +++ b/zwgc/variables.c @@ -12,8 +12,10 @@ * "mit-copyright.h". */ +#include + #if (!defined(lint) && !defined(SABER)) -static char rcsid_variables_c[] = "$Id$"; +static const char rcsid_variables_c[] = "$Id$"; #endif #include @@ -24,8 +26,6 @@ static char rcsid_variables_c[] = "$Id$"; /* */ /****************************************************************************/ -#include -#include #include "new_memory.h" #include "notice.h" #include "string_dictionary_aux.h" diff --git a/zwgc/xcut.c b/zwgc/xcut.c index 50893d6..aee164e 100644 --- a/zwgc/xcut.c +++ b/zwgc/xcut.c @@ -12,8 +12,10 @@ * "mit-copyright.h". */ +#include + #if (!defined(lint) && !defined(SABER)) -static char rcsid_xcut_c[] = "$Id$"; +static const char rcsid_xcut_c[] = "$Id$"; #endif #include @@ -24,13 +26,13 @@ static char rcsid_xcut_c[] = "$Id$"; /* */ /****************************************************************************/ +#ifndef X_DISPLAY_MISSING + #include #include -#include #include "new_memory.h" #include "new_string.h" #include "X_gram.h" -#include #include "zwgc.h" #include "xselect.h" #include "xmark.h" @@ -362,3 +364,6 @@ void xcut(dpy,event,desc_context) XFlush(dpy); } + +#endif + diff --git a/zwgc/xerror.c b/zwgc/xerror.c index 58283a8..d40f986 100644 --- a/zwgc/xerror.c +++ b/zwgc/xerror.c @@ -12,14 +12,17 @@ * "mit-copyright.h". */ +#include + #if (!defined(lint) && !defined(SABER)) -static char rcsid_xerror_c[] = "$Id$"; +static const char rcsid_xerror_c[] = "$Id$"; #endif #include +#ifndef X_DISPLAY_MISSING + #include -#include #include "mux.h" int xerror_happened; @@ -46,3 +49,6 @@ void end_xerror_trap(dpy) XSync(dpy,False); XSetErrorHandler(NULL); } + +#endif + diff --git a/zwgc/xerror.h b/zwgc/xerror.h index 0e17936..c6e801a 100644 --- a/zwgc/xerror.h +++ b/zwgc/xerror.h @@ -16,7 +16,7 @@ #define _XERROR_H_ #if (!defined(lint) && !defined(SABER)) -static char rcsid_xerror_h[] = "$Id$"; +static const char rcsid_xerror_h[] = "$Id$"; #endif #include diff --git a/zwgc/xmark.c b/zwgc/xmark.c index 7b32a80..a6e68f3 100644 --- a/zwgc/xmark.c +++ b/zwgc/xmark.c @@ -18,13 +18,16 @@ static char rcsid_xmark_c[] = "$Id$"; #include +#include + +#ifndef X_DISPLAY_MISSING + #include #include #include "X_gram.h" #include "X_fonts.h" #include "xmark.h" #include "new_string.h" -#include int markblock[3] = { -1 , -1 , -1 }; int markchar[3] = { -1 , -1 , -1 }; @@ -383,3 +386,6 @@ char *xmarkGetText() return(text_so_far); } + +#endif /* X_DISPLAY_MISSING */ + diff --git a/zwgc/xrevstack.c b/zwgc/xrevstack.c index ae22da7..d594b6e 100644 --- a/zwgc/xrevstack.c +++ b/zwgc/xrevstack.c @@ -12,15 +12,18 @@ * "mit-copyright.h". */ +#include + #if (!defined(lint) && !defined(SABER)) -static char rcsid_xrevstack_c[] = "$Id$"; +static const char rcsid_xrevstack_c[] = "$Id$"; #endif #include -#ifdef REVSTACK +#ifndef X_DISPLAY_MISSING + +#ifndef TRUEREVSTACK #include "X_gram.h" -#include x_gram *bottom_gram = NULL; x_gram *unlinked = NULL; @@ -260,3 +263,6 @@ x_gram *gram; } #endif /* TRUEREVSTACK */ + +#endif /* X_DISPLAY_MISSING */ + diff --git a/zwgc/xselect.c b/zwgc/xselect.c index 59ed16c..2d12b4b 100644 --- a/zwgc/xselect.c +++ b/zwgc/xselect.c @@ -12,8 +12,10 @@ * "mit-copyright.h". */ +#include + #if (!defined(lint) && !defined(SABER)) -static char rcsid_xselect_c[] = "$Id$"; +static const char rcsid_xselect_c[] = "$Id$"; #endif #include @@ -21,7 +23,8 @@ static char rcsid_xselect_c[] = "$Id$"; /* xselect.c - ICCCM compliant cut-and-paste */ /* also includes some other ICCCMisms, such as the WM_PROTOCOL handling */ -#include +#ifndef X_DISPLAY_MISSING + #include #include #include @@ -204,3 +207,6 @@ void xselGiveUpOwnership(dpy,w) ownership_end=ownership_start; /* Is this right? what should I use? */ } + +#endif /* X_DISPLAY_MISSING */ + diff --git a/zwgc/xshow.c b/zwgc/xshow.c index 402368d..27a9df1 100644 --- a/zwgc/xshow.c +++ b/zwgc/xshow.c @@ -12,13 +12,16 @@ * "mit-copyright.h". */ +#include + #if (!defined(lint) && !defined(SABER)) -static char rcsid_xshow_c[] = "$Id$"; +static const char rcsid_xshow_c[] = "$Id$"; #endif #include -#include +#ifndef X_DISPLAY_MISSING + #include #include #include @@ -572,3 +575,6 @@ void x_get_input(dpy) xhandleevent(dpy, event.xany.window, &event); } } + +#endif /* X_DISPLAY_MISSING */ + diff --git a/zwgc/zephyr.c b/zwgc/zephyr.c index f8d7389..ded5e01 100644 --- a/zwgc/zephyr.c +++ b/zwgc/zephyr.c @@ -12,8 +12,10 @@ * "mit-copyright.h". */ +#include + #if (!defined(lint) && !defined(SABER)) -static char rcsid_zephyr_c[] = "$Id$"; +static const char rcsid_zephyr_c[] = "$Id$"; #endif #include @@ -24,7 +26,6 @@ static char rcsid_zephyr_c[] = "$Id$"; /* */ /****************************************************************************/ -#include #include #include #include "new_string.h" @@ -34,42 +35,14 @@ static char rcsid_zephyr_c[] = "$Id$"; #include "subscriptions.h" #include "variables.h" #include "pointer.h" +#ifndef X_DISPLAY_MISSING +#include "X_driver.h" +#endif #ifdef DEBUG extern int zwgc_debug; #endif /* DEBUG */ -/* - * Internal Routine: - * - * char *parse_exposure_level(string text) - * Effects: Compares text to each of the standard zephyr - * exposure levels ignoring case. If it matches, - * returns the corresponding magic constant for - * use with ZSetLocation. (i.e., returns EXPOSE_OPSTAFF - * for "opstaff", etc.) If it does not match, returns - * NULL. - */ - -static char *parse_exposure_level(text) - string text; -{ - if (!strcasecmp(text, EXPOSE_NONE)) - return (EXPOSE_NONE); - else if (!strcasecmp(text, EXPOSE_OPSTAFF)) - return (EXPOSE_OPSTAFF); - else if (!strcasecmp(text, EXPOSE_REALMVIS)) - return (EXPOSE_REALMVIS); - else if (!strcasecmp(text, EXPOSE_REALMANN)) - return (EXPOSE_REALMANN); - else if (!strcasecmp(text, EXPOSE_NETVIS)) - return (EXPOSE_NETVIS); - else if (!strcasecmp(text, EXPOSE_NETANN)) - return (EXPOSE_NETANN); - else - return(NULL); -} - /* * Internal Routine: * @@ -136,6 +109,7 @@ void zephyr_init(notice_handler) unsigned short port = 0; /* Use any old port */ char *temp; char *exposure; + char *tty = NULL; FILE *port_file; /* @@ -150,7 +124,14 @@ void zephyr_init(notice_handler) */ temp = get_zwgc_port_number_filename(); errno = 0; - port_file = fopen(temp, "w+"); + port_file = fopen(temp, "r"); + if (port_file) { + fprintf(stderr, "zwgc: windowgram file already exists. If you are\n"); + fprintf(stderr, "zwgc: not already running zwgc, delete %s\n", temp); + fprintf(stderr, "zwgc: and try again.\n"); + exit(1); + } + port_file = fopen(temp, "w"); if (port_file) { fprintf(port_file, "%d\n", port); fclose(port_file); @@ -159,6 +140,15 @@ void zephyr_init(notice_handler) perror(""); } + /* Set hostname and tty for locations. If we support X, use the + * display string for the tty name. */ +#ifndef X_DISPLAY_MISSING + if (dpy) + tty = DisplayString(dpy); +#endif + error_code = ZInitLocationInfo(NULL, tty); + TRAP( error_code, "while initializing location information" ); + /* * Retrieve the user's desired exposure level (from the zephyr variable * "exposure"), convert it to the proper internal form then @@ -167,7 +157,7 @@ void zephyr_init(notice_handler) * EXPOSE_NONE. */ if (temp = ZGetVariable("exposure")) { - if (!(exposure = parse_exposure_level(temp))) { + if (!(exposure = ZParseExposureLevel(temp))) { ERROR2("invalid exposure level %s, using exposure level none instead.\n", temp); exposure = EXPOSE_NONE; } diff --git a/zwgc/zephyr.vars b/zwgc/zephyr.vars deleted file mode 100644 index 75a0a72..0000000 --- a/zwgc/zephyr.vars +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright 1988 Massachusetts Institute of Technology -# -# For copying and distribution information, see the file -# "mit-copyright.h". -# -# $Source$ -# $Author$ -# $Id$ -# -# Zephyr default variables file -# -# Format is: -# -# var = value -# - -# Exposure setting defaults to realm-visible. - -exposure = realm-visible - -# Initialization programs. - -initprogs = /etc/athena/zinit diff --git a/zwgc/zephyr.vars.in b/zwgc/zephyr.vars.in new file mode 100644 index 0000000..c1a7fb9 --- /dev/null +++ b/zwgc/zephyr.vars.in @@ -0,0 +1,23 @@ +# Copyright 1988 Massachusetts Institute of Technology +# +# For copying and distribution information, see the file +# "mit-copyright.h". +# +# $Source$ +# $Author$ +# $Id$ +# +# Zephyr default variables file +# +# Format is: +# +# var = value +# + +# Exposure setting defaults to realm-visible. + +exposure = realm-visible + +# Initialization programs. + +initprogs = @INITPROGS@ diff --git a/zwgc/zwgc.1 b/zwgc/zwgc.1 index 233694e..379b13f 100644 --- a/zwgc/zwgc.1 +++ b/zwgc/zwgc.1 @@ -17,6 +17,14 @@ .el \\*(]X\h@|\\n()Iu+\\n()Ru@\c .}f .. +.de }N +.if \\n()E .br +.di +.if "\\n()E"0" .}f +.if "\\n()E"1" .}1 +.if "\\n()E"2" .}2 +.nr )E 0 +.. ' # tagged paragraph (paragraph with hanging label, but no para spacing) .de TQ .if !"\\$1"" .nr )I \\$1n @@ -314,6 +322,9 @@ Returns the value of \fIexpr\fR, converted to upper case. Returns a string that will be displayed exactly as \fIexpr\fR looks. Anything which could be mistaken for an environment is quoted. .TP +.BI stylestrip (expr) +Returns \fIexpr\fR with all environments stripped out. +.TP .BI zvar (expr) Returns the value of the zephyr variable \fIexpr\fR, or the empty @@ -333,7 +344,7 @@ String concatenation of .IB expr1 " == " expr2 True if the two expressions are equal, false otherwise. .TP -.IB expr " =~ " expr2 +.IB expr1 " =~ " expr2 True if the regular expression pattern .IR expr2 " matches " expr1. .TP @@ -821,15 +832,6 @@ WM_DELETE_WINDOW as contents. EnableDelete Secondary value to enable WM_DELETE_WINDOW protocol on zgrams [default False] .TP -global -(logical) If true, zwgc creates a _SGI_DESKS_HINTS property on all zgrams, with -_SGI_DESKS_ALWAYS_GLOBAL as contents. This results in zgrams appearing -on all desks in SGI's 4Dwm window manager. Otherwise, zgrams appear and -remain on whatever desk is in use at the time. -.TP -Global -Secondary value to set _SGI_DESKS_HINTS property on zgrams [default True] -.TP minTimeToLive Primary value which specifies the minimum amount of time (``minimum time to live'') a WindowGram must be on-screen (in milliseconds) until it can @@ -1000,7 +1002,14 @@ For an example of X resources, see The X selection code can highlight the wrong portions of messages containing formatted text placed with the @center() or @right() directives. - +.PP +If you are using Kerberos support and get new tickets (using +``kinit''), you must send a subscription notice to the server (using a +command such as ``zctl load /dev/null'') or all received Zephyr +notices will appear to be unauthentic. (If all received Zephyr +notices appear to be forged, your tickets have probably expired, in +which case you must get new tickets and then run ``zctl load +/dev/null''.) .SH FILES .TQ 15 $HOME/.zwgc.desc diff --git a/zwgc/zwgc.desc b/zwgc/zwgc.desc index 01a2e62..796eaf0 100644 --- a/zwgc/zwgc.desc +++ b/zwgc/zwgc.desc @@ -87,14 +87,18 @@ match "WG_CTL_CLASS" # put # exit match "message" - case $instance - match "PERSONAL" - set type = "Personal" - match "URGENT" - set type = "Urgent" - default + if (downcase($recipient) == downcase($user)) then + case $instance + match "PERSONAL" + set type = "Personal" + match "URGENT" + set type = "Urgent" + default + set type = $instance + endcase + else set type = "Instance "+$instance - endcase + endif fields signature body if ($body == "") then -- cgit v1.2.3