Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > NSTask & Argument Arrays

NSTask & Argument Arrays
Thread Tools
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
Jun 16, 2004, 03:49 PM
 
Hey guys,

I'm trying to use the Tidy library in my application. And it basically _works_. I says works, but I mean it works barely. I am having a problem with getting the arguments for each option to work correctly. By arguments, I mean the 'y/n' bools.

Here is my code to get the commands from the tidy executable:

Code:
NSMutableArray *argumentArray = [[NSMutableArray alloc] init]; if ([[arguments objectAtIndex:0] boolValue]) [argumentArray addObject:@"indent-attributes"]; [argumentArray addObject:@"y"]; if ([[arguments objectAtIndex:1] boolValue]) [argumentArray addObject:@"indent"]; [argumentArray addObject:@"y"]; if ([[arguments objectAtIndex:2] boolValue]) [argumentArray addObject:@"uppercase-attributes"]; [argumentArray addObject:@"y"]; if ([[arguments objectAtIndex:3] boolValue]) [argumentArray addObject:@"lower-literals"]; [argumentArray addObject:@"y"]; if ([[arguments objectAtIndex:4] boolValue]) [argumentArray addObject:@"upper"]; [argumentArray addObject:@"y"]; if ([[arguments objectAtIndex:5] boolValue]) [argumentArray addObject:@"repeated-attributes"]; [argumentArray addObject:@"keep-first"]; if ([[arguments objectAtIndex:6] boolValue]) [argumentArray addObject:@"word-2000"]; [argumentArray addObject:@"y"]; if ([[arguments objectAtIndex:7] boolValue]) [argumentArray addObject:@"drop-proprietary-attributes"]; [argumentArray addObject:@"y"]; if ([[arguments objectAtIndex:8] boolValue]) [argumentArray addObject:@"fix-bad-comments"]; [argumentArray addObject:@"y"]; if ([[arguments objectAtIndex:9] boolValue]) [argumentArray addObject:@"clean"]; [argumentArray addObject:@"y"]; if ([[arguments objectAtIndex:10] boolValue]) [argumentArray addObject:@"asxhtml"]; [argumentArray addObject:@"y"]; if ([[arguments objectAtIndex:11] boolValue]) [argumentArray addObject:@"alt-text"]; [argumentArray addObject:@"y"]; [argumentArray addObject:[NSHomeDirectory() stringByAppendingString:@"/Library/Application Support/Tag/Temporary Preview/Tidy.txt"]];
Now, after looking through the tidy help, these all seem correct, and all seem to require a y/n command (except the keep-first).

The problem here is, when I execute this method with those options, I get this:

2004-06-16 21:48:15.526 [507] *** -[NSCFArray objectAtIndex:]: index (0) beyond bounds (0)

Now, if I get rid of each of the y arguments (and the keep-first one) it works fine with no errors, but of course it doesn't work correctly.

Does anyone have any idea whats going wrong here?

Thanks,
Oliver
     
Addicted to MacNN
Join Date: Nov 2002
Location: Seattle, WA
Status: Offline
Reply With Quote
Jun 16, 2004, 05:16 PM
 
where are you getting "arguments" from? looks like that's an empty array
     
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
Jun 16, 2004, 05:31 PM
 
Originally posted by Uncle Skeleton:
where are you getting "arguments" from? looks like that's an empty array
In my tidy wrapper, I have a method called this:

+ (NSDictionary *)tidyHTML:(NSString *)html withArguments:(NSArray *)arguments

and in my controller class for the actual tidying of a HTML document:

Code:
- (void)repairOK:(id)sender { NSArray *argueArray = [[NSArray alloc] initWithObjects:[self getStateBool:indentAttributes],[self getStateBool:indentTags],[self getStateBool:upperAttributes],[self getStateBool:lowerLiterals],[self getStateBool:upperTags],[self getStateBool:rmRepeatAttributes],[self getStateBool:stripMSCode],[self getStateBool:dropPropAttributes],[self getStateBool:fixBadComments],[self getStateBool:htmlToCSS],[self getStateBool:convertToXHTML],[self getStateBool:addAltToImages], nil]; NSDictionary *tidyDictionary = [Tidy tidyHTML:[docTextView string] withArguments:argueArray]; if ([[tidyDictionary objectForKey:@"html"] length] > 0) [docTextView setString:[tidyDictionary objectForKey:@"html"]]; [self willChangeValueForKey:@"errorArray"]; [errorArray setArray:[tidyDictionary objectForKey:@"errors"]]; [self didChangeValueForKey:@"errorArray"]; [[NSApplication sharedApplication] endSheet:tidySheet]; [tidySheet close]; }
I don't see why the array should/could be empty? Any ideas?

Edit: Ack smilies

Thanks,
Oliver
     
Addicted to MacNN
Join Date: Nov 2002
Location: Seattle, WA
Status: Offline
Reply With Quote
Jun 16, 2004, 10:34 PM
 
rrr, not really, unless [self getStateBool:indentAttributes] happens to return nil. How about this...I'm no expert but my C intuition tells me this is a typo:
if ([[arguments objectAtIndex:0] boolValue]) [argumentArray addObject:@"indent-attributes"]; [argumentArray addObject:@"y"];
because only the first clause is conditional on the if statement (isn't it?) and that [argumentArray addObject:@"y"] will be called regardless (unless that's what you want?). dunno. try adding a bunch of curly brackets.
     
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
Jun 17, 2004, 01:38 AM
 
Originally posted by Uncle Skeleton:
rrr, not really, unless [self getStateBool:indentAttributes] happens to return nil. How about this...I'm no expert but my C intuition tells me this is a typo:

because only the first clause is conditional on the if statement (isn't it?) and that [argumentArray addObject:@"y"] will be called regardless (unless that's what you want?). dunno. try adding a bunch of curly brackets.
I did the first thing you asked (the brackets) and that didn't seem to change anything. I then tried commenting out getStateBool:indentAttributes, but then instead of getting '0' in the array warning thing, I got 11. If I commented out 11, I got 10, etc etc.

Any ideas at all?

Here is my getStateBool: code:

Code:
- (NSNumber *)getStateBool:(NSButton *)sender { if ([sender state] == NSOnState) return [NSNumber numberWithBool:YES]; return [NSNumber numberWithBool:NO]; }
     
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status: Offline
Reply With Quote
Jun 17, 2004, 02:18 AM
 
Whyntcha stick an NSLog(@"%@", arguments) at the beginning of the problem code and make sure that 'arguments' is what you think it is?

I also didn't think your 'if' statements will work as you intend them to without curly braces, btw.
Geekspiff - generating spiffdiddlee software since before you began paying attention.
     
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
Jun 17, 2004, 02:21 AM
 
I changed the brackets to how skeleton said. The NSLog produced this if no checkmarks were ticked:

2004-06-17 08:28:57.752 Tag[981] <CFArray 0x4bea790 [0xa01900e0]>{type = immutable, count = 12, values = (
0 : <CFBoolean 0xa0190b98 [0xa01900e0]>{value = false}
1 : <CFBoolean 0xa0190b98 [0xa01900e0]>{value = false}
2 : <CFBoolean 0xa0190b98 [0xa01900e0]>{value = false}
3 : <CFBoolean 0xa0190b98 [0xa01900e0]>{value = false}
4 : <CFBoolean 0xa0190b98 [0xa01900e0]>{value = false}
5 : <CFBoolean 0xa0190b98 [0xa01900e0]>{value = false}
6 : <CFBoolean 0xa0190b98 [0xa01900e0]>{value = false}
7 : <CFBoolean 0xa0190b98 [0xa01900e0]>{value = false}
8 : <CFBoolean 0xa0190b98 [0xa01900e0]>{value = false}
9 : <CFBoolean 0xa0190b98 [0xa01900e0]>{value = false}
10 : <CFBoolean 0xa0190b98 [0xa01900e0]>{value = false}
11 : <CFBoolean 0xa0190b98 [0xa01900e0]>{value = false}
)}

And argueArray in my other class makes this:

2004-06-17 08:28:57.753 Tag[981] <CFArray 0x4bea790 [0xa01900e0]>{type = immutable, count = 12, values = (
0 : <CFBoolean 0xa0190b98 [0xa01900e0]>{value = false}
1 : <CFBoolean 0xa0190b98 [0xa01900e0]>{value = false}
2 : <CFBoolean 0xa0190b98 [0xa01900e0]>{value = false}
3 : <CFBoolean 0xa0190b98 [0xa01900e0]>{value = false}
4 : <CFBoolean 0xa0190b98 [0xa01900e0]>{value = false}
5 : <CFBoolean 0xa0190b98 [0xa01900e0]>{value = false}
6 : <CFBoolean 0xa0190b98 [0xa01900e0]>{value = false}
7 : <CFBoolean 0xa0190b98 [0xa01900e0]>{value = false}
8 : <CFBoolean 0xa0190b98 [0xa01900e0]>{value = false}
9 : <CFBoolean 0xa0190b98 [0xa01900e0]>{value = false}
10 : <CFBoolean 0xa0190b98 [0xa01900e0]>{value = false}
11 : <CFBoolean 0xa0190b98 [0xa01900e0]>{value = false}
)}

I don't really have any idea if this is bad or not, any ideas?

Thanks,
Oliver
(Last edited by iOliverC; Jun 17, 2004 at 02:29 AM. )
     
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status: Offline
Reply With Quote
Jun 17, 2004, 02:40 AM
 
That looks fine. Here's another idea. Set a breakpoint at the beginning of the problem area by clicking in the margin to the left of the code. Run your code in the debugger. It'll break at the breakpoint you set. From the toolbar, press the Console Drawer button (a drawer will open on the bottom of the debugger). Type the following:
br -[NSException raise]
and then hit the Continue button. You'll drop back into the debugger as the exception is being thrown, and you can click through the stack trace area (top left) to see exactly where in your code the problem is.
Geekspiff - generating spiffdiddlee software since before you began paying attention.
     
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
Jun 17, 2004, 10:26 AM
 
Originally posted by smeger:
That looks fine. Here's another idea. Set a breakpoint at the beginning of the problem area by clicking in the margin to the left of the code. Run your code in the debugger. It'll break at the breakpoint you set. From the toolbar, press the Console Drawer button (a drawer will open on the bottom of the debugger). Type the following:
br -[NSException raise]
and then hit the Continue button. You'll drop back into the debugger as the exception is being thrown, and you can click through the stack trace area (top left) to see exactly where in your code the problem is.
I tried this, and even though I have debug symbols on, all I got was grayed out items. The methods were nothing to note, just the tidyHTML one. Any ideas appreciated, I've been fighting this problem for agges, and still can't figure it out

Thanks,
Oliver
     
Addicted to MacNN
Join Date: Nov 2002
Location: Seattle, WA
Status: Offline
Reply With Quote
Jun 17, 2004, 10:27 AM
 
Originally posted by iOliverC:
I did the first thing you asked (the brackets) and that didn't seem to change anything. I then tried commenting out getStateBool:indentAttributes, but then instead of getting '0' in the array warning thing, I got 11. If I commented out 11, I got 10, etc etc.

Any ideas at all?
ah, then that was it! go find out what's wrong with getStateBool: like is it returning a bool instead of an NSNumber or something. (see why? if you remove the first array item then you only have 10 instead of 11 and when your loop gets to number 11 you'll be out of bounds. Then when you remove another you'll be out of bounds at 10)
     
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
Jun 17, 2004, 10:43 AM
 
Hmm, shouldn't this return a NSNumber?

Code:
- (NSNumber *)getStateBool:(NSButton *)sender { if ([sender state] == NSOnState) return [NSNumber numberWithBool:YES]; return [NSNumber numberWithBool:NO]; }
     
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
Jun 17, 2004, 11:26 AM
 
Ok, so I tried this code:

Code:
- (void)repairOK:(id)sender { NSArray *argueArray = [[NSArray alloc] initWithObjects:[self getStateBool:indentAttributes],[self getStateBool:indentTags],[self getStateBool:upperAttributes],[self getStateBool:lowerLiterals],[self getStateBool:upperTags],[self getStateBool:rmRepeatAttributes],[self getStateBool:stripMSCode],[self getStateBool:dropPropAttributes],[self getStateBool:fixBadComments],[self getStateBool:htmlToCSS],[self getStateBool:convertToXHTML],[self getStateBool:addAltToImages], nil]; NSLog(@"%@", argueArray); NSDictionary *tidyDictionary = [Tidy tidyHTML:[docTextView string] withArguments:argueArray]; if ([[tidyDictionary objectForKey:@"html"] length] > 0) [docTextView setString:[tidyDictionary objectForKey:@"html"]]; [self willChangeValueForKey:@"errorArray"]; // This is probably the place where it borks [errorArray setArray:[[[tidyDictionary objectForKey:@"errors"] copy] autorelease]]; //[self didChangeValueForKey:@"errorArray"]; [[NSApplication sharedApplication] endSheet:tidySheet]; [tidySheet close]; }
Note the commented out [self didChangeValueForKey:@"errorArray"];. This seems to work with no array error, when I de-comment it, the array problem comes back. Since im using bindings, I need to use it.

Any ideas?

Thanks,
Oliver
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:36 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2