• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSScanner under Mac OS X 10.2 Jaguar and Mac OS X 10.1.x
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSScanner under Mac OS X 10.2 Jaguar and Mac OS X 10.1.x


  • Subject: Re: NSScanner under Mac OS X 10.2 Jaguar and Mac OS X 10.1.x
  • From: Simone Manganelli <email@hidden>
  • Date: Sun, 10 Nov 2002 12:21:28 -0800

Here's the code that takes in a certain string, and then uses an NSScanner to parse out what I want:

- (void)setFullProcessName:(NSString *)n;
{
NSScanner *scanner;
NSString *tempString = nil;
[n retain];
[fullProcessName release];
fullProcessName = n;
scanner = [[NSScanner alloc] initWithString:[[fullProcessName componentsSeparatedByString:@"/"] lastObject]];
[scanner setCaseSensitive:YES];
[scanner scanUpToString:@"console" intoString:&tempString];
if ([[[fullProcessName componentsSeparatedByString:@"/"] lastObject] isEqualToString:tempString]) {
[scanner setScanLocation:0];
[scanner scanUpToString:@"-psn" intoString:&tempString];
} else if (![tempString length]) {
tempString = [[fullProcessName componentsSeparatedByString:@"/"] lastObject];
} else {
[scanner scanString:@"console" intoString:NULL];
}
[self setProcessName:tempString];
[scanner release];
//[tempString release];
//}
}

The string that is passed to this subroutine comes from a command line output of the command "ps -auxmww", and results from this:

NSArray *tempArray = [[arrayOfLines objectAtIndex:i] componentsSeparatedByString:@" "];
for (j = 10; j <= ([tempArray count] - 1); j++) {
if (j == 10) {
[tempFullName setString:[tempArray objectAtIndex:j]];
} else {
[tempFullName appendFormat:@" %@",[tempArray objectAtIndex:j]];
}
}
[newProcess setFullProcessName:[NSString stringWithString:tempFullName]];

Basically, if you look at the format of the output of the "ps -auxmww" command in the Terminal, the full command for the process is listed at the very end, using "fields" 10 through the end of the line, and this small subroutine just steps through the 10 through end of line fields and makes one big long string out of them. Then it is passed to the first code snippit. Note that the first code snippit tries to get the very last portion of the command (everything after the last slash), and then scans off the "-psn" and some numbers at the end, or it scans off the word "console", because these two things are inessential for the command name.

So is there a problem in this code that will lead to the behavior that I've seen with my prog under Mac OS X 10.2 Jaguar and Mac OS X 10.1? Note that I am kind of inexperienced in Obj-C, so if you see any inefficiencies or any other suggestions, I would love to hear them.

Thanks again for all the help you guys can give.

-- Simone Manganelli


On Sunday, November 10, 2002, at 08:40 AM, Paul Ferguson wrote:


On Sunday, November 10, 2002, at 12:44 AM, Simone Manganelli wrote:

My application uses an NSScanner class to parse some command line output into data that gets put into a table view. On Mac OS X 10.2 Jaguar, my application works as expected. However, under Mac OS X 10.1.x, any data that got parsed via an NSScanner class does not display correctly in the NSTableView  it displays the wrong parts of the strings that should have been parsed. However, data that was parsed simply via the NSString methods do not exhibit this problem under Mac OS X 10.1.x  only NSScanner parsed data has this problem.

Is there any way to fix this problem and make my application work under both operating systems? Any help would be greatly appreciated. If there's another way to accomplish what NSScanner does, that would be acceptable too, as long as it works under both Mac OS X 10.1.x and 10.2.x Jaguar.

This sounds like it may be a bug in your code. The only difference I'm aware of between 10.1.5 and Jaguar with regard to NSScanner is how it handles a nil pattern string (Jaguar doesn't allow them).

When learning the nuances of NSScanner, I found it easier to create a small test application where I could study the behavior of the scanner isolated from my application; this makes it easier to find where the scanner doesn't behave like you think it should.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Move a file to the Trash
  • Next by Date: Re: Free calendar widgets?
  • Previous by thread: Re: NSScanner under Mac OS X 10.2 Jaguar and Mac OS X 10.1.x
  • Next by thread: Languages (was Re: To all cocoa developers...)
  • Index(es):
    • Date
    • Thread