Index: tools/prettyprinter/main.cc
===================================================================
--- tools/prettyprinter/main.cc	(revision c9383ee129f19e14e79cdf7dfbed73ff89c02129)
+++ tools/prettyprinter/main.cc	(revision b0f7a431679f3dd6bb471f22feea766dda4b90ef)
@@ -1,4 +1,4 @@
 // 
-// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
+// Cforall Version 1.0.0 Copyright (C) 2017 University of Waterloo
 //
 // The contents of this file are covered under the licence agreement in the
@@ -10,6 +10,6 @@
 // Created On       : Wed Jun 28 22:57:26 2017
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Thu Jun 29 09:02:37 2017
-// Update Count     : 15
+// Last Modified On : Thu Jun 29 13:09:32 2017
+// Update Count     : 58
 // 
 
@@ -19,56 +19,91 @@
 using namespace std;
 #include <unistd.h>										// close
+#include <getopt.h>										// getopt
 #include "filter.h"
 
 extern FILE * yyin;
-extern int yylineno;
 extern int yydebug;
 extern int yyparse( void );
 
+bool parse_cmdline( int argc, char * argv[] ) {
+	enum { Html, Identity, Latex, Nocode, ParseTree, };
+
+	static struct option long_opts[] = {
+		{ "html", no_argument, nullptr, Html },
+		{ "identity", no_argument, nullptr, Identity },
+		{ "latex", no_argument, nullptr, Latex },
+		{ "nocode", no_argument, nullptr, Nocode },
+		{ "parse-tree", no_argument, nullptr, ParseTree },
+		{ nullptr, 0, nullptr, 0 }
+	}; // long_opts
+	int long_index;
+
+	opterr = 0;											// (global) prevent getopt from printing error messages
+
+	int c;
+	while ( (c = getopt_long( argc, argv, "hilnp", long_opts, &long_index )) != -1 ) {
+		switch ( c ) {
+		  case Html:
+		  case 'h':
+			filter = HTML;
+			break;
+		  case Identity:
+		  case 'i':
+			filter = ::Identity;
+			break;
+		  case Latex:
+		  case 'l':
+			filter = LaTeX;
+			break;
+		  case Nocode:
+		  case 'n':
+			filter = ::Nocode;
+			break;
+		  case ParseTree:
+		  case 'p':
+			filter = Parse_Tree;
+		  case '?':
+			if ( optopt ) {								// short option ?
+				cerr << "Unknown option: -" << (char)optopt << endl;
+			} else {									// long option
+				cerr << "Unknown option: " << argv[optind - 1] << endl;
+			} // if
+			return false;
+		  default:
+			abort();
+		} // switch
+	} // while
+
+	if ( optind != argc ) {								// input files ?
+		if ( optind == argc - 1 ) {						// any commands after the flags ? => input file name
+			yyin = fopen( argv[ optind ], "r" );
+			if ( yyin == nullptr ) {
+				cerr << "Open failure for input file \"" << argv[ optind ] << "\"" << endl;
+				return false;
+			} // if
+		} else {
+			cerr << "Too many input files " << argv[ optind + 1 ] << endl;
+			return false;
+		} // if
+	} // if
+	return true;
+} // parse_cmdline
+
 int main( int argc, char *argv[] ) {
-	yyin = stdin;
+	yyin = stdin;										// defaults
 	filter = Nocode;
 
-	try {
-		switch ( argc ) {
-		  case 3:
-			yyin = fopen( argv[ 2 ], "r" );
-			if ( yyin == nullptr ) {
-				throw ios_base::failure( "unknown printer option arguments" );
-			} // if
-			// FALL THROUGH
-		  case 2: {
-			  string arg( argv[1] );
-
-			  if ( arg == "-identity" ) {
-				  filter = Identity;
-			  } else if ( arg == "-parse_tree" ) {
-				  filter = Parse_Tree;
-			  } else if ( arg == "-nocode" ) {
-				  filter = Nocode;
-			  } else if ( arg == "-latex" ) {
-				  filter = LaTeX;
-			  } else if ( arg == "-html" ) {
-				  filter = HTML;
-			  } else {
-				  throw ios_base::failure( "unknown printer option arguments" );
-			  } // if
-			  break;
-		  }
-		  default:
-			throw ios_base::failure( "wrong number of arguments" );
-		} // switch
-	} catch( ios_base::failure err ) {
-		cerr << err.what() << endl;
-		cerr << "Usage: [" << argv[0]
-			 << "-identity |"
-			 << "-parse_tree |"
-			 << "-nocode |"
-			 << "-latex |"
-			 << "-html"
+	if ( ! parse_cmdline( argc, argv ) ) {
+		cerr << "Usage: " << argv[0]
+			 << " ["
+			 << "-h/--html | "
+			 << "-i/--identity | "
+			 << "-l/--latex | "
+			 << "-n/--nocode | "
+			 << "-p/--parse-tree"
 			 << "] [input-file]"
 			 << endl;
 		exit( EXIT_FAILURE );							// TERMINATE
-	} // try
+	} // if
 
 	//yydebug = 1;
