Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for htmltags.rex

(view source code of htmltags.rex as plain text)

  1. /* Convert HTML tags to uppercase */
  2.  
  3. /* Display blank line */
  4. Say
  5.  
  6. /* Leave debug information on errors */
  7. Signal On Error   Name Quit
  8. Signal On Failure Name Quit
  9. Signal On Halt    Name Quit
  10. Signal On Syntax  Name Quit
  11.  
  12. /* Initialize RexxUtil */
  13. If RxFuncQuery( "sysloadfuncs" ) <> 0 Then Do
  14. 	Call RxFuncAdd "sysloadfuncs", "RexxUtil", "sysloadfuncs"
  15. 	Call sysloadfuncs
  16. End
  17.  
  18. /* Parse command line parameter(s) */
  19. Parse Upper Arg infiles dummy
  20. If dummy  <> "" Then Call Syntax
  21. If infiles = "" Then Call Syntax
  22.  
  23. /* Check if file(s) exist */
  24. Call SysFileTree infiles, "infile.", "F"
  25. If infile.0 = 0 Then Call Syntax "File not found: "||infiles
  26.  
  27. /* Covert tags in all specified files to uppercase */
  28. Do i = 1 To infile.0
  29. 	Call CheckTags infile.i
  30. End
  31. Exit
  32.  
  33.  
  34. CheckTags: Procedure Expose outfile
  35. 	/* Parse argument(s) */
  36. 	infile = Arg( 1 )
  37. 	Parse Value infile With . . size . file
  38. 	file = Strip( file )
  39. 	Parse Upper Value file With outfile".HTM"
  40. 	outfile = outfile||".UPC"
  41.  
  42. 	/* Read file */
  43. 	allstring = CharIn( file, 1, size )
  44. 	Call LineOut file
  45.  
  46. 	/* Find all tags and convert them */
  47. 	newstring = ""
  48. 	convert   = 1
  49. 	Do forever
  50. 		Parse Value allstring With string"<"tag">"allstring
  51. 		If tag = "" Then Do
  52. 			Leave
  53. 		End
  54. 		newtag = ConvertTag( tag )
  55. 		If newtag = "/SCRIPT" Then convert = 1
  56. 		If convert = 1 Then tag = newtag
  57. 		Say "Converted tag: <"||tag||">"||"0D0A"X
  58. 		newstring = newstring||string||"<"||tag||">"
  59. 		If left( newtag, 6 ) = "SCRIPT" Then convert = 0
  60. 	End
  61. 	If allstring <> "" Then newstring = newstring||allstring
  62.  
  63. 	/* Save results */
  64. 	Call charout outfile, newstring
  65. 	Call LineOut outfile
  66. Return
  67.  
  68.  
  69. ColorConvert: procedure expose outfile
  70. 	/* Parse argument(s) */
  71. 	args = Arg( )
  72. 	string = Arg( 1 )
  73. 	If string > 1 Then Do i = 2 To args
  74. 		string = string||","||Arg( i )
  75. 	End
  76.  
  77. 	/* Check if string is hex color designation */
  78. 	/* and convert to uppercase if true         */
  79. 	If Length( string ) = 7 Then Do
  80. 		If Left( string, 1 ) = "#" Then Do
  81. 			If DataType( Right( string, 6 ), "X" ) = 1 Then Do
  82. 				string = Translate( string )
  83. 			End
  84. 		End
  85. 	End
  86. Return string
  87.  
  88.  
  89. ConvertTag: procedure expose outfile
  90. 	/* Parse argument(s) */
  91. 	args = Arg( )
  92. 	tag = Arg( 1 )
  93. 	If args > 1 Then Do i = 2 To args
  94. 		tag = tag||","||Arg( i )
  95. 	End
  96. 	Say "Original tag:  <"||tag||">"
  97.  
  98. 	/* First, remove line breaks from within tag */
  99. 	Do Until break = 0
  100. 		break = Pos( "0D0A"X, tag )
  101. 		If break > 1 Then Do
  102. 			tag = SubStr( tag, 1, break - 1 )||" "||,
  103. 			      SubStr( tag, break + 2 )
  104. 		End
  105. 	End
  106.  
  107. 	/* Then, check for literals within tag */
  108. 	If Pos( '"', tag ) = 0 Then Do
  109. 		newtag = Translate( tag )
  110. 	End
  111. 	Else Do
  112. 		newtag   = ""
  113. 		Do Until qposo = 0
  114. 			qposo = pos( '"', tag )
  115. 			If qposo > 1 Then Do
  116. 				newtag = newtag||Translate( SubStr( tag, 1, qposo ) )
  117. 				tag = SubStr( tag, qposo + 1 )
  118. 			End
  119. 			qposc = Pos( '"', tag )
  120. 			If qposc > 1 Then Do
  121. 				qstr = SubStr( tag, 1, qposc - 1 )
  122. 				newtag = newtag||ColorConvert( qstr )||'"'
  123. 				tag = SubStr( tag, qposc + 1 )
  124. 			End
  125. 			Else Do
  126. 				If qposc = 1 Then Do
  127. 					newtag = newtag||'"'
  128. 					tag = SubStr( tag, 2 )
  129. 				End
  130. 				Else Leave
  131. 			End
  132. 		End
  133. 		If tag <> "" Then newtag = newtag||tag
  134. 	End
  135. Return newtag
  136.  
  137.  
  138. Quit: Procedure Expose outfile
  139. 	/* Close output file and end program */
  140. 	Call LineOut outfile
  141. 	Exit
  142. Return
  143.  
  144.  
  145. Syntax: Procedure Expose outfile
  146. 	Parse arg errmsg
  147. 	If errmsg <> "" Then Say "Error:"||"0D0A"X||errmsg||"0D0A0D0A"X
  148. 	Say "HTMLTags.rex,  Version 2.01"
  149. 	Say "Convert HTML tag commands to uppercase for readability and to conform to"
  150. 	Say "original HTML specifications"
  151. 	Say
  152. 	Say "Usage:   HTMLTAGS.REX  <html_filespec>"
  153. 	Say
  154. 	Say 'Result:  Converted file with name of HTML file and extension ".UPC"'
  155. 	Say
  156. 	Say "Written by Rob van der Woude"
  157. 	Say "http://www.robvanderwoude.com"
  158. 	Call Quit
  159. Return
  160.  

page last modified: 2024-04-16; loaded in 0.0228 seconds