[comp.windows.news] Long winded problem with cps.

earley@modular.UUCP (Joe Earley) (10/12/90)

We have an application which is talking to the NeWS server using the cps
facilities of OpenWindows 2.0.  The code we use to open the server connection
from an XView application is:

------------
crtps_open()
  {
  Frame crt_frame();
  NeWStoken newstoken;

  if ( PostScript || PostScriptInput )
    ps_close_PostScript();
  
  if ( ps_open_PostScript() == 0 )
    {
    fprintf( stderr, "crtps_open: could not open PostScript socket\n" );
    return( -1 );
    }

  if ( ! ps_token_from_xid( xv_get( crt_canvas(), XV_XID ), &newstoken ) )
    {
    fprintf( stderr, "crtps_open: could not get canvas token\n" );
    return( -1 );
    }

  ps_setcanvas( newstoken );
  crtps_init( newstoken );
  ps_flush_PostScript();
  return( psio_fileno( PostScriptInput ) );
  }
------------

The code used to look for input from the socket is:

------------
int crtps_input(client, fd)
Notify_client client;
int fd;
  {
  char buf[ 8 * 1024 ];
  int check_return, peek_return, tag;
    
  while ( 1 )
    {
    if ( (check_return = ps_check_input()) == -1 )
      fprintf( stderr, "crtps: error returned from ps_check_input\n" );
    else if ( check_return == 0 )      
      return NOTIFY_DONE;
    else
      {
      peek_return = ps_peek_tag( &tag );
      if ( peek_return  < 1 )
	{
	fprintf( stderr, "crtps: ps_peek_tag = %d\n", peek_return );
	ps_skip_input_value();
        psio_clearerr( PostScriptInput );
	}
      else
	{
        .
        . code to handle the tagged info
	.
	}
      }
    }
  }
------------


The crtps_input function is called whenever the XView canvas gets input:

------------
	crt.psfd = crtps_open();
	if( crt.psfd >= 0 )
	  notify_set_input_func(handles+H_PS, crtps_input, crt.psfd);
------------

What I'm are trying to accomplish here is to get an XView vt220 terminal
emulator to display PostScript graphics.  We surround a stream of NeWS code
with escape sequences.  The NeWS code will overlay the vt220 canvas
with a new canvas that will be used to draw the report.
(Eventually we should have a set of graphics report classes that require us
to only send down the code to create the instance of the type of report we
want along with data and any code we need to override the class defaults.)
I've got the basic part of this working.

I'm also trying to create new canvases off of the framebuffer and
am getting errors. The test code I'm sending to the server is this:

----t8.ps file---
createevent dup
    /Name (ChildMessage) put
expressinterest

{
    (news/t9.ps) (r) file cvx exec
} fork pop

{
    awaitevent
    /Name get (ChildMessage) eq {
	console (Got event from child!) fprintf
	exit
    } if
} loop
----------------

----t9.ps file---
%
% Create a Pit Canvas class
%
/PitClassCanvas ClassCanvas []
classbegin
    /PaintCanvas { % - -> -
	/PaintCanvas super send
	/size self send 2 div exch 2 div exch moveto
    } def
classend def

%
% Make a PitCanvas
%
/PitCanvas framebuffer /new PitClassCanvas send def
/PitFrame PitCanvas [] framebuffer /newdefault OpenLookBaseFrame send def
/reshapefromuser PitFrame send
/activate PitFrame send
/map PitFrame send

createevent dup
    /Name (ChildMessage) put
sendevent
-----------------

I can run the t8.ps file with psh and get the "Got event..." message on the
console and the new window.  But when I run this through the XView application
I'm getting a continous stream of

crtps: ps_peek_tag = -1
crtps: ps_peek_tag = -1
crtps: ps_peek_tag = -1
.
.
.

in the console window.  What have I forgotten or not learned from reading the
NeWS 2.1 Programmers Guide?

And just in case it is important the cps file to handle this interface is:

---------------
#include "pstags.h"
C: #include "pstags.h"

cdef crtps_get_data( string buf )  => DATA_TAG ( buf )
cdef crtps_get_error( string buf ) => ERROR_TAG ( buf )

cdef crtps_init( canvastoken )
    /crt_canvas canvastoken getfileinputtoken def
    crt_canvas setcanvas
    %
    % flip the X coordinates into NeWS coordinates
    %
    clippath pathbbox 0 exch translate pop pop pop 1 -1 scale
    (.crtinit.ps) LoadFile
----------------

where pstags.h is:

----------------
#ifdef notdef
  % This file contains the definitions of the tags that are used to
  % communicate information from the server back to the crttool program.
  % (Everything between ifdef and endif is a comment.)
#endif

#define DATA_TAG    1
#define ERROR_TAG   2
----------------

I hope this is enough information to get a few answers, hints, or
"RTFM on page xxx" flames.

Joe Earley, Modular Mining Systems
USENET:     {uunet}!arizona!modular!earley
INTERNET:   modular!earley@arizona.edu

flar@bendenweyr.Eng.Sun.COM (Jim Graham) (10/16/90)

Usually the only reason to get an error (-1 return value) from ps_peek_tag()
is due to the file being closed.  Usually the only reasons for the file
to be closed are either you closed it yourself, or an error caused your
PostScript process to die and its connection to be closed.

Since you are getting a continuous stream of error messages on your console,
you may not be seeing a PostScript error message go by at high speed.  Try
putting an exit() after the error message so that you don't scroll the PS
error off the console (or using a console with a scrollbar, or redirecting
the stderr output of the server to a file so that you don't lose a record
of the errors).

					...jim