Sun-Spots Digest, v6n115

William LeFebvre Sun-Spots-Request at RICE.EDU
Mon Jun 20 12:07:19 AEST 1988


SUN-SPOTS DIGEST           Sunday, 19 June 1988       Volume 6 : Issue 115

Today's Topics:
                 Introduction to this "all source" issue
                                 Tooltool
                               Console Tool
                pw_line() that elusive yet useful function
                          Sample IBM DAI program
                     Son of Rastool (includes source)
         Sun rasterfile to DEC sixel converter (includes source)

Send contributions to:  sun-spots at rice.edu
Send subscription add/delete requests to:  sun-spots-request at rice.edu
Bitnet readers can subscribe directly with the CMS command:
    TELL LISTSERV AT RICE SUBSCRIBE SUNSPOTS My Full Name
Recent backissues are available via anonymous FTP from "titan.rice.edu".
For volume X, issue Y, "get sun-spots/vXnY".  They are also accessible
through the archive server:  mail the request "send sun-spots vXnY" to
"archive-server at rice.edu" or mail the word "help" to the same address
for more information.

----------------------------------------------------------------------

Date:    Sun, 19 Jun 88 12:54:55 CDT
From:    William LeFebvre <phil at Rice.edu>
Subject: Introduction to this "all source" issue

This issue of Sun-Spots contains source, source, and more source.  Some of
the articlese are merely introductions to programs written by some of the
readers:  the programs themselves are in shar file format in the archives.
Other articles contain short programs (these are all collected at the end
of this issue).  This takes care of most of the source that was waiting in
the backlog.  It takes me a little longer to process submissions of source
programs because I take the time to make sure that the shar file will
unpack correctly, and in some cases I even try to compile the code and
give it a trial run.

All archived files mentioned in this issue can be retrieved via anonymous
FTP from the host "titan.rice.edu" or via the archive server.  For more
information about the archive server, send a mail message containing the
word "help" to the address "archive-server at rice.edu".

I am afraid that this issue will generate a flood of archive server
requests.  So please wait patiently for the server's replies and go easy
on the requests (try to spread them out over the week).  By the way, there
are currently NO requests waiting in the server's queue.

I will start things off by introducing a shar file that contains two
"screen hacks".  A screen hack is a program that does something surprising
and amusing to the screen.  Since part of the fun of such programs is
being surprised by what they do, I will not explain these two programs any
further.  However, I will say that I have scrutinized the code and I
consider them "safe".  In other words, I did not find anything potentially
harmful in either of them.  I'm not sure where these came from.  They just
showed up one day in one of our anonymous FTP directories.  The
documentation says that they were written by "Natuerlich!".  The shar file
can be found in the archives as "sun-source/mystery.shar" and it is 22783
bytes.  Enjoy!

William LeFebvre

------------------------------

Date:    Thu, 12 May 88 14:21:13 EDT
From:    Chuck Musciano <chuck at trantor.harris-atd.com>
Subject: Tooltool

I have written a new kind of windowed application which allows users to
build windowed tools without using SunView.  By specifying how buttons,
menus, the mouse, and function keys behave using a simple language,
tooltool will handle all the gross window interface code, and you get a
windowed tool faster than you ever thought possible.  For example, I
converted top, everybody's favorite program, into a windowed tool,
complete with buttons, menus, an icon, and behavior modification based on
whether the window is open or closed, in about ten minutes.

Tooltool comes complete with 20 pages of documentation, several sample
applications, and a 30 day, money back guarantee. :-)  If you do use
tooltool, please send me your e-mail address, and I'll keep you up to date
on enhancements, new tooltool specifications, and the like.

Chuck Musciano
Advanced Technology Department
Harris Corporation
(407) 727-6131
ARPA: chuck at trantor.harris-atd.com

[[ It comes in four shar files.  These files are in the archives under
"sun-source":  "tooltool.shar.1" (47934 bytes), "tooltool.shar.2" (54002
bytes), "tooltool.shar.3" (36812 bytes),"tooltool.shar.4" (49679 bytes).
--wnl ]]

------------------------------

Date:    Wed, 1 Jun 88 11:42:59 EDT
From:    Chuck Musciano <chuck at trantor.harris-atd.com>
Subject: Console Tool

A recent article discussed a hard copy console output device, which
prompts me to send our version of the desktop console, contool.  Contool
replaces the Sun desktop console, which is created using "cmdtool -C".
The Sun version has several drawbacks.  First, you must always leave it
open, or you won't see console messages.  This uses up valuable screen
real estate.  Second, you have no idea when messages appeared in the
console.  Several times I have arrived in the morning to see "file system
full" in my console, and wonder whether this is just occuring, or happened
eight hours ago.

Contool solves these problems.  You leave it closed on your desktop, and
when a console mesage arrives, it beeps and flashes its icon to let you
know.  Arriving messages are timestamped, so you know when they arrived.
Finally, contool lets you specify certain classes of messages which can be
ignored, so that only really important things show up in your console.
The only drawback is that contool is read-only; it does not let you type
commands a la cmdtool -C.  We like this behavior, since the console does
not become cluttered with unrelated data.

Chuck Musciano
Advanced Technology Department
Harris Corporation
(407) 727-6131
ARPA: chuck at trantor.harris-atd.com

[[ In the archives under "sun-source" as "contool.shar" (39431 bytes).
--wnl ]]

------------------------------

Date:    Tue, 07 Jun 88 12:35:13 -0400
From:    mesard at bbn.com
Subject: pw_line() that elusive yet useful function
Phone:   617-873-1878

Enclosed is a shar file containing a sample program, some poorly pounded
prose, and some hexidecimal numbers.  Together they represent a
half-hearted attempt on my part to reverse engineer the pw_line() function
from the sunwindow library.

The _SunView Programmer's Guide_ says that it "draws a solid of textured
line between two points with a 'brush' of a specified width."  And that's
about all it says.  More than once, I've seen code with calls to pw_line()
commented out usually with a note from the programmer saying "this is
virtually undocumented. sigh."  And in it's place, is usually a for loop
with one or more pw_vector() calls.

I've learned enough about this to satisfy my curiousity and my immediate
needs.  My reason for submitting this is to find out if there's any
interest in this function and why it's cloaked in mystery, as well as to
give others a head start in more fully understanding its parameters and
functionality.

unsigned *Wayne_Mesard();        MESARD at BBN.COM        BBN Labs, Cambridge, MA

[[ In the archives under "sun-source" as "linedemo.shar" (12447 bytes).
--wnl ]]

------------------------------

Date:    Thu, 9 Jun 88 09:26:45 BST
From:    sunuk!roundhouse!kluger at sun.com (Larry Kluger Sun Europe)
Subject: Sample IBM DAI program

A customer (who wishes to remain anonymous) has supplied me with the
following program that they use for data transfer between a Sun
application and an IBM host based application. Permission for unlimited
(with no warranty) usage of the code is granted.

The program uses the Datastream Access Interface (DAI) that is supplied
with Sun Microsystems' SunLink 3270 products SNA3270, (channel attached)
Local3270, and BSC3270.

Regards,

Larry Kluger
European Software Marketing
Sun Microsystems Europe
Camberley, Surrey UK

lkluger at sun.com

ps. Congratulations on issue 100!

[[ Thank you.  This program did not come in the form of a shar file.
Those who are interested can retrieve the file, but they will have to
separate the documentation and the program by hand (it's not that hard,
really).  It is stored under "sun-source" as "dai.example" and it is 32718
bytes.  --wnl ]]

------------------------------

Date:    Sun, 5 Jun 88 13:15:34 edt
From:    flynn at cpsvax.cps.msu.edu (Patrick Flynn)
Subject: Son of Rastool (includes source)

I submitted a teeny program about two months ago which simply puts the
contents of a rasterfile (1 or 8 bits deep) in a window.  After it
appeared I got several suggestions/comments, and Mike Khaw did a
substantial rewrite which cleaned up some problems with backing store
handling and refreshing.  The improved source (thanks, Mike!) appears
below.

Many of my email messages said (in effect):
   "Dear Pat: rastool doesn't work.  Sincerely, <name>."

If the new version doesn't work, let me know, but also let me know the
symptoms!  Does it not compile?  Does it dump core as soon as it starts?
Does it erase /vmunix?  Also, which machine are you running on, and which
version of SunOS?  (I use a 3/110 and 3.5)

I don't expect to make any other changes to rastool.  I was recently told
about the program named touchup, which is in the Sun-Spots archive.  If
people desire a little more functionality (i.e. a full-bore pixel-based
color rasterfile editor), I recomment touchup.  It's *real nice*.

Best,
Pat Flynn
flynn at cpsvax.cps.msu.edu
ihnp4!msudoc!flynn <= unreliable
FLYNN at MSUEGR.BITNET

p.s. wow! 100 issues of sun-spots in 5 months!  do ya think we can make it
to 1000 by december? :-)  [[ I hope not!  --wnl ]]

==============================================================================
/*
 * rastool: display a rasterfile in a sun window
 * written by Pat Flynn (flynn at cpsvax.cps.msu.edu)
 * fixed colormap bug, added resize handler: Mike Khaw (mkhaw at teknowledge.arpa)
 *
 * Compile with: cc -o rastool rastool.c -lsuntool -lsunwindow -lpixrect
 *
 * Usage: rastool < rasterfile
 *
 */

#include <stdio.h> 
#include <errno.h>
#include <sys/types.h>
#include <pixrect/pixrect.h>
#include <pixrect/pr_io.h>
#include <suntool/sunview.h> 
#include <suntool/canvas.h>

struct pixrect *img;

main(argc,argv)
  int argc;
  char *argv[];
  {
    extern struct pixrect *pr_load_image();
    int can_size_eh();
    extern int errno;
    Frame base_frame;
    Canvas canvas;
    Pixwin *canpixwin;
    char colormapname[256];
    struct rasterfile rh;
    FILE *fp = stdin;
    static u_char red[256], green[256], blue[256];
    static colormap_t colormap = { RMT_NONE, 0, { red, green, blue } };
    colormap_t *colormap_ptr = &colormap;

    errno = 0;
    if (pr_load_header(fp, &rh)) {
      perror("rastool: pr_load_header");
      exit(errno);
      }
    if (rh.ras_maptype == RMT_NONE)
      colormap_ptr = (colormap_t *) NULL;
    else {
      colormap.type = rh.ras_maptype;
      colormap.length = rh.ras_maplength/3;
      }
    errno = 0;
    if (pr_load_colormap(fp, &rh, colormap_ptr)) {
      perror("rastool: pr_load_colormap");
      exit(errno);
      }
    errno = 0;
    if (!(img = pr_load_image(fp, &rh, colormap_ptr))) {
      perror("rastool: pr_load_image");
      exit(errno);
      };
    base_frame = window_create(NULL, FRAME, FRAME_LABEL, "rastool",
                               WIN_WIDTH, 9 + rh.ras_width,
                               WIN_HEIGHT, 22 + rh.ras_height,
                               FRAME_ARGS, argc, argv, 0);
        /*
         * can't set a deep enough canvas backing store until
         * colormap is set
         */
     canvas=window_create(base_frame,CANVAS,CANVAS_RETAINED,FALSE,0);
     canpixwin = canvas_pixwin(canvas);
     sprintf(colormapname, "rastool%d", getpid());
     pw_setcmsname(canpixwin, colormapname);
     pw_putcolormap(canpixwin, 0, colormap.length,
          colormap.map[0], colormap.map[1], colormap.map[2]);
     /* now set canvas backing store, resize handler, etc. */
     window_set(canvas,CANVAS_RETAINED,TRUE,
                CANVAS_RESIZE_PROC,can_size_eh,CANVAS_WIDTH,rh.ras_width,
                CANVAS_HEIGHT,rh.ras_height,CANVAS_DEPTH,rh.ras_depth, 0);
     pw_rop(canpixwin,0,0,rh.ras_width,rh.ras_height,PIX_SRC,img,0,0);
     window_main_loop(base_frame);
  }

static int can_size_eh(canvas, width, height)
  Canvas canvas;
  int width;
  int height;
  {
    Pixwin *pixwin;
    pixwin = canvas_pixwin(canvas);
    pw_rop(pixwin,0,0,width,height,PIX_SRC,img,0,0);
}

------------------------------

Date:    Tue, 17 May 88 09:19:56 EDT
From:    gfr%wolfgang at gateway.mitre.org (Glenn Roberts)
Subject: Sun rasterfile to DEC sixel converter (includes source)

A number of people have asked about a Unix filter I mentioned in a recent
Sun-Spots for converting Sun rasterfiles to DEC's "sixel" format.  We use
this to allow us to do screen dumps on our LN03 (via SunLink DNI), but it
could be converted to support other DEC printers such as the LCG01.
Anyway, here is the code ...

/* 
** lasersun
**
** converts standard raster image file from Sun format
** (read from stdin) to  DEC "sixel" graphics format,
** printable on an LN03.  Output written to stdout.
**
**
** usage:   lasersun
**
** Author:  Dr. Glenn F. Roberts
**          MITRE corp., Mail Stop W335
**          7525 Colshire Drive, McLean, VA, 22102
**          gfr%wolfgang at gateway.mitre.org
**
** Last revision:
**          1.0            March 30, 1987
**
** Use this script to print screen via SunLink DNI (also add entry
** in /usr/lib/rootmenu to point to this script):
**
**  sleep 2
**  screendump -f /dev/bwtwo0 | lasersun | dnacp - 'vax::laser'
**
**
*/

#include <stdio.h>
#include <rasterfile.h>

/*
** defaults to describe nice layout for full screen print
*/
#define OUT_LINE_LEN	1152
#define LINE_LEN	OUT_LINE_LEN/8
#define H_OFFSET	286
#define V_OFFSET	345
#define PIX_SIZE	2

char	scan_line[LINE_LEN];
char	output_line[OUT_LINE_LEN];
struct	rasterfile hdr;

main (argc, argv)
int argc;
char *argv[];
{
  int i, j, row, char_count;
  char this_char, last_char;

  /*
  ** read header
  */
  if (fread(&hdr, sizeof(hdr), 1, stdin) == 0) {
    fprintf(stderr, "Error reading pixrect header\n");
    exit(1);
  }

  /*
  ** validate header data
  */
  if (hdr.ras_magic != RAS_MAGIC) {
    fprintf(stderr, "Not a raster image file !\n");
    exit(1);
  }
  if (hdr.ras_type != RT_STANDARD) {
    fprintf(stderr, "Raster type is %d\n", hdr.ras_type);
    fprintf(stderr, "Only RT_STANDARD (type %d) is supported!\n", 
	RT_STANDARD);
    exit(1);
  }
  if (hdr.ras_depth != 1) {
    fprintf(stderr, "Pixel depth is %d\n", hdr.ras_depth);
    fprintf(stderr, "Only monochrome images are supported!\n");
    exit(1);
  }
  if (hdr.ras_width > OUT_LINE_LEN) {
    fprintf(stderr, "Image is too wide\n");
    fprintf(stderr, "Maximum supported width is %d\n", OUT_LINE_LEN);
    exit(1);
  }

  /*
  ** set up LN03
  */
  printf("\033[?21 J");		/* landscape mode       (PFS) */
  printf("\033[7 I");		/* pixels are 1/300th   (SSU) */
  printf("\033[11h");		/* move by pixels       (PUM) */
  printf("\033[%da", H_OFFSET);	/* move relative right  (HPR) */
  printf("\033[%de", V_OFFSET);	/* move relative down   (VPR) */

  /*
  ** introduce sixel stream
  */
  printf("\033P0;0;%dq\"100;100", PIX_SIZE);

  /* 
  ** loop over scan lines in groups of 6
  */
  for (row=0; row<(hdr.ras_height/6); row++) {
    for (i=0; i<OUT_LINE_LEN; i++)
      output_line[i] = '\0';
    for (i=0; i<6; i++) {
      fread(scan_line, (hdr.ras_width>>3), 1, stdin);
      store_line(scan_line, (hdr.ras_width>>3), i);
    }

    /*
    ** six rows complete; convert line to sixel data
    ** (run length encode repeats of more than 3 )
    */
    last_char = '\0';
    char_count = 0;
    for (i=0; i<hdr.ras_width; i++) {
      this_char = output_line[i] + '\077';
      if (this_char != last_char) {
	output(last_char, char_count);
        last_char = this_char;
        char_count = 1;
      }
      else
        char_count++;
    }

    /* 
    ** flush unprinted characters, then graphic new-line 
    */
    output(last_char, char_count);
    printf("-\n");
  }

  /*
  ** terminate the sixel stream with an ST 
  */
  printf("\033\\\n");
}


/*
** output -- output one or more characters.
** Use run length encoding for repeats of more
** than three characters.
*/
output(c, n)
char c;
int n;
{
  int j;

  if (n > 3)
    printf("!%d%c", n, c);
  else
    for (j=0; j<n; j++)
      putchar(c);
}


/*
** store_line -- convert row-oriented scan line data
** to column oriented sixel data.  r is the sixel row
** (from 0 to 5).
*/
store_line(line, length, r)
char *line;
int length, r;
{
  int i, j, col, mask;
  char ich;

  mask = 1 << r;
  /* loop over bytes per line */
  for (col=0,i=0; i<length; i++) {
    ich = line[i];
    /* loop over 8 bits per byte */
    for (j=col+7; j>=col; j--) {
      if (ich & 1)
        output_line[j] |= mask;
      ich = ich >> 1;
    }
    col += 8;
  }
}

------------------------------

End of SUN-Spots Digest
***********************



More information about the Comp.sys.sun mailing list