mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
Add operatingSystemVersionString method to NSProcessInfo
Clean-up and streamline NSLog, limiting customisation to simply over-riding the printf handler Preparing for better support for logging to eventlog git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/branches/mswin-ng@23715 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
d95e1b35aa
commit
80e69de2a6
7 changed files with 286 additions and 316 deletions
15
ChangeLog
15
ChangeLog
|
@ -1,3 +1,18 @@
|
|||
2006-09-20 Sheldon Gill <sheldon@westnet.net.au>
|
||||
|
||||
* Headers/Foundation/NSProcessInfo.h
|
||||
* Source/NSProcessInfo.m:
|
||||
Add operatingSystemVersionString
|
||||
Change return of operatingSystem to useful
|
||||
* Headers/Foundation/NSObjCRuntime.h:
|
||||
* Source/NSLog.m:
|
||||
Remove _NSLogDescriptor customisation
|
||||
|
||||
2006-09-19 Sheldon Gill <sheldon@westnet.net.au>
|
||||
|
||||
* Source/NSString.m:
|
||||
Note where we should add UTF32 detection
|
||||
|
||||
2006-09-18 Sheldon Gill <sheldon@westnet.net.au>
|
||||
|
||||
* Source/NSTask.m:
|
||||
|
|
|
@ -47,13 +47,10 @@ GS_EXPORT const char *NSGetSizeAndAlignment(const char *typePtr,
|
|||
/**
|
||||
* OpenStep spec states that log messages go to stderr, but just in case
|
||||
* someone wants them to go somewhere else, they can implement a function
|
||||
* like this and assign a pointer to it to _NSLog_printf_handler.
|
||||
* like this and assign a pointer to it in _NSLog_printf_handler.
|
||||
*/
|
||||
typedef void NSLog_printf_handler (NSString* message);
|
||||
GS_EXPORT NSLog_printf_handler *_NSLog_printf_handler;
|
||||
GS_EXPORT int _NSLogDescriptor;
|
||||
@class NSRecursiveLock;
|
||||
GS_EXPORT NSRecursiveLock *GSLogLock(void);
|
||||
#endif
|
||||
|
||||
GS_EXPORT void NSLog (NSString *format, ...);
|
||||
|
|
|
@ -54,28 +54,31 @@ enum {
|
|||
NSMACHOperatingSystem,
|
||||
NSSunOSOperatingSystem,
|
||||
NSOSF1OperatingSystem,
|
||||
NSGNULinuxOperatingSystem = 100,
|
||||
NSBSDOperatingSystem,
|
||||
NSBeOperatingSystem,
|
||||
NSCygwinOperatingSystem
|
||||
GSGNULinuxOperatingSystem = 100,
|
||||
GSBSDOperatingSystem,
|
||||
GSBeOperatingSystem,
|
||||
GSCygwinOperatingSystem
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
@interface NSProcessInfo: NSObject
|
||||
|
||||
+ (NSProcessInfo*) processInfo;
|
||||
+ (NSProcessInfo *) processInfo;
|
||||
|
||||
- (NSArray*) arguments;
|
||||
- (NSDictionary*) environment;
|
||||
- (NSString*) globallyUniqueString;
|
||||
- (NSString*) hostName;
|
||||
- (NSArray *) arguments;
|
||||
- (NSDictionary *) environment;
|
||||
- (NSString *) globallyUniqueString;
|
||||
- (NSString *) hostName;
|
||||
#ifndef STRICT_OPENSTEP
|
||||
- (unsigned int) operatingSystem;
|
||||
- (NSString*) operatingSystemName;
|
||||
- (NSString *) operatingSystemName;
|
||||
- (int) processIdentifier;
|
||||
#endif
|
||||
- (NSString*) processName;
|
||||
- (NSString *) processName;
|
||||
#if OS_API_VERSION(100200,GS_API_LATEST) && GS_API_VERSION(011400,GS_API_LATEST)
|
||||
- (NSString *) operatingSystemVersionString;
|
||||
#endif
|
||||
|
||||
- (void) setProcessName: (NSString*)newName;
|
||||
|
||||
|
@ -87,7 +90,7 @@ enum {
|
|||
- (BOOL) debugLoggingEnabled;
|
||||
- (NSMutableSet*) debugSet;
|
||||
- (void) setDebugLoggingEnabled: (BOOL)flag;
|
||||
- (BOOL) setLogFile: (NSString*)path;
|
||||
//- (BOOL) setLogFile: (NSString*)path; DEPRECATED-DELETED
|
||||
+ (void) initializeWithArguments: (char**)argv
|
||||
count: (int)argc
|
||||
environment: (char**)env;
|
||||
|
|
350
Source/NSLog.m
350
Source/NSLog.m
|
@ -4,6 +4,9 @@
|
|||
Written by: Adam Fedor <fedor@boulder.colorado.edu>
|
||||
Date: November 1996
|
||||
|
||||
Modified: Sheldon Gill <sheldon@westnet.net.au>
|
||||
Date: September 2006
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
|
@ -37,167 +40,147 @@
|
|||
#include "Foundation/NSData.h"
|
||||
#include "Foundation/NSThread.h"
|
||||
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
#include <syslog.h>
|
||||
#endif
|
||||
|
||||
#define UNISTR(X) \
|
||||
((const unichar*)[(X) cStringUsingEncoding: NSUnicodeStringEncoding])
|
||||
|
||||
#if defined(HAVE_SYSLOG)
|
||||
# if defined(LOG_ERR)
|
||||
# if defined(LOG_USER)
|
||||
# define SYSLOGMASK (LOG_ERR|LOG_USER)
|
||||
# else
|
||||
# define SYSLOGMASK (LOG_ERR)
|
||||
# endif // LOG_USER
|
||||
# elif defined(LOG_ERROR)
|
||||
# if defined(LOG_USER)
|
||||
# define SYSLOGMASK (LOG_ERROR|LOG_USER)
|
||||
# else
|
||||
# define SYSLOGMASK (LOG_ERROR)
|
||||
# endif // LOG_USER
|
||||
# else
|
||||
# error "Help, I can't find a logging level for syslog"
|
||||
# endif
|
||||
#endif // HAVE_SYSLOG
|
||||
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "GSPrivate.h"
|
||||
|
||||
extern NSThread *GSCurrentThread();
|
||||
extern NSThread *GSCurrentThread(); // why isn't this in GSPrivate.h ?? -SG
|
||||
|
||||
/**
|
||||
// From "Win32Support.h"
|
||||
#define UNISTR(X) \
|
||||
((const unichar*)[(X) cStringUsingEncoding: NSUnicodeStringEncoding])
|
||||
|
||||
// From private base shared functions
|
||||
void crash(char *description);
|
||||
|
||||
void crash(char *description)
|
||||
{
|
||||
#if defined(__MINGW32__)
|
||||
ExitProcess(-1);
|
||||
#else
|
||||
abort();
|
||||
#endif
|
||||
}
|
||||
|
||||
/* DEPRECATED - DELETED Base 1.14 => we don't support this anymore
|
||||
*
|
||||
* We delete these entirely. Simpler, faster, smaller
|
||||
*
|
||||
* A variable holding the file descriptor to which NSLogv() messages are
|
||||
* written by default. GNUstep initialises this to stderr.<br />
|
||||
* You may change this, but for thread safety should
|
||||
* use the lock provided by GSLogLock() to protect the change.
|
||||
*
|
||||
* int _NSLogDescriptor = 2;
|
||||
*
|
||||
* static NSRecursiveLock *myLock = nil;
|
||||
* NSRecursiveLock *GSLogLock();
|
||||
*
|
||||
* You can over-ride the printf_handler and do whatever you like...
|
||||
* so we don't need the _NSLogDescriptor as another customisation method
|
||||
*
|
||||
* A pointer store is atomic so the lock isn't needed. (x86, PPC, sparc)
|
||||
* Besides which, that are you doing! Trying to change the handler multiple
|
||||
* times in different threads? Please! -SG
|
||||
*/
|
||||
int _NSLogDescriptor = 2;
|
||||
|
||||
static NSRecursiveLock *myLock = nil;
|
||||
|
||||
/**
|
||||
* Returns the lock used to protect the GNUstep NSLogv() implementation.
|
||||
* Use this to protect changes to
|
||||
* <ref type="variable" id="_NSLogDescriptor">_NSLogDescriptor</ref> and
|
||||
* <ref type="variable" id="_NSLog_printf_handler">_NSLog_printf_handler</ref>
|
||||
*/
|
||||
NSRecursiveLock *
|
||||
GSLogLock()
|
||||
{
|
||||
if (myLock == nil)
|
||||
{
|
||||
[gnustep_global_lock lock];
|
||||
if (myLock == nil)
|
||||
{
|
||||
myLock = [NSRecursiveLock new];
|
||||
}
|
||||
[gnustep_global_lock unlock];
|
||||
}
|
||||
return myLock;
|
||||
}
|
||||
|
||||
#if defined(__MINGW32__)
|
||||
static void
|
||||
_NSLog_standard_printf_handler (NSString* message)
|
||||
send_event_to_eventlog(WORD eventtype, LPCWSTR msgbuffer)
|
||||
{
|
||||
NSData *d;
|
||||
const char *buf;
|
||||
unsigned len;
|
||||
#if defined(__MINGW32__)
|
||||
LPCWSTR null_terminated_buf;
|
||||
#else
|
||||
#if defined(HAVE_SYSLOG)
|
||||
char *null_terminated_buf;
|
||||
#endif
|
||||
#endif
|
||||
static NSStringEncoding enc = 0;
|
||||
static HANDLE eventloghandle = 0;
|
||||
|
||||
if (enc == 0)
|
||||
if (!eventloghandle)
|
||||
{
|
||||
enc = [NSString defaultCStringEncoding];
|
||||
// FIXME: Need a mechanism for a more descriptive registration -SG
|
||||
eventloghandle = RegisterEventSourceW(NULL,
|
||||
UNISTR([[NSProcessInfo processInfo] processName]));
|
||||
}
|
||||
d = [message dataUsingEncoding: enc allowLossyConversion: NO];
|
||||
if (d == nil)
|
||||
if (eventloghandle)
|
||||
{
|
||||
d = [message dataUsingEncoding: NSUTF8StringEncoding
|
||||
allowLossyConversion: NO];
|
||||
}
|
||||
|
||||
if (d == nil) // Should never happen.
|
||||
{
|
||||
buf = [message lossyCString];
|
||||
len = strlen(buf);
|
||||
ReportEventW(eventloghandle, // event log handle
|
||||
eventtype, // event type
|
||||
0, // category zero
|
||||
0, // event identifier
|
||||
NULL, // security identifier
|
||||
1, // num substitution string
|
||||
0, // num data for substitution
|
||||
&msgbuffer, // message string array
|
||||
NULL); // pointer to data
|
||||
}
|
||||
else
|
||||
{
|
||||
buf = (const char*)[d bytes];
|
||||
len = [d length];
|
||||
[NSException raise: NSGenericException
|
||||
format: @"Couldn't get handle for eventlog"];
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(__MINGW32__)
|
||||
null_terminated_buf = UNISTR(message);
|
||||
static void
|
||||
_GSLog_standard_printf_handler(NSString* message)
|
||||
{
|
||||
static HANDLE hStdErr = NULL;
|
||||
LPCWSTR null_terminated_buf = UNISTR(message);
|
||||
DWORD bytes_out;
|
||||
|
||||
OutputDebugStringW(null_terminated_buf);
|
||||
#ifndef RELEASE_VERSION
|
||||
if (IsDebuggerPresent())
|
||||
OutputDebugStringW(null_terminated_buf);
|
||||
#endif
|
||||
|
||||
if ((GSUserDefaultsFlag(GSLogSyslog) == YES
|
||||
|| write(_NSLogDescriptor, buf, len) != (int)len) && !IsDebuggerPresent())
|
||||
if (hStdErr == NULL)
|
||||
hStdErr = GetStdHandle(STD_ERROR_HANDLE);
|
||||
|
||||
if ((GSUserDefaultsFlag(GSLogSyslog) == YES) || (hStdErr == NULL))
|
||||
{
|
||||
static HANDLE eventloghandle = 0;
|
||||
|
||||
if (!eventloghandle)
|
||||
{
|
||||
eventloghandle = RegisterEventSourceW(NULL,
|
||||
UNISTR([[NSProcessInfo processInfo] processName]));
|
||||
}
|
||||
if (eventloghandle)
|
||||
{
|
||||
ReportEventW(eventloghandle, // event log handle
|
||||
EVENTLOG_WARNING_TYPE, // event type
|
||||
0, // category zero
|
||||
0, // event identifier
|
||||
NULL, // no user security identifier
|
||||
1, // one substitution string
|
||||
0, // no data
|
||||
&null_terminated_buf, // pointer to string array
|
||||
NULL); // pointer to data
|
||||
}
|
||||
send_event_to_eventlog(EVENTLOG_ERROR_TYPE, null_terminated_buf);
|
||||
}
|
||||
#else
|
||||
|
||||
#if defined(HAVE_SYSLOG)
|
||||
else
|
||||
{
|
||||
if (!WriteFile(hStdErr, null_terminated_buf,
|
||||
wcslen(null_terminated_buf)*2,
|
||||
&bytes_out, NULL))
|
||||
{
|
||||
send_event_to_eventlog(EVENTLOG_ERROR_TYPE, null_terminated_buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
#else // *nix version
|
||||
|
||||
int _NSLogDescriptor = 2;
|
||||
|
||||
static void
|
||||
_GSLog_standard_printf_handler(NSString* message)
|
||||
{
|
||||
const char *buf;
|
||||
unsigned len;
|
||||
|
||||
buf = [message cStringUsingEncoding: NSUTF8StringEncoding];
|
||||
len = strlen(buf);
|
||||
|
||||
#if defined(HAVE_SYSLOG)
|
||||
if (GSUserDefaultsFlag(GSLogSyslog) == YES
|
||||
|| write(_NSLogDescriptor, buf, len) != (int)len)
|
||||
{
|
||||
null_terminated_buf = objc_malloc (sizeof (char) * (len + 1));
|
||||
strncpy (null_terminated_buf, buf, len);
|
||||
null_terminated_buf[len] = '\0';
|
||||
|
||||
syslog(SYSLOGMASK, "%s", null_terminated_buf);
|
||||
|
||||
objc_free (null_terminated_buf);
|
||||
syslog(SYSLOGMASK, "%s", buf);
|
||||
}
|
||||
#else
|
||||
write(_NSLogDescriptor, buf, len);
|
||||
#endif
|
||||
#endif // __MINGW32__
|
||||
}
|
||||
#endif // __MINGW32
|
||||
|
||||
/**
|
||||
* A pointer to a function used to actually write the log data.
|
||||
* <p>
|
||||
* GNUstep initialises this to a function implementing the standard
|
||||
* behavior for logging, but you may change this in your program
|
||||
* in order to implement any custom behavior you wish. You should
|
||||
* use the lock returned by GSLogLock() to protect any change you make.
|
||||
* </p>
|
||||
* <p>
|
||||
* Calls from NSLogv() to the function pointed to by this variable
|
||||
* are protected by a lock, and should therefore be thread safe.
|
||||
* in order to implement any custom behavior you wish.
|
||||
* </p>
|
||||
* <p>
|
||||
* This function should accept a single NSString argument and return void.
|
||||
|
@ -209,27 +192,16 @@ _NSLog_standard_printf_handler (NSString* message)
|
|||
* encoding or, if that is not possible, to UTF8 data.
|
||||
* </item>
|
||||
* <item>
|
||||
* If the system supports writing to syslog and the user default to
|
||||
* If the platform supports writing to syslog and the user default to
|
||||
* say that logging should be done to syslog (GSLogSyslog) is set,
|
||||
* writes the data to the syslog.<br />
|
||||
* On an mswindows system, where syslog is not available, the
|
||||
* GSLogSyslog user default controls whether or not data is written
|
||||
* to the system event log,
|
||||
* writes the data to the syslog(*nix) or the EventLog(ms-windows).<br />
|
||||
* </item>
|
||||
* <item>
|
||||
* Otherwise, writes the data to the file descriptor stored in the
|
||||
* variable
|
||||
* <ref type="variable" id="_NSLogDescriptor">_NSLogDescriptor</ref>,
|
||||
* which is set by default to stderr.<br />
|
||||
* Your program may change this descriptor ... but you should protect
|
||||
* changes using the lock provided by GSLogLock().<br />
|
||||
* NB. If the write to the descriptor fails, and the system supports
|
||||
* writing to syslog, then the log is written to syslog as if the
|
||||
* appropriate user default had been set.
|
||||
* Otherwise, writes the data is written to stderr.<br />
|
||||
* </item>
|
||||
* </list>
|
||||
*/
|
||||
NSLog_printf_handler *_NSLog_printf_handler = _NSLog_standard_printf_handler;
|
||||
NSLog_printf_handler *_NSLog_printf_handler = _GSLog_standard_printf_handler;
|
||||
|
||||
/**
|
||||
* <p>Provides the standard OpenStep logging facility. For details see
|
||||
|
@ -238,13 +210,12 @@ NSLog_printf_handler *_NSLog_printf_handler = _NSLog_standard_printf_handler;
|
|||
* <p>GNUstep provides powerful alternatives for logging ... see
|
||||
* NSDebugLog(), NSWarnLog() and GSPrintf() for example. We recommend
|
||||
* the use of NSDebugLog() and its relatives for debug purposes, and
|
||||
* GSPrintf() for general log messages, with NSLog() being reserved
|
||||
* for reporting possible/likely errors. GSPrintf() is declared in
|
||||
* GSObjCRuntime.h.
|
||||
* GSPrintf() for general messages, with NSLog() being reserved
|
||||
* for reporting possible/likely errors. See GSObjCRuntime.h
|
||||
* </p>
|
||||
*/
|
||||
void
|
||||
NSLog (NSString* format, ...)
|
||||
NSLog(NSString* format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
|
@ -280,61 +251,17 @@ NSLog (NSString* format, ...)
|
|||
* </p>
|
||||
*/
|
||||
void
|
||||
NSLogv (NSString* format, va_list args)
|
||||
NSLogv(NSString* format, va_list args)
|
||||
{
|
||||
NSString *prefix;
|
||||
NSString *message;
|
||||
static int pid = 0;
|
||||
NSString *outMsg;
|
||||
NSString *idStr;
|
||||
NSString *message;
|
||||
static NSRecursiveLock *logLock;
|
||||
CREATE_AUTORELEASE_POOL(arp);
|
||||
|
||||
if (_NSLog_printf_handler == NULL)
|
||||
{
|
||||
_NSLog_printf_handler = *_NSLog_standard_printf_handler;
|
||||
}
|
||||
|
||||
if (pid == 0)
|
||||
{
|
||||
#if defined(__MINGW32__)
|
||||
pid = (int)GetCurrentProcessId();
|
||||
#else
|
||||
pid = (int)getpid();
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef HAVE_SYSLOG
|
||||
if (GSUserDefaultsFlag(GSLogSyslog) == YES)
|
||||
{
|
||||
if (GSUserDefaultsFlag(GSLogThread) == YES)
|
||||
{
|
||||
prefix = [NSString stringWithFormat: @"[thread:%x] ",
|
||||
GSCurrentThread()];
|
||||
}
|
||||
else
|
||||
{
|
||||
prefix = @"";
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
if (GSUserDefaultsFlag(GSLogThread) == YES)
|
||||
{
|
||||
prefix = [NSString
|
||||
stringWithFormat: @"%@ %@[%d,%x] ",
|
||||
[[NSCalendarDate calendarDate]
|
||||
descriptionWithCalendarFormat: @"%Y-%m-%d %H:%M:%S.%F"],
|
||||
[[NSProcessInfo processInfo] processName],
|
||||
pid, GSCurrentThread()];
|
||||
}
|
||||
else
|
||||
{
|
||||
prefix = [NSString
|
||||
stringWithFormat: @"%@ %@[%d] ",
|
||||
[[NSCalendarDate calendarDate]
|
||||
descriptionWithCalendarFormat: @"%Y-%m-%d %H:%M:%S.%F"],
|
||||
[[NSProcessInfo processInfo] processName],
|
||||
pid];
|
||||
}
|
||||
_NSLog_printf_handler = *_GSLog_standard_printf_handler;
|
||||
}
|
||||
|
||||
/* Check if there is already a newline at the end of the format */
|
||||
|
@ -344,19 +271,52 @@ NSLogv (NSString* format, va_list args)
|
|||
}
|
||||
message = [NSString stringWithFormat: format arguments: args];
|
||||
|
||||
prefix = [prefix stringByAppendingString: message];
|
||||
|
||||
if (myLock == nil)
|
||||
#ifdef HAVE_SYSLOG
|
||||
if (GSUserDefaultsFlag(GSLogSyslog) == YES)
|
||||
{
|
||||
GSLogLock();
|
||||
if ([NSThread isMultiThreaded])
|
||||
{
|
||||
outMsg = [NSString stringWithFormat: @"[thread:%x] %@",
|
||||
GSCurrentThread(),message];
|
||||
}
|
||||
else
|
||||
{
|
||||
outMsg = message;
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
if ([NSThread isMultiThreaded])
|
||||
{
|
||||
idStr = [NSString stringWithFormat: @"%d, %x",
|
||||
[[NSProcessInfo processInfo] processIdentifier],
|
||||
GSCurrentThread()];
|
||||
}
|
||||
else
|
||||
{
|
||||
idStr = [NSString stringWithFormat: @"%d",
|
||||
[[NSProcessInfo processInfo] processIdentifier]];
|
||||
}
|
||||
outMsg = [NSString
|
||||
stringWithFormat: @"%@ %@[%@] %@",
|
||||
[[NSCalendarDate calendarDate]
|
||||
descriptionWithCalendarFormat: @"%Y-%m-%d %H:%M:%S.%F"],
|
||||
[[NSProcessInfo processInfo] processName],
|
||||
idStr,
|
||||
message];
|
||||
}
|
||||
|
||||
[myLock lock];
|
||||
|
||||
_NSLog_printf_handler(prefix);
|
||||
|
||||
[myLock unlock];
|
||||
// Lock and print the output
|
||||
if (logLock == nil)
|
||||
{
|
||||
[gnustep_global_lock lock];
|
||||
logLock = [NSRecursiveLock new];
|
||||
[gnustep_global_lock unlock];
|
||||
}
|
||||
[logLock lock];
|
||||
_NSLog_printf_handler(outMsg);
|
||||
[logLock unlock];
|
||||
|
||||
RELEASE(arp);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
Written by: Georg Tuparev <Tuparev@EMBL-Heidelberg.de>
|
||||
Heidelberg, Germany
|
||||
Modified by: Richard Frith-Macdonald <rfm@gnu.org>
|
||||
Modified by: Sheldon Gill <sheldon@westnet.net.au>
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
|
||||
|
@ -27,27 +28,22 @@
|
|||
*/
|
||||
|
||||
/*************************************************************************
|
||||
* File Name : NSProcessInfo.m
|
||||
* Date : 06-aug-1995
|
||||
******** Notes
|
||||
*************************************************************************
|
||||
* Notes :
|
||||
* 1) The class functionality depends on the following UNIX functions and
|
||||
* global variables: gethostname(), getpid(), and environ. For all system
|
||||
* I had the opportunity to test them they are defined and have the same
|
||||
* behavior. The same is true for the meaning of argv[0] (process name).
|
||||
* 2) The global variable _gnu_sharedProcessInfoObject should NEVER be
|
||||
* deallocate during the process runtime. Therefore I implemented a
|
||||
* deallocated during the process runtime. Therefore I implemented a
|
||||
* concrete NSProcessInfo subclass (_NSConcreteProcessInfo) with the only
|
||||
* purpose to override the autorelease, retain, and release methods.
|
||||
* To Do :
|
||||
* 1) To test the class on more platforms;
|
||||
* -----------------------------------------------------------------------
|
||||
* TODO : Clean up the initialisation. Its too messy and confusing.
|
||||
* Drop FallbackInitialisation entirely.
|
||||
* Clean up the debugging extras; don't alter the argv[]...
|
||||
* -----------------------------------------------------------------------
|
||||
* Bugs : Not known
|
||||
* Last update: 07-aug-2002
|
||||
* History : 06-aug-1995 - Birth and the first beta version (v. 0.5);
|
||||
* 08-aug-1995 - V. 0.6 (tested on NS, SunOS, Solaris, OSF/1
|
||||
* The use of the environ global var was changed to more
|
||||
* conventional env[] (main function) so now the class could be
|
||||
* used on SunOS and Solaris. [GT]
|
||||
*************************************************************************
|
||||
* Acknowledgments:
|
||||
* - Adam Fedor, Andrew McCallum, and Paul Kunz for their help;
|
||||
|
@ -203,6 +199,7 @@ static BOOL fallbackInitialisation = NO;
|
|||
*** Implementing the gnustep_base_user_main function
|
||||
*************************************************************************/
|
||||
|
||||
// FIXME: This is too much of a mess!! -SG
|
||||
void
|
||||
_gnu_process_args(int argc, char *argv[], char *env[])
|
||||
{
|
||||
|
@ -975,82 +972,48 @@ int main(int argc, char *argv[], char *env[])
|
|||
* The known types are listed in the header file, but not all of the
|
||||
* listed types are actually implemented ... some are present for
|
||||
* MacOS-X compatibility only.<br />
|
||||
* GNUstep adds a few additional definitions for platforms which didn't
|
||||
* have original OpenStep support.
|
||||
* <list>
|
||||
* <item>NSWindowsNTOperatingSystem - used for windows NT, 2000, XP</item>
|
||||
* <item>NSWindowsNTOperatingSystem - Microsoft Windows (NT/2000/XP/2003/Vista)</item>
|
||||
* <item>NSWindows95OperatingSystem - probably never to be implemented</item>
|
||||
* <item>NSSolarisOperatingSystem - not yet recognised</item>
|
||||
* <item>NSSolarisOperatingSystem - Sun operating systems from Version 5 on</item>
|
||||
* <item>NSHPUXOperatingSystem - not implemented</item>
|
||||
* <item>NSMACHOperatingSystem - perhaps the HURD in future?</item>
|
||||
* <item>NSMACHOperatingSystem - Darwin, MacOS-X, NeXTStep and other MACH kernel based</item>
|
||||
* <item>NSSunOSOperatingSystem - probably never to be implemented</item>
|
||||
* <item>NSOSF1OperatingSystem - probably never to be implemented</item>
|
||||
* <item>NSGNULinuxOperatingSystem - the GNUstep 'standard'</item>
|
||||
* <item>NSBSDOperatingSystem - BSD derived operating systems</item>
|
||||
* <item>NSCygwinOperatingSystem - cygwin unix-like environment</item>
|
||||
* <item>GSGNULinuxOperatingSystem - all GNU/Linux distributions including Debian, RedHat etc</item>
|
||||
* <item>GSBSDOperatingSystem - BSD derived operating systems</item>
|
||||
* <item>GSCygwinOperatingSystem - cygwin unix-like environment on Microsoft Windows</item>
|
||||
* </list>
|
||||
*/
|
||||
- (unsigned int) operatingSystem
|
||||
{
|
||||
static unsigned int os = 0;
|
||||
|
||||
if (os == 0)
|
||||
{
|
||||
NSString *n = [self operatingSystemName];
|
||||
|
||||
if ([n isEqualToString: @"linux-gnu"] == YES)
|
||||
{
|
||||
os = NSGNULinuxOperatingSystem;
|
||||
}
|
||||
else if ([n hasPrefix: @"mingw"] == YES)
|
||||
{
|
||||
os = NSWindowsNTOperatingSystem;
|
||||
}
|
||||
else if ([n isEqualToString: @"cygwin"] == YES)
|
||||
{
|
||||
os = NSCygwinOperatingSystem;
|
||||
}
|
||||
else if ([n hasPrefix: @"bsd"] == YES)
|
||||
{
|
||||
os = NSBSDOperatingSystem;
|
||||
}
|
||||
else if ([n hasPrefix: @"freebsd"] == YES)
|
||||
{
|
||||
os = NSBSDOperatingSystem;
|
||||
}
|
||||
else if ([n hasPrefix: @"netbsd"] == YES)
|
||||
{
|
||||
os = NSBSDOperatingSystem;
|
||||
}
|
||||
else if ([n hasPrefix: @"openbsd"] == YES)
|
||||
{
|
||||
os = NSBSDOperatingSystem;
|
||||
}
|
||||
else if ([n isEqualToString: @"beos"] == YES)
|
||||
{
|
||||
os = NSBeOperatingSystem;
|
||||
}
|
||||
else if ([n hasPrefix: @"darwin"] == YES)
|
||||
{
|
||||
os = NSMACHOperatingSystem;
|
||||
}
|
||||
else if ([n hasPrefix: @"solaris"] == YES)
|
||||
{
|
||||
os = NSSolarisOperatingSystem;
|
||||
}
|
||||
else if ([n hasPrefix: @"hpux"] == YES)
|
||||
{
|
||||
os = NSHPUXOperatingSystem;
|
||||
}
|
||||
else
|
||||
{
|
||||
NSLog(@"Unable to determine O/S ... assuming GNU/Linux");
|
||||
os = NSGNULinuxOperatingSystem;
|
||||
}
|
||||
}
|
||||
return os;
|
||||
#if defined(__linux)
|
||||
return GSGNULinuxOperatingSystem;
|
||||
#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
|
||||
defined(__DragonFly__) || defined(__bsdi__)
|
||||
return GSBSDLinuxOperatingSystem;
|
||||
#elif defined(__CYGWIN__)
|
||||
return GSCygwinOperatingSystem;
|
||||
#elif defined(__sun)
|
||||
return NSSolarisOperatingSystem;
|
||||
#elif defined(DARWIN) || defined(__APPLE__)
|
||||
return NSMACHOperatingSystem;
|
||||
#elif defined(__MINGW32__)
|
||||
return NSWindowsNTOperatingSystem;
|
||||
#else
|
||||
#warning Can't determine the operatingSystem constant for this platform!
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the operating system in use.
|
||||
* Returns the name of the operating system in use.<br>
|
||||
* OpenStep/Cocoa return a string representation of the operatingSystem
|
||||
* constant. MacOS-X will always return @"NSMACHOperatingSystem"<br/>
|
||||
* This implementation is different in that it will return the
|
||||
* name of the operating system. (eg "Linux", "Darwin", "FreeBSD")
|
||||
*/
|
||||
- (NSString*) operatingSystemName
|
||||
{
|
||||
|
@ -1058,25 +1021,64 @@ int main(int argc, char *argv[], char *env[])
|
|||
|
||||
if (os == nil)
|
||||
{
|
||||
os = [[NSBundle _gnustep_target_os] copy];
|
||||
#if defined(__MINGW32__)
|
||||
os = @"Microsoft Windows";
|
||||
#else
|
||||
struct utsname uns;
|
||||
|
||||
if (uname(&uns) != -1)
|
||||
{
|
||||
os = [NSString stringWithCString: uts.sysname
|
||||
encoding: NSDefaultEncoding];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a localised string with the name and version information about the
|
||||
* operating system on which the process is running. The string is designed
|
||||
* to be read by a human and shouldn't be used by an application to determine
|
||||
* details about the host operating system.<p>
|
||||
*
|
||||
* Known Bugs: No localisation support yet
|
||||
* <introduced/>MacOS 10.2, Base 1.14</introduced>
|
||||
*/
|
||||
- (NSString *) operatingSystemVersionString
|
||||
{
|
||||
static NSString *osVerName = nil;
|
||||
|
||||
if (osVerName == nil)
|
||||
{
|
||||
#if defined(__MINGW32__)
|
||||
osVerName = @"Version 5.0 or later..";
|
||||
#else
|
||||
struct utsname uns;
|
||||
|
||||
if (uname(&uns) != -1)
|
||||
{
|
||||
osVerName = [NSString stringWithCString: uts.version
|
||||
encoding: NSDefaultEncoding];
|
||||
// FIXME: Add localisation support and the appropriate
|
||||
// localisation strings - sheldon
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return osVerName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the process identifier number which identifies this process
|
||||
* on this machine.
|
||||
*/
|
||||
- (int) processIdentifier
|
||||
{
|
||||
int pid;
|
||||
|
||||
#if defined(__MINGW32__)
|
||||
pid = (int)GetCurrentProcessId();
|
||||
return (int)GetCurrentProcessId();
|
||||
#else
|
||||
pid = (int)getpid();
|
||||
return (int)getpid();
|
||||
#endif
|
||||
return pid;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1090,7 +1092,11 @@ int main(int argc, char *argv[], char *env[])
|
|||
}
|
||||
|
||||
/**
|
||||
* Change the name of the current process to newName.
|
||||
* Change the name of the current process to newName. The newName is used
|
||||
* by the GNUstep libraries but it will not change the name of the binary
|
||||
* being executed.<br>
|
||||
* Use this carefully as other objects use this in their functionality, for
|
||||
* example: NSUserDefaults
|
||||
*/
|
||||
- (void) setProcessName: (NSString *)newName
|
||||
{
|
||||
|
@ -1174,32 +1180,18 @@ static BOOL debugTemporarilyDisabled = NO;
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/* DEPRECATED-DELETED
|
||||
* You can over-ride the _NSLog_standard_printf_handler and do whatever
|
||||
* you feel like. That is the *only* mechanism.
|
||||
*
|
||||
* Set the file to which NSLog output should be directed.<br />
|
||||
* Returns YES on success, NO on failure.<br />
|
||||
* By default logging goes to standard error.
|
||||
*/
|
||||
*
|
||||
- (BOOL) setLogFile: (NSString*)path
|
||||
{
|
||||
extern int _NSLogDescriptor;
|
||||
int desc;
|
||||
|
||||
#if defined(__MINGW32__)
|
||||
desc = _wopen([path fileSystemRepresentation], O_RDWR|O_CREAT|O_APPEND, 0644);
|
||||
#else
|
||||
desc = open([path fileSystemRepresentation], O_RDWR|O_CREAT|O_APPEND, 0644);
|
||||
#endif
|
||||
if (desc >= 0)
|
||||
{
|
||||
if (_NSLogDescriptor >= 0 && _NSLogDescriptor != 2)
|
||||
{
|
||||
close(_NSLogDescriptor);
|
||||
}
|
||||
_NSLogDescriptor = desc;
|
||||
return YES;
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
*/
|
||||
@end
|
||||
|
||||
/**
|
||||
|
|
|
@ -1185,7 +1185,7 @@ handle_printf_atsign (FILE *stream,
|
|||
if ((data_ucs2chars[0] == byteOrderMark)
|
||||
|| (data_ucs2chars[0] == byteOrderMarkSwapped))
|
||||
{
|
||||
/* somebody set up us the BOM! */
|
||||
/* we've detected the BOM so its UTF-16 */
|
||||
enc = NSUnicodeStringEncoding;
|
||||
}
|
||||
else if (len >= 3
|
||||
|
@ -1195,12 +1195,13 @@ handle_printf_atsign (FILE *stream,
|
|||
{
|
||||
enc = NSUTF8StringEncoding;
|
||||
}
|
||||
// FIXME: Detect UTF32 BOM. -SG
|
||||
}
|
||||
self = [self initWithData: d encoding: enc];
|
||||
RELEASE(d);
|
||||
if (self == nil)
|
||||
{
|
||||
NSWarnMLog(@"Contents of file '%@' are not string data", path);
|
||||
NSWarnMLog(@"Contents of file '%@' is not string data", path);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
|
|
@ -89,11 +89,13 @@ int main( int argc, char *argv[] )
|
|||
NSDocumentDirectory,
|
||||
NSAllApplicationsDirectory,
|
||||
NSAllLibrariesDirectory,
|
||||
#ifdef GNUSTEP_BASE_LIBRARY
|
||||
GSLibrariesDirectory,
|
||||
GSToolsDirectory,
|
||||
GSApplicationSupportDirectory,
|
||||
GSFrameworksDirectory,
|
||||
GSFontsDirectory
|
||||
#endif
|
||||
};
|
||||
|
||||
NSSearchPathDirectory key;
|
||||
|
|
Loading…
Reference in a new issue