v01i019: ify - a program to iconify MGR windows, Part02/02

comp.sources.3b1 dhb at uunet.UU.NET
Sun Apr 7 14:47:00 AEST 1991


Submitted-by: pyuxd!scj (Steven C. Johnson)
Posting-number: Volume 1, Issue 19
Archive-name: ify/part02

Part two of ify sources

---- Cut Here and unpack ----
#!/bin/sh
# This is part 02 of volume01/ify_src
if touch 2>&1 | fgrep '[-amc]' > /dev/null
 then TOUCH=touch
 else TOUCH=true
fi
# ============= makefile ==============
if test X"$1" != X"-c" -a -f 'makefile'; then
	echo "File already exists: skipping 'makefile'"
else
echo "x - extracting makefile (Text)"
sed 's/^X//' << 'SHAR_EOF' > makefile &&
X# Makefile for ify
X
X# Stock 3b1 cc can't handle ify.c compile
XCC = gcc
X
X# change these lines to say where to find the mgr #include files and libraries
X# perhaps add -DOLDMGR to the end of CFLAGS
X# CFLAGS = -g -I/usr/mgr/include -DOLDMGR
X# use the next line if you have a (non-standard, 3b1) write black MGR
X# CFLAGS = -O -I/usr/mgr/include -DBBB1 -DBOW
XCFLAGS = -O -I/usr/mgr/include -DBBB1
X
XMGRLIB = /usr/mgr/lib/libmgr.a
X
X# define SHLIB as null if you don't want shared libraries (say, for debug)
XSHLIB = -shlib
X
Xall: mesg ify setname
Xmesg:
X	@echo "If the compile fails, adjust CFLAGS and MGRLIB in the"
X	@echo "makefile to say where to find the mgr #include files and"
X	@echo "libraries."
X	@echo " "
X	@echo "If the compile still fails, or if ify compiles but hangs,"
X	@echo "try adding -DOLDMGR to the end of the CFLAGS."
X	@echo " "
X	@echo "In the worst case, try changing CC to cc instead of gcc."
Xify: ify.o icondata.o
X	$(CC) $(SHLIB) $(CFLAGS) ify.o icondata.o $(MGRLIB) -o ify
Xify.o: ify.c
Xicondata.o: icondata.c
Xsetname: setname.c
X	$(CC) $(SHLIB) $(CFLAGS) setname.c $(MGRLIB) -o setname
SHAR_EOF
$TOUCH -am 0328155691 makefile &&
chmod 0644 makefile ||
echo "restore of makefile failed"
set `wc -c makefile`;Wc_c=$1
if test "$Wc_c" != "1096"; then
	echo original size 1096, current size $Wc_c
fi
fi
# ============= patchlevel.h ==============
if test X"$1" != X"-c" -a -f 'patchlevel.h'; then
	echo "File already exists: skipping 'patchlevel.h'"
else
echo "x - extracting patchlevel.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > patchlevel.h &&
X#define PATCHLEVEL 0
SHAR_EOF
$TOUCH -am 0328153691 patchlevel.h &&
chmod 0640 patchlevel.h ||
echo "restore of patchlevel.h failed"
set `wc -c patchlevel.h`;Wc_c=$1
if test "$Wc_c" != "21"; then
	echo original size 21, current size $Wc_c
fi
fi
# ============= setname.1 ==============
if test X"$1" != X"-c" -a -f 'setname.1'; then
	echo "File already exists: skipping 'setname.1'"
else
echo "x - extracting setname.1 (Text)"
sed 's/^X//' << 'SHAR_EOF' > setname.1 &&
X.TH setname 1L "July 25, 1989"
X.SH NAME
Xsetname \- name an MGR window
X.SH SYNOPSIS
X.B setname
X\fIwindow name\fP
X.SH DESCRIPTION
X\fBsetname\fP sets the \fBNOTIFY\fP string of its window.  Programs like
X\fBify(1L)\fP use the \fBNOTIFY\fP string as the 'name' of the window.
X.PP
X\fIWindow name\fP may contain % escapes, in the manner of
X\fBprintf(3S)\fP.  \fBSetname\fP performs the following substitutions on
X\fIwindow name\fP:
X.TP
X.B \fB%m\fP
Xreplaced by the name of the machine \fBsetname\fP is running on
X.TP
X.B \fB%w\fP
Xreplaced by the width of the window, in columns of text
X.TP
X.B \fB%c\fP
Xreplaced by the height of the window, in rows of text
X.TP
X.B \fB%p\fP
Xreplaced by a vague verbal description of the window's position
X.TP
X.B \fB%%\fP
Xreplaced by a single \fB%\fP
X.SH SEE ALSO
Xmgr(1L), ify(1L)
X.SH DIAGNOSTICS
XIf \fBsetname\fP is invoked with no arguments, it prints a short explanatory
Xmessage.
X.SH BUGS
XCreeping featurism at its worst.  Real hackers use escape codes.
X.SH AUTHOR
XJim Blandy
SHAR_EOF
$TOUCH -am 0328153691 setname.1 &&
chmod 0644 setname.1 ||
echo "restore of setname.1 failed"
set `wc -c setname.1`;Wc_c=$1
if test "$Wc_c" != "1001"; then
	echo original size 1001, current size $Wc_c
fi
fi
# ============= setname.c ==============
if test X"$1" != X"-c" -a -f 'setname.c'; then
	echo "File already exists: skipping 'setname.c'"
else
echo "x - extracting setname.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > setname.c &&
X/* setname.c - specify the name to appear when window is iconified
X   Jim Blandy - Monday, July 17, 1989 - Bell Communications Research
X   *** Modified for the AT&T 3B1 by Steve Johnson - March, 1991 *** */
X
X#include "term.h"
X#include "patchlevel.h"
X
Xextern char *malloc( /* unsigned size */ ),
X            *realloc( /* char *ptr, unsigned size */ );
X
Xchar *progname;			/* name of program */
X
X#define MAXHOSTLEN (80)		/* maximum length of host name  */
Xchar *buf;			/* where we accumulate the name */
Xint bufsize;			/* how many bytes it has allocated to it */
X
X#define ADD(size) assure(bufsize+(size))
X
Xchar usage[] = "\
XUsage: %s <window name>\n\
Xchanges the name of the window to <window name>.\n\
X<window name> may contain:\n\
X  %%m - current host name\n\
X  %%w - width of the window, in columns of text\n\
X  %%h - height of the window, in rows of text\n\
X  %%p - vague verbal description of the window's position\n\
X  %%%% - a single %%\n";
X
Xmain(argc, argv)
X     int argc;
X     char **argv;
X{
X    int bufend;
X    int cols, rows;
X    char hostname[MAXHOSTLEN];
X    int disp_w, disp_h;
X    int wind_x, wind_y, wind_w, wind_h;
X    int eps_x, eps_y;
X
X    progname = argv[0];
X
X    if (argc == 1) {
X	fprintf(stderr, usage, progname);
X	exit(1);
X    }
X    
X    m_setup(M_FLUSH);
X    m_ttyset();
X    get_param(NULL, &disp_w, &disp_h, NULL);
X#ifdef BSD
X    gethostname(hostname, MAXHOSTLEN);
X#else /* SYSV */
X{
X#include <sys/utsname.h>
X    struct utsname ux_name;
X    uname(&ux_name);
X    strcpy(hostname, ux_name.nodename);
X}
X#endif /* BSD */
X    eps_x = disp_w>>3;
X    eps_y = disp_h>>3;
X    get_colrow(&cols, &rows);
X    get_size(&wind_x, &wind_y, &wind_w, &wind_h);
X    m_ttyreset();
X    assure(100);
X
X    bufend = 0;
X    for (argc--, argv++; argc>0; argc--, argv++) {
X	char *p;
X
X	assure(bufend+strlen(*argv));
X
X	for (p = *argv; *p; p++)
X	    if (*p == '%')
X	      switch(p[1]) {
X		case '%':	/* an ordinary % */
X		  buf[bufend++] = *++p;
X		  break;
X		case 'm':	/* machine name */
X		  {
X		      int len;
X
X		      ADD(len = strlen(hostname));
X		      strcpy(buf+bufend, hostname);
X		      bufend+=len;
X		      p++;
X		  }
X		  break;
X		case 'w':	/* columns in window */
X		  ADD(3);
X		  sprintf(buf+bufend, "%d", cols);
X		  bufend+=strlen(buf+bufend);
X		  p++;
X		  break;
X		case 'h':	/* rows in window */
X		  ADD(3);
X		  sprintf(buf+bufend, "%d", rows);
X		  bufend+=strlen(buf+bufend);
X		  p++;
X		  break;
X		case 'p':	/* vague description of window's */
X				/* position*/
X		  {
X		      int h = wind_x - (disp_w - (wind_x+wind_w));
X		      int v = wind_y - (disp_h - (wind_y+wind_h));
X
X		      ADD(15);
X
X		      if (v<-eps_y)
X			strcpy(buf+bufend, "upper");
X		      else if (v>eps_y)
X			strcpy(buf+bufend, "lower");
X		      else
X			strcpy(buf+bufend, "middle");
X
X		      bufend += strlen(buf+bufend);
X
X		      if (h<-eps_x)
X			strcpy(buf+bufend, " left");
X		      else if (h>eps_x)
X			strcpy(buf+bufend, " right");
X		      else if (v<-eps_x || v>eps_x)
X			strcpy(buf+bufend, " middle");
X
X		      bufend += strlen(buf+bufend);
X		      p++;
X		  }
X		  break;
X		default:
X		  buf[bufend++] = *p;
X		  break;
X	      }
X	    else
X	      buf[bufend++] = *p;
X
X	if (argc>1)
X	  buf[bufend++] = ' ';
X    }
X
X    buf[bufend] = '\0';
X    m_setevent(NOTIFY, buf);
X    die(NULL);
X}
X
X
Xdie(mesg, err)
X     char *mesg;
X     int err;
X{
X    if (mesg && mesg[0] != '\0')
X      fprintf(stderr, "%s: %s\n", progname, mesg);
X    exit(err);
X}
X
X
Xassure(size)
X     int size;
X{
X    if (size < bufsize)
X      return;
X    size = (size + 127L) & ~127L;
X    if ((buf == NULL && (buf = malloc(size)) == NULL)
X	|| (buf = realloc(buf, size)) == NULL)
X      die("out of memory");
X}
SHAR_EOF
$TOUCH -am 0328153691 setname.c &&
chmod 0644 setname.c ||
echo "restore of setname.c failed"
set `wc -c setname.c`;Wc_c=$1
if test "$Wc_c" != "3635"; then
	echo original size 3635, current size $Wc_c
fi
fi
exit 0
_
Steven C. Johnson [...![bcr|bellcore]!pyuxd!scj | scj at pahasapa.bellcore.com]
bus. (908) 699-5514                              <scj at 128.96.131.41        >

-- 
David H. Brierley
Home: dave at galaxia.newport.ri.us; Work: dhb at quahog.ssd.ray.com
Send comp.sources.3b1 submissions to comp-sources-3b1 at galaxia.newport.ri.us
%% Can I be excused, my brain is full. **



More information about the Comp.sources.3b1 mailing list