Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for checkvarsvbs.cs

(view source code of checkvarsvbs.cs as plain text)

  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6.  
  7.  
  8. namespace RobvanderWoude
  9. {
  10. 	class CheckVarsVBS
  11. 	{
  12. 		static string progver = "1.02";
  13.  
  14.  
  15. 		static List<string> csserrors = new List<string>( );
  16.  
  17.  
  18. 		static int Main( string[] args )
  19. 		{
  20. 			#region Initialize Variables
  21.  
  22. 			int rc = 0;
  23. 			SortedList<string, int> subroutines = new SortedList<string, int>( );
  24. 			SortedList<string, int> variables = new SortedList<string, int>( );
  25. 			bool htawindowevents = false;
  26. 			bool showsubs = true;
  27. 			bool showvars = true;
  28. 			bool unusedonly = false;
  29. 			string scriptcode = String.Empty;
  30. 			string scriptext = String.Empty;
  31. 			string scriptfile = String.Empty;
  32. 			int columnwidth = 12;
  33. 			int unusedsubs = 0;
  34. 			int unusedvars = 0;
  35. 			List<string> ignoredsubs = new List<string>( )
  36. 			{
  37. 				"window_onbeforeunload",
  38. 				"window_onblur",
  39. 				"window_onfocus",
  40. 				"window_onhelp",
  41. 				"window_onload",
  42. 				"window_onresize",
  43. 				"window_onunload"
  44. 			};
  45.  
  46. 			#endregion Initialize Variables
  47.  
  48.  
  49. 			#region Command Line Parsing
  50.  
  51. 			if ( args.Length == 0 )
  52. 			{
  53. 				return ShowHelp( );
  54. 			}
  55.  
  56. 			foreach ( string arg in args )
  57. 			{
  58. 				if ( arg[0] == '/' )
  59. 				{
  60. 					if ( arg.ToUpper( ) == "/?" )
  61. 					{
  62. 						return ShowHelp( );
  63. 					}
  64. 					else if ( arg.ToUpper( ) == "/S" )
  65. 					{
  66. 						if ( !showvars )
  67. 						{
  68. 							return ShowHelp( "Duplicate command line switch /S" );
  69. 						}
  70. 						if ( !showsubs )
  71. 						{
  72. 							return ShowHelp( "Use /S or /V or neither, but not both" );
  73. 						}
  74. 						showvars = false;
  75. 					}
  76. 					else if ( arg.ToUpper( ) == "/U" )
  77. 					{
  78. 						if ( unusedonly )
  79. 						{
  80. 							return ShowHelp( "Duplicate command line switch /U" );
  81. 						}
  82. 						unusedonly = true;
  83. 					}
  84. 					else if ( arg.ToUpper( ) == "/V" )
  85. 					{
  86. 						if ( !showsubs )
  87. 						{
  88. 							return ShowHelp( "Duplicate command line switch /V" );
  89. 						}
  90. 						if ( !showvars )
  91. 						{
  92. 							return ShowHelp( "Use /S or /V or neither, but not both" );
  93. 						}
  94. 						showsubs = false;
  95. 					}
  96. 					else if ( arg.ToUpper( ) == "/W" )
  97. 					{
  98. 						if ( htawindowevents )
  99. 						{
  100. 							return ShowHelp( "Duplicate command line switch /W" );
  101. 						}
  102. 						htawindowevents = true;
  103. 					}
  104. 					else
  105. 					{
  106. 						return ShowHelp( "Invalid command line switch \"{0}\"", arg );
  107. 					}
  108. 				}
  109. 				else
  110. 				{
  111. 					if ( !String.IsNullOrWhiteSpace( scriptfile ) )
  112. 					{
  113. 						return ShowHelp( "Duplicate command line argument for VBScript file" );
  114. 					}
  115. 					if ( !File.Exists( arg ) )
  116. 					{
  117. 						return ShowHelp( "Invalid file name or file not found: \"{0}\"", arg );
  118. 					}
  119. 					scriptext = Path.GetExtension( arg ).ToLower( );
  120. 					if ( scriptext != ".hta" && scriptext != ".vbs" )
  121. 					{
  122. 						return ShowHelp( "Invalid file type \"{0}\"", arg );
  123. 					}
  124. 					scriptfile = Path.GetFullPath( arg );
  125. 				}
  126.  
  127. 			}
  128.  
  129. 			if ( String.IsNullOrWhiteSpace( scriptfile ) )
  130. 			{
  131. 				return ShowHelp( "Please specify a source file" );
  132. 			}
  133.  
  134. 			#endregion Command Line Parsing
  135.  
  136.  
  137. 			#region Read File
  138.  
  139. 			// Read the code from the file
  140. 			scriptcode = File.ReadAllText( scriptfile, Encoding.UTF8 );
  141. 			// Remove comment lines from the code (does NOT strip comments starting halfway on a line)
  142. 			string pattern = @"(^|\n|\r)[ \t]*'[^\n\r]+";
  143. 			Regex regex = new Regex( pattern );
  144. 			scriptcode = regex.Replace( scriptcode, String.Empty );
  145.  
  146. 			#endregion Read File
  147.  
  148.  
  149. 			#region List Subroutines
  150.  
  151. 			// Create a list of subroutines found in the code
  152. 			if ( showsubs )
  153. 			{
  154. 				pattern = @"(?:^|\n|\r)[ \t]*(?:Sub|Function)[ \t]+([A-Z][^\s\(]+)";
  155. 				regex = new Regex( pattern, RegexOptions.IgnoreCase );
  156. 				if ( regex.IsMatch( scriptcode ) )
  157. 				{
  158. 					MatchCollection matches = regex.Matches( scriptcode );
  159. 					if ( matches.Count > 0 )
  160. 					{
  161. 						foreach ( Match match in matches )
  162. 						{
  163. 							bool listed = false;
  164. 							string sub = match.Groups[1].ToString( );
  165. 							foreach ( string key in subroutines.Keys )
  166. 							{
  167. 								if ( sub.ToLower( ) == key.ToLower( ) )
  168. 								{
  169. 									listed = true;
  170. 								}
  171. 							}
  172. 							if ( !listed )
  173. 							{
  174. 								subroutines[sub] = 0;
  175. 								if ( sub.Length > columnwidth )
  176. 								{
  177. 									columnwidth = sub.Length;
  178. 								}
  179. 							}
  180. 						}
  181. 					}
  182. 				}
  183. 			}
  184. 			#endregion List Subroutines
  185.  
  186.  
  187. 			#region Check Subroutine Nesting
  188.  
  189. 			if ( showsubs )
  190. 			{
  191. 				pattern = @"(?:^|\n|\r)[ \t]*End[ \t]+(?:Sub|Function)('|\s|$)";
  192. 				regex = new Regex( pattern, RegexOptions.IgnoreCase );
  193. 				if ( regex.IsMatch( scriptcode ) )
  194. 				{
  195. 					MatchCollection matches = regex.Matches( scriptcode );
  196. 					if ( matches.Count != subroutines.Count )
  197. 					{
  198. 						RedLine( "{0} subroutines found, against {1} End Sub and End Function statements\n", subroutines.Count.ToString( ), matches.Count.ToString( ) );
  199.  
  200. 					}
  201. 					pattern = @"(?:^|\r|\n)\s*(Sub|Function)\s.*?(?:^|\n|\r)[ \t]*End[ \t]+\1('|\s|$)";
  202. 					regex = new Regex( pattern, RegexOptions.Singleline );
  203. 					if ( regex.IsMatch( scriptcode ) )
  204. 					{
  205. 						matches = regex.Matches( scriptcode );
  206. 						foreach ( Match match in matches )
  207. 						{
  208. 							string subroutine = match.Groups[0].ToString( );
  209. 							List<string> subs = new List<string>( );
  210. 							int startsubs = 0;
  211. 							int endsubs = 0;
  212. 							pattern = @"(?:^|\r|\n)\s*(?:Sub|Function)\s(\w+)";
  213. 							regex = new Regex( pattern );
  214. 							if ( regex.IsMatch( subroutine ) )
  215. 							{
  216. 								MatchCollection submatches = regex.Matches( subroutine );
  217. 								startsubs = submatches.Count;
  218. 								foreach ( Match sub in submatches )
  219. 								{
  220. 									subs.Add( sub.Value.Trim( "\n\r\t ".ToCharArray( ) ) );
  221. 								}
  222. 								/*
  223. 								if ( subs.Count > 1 )
  224. 								{
  225. 									RedLine( "Nested or improperly terminated functions and/or subroutines:" );
  226. 									Console.WriteLine( "\t{0}\n", String.Join( "\n\t", subs.ToArray( ) ) );
  227. 								}
  228. 								*/
  229. 							}
  230. 							pattern = @"[\n\r]+\s*End[ \t]+(Sub|Function)(?:\s|$)";
  231. 							regex = new Regex( pattern );
  232. 							if ( regex.IsMatch( subroutine ) )
  233. 							{
  234. 								MatchCollection submatches = regex.Matches( subroutine );
  235. 								endsubs = submatches.Count;
  236. 							}
  237. 							if ( startsubs > 1 || endsubs > 1 )
  238. 							{
  239. 								RedLine( "Nested or improperly terminated functions and/or subroutines:" );
  240. 								Console.WriteLine( "\t{0}\n", String.Join( "\n\t", subs.ToArray( ) ) );
  241. 							}
  242. 						}
  243. 					}
  244. 				}
  245. 			}
  246.  
  247. 			#endregion Check Subroutine Nesting
  248.  
  249.  
  250. 			#region List Variables
  251.  
  252. 			// Create a list of variables found in the code
  253. 			if ( showvars )
  254. 			{
  255. 				pattern = @"(?:^|\n|\r)[ \t]*Dim[ \t]+([A-Z][^\n\r:]+)";
  256. 				regex = new Regex( pattern, RegexOptions.IgnoreCase );
  257. 				if ( regex.IsMatch( scriptcode ) )
  258. 				{
  259. 					MatchCollection matches = regex.Matches( scriptcode );
  260. 					if ( matches.Count > 0 )
  261. 					{
  262. 						foreach ( Match match in matches )
  263. 						{
  264. 							string[] vars = match.Groups[1].ToString( ).Split( ", ()".ToCharArray( ), StringSplitOptions.RemoveEmptyEntries );
  265. 							foreach ( string var in vars )
  266. 							{
  267. 								bool listed = false;
  268. 								foreach ( string key in subroutines.Keys )
  269. 								{
  270. 									if ( var.ToLower( ) == key.ToLower( ) )
  271. 									{
  272. 										listed = true;
  273. 									}
  274. 								}
  275. 								if ( !listed )
  276. 								{
  277. 									variables[var] = 0;
  278. 									if ( var.Length > columnwidth )
  279. 									{
  280. 										columnwidth = var.Length;
  281. 									}
  282. 								}
  283. 							}
  284. 						}
  285. 					}
  286. 				}
  287. 			}
  288.  
  289. 			#endregion List Variables
  290.  
  291.  
  292. 			#region Count and Display Subroutines Usage
  293.  
  294. 			// Iterate through the list of subroutines and count the occurences of its name
  295. 			if ( showsubs )
  296. 			{
  297. 				List<string> keys = new List<string>( subroutines.Keys );
  298. 				foreach ( string sub in keys )
  299. 				{
  300. 					bool ignorethissub = !htawindowevents && scriptext == ".hta" && ignoredsubs.Contains( sub.ToLower( ) );
  301. 					if ( !ignorethissub )
  302. 					{
  303. 						pattern = String.Format( @"\b{0}\b", sub );
  304. 						regex = new Regex( pattern, RegexOptions.IgnoreCase );
  305. 						if ( regex.IsMatch( scriptcode ) )
  306. 						{
  307. 							subroutines[sub] = regex.Matches( scriptcode ).Count - 1;
  308. 							if ( subroutines[sub] == 0 )
  309. 							{
  310. 								unusedsubs += 1;
  311. 							}
  312. 						}
  313. 					}
  314. 				}
  315. 				// Show the results
  316. 				if ( unusedonly )
  317. 				{
  318. 					Console.WriteLine( "{0} Unused Subroutine{1}{2}", unusedsubs, ( unusedsubs == 1 ? String.Empty : "s" ), ( unusedsubs == 0 ? String.Empty : ":" ) );
  319. 					Console.WriteLine( "{0}=================={1}{2}", new String( '=', unusedsubs.ToString( ).Length ), ( unusedsubs == 1 ? String.Empty : "=" ), ( unusedsubs == 0 ? String.Empty : "=" ) );
  320.  
  321. 				}
  322. 				else
  323. 				{
  324. 					Console.WriteLine( "{0,-" + columnwidth + "}    Occurences:", "Subroutine:" );
  325. 					Console.WriteLine( "{0,-" + columnwidth + "}    ===========", "===========" );
  326. 				}
  327. 				foreach ( string key in subroutines.Keys )
  328. 				{
  329. 					bool ignorethissub = !htawindowevents && scriptext == ".hta" && ignoredsubs.Contains( key.ToLower( ) );
  330. 					if ( subroutines[key] == 0 )
  331. 					{
  332. 						if ( unusedonly )
  333. 						{
  334. 							if ( !ignorethissub )
  335. 							{
  336. 								Console.WriteLine( key );
  337. 							}
  338. 						}
  339. 						else
  340. 						{
  341. 							if ( ignorethissub )
  342. 							{
  343. 								Console.WriteLine( "{0,-" + columnwidth + "}    {1}", key, subroutines[key] );
  344. 							}
  345. 							else
  346. 							{
  347. 								RedLine( String.Format( "{0,-" + columnwidth + "}    {1}", key, subroutines[key] ) );
  348. 							}
  349. 						}
  350. 						rc += 1;
  351. 					}
  352. 					else if ( !unusedonly )
  353. 					{
  354. 						Console.WriteLine( "{0,-" + columnwidth + "}    {1}", key, subroutines[key] );
  355. 					}
  356. 				}
  357. 				Console.WriteLine( );
  358. 			}
  359.  
  360. 			#endregion Count and Display Subroutines Usage
  361.  
  362.  
  363. 			#region Count and Display Variables Usage
  364.  
  365. 			// Iterate through the list of variables and count the occurences of its name
  366. 			if ( showvars )
  367. 			{
  368. 				List<string> keys = new List<string>( variables.Keys );
  369. 				foreach ( string variable in keys )
  370. 				{
  371. 					pattern = String.Format( @"\b{0}\b", variable );
  372. 					regex = new Regex( pattern, RegexOptions.IgnoreCase );
  373. 					if ( regex.IsMatch( scriptcode ) )
  374. 					{
  375. 						variables[variable] = regex.Matches( scriptcode ).Count - 1;
  376. 						if ( variables[variable] == 0 )
  377. 						{
  378. 							unusedvars += 1;
  379. 						}
  380. 					}
  381. 				}
  382. 				// Show the results
  383. 				if ( unusedonly )
  384. 				{
  385. 					Console.WriteLine( "{0} Unused Variable{1}{2}", unusedvars, ( unusedvars == 1 ? String.Empty : "s" ), ( unusedvars == 0 ? String.Empty : ":" ) );
  386. 					Console.WriteLine( "{0}================{1}{2}", new String( '=', unusedvars.ToString( ).Length ), ( unusedvars == 1 ? String.Empty : "=" ), ( unusedvars == 0 ? String.Empty : "=" ) );
  387. 				}
  388. 				else
  389. 				{
  390. 					Console.WriteLine( "{0,-" + columnwidth + "}    Occurences:", "Variable:" );
  391. 					Console.WriteLine( "{0,-" + columnwidth + "}    ===========", "=========" );
  392. 				}
  393. 				foreach ( string key in variables.Keys )
  394. 				{
  395. 					if ( variables[key] == 0 )
  396. 					{
  397. 						if ( unusedonly )
  398. 						{
  399. 							Console.WriteLine( key );
  400. 						}
  401. 						else
  402. 						{
  403. 							RedLine( String.Format( "{0,-" + columnwidth + "}    {1}", key, variables[key] ) );
  404. 						}
  405. 						rc += 1;
  406. 					}
  407. 					else if ( !unusedonly )
  408. 					{
  409. 						Console.WriteLine( "{0,-" + columnwidth + "}    {1}", key, variables[key] );
  410. 					}
  411. 				}
  412. 				Console.WriteLine( );
  413. 			}
  414.  
  415. 			#endregion Count and Display Variables Usage
  416.  
  417.  
  418. 			#region Check HTA Head
  419.  
  420. 			if ( showsubs && showvars )
  421. 			{
  422. 				if ( Path.GetExtension( scriptfile ).ToLower( ) == ".hta" )
  423. 				{
  424. 					Console.WriteLine( "HTA Head:" );
  425. 					Console.WriteLine( "=========" );
  426. 					int htaerrors = 0;
  427. 					pattern = @"<style[^>]*>((?:.|\n|\r)*?)</style>";
  428. 					regex = new Regex( pattern, RegexOptions.IgnoreCase );
  429. 					if ( regex.IsMatch( scriptcode ) )
  430. 					{
  431. 						MatchCollection matches = regex.Matches( scriptcode );
  432. 						if ( matches.Count > 0 )
  433. 						{
  434. 							foreach ( Match match in matches )
  435. 							{
  436. 								foreach ( Group submatch in match.Groups )
  437. 								{
  438. 									htaerrors += CheckStyles( submatch.ToString( ) );
  439. 								}
  440. 							}
  441. 						}
  442. 					}
  443. 					switch ( htaerrors )
  444. 					{
  445. 						case 0:
  446. 							Console.WriteLine( "No CSS errors found" );
  447. 							break;
  448. 						case 1:
  449. 							RedLine( "\n1 possible CSS error found" );
  450. 							break;
  451. 						default:
  452. 							RedLine( "\n{0} possible CSS errors found", htaerrors.ToString( ) );
  453. 							break;
  454. 					}
  455. 				}
  456. 			}
  457.  
  458. 			#endregion Check HTA Head
  459.  
  460.  
  461. 			return rc;
  462. 		}
  463.  
  464.  
  465. 		static int CheckStyle( string styledef )
  466. 		{
  467. 			int errors = 0;
  468. 			string pattern = @"^([^\{]+)\{([^\}]+)\}";
  469. 			Regex regex = new Regex( pattern );
  470. 			if ( regex.IsMatch( styledef ) )
  471. 			{
  472. 				string tagdef = regex.Match( styledef ).Groups[1].ToString( ).Trim( "\n\r\t ".ToCharArray( ) );
  473. 				string tagstyle = regex.Match( styledef ).Groups[2].ToString( ).Trim( "\n\r\t ".ToCharArray( ) );
  474. 				string[] tagcssall = tagstyle.Split( ';' );
  475. 				for ( int i = 0; i < tagcssall.Length; i++ )
  476. 				{
  477. 					tagcssall[i] = tagcssall[i].Trim( "\n\r\t ".ToCharArray( ) );
  478. 				}
  479. 				string pattern1 = @"^([\w-]+)\s*:\s*([^\n\r\;\{\}]+)$";
  480. 				Regex regex1 = new Regex( pattern1 );
  481. 				string pattern2 = @"^([\w-]+)\s*:";
  482. 				Regex regex2 = new Regex( pattern2 );
  483. 				foreach ( string line in tagcssall )
  484. 				{
  485. 					if ( String.IsNullOrWhiteSpace( line ) )
  486. 					{
  487. 						// No action required
  488. 					}
  489. 					else if ( regex1.IsMatch( line ) )
  490. 					{
  491. 						MatchCollection matches1 = regex1.Matches( line );
  492. 						string csskey = matches1[0].Groups[1].ToString( );
  493. 						string cssval = matches1[0].Groups[2].ToString( );
  494. 						string pattern3 = @"^[^\(]*\)|\([^\)]*$";
  495. 						regex = new Regex( pattern3 );
  496. 						if ( regex.IsMatch( cssval ) )
  497. 						{
  498. 							if ( !csserrors.Contains( csskey ) )
  499. 							{
  500. 								csserrors.Add( csskey );
  501. 								RedLine( "Possible CSS error for {0}:", csskey );
  502. 								Console.WriteLine( "\t{0}\n", cssval );
  503. 								errors += 1;
  504. 							}
  505. 						}
  506. 					}
  507. 					else if ( regex2.IsMatch( line ) )
  508. 					{
  509. 						MatchCollection matches2 = regex2.Matches( line );
  510. 						string csskey = matches2[0].Groups[1].ToString( );
  511. 						if ( !csserrors.Contains( csskey ) )
  512. 						{
  513. 							csserrors.Add( csskey );
  514. 							RedLine( "Possible CSS error(s) for {0}:", csskey );
  515. 							errors += 1;
  516. 						}
  517. 					}
  518. 					else
  519. 					{
  520. 						string csserror = styledef.Substring( 0, styledef.IndexOfAny( "{\n\r".ToCharArray( ) ) ).Trim( "{\n\r\t ".ToCharArray( ) );
  521. 						if ( !csserrors.Contains( csserror ) )
  522. 						{
  523. 							RedLine( "Possible CSS error(s):" );
  524. 							Console.WriteLine( "{0}\n", styledef );
  525. 							errors += 1;
  526. 						}
  527. 					}
  528. 				}
  529. 			}
  530. 			return errors;
  531. 		}
  532.  
  533.  
  534. 		static int CheckStyles( string stylesheet )
  535. 		{
  536. 			int errors = 0;
  537. 			string pattern = @"\/\*(.|\n|\r)*?\*\/";
  538. 			Regex regex = new Regex( pattern );
  539. 			if ( regex.IsMatch( stylesheet ) )
  540. 			{
  541. 				stylesheet = regex.Replace( stylesheet, String.Empty );
  542. 			}
  543. 			pattern = @"[^\n\r\{\}]+\s*\{[^\}]+\}";
  544. 			regex = new Regex( pattern, RegexOptions.IgnoreCase );
  545. 			if ( regex.IsMatch( stylesheet ) )
  546. 			{
  547. 				MatchCollection matches = regex.Matches( stylesheet );
  548. 				foreach ( Match match in matches )
  549. 				{
  550. 					errors += CheckStyle( match.ToString( ) );
  551. 				}
  552. 			}
  553. 			return errors;
  554. 		}
  555.  
  556.  
  557. 		static void RedLine( string line, params string[] rlargs )
  558. 		{
  559. 			Console.ForegroundColor = ConsoleColor.Red;
  560. 			if ( rlargs.Length > 0 )
  561. 			{
  562. 				Console.WriteLine( line, rlargs );
  563. 			}
  564. 			else
  565. 			{
  566. 				Console.WriteLine( line );
  567. 			}
  568. 			Console.ResetColor( );
  569. 		}
  570.  
  571.  
  572. 		static int ShowHelp( params string[] errmsg )
  573. 		{
  574. 			#region Error Message
  575.  
  576. 			if ( errmsg.Length > 0 )
  577. 			{
  578. 				List<string> errargs = new List<string>( errmsg );
  579. 				errargs.RemoveAt( 0 );
  580. 				Console.Error.WriteLine( );
  581. 				Console.ForegroundColor = ConsoleColor.Red;
  582. 				Console.Error.Write( "ERROR:\t" );
  583. 				Console.ForegroundColor = ConsoleColor.White;
  584. 				Console.Error.WriteLine( errmsg[0], errargs.ToArray( ) );
  585. 				Console.ResetColor( );
  586. 			}
  587.  
  588. 			#endregion Error Message
  589.  
  590.  
  591. 			#region Help Text
  592.  
  593. 			/*
  594. 			CheckVarsVBS.exe,  Version 1.02
  595. 			Check VBScript code for unused variables and subroutines
  596.  
  597. 			Usage:    CheckVarsVBS.exe  "vbsfile"  [ /S | /V ]  [ /U ]  [ /W ]
  598.  
  599. 			Where:    "vbsfile"         is the VBScript or HTA file to be examined
  600. 			          /S                tests Subroutines only
  601. 			                            (default: subroutines as well as variables)
  602. 			          /U                list Unused subroutines and variables only
  603. 			                            (default: list all subroutines and variables)
  604. 			          /V                tests Variables only
  605. 			                            (default: subroutines as well as variables)
  606. 			          /W                include Window_On* subroutines for HTAs
  607. 			                            (default: ignore Window_On* subroutines in HTAs)
  608.  
  609. 			Notes:    When checking subroutines, the program will also check for
  610. 			          improperly terminated and nested subroutines.
  611. 			          For HTAs only, the following special subroutines are ignored
  612. 			          (not listed in red, or not at all with /U switch) by default:
  613. 			          Window_OnBeforeUnload, Window_OnBlur, Window_OnFocus,
  614. 			          Window_OnHelp, Window_OnLoad, Window_OnResize, Window_OnUnload;
  615. 			          use /W to treat them as ordinary subroutines.
  616. 			          For HTAs only, unless checking for variables only (/V switch),
  617. 			          this program will search the HTA's head for CSS style definitions,
  618. 			          and check those for some common typos.
  619. 			          The program's return code equals the number of unused subroutines
  620. 			          and/or variables, or -1 in case of (command line) errors.
  621.  
  622. 			Written by Rob van der Woude
  623. 			http://www.robvanderwoude.com
  624. 			*/
  625.  
  626. 			Console.Error.WriteLine( );
  627.  
  628. 			Console.Error.WriteLine( "CheckVarsVBS.exe,  Version {0}", progver );
  629.  
  630. 			Console.Error.WriteLine( "Check VBScript code for unused variables and subroutines" );
  631.  
  632. 			Console.Error.WriteLine( );
  633.  
  634. 			Console.Error.Write( "Usage:    " );
  635. 			Console.ForegroundColor = ConsoleColor.White;
  636. 			Console.Error.WriteLine( "CheckVarsVBS.exe  \"vbsfile\"  [ /S | /V ]  [ /U ]  [ /W ]" );
  637. 			Console.ResetColor( );
  638.  
  639. 			Console.Error.WriteLine( );
  640.  
  641. 			Console.Error.Write( "Where:    " );
  642. 			Console.ForegroundColor = ConsoleColor.White;
  643. 			Console.Error.Write( "\"vbsfile\"" );
  644. 			Console.ResetColor( );
  645. 			Console.Error.WriteLine( "         is the VBScript or HTA file to be examined" );
  646.  
  647. 			Console.ForegroundColor = ConsoleColor.White;
  648. 			Console.Error.Write( "          /S" );
  649. 			Console.ResetColor( );
  650. 			Console.Error.Write( "                tests " );
  651. 			Console.ForegroundColor = ConsoleColor.White;
  652. 			Console.Error.Write( "S" );
  653. 			Console.ResetColor( );
  654. 			Console.Error.WriteLine( "ubroutines only" );
  655.  
  656. 			Console.Error.WriteLine( "                            (default: subroutines as well as variables)" );
  657.  
  658. 			Console.ForegroundColor = ConsoleColor.White;
  659. 			Console.Error.Write( "          /U" );
  660. 			Console.ResetColor( );
  661. 			Console.Error.Write( "                list " );
  662. 			Console.ForegroundColor = ConsoleColor.White;
  663. 			Console.Error.Write( "U" );
  664. 			Console.ResetColor( );
  665. 			Console.Error.WriteLine( "nused subroutines and variables only" );
  666.  
  667. 			Console.Error.WriteLine( "                            (default: list all subroutines and variables)" );
  668.  
  669. 			Console.ForegroundColor = ConsoleColor.White;
  670. 			Console.Error.Write( "          /V" );
  671. 			Console.ResetColor( );
  672. 			Console.Error.Write( "                tests " );
  673. 			Console.ForegroundColor = ConsoleColor.White;
  674. 			Console.Error.Write( "V" );
  675. 			Console.ResetColor( );
  676. 			Console.Error.WriteLine( "ariables only" );
  677.  
  678. 			Console.Error.WriteLine( "                            (default: subroutines as well as variables)" );
  679.  
  680. 			Console.ForegroundColor = ConsoleColor.White;
  681. 			Console.Error.Write( "          /W" );
  682. 			Console.ResetColor( );
  683. 			Console.Error.Write( "                include " );
  684. 			Console.ForegroundColor = ConsoleColor.White;
  685. 			Console.Error.Write( "W" );
  686. 			Console.ResetColor( );
  687. 			Console.Error.WriteLine( "indow_On* subroutines for HTAs" );
  688.  
  689. 			Console.Error.WriteLine( "                            (default: ignore Window_On* subroutines in HTAs)" );
  690.  
  691. 			Console.Error.WriteLine( );
  692.  
  693. 			Console.Error.WriteLine( "Notes:    When checking subroutines, the program will also check for" );
  694.  
  695. 			Console.Error.WriteLine( "          improperly terminated and nested subroutines." );
  696.  
  697. 			Console.Error.WriteLine( "          For HTAs only, the following special subroutines are ignored" );
  698.  
  699. 			Console.Error.Write( "          (not listed in red, or not at all with " );
  700. 			Console.ForegroundColor = ConsoleColor.White;
  701. 			Console.Error.Write( "/U" );
  702. 			Console.ResetColor( );
  703. 			Console.Error.WriteLine( " switch) by default:" );
  704.  
  705. 			Console.Error.WriteLine( "          Window_OnBeforeUnload, Window_OnBlur, Window_OnFocus," );
  706.  
  707. 			Console.Error.WriteLine( "          Window_OnHelp, Window_OnLoad, Window_OnResize, Window_OnUnload;" );
  708.  
  709. 			Console.Error.Write( "          use " );
  710. 			Console.ForegroundColor = ConsoleColor.White;
  711. 			Console.Error.Write( "/W" );
  712. 			Console.ResetColor( );
  713. 			Console.Error.WriteLine( " to treat them as ordinary subroutines." );
  714.  
  715. 			Console.Error.Write( "          For HTAs only, unless checking for variables only (" );
  716. 			Console.ForegroundColor = ConsoleColor.White;
  717. 			Console.Error.Write( "/V" );
  718. 			Console.ResetColor( );
  719. 			Console.Error.WriteLine( " switch)," );
  720.  
  721. 			Console.Error.WriteLine( "          this program will search the HTA's head for CSS style definitions," );
  722.  
  723. 			Console.Error.WriteLine( "          and check those for some common typos." );
  724.  
  725. 			Console.Error.WriteLine( "          The program's return code equals the number of unused subroutines" );
  726.  
  727. 			Console.Error.WriteLine( "          and/or variables, or -1 in case of (command line) errors." );
  728.  
  729. 			Console.Error.WriteLine( );
  730.  
  731. 			Console.Error.WriteLine( "Written by Rob van der Woude" );
  732.  
  733. 			Console.Error.WriteLine( "http://www.robvanderwoude.com" );
  734.  
  735. 			#endregion Help Text
  736.  
  737.  
  738. 			return -1;
  739. 		}
  740. 	}
  741. }
  742.  

page last uploaded: 2018-12-04, 10:47