home *** CD-ROM | disk | FTP | other *** search
Wrap
Text File | 1996-03-28 | 57.0 KB | 1,153 lines
/* NOTE: Read the comment about duplication below after the ctype rules. */ /*********** StringConversion: warn about ansi/ctype.h calls and make suggestions about changes ***********/ replace "NXIsAlNum" with "NXIsAlNum" warning "StringConversion2: Consider using [[NSCharacterSet alphanumericCharacterSet] characterIsMember:x] instead of NXIsAlNum(x)" replace "NXIsAscii" with "NXIsAscii" warning "StringConversion2: Consider using [[NSCharacterSet characterSetWithRange:NSMakeRange(0,128)] characterIsMember:x] instead of NXIsAscii(x)" replace "NXIsDigit" with "NXIsDigit" warning "StringConversion2: Consider using [NSCharacterSet decimalDigitCharacterSet] characterIsMember:x] instead of NXIsDigit(x)" replace "NXIsLower" with "NXIsLower" warning "StringConversion2: Consider using [NSCharacterSet lowercaseLetterCharacterSet] characterIsMember:x] instead of NXIsLower(x); Note that (not-lower && is-alpha) does not mean is-upper." replace "NXIsPunct" with "NXIsPunct" warning "StringConversion2: Consider using (!([[NSCharacterSet alphanumericCharacterSet] characterIsMember:x] || [[NSCharacterSet letterCharacterSet] characterIsMember:x])) instead of NXIsPunct(x)" replace "NXIsUpper" with "NXIsUpper" warning "StringConversion2: Consider using [[NSCharacterSet uppercaseLetterCharacterSet] characterIsMember:x] instead of NXIsUpper(x); Note that (not-upper && is-alpha) does not mean is-lower" replace "NXIsAlpha" with "NXIsAlpha" warning "StringConversion2: Consider using [[NSCharacterSet letterCharacterSet] characterIsMember:x] instead of NXIsAlpha(x)" replace "NXIsCntrl" with "NXIsCntrl" warning "StringConversion2: Consider using [[NSCharacterSet controlCharacterSet] characterIsMember:x] instead of NXIsCntrl(x)" replace "NXIsGraph" with "NXIsGraph" warning "StringConversion2: Consider using (![[NSCharacterSet controlCharacterSet] characterIsMember:x]) instead of NXIsGraph(x)" replace "NXIsPrint" with "NXIsPrint" warning "StringConversion2: Consider using (![[NSCharacterSet controlCharacterSet] characterIsMember:x]) instead of NXIsPrint(x)" replace "NXIsSpace" with "NXIsSpace" warning "StringConversion2: Consider using [[NSCharacterSet whitespaceAndNewlineCharacterSet] characterIsMember:x] instead of NXIsSpace(x)" replace "NXIsXDigit" with "NXIsXDigit" warning "StringConversion2: Consider using [[NSCharacterSet characterSetWithCharactersInString:@\"0123456789ABCDEFabcdef\"] characterIsMember:x] instead of NXIsXDigit(x)." replace "NXToAscii" with "NXToAscii" warning "StringConversion2: Consider conversion to the encoding NSASCIIStringEncoding or NSNonLossyASCIIStringEncoding using an NSString method instead of NXToAscii()" replace "NXToUpper" with "NXToUpper" warning "StringConversion2: Consider conversion using the NSString method 'uppercaseString' method instead of NXToUpper()." replace "NXToLower" with "NXToLower" warning "StringConversion2: Consider conversion using the NSString method 'lowercaseString' method instead of NXToLower()." replace "[<aString> cString] = <anotherString>;" with "<aString> = [NSString stringWithCString:<anotherString>];" /* NOTE: The contents of this whole script are duplicated twice because the propagation of NSString type back to variable decls sometimes allows second and third order conversions. */ /*********** StringConversion: propagate NSString types up to variable decls ***********/ replace "{<w w1>}" with "{<w w1>CONVERSION_EMPTYMETHOD}" /* Prevent char buffers used in read() calls from being changed to NSStrings. */ replace "{<w w1><b imp><w w2>}" with same within ("<imp>") { replace "<any imp1><w w3>read(<fd>, <aString>, <bytesToRead>)<w w4><any imp2>" with "<any imp1><w w3>CONVERSIONread(<fd>, <aString>, <bytesToRead>)<w w4><any imp2>" within ("<imp1>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } within ("<imp2>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } } replace "CONVERSIONread" with "read" /* Prevent char buffers used in NXRead() calls from being changed to NSStrings. */ replace "{<w w1><b imp><w w2>}" with same within ("<imp>") { replace "<any imp1><w w3>NXRead(<stream>, <aString>, <bytesToRead>)<w w4><any imp2>" with "<any imp1><w w3>CONVERSIONNXRead(<stream>, <aString>, <bytesToRead>)<w w4><any imp2>" within ("<imp1>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } within ("<imp2>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } } replace "CONVERSIONNXRead" with "NXRead" /* Prevent char buffers used in gets() calls from being changed to NSStrings. */ replace "{<w w1><b imp><w w2>}" with same within ("<imp>") { replace "<any imp1><w w3>gets(<aString>)<w w4><any imp2>" with "<any imp1><w w3>CONVERSIONgets(<aString>)<w w4><any imp2>" within ("<imp1>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } within ("<imp2>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } } replace "CONVERSIONgets" with "gets" /* Prevent char buffers used in fgets() calls from being changed to NSStrings. */ replace "{<w w1><b imp><w w2>}" with same within ("<imp>") { replace "<any imp1><w w3>fgets(<aString>, <count>, <stream>)<w w4><any imp2>" with "<any imp1><w w3>CONVERSIONgets(<aString>, <count>, <stream>)<w w4><any imp2>" within ("<imp1>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } within ("<imp2>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } } replace "CONVERSIONfgets" with "fgets" /* this is necessary because tops won't do "<any imp1><w w3><t aString>++" */ replace "<w w1><t aString><w w2>++" with "(CONVERSIONPOSTPLUSPLUS(<w w1><aString><w w2>))" replace "<w w1><t aString><w w2>--" with "(CONVERSIONPOSTMINUSMINUS(<w w1><aString><w w2>))" /* Prevent char pointers that are post incremented from being changed to NSStrings. */ replace "{<w w1><b imp><w w2>}" with same within ("<imp>") { replace "<any imp1><w w3>CONVERSIONPOSTPLUSPLUS(<aString>)<w w4><any imp2>" with "<any imp1><w w3>NOCONVERSIONPOSTPLUSPLUS(<aString>)<w w4><any imp2>" within ("<imp1>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } within ("<imp2>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } } replace "(CONVERSIONPOSTPLUSPLUS(<w w1><t aString><w w2>))" with "<w w1><aString><w w2>++" replace "(NOCONVERSIONPOSTPLUSPLUS(<w w1><t aString><w w2>))" with "<w w1><aString><w w2>++" /* Prevent char pointers that are pre incremented from being changed to NSStrings. */ replace "{<w w1><b imp><w w2>}" with same within ("<imp>") { replace "<any imp1><w w3>++<w w5><t aString><w w4><any imp2>" with "<any imp1><w w3>(CONVERSIONPREPLUSPLUS(<w w5><aString>))<w w4><any imp2>" within ("<imp1>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } within ("<imp2>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } } replace "(CONVERSIONPREPLUSPLUS(<w w5><t aString>))" with "++<w w5><aString>" /* Prevent char pointers that are post decremented from being changed to NSStrings. */ replace "{<w w1><b imp><w w2>}" with same within ("<imp>") { replace "<any imp1><w w3>CONVERSIONPOSTMINUSMINUS(<aString>)<w w4><any imp2>" with "<any imp1><w w3>NOCONVERSIONPOSTMINUSMINUS(<aString>)<w w4><any imp2>" within ("<imp1>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } within ("<imp2>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } } replace "(CONVERSIONPOSTMINUSMINUS(<w w1><t aString><w w2>))" with "<w w1><aString><w w2>--" replace "(NOCONVERSIONPOSTMINUSMINUS(<w w1><t aString><w w2>))" with "<w w1><aString><w w2>--" /* Prevent char pointers that are pre decremented from being changed to NSStrings. */ replace "{<w w1><b imp><w w2>}" with same within ("<imp>") { replace "<any imp1><w w3>--<w w5><t aString><w w4><any imp2>" with "<any imp1><w w3>(CONVERSIONPREMINUSMINUS(<w w5><aString>))<w w4><any imp2>" within ("<imp1>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } within ("<imp2>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } } replace "(CONVERSIONPREMINUSMINUS(<w w5><t aString>))" with "--<w w5><aString>" /* mark char* vars used in stringWithCString for conversion to NSStrings */ /* In the first replace, stringWithCString is replaced by CONVERSIONstringWithCString to make tops believe the rule won't infinitely recurse, which allows it to match more than once. */ replace "{<w w1><b imp><w w2>}" with same within ("<imp>") { replace "<any imp1><w w3>[NSString stringWithCString:<aString>]<w w4><any imp2>" with "<any imp1><w w3>[NSString CONVERSIONstringWithCString:<aString>]<w w4><any imp2>" within ("<imp1>") { /* char ..., NSString; */ replace "char <b stuff>, *<aString>;" with "char <b stuff>; CONVERSIONNSString( *<aString>);" replace "char <b stuff>, *<aString> = <val>;" with "char <b stuff>; CONVERSIONNSString( *<aString>) = [NSString stringWithCString:<val>];" replace "char <b stuff>, <aString>[<len>];" with "char <b stuff>; CONVERSIONNSString( *<aString>) = @\"\";" /* char ..., NSString, char ...; */ replace "char <b stuff>, *<aString>," with "char <b stuff>; CONVERSIONNSString( *<aString>); char" replace "char <b stuff>, *<aString> = <val>," with "char <b stuff>; CONVERSIONNSString( *<aString>) = [NSString stringWithCString:<val>]; char" replace "char <b stuff>, <aString>[<len>]," with "char <b stuff>; CONVERSIONNSString( *<aString>) = @\"\"; char" /* NSString; */ replace "char *<aString>;" with "CONVERSIONNSString( *<aString>);" replace "char *<aString>," with "CONVERSIONNSString( *<aString>); char" replace "char *<aString> = <val>;" with "CONVERSIONNSString( *<aString>) = [NSString stringWithCString:<val>];" replace "char *<aString> = <val>," with "CONVERSIONNSString( *<aString>) = [NSString stringWithCString:<val>]; char" replace "char <aString>[<len>];" with "CONVERSIONNSString( *<aString>);" replace "char <aString>[<len>]," with "CONVERSIONNSString( *<aString>)," replace "const CONVERSIONNSString" with "CONVERSIONNSString" } } replace "NOCONVERSIONstringWithCString" with "stringWithCString" replace "CONVERSIONstringWithCString" with "stringWithCString" replace "; CONVERSIONNSString( *<aString>)" with "; CONVERSIONNSString( *<aString>)" replace "CONVERSIONNSString( *<aString>); char" with "CONVERSIONNSString *<aString>; char" replace "CONVERSIONNSString( *<aString>) = <aStringExp>; char" with "CONVERSIONNSString *<aString> = <aStringExp>; char" /* strip parens in this rule to make tops believe the rule won't infinitely recurse, which allows it to match more than once. */ replace "{<w w1><b imp><w w2>}" with same within ("<imp>") { replace "<any imp1><w w3>CONVERSIONNSString( *<aString>)<w w4><any imp2>" with "<any imp1><w w3>CONVERSIONNSString *<aString><w w4><any imp2>" within ("<imp2>") { replace "<aString>" with "[<aString> cString]" } } replace "CONVERSIONNSString( *<aString>)" with "CONVERSIONNSString *<aString>" replace "CONVERSIONNSString" with "NSString" replace "[[<aString> cString] cString]" with "[<aString> cString]" /*********** StringConversion: ANSI str routines and NXCopyStringBuffer ***********/ /******** NOTE: duplicated in StringConversion.tops *********/ replace "sprintf([<str1> cString], <format>)" with "<str1> = [NSString stringWithCString:<format>]" replace "sprintf([<str1> cString], <format>, <b args>)" with "<str1> = [NSString stringWithFormat:[NSString stringWithCString:<format>], <b args>]" replace "strcat([<str1> cString], <str2>)" with "<str1> = [<str1> stringByAppendingString:[NSString stringWithCString:<str2>]]" replace "strncat([<str1> cString], <str2>, <len>)" with "<str1> = [<str1> stringByAppendingString:[[NSString stringWithCString:<str2>] substringToIndex:<len> - 1]]" replace "strcmp([<str1> cString], <str2>)" with "strcmp([<str1> cString], [[NSString stringWithCString:<str2>] cString])" replace "strcmp(<str1>, [<str2> cString])" with "strcmp([[NSString stringWithCString:<str1>] cString], [<str2> cString])" replace "strcmp([<str1> cString], [<str2> cString]) == 0" with "[<str1> isEqualToString:<str2>]" replace "!strcmp([<str1> cString], [<str2> cString])" with "[<str1> isEqualToString:<str2>]" replace "!(strcmp([<str1> cString], [<str2> cString]))" with "[<str1> isEqualToString:<str2>]" replace "(strcmp([<str1> cString], [<str2> cString]))" with "(![<str1> isEqualToString:<str2>])" replace "strcmp([<str1> cString], [<str2> cString])" with "[<str1> compare:<str2>]" /* strncmp assumes prefix search */ replace "strncmp([<str1> cString], <str2>, <length>)" with "strcmp([<str1> cString], [[NSString stringWithCString:<str2>] cString], <length>)" replace "strncmp(<str1>, [<str2> cString], <length>)" with "strcmp([[NSString stringWithCString:<str1>] cString], [<str2> cString], <length>)" replace "strncmp([<str1> cString], [<str2> cString], <length>) == 0" with "[<str1> hasPrefix:<str2>]" replace "!strncmp([<str1> cString], [<str2> cString], <length>)" with "[<str1> hasPrefix:<str2>]" replace "!(strncmp([<str1> cString], [<str2> cString], <length>))" with "[<str1> hasPrefix:<str2>]" replace "(strncmp([<str1> cString], [<str2> cString], <length>))" with "(![<str1> hasPrefix:<str2>])" replace "strcasecmp([<str1> cString], <str2>)" with "strcasecmp([<str1> cString], [[NSString stringWithCString:<str2>] cString])" replace "strcasecmp(<str1>, [<str2> cString])" with "strcasecmp([[NSString stringWithCString:<str1>] cString], [<str2> cString])" replace "strcasecmp([<str1> cString], [<str2> cString])" with "[<str1> compare:<str2> options:NSCaseInsensitiveSearch]" /* strncasecmp assumes prefix search */ replace "strncasecmp([<str1> cString], <str2>, <length>)" with "strncasecmp([<str1> cString], [[NSString stringWithCString:<str2>] cString], <length>)" replace "strncasecmp(<str1>, [<str2> cString], <length>)" with "strncasecmp([[NSString stringWithCString:<str1>] cString], [<str2> cString], <length>)" replace "strncasecmp([<str1> cString], [<str2> cString], <length>)" with "[<str1> compare:<str2> options:NSCaseInsensitiveSearch range:NSMakeRange(0, <length>)]" replace "strlen([<str1> cString]) == 0" with "[<str1> isEqualToString:@\"\"]" replace "!strlen([<str1> cString])" with "[<str1> isEqualToString:@\"\"]" replace "strlen([<str1> cString])" with "[<str1> length]" replace "strcpy([<str1> cString], [<str2> cString])" with "<str1> = <str2>" warning "StringConversion: This assignment of NSStrings used to be a strcpy(). With NStrings this is usually what you want because they are immutable. However, you may need to replace <str2> with [<str2> copy] or [[<str2> copy] autorelease]." replace "strcpy([<str1> cString], <str2>)" with "<str1> = [NSString stringWithCString:<str2>]" replace "strncpy([<str1> cString], <str2>, <length>)" with "<str1> = [[NSString stringWithCString:<str2>] substringToIndex:<length> - 1]" replace "[<str1> cString] = NXCopyStringBuffer([<str2> cString])" with "<str1> = [<str2> copy]" replace "[<str1> cString] = NXCopyStringBufferFromZone([<str2> cString], <zone>)" with "<str1> = [<str2> copyWithZone:<zone>]" /*********** StringConversion: a couple extra combinations ***********/ replace "<str1> = [<str1> stringByAppendingString:[NSString stringWithCString:<str2>]]; <str1> = [<str1> stringByAppendingString:[NSString stringWithCString:<str3>]]" with "<str1> = [<str1> stringByAppendingFormat:@\"%@%@\", [NSString stringWithCString:<str2>], [NSString stringWithCString:<str3>]]" replace "<str1> = [NSString stringWithCString:<str2>]; <str1> = [<str1> stringByAppendingString:[NSString stringWithCString:<str3>]]" with "<str1> = [NSString stringWithFormat:@\"%@%@\", [NSString stringWithCString:<str2>], [NSString stringWithCString:<str3>]]" /*********** StringConversion: boolean expressions ***********/ /********* NOTE: duplicated in StringConversion.tops *********/ /* some of these might not remain valid for deep conversions */ replace "if ([<str1> cString])" with "if (<str1>)" replace "([<str1> cString] &&" with "(<str1> &&" replace "([<str1> cString] ||" with "(<str1> ||" replace "&& [<str1> cString]" with "&& <str1>" replace "|| [<str1> cString]" with "|| <str1>" replace "![<str1> cString]" with "!<str1>" replace "!*[<str1> cString]" with "[<str1> isEqualToString:@\"\"]" replace "*[<str1> cString] == '\0'" with "[<str1> isEqualToString:@\"\"]" replace "*[<str1> cString] != '\0'" with "![<str1> isEqualToString:@\"\"]" replace "*[<str1> cString] == 0" with "[<str1> isEqualToString:@\"\"]" replace "*[<str1> cString] != 0" with "![<str1> isEqualToString:@\"\"]" replace "&& *[<str1> cString]" with "&& ![<str1> isEqualToString:@\"\"]" replace "|| *[<str1> cString]" with "|| ![<str1> isEqualToString:@\"\"]" replace "if (*[<str1> cString]" with "if(![<str1> isEqualToString:@\"\"]" replace "![<str1> isEqualToString:@\"\"] && ![<str1> isEqualToString:@\"\"]" with "![<str1> isEqualToString:@\"\"]" replace "![<str1> isEqualToString:@\"\"] || ![<str1> isEqualToString:@\"\"]" with "![<str1> isEqualToString:@\"\"]" replace "[<str1> isEqualToString:@\"\"] && [<str1> isEqualToString:@\"\"]" with "![<str1> isEqualToString:@\"\"]" replace "[<str1> isEqualToString:@\"\"] || [<str1> isEqualToString:@\"\"]" with "![<str1> isEqualToString:@\"\"]" /*********** StringConversion: cleanup ***********/ /********* NOTE: duplicated in StringConversion.tops *********/ replace "[NSString stringWithCString:<boolexp> ? <iftrue> : <iffalse>]" with "<boolexp> ? [NSString stringWithCString:<iftrue>] : [NSString stringWithCString:<iffalse>]" /* ??? */ replace "[<aString> cString] ?" with "<aString> ?" replace "[<aString> cString] = <anotherString>;" with "<aString> = [NSString stringWithCString:<anotherString>];" replace "[NSString stringWithCString:[NSString stringWithCString:<aString>]]" with "[NSString stringWithCString:<aString>]" replace "[[NSString stringWithCString:<aString>] cString]" with "<aString>" replace "[[<aString> cString] cString]" with "[<aString> cString]" replace "[NSString stringWithCString:[<aString> cString]]" with "<aString>" replace "[NSString stringWithCString:(char *)[<aString> cString]]" with "<aString>" replace "[NSString stringWithCString:(const char *)[<aString> cString]]" with "<aString>" replace "[NSString stringWithCString:@<string stringconst>]" with "@<string stringconst>" replace "[NSString stringWithCString:<string stringconst>]" with "@<string stringconst>" replace "[@<string stringconst> cString]" with "<string stringconst>" replace "[<aString> cString][0] = '\0'" with "<aString> = @\"\"" replace "*[<aString> cString] = '\0'" with "<aString> = @\"\"" replace "extern NXAtom [<aString> cString]" with "extern NSString *<aString>" replace "extern NSString *[<aString> cString]" with "extern NSString *<aString>" replace "extern char *[<aString> cString]" with "extern NSString *<aString>" replace "extern const char *[<aString> cString]" with "extern NSString *<aString>" replace "free([<aString> cString])" with "[<aString> release]" replace "@<string str1><w w><string str2>" with "@<string str1><w w>@<string str2>" /*********** StringConversion: more cleanup ***********/ replace "[NSString stringWithCString:NULL]" with "nil" /* ??? */ replace "[NSString stringWithCString:nil]" with "nil" /* ??? */ replace "CONVERSION_EMPTYMETHOD" with "" replace ":<anExp> [<aString> cString]]" with ":<anExp> <aString>]" replace "[<anExp> [<aString> cString]]" with "[<anExp> <aString>]" replace ":<anExp> [<aString> cString]:" with ":<anExp> <aString>:" replace "[<anExp> [<aString> cString]:" with "[<anExp> <aString>:" /* This is a repeat of the above part of the file */ /* NOTE: The contents of this whole script are duplicated twice because the propagation of NSString type back to variable decls sometimes allows second and third order conversions. */ /*********** StringConversion: propagate NSString types up to variable decls ***********/ replace "{<w w1>}" with "{<w w1>CONVERSION_EMPTYMETHOD}" /* Prevent char buffers used in read() calls from being changed to NSStrings. */ replace "{<w w1><b imp><w w2>}" with same within ("<imp>") { replace "<any imp1><w w3>read(<fd>, <aString>, <bytesToRead>)<w w4><any imp2>" with "<any imp1><w w3>CONVERSIONread(<fd>, <aString>, <bytesToRead>)<w w4><any imp2>" within ("<imp1>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } within ("<imp2>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } } replace "CONVERSIONread" with "read" /* Prevent char buffers used in NXRead() calls from being changed to NSStrings. */ replace "{<w w1><b imp><w w2>}" with same within ("<imp>") { replace "<any imp1><w w3>NXRead(<stream>, <aString>, <bytesToRead>)<w w4><any imp2>" with "<any imp1><w w3>CONVERSIONNXRead(<stream>, <aString>, <bytesToRead>)<w w4><any imp2>" within ("<imp1>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } within ("<imp2>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } } replace "CONVERSIONNXRead" with "NXRead" /* Prevent char buffers used in gets() calls from being changed to NSStrings. */ replace "{<w w1><b imp><w w2>}" with same within ("<imp>") { replace "<any imp1><w w3>gets(<aString>)<w w4><any imp2>" with "<any imp1><w w3>CONVERSIONgets(<aString>)<w w4><any imp2>" within ("<imp1>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } within ("<imp2>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } } replace "CONVERSIONgets" with "gets" /* Prevent char buffers used in fgets() calls from being changed to NSStrings. */ replace "{<w w1><b imp><w w2>}" with same within ("<imp>") { replace "<any imp1><w w3>fgets(<aString>, <count>, <stream>)<w w4><any imp2>" with "<any imp1><w w3>CONVERSIONgets(<aString>, <count>, <stream>)<w w4><any imp2>" within ("<imp1>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } within ("<imp2>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } } replace "CONVERSIONfgets" with "fgets" /* this is necessary because tops won't do "<any imp1><w w3><t aString>++" */ replace "<w w1><t aString><w w2>++" with "(CONVERSIONPOSTPLUSPLUS(<w w1><aString><w w2>))" replace "<w w1><t aString><w w2>--" with "(CONVERSIONPOSTMINUSMINUS(<w w1><aString><w w2>))" /* Prevent char pointers that are post incremented from being changed to NSStrings. */ replace "{<w w1><b imp><w w2>}" with same within ("<imp>") { replace "<any imp1><w w3>CONVERSIONPOSTPLUSPLUS(<aString>)<w w4><any imp2>" with "<any imp1><w w3>NOCONVERSIONPOSTPLUSPLUS(<aString>)<w w4><any imp2>" within ("<imp1>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } within ("<imp2>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } } replace "(CONVERSIONPOSTPLUSPLUS(<w w1><t aString><w w2>))" with "<w w1><aString><w w2>++" replace "(NOCONVERSIONPOSTPLUSPLUS(<w w1><t aString><w w2>))" with "<w w1><aString><w w2>++" /* Prevent char pointers that are pre incremented from being changed to NSStrings. */ replace "{<w w1><b imp><w w2>}" with same within ("<imp>") { replace "<any imp1><w w3>++<w w5><t aString><w w4><any imp2>" with "<any imp1><w w3>(CONVERSIONPREPLUSPLUS(<w w5><aString>))<w w4><any imp2>" within ("<imp1>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } within ("<imp2>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } } replace "(CONVERSIONPREPLUSPLUS(<w w5><t aString>))" with "++<w w5><aString>" /* Prevent char pointers that are post decremented from being changed to NSStrings. */ replace "{<w w1><b imp><w w2>}" with same within ("<imp>") { replace "<any imp1><w w3>CONVERSIONPOSTMINUSMINUS(<aString>)<w w4><any imp2>" with "<any imp1><w w3>NOCONVERSIONPOSTMINUSMINUS(<aString>)<w w4><any imp2>" within ("<imp1>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } within ("<imp2>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } } replace "(CONVERSIONPOSTMINUSMINUS(<w w1><t aString><w w2>))" with "<w w1><aString><w w2>--" replace "(NOCONVERSIONPOSTMINUSMINUS(<w w1><t aString><w w2>))" with "<w w1><aString><w w2>--" /* Prevent char pointers that are pre decremented from being changed to NSStrings. */ replace "{<w w1><b imp><w w2>}" with same within ("<imp>") { replace "<any imp1><w w3>--<w w5><t aString><w w4><any imp2>" with "<any imp1><w w3>(CONVERSIONPREMINUSMINUS(<w w5><aString>))<w w4><any imp2>" within ("<imp1>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } within ("<imp2>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } } replace "(CONVERSIONPREMINUSMINUS(<w w5><t aString>))" with "--<w w5><aString>" /* mark char* vars used in stringWithCString for conversion to NSStrings */ /* In the first replace, stringWithCString is replaced by CONVERSIONstringWithCString to make tops believe the rule won't infinitely recurse, which allows it to match more than once. */ replace "{<w w1><b imp><w w2>}" with same within ("<imp>") { replace "<any imp1><w w3>[NSString stringWithCString:<aString>]<w w4><any imp2>" with "<any imp1><w w3>[NSString CONVERSIONstringWithCString:<aString>]<w w4><any imp2>" within ("<imp1>") { /* char ..., NSString; */ replace "char <b stuff>, *<aString>;" with "char <b stuff>; CONVERSIONNSString( *<aString>);" replace "char <b stuff>, *<aString> = <val>;" with "char <b stuff>; CONVERSIONNSString( *<aString>) = [NSString stringWithCString:<val>];" replace "char <b stuff>, <aString>[<len>];" with "char <b stuff>; CONVERSIONNSString( *<aString>) = @\"\";" /* char ..., NSString, char ...; */ replace "char <b stuff>, *<aString>," with "char <b stuff>; CONVERSIONNSString( *<aString>); char" replace "char <b stuff>, *<aString> = <val>," with "char <b stuff>; CONVERSIONNSString( *<aString>) = [NSString stringWithCString:<val>]; char" replace "char <b stuff>, <aString>[<len>]," with "char <b stuff>; CONVERSIONNSString( *<aString>) = @\"\"; char" /* NSString; */ replace "char *<aString>;" with "CONVERSIONNSString( *<aString>);" replace "char *<aString>," with "CONVERSIONNSString( *<aString>); char" replace "char *<aString> = <val>;" with "CONVERSIONNSString( *<aString>) = [NSString stringWithCString:<val>];" replace "char *<aString> = <val>," with "CONVERSIONNSString( *<aString>) = [NSString stringWithCString:<val>]; char" replace "char <aString>[<len>];" with "CONVERSIONNSString( *<aString>);" replace "char <aString>[<len>]," with "CONVERSIONNSString( *<aString>)," replace "const CONVERSIONNSString" with "CONVERSIONNSString" } } replace "NOCONVERSIONstringWithCString" with "stringWithCString" replace "CONVERSIONstringWithCString" with "stringWithCString" replace "; CONVERSIONNSString( *<aString>)" with "; CONVERSIONNSString( *<aString>)" replace "CONVERSIONNSString( *<aString>); char" with "CONVERSIONNSString *<aString>; char" replace "CONVERSIONNSString( *<aString>) = <aStringExp>; char" with "CONVERSIONNSString *<aString> = <aStringExp>; char" /* strip parens in this rule to make tops believe the rule won't infinitely recurse, which allows it to match more than once. */ replace "{<w w1><b imp><w w2>}" with same within ("<imp>") { replace "<any imp1><w w3>CONVERSIONNSString( *<aString>)<w w4><any imp2>" with "<any imp1><w w3>CONVERSIONNSString *<aString><w w4><any imp2>" within ("<imp2>") { replace "<aString>" with "[<aString> cString]" } } replace "CONVERSIONNSString( *<aString>)" with "CONVERSIONNSString *<aString>" replace "CONVERSIONNSString" with "NSString" replace "[[<aString> cString] cString]" with "[<aString> cString]" /*********** StringConversion: ANSI str routines and NXCopyStringBuffer ***********/ /******** NOTE: duplicated in StringConversion.tops *********/ replace "sprintf([<str1> cString], <format>)" with "<str1> = [NSString stringWithCString:<format>]" replace "sprintf([<str1> cString], <format>, <b args>)" with "<str1> = [NSString stringWithFormat:[NSString stringWithCString:<format>], <b args>]" replace "strcat([<str1> cString], <str2>)" with "<str1> = [<str1> stringByAppendingString:[NSString stringWithCString:<str2>]]" replace "strncat([<str1> cString], <str2>, <len>)" with "<str1> = [<str1> stringByAppendingString:[[NSString stringWithCString:<str2>] substringToIndex:<len> - 1]]" replace "strcmp([<str1> cString], <str2>)" with "strcmp([<str1> cString], [[NSString stringWithCString:<str2>] cString])" replace "strcmp(<str1>, [<str2> cString])" with "strcmp([[NSString stringWithCString:<str1>] cString], [<str2> cString])" replace "strcmp([<str1> cString], [<str2> cString]) == 0" with "[<str1> isEqualToString:<str2>]" replace "!strcmp([<str1> cString], [<str2> cString])" with "[<str1> isEqualToString:<str2>]" replace "!(strcmp([<str1> cString], [<str2> cString]))" with "[<str1> isEqualToString:<str2>]" replace "(strcmp([<str1> cString], [<str2> cString]))" with "(![<str1> isEqualToString:<str2>])" replace "strcmp([<str1> cString], [<str2> cString])" with "[<str1> compare:<str2>]" /* strncmp assumes prefix search */ replace "strncmp([<str1> cString], <str2>, <length>)" with "strcmp([<str1> cString], [[NSString stringWithCString:<str2>] cString], <length>)" replace "strncmp(<str1>, [<str2> cString], <length>)" with "strcmp([[NSString stringWithCString:<str1>] cString], [<str2> cString], <length>)" replace "strncmp([<str1> cString], [<str2> cString], <length>) == 0" with "[<str1> hasPrefix:<str2>]" replace "!strncmp([<str1> cString], [<str2> cString], <length>)" with "[<str1> hasPrefix:<str2>]" replace "!(strncmp([<str1> cString], [<str2> cString], <length>))" with "[<str1> hasPrefix:<str2>]" replace "(strncmp([<str1> cString], [<str2> cString], <length>))" with "(![<str1> hasPrefix:<str2>])" replace "strcasecmp([<str1> cString], <str2>)" with "strcasecmp([<str1> cString], [[NSString stringWithCString:<str2>] cString])" replace "strcasecmp(<str1>, [<str2> cString])" with "strcasecmp([[NSString stringWithCString:<str1>] cString], [<str2> cString])" replace "strcasecmp([<str1> cString], [<str2> cString])" with "[<str1> compare:<str2> options:NSCaseInsensitiveSearch]" /* strncasecmp assumes prefix search */ replace "strncasecmp([<str1> cString], <str2>, <length>)" with "strncasecmp([<str1> cString], [[NSString stringWithCString:<str2>] cString], <length>)" replace "strncasecmp(<str1>, [<str2> cString], <length>)" with "strncasecmp([[NSString stringWithCString:<str1>] cString], [<str2> cString], <length>)" replace "strncasecmp([<str1> cString], [<str2> cString], <length>)" with "[<str1> compare:<str2> options:NSCaseInsensitiveSearch range:NSMakeRange(0, <length>)]" replace "strlen([<str1> cString]) == 0" with "[<str1> isEqualToString:@\"\"]" replace "!strlen([<str1> cString])" with "[<str1> isEqualToString:@\"\"]" replace "strlen([<str1> cString])" with "[<str1> length]" replace "strcpy([<str1> cString], [<str2> cString])" with "<str1> = <str2>" warning "StringConversion: This assignment of NSStrings used to be a strcpy(). With NStrings this is usually what you want because they are immutable. However, you may need to replace <str2> with [<str2> copy] or [[<str2> copy] autorelease]." replace "strcpy([<str1> cString], <str2>)" with "<str1> = [NSString stringWithCString:<str2>]" replace "strncpy([<str1> cString], <str2>, <length>)" with "<str1> = [[NSString stringWithCString:<str2>] substringToIndex:<length> - 1]" replace "[<str1> cString] = NXCopyStringBuffer([<str2> cString])" with "<str1> = [<str2> copy]" replace "[<str1> cString] = NXCopyStringBufferFromZone([<str2> cString], <zone>)" with "<str1> = [<str2> copyWithZone:<zone>]" /*********** StringConversion: a couple extra combinations ***********/ replace "<str1> = [<str1> stringByAppendingString:[NSString stringWithCString:<str2>]]; <str1> = [<str1> stringByAppendingString:[NSString stringWithCString:<str3>]]" with "<str1> = [<str1> stringByAppendingFormat:@\"%@%@\", [NSString stringWithCString:<str2>], [NSString stringWithCString:<str3>]]" replace "<str1> = [NSString stringWithCString:<str2>]; <str1> = [<str1> stringByAppendingString:[NSString stringWithCString:<str3>]]" with "<str1> = [NSString stringWithFormat:@\"%@%@\", [NSString stringWithCString:<str2>], [NSString stringWithCString:<str3>]]" /*********** StringConversion: boolean expressions ***********/ /********* NOTE: duplicated in StringConversion.tops *********/ /* some of these might not remain valid for deep conversions */ replace "if ([<str1> cString])" with "if (<str1>)" replace "([<str1> cString] &&" with "(<str1> &&" replace "([<str1> cString] ||" with "(<str1> ||" replace "&& [<str1> cString]" with "&& <str1>" replace "|| [<str1> cString]" with "|| <str1>" replace "![<str1> cString]" with "!<str1>" replace "!*[<str1> cString]" with "[<str1> isEqualToString:@\"\"]" replace "*[<str1> cString] == '\0'" with "[<str1> isEqualToString:@\"\"]" replace "*[<str1> cString] != '\0'" with "![<str1> isEqualToString:@\"\"]" replace "*[<str1> cString] == 0" with "[<str1> isEqualToString:@\"\"]" replace "*[<str1> cString] != 0" with "![<str1> isEqualToString:@\"\"]" replace "&& *[<str1> cString]" with "&& ![<str1> isEqualToString:@\"\"]" replace "|| *[<str1> cString]" with "|| ![<str1> isEqualToString:@\"\"]" replace "if (*[<str1> cString]" with "if(![<str1> isEqualToString:@\"\"]" replace "![<str1> isEqualToString:@\"\"] && ![<str1> isEqualToString:@\"\"]" with "![<str1> isEqualToString:@\"\"]" replace "![<str1> isEqualToString:@\"\"] || ![<str1> isEqualToString:@\"\"]" with "![<str1> isEqualToString:@\"\"]" replace "[<str1> isEqualToString:@\"\"] && [<str1> isEqualToString:@\"\"]" with "![<str1> isEqualToString:@\"\"]" replace "[<str1> isEqualToString:@\"\"] || [<str1> isEqualToString:@\"\"]" with "![<str1> isEqualToString:@\"\"]" /*********** StringConversion: cleanup ***********/ /********* NOTE: duplicated in StringConversion.tops *********/ replace "[NSString stringWithCString:<boolexp> ? <iftrue> : <iffalse>]" with "<boolexp> ? [NSString stringWithCString:<iftrue>] : [NSString stringWithCString:<iffalse>]" /* ??? */ replace "[<aString> cString] ?" with "<aString> ?" replace "[<aString> cString] = <anotherString>;" with "<aString> = [NSString stringWithCString:<anotherString>];" replace "[NSString stringWithCString:[NSString stringWithCString:<aString>]]" with "[NSString stringWithCString:<aString>]" replace "[[NSString stringWithCString:<aString>] cString]" with "<aString>" replace "[[<aString> cString] cString]" with "[<aString> cString]" replace "[NSString stringWithCString:[<aString> cString]]" with "<aString>" replace "[NSString stringWithCString:(char *)[<aString> cString]]" with "<aString>" replace "[NSString stringWithCString:(const char *)[<aString> cString]]" with "<aString>" replace "[NSString stringWithCString:@<string stringconst>]" with "@<string stringconst>" replace "[NSString stringWithCString:<string stringconst>]" with "@<string stringconst>" replace "[@<string stringconst> cString]" with "<string stringconst>" replace "[<aString> cString][0] = '\0'" with "<aString> = @\"\"" replace "*[<aString> cString] = '\0'" with "<aString> = @\"\"" replace "extern NXAtom [<aString> cString]" with "extern NSString *<aString>" replace "extern NSString *[<aString> cString]" with "extern NSString *<aString>" replace "extern char *[<aString> cString]" with "extern NSString *<aString>" replace "extern const char *[<aString> cString]" with "extern NSString *<aString>" replace "free([<aString> cString])" with "[<aString> release]" replace "@<string str1><w w><string str2>" with "@<string str1><w w>@<string str2>" /*********** StringConversion: more cleanup ***********/ replace "[NSString stringWithCString:NULL]" with "nil" /* ??? */ replace "[NSString stringWithCString:nil]" with "nil" /* ??? */ replace "CONVERSION_EMPTYMETHOD" with "" replace ":<anExp> [<aString> cString]]" with ":<anExp> <aString>]" replace "[<anExp> [<aString> cString]]" with "[<anExp> <aString>]" replace ":<anExp> [<aString> cString]:" with ":<anExp> <aString>:" replace "[<anExp> [<aString> cString]:" with "[<anExp> <aString>:" /* This is a repeat of the above part of the file */ /* NOTE: The contents of this whole script are duplicated twice because the propagation of NSString type back to variable decls sometimes allows second and third order conversions. */ /*********** StringConversion: propagate NSString types up to variable decls ***********/ replace "{<w w1>}" with "{<w w1>CONVERSION_EMPTYMETHOD}" /* Prevent char buffers used in read() calls from being changed to NSStrings. */ replace "{<w w1><b imp><w w2>}" with same within ("<imp>") { replace "<any imp1><w w3>read(<fd>, <aString>, <bytesToRead>)<w w4><any imp2>" with "<any imp1><w w3>CONVERSIONread(<fd>, <aString>, <bytesToRead>)<w w4><any imp2>" within ("<imp1>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } within ("<imp2>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } } replace "CONVERSIONread" with "read" /* Prevent char buffers used in NXRead() calls from being changed to NSStrings. */ replace "{<w w1><b imp><w w2>}" with same within ("<imp>") { replace "<any imp1><w w3>NXRead(<stream>, <aString>, <bytesToRead>)<w w4><any imp2>" with "<any imp1><w w3>CONVERSIONNXRead(<stream>, <aString>, <bytesToRead>)<w w4><any imp2>" within ("<imp1>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } within ("<imp2>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } } replace "CONVERSIONNXRead" with "NXRead" /* Prevent char buffers used in gets() calls from being changed to NSStrings. */ replace "{<w w1><b imp><w w2>}" with same within ("<imp>") { replace "<any imp1><w w3>gets(<aString>)<w w4><any imp2>" with "<any imp1><w w3>CONVERSIONgets(<aString>)<w w4><any imp2>" within ("<imp1>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } within ("<imp2>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } } replace "CONVERSIONgets" with "gets" /* Prevent char buffers used in fgets() calls from being changed to NSStrings. */ replace "{<w w1><b imp><w w2>}" with same within ("<imp>") { replace "<any imp1><w w3>fgets(<aString>, <count>, <stream>)<w w4><any imp2>" with "<any imp1><w w3>CONVERSIONgets(<aString>, <count>, <stream>)<w w4><any imp2>" within ("<imp1>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } within ("<imp2>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } } replace "CONVERSIONfgets" with "fgets" /* this is necessary because tops won't do "<any imp1><w w3><t aString>++" */ replace "<w w1><t aString><w w2>++" with "(CONVERSIONPOSTPLUSPLUS(<w w1><aString><w w2>))" replace "<w w1><t aString><w w2>--" with "(CONVERSIONPOSTMINUSMINUS(<w w1><aString><w w2>))" /* Prevent char pointers that are post incremented from being changed to NSStrings. */ replace "{<w w1><b imp><w w2>}" with same within ("<imp>") { replace "<any imp1><w w3>CONVERSIONPOSTPLUSPLUS(<aString>)<w w4><any imp2>" with "<any imp1><w w3>NOCONVERSIONPOSTPLUSPLUS(<aString>)<w w4><any imp2>" within ("<imp1>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } within ("<imp2>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } } replace "(CONVERSIONPOSTPLUSPLUS(<w w1><t aString><w w2>))" with "<w w1><aString><w w2>++" replace "(NOCONVERSIONPOSTPLUSPLUS(<w w1><t aString><w w2>))" with "<w w1><aString><w w2>++" /* Prevent char pointers that are pre incremented from being changed to NSStrings. */ replace "{<w w1><b imp><w w2>}" with same within ("<imp>") { replace "<any imp1><w w3>++<w w5><t aString><w w4><any imp2>" with "<any imp1><w w3>(CONVERSIONPREPLUSPLUS(<w w5><aString>))<w w4><any imp2>" within ("<imp1>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } within ("<imp2>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } } replace "(CONVERSIONPREPLUSPLUS(<w w5><t aString>))" with "++<w w5><aString>" /* Prevent char pointers that are post decremented from being changed to NSStrings. */ replace "{<w w1><b imp><w w2>}" with same within ("<imp>") { replace "<any imp1><w w3>CONVERSIONPOSTMINUSMINUS(<aString>)<w w4><any imp2>" with "<any imp1><w w3>NOCONVERSIONPOSTMINUSMINUS(<aString>)<w w4><any imp2>" within ("<imp1>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } within ("<imp2>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } } replace "(CONVERSIONPOSTMINUSMINUS(<w w1><t aString><w w2>))" with "<w w1><aString><w w2>--" replace "(NOCONVERSIONPOSTMINUSMINUS(<w w1><t aString><w w2>))" with "<w w1><aString><w w2>--" /* Prevent char pointers that are pre decremented from being changed to NSStrings. */ replace "{<w w1><b imp><w w2>}" with same within ("<imp>") { replace "<any imp1><w w3>--<w w5><t aString><w w4><any imp2>" with "<any imp1><w w3>(CONVERSIONPREMINUSMINUS(<w w5><aString>))<w w4><any imp2>" within ("<imp1>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } within ("<imp2>") { /* char ..., NSString; */ replace "[NSString stringWithCString:<aString>]" with "[NSString NOCONVERSIONstringWithCString:<aString>]" } } replace "(CONVERSIONPREMINUSMINUS(<w w5><t aString>))" with "--<w w5><aString>" /* mark char* vars used in stringWithCString for conversion to NSStrings */ /* In the first replace, stringWithCString is replaced by CONVERSIONstringWithCString to make tops believe the rule won't infinitely recurse, which allows it to match more than once. */ replace "{<w w1><b imp><w w2>}" with same within ("<imp>") { replace "<any imp1><w w3>[NSString stringWithCString:<aString>]<w w4><any imp2>" with "<any imp1><w w3>[NSString CONVERSIONstringWithCString:<aString>]<w w4><any imp2>" within ("<imp1>") { /* char ..., NSString; */ replace "char <b stuff>, *<aString>;" with "char <b stuff>; CONVERSIONNSString( *<aString>);" replace "char <b stuff>, *<aString> = <val>;" with "char <b stuff>; CONVERSIONNSString( *<aString>) = [NSString stringWithCString:<val>];" replace "char <b stuff>, <aString>[<len>];" with "char <b stuff>; CONVERSIONNSString( *<aString>) = @\"\";" /* char ..., NSString, char ...; */ replace "char <b stuff>, *<aString>," with "char <b stuff>; CONVERSIONNSString( *<aString>); char" replace "char <b stuff>, *<aString> = <val>," with "char <b stuff>; CONVERSIONNSString( *<aString>) = [NSString stringWithCString:<val>]; char" replace "char <b stuff>, <aString>[<len>]," with "char <b stuff>; CONVERSIONNSString( *<aString>) = @\"\"; char" /* NSString; */ replace "char *<aString>;" with "CONVERSIONNSString( *<aString>);" replace "char *<aString>," with "CONVERSIONNSString( *<aString>); char" replace "char *<aString> = <val>;" with "CONVERSIONNSString( *<aString>) = [NSString stringWithCString:<val>];" replace "char *<aString> = <val>," with "CONVERSIONNSString( *<aString>) = [NSString stringWithCString:<val>]; char" replace "char <aString>[<len>];" with "CONVERSIONNSString( *<aString>);" replace "char <aString>[<len>]," with "CONVERSIONNSString( *<aString>)," replace "const CONVERSIONNSString" with "CONVERSIONNSString" } } replace "NOCONVERSIONstringWithCString" with "stringWithCString" replace "CONVERSIONstringWithCString" with "stringWithCString" replace "; CONVERSIONNSString( *<aString>)" with "; CONVERSIONNSString( *<aString>)" replace "CONVERSIONNSString( *<aString>); char" with "CONVERSIONNSString *<aString>; char" replace "CONVERSIONNSString( *<aString>) = <aStringExp>; char" with "CONVERSIONNSString *<aString> = <aStringExp>; char" /* strip parens in this rule to make tops believe the rule won't infinitely recurse, which allows it to match more than once. */ replace "{<w w1><b imp><w w2>}" with same within ("<imp>") { replace "<any imp1><w w3>CONVERSIONNSString( *<aString>)<w w4><any imp2>" with "<any imp1><w w3>CONVERSIONNSString *<aString><w w4><any imp2>" within ("<imp2>") { replace "<aString>" with "[<aString> cString]" } } replace "CONVERSIONNSString( *<aString>)" with "CONVERSIONNSString *<aString>" replace "CONVERSIONNSString" with "NSString" replace "[[<aString> cString] cString]" with "[<aString> cString]" /*********** StringConversion: ANSI str routines and NXCopyStringBuffer ***********/ /******** NOTE: duplicated in StringConversion.tops *********/ replace "sprintf([<str1> cString], <format>)" with "<str1> = [NSString stringWithCString:<format>]" replace "sprintf([<str1> cString], <format>, <b args>)" with "<str1> = [NSString stringWithFormat:[NSString stringWithCString:<format>], <b args>]" replace "strcat([<str1> cString], <str2>)" with "<str1> = [<str1> stringByAppendingString:[NSString stringWithCString:<str2>]]" replace "strncat([<str1> cString], <str2>, <len>)" with "<str1> = [<str1> stringByAppendingString:[[NSString stringWithCString:<str2>] substringToIndex:<len> - 1]]" replace "strcmp([<str1> cString], <str2>)" with "strcmp([<str1> cString], [[NSString stringWithCString:<str2>] cString])" replace "strcmp(<str1>, [<str2> cString])" with "strcmp([[NSString stringWithCString:<str1>] cString], [<str2> cString])" replace "strcmp([<str1> cString], [<str2> cString]) == 0" with "[<str1> isEqualToString:<str2>]" replace "!strcmp([<str1> cString], [<str2> cString])" with "[<str1> isEqualToString:<str2>]" replace "!(strcmp([<str1> cString], [<str2> cString]))" with "[<str1> isEqualToString:<str2>]" replace "(strcmp([<str1> cString], [<str2> cString]))" with "(![<str1> isEqualToString:<str2>])" replace "strcmp([<str1> cString], [<str2> cString])" with "[<str1> compare:<str2>]" /* strncmp assumes prefix search */ replace "strncmp([<str1> cString], <str2>, <length>)" with "strcmp([<str1> cString], [[NSString stringWithCString:<str2>] cString], <length>)" replace "strncmp(<str1>, [<str2> cString], <length>)" with "strcmp([[NSString stringWithCString:<str1>] cString], [<str2> cString], <length>)" replace "strncmp([<str1> cString], [<str2> cString], <length>) == 0" with "[<str1> hasPrefix:<str2>]" replace "!strncmp([<str1> cString], [<str2> cString], <length>)" with "[<str1> hasPrefix:<str2>]" replace "!(strncmp([<str1> cString], [<str2> cString], <length>))" with "[<str1> hasPrefix:<str2>]" replace "(strncmp([<str1> cString], [<str2> cString], <length>))" with "(![<str1> hasPrefix:<str2>])" replace "strcasecmp([<str1> cString], <str2>)" with "strcasecmp([<str1> cString], [[NSString stringWithCString:<str2>] cString])" replace "strcasecmp(<str1>, [<str2> cString])" with "strcasecmp([[NSString stringWithCString:<str1>] cString], [<str2> cString])" replace "strcasecmp([<str1> cString], [<str2> cString])" with "[<str1> compare:<str2> options:NSCaseInsensitiveSearch]" /* strncasecmp assumes prefix search */ replace "strncasecmp([<str1> cString], <str2>, <length>)" with "strncasecmp([<str1> cString], [[NSString stringWithCString:<str2>] cString], <length>)" replace "strncasecmp(<str1>, [<str2> cString], <length>)" with "strncasecmp([[NSString stringWithCString:<str1>] cString], [<str2> cString], <length>)" replace "strncasecmp([<str1> cString], [<str2> cString], <length>)" with "[<str1> compare:<str2> options:NSCaseInsensitiveSearch range:NSMakeRange(0, <length>)]" replace "strlen([<str1> cString]) == 0" with "[<str1> isEqualToString:@\"\"]" replace "!strlen([<str1> cString])" with "[<str1> isEqualToString:@\"\"]" replace "strlen([<str1> cString])" with "[<str1> length]" replace "strcpy([<str1> cString], [<str2> cString])" with "<str1> = <str2>" warning "StringConversion: This assignment of NSStrings used to be a strcpy(). With NStrings this is usually what you want because they are immutable. However, you may need to replace <str2> with [<str2> copy] or [[<str2> copy] autorelease]." replace "strcpy([<str1> cString], <str2>)" with "<str1> = [NSString stringWithCString:<str2>]" replace "strncpy([<str1> cString], <str2>, <length>)" with "<str1> = [[NSString stringWithCString:<str2>] substringToIndex:<length> - 1]" replace "[<str1> cString] = NXCopyStringBuffer([<str2> cString])" with "<str1> = [<str2> copy]" replace "[<str1> cString] = NXCopyStringBufferFromZone([<str2> cString], <zone>)" with "<str1> = [<str2> copyWithZone:<zone>]" /*********** StringConversion: a couple extra combinations ***********/ replace "<str1> = [<str1> stringByAppendingString:[NSString stringWithCString:<str2>]]; <str1> = [<str1> stringByAppendingString:[NSString stringWithCString:<str3>]]" with "<str1> = [<str1> stringByAppendingFormat:@\"%@%@\", [NSString stringWithCString:<str2>], [NSString stringWithCString:<str3>]]" replace "<str1> = [NSString stringWithCString:<str2>]; <str1> = [<str1> stringByAppendingString:[NSString stringWithCString:<str3>]]" with "<str1> = [NSString stringWithFormat:@\"%@%@\", [NSString stringWithCString:<str2>], [NSString stringWithCString:<str3>]]" /*********** StringConversion: boolean expressions ***********/ /********* NOTE: duplicated in StringConversion.tops *********/ /* some of these might not remain valid for deep conversions */ replace "if ([<str1> cString])" with "if (<str1>)" replace "([<str1> cString] &&" with "(<str1> &&" replace "([<str1> cString] ||" with "(<str1> ||" replace "&& [<str1> cString]" with "&& <str1>" replace "|| [<str1> cString]" with "|| <str1>" replace "![<str1> cString]" with "!<str1>" replace "!*[<str1> cString]" with "[<str1> isEqualToString:@\"\"]" replace "*[<str1> cString] == '\0'" with "[<str1> isEqualToString:@\"\"]" replace "*[<str1> cString] != '\0'" with "![<str1> isEqualToString:@\"\"]" replace "*[<str1> cString] == 0" with "[<str1> isEqualToString:@\"\"]" replace "*[<str1> cString] != 0" with "![<str1> isEqualToString:@\"\"]" replace "&& *[<str1> cString]" with "&& ![<str1> isEqualToString:@\"\"]" replace "|| *[<str1> cString]" with "|| ![<str1> isEqualToString:@\"\"]" replace "if (*[<str1> cString]" with "if(![<str1> isEqualToString:@\"\"]" replace "![<str1> isEqualToString:@\"\"] && ![<str1> isEqualToString:@\"\"]" with "![<str1> isEqualToString:@\"\"]" replace "![<str1> isEqualToString:@\"\"] || ![<str1> isEqualToString:@\"\"]" with "![<str1> isEqualToString:@\"\"]" replace "[<str1> isEqualToString:@\"\"] && [<str1> isEqualToString:@\"\"]" with "![<str1> isEqualToString:@\"\"]" replace "[<str1> isEqualToString:@\"\"] || [<str1> isEqualToString:@\"\"]" with "![<str1> isEqualToString:@\"\"]" /*********** StringConversion: cleanup ***********/ /********* NOTE: duplicated in StringConversion.tops *********/ replace "[NSString stringWithCString:<boolexp> ? <iftrue> : <iffalse>]" with "<boolexp> ? [NSString stringWithCString:<iftrue>] : [NSString stringWithCString:<iffalse>]" /* ??? */ replace "[<aString> cString] ?" with "<aString> ?" replace "[<aString> cString] = <anotherString>;" with "<aString> = [NSString stringWithCString:<anotherString>];" replace "[NSString stringWithCString:[NSString stringWithCString:<aString>]]" with "[NSString stringWithCString:<aString>]" replace "[[NSString stringWithCString:<aString>] cString]" with "<aString>" replace "[[<aString> cString] cString]" with "[<aString> cString]" replace "[NSString stringWithCString:[<aString> cString]]" with "<aString>" replace "[NSString stringWithCString:(char *)[<aString> cString]]" with "<aString>" replace "[NSString stringWithCString:(const char *)[<aString> cString]]" with "<aString>" replace "[NSString stringWithCString:@<string stringconst>]" with "@<string stringconst>" replace "[NSString stringWithCString:<string stringconst>]" with "@<string stringconst>" replace "[@<string stringconst> cString]" with "<string stringconst>" replace "[<aString> cString][0] = '\0'" with "<aString> = @\"\"" replace "*[<aString> cString] = '\0'" with "<aString> = @\"\"" replace "extern NXAtom [<aString> cString]" with "extern NSString *<aString>" replace "extern NSString *[<aString> cString]" with "extern NSString *<aString>" replace "extern char *[<aString> cString]" with "extern NSString *<aString>" replace "extern const char *[<aString> cString]" with "extern NSString *<aString>" replace "free([<aString> cString])" with "[<aString> release]" replace "@<string str1><w w><string str2>" with "@<string str1><w w>@<string str2>" /*********** StringConversion: more cleanup ***********/ replace "[NSString stringWithCString:NULL]" with "nil" /* ??? */ replace "[NSString stringWithCString:nil]" with "nil" /* ??? */ replace "CONVERSION_EMPTYMETHOD" with "" replace ":<anExp> [<aString> cString]]" with ":<anExp> <aString>]" replace "[<anExp> [<aString> cString]]" with "[<anExp> <aString>]" replace ":<anExp> [<aString> cString]:" with ":<anExp> <aString>:" replace "[<anExp> [<aString> cString]:" with "[<anExp> <aString>:"