mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 08:30:59 +00:00
Move example.service and md5Digest.app to usr-apps/examples/gui/ExampleService/.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@18099 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
e74cf34dc6
commit
266578092f
5 changed files with 7 additions and 524 deletions
|
@ -1,3 +1,9 @@
|
|||
2003-11-19 17:06 Alexander Malmberg <alexander@malmberg.org>
|
||||
|
||||
* Tools/GNUmakefile, Tools/example.m, Tools/exampleInfo.plist,
|
||||
Tools/md5Digest.m: Move example.service and md5Digest.app to
|
||||
usr-apps/examples/gui/ExampleService/.
|
||||
|
||||
2003-11-19 Adam Fedor <fedor@gnu.org>
|
||||
|
||||
* Window Focus fixes.
|
||||
|
|
|
@ -29,21 +29,16 @@ include ../config.make
|
|||
include ../Version
|
||||
|
||||
SUBPROJECTS = $(BUILD_GSND)
|
||||
APP_NAME = md5Digest
|
||||
TOOL_NAME = make_services set_show_service gopen
|
||||
SERVICE_NAME = example GSspell
|
||||
SERVICE_NAME = GSspell
|
||||
|
||||
# The source files to be compiled
|
||||
md5Digest_OBJC_FILES = md5Digest.m
|
||||
|
||||
gopen_OBJC_FILES = gopen.m
|
||||
|
||||
make_services_OBJC_FILES = make_services.m
|
||||
|
||||
set_show_service_OBJC_FILES = set_show_service.m
|
||||
|
||||
example_OBJC_FILES = example.m
|
||||
|
||||
GSspell_OBJC_FILES = GSspell.m
|
||||
|
||||
include GNUmakefile.preamble
|
||||
|
@ -52,7 +47,6 @@ include GNUmakefile.preamble
|
|||
|
||||
GNUSTEP_MAKE_SERVICES=./$(GNUSTEP_OBJ_DIR)/make_services
|
||||
|
||||
include $(GNUSTEP_MAKEFILES)/application.make
|
||||
include $(GNUSTEP_MAKEFILES)/tool.make
|
||||
include $(GNUSTEP_MAKEFILES)/service.make
|
||||
include $(GNUSTEP_MAKEFILES)/aggregate.make
|
||||
|
|
363
Tools/example.m
363
Tools/example.m
|
@ -1,363 +0,0 @@
|
|||
/*
|
||||
example.m
|
||||
|
||||
GNUstep example services facility
|
||||
|
||||
Copyright (C) 1998 Free Software Foundation, Inc.
|
||||
|
||||
Author: Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
Date: November 1998
|
||||
|
||||
This file is part of the GNUstep Project
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
You should have received a copy of the GNU General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
*/
|
||||
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <Foundation/NSDictionary.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSRunLoop.h>
|
||||
#include <Foundation/NSProcessInfo.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSTask.h>
|
||||
#include <Foundation/NSUserDefaults.h>
|
||||
#include <AppKit/NSApplication.h>
|
||||
#include <AppKit/NSPasteboard.h>
|
||||
|
||||
#include "wgetopt.h"
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#ifndef NSIG
|
||||
#define NSIG 32
|
||||
#endif
|
||||
|
||||
@interface ExampleServices : NSObject
|
||||
- (void) md5: (NSPasteboard*)bp
|
||||
userData: (NSString*)ud
|
||||
error: (NSString**)err;
|
||||
- (void) openURL: (NSPasteboard*)bp
|
||||
userData: (NSString*)ud
|
||||
error: (NSString**)err;
|
||||
- (void) tolower: (NSPasteboard*)bp
|
||||
userData: (NSString*)ud
|
||||
error: (NSString**)err;
|
||||
- (void) toupper: (NSPasteboard*)bp
|
||||
userData: (NSString*)ud
|
||||
error: (NSString**)err;
|
||||
@end
|
||||
|
||||
@implementation ExampleServices
|
||||
|
||||
/**
|
||||
* Filter a string to an md5 digest of its utf8 value.
|
||||
*/
|
||||
- (void) md5: (NSPasteboard*)pb
|
||||
userData: (NSString*)ud
|
||||
error: (NSString**)err
|
||||
{
|
||||
NSArray *types;
|
||||
NSString *val;
|
||||
NSData *data;
|
||||
|
||||
*err = nil;
|
||||
types = [pb types];
|
||||
if (![types containsObject: NSStringPboardType])
|
||||
{
|
||||
*err = @"No string type supplied on pasteboard";
|
||||
return;
|
||||
}
|
||||
|
||||
val = [pb stringForType: NSStringPboardType];
|
||||
if (val == nil)
|
||||
{
|
||||
*err = @"No string value supplied on pasteboard";
|
||||
return;
|
||||
}
|
||||
|
||||
data = [val dataUsingEncoding: NSUTF8StringEncoding];
|
||||
data = [data md5Digest];
|
||||
[pb declareTypes: [NSArray arrayWithObject: @"md5Digest"] owner: nil];
|
||||
[pb setData: data forType: @"md5Digest"];
|
||||
}
|
||||
|
||||
- (void) openURL: (NSPasteboard*)pb
|
||||
userData: (NSString*)ud
|
||||
error: (NSString**)err
|
||||
{
|
||||
NSString *url;
|
||||
NSArray *types;
|
||||
NSArray *args;
|
||||
NSString *path;
|
||||
NSTask *task;
|
||||
NSString *browser;
|
||||
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
|
||||
|
||||
*err = nil;
|
||||
types = [pb types];
|
||||
if (![types containsObject: NSStringPboardType])
|
||||
{
|
||||
*err = @"No string type supplied on pasteboard";
|
||||
return;
|
||||
}
|
||||
|
||||
url = [pb stringForType: NSStringPboardType];
|
||||
if (url == nil)
|
||||
{
|
||||
*err = @"No string value supplied on pasteboard";
|
||||
return;
|
||||
}
|
||||
|
||||
browser = [defs objectForKey:@"NSWebBrowser"];
|
||||
if(!browser || [browser isEqualToString:@""])
|
||||
{
|
||||
browser = @"mozilla -remote \"openURL(%@,new-window)\"";
|
||||
}
|
||||
|
||||
path = @"/bin/sh";
|
||||
args = [NSArray arrayWithObjects:
|
||||
@"-c",
|
||||
[NSString stringWithFormat: browser, url],
|
||||
nil];
|
||||
|
||||
task = [NSTask launchedTaskWithLaunchPath: path
|
||||
arguments: args];
|
||||
}
|
||||
- (void) tolower: (NSPasteboard*)pb
|
||||
userData: (NSString*)ud
|
||||
error: (NSString**)err
|
||||
{
|
||||
NSString *in;
|
||||
NSString *out;
|
||||
NSArray *types;
|
||||
|
||||
*err = nil;
|
||||
types = [pb types];
|
||||
if (![types containsObject: NSStringPboardType])
|
||||
{
|
||||
*err = @"No string type supplied on pasteboard";
|
||||
return;
|
||||
}
|
||||
|
||||
in = [pb stringForType: NSStringPboardType];
|
||||
if (in == nil)
|
||||
{
|
||||
*err = @"No string value supplied on pasteboard";
|
||||
return;
|
||||
}
|
||||
|
||||
out = [in lowercaseString];
|
||||
types = [NSArray arrayWithObject: NSStringPboardType];
|
||||
[pb declareTypes: types owner: nil];
|
||||
[pb setString: out forType: NSStringPboardType];
|
||||
|
||||
}
|
||||
- (void) toupper: (NSPasteboard*)pb
|
||||
userData: (NSString*)ud
|
||||
error: (NSString**)err
|
||||
{
|
||||
NSString *in;
|
||||
NSString *out;
|
||||
NSArray *types;
|
||||
|
||||
*err = nil;
|
||||
types = [pb types];
|
||||
if (![types containsObject: NSStringPboardType])
|
||||
{
|
||||
*err = @"No string type supplied on pasteboard";
|
||||
return;
|
||||
}
|
||||
|
||||
in = [pb stringForType: NSStringPboardType];
|
||||
if (in == nil)
|
||||
{
|
||||
*err = @"No string value supplied on pasteboard";
|
||||
return;
|
||||
}
|
||||
|
||||
out = [in uppercaseString];
|
||||
types = [NSArray arrayWithObject: NSStringPboardType];
|
||||
[pb declareTypes: types owner: nil];
|
||||
[pb setString: out forType: NSStringPboardType];
|
||||
|
||||
}
|
||||
@end
|
||||
|
||||
static int debug = 0;
|
||||
static int verbose = 0;
|
||||
static const char *progName = "example";
|
||||
|
||||
static void
|
||||
ihandler(int sig)
|
||||
{
|
||||
static BOOL beenHere = NO;
|
||||
BOOL action;
|
||||
const char *e;
|
||||
|
||||
/*
|
||||
* Prevent recursion.
|
||||
*/
|
||||
if (beenHere == YES)
|
||||
{
|
||||
abort();
|
||||
}
|
||||
beenHere = YES;
|
||||
|
||||
/*
|
||||
* If asked to terminate, do so cleanly.
|
||||
*/
|
||||
if (sig == SIGTERM)
|
||||
{
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
action = YES; // abort() by default.
|
||||
#else
|
||||
action = NO; // exit() by default.
|
||||
#endif
|
||||
e = getenv("CRASH_ON_ABORT");
|
||||
if (e != 0)
|
||||
{
|
||||
if (strcasecmp(e, "yes") == 0 || strcasecmp(e, "true") == 0)
|
||||
action = YES;
|
||||
else if (strcasecmp(e, "no") == 0 || strcasecmp(e, "false") == 0)
|
||||
action = NO;
|
||||
else if (isdigit(*e) && *e != '0')
|
||||
action = YES;
|
||||
else
|
||||
action = NO;
|
||||
}
|
||||
|
||||
if (action == YES)
|
||||
{
|
||||
abort();
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "%s killed by signal %d\n", progName, sig);
|
||||
exit(sig);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
init(int argc, char** argv)
|
||||
{
|
||||
const char *options = "Hdv";
|
||||
int sym;
|
||||
|
||||
progName = argv[0];
|
||||
while ((sym = getopt(argc, argv, options)) != -1)
|
||||
{
|
||||
switch(sym)
|
||||
{
|
||||
case 'H':
|
||||
printf("%s -[%s]\n", argv[0], options);
|
||||
printf("GNU Services example server\n");
|
||||
printf("-H\tfor help\n");
|
||||
printf("-d\tavoid fork() to make debugging easy\n");
|
||||
exit(EXIT_SUCCESS);
|
||||
|
||||
case 'd':
|
||||
debug++;
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
verbose++;
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("%s - filter server\n", argv[0]);
|
||||
printf("-H for help\n");
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
for (sym = 0; sym < NSIG; sym++)
|
||||
{
|
||||
signal(sym, ihandler);
|
||||
}
|
||||
#ifndef __MINGW__
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
signal(SIGTTOU, SIG_IGN);
|
||||
signal(SIGTTIN, SIG_IGN);
|
||||
signal(SIGHUP, SIG_IGN);
|
||||
#endif
|
||||
signal(SIGTERM, ihandler);
|
||||
|
||||
if (debug == 0)
|
||||
{
|
||||
/*
|
||||
* Now fork off child process to run in background.
|
||||
*/
|
||||
#ifndef __MINGW__
|
||||
switch (fork())
|
||||
{
|
||||
case -1:
|
||||
NSLog(@"gpbs - fork failed - bye.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
case 0:
|
||||
/*
|
||||
* Try to run in background.
|
||||
*/
|
||||
#ifdef NeXT
|
||||
setpgrp(0, getpid());
|
||||
#else
|
||||
setsid();
|
||||
#endif
|
||||
break;
|
||||
|
||||
default:
|
||||
if (verbose)
|
||||
{
|
||||
NSLog(@"Process backgrounded (running as daemon)\r\n");
|
||||
}
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv, char **env)
|
||||
{
|
||||
NSAutoreleasePool *pool;
|
||||
ExampleServices *server;
|
||||
|
||||
#ifdef GS_PASS_ARGUMENTS
|
||||
[NSProcessInfo initializeWithArguments:argv count:argc environment:env];
|
||||
#endif
|
||||
pool = [NSAutoreleasePool new];
|
||||
server = [ExampleServices new];
|
||||
init(argc, argv);
|
||||
|
||||
// [NSObject enableDoubleReleaseCheck: YES];
|
||||
|
||||
if (server == nil)
|
||||
{
|
||||
NSLog(@"Unable to create server object.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
NSRegisterServicesProvider(server, @"ExampleServices");
|
||||
|
||||
[[NSRunLoop currentRunLoop] run];
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
NSServices = (
|
||||
{
|
||||
NSFilter = cat;
|
||||
NSInputMechanism = NSUnixStdio;
|
||||
NSPortName = "/bin/cat";
|
||||
NSSendTypes = (
|
||||
NSFilenamesPboardType
|
||||
);
|
||||
NSReturnTypes = (
|
||||
NSGeneralPboardType
|
||||
);
|
||||
},
|
||||
{
|
||||
NSPortName = ExampleServices;
|
||||
NSFilter = md5;
|
||||
NSSendTypes = (
|
||||
NSStringPboardType
|
||||
);
|
||||
NSReturnTypes = (
|
||||
md5Digest
|
||||
);
|
||||
},
|
||||
{
|
||||
NSPortName = ExampleServices;
|
||||
NSMessage = openURL;
|
||||
NSSendTypes = (
|
||||
NSStringPboardType
|
||||
);
|
||||
NSMenuItem = {
|
||||
default = "Open URL";
|
||||
English = "Open URL";
|
||||
Italian = "Apri URL";
|
||||
German = "URL \U00F6ffnen";
|
||||
};
|
||||
NSKeyEquivalent = {
|
||||
default = O;
|
||||
English = O;
|
||||
};
|
||||
},
|
||||
{
|
||||
NSPortName = ExampleServices;
|
||||
NSMessage = tolower;
|
||||
NSSendTypes = (
|
||||
NSStringPboardType
|
||||
);
|
||||
NSReturnTypes = (
|
||||
NSStringPboardType
|
||||
);
|
||||
NSMenuItem = {
|
||||
default = "To lower";
|
||||
English = "To lower";
|
||||
Italian = "Rendi minuscolo";
|
||||
German = "Klein schreiben";
|
||||
};
|
||||
NSKeyEquivalent = {
|
||||
default = L;
|
||||
English = L;
|
||||
};
|
||||
},
|
||||
{
|
||||
NSPortName = ExampleServices;
|
||||
NSMessage = toupper;
|
||||
NSSendTypes = (
|
||||
NSStringPboardType
|
||||
);
|
||||
NSReturnTypes = (
|
||||
NSStringPboardType
|
||||
);
|
||||
NSMenuItem = {
|
||||
default = "To upper";
|
||||
English = "To upper";
|
||||
Italian = "Rendi maiuscolo";
|
||||
German = "Gro\U00DF schreiben";
|
||||
};
|
||||
NSKeyEquivalent = {
|
||||
default = U;
|
||||
English = U;
|
||||
};
|
||||
}
|
||||
);
|
|
@ -1,74 +0,0 @@
|
|||
/* This tool creates an md5 digest using the example filter
|
||||
based on what type of file is being accessed.
|
||||
|
||||
Copyright (C) 2003 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Rrichard Frith-Macdonald <rfm@gnu.org>
|
||||
Created: June 2003
|
||||
|
||||
This file is part of the GNUstep Project
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
You should have received a copy of the GNU General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
*/
|
||||
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSFileHandle.h>
|
||||
#include <Foundation/NSProcessInfo.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSUserDefaults.h>
|
||||
#include <AppKit/NSPasteboard.h>
|
||||
|
||||
int
|
||||
main(int argc, char** argv, char **env_c)
|
||||
{
|
||||
CREATE_AUTORELEASE_POOL(pool);
|
||||
NSFileHandle *fh;
|
||||
NSData *data;
|
||||
NSString *string;
|
||||
NSPasteboard *pb;
|
||||
NSUserDefaults *defs;
|
||||
|
||||
#ifdef GS_PASS_ARGUMENTS
|
||||
[NSProcessInfo initializeWithArguments:argv count:argc environment:env_c];
|
||||
#endif
|
||||
|
||||
defs = [NSUserDefaults standardUserDefaults];
|
||||
string = [defs stringForKey: @"CatFile"];
|
||||
if (string != nil)
|
||||
{
|
||||
data = [NSSerializer serializePropertyList: string];
|
||||
pb = [NSPasteboard pasteboardByFilteringData: data
|
||||
ofType: NSFilenamesPboardType];
|
||||
NSLog(@"Types: %@", [pb types]);
|
||||
data = [pb dataForType: NSGeneralPboardType];
|
||||
NSLog(@"Got %@", data);
|
||||
}
|
||||
else
|
||||
{
|
||||
NSLog(@"This program expects to read utf8 text from stdin -");
|
||||
fh = [NSFileHandle fileHandleWithStandardInput];
|
||||
data = [fh readDataToEndOfFile];
|
||||
string = [[NSString alloc] initWithData: data
|
||||
encoding: NSUTF8StringEncoding];
|
||||
data = [NSSerializer serializePropertyList: string];
|
||||
|
||||
pb = [NSPasteboard pasteboardByFilteringData: data
|
||||
ofType: NSStringPboardType];
|
||||
NSLog(@"Types: %@", [pb types]);
|
||||
data = [pb dataForType: @"md5Digest"];
|
||||
NSLog(@"Got %@", data);
|
||||
}
|
||||
|
||||
RELEASE(pool);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
Loading…
Reference in a new issue