All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
pairdiff.cc
Go to the documentation of this file.
1 /* pairdiff.cc
2  */
3 
5 #include "osl/record/csa.h"
6 #include <boost/scoped_ptr.hpp>
7 #include <iostream>
8 #include <cstdlib>
9 #include <cstdio>
10 #include <unistd.h>
11 
12 // 二つのテーブルの差を表示
13 
14 using namespace osl;
15 using namespace osl::eval;
16 
17 void usage(const char *prog)
18 {
19  using namespace std;
20  cerr << "Usage: " << prog << " table1 table2"
21  << endl;
22  exit(1);
23 }
24 
25 void show(std::ostream& os, Square pos, PtypeO ptypeo)
26 {
27  csaShow(os, pos);
28  os << " ";
29  os << getOwner(ptypeo);
30  csaShow(os, getPtype(ptypeo));
31 }
32 
33 int main(int argc, char **argv)
34 {
35  const char *program_name = argv[0];
36  bool error_flag = false;
37  const char *filename1 = 0;
38  const char *filename2 = 0;
39 
40  // extern char *optarg;
41  extern int optind;
42  char c;
43  while ((c = getopt(argc, argv, "vh")) != EOF)
44  {
45  switch(c)
46  {
47  default: error_flag = true;
48  }
49  }
50  argc -= optind;
51  argv += optind;
52 
53  if (error_flag || (argc < 2))
54  usage(program_name);
55  filename1 = argv[0];
56  filename2 = argv[1];
57 
58  boost::scoped_ptr<PiecePairRawTable> table1(new PiecePairRawTable());
59  table1->loadFromBinaryFile(filename1);
60  boost::scoped_ptr<PiecePairRawTable> table2(new PiecePairRawTable());
61  table2->loadFromBinaryFile(filename2);
62 
63  for (unsigned int i=0; i<PiecePairRawTable::maxPairIndex; ++i)
64  {
65  const int val1 = table1->value(i);
66  const int val2 = table2->value(i);
67  if (val1 != val2)
68  {
69  size_t i1, i2;
70  PiecePairRawTable::meltIndex(i, i1, i2);
71  Square pos1, pos2;
72  PtypeO ptypeo1, ptypeo2;
73  PiecePairRawTable::meltIndex(i1, pos1, ptypeo1);
74  PiecePairRawTable::meltIndex(i2, pos2, ptypeo2);
75  show(std::cout, pos1, ptypeo1);
76  std::cout << " ";
77  show(std::cout, pos2, ptypeo2);
78  std::cout << " : " << val1 << " != " << val2 << "\n";
79  }
80  }
81 }
82 
83 
84 /* ------------------------------------------------------------------------- */
85 // ;;; Local Variables:
86 // ;;; mode:c++
87 // ;;; c-basic-offset:2
88 // ;;; End: