#!/bin/sh
# This is a shell archive (shar 3.21)
# made 08/19/1993 21:19 UTC by spencer@guraldi.itn.med.umich.edu
# Source directory /l/spencer/src/tcl
#
# existing files WILL be overwritten
#
# This shar contains:
# length  mode       name
# ------ ---------- ------------------------------------------
#    379 -rw-rw---- zapinterps.tcl
#   4399 -rw-rw---- unregister.c
#
if touch 2>&1 | fgrep '[-amc]' > /dev/null
 then TOUCH=touch
 else TOUCH=true
fi
# ============= zapinterps.tcl ==============
echo "x - extracting zapinterps.tcl (Text)"
sed 's/^X//' << 'SHAR_EOF' > zapinterps.tcl &&
X#! /usr/hgp/bin/wish -f
X#
X# Zap all wish interps that don't exist
X#
X
Xwm withdraw .
Xset zaplist {}
Xforeach i [winfo interps] {
X  puts stderr  "$i ..." nonewline
X  if [catch {send $i {}}] {
X    puts stderr Gone;
X    lappend zaplist $i;
X  } {
X    puts stderr Ok;
X  }
X}
X
Xif {$zaplist != {}} {
X  catch [concat exec unregister $zaplist | grep ^Removing] out;
X  puts $out;
X}
X
Xdestroy .
SHAR_EOF
$TOUCH -am 0819143693 zapinterps.tcl &&
chmod 0660 zapinterps.tcl ||
echo "restore of zapinterps.tcl failed"
set `wc -c zapinterps.tcl`;Wc_c=$1
if test "$Wc_c" != "379"; then
	echo original size 379, current size $Wc_c
fi
# ============= unregister.c ==============
echo "x - extracting unregister.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > unregister.c &&
X#include <X11/Xlib.h>
X#include <X11/Xatom.h>
X#include <stdio.h>
X
X/* unregister.c:
X * The purpose of this is to remove from the InterpRegistry property the
X * id/name strings of any interpreters named on the command line.
X * Usage: unregister <interpreter name> <interpreter name> ...
X *        unregister without arguments will list the currently-registered
X *        interpreters.
X *
X * To compile: cc -o unregister -lX11 unregister.c
X *
X * Author: Jim Curran (jim@cis.ohio-state.edu)
X */
X
X#define MAX_PROP_WORDS 100000
X
X
Xint find_interp();
Xint split_interps();
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X
X{
XDisplay *dpy;
XAtom type_return;
Xint format_return;
Xunsigned long nitems_return, bytes_after_return;
Xchar *prop, *p, *s, *new_prop;
Xint index, num_interps, result, i;
Xchar *interps[50];
X
X  /*--- open the display ---*/
X  if( (dpy = XOpenDisplay(NULL))==NULL) {
X    printf("Couldn't open default display\n");
X    exit(-1);
X  }
X
X  /*--- try to get the InterpRegistery property ---*/
X  result = XGetWindowProperty(dpy, RootWindow(dpy, 0),
X                              XInternAtom(dpy, "InterpRegistry", False),
X                              0, MAX_PROP_WORDS, False, XA_STRING,
X                              &type_return, &format_return,
X                              &nitems_return, &bytes_after_return,
X                              &prop);
X
X  /*--- get the interpreter strings into an array of strings ---*/
X  num_interps = split_prop_string(prop, interps, nitems_return);
X
X  /*--- print them out ---*/
X  for(index=0; index<num_interps; index++)
X    printf("%s\n", interps[index]);
X
X  /*--- if the user didn't specify anything to delete then exit ---*/
X  if(argc==1)
X    exit(0);
X
X  /*--- now eliminate interpreters named on the command line ---*/
X  printf("\n");
X
X  /*--- allocate a buffer for the new property ---*/
X  new_prop = (char *) malloc(nitems_return); 
X  p = new_prop;
X
X  /* now that we have an array of all of the strings in the property
X   * we can re-build the property string to our liking.  We check each
X   * one interpreter string against the interpreter names specified on
X   * the command line.  If there is a match then we simply skip copying that
X   * window id/interpreter string into the new property.
X   */
X
X  /*--- process each interpreter id/name string ---*/
X  for(i=0; i<num_interps; i++) {
X    /*--- process each command line arg ---*/
X    for(index=1, result=0; (index<argc)&&(result==0); index++) {
X      /*--- see if this id/name corresponds to a targeted interpreter ---*/
X      if(find_interp(argv[index], interps[i])==0)
X        result = 1;
X    }
X    /*--- did we match any of the args ? ---*/
X    if(!result) {
X      /*--- nope, go ahead and copy the id/name into the new property ---*/
X      s = interps[i];
X      while(*s)
X        *p++ = *s++; 
X      *p++ = 0;
X      } else {
X        printf("Removing %s\n", interps[i]);
X      }
X  } 
X  /*--- now re-install the new property ---*/
X  result = XChangeProperty(dpy, RootWindow(dpy, 0),
X                           XInternAtom(dpy, "InterpRegistry", False),
X                           XA_STRING, format_return, PropModeReplace,
X                           new_prop, (p-new_prop));
X  XSync(dpy);
X  XCloseDisplay(dpy);
X}
X
X
X/*--- this find the named interpreter pattern (p) in the property (s) ---*/
Xint find_interp(p, s) 
Xchar *p, *s;
X{
X  /* as far as I can tell there is a single space separating the
X   * window ID from the interpreter name.
X   */
X
X  /*--- advance to the first space character in the search space ---*/
X  while(*s != ' ')
X    s++;
X
X  /*--- point past the separating space ---*/
X  s++;
X
X  /*--- now compare what's left with the search pattern ---*/
X  if (strcmp(s, p)==0) 
X    return 0;
X  else 
X    return 1;
X}
X
X
X/*--- split the property into an array of strings ---*/
X
Xint split_prop_string(prop, names, nbytes)
Xchar *prop; 
Xchar *names[];
Xunsigned long nbytes;
X{
Xint count, index;
X
X  /*--- process the first string ---*/
X  count=0;
X  if(*prop)
X    names[count++] = prop;
X
X  /*--- process the remaining strings ---*/
X  for(index=0; index<nbytes; index++) {
X    /*--- if this is the end of a string ---*/
X    if(prop[index]==0) {
X      /*--- and it's not the last string ---*/
X      if((index+1)<nbytes)
X        /*--- then save a pointer to the string ---*/
X        names[count++] = &prop[index+1];
X    }
X  }
X  /*--- return the number of strings found in the property ---*/
X  return(count);
X}
X
SHAR_EOF
$TOUCH -am 0723102293 unregister.c &&
chmod 0660 unregister.c ||
echo "restore of unregister.c failed"
set `wc -c unregister.c`;Wc_c=$1
if test "$Wc_c" != "4399"; then
	echo original size 4399, current size $Wc_c
fi
exit 0
