2
0

convertvf 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. #! /bin/ksh
  2. ##############################################################################
  3. #
  4. # convertVf
  5. #
  6. # This shell script converts the VUE 3.0 filetypes database files (*.vf)
  7. # to the CDE 1.0 datatypes database files (*.dt). This script is a
  8. # filter, this allows the user to select the input and output file names.
  9. # To be recognized as a CDE 1.0 desktop datatypes file the output file
  10. # name must be of the form: "*.dt"
  11. #
  12. # The transformations applied to the input are:
  13. # 1) change a number of strings;
  14. # 2) enclose type/action definitions in brackets;
  15. # 3) remove "END" lines;
  16. # 4) break up FILETYPES definitions into DATA_CRITERIA and
  17. # DATA_ATTRIBUTES definitions.
  18. # 5) escape special characters which appear in NAME_PATTERNS
  19. # (PATH_PATTERNS) with a backslash. (e.g. '!')
  20. # 6) Replace LARGE and SMALL ICON references with a single ICON
  21. # reference, while possibly removing size-related suffixes from
  22. # the icon name string. (e.g foo.l --> foo )
  23. # 7) Convert TYPE MAP <action> lines to
  24. # TYPE MAP
  25. # MAP_ACTION <action>
  26. #
  27. # Usage: convertvf < file.vf > file.dt
  28. #
  29. ##############################################################################
  30. typeset USAGE="Usage: $(basename $0) < file.vf > file.dt"
  31. ###############################################################################
  32. #
  33. # changeStrings()
  34. # This function invokes sed to search and replace a number of
  35. # strings which have been changed between the Vue3.0 ".vf"
  36. # files and the CDE 1.0 ".dt" files.
  37. #
  38. ###############################################################################
  39. changeStrings() {
  40. # NOTE:
  41. # LARGE_ICON definitions are retained and converted to their ICON equivalents
  42. # SMALL_ICON definitions are discarded.
  43. #
  44. sed '
  45. s/Filetype/DataType/g
  46. s/filetype/DataType/g
  47. s/%FileName%/%name%/g
  48. s/%PathName%/%dir%/g
  49. s/PATH-PATTERN/PATH_PATTERN/
  50. s/FILETYPE/DATA_CRITERIA/
  51. s/FILE-PATTERN/NAME_PATTERN/
  52. s/ARG-TYPES/ARG_TYPE/
  53. s/ARG-COUNT/ARG_COUNT/
  54. s/WINDOW-TYPE/WINDOW_TYPE/
  55. s/EXEC-STRING/EXEC_STRING/
  56. s/EXEC-HOST/EXEC_HOST/
  57. s/NO-STDIO/NO_STDIO/
  58. s/PERM-TERMINAL/PERM_TERMINAL/
  59. s/SHELL-TERMINAL/SHELL_TERMINAL/
  60. s/OUTPUT-ONLY/PERM_TERMINAL/
  61. s/SHARED-OUTPUT/PERM_TERMINAL/
  62. s/\([^_]\)ATTRIBUTES\([^_]\)/\1PROPERTIES\2/
  63. s/RELOAD-TYPES-DB/RELOAD_TYPES_DB/
  64. s/MSG-TOOL/DT_SVC/
  65. s/MSG-COMMAND/DT_REQUEST_NAME/
  66. s/L-ICON/ICON/
  67. s/LARGE_ICON/ICON/
  68. s/L-INSTANCE-ICON/INSTANCE_ICON/
  69. s/LARGE_INSTANCE_ICON/INSTANCE_ICON/
  70. s/MSG-DATA/DT_ARG0_VALUE/
  71. /S-ICON/d
  72. /SMALL_ICON/d
  73. /S-INSTANCE-ICON/d
  74. /SMALL_INSTANCE_ICON/d
  75. /^[ ]*set[ ]/s/\(.*\)\.[lms]\.bm/\1/
  76. /ICON/s/\(.*\)\.[lms]\.bm/\1/
  77. ' $*
  78. }
  79. ###############################################################################
  80. #
  81. # replaceFileTypes()
  82. # This function invokes awk to replace FILETYPE definitions with
  83. # DATA_CRITERIA and DATA_ATTRIBUTES definitions. It places brackets
  84. # around the definitions, instead of using "END" to mark the end of
  85. # a definition.
  86. #
  87. ###############################################################################
  88. replaceFileTypes() {
  89. awk '
  90. function printCrit( array )
  91. {
  92. if ( names[TypeName] )
  93. print "DATA_CRITERIA", TypeName names[TypeName];
  94. else
  95. print "DATA_CRITERIA", TypeName
  96. print "{"
  97. print " DATA_ATTRIBUTES_NAME",TypeName
  98. for (c in array) {
  99. print array[c];
  100. delete array[c];
  101. }
  102. print "}"
  103. }
  104. function printAtt( array )
  105. {
  106. print "DATA_ATTRIBUTES",TypeName;
  107. print "{"
  108. for (c in array) {
  109. print array[c];
  110. delete array[c];
  111. }
  112. print "}"
  113. }
  114. BEGIN {
  115. criteria[1] = "NAME_PATTERN";
  116. criteria[2] = "PATH_PATTERN";
  117. criteria[3] = "CONTENT";
  118. criteria[4] = "MODE";
  119. criteria[5] = "LINK_PATH";
  120. criteria[6] = "LINK_NAME";
  121. criteria[7] = "DATA_ATTRIBUTES_NAME";
  122. critMax = 7;
  123. gettingLines = 0;
  124. }
  125. #
  126. # Special treatment CRITERIA/ATTRIBUTE Fields
  127. #
  128. $1 == "NAME_PATTERN" {
  129. #
  130. # escape special syntax chars in name patterns
  131. #
  132. if ( $2 ~ /!/) {
  133. gsub(/!/,"\\!")
  134. }
  135. }
  136. $1 == "ICON" || $1 == "INSTANCE_ICON" {
  137. if ( $2 ~ /.l/ ) {
  138. sub(/\.l$/,"",$0);
  139. }
  140. }
  141. $1 == "DATA_CRITERIA" {
  142. TypeName = $2;
  143. names[$2]++;
  144. gettingLines = 1;
  145. next;
  146. }
  147. #
  148. # Special treatment ACTION FIELDS
  149. #
  150. $1 == "TYPE" && $2 == "MAP" && NF == 3 {
  151. print " " $1 " " $2
  152. print " MAP_ACTION " $3
  153. next;
  154. }
  155. #
  156. # TYPE MESSAGE actions were not publicly exposed so there should
  157. # not be many message actions to translate. Here we make some
  158. # assumptions about the message action.
  159. #
  160. # Only the ReloadActions broadcast message becomes a DT_NOTIFY message.
  161. # Assume all other messages turn into DT_REQUESTs.
  162. #
  163. $1 == "TYPE" && $2 == "MESSAGE" {
  164. if ( ActionName == "ReloadActions" )
  165. print " TYPE DT_NOTIFY"
  166. else
  167. print " TYPE DT_REQUEST"
  168. next;
  169. }
  170. $1 == "DT_REQUEST_NAME" && ActionName == "ReloadActions" {
  171. print " DT_NOTIFY_NAME " $2
  172. next
  173. }
  174. $1 == "ACTION" {
  175. ActionName = $2
  176. print $0
  177. print "{"
  178. next;
  179. }
  180. (($1 == "END") || ($1 == "}")) && gettingLines {
  181. gettingLines = 0;
  182. if ( names[TypeName] == 1 )
  183. printAtt(newAtt);
  184. printCrit(newCrit);
  185. next;
  186. }
  187. $1 == "END" {
  188. print "}"
  189. next;
  190. }
  191. $1 == "{" {
  192. # do not print any brackets -- we will
  193. # supply any that are necessary
  194. next;
  195. }
  196. gettingLines == 1 {
  197. for ( i = 1; i <= critMax; i++ ) {
  198. # compare to criteria strings
  199. if ( $1 == criteria[i] ) {
  200. tmp = $1;
  201. newCrit[$1] = $0
  202. while ( substr($0,length($0),1) == "\\" ) {
  203. getline;
  204. newCrit[tmp] = newCrit[tmp] "\n" $0;
  205. }
  206. next;
  207. }
  208. }
  209. #
  210. # If we have not found it yet it must be an
  211. # attribute.
  212. #
  213. tmp = $1
  214. newAtt[tmp] = $0;
  215. while ( substr($0,length($0),1) == "\\" ) {
  216. getline;
  217. newAtt[tmp] = newAtt[tmp] "\n" $0;
  218. }
  219. next;
  220. }
  221. gettingLines == 0 { print $0 }
  222. ' $*
  223. }
  224. ###############################################################################
  225. [ $# -eq 0 ] || {
  226. echo $USAGE;
  227. exit 1;
  228. }
  229. changeStrings $i | replaceFileTypes