home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / OpenStepConversion / UtilityScripts / shellscripts / preprocess < prev    next >
Encoding:
Text File  |  1996-03-28  |  9.5 KB  |  288 lines

  1. #!/bin/csh -f
  2. # produce method lists and class heirarchies for the conversion process
  3. ##############################################################################
  4.  
  5. ##############################################################################
  6. # setup
  7. ##############################################################################
  8.  
  9. if ( $#argv == 0 ) then
  10.     set preprocessFiles = `find . \( -name '*.[hmcCM]' -o -name '*.psw*' \) -print`
  11. else 
  12.     set preprocessFiles = ($argv)
  13. endif
  14.  
  15. if (  $?conversionDir == 0 ) then
  16.     set conversionDir = "/NextDeveloper/OpenStepConversion/"
  17. endif
  18.  
  19. set classHierarchy1 = "CONVERSION/ClassHierarchy1"
  20.  
  21. set classHierarchy2 = "CONVERSION/ClassHierarchy2"
  22.  
  23. set allMethodsFile = "CONVERSION/allmethods"
  24.  
  25. set optionalRect = "CONVERSION/RectMethods"
  26.  
  27. set optionalString = "CONVERSION/StringMethods"
  28.  
  29. set optionalStringSym = "CONVERSION/StringDefines"
  30.  
  31. # set optionalStringFunc = "CONVERSION/optStringFunctions"
  32.  
  33. set optionalVoid = "CONVERSION/VoidMethods"
  34.  
  35. set nameConflicts = "CONVERSION/nameConflicts"
  36.  
  37. set tmp1 = "CONVERSION/tmp1"
  38.  
  39. set tmp2 = "CONVERSION/tmp2"
  40.  
  41. set nameChanges = "$conversionDir/ConversionScripts/NSNameConversion.tops"
  42.  
  43. set allMethodsScript = "$conversionDir/UtilityScripts/topsscripts/findAllMethods.tops"
  44.  
  45. set cleanMethods = "$conversionDir/UtilityScripts/topsscripts/cleanUpMethods.tops"
  46.  
  47. set removeCommon = "$conversionDir/UtilityScripts/topsscripts/markOverriden.tops"
  48.  
  49. set findConflicts = "$conversionDir/UtilityScripts/grepscripts/findOSMethods.fgrep"
  50.  
  51. set oneline = "$conversionDir/UtilityScripts/lexscripts/oneline"
  52.  
  53. /bin/rm -rf CONVERSION
  54.  
  55. /bin/mkdir CONVERSION
  56.  
  57. ##############################################################################
  58. # produce first class hierarchy
  59. ##############################################################################
  60.  
  61. echo "Generating first class hierarchy"
  62.  
  63. # find all #import and #include lines
  64. /usr/bin/egrep '#import|#include' $preprocessFiles > $tmp1
  65.  
  66. # remove extraneous file and line number info from egrep
  67. /bin/sed -e 's/^[^#]*\(#.*\)$/\1/' $tmp1 > $tmp2
  68.  
  69. # remove duplicates
  70. /usr/bin/sort -u $tmp2 > $tmp1
  71.  
  72. # cpp tmp2 (contains all #includes and #imports
  73. /bin/cc -E -I. -I$conversionDir/Headers/3.3Headers $tmp1 >& $tmp2
  74.  
  75. # find all @interface lines
  76. /bin/grep '@interface' $preprocessFiles $tmp2 > $tmp1
  77.  
  78. # delete the category @interfaces
  79. /bin/sed -e '/(/d' $tmp1 > $tmp2
  80.  
  81. # convert to Class, Superclass pairings
  82. /bin/sed -e 's/@interface[     ]*\([a-zA-Z_$0-9%]*\)[     ]*[:]*[     ]*\([a-zA-Z_$0-9%]*\).*$/@\1, \2/' $tmp2 > $tmp1
  83.  
  84. # add ROOT as the superclass of root classes
  85. /bin/sed -e 's/^[^@]*@\([a-zA-Z_$0-9%]*\), $/\1, ROOT/' $tmp1 > $tmp2
  86.  
  87. # again remove extraneous file inf
  88. /bin/sed -e 's/^[^@]*@\(.*\)$/\1/' $tmp2 > $tmp1
  89.  
  90. # remove duplicates
  91. /usr/bin/sort -uo $tmp1 > $tmp2
  92.  
  93. # save the result
  94. /bin/mv -f $tmp2 $classHierarchy1
  95.  
  96. # remove temporary files
  97. /bin/rm -f $tmp1
  98.  
  99. ##############################################################################
  100. # produce second class hierarchy
  101. # NOTE: this script might be incorrect if the user does not convert all classes
  102. # to descend from NSObject
  103. ##############################################################################
  104.  
  105. echo 'Generating second class hierarchy'
  106.  
  107. # find all #import and #include lines
  108. /usr/bin/egrep '#import|#include' $preprocessFiles > $tmp1
  109.  
  110. # remove extraneous file and line number info from egrep
  111. /bin/sed -e 's/^[^#]*\(#.*\)$/\1/' $tmp1 > $tmp2
  112.  
  113. # remove duplicates
  114. /usr/bin/sort -u $tmp2 > $tmp1
  115.  
  116. # apply name changes to included files
  117. tops -scriptfile $nameChanges $tmp1
  118.  
  119. # cpp tmp1 (contains all #includes and #imports
  120. /bin/cc -E -I. -I$conversionDir/Headers/3.3Headers $tmp1 >& $tmp2
  121.  
  122. # find all @interface lines
  123. /bin/grep '@interface' $preprocessFiles $tmp2 > $tmp1
  124.  
  125. # delete the category @interfaces
  126. /bin/sed -e '/(/d' $tmp1 > $tmp2
  127.  
  128. # apply name changes once again (for client classes)
  129. tops -scriptfile $nameChanges $tmp2
  130.  
  131. # find all @interface lines (conversion above may insert warnings)
  132. /bin/grep '@interface' $tmp2 > $tmp1
  133. cp $tmp1 $tmp2
  134.  
  135. # convert to Class, Superclass pairings
  136. /bin/sed -e 's/@interface[     ]*\([a-zA-Z_$0-9%]*\)[     ]*[:]*[     ]*\([a-zA-Z_$0-9%]*\).*$/@\1, \2/' $tmp2 > $tmp1
  137.  
  138. # add ROOT as the superclass of root classes
  139. /bin/sed -e 's/^[^@]*@\([a-zA-Z_$0-9%]*\), $/\1, ROOT/' $tmp1 > $tmp2
  140.  
  141. # again remove extraneous file inf
  142. /bin/sed -e 's/^[^@]*@\(.*\)$/\1/' $tmp2 > $tmp1
  143.  
  144. # fix a few lies
  145. /bin/sed -e 's/List, NSObject/List, Object/' $tmp1 > $tmp2
  146. /bin/sed -e 's/Storage, NSObject/Storage, Object/' $tmp2 > $tmp1
  147. /bin/sed -e 's/NXBundle, NSObject/NXBundle, Object/' $tmp1 > $tmp2
  148. /bin/sed -e 's/HashTable, NSObject/HashTable, Object/' $tmp2 > $tmp1
  149.  
  150. # remove duplicates
  151. /usr/bin/sort -uo $tmp1 > $tmp2
  152.  
  153. # save the result
  154. /bin/mv -f $tmp2 $classHierarchy2
  155.  
  156. # remove temporary files
  157. /bin/rm -f $tmp1
  158.  
  159. ##############################################################################
  160. # get list of all methods
  161. ##############################################################################
  162.  
  163. echo "Generating list of all methods"
  164.  
  165. # generate list of all methods found in implementation files
  166. tops -scriptfile $allMethodsScript $preprocessFiles > $tmp1
  167.  
  168. # remove the '{' and extraneous whitespace
  169. tops -scriptfile $cleanMethods $tmp1
  170.  
  171. # put all methods on one line
  172. /bin/cat $tmp1 | $oneline > $tmp2
  173.  
  174. # remove extraneous lines
  175. /usr/bin/egrep '^[-a-zA-Z/01-9_:;.+( )*]*$' $tmp2 > $allMethodsFile
  176.  
  177. # delete overridden kit methods (hopefully there are no name conflicts)
  178. tops -scriptfile $removeCommon $allMethodsFile
  179. /bin/sed -e '/OVERRIDDEN/d' $allMethodsFile > $tmp1
  180. /bin/mv $tmp1 $allMethodsFile
  181.  
  182. ##############################################################################
  183. # generate deep conversion string method list
  184. ##############################################################################
  185.  
  186. echo 'Generating list of methods for optional string conversion'
  187.  
  188. # produce candidates for deep string conversion
  189. /usr/bin/egrep 'char \*|NXAtom' $allMethodsFile > $optionalString
  190.  
  191.  
  192. ##############################################################################
  193. # generate deep conversion global symbol list
  194. ##############################################################################
  195.  
  196. echo 'Generating list of #defines for optional string conversion'
  197.  
  198. # produce candidates for deep string conversion
  199. /usr/bin/egrep '#define *[a-zA-Z_0-9]*[     ]*"|#define[     ]*[a-zA-Z_0-9]*[     ]*NXLocal' $preprocessFiles > $optionalStringSym
  200. # /usr/bin/egrep 'extern[     ]*const[     ]*char[     ]*\*[^(]*;|extern[     ]*char[     ]*\*[^(]*;' $preprocessFiles >> $optionalStringSym
  201. # /usr/bin/egrep 'extern[     ]*NXAtom[     ]*[^(]*;|^static[     ]*const[     ]*char[     ]*\*[^(]*;' $preprocessFiles >> $optionalStringSym
  202. # /usr/bin/egrep '^static[     ]*char[     ]*\*[^(]*;|^static[     ]*NXAtom[     ]*[^(]*;' $preprocessFiles >> $optionalStringSym
  203.  
  204.  
  205. ##############################################################################
  206. # generate deep conversion function list
  207. ##############################################################################
  208.  
  209. # echo 'Generating list of functions for optional string conversion'
  210.  
  211. # produce candidates for deep string conversion
  212. # /usr/bin/egrep 'extern[     ]*const[     ]*char[     ]*\*[^(]*\(|extern[     ]*char[     ]*\*[^(]*\(' $preprocessFiles > $optionalStringFunc
  213. # /usr/bin/egrep 'extern[     ]*NXAtom[     ]*[^(]*\(|^static[     ]*const[     ]*char[     ]*\*[^(]*\(' $preprocessFiles >> $optionalStringFunc
  214. # /usr/bin/egrep '^static[     ]*char[     ]*\*[^(]*\(|^static[     ]*NXAtom[     ]*[^(]*\(' $preprocessFiles >> $optionalStringFunc
  215.  
  216. ##############################################################################
  217. # generate deep conversion rect/point/size method list
  218. ##############################################################################
  219.  
  220. echo 'Generating list of methods for optional rect conversion'
  221.  
  222. # produce candidates for deep rect conversion
  223. /usr/bin/egrep 'NXRect[     ]*\*|NXSize[     ]*\*|NXPoint[     ]*\*' $allMethodsFile > $optionalRect
  224.  
  225.  
  226. #############################################################################
  227. # generate deep conversion void method list
  228. ##############################################################################
  229.  
  230. echo 'Generating list of methods for optional void conversion'
  231.  
  232. # remove typed methods
  233. /bin/sed -e '/[+-] *(/d' $allMethodsFile > $tmp1
  234.  
  235. # remove init, copy and new methods
  236. /bin/sed -e '/- init.*/d' $tmp1 > $tmp2
  237. /bin/sed -e '/- copy.*/d' $tmp2 > $tmp1
  238. /bin/sed -e '/+ new.*/d' $tmp1 > $tmp2
  239.  
  240. #set the default to SELF-VOID
  241. /bin/sed -e 's/^\(.*\)$/SELF-VOID \1/' $tmp2 > $tmp1
  242.  
  243. # save the result
  244. /bin/mv -f $tmp1 $optionalVoid
  245.  
  246. ##############################################################################
  247. # generate list of name conflicts
  248. ##############################################################################
  249.  
  250. # echo 'Generating list of potential name conflicts'
  251.  
  252. # clean up the method list
  253.  
  254. # mark the beginning the line with %
  255. # /bin/sed -e 's/^\(.*\)$/%\1/' $allMethodsFile > $tmp2
  256.  
  257. # replace colons around line numbers with !
  258. # /bin/sed -e 's/:\([0-9]*\):/&\1&/' $tmp2 > $tmp1
  259.  
  260. # make every method argument typed
  261. # /bin/sed -e 's/:/:(id)/g' $tmp1 > $tmp2
  262. # /bin/sed -e 's/:(id)(/:(/g' $tmp2 > $tmp1
  263.  
  264. # remove types
  265. # /bin/sed -e 's/:([^)]*)[ :;]*/:/g' $tmp1 > $tmp2
  266.  
  267. # find matches
  268. # /usr/bin/fgrep -f $findConflicts $tmp2 > $tmp1
  269.  
  270. # remove line number info from the last fgrep
  271. # /bin/sed -e 's/^[^%]%\(.*\)$/\1/' $tmp1 > $tmp2
  272.  
  273. # put the line number colons back in
  274. # /bin/sed -e 's/&/:/' $tmp2 > $tmp1
  275.  
  276. # store the result
  277. # /bin/mv -f $tmp1 $nameConflicts
  278.  
  279. ##############################################################################
  280. # clean up
  281. ##############################################################################
  282.  
  283. /bin/rm -rf $tmp2 
  284.  
  285. /bin/rm -rf $tmp1 
  286.  
  287. /bin/rm -rf $allMethodsFile 
  288.