public static void test_uint1() { Parser.Error r = p.Register("test-uint1 uint u0", Parser.Ignored); Equal(r, Parser.Error.NONE); r = p.Parse("test-uint1:-2"); Equal(r, Parser.Error.NOT_NUMBER); Ok(); }
public static void test_str0() { p.Register("test-str0 str s0", helper_str0); p.priv = 0; Parser.Error r = p.Parse("test-str0:foo:bar:baz quxx..."); Equal(r, Parser.Error.NONE); Equal(p.priv, 1); Ok(); }
public static void test_int1() { p.Register("test-int1 int i0", helper_int1); p.priv = false; Parser.Error r = p.Parse("test-int1:-3"); Equal(r, Parser.Error.NONE); Equal(p.priv, true); Ok(); }
public static void test_char1() { Parser.Error r = p.Register("test-char1 char c0 int i0 char c1 str s", helper_char1); Equal(r, Parser.Error.NONE); p.priv = false; r = p.Parse("test-char1:::34:::lala"); Equal(r, Parser.Error.NONE); Equal(p.priv, true); Ok(); }
public static void test_char0() { Parser.Error r = p.Register("test-char0 char c", helper_char0); Equal(r, Parser.Error.NONE); p.priv = false; r = p.Parse("test-char0:C"); Equal(r, Parser.Error.NONE); Equal(p.priv, true); Ok(); }
public static void test_sym1() { int wasok = 0; p.Register("test-sym1 sym foo sym baz", helper_sym1); p.priv = wasok; Parser.Error r = p.Parse("test-sym1:bar:quxx"); Equal(r, Parser.Error.NONE); Equal(p.priv, 1); Ok(); }
public static void test_uint0() { Parser.Error r = p.Register("test-uint0 uint u0", helper_uint0); Equal(r, Parser.Error.NONE); p.priv = false; Parser.Error e = p.Parse("test-uint0:42"); Equal(e, Parser.Error.NONE); Equal(p.priv, true); Ok(); }
public static void test_sym0() { int wasok = 0; p.Register("test-sym0 sym foo", helper_sym0); p.priv = wasok; Parser.Error r = p.Parse("test-sym0:bar"); Equal(r, Parser.Error.NONE); Equal(wasok, 1); Ok(); }
/* * Process the user pref file with the given name. * "quiet" means "don't complain about not finding the file. * * 'user' should be true if the pref file loaded is user-specific and not * a game default. * * Returns true if everything worked OK, false otherwise */ public static bool process_pref_file(string name, bool quiet, bool user) { //Nick: Rewritten from scratch, since io is so different from C string path = Misc.path_build(Misc.ANGBAND_DIR_PREF, name); if (!File.Exists(path)) { path = Misc.path_build(Misc.ANGBAND_DIR_USER, name); if (!File.Exists(path)) { if (!quiet) { Utilities.msg("Can not open " + path + "."); } return(false); } } FileStream f = null; try { f = File.OpenRead(path); } catch { if (!quiet) { Utilities.msg("Can not open " + path + "."); } return(false); } finally { if (f != null) { f.Close(); //Just wanted to see if we could open it before proceeding... } } Parser p = init_parse_prefs(user); Parser.Error e = p.parse_file(path, false); finish_parse_prefs(p); p.Destroy(); return(e == Parser.Error.NONE); //Below I wrote until I realized that there exists a Parser.ParseFile... //StreamReader sr = new StreamReader(f); //while (!sr.EndOfStream) //{ // line_no++; // e = p.Parse(line); // if (e != Parser.Error.NONE) // { // print_error(buf, p); // break; // } //} //finish_parse_prefs(p); //f.Close(); //p.Destroy(); ///* Result */ //return e == Parser.Error.NONE; //======================Original below for comparison //char buf[1024]; //ang_file *f; //Parser p; //int e = 0; //int line_no = 0; ///* Build the filename */ //path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, name); //if (!file_exists(buf)) // path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name); //f = file_open(buf, MODE_READ, -1); //if (!f) //{ // if (!quiet) // msg("Cannot open '%s'.", buf); //} //else //{ // char line[1024]; // p = init_parse_prefs(user); // while (file_getl(f, line, sizeof line)) // { // line_no++; // e = parser_parse(p, line); // if (e != Parser.Error.NONE) // { // print_error(buf, p); // break; // } // } // finish_parse_prefs(p); // file_close(f); // mem_free(p.priv); // parser_destroy(p); //} ///* Result */ //return e == Parser.Error.NONE; }