An improvement around MANPATH of Bwana
Posted: Thu Feb 21, 2008 7:38 pm
Bwana is very useful, but one of the problem is that adding MANPATH is not easy. I think editing man.conf should be avoided if possible.
I guess almost people needs same MANPATHes to a login shell. The better way is sharing MAPATH setting with login shell.
I make a patch to do this. All of information is obtained through a login shell.
I hope same behavior is implemented in future version.
--- MyController.m.orig 2007-12-09 20:03:24.000000000 +0900
+++ MyController.m 2008-02-22 02:30:22.000000000 +0900
@@ -470,22 +470,21 @@
[webPage appendString:[NSString stringWithFormat:HTML_HEADER_INDEX, indexFilter ? indexFilter : @""]];
- //Get all the man paths from /usr/share/misc/man.conf
- NSString *manConfFile;
- if ([self isLeopard])
- manConfFile = [NSString stringWithContentsOfFile:@"/private/etc/man.conf"];
- else
- manConfFile = [NSString stringWithContentsOfFile:@"/usr/share/misc/man.conf"];
-
- NSEnumerator *linesOfFileEnum = [[manConfFile componentsSeparatedByString:@"\n"] objectEnumerator];
- NSString *nextLine;
- NSMutableArray *manPathsToUse = [NSMutableArray array];
-
- while (nextLine = [linesOfFileEnum nextObject]) {
- if (![nextLine hasPrefix:@"#"] && ([nextLine hasPrefix:@"MANPATH "] || [nextLine hasPrefix:@"MANPATH\t"]))
- [manPathsToUse addObject:[nextLine substringFromIndex:8]];
- }
-
+ //Get all the man paths from man -w in login shell
+ NSTask *listManPathTask = [[[NSTask alloc] init] autorelease];
+ NSPipe *listManPathPipe = [NSPipe pipe];
+ NSFileHandle *listManPathHandle = [listManPathPipe fileHandleForReading];
+ [listManPathTask setStandardOutput:listManPathPipe];
+
+ char *login_shell = getenv("SHELL");
+ [listManPathTask setLaunchPath:[NSString stringWithUTF8String:login_shell]];
+ [listManPathTask setArguments:[NSArray arrayWithObjects:@"-lc", @"/usr/bin/man -w", nil]];
+ [listManPathTask launch];
+
+ NSData *dataRecieved = [listManPathHandle readDataToEndOfFile];
+ NSString *manPathes = [[[NSString alloc] initWithData:dataRecieved encoding:NSUTF8StringEncoding] autorelease];
+
+ NSArray *manPathsToUse = [manPathes componentsSeparatedByString:@":"];
int i;
NSEnumerator *manPagePaths = [manPathsToUse objectEnumerator];
NSString *manDirectory;
@@ -512,7 +511,7 @@
NSString *currItem;
while (currItem = [e nextObject]) {
NSRange sections;
- if ((sections = [currItem rangeOfString:@"."]).location != NSNotFound) {
+ if ( ![currItem hasPrefix:@"."] && ((sections = [currItem rangeOfString:@"."]).location != NSNotFound)) {
NSString *manName = [currItem substringToIndex:sections.location];
NSRange filterRange = {NSNotFound, 0};
@@ -666,11 +665,14 @@
NSPipe *findPathPipe = [NSPipe pipe];
NSFileHandle *findPathHandle = [findPathPipe fileHandleForReading];
[findPathTask setStandardOutput:findPathPipe];
- [findPathTask setLaunchPath:@"/usr/bin/man"];
+
+ char *login_shell = getenv("SHELL");
+ [findPathTask setLaunchPath:[NSString stringWithUTF8String:login_shell]];
+
if (section)
- [findPathTask setArguments:[NSArray arrayWithObjects:@"-w", section, manualPage, nil]];
+ [findPathTask setArguments:[NSArray arrayWithObjects:@"-lc", @"/usr/bin/man -w $0 $1", section, manualPage, nil]];
else
- [findPathTask setArguments:[NSArray arrayWithObjects:@"-w", manualPage, nil]];
+ [findPathTask setArguments:[NSArray arrayWithObjects:@"-lc", @"/usr/bin/man -w $0", manualPage, nil]];
[findPathTask launch];
NSString *pathToManual = nil;
I guess almost people needs same MANPATHes to a login shell. The better way is sharing MAPATH setting with login shell.
I make a patch to do this. All of information is obtained through a login shell.
I hope same behavior is implemented in future version.
--- MyController.m.orig 2007-12-09 20:03:24.000000000 +0900
+++ MyController.m 2008-02-22 02:30:22.000000000 +0900
@@ -470,22 +470,21 @@
[webPage appendString:[NSString stringWithFormat:HTML_HEADER_INDEX, indexFilter ? indexFilter : @""]];
- //Get all the man paths from /usr/share/misc/man.conf
- NSString *manConfFile;
- if ([self isLeopard])
- manConfFile = [NSString stringWithContentsOfFile:@"/private/etc/man.conf"];
- else
- manConfFile = [NSString stringWithContentsOfFile:@"/usr/share/misc/man.conf"];
-
- NSEnumerator *linesOfFileEnum = [[manConfFile componentsSeparatedByString:@"\n"] objectEnumerator];
- NSString *nextLine;
- NSMutableArray *manPathsToUse = [NSMutableArray array];
-
- while (nextLine = [linesOfFileEnum nextObject]) {
- if (![nextLine hasPrefix:@"#"] && ([nextLine hasPrefix:@"MANPATH "] || [nextLine hasPrefix:@"MANPATH\t"]))
- [manPathsToUse addObject:[nextLine substringFromIndex:8]];
- }
-
+ //Get all the man paths from man -w in login shell
+ NSTask *listManPathTask = [[[NSTask alloc] init] autorelease];
+ NSPipe *listManPathPipe = [NSPipe pipe];
+ NSFileHandle *listManPathHandle = [listManPathPipe fileHandleForReading];
+ [listManPathTask setStandardOutput:listManPathPipe];
+
+ char *login_shell = getenv("SHELL");
+ [listManPathTask setLaunchPath:[NSString stringWithUTF8String:login_shell]];
+ [listManPathTask setArguments:[NSArray arrayWithObjects:@"-lc", @"/usr/bin/man -w", nil]];
+ [listManPathTask launch];
+
+ NSData *dataRecieved = [listManPathHandle readDataToEndOfFile];
+ NSString *manPathes = [[[NSString alloc] initWithData:dataRecieved encoding:NSUTF8StringEncoding] autorelease];
+
+ NSArray *manPathsToUse = [manPathes componentsSeparatedByString:@":"];
int i;
NSEnumerator *manPagePaths = [manPathsToUse objectEnumerator];
NSString *manDirectory;
@@ -512,7 +511,7 @@
NSString *currItem;
while (currItem = [e nextObject]) {
NSRange sections;
- if ((sections = [currItem rangeOfString:@"."]).location != NSNotFound) {
+ if ( ![currItem hasPrefix:@"."] && ((sections = [currItem rangeOfString:@"."]).location != NSNotFound)) {
NSString *manName = [currItem substringToIndex:sections.location];
NSRange filterRange = {NSNotFound, 0};
@@ -666,11 +665,14 @@
NSPipe *findPathPipe = [NSPipe pipe];
NSFileHandle *findPathHandle = [findPathPipe fileHandleForReading];
[findPathTask setStandardOutput:findPathPipe];
- [findPathTask setLaunchPath:@"/usr/bin/man"];
+
+ char *login_shell = getenv("SHELL");
+ [findPathTask setLaunchPath:[NSString stringWithUTF8String:login_shell]];
+
if (section)
- [findPathTask setArguments:[NSArray arrayWithObjects:@"-w", section, manualPage, nil]];
+ [findPathTask setArguments:[NSArray arrayWithObjects:@"-lc", @"/usr/bin/man -w $0 $1", section, manualPage, nil]];
else
- [findPathTask setArguments:[NSArray arrayWithObjects:@"-w", manualPage, nil]];
+ [findPathTask setArguments:[NSArray arrayWithObjects:@"-lc", @"/usr/bin/man -w $0", manualPage, nil]];
[findPathTask launch];
NSString *pathToManual = nil;