Ejemplo n.º 1
0
        /// <summary>
        /// Application Entry Point.
        /// </summary>
        public static void Main(string[] args)
        {
            DictionaryReader reader = new DictionaryReader();
            string dictionaryPath = Properties.Settings.Default.DictionaryPath;
            string dictionaryURL = Properties.Settings.Default.DictionaryURL;

            /* Set up the command line flag handler(s) */
            CommandLineArgs cmdLine = new CommandLineArgs();
            cmdLine.PrefixRegexPatternList.Add("-{1}");

            cmdLine.registerSpecificSwitchMatchHandler("u", (sender, e) => {
                download(dictionaryURL, dictionaryPath);
            });
            cmdLine.registerSpecificSwitchMatchHandler("d", (sender, e) => {
                dictionaryPath = e.Value;
            });
            // D flag is for updating the configuration file with the path to the specified dictionary
            //cmdLine.registerSpecificSwitchMatchHandler("D", (sender, e) => {

            //});

            try {
                cmdLine.processCommandLineArgs(args);

                Tuple<string, string> word = reader.getNextWord();

                Console.WriteLine();
                Console.WriteLine(word.Item1);
                Console.WriteLine(" - " + word.Item2);
                Console.WriteLine();
            #if (DEBUG)
                Console.Read();
            #endif
            }
            catch (Exception e) {
                Console.WriteLine(e.Message);
            #if (DEBUG)
                Console.Read();
            #endif
            }
        }
Ejemplo n.º 2
0
		/// <summary>
		/// Attempt to read a file and print the last n lines to stdout. 
		/// </summary>
		/// <param name="args"></param>
		static void Main(string[] args) {
			bool p_flag = false;			/* Determine if the -p flag was given */
			string filePath = string.Empty;	/* Path to file */
			uint numLines = 10;				/* Default number of lines to print */

			/* Set up the command line flag handler(s) */
			CommandLineArgs cmdLine = new CommandLineArgs();
			cmdLine.PrefixRegexPatternList.Add("-{1}");
			
			cmdLine.registerSpecificSwitchMatchHandler("n", (sender, e) => {
				numLines = uint.Parse(e.Value);
			});
			cmdLine.registerSpecificSwitchMatchHandler("p", (sender, e) => {
				filePath = e.Value;
				p_flag = true;
			});

			try {
				// Put a newline before doing anything. Looks better.
				Console.WriteLine();

				cmdLine.processCommandLineArgs(args);

				if (!p_flag) {
					Console.WriteLine("error: no file given");
					Console.WriteLine(usage);
					goto Exit;
				}

				print(readFile(filePath), numLines);
			}
			catch (IndexOutOfRangeException e) {
				Console.WriteLine("error: invalid number of arguments");
				Console.WriteLine(usage);
			}
			catch (Exception e) {
				Console.WriteLine(e.Message);
				Console.WriteLine(usage);
			}

		Exit:
			// Put a newline after everything is done. Looks better.
			Console.WriteLine();
#if DEBUG
		foreach (string invalidArg in cmdLine.InvalidArgs) {
			Console.WriteLine(invalidArg);
		}
		Console.ReadLine();
#endif
		}