home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / OpenStepConversion / UtilityScripts / shellscripts / generateScripts < prev    next >
Encoding:
Text File  |  1996-01-24  |  26.6 KB  |  956 lines

  1. #! /bin/csh -f
  2.  
  3. if (  $?conversionDir == 0 ) then
  4.     set conversionDir = "/NextDeveloper/OpenStepConversion/"
  5. endif
  6.  
  7. set tmp1 = "CONVERSION/tmp1"
  8. set tmp2 = "CONVERSION/tmp2"
  9. set tmp3 = "CONVERSION/tmp3"
  10. set tmp4 = "CONVERSION/tmp4"
  11. set tmp5 = "CONVERSION/tmp5"
  12. set tmp6 = "CONVERSION/tmp6"
  13. set tmp7 = "CONVERSION/tmp7"
  14. set tmp8 = "CONVERSION/tmp8"
  15. set tmp9 = "CONVERSION/tmp9"
  16.  
  17. ##############################################################################
  18. # produce optional conversion script
  19. ##############################################################################
  20.  
  21. # prep
  22. if ($1 == rect) then
  23.     echo 'Generating optional rect conversion script'
  24.     set optConvert = "CONVERSION/RectMethods"
  25.     set optConvertTops = "CONVERSION/RectMethods.tops"
  26. else if ($1 == point) then
  27.     set optConvert = "CONVERSION/RectMethods"
  28.     set optConvertTops = "CONVERSION/RectMethods.tops"
  29. else if ($1 == size) then
  30.     set optConvert = "CONVERSION/RectMethods"
  31.     set optConvertTops = "CONVERSION/RectMethods.tops"
  32. else if ($1 == string) then
  33.     echo 'Generating optional string conversion script'
  34.     set optConvert = "CONVERSION/StringMethods"
  35.     set optConvertTops = "CONVERSION/StringMethods.tops"
  36.     set optStringSym = "CONVERSION/StringDefines"
  37. else if ($1 == void) then
  38.     echo 'Generating optional void conversion script'
  39.     set optConvert = "CONVERSION/VoidMethods"
  40.     set optConvertTops = "CONVERSION/VoidMethods.tops"
  41. endif
  42.  
  43. # remove file info, we need to retain the SELF, ID, SELFNIL for void
  44. if ($1 == void) then
  45.     /bin/sed -e 's/^\([-A-Z]*\)[^-+]*[-+] *\(.*\)$/\1 \2/' $optConvert > $tmp1
  46. else
  47.     /bin/sed -e 's/^[^-+]*[-+] *\(.*\)$/\1/' $optConvert > $tmp1
  48. endif
  49.  
  50. # make every parameter typed
  51. /bin/sed -e 's/:/:(id)/g' $tmp1 > $tmp2
  52. /bin/sed -e 's/:(id)(/:(/g' $tmp2 > $tmp1
  53.  
  54. # remove parameter names
  55. /bin/sed -e 's/\(:([^)]*)\)[^ :;]*/\1/g' $tmp1 > $tmp2
  56.  
  57. # remove the semicolon
  58. /bin/sed -e 's/;//' $tmp2 > $tmp1
  59.  
  60. # mark the parameters to be converted
  61. switch ($1)
  62.     case rect:
  63.     /bin/sed -e 's/( *const *NXRect *\* *)/@convert@/g' $tmp1 > $tmp2
  64.     /bin/sed -e 's/( *NXRect *\* *)/@convert@/g' $tmp2 > $tmp1
  65.     breaksw
  66.     case point:
  67.     /bin/sed -e 's/( *const *NXPoint *\* *)/@convert@/g' $tmp1 > $tmp2
  68.     /bin/sed -e 's/( *NXPoint *\* *)/@convert@/g' $tmp2 > $tmp1
  69.     breaksw
  70.     case size:
  71.     /bin/sed -e 's/( *const *NXSize *\* *)/@convert@/g' $tmp1 > $tmp2
  72.     /bin/sed -e 's/( *NXSize *\* *)/@convert@/g' $tmp2 > $tmp1
  73.     breaksw
  74.     case string:
  75.     /bin/sed -e 's/( *const *char *\* *)/@convert@/g' $tmp1 > $tmp2
  76.     /bin/sed -e 's/( *char *\* *)/@convert@/g' $tmp2 > $tmp1
  77.     breaksw
  78.     case atom:
  79.     /bin/sed -e 's/( *NXAtom *)/@convert@/g' $tmp1 > $tmp2
  80.     /bin/cp $tmp2 $tmp1
  81.     breaksw
  82.     case stringarray:
  83.     /bin/sed -e 's/( *NXAtom *\* *)/@convert@/g' $tmp1 > $tmp2
  84.     /bin/sed -e 's/( *const *\* *char *\* *)/@convert@/g' $tmp2 > $tmp2
  85.     breaksw
  86.     case void:
  87.         breaksw
  88. endsw
  89.  
  90. # remove all other types
  91. /bin/sed -e 's/([^)]*)/ /g' $tmp1 > $tmp2
  92.  
  93. # thats where the void similarity ends
  94. if ($1 == void) goto doVoid
  95.  
  96. # number the converted params by the order they appear
  97. /bin/sed -e 's/\([^@]*\)@convert@ */\1<convert1> /' $tmp2 > $tmp1
  98. /bin/sed -e 's/\([^@]*\)@convert@ */\1<convert2> /' $tmp1 > $tmp2
  99. /bin/sed -e 's/\([^@]*\)@convert@ */\1<convert3> /' $tmp2 > $tmp1
  100. /bin/sed -e 's/\([^@]*\)@convert@ */\1<convert4> /' $tmp1 > $tmp2
  101. /bin/sed -e 's/\([^@]*\)@convert@ */\1<convert5> /' $tmp2 > $tmp1
  102. /bin/sed -e 's/\([^@]*\)@convert@ */\1<convert6> /' $tmp1 > $tmp2
  103.  
  104. # store those with return types converted in tmp3
  105. /usr/bin/egrep '^ *<' $tmp2 > $tmp3
  106.  
  107. # strip off any <convert> in the return type position
  108. /bin/sed -e 's/^ *<convert1>\(.*\)$/\1/' $tmp2 > $tmp1
  109.  
  110. # delete all <convert>s but <convert1> and save
  111. /bin/sed -e 's/<convert[^1]>//g' $tmp1 > $tmp4
  112.  
  113. # delete all <convert>s but <convert2> and save
  114. /bin/sed -e 's/<convert[^2]>//g' $tmp1 > $tmp5
  115.  
  116. # delete all <convert>s but <convert3> and save
  117. /bin/sed -e 's/<convert[^3]>//g' $tmp1 > $tmp6
  118.  
  119. # delete all <convert>s but <convert4> and save
  120. /bin/sed -e 's/<convert[^4]>//g' $tmp1 > $tmp7
  121.  
  122. # delete all <convert>s but <convert5> and save
  123. /bin/sed -e 's/<convert[^5]>//g' $tmp1 > $tmp8
  124.  
  125. # delete all <convert>s but <convert6> and save
  126. /bin/sed -e 's/<convert[^6]>//g' $tmp1 > $tmp9
  127.  
  128. # convert all convert[1-6] into just convert
  129. /bin/sed -e 's/<convert[0-9]>/<convert>/g' $tmp4 > $tmp1
  130. /bin/cat $tmp1 > $tmp4
  131.  
  132. # convert all convert[1-6] into just convert
  133. /bin/sed -e 's/<convert[0-9]>/<convert>/g' $tmp5 > $tmp1
  134. /bin/cat $tmp1 > $tmp5
  135.  
  136. # convert all convert[1-6] into just convert
  137. /bin/sed -e 's/<convert[0-9]>/<convert>/g' $tmp6 > $tmp1
  138. /bin/cat $tmp1 > $tmp6
  139.  
  140. # convert all convert[1-6] into just convert
  141. /bin/sed -e 's/<convert[0-9]>/<convert>/g' $tmp7 > $tmp1
  142. /bin/cat $tmp1 > $tmp7
  143.  
  144. # convert all convert[1-6] into just convert
  145. /bin/sed -e 's/<convert[0-9]>/<convert>/g' $tmp8 > $tmp1
  146. /bin/cat $tmp1 > $tmp8
  147.  
  148. # convert all convert[1-6] into just convert
  149. /bin/sed -e 's/<convert[0-9]>/<convert>/g' $tmp9 > $tmp1
  150. /bin/cat $tmp1 > $tmp9
  151.  
  152. # make a unique list of those that require replacement
  153. /bin/cat $tmp4 | /usr/bin/sort -ou  > $tmp1
  154. /bin/grep '<' $tmp1 > $tmp4
  155.  
  156. # make a unique list of those that require replacement
  157. /bin/cat $tmp5 | /usr/bin/sort -ou  > $tmp1
  158. /bin/grep '<' $tmp1 > $tmp5
  159.  
  160. # make a unique list of those that require replacement
  161. /bin/cat $tmp6 | /usr/bin/sort -ou  > $tmp1
  162. /bin/grep '<' $tmp1 > $tmp6
  163.  
  164. # make a unique list of those that require replacement
  165. /bin/cat $tmp7 | /usr/bin/sort -ou  > $tmp1
  166. /bin/grep '<' $tmp1 > $tmp7
  167.  
  168. # make a unique list of those that require replacement
  169. /bin/cat $tmp8 | /usr/bin/sort -ou  > $tmp1
  170. /bin/grep '<' $tmp1 > $tmp8
  171.  
  172. # make a unique list of those that require replacement
  173. /bin/cat $tmp9 | /usr/bin/sort -ou  > $tmp1
  174. /bin/grep '<' $tmp1 > $tmp9
  175.  
  176. # put these in good form for the script
  177. /bin/sed -e 's/^\(.*\)$/"\1"/' $tmp4 > $tmp1
  178. /bin/sed -e 's/^" *\(.*\)$/        "\1/' $tmp1 > $tmp2
  179. /bin/sed -e 's/:[     ]*\(.*\)/:\1/g' $tmp2 > $tmp1
  180. /bin/sed -e 's/ *"$/"/g' $tmp1 > $tmp4
  181.  
  182. # put these in good form for the script
  183. /bin/sed -e 's/^\(.*\)$/"\1"/' $tmp5 > $tmp1
  184. /bin/sed -e 's/^" *\(.*\)$/        "\1/' $tmp1 > $tmp2
  185. /bin/sed -e 's/:[     ]*\(.*\)/:\1/g' $tmp2 > $tmp1
  186. /bin/sed -e 's/ *"$/"/g' $tmp1 > $tmp5
  187.  
  188. # put these in good form for the script
  189. /bin/sed -e 's/^\(.*\)$/"\1"/' $tmp6 > $tmp1
  190. /bin/sed -e 's/^" *\(.*\)$/        "\1/' $tmp1 > $tmp2
  191. /bin/sed -e 's/:[     ]*\(.*\)/:\1/g' $tmp2 > $tmp1
  192. /bin/sed -e 's/ *"$/"/g' $tmp1 > $tmp6
  193.  
  194. # put these in good form for the script
  195. /bin/sed -e 's/^\(.*\)$/"\1"/' $tmp7 > $tmp1
  196. /bin/sed -e 's/^" *\(.*\)$/        "\1/' $tmp1 > $tmp2
  197. /bin/sed -e 's/:[     ]*\(.*\)/:\1/g' $tmp2 > $tmp1
  198. /bin/sed -e 's/ *"$/"/g' $tmp1 > $tmp7
  199.  
  200. # put these in good form for the script
  201. /bin/sed -e 's/^\(.*\)$/"\1"/' $tmp8 > $tmp1
  202. /bin/sed -e 's/^" *\(.*\)$/        "\1/' $tmp1 > $tmp2
  203. /bin/sed -e 's/:[     ]*\(.*\)/:\1/g' $tmp2 > $tmp1
  204. /bin/sed -e 's/ *"$/"/g' $tmp1 > $tmp8
  205.  
  206. # put these in good form for the script
  207. /bin/sed -e 's/^\(.*\)$/"\1"/' $tmp9 > $tmp1
  208. /bin/sed -e 's/^" *\(.*\)$/        "\1/' $tmp1 > $tmp2
  209. /bin/sed -e 's/:[     ]*\(.*\)/:\1/g' $tmp2 > $tmp1
  210. /bin/sed -e 's/ *"$/"/g' $tmp1 > $tmp9
  211.  
  212. # put them into the script
  213.  
  214. # *** tmp4 ***
  215.  
  216. switch ($1)
  217.     case rect:
  218.     echo '\
  219. \
  220. replacemethod "<sel>" with same {\
  221.     replace "<convert_type>" with "(NSRect)"\
  222.     replace "<convert_arg>" with "*<convert_arg>"\
  223.     }\
  224.     within ("<implementation>") {\
  225.     replace "<convert_param>->" with "*<convert_param>."\
  226.     replace "<convert_param>" with "&<convert_param>"\
  227.     }\
  228.     where "<sel>" isOneOf { \
  229.     "PLACEHOLDERMETHOD" ' > $optConvertTops
  230.     breaksw
  231.     case point:
  232.     echo '\
  233. \
  234. replacemethod "<sel>" with same {\
  235.     replace "<convert_type>" with "(NSPoint)"\
  236.     replace "<convert_arg>" with "*<convert_arg>"\
  237.     }\
  238.     within ("<implementation>") {\
  239.     replace "<convert_param>->" with "*<convert_param>."\
  240.     replace "<convert_param>" with "&<convert_param>"\
  241.     }\
  242.     where "<sel>" isOneOf { \
  243.     "PLACEHOLDERMETHOD" ' >> $optConvertTops
  244.     breaksw
  245.     case size:
  246.     echo '\
  247. \
  248. replacemethod "<sel>" with same {\
  249.     replace "<convert_type>" with "(NSSize)"\
  250.     replace "<convert_arg>" with "*<convert_arg>"\
  251.     }\
  252.     within ("<implementation>") {\
  253.     replace "<convert_param>->" with "*<convert_param>."\
  254.     replace "<convert_param>" with "&<convert_param>"\
  255.     }\
  256.     where "<sel>" isOneOf { \
  257.     "PLACEHOLDERMETHOD" ' >> $optConvertTops
  258.     breaksw
  259.     case string:
  260. echo '\
  261. \
  262. replacemethod "<sel>" with same {\
  263.     replace "<convert_arg>" with "[NSString stringWithCString:<convert_arg>]"\
  264.     replace "<convert_type>" with "(NSString *)"\
  265.     }\
  266.     within ("<implementation>") {\
  267.     replace "<convert_param>" with "[<convert_param> cString]"\
  268.     }\
  269.     where "<sel>" isOneOf { \
  270.     "PLACEHOLDERMETHOD" ' > $optConvertTops
  271.     breaksw
  272. endsw
  273.  
  274. # insert the methods
  275. /bin/cat $tmp4 >> $optConvertTops
  276.  
  277. echo '    }' >> $optConvertTops
  278. echo  >> $optConvertTops
  279.  
  280. # put them into the script
  281.  
  282. # *** tmp5 ***
  283.  
  284. switch ($1)
  285.     case rect:
  286.     echo '\
  287. \
  288. replacemethod "<sel>" with same {\
  289.     replace "<convert_type>" with "(NSRect)"\
  290.     replace "<convert_arg>" with "*<convert_arg>"\
  291.     }\
  292.     within ("<implementation>") {\
  293.     replace "<convert_param>->" with "*<convert_param>."\
  294.     replace "<convert_param>" with "&<convert_param>"\
  295.     }\
  296.     where "<sel>" isOneOf { \
  297.     "PLACEHOLDERMETHOD" ' >> $optConvertTops
  298.     breaksw
  299.     case point:
  300.     echo '\
  301. \
  302. replacemethod "<sel>" with same {\
  303.     replace "<convert_type>" with "(NSPoint)"\
  304.     replace "<convert_arg>" with "*<convert_arg>"\
  305.     }\
  306.     within ("<implementation>") {\
  307.     replace "<convert_param>->" with "*<convert_param>."\
  308.     replace "<convert_param>" with "&<convert_param>"\
  309.     }\
  310.     where "<sel>" isOneOf { \
  311.     "PLACEHOLDERMETHOD" ' >> $optConvertTops
  312.     breaksw
  313.     case size:
  314.     echo '\
  315. \
  316. replacemethod "<sel>" with same {\
  317.     replace "<convert_type>" with "(NSSize)"\
  318.     replace "<convert_arg>" with "*<convert_arg>"\
  319.     }\
  320.     within ("<implementation>") {\
  321.     replace "<convert_param>->" with "*<convert_param>."\
  322.     replace "<convert_param>" with "&<convert_param>"\
  323.     }\
  324.     where "<sel>" isOneOf { \
  325.     "PLACEHOLDERMETHOD" ' >> $optConvertTops
  326.     breaksw
  327.     case string:
  328. echo '\
  329. \
  330. replacemethod "<sel>" with same {\
  331.     replace "<convert_arg>" with "[NSString stringWithCString:<convert_arg>]"\
  332.     replace "<convert_type>" with "(NSString *)"\
  333.     }\
  334.     within ("<implementation>") {\
  335.     replace "<convert_param>" with "[<convert_param> cString]"\
  336.     }\
  337.     where "<sel>" isOneOf { \
  338.     "PLACEHOLDERMETHOD" ' >> $optConvertTops
  339.     breaksw
  340. endsw
  341.  
  342. # insert the methods
  343. /bin/cat $tmp5 >> $optConvertTops
  344.  
  345. echo '    }' >> $optConvertTops
  346. echo  >> $optConvertTops
  347.  
  348. # put them into the script
  349.  
  350. # *** tmp6 ***
  351.  
  352. switch ($1)
  353.     case rect:
  354.     echo '\
  355. \
  356. replacemethod "<sel>" with same {\
  357.     replace "<convert_type>" with "(NSRect)"\
  358.     replace "<convert_arg>" with "*<convert_arg>"\
  359.     }\
  360.     within ("<implementation>") {\
  361.     replace "<convert_param>->" with "*<convert_param>."\
  362.     replace "<convert_param>" with "&<convert_param>"\
  363.     }\
  364.     where "<sel>" isOneOf { \
  365.     "PLACEHOLDERMETHOD" ' >> $optConvertTops
  366.     breaksw
  367.     case point:
  368.     echo '\
  369. \
  370. replacemethod "<sel>" with same {\
  371.     replace "<convert_type>" with "(NSPoint)"\
  372.     replace "<convert_arg>" with "*<convert_arg>"\
  373.     }\
  374.     within ("<implementation>") {\
  375.     replace "<convert_param>->" with "*<convert_param>."\
  376.     replace "<convert_param>" with "&<convert_param>"\
  377.     }\
  378.     where "<sel>" isOneOf { \
  379.     "PLACEHOLDERMETHOD" ' >> $optConvertTops
  380.     breaksw
  381.     case size:
  382.     echo '\
  383. \
  384. replacemethod "<sel>" with same {\
  385.     replace "<convert_type>" with "(NSSize)"\
  386.     replace "<convert_arg>" with "*<convert_arg>"\
  387.     }\
  388.     within ("<implementation>") {\
  389.     replace "<convert_param>->" with "*<convert_param>."\
  390.     replace "<convert_param>" with "&<convert_param>"\
  391.     }\
  392.     where "<sel>" isOneOf { \
  393.     "PLACEHOLDERMETHOD" ' >> $optConvertTops
  394.     breaksw
  395.     case string:
  396. echo '\
  397. \
  398. replacemethod "<sel>" with same {\
  399.     replace "<convert_arg>" with "[NSString stringWithCString:<convert_arg>]"\
  400.     replace "<convert_type>" with "(NSString *)"\
  401.     }\
  402.     within ("<implementation>") {\
  403.     replace "<convert_param>" with "[<convert_param> cString]"\
  404.     }\
  405.     where "<sel>" isOneOf { \
  406.     "PLACEHOLDERMETHOD" ' >> $optConvertTops
  407.     breaksw
  408. endsw
  409.  
  410. # insert the methods
  411. /bin/cat $tmp6 >> $optConvertTops
  412.  
  413. echo '    }' >> $optConvertTops
  414. echo  >> $optConvertTops
  415.  
  416. # put them into the script
  417.  
  418. # *** tmp7 ***
  419.  
  420. switch ($1)
  421.     case rect:
  422.     echo '\
  423. \
  424. replacemethod "<sel>" with same {\
  425.     replace "<convert_type>" with "(NSRect)"\
  426.     replace "<convert_arg>" with "*<convert_arg>"\
  427.     }\
  428.     within ("<implementation>") {\
  429.     replace "<convert_param>->" with "*<convert_param>."\
  430.     replace "<convert_param>" with "&<convert_param>"\
  431.     }\
  432.     where "<sel>" isOneOf { \
  433.     "PLACEHOLDERMETHOD" ' >> $optConvertTops
  434.     breaksw
  435.     case point:
  436.     echo '\
  437. \
  438. replacemethod "<sel>" with same {\
  439.     replace "<convert_type>" with "(NSPoint)"\
  440.     replace "<convert_arg>" with "*<convert_arg>"\
  441.     }\
  442.     within ("<implementation>") {\
  443.     replace "<convert_param>->" with "*<convert_param>."\
  444.     replace "<convert_param>" with "&<convert_param>"\
  445.     }\
  446.     where "<sel>" isOneOf { \
  447.     "PLACEHOLDERMETHOD" ' >> $optConvertTops
  448.     breaksw
  449.     case size:
  450.     echo '\
  451. \
  452. replacemethod "<sel>" with same {\
  453.     replace "<convert_type>" with "(NSSize)"\
  454.     replace "<convert_arg>" with "*<convert_arg>"\
  455.     }\
  456.     within ("<implementation>") {\
  457.     replace "<convert_param>->" with "*<convert_param>."\
  458.     replace "<convert_param>" with "&<convert_param>"\
  459.     }\
  460.     where "<sel>" isOneOf { \
  461.     "PLACEHOLDERMETHOD" ' >> $optConvertTops
  462.     breaksw
  463.     case string:
  464. echo '\
  465. \
  466. replacemethod "<sel>" with same {\
  467.     replace "<convert_arg>" with "[NSString stringWithCString:<convert_arg>]"\
  468.     replace "<convert_type>" with "(NSString *)"\
  469.     }\
  470.     within ("<implementation>") {\
  471.     replace "<convert_param>" with "[<convert_param> cString]"\
  472.     }\
  473.     where "<sel>" isOneOf { \
  474.     "PLACEHOLDERMETHOD" ' >> $optConvertTops
  475.     breaksw
  476. endsw
  477.  
  478. # insert the methods
  479. /bin/cat $tmp7 >> $optConvertTops
  480.  
  481. echo '    }' >> $optConvertTops
  482. echo  >> $optConvertTops
  483.  
  484. # put them into the script
  485.  
  486. # *** tmp8 ***
  487.  
  488. switch ($1)
  489.     case rect:
  490.     echo '\
  491. \
  492. replacemethod "<sel>" with same {\
  493.     replace "<convert_type>" with "(NSRect)"\
  494.     replace "<convert_arg>" with "*<convert_arg>"\
  495.     }\
  496.     within ("<implementation>") {\
  497.     replace "<convert_param>->" with "*<convert_param>."\
  498.     replace "<convert_param>" with "&<convert_param>"\
  499.     }\
  500.     where "<sel>" isOneOf { \
  501.     "PLACEHOLDERMETHOD" ' >> $optConvertTops
  502.     breaksw
  503.     case point:
  504.     echo '\
  505. \
  506. replacemethod "<sel>" with same {\
  507.     replace "<convert_type>" with "(NSPoint)"\
  508.     replace "<convert_arg>" with "*<convert_arg>"\
  509.     }\
  510.     within ("<implementation>") {\
  511.     replace "<convert_param>->" with "*<convert_param>."\
  512.     replace "<convert_param>" with "&<convert_param>"\
  513.     }\
  514.     where "<sel>" isOneOf { \
  515.     "PLACEHOLDERMETHOD" ' >> $optConvertTops
  516.     breaksw
  517.     case size:
  518.     echo '\
  519. \
  520. replacemethod "<sel>" with same {\
  521.     replace "<convert_type>" with "(NSSize)"\
  522.     replace "<convert_arg>" with "*<convert_arg>"\
  523.     }\
  524.     within ("<implementation>") {\
  525.     replace "<convert_param>->" with "*<convert_param>."\
  526.     replace "<convert_param>" with "&<convert_param>"\
  527.     }\
  528.     where "<sel>" isOneOf { \
  529.     "PLACEHOLDERMETHOD" ' >> $optConvertTops
  530.     breaksw
  531.     case string:
  532. echo '\
  533. \
  534. replacemethod "<sel>" with same {\
  535.     replace "<convert_arg>" with "[NSString stringWithCString:<convert_arg>]"\
  536.     replace "<convert_type>" with "(NSString *)"\
  537.     }\
  538.     within ("<implementation>") {\
  539.     replace "<convert_param>" with "[<convert_param> cString]"\
  540.     }\
  541.     where "<sel>" isOneOf { \
  542.     "PLACEHOLDERMETHOD" ' >> $optConvertTops
  543.     breaksw
  544. endsw
  545.  
  546. # insert the methods
  547. /bin/cat $tmp8 >> $optConvertTops
  548.  
  549. echo '    }' >> $optConvertTops
  550. echo  >> $optConvertTops
  551.  
  552. # put them into the script
  553.  
  554. # *** tmp9 ***
  555.  
  556. switch ($1)
  557.     case rect:
  558.     echo '\
  559. \
  560. replacemethod "<sel>" with same {\
  561.     replace "<convert_type>" with "(NSRect)"\
  562.     replace "<convert_arg>" with "*<convert_arg>"\
  563.     }\
  564.     within ("<implementation>") {\
  565.     replace "<convert_param>->" with "*<convert_param>."\
  566.     replace "<convert_param>" with "&<convert_param>"\
  567.     }\
  568.     where "<sel>" isOneOf { \
  569.     "PLACEHOLDERMETHOD" ' >> $optConvertTops
  570.     breaksw
  571.     case point:
  572.     echo '\
  573. \
  574. replacemethod "<sel>" with same {\
  575.     replace "<convert_type>" with "(NSPoint)"\
  576.     replace "<convert_arg>" with "*<convert_arg>"\
  577.     }\
  578.     within ("<implementation>") {\
  579.     replace "<convert_param>->" with "*<convert_param>."\
  580.     replace "<convert_param>" with "&<convert_param>"\
  581.     }\
  582.     where "<sel>" isOneOf { \
  583.     "PLACEHOLDERMETHOD" ' >> $optConvertTops
  584.     breaksw
  585.     case size:
  586.     echo '\
  587. \
  588. replacemethod "<sel>" with same {\
  589.     replace "<convert_type>" with "(NSSize)"\
  590.     replace "<convert_arg>" with "*<convert_arg>"\
  591.     }\
  592.     within ("<implementation>") {\
  593.     replace "<convert_param>->" with "*<convert_param>."\
  594.     replace "<convert_param>" with "&<convert_param>"\
  595.     }\
  596.     where "<sel>" isOneOf { \
  597.     "PLACEHOLDERMETHOD" ' >> $optConvertTops
  598.     breaksw
  599.     case string:
  600. echo '\
  601. \
  602. replacemethod "<sel>" with same {\
  603.     replace "<convert_arg>" with "[NSString stringWithCString:<convert_arg>]"\
  604.     replace "<convert_type>" with "(NSString *)"\
  605.     }\
  606.     within ("<implementation>") {\
  607.     replace "<convert_param>" with "[<convert_param> cString]"\
  608.     }\
  609.     where "<sel>" isOneOf { \
  610.     "PLACEHOLDERMETHOD" ' >> $optConvertTops
  611.     breaksw
  612. endsw
  613.  
  614. # insert the methods
  615. /bin/cat $tmp9 >> $optConvertTops
  616.  
  617. echo '    }' >> $optConvertTops
  618. echo  >> $optConvertTops
  619.  
  620. # now do the return type conversions
  621.  
  622. # delete all <convert>s but <convert1> and save
  623. /bin/sed -e 's/<convert[^1]>/ /g' $tmp3 | sed -e 's/<convert1> */<convert>/' > $tmp2
  624.  
  625. # put these in good form for the script
  626. /bin/sed -e 's/^\(.*\)$/"\1"/' $tmp2 > $tmp1
  627. /bin/sed -e 's/^" *\(.*\)$/        "\1/' $tmp1 > $tmp2
  628. /bin/sed -e 's/: *\(.*\)$/:\1/g' $tmp2 > $tmp1
  629. /bin/sed -e 's/ *"$/"/g' $tmp1 > $tmp2
  630.  
  631. # remove duplicates
  632. /bin/cat $tmp2 | /usr/bin/sort -u > $tmp1
  633.  
  634. # put them into the script
  635.  
  636. switch ($1)
  637.     case rect:
  638.     echo '\
  639. \
  640. replacemethod "<sel>" with same {\
  641.     replace "<rettype>" with "(NSRect)"\
  642.     }\
  643.     within ("<implementation>") {\
  644.     replace "return <exp>;" with "return *<exp>;"\
  645.     }\
  646.     where "<sel>" isOneOf { \
  647.     "PLACEHOLDERMETHOD" ' >> $optConvertTops
  648.     breaksw
  649.     case point:
  650.     echo '\
  651. \
  652. replacemethod "<sel>" with same {\
  653.     replace "<rettype>" with "(NSPoint)"\
  654.     }\
  655.     within ("<implementation>") {\
  656.     replace "return <exp>;" with "return *<exp>;"\
  657.     }\
  658.     where "<sel>" isOneOf { \
  659.     "PLACEHOLDERMETHOD" ' >> $optConvertTops
  660.     breaksw
  661.     case size:
  662.     echo '\
  663. \
  664. replacemethod "<sel>" with same {\
  665.     replace "<rettype>" with "(NSPoint)"\
  666.     }\
  667.     within ("<implementation>") {\
  668.     replace "return <exp>;" with "return *<exp>;"\
  669.     }\
  670.     where "<sel>" isOneOf { \
  671.     "PLACEHOLDERMETHOD" ' >> $optConvertTops
  672.     breaksw
  673.     case string:
  674.     echo '\
  675. \
  676. replacemethod "<sel>" with same {\
  677.     replace "<rettype>" with "(NSString *)"\
  678.     replace "<call>" with "[<call> cString]"\
  679.     }\
  680.     within ("<implementation>") {\
  681.     replace "return <exp>;" with "return [NSString stringWithCString:<exp>];"\
  682.     }\
  683.     where "<sel>" isOneOf { \
  684.     "PLACEHOLDERMETHOD" ' >> $optConvertTops
  685.     breaksw
  686.     case void:
  687.     echo '\
  688. \
  689. replacemethod "<sel>" with same {\
  690.     replace "<rettype>" with "(void)"\
  691.     }\
  692.     within ("<implementation>") {\
  693.     replace "return <exp>;" with "return [NSString stringWithCString:<exp>];"\
  694.     }\
  695.     where "<sel>" isOneOf { \
  696.     "PLACEHOLDERMETHOD" ' >> $optConvertTops
  697.     breaksw
  698. endsw
  699.  
  700. # insert the methods
  701. /bin/cat $tmp1 >> $optConvertTops
  702.  
  703. # finish up the rule
  704. echo '    }' >> $optConvertTops
  705. echo  >> $optConvertTops
  706.  
  707. # do the string defines
  708. if ($1 == string) then
  709.  
  710.     /usr/bin/egrep '#define' $optStringSym > $tmp2
  711.     /bin/sed -e 's/^[^#]*#define[     ]*\([^     ]*\)[     ]*\(.*\)$/        "\1",/' $tmp2 > $tmp1
  712.     echo '\
  713. \
  714. replace "<symbol>" with "[<symbol> cString]"\
  715.     where "<symbol>" isOneOf { \
  716.     "PLACEHOLDERSYMBOL" ' >> $optConvertTops
  717.    
  718.     cat $tmp1 >> $optConvertTops
  719.  
  720.     echo '    } \
  721. \
  722. replace "#define [<symbol> cString] <t function>(<b args>)" with "#define <symbol> [NSString stringWithCString:<t function>(<b args>)]" \
  723. \
  724. replace "#define [<symbol> cString] <t aString>" with "#define <symbol> [NSString stringWithCString:<t aString>]" \
  725. ' >> $optConvertTops
  726.  
  727. endif
  728.  
  729. exit
  730.  
  731. doVoid:
  732. # here is the void stuff, so far we have removed parameter types and names
  733.  
  734. # make a unique list of those that require replacement
  735. /bin/cat $tmp2 | /usr/bin/sort -ou  > $tmp1
  736.  
  737. # put these in good form for the script
  738. /bin/sed -e 's/^\([-A-Z]*\) *\(.*\)$/\1       "\2"/' $tmp1 > $tmp2
  739. /bin/sed -e 's/: *\(.*\)$/:\1/g' $tmp2 > $tmp1
  740. /bin/sed -e 's/ *"$/"/g' $tmp1 > $tmp2
  741.  
  742. echo ' \
  743. SELFNIL-BOOL        "PLACEHOLDER" \
  744. SELF-VOID        "PLACEHOLDER" \
  745. OBJ-VOID        "PLACEHOLDER"' >> $tmp2
  746.  
  747. # store the id to void methods in $tmp3
  748. /usr/bin/egrep '^ *OBJ-VOID' $tmp2 > $tmp1
  749. /bin/sed -e 's/^ *OBJ-VOID\(.*\)$/\1/' $tmp1 > $tmp3
  750.  
  751. # put them in the script
  752. echo '\
  753. replacemethod "<sel>" with same {\
  754.     replace "<rettype>" with "(void)"\
  755.     }\
  756.     where "<sel>" isOneOf {' > $optConvertTops
  757.  
  758. #insert the methods
  759. /bin/cat $tmp3 >> $optConvertTops    
  760.  
  761. echo '    }' >> $optConvertTops
  762. echo  >> $optConvertTops
  763.  
  764. # store the id to void methods in $tmp3
  765. /usr/bin/egrep '^ *SELFNIL-BOOL' $tmp2 > $tmp1
  766. /bin/sed -e 's/^ *SELFNIL-BOOL\(.*\)$/\1/' $tmp1 > $tmp3
  767.  
  768. # put them in the script
  769. echo '\
  770. replacemethod "<sel>" with same { \
  771.     replace "<rettype>" with "(BOOL)" \
  772.     } \
  773.     within ("<implementation>") {  \
  774.     replace "return self;" with "return YES;" \
  775.     replace "return (self);" with "return YES;" \
  776.     replace "return nil;" with "return NO;" \
  777.     replace "return (nil);" with "return NO;" \
  778.     replace "return NULL;" with "return NO;" \
  779.     replace "return (NULL);" with "return NO;" \
  780.     } \
  781.     where "<sel>" isOneOf {' >> $optConvertTops
  782.  
  783. #insert the methods
  784. /bin/cat $tmp3 >> $optConvertTops    
  785.  
  786. echo '    }' >> $optConvertTops
  787. echo  >> $optConvertTops
  788.  
  789. # store the self to void methods in $tmp3
  790. /usr/bin/egrep '^ *SELF-VOID' $tmp2 > $tmp1
  791. /bin/sed -e 's/^ *SELF-VOID\(.*\)$/\1/' $tmp1 > $tmp3
  792.  
  793. # put them in the script
  794. echo '\
  795. replacemethod "<sel>" with same {\
  796.     replace "<rettype>" with "(void)"\
  797.     }\
  798.     within ("<implementation>") { \
  799.     replace "return self;" with "return;"\
  800.     replace "return (self)" with "return;"\
  801.     }\
  802.     where "<sel>" isOneOf {' >> $optConvertTops
  803.  
  804. #insert the methods
  805. /bin/cat $tmp3 >> $optConvertTops    
  806.  
  807. echo '    }' >> $optConvertTops
  808. echo  >> $optConvertTops
  809.     
  810. # now we do some extra work for the SELF-VOID calls
  811.  
  812. # number the params by the order they appear
  813. /bin/sed -e 's/\([^:]*\):/\1@<convert1>/' $tmp3 > $tmp1
  814. /bin/sed -e 's/\([^:]*\):/\1@<convert2>/' $tmp1 > $tmp2
  815. /bin/sed -e 's/\([^:]*\):/\1@<convert3>/' $tmp2 > $tmp1
  816. /bin/sed -e 's/\([^:]*\):/\1@<convert4>/' $tmp1 > $tmp2
  817. /bin/sed -e 's/\([^:]*\):/\1@<convert5>/' $tmp2 > $tmp1
  818. /bin/sed -e 's/\([^:]*\):/\1@<convert6>/' $tmp1 > $tmp2
  819. /bin/sed -e 's/\([^:]*\):/\1@<convert7>/' $tmp2 > $tmp1
  820.  
  821. # write out the rules
  822. echo '\
  823. \
  824. replace "if (<b cond>) return [<obj> <b method>];" with "if (<b cond>) {[<obj> <b method>]; return;}" \
  825.     where "<b method>" isOneOf {' >> $optConvertTops
  826.  
  827. /bin/cat $tmp3 >> $optConvertTops
  828.  
  829. echo '    } \
  830.  \
  831. replace "if (<b cond>) return ([<obj> <b method>]);" with "if (<b cond>) {[<obj> <b method>]; return;}" \
  832.     where "<b method>" isOneOf  {' >> $optConvertTops
  833.  
  834. /bin/cat $tmp3 >> $optConvertTops
  835.  
  836. echo '    } \
  837.  \
  838. replace "return [<obj> <b method>];" with "[<obj> <b method>]; return;" \
  839.     where "<b method>" isOneOf  {' >> $optConvertTops
  840.  
  841. /bin/cat $tmp3 >> $optConvertTops
  842.  
  843. echo '    } \
  844.  \
  845. replace "return ([<obj> <b method>]);" with "[<obj> <b method>]; return;" \
  846.     where "<b method>" isOneOf  {' >> $optConvertTops
  847.  
  848. /bin/cat $tmp3 >> $optConvertTops
  849.  
  850. echo '    } \
  851.  \
  852. replace "if (<b cond>) <token var> = [<token obj> <b method>];" \
  853. with "if (<b cond>) {[<token obj> <b method>]; <token var> = <token obj>;}" \
  854.     where "<b method>" isOneOf  {' >> $optConvertTops
  855.  
  856. /bin/cat $tmp3 >> $optConvertTops
  857.  
  858. echo '    } \
  859.  \
  860. replace "if (<b cond>) <token var> = [<obj> <b method>];" with "if (<b cond>) {<token var> = <obj>; [<token var> <b method>];}" \
  861.     where "<b method>" isOneOf  {' >> $optConvertTops
  862.  
  863. /bin/cat $tmp3 >> $optConvertTops
  864.  
  865. echo '    } \
  866.  \
  867. replace "<w w><token var> = [<token obj> <b method>];" with "[<token obj> <b method>];<w w><token var> = <token obj>;" \
  868.     where "<b method>" isOneOf  {' >> $optConvertTops
  869.  
  870. /bin/cat $tmp3 >> $optConvertTops
  871.  
  872. echo '    } \
  873.  \
  874. replace "<w w><token var> = [<obj> <b method>];" with "<token var> = <obj>;<w w>[<token var> <b method>];" \
  875.     where "<b method>" isOneOf  {' >> $optConvertTops
  876.  
  877. /bin/cat $tmp3 >> $optConvertTops
  878.  
  879. echo '    } \
  880.  \
  881. replace "if (<b cond>) [[<token obj> <b method>] <b dosomething>];" with "if (<b cond>) {[<token obj> <b method>]; [<token obj> <b dosomething>];}" \
  882.     where "<b method>" isOneOf  {' >> $optConvertTops
  883.  
  884. /bin/cat $tmp3 >> $optConvertTops
  885.  
  886. echo '    } \
  887.  \
  888. replace "if (<b cond>) <token var> = [[<token obj> <b method>] <b dosomething>];" \
  889. with  "if (<b cond>) {[<token obj> <b method>]; <token var> = [<token obj> <b dosomething>];}" \
  890.     where "<b method>" isOneOf  {' >> $optConvertTops
  891.  
  892. /bin/cat $tmp3 >> $optConvertTops
  893.  
  894. echo '    } \
  895.  \
  896. replace "<w w><token var> = [[<token obj> <b method>] <b dosomething>];" \
  897. with  "[<token obj> <b method>];<w w><token var> = [<token obj> <b dosomething>];" \
  898.     where "<b method>" isOneOf  {' >> $optConvertTops
  899.  
  900. /bin/cat $tmp3 >> $optConvertTops
  901.  
  902. echo '    } \
  903.  \
  904. replace "<w w>[[<token obj> <b method>] <b dosomething>];" \
  905. with  "[<token obj> <b method>];<w w>[<token obj> <b dosomething>];" \
  906.     where "<b method>" isOneOf  {' >> $optConvertTops
  907.  
  908. /bin/cat $tmp3 >> $optConvertTops
  909.  
  910. echo '    } \
  911.  \
  912. replace "if (<b cond>) [<b objAndMethod1>:[<token obj> <b method>]<w w><b rest>];" \
  913. with  "if (<b cond>) {[<token obj> <b method>]; [<b objAndMethod1>:<token obj><w w><b rest>];}" \
  914.     where "<b method>" isOneOf  {' >> $optConvertTops
  915.  
  916. /bin/cat $tmp3 >> $optConvertTops
  917.  
  918. echo '    } \
  919.  \
  920. replace "<w w1>[<b objAndMethod1>:[<token obj> <b method>]<w w2><b rest>];" \
  921. with  "[<token obj> <b method>];<w w1>[<b objAndMethod1>:<token obj><w w2><b rest>];" \
  922.     where "<b method>" isOneOf  {' >> $optConvertTops
  923.  
  924. /bin/cat $tmp3 >> $optConvertTops
  925.  
  926. echo '    } \
  927.  \
  928. replace "[[[<token obj> <b dosomething>] <b method>] <b dosomething Else>];" \
  929. with "{ \
  930.     id newVar = [<token obj> <b dosomething>]; \
  931.     [newVar <b method>]; \
  932.     [newVar <b dosomething>Else]; \
  933. }" \
  934.     warning "VoidConversion:  creating new variable to deal with methods returning void (previously self)" \
  935.     where "<b method>" isOneOf  {' >> $optConvertTops
  936.  
  937. /bin/cat $tmp3 >> $optConvertTops
  938.  
  939. echo '    } \
  940.  \
  941. replace "- (void)<b method><w w1>{<w w2><b implementation>return;}" \
  942. with "- (void)<b method><w w1>{<w w2><b implementation> \
  943. }" \
  944. ' >> $optConvertTops
  945.  
  946. /bin/rm -rf $tmp1
  947. /bin/rm -rf $tmp2
  948. /bin/rm -rf $tmp3
  949. /bin/rm -rf $tmp4
  950. /bin/rm -rf $tmp5
  951. /bin/rm -rf $tmp6
  952. /bin/rm -rf $tmp7
  953. /bin/rm -rf $tmp8
  954. /bin/rm -rf $tmp9
  955.  
  956.