File:  [NeXTSTEP 3.3 examples] / Examples / UNIX / Subprocess / Coordinator.m
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:48:25 2018 UTC (8 years, 1 month ago) by root
Branches: NeXT, MAIN
CVS tags: NeXTSTEP33, HEAD
Sample Programs from NeXSTEP 3.3

/*
	Coordinator.m
	by Joe Freeman, David LaVallee
	Subprocess Example, Release 2.0
	NeXT Computer, Inc.

	You may freely copy, distribute and reuse the code in this example.
	NeXT disclaims any warranty of any kind, expressed or implied, as to
	its fitness for any particular use.
*/

#import "Coordinator.h"
#import "CommandScroll.h"
#import "Subprocess.h"
#import <appkit/nextstd.h>
#import <appkit/Application.h>
#import <appkit/Panel.h>
#import <objc/NXStringTable.h>

@implementation Coordinator

- showInfo:sender
{
    if (!infoPanel)
    {
	infoPanel =
	    [NXApp loadNibSection:"InfoPanel.nib" owner:NXApp withNames:NO];
    }
    [infoPanel orderFront:self];
    return self;
}

/*==========================================================
 *
 * Subprocess Delegation
 *
 *==========================================================*/
 
- subprocessOutput:(char *)buffer
{
    [commandView appendString:buffer];
    return self;
}

- subprocessDone
{
    [NXApp terminate:self];
    return self;
}

- subprocessError:(const char *)errorString
    // uses stringTable to localize error messages as appropriate,
    // and then displays the message in an alert panel
{
    const char *returnedString;
    
    if ((returnedString = [stringTable valueForStringKey:errorString]))
    {
	NXRunAlertPanel(0, returnedString, 0, 0, 0);
    }
    else
    {
	NXRunAlertPanel(0, errorString, 0, 0, 0);
    }
    return self;
}

/*==========================================================
 *
 * CommandScroll Delegation
 *
 *==========================================================*/
 
- userEntered:(char *)buffer
{
    [theSubprocess send:buffer withNewline:NO];
    return self;
}

/*==========================================================
 *
 * Application Object Delegation
 *
 *==========================================================*/

- appDidInit:sender
{
    theSubprocess =
	[[Subprocess alloc]
	    init:"/bin/sh" withDelegate:self andPtySupport:YES andStdErr:YES];
    return self;
}

- appWillTerminate:sender
{
    [theSubprocess terminate:sender];
    return self;
}

@end

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.