add -f and -c
This commit is contained in:
parent
68bdff57eb
commit
bfb6afa369
|
|
@ -21,6 +21,7 @@
|
|||
#include "dcClass.h"
|
||||
#include "dcTypedef.h"
|
||||
#include "memoryUsage.h"
|
||||
#include "indent.h"
|
||||
|
||||
#ifndef HAVE_GETOPT
|
||||
#include "gnu_getopt.h"
|
||||
|
|
@ -33,7 +34,7 @@ usage() {
|
|||
cerr <<
|
||||
"\n"
|
||||
"Usage:\n\n"
|
||||
"dcparse [-v | -b] [file1 file2 ...]\n"
|
||||
"dcparse [options] [file1 file2 ...]\n"
|
||||
"dcparse -h\n\n";
|
||||
}
|
||||
|
||||
|
|
@ -46,18 +47,93 @@ help() {
|
|||
"the file(s) are read and concatenated, and a single hash code is printed\n"
|
||||
"corresponding to the file's contents.\n\n"
|
||||
|
||||
"With -b, this writes a brief version of the file to standard output\n"
|
||||
"instead. With -v, this writes a more verbose version.\n\n";
|
||||
"Options:\n\n"
|
||||
|
||||
" -v Writes a complete parseable version of the file to standard\n"
|
||||
" output instead of printing a hash code.\n\n"
|
||||
|
||||
" -b Writes a brief parseable version of the file instead of a full\n"
|
||||
" version. This is semantically the same as the output produced\n"
|
||||
" the above -v option--reading it would produce exactly the same\n"
|
||||
" results--but it is designed to be slightly obfuscated. The\n"
|
||||
" comments and parameter names are not included.\n\n"
|
||||
|
||||
" -c Write a list of class names, showing the inheritance hierarchy.\n"
|
||||
" Some class names will be listed twice in the presence of multiple\n"
|
||||
" inheritance.\n\n"
|
||||
|
||||
" -f Write a complete list of field names available for each class,\n"
|
||||
" including all inherited fields.\n\n";
|
||||
}
|
||||
|
||||
void
|
||||
write_class_hierarchy(int indent_level, const DCFile &file,
|
||||
const DCClass *this_dclass) {
|
||||
indent(cout, indent_level)
|
||||
<< this_dclass->get_name() << "\n";
|
||||
|
||||
int num_classes = file.get_num_classes();
|
||||
for (int i = 0; i < num_classes; ++i) {
|
||||
const DCClass *dclass = file.get_class(i);
|
||||
bool is_my_child = false;
|
||||
int num_parents = dclass->get_num_parents();
|
||||
for (int j = 0; j < num_parents && !is_my_child; ++j) {
|
||||
is_my_child = (dclass->get_parent(j) == this_dclass);
|
||||
}
|
||||
|
||||
if (is_my_child) {
|
||||
write_class_hierarchy(indent_level + 2, file, dclass);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
write_class_hierarchy(const DCFile &file) {
|
||||
int num_classes = file.get_num_classes();
|
||||
for (int i = 0; i < num_classes; ++i) {
|
||||
const DCClass *dclass = file.get_class(i);
|
||||
if (dclass->get_num_parents() == 0) {
|
||||
write_class_hierarchy(0, file, dclass);
|
||||
cout << "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
write_complete_field_list(const DCFile &file) {
|
||||
int num_classes = file.get_num_classes();
|
||||
for (int i = 0; i < num_classes; ++i) {
|
||||
const DCClass *dclass = file.get_class(i);
|
||||
cout << "\n" << dclass->get_name() << "\n";
|
||||
int num_inherited_fields = dclass->get_num_inherited_fields();
|
||||
for (int j = 0; j < num_inherited_fields; ++j) {
|
||||
const DCField *field = dclass->get_inherited_field(j);
|
||||
cout << " ";
|
||||
if (field->get_class() != dclass) {
|
||||
cout << field->get_class()->get_name() << "::";
|
||||
}
|
||||
cout << field->get_name();
|
||||
if (field->as_atomic_field() != (DCAtomicField *)NULL ||
|
||||
field->as_molecular_field() != (DCMolecularField *)NULL) {
|
||||
// It's a "method".
|
||||
cout << "()";
|
||||
}
|
||||
field->output_keywords(cout);
|
||||
cout << "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[]) {
|
||||
// extern char *optarg;
|
||||
extern int optind;
|
||||
const char *optstr = "bvh";
|
||||
const char *optstr = "bvcfh";
|
||||
|
||||
bool dump_verbose = false;
|
||||
bool dump_brief = false;
|
||||
bool dump_classes = false;
|
||||
bool dump_fields = false;
|
||||
|
||||
int flag = getopt(argc, argv, optstr);
|
||||
|
||||
|
|
@ -71,6 +147,14 @@ main(int argc, char *argv[]) {
|
|||
dump_verbose = true;
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
dump_classes = true;
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
dump_fields = true;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
help();
|
||||
exit(1);
|
||||
|
|
@ -116,16 +200,22 @@ main(int argc, char *argv[]) {
|
|||
}
|
||||
}
|
||||
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (dump_verbose || dump_brief) {
|
||||
if (!file.write(cout, dump_brief)) {
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
} else if (dump_classes) {
|
||||
write_class_hierarchy(file);
|
||||
|
||||
} else if (dump_fields) {
|
||||
write_complete_field_list(file);
|
||||
|
||||
} else {
|
||||
long hash = file.get_hash();
|
||||
unsigned long hash = file.get_hash();
|
||||
cerr << "File hash is " << hash << "\n";
|
||||
}
|
||||
|
||||
|
|
@ -141,5 +231,5 @@ main(int argc, char *argv[]) {
|
|||
}
|
||||
#endif
|
||||
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue