Term-Gnuplot
view release on metacpan or search on metacpan
gnuterm/term/openstep.trm view on Meta::CPAN
NEXTsize *= 2;
NEXTBuffer = realloc(NEXTBuffer, NEXTsize);
NEXTBufEnd = NEXTBuffer + NEXTsize;
NEXTBufAt = NEXTBuffer + NEXToff;
}
*NEXTBufAt = *pb;
}
return;
}
/* This next section implements the GnuTermDriver object which manages
the D.O. connection and interface to Obj-C
*/
@protocol GnuTermServerMethods
/*- (oneway) executePScode:(in char *)PStext termTitle:(in char *)title;*/
- (void) executePScode:(NSString *) PStext termTitle:(NSString *) title;
@end
@implementation GnuTermDriver
- init
{
NSConnection *myConnection;
char serverpath[100], *envstring;
int GnuTermPathSet = 0;
/* Ask OS for connection to server */
server = [NSConnection rootProxyForConnectionWithRegisteredName: @"gnuplotServer" host:nil];
[server retain];
/* Server is running ready to go */
if (server) printf("Connected to server\n")
;
/* Server isn't running, we must fire it up */
else {
printf("Launching GnuTerm\n");
*serverpath = 0;
/* Check for path set in environment */
if ((envstring = getenv("GNUTERMPATH")) != (char *) NULL) {
sprintf(serverpath, "%s/GnuTerm.app/GnuTerm", envstring);
GnuTermPathSet = 1;
}
/* Not in environment */
else
strcpy(serverpath, "GnuTerm");
/* Try to launch application */
if ([[NSWorkspace sharedWorkspace] launchApplication:[NSString stringWithCString:serverpath]] == NO) {
printf("Failed to launch %s.\n", serverpath);
/* Offer a little advice */
if (GnuTermPathSet) {
printf("You must have setenv GNUTERMPATH to something wrong\n");
printf("I recommend you exit gnuplot and fix this.\n");
} else {
printf("It must be located in ~/Apps or /LocalApps\n");
printf("I recommend that you either\n");
printf("- move GnuTerm.app to one of these locations\n");
printf("- set GNUTERMPATH with host%% setenv GNUTERMPATH /directory/containing_GnuTerm.app\n");
printf("- start GnuTerm ahead of the first plot command\n");
}
}
/* I wish the gnuplot terminal interface would
let me return an error here.
*/
/* Application is launching */
else {
/* Wait for it to register Server methods with OS */
do {
server =[[NSConnection
rootProxyForConnectionWithRegisteredName: @"gnuplotServer" host:nil] retain];
} while (!server); /* This could result in a hang,
but I've never seen it fail */
}
}
/* By limiting ourselves to known protocol
* we speed up the messaging
*/
[server setProtocolForProxy:@protocol(GnuTermServerMethods)];
myConnection = [server connectionForProxy];
/* If the server dies we want to know about it */
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(senderIsInvalid:) name:NSConnectionDidDieNotification object:myConnection];
/* In fact, we'll worry about it */
;
return self;
}
- (void) plot:(char *)PSstr;
{
/* If server has become invalid, re-initialize */
if (!server)
[self init];
/* This is where we send the huge postscript string to the server
Note:
The D.O. system doesn't actually give this pointer to the server.
The pointer is dereferenced on the client side and the
resulting data is sent to the server. On the server side,
space for the data is automatically allocated, and a pointer to
the local data is received.
For details check out:
/NextLibrary/Documentation/NextDev/GeneralRef/06_DistributedObjects/IntroDistObjects.rtf
*/
printf("Calling server...");
[server executePScode: [NSString stringWithCString: PSstr]
termTitle: [NSString stringWithCString: NEXT_title]];
printf("returned\n");
*NEXT_title = 0;
}
/* This gets called by OS if server goes down */
( run in 1.006 second using v1.01-cache-2.11-cpan-2398b32b56e )