00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "pandabase.h"
00016 #include "eggMiscFuncs.h"
00017 #include "indent.h"
00018
00019 #include <ctype.h>
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 ostream &
00030 enquote_string(ostream &out, const string &str, int indent_level,
00031 bool always_quote) {
00032 indent(out, indent_level);
00033
00034
00035 bool legal = !always_quote;
00036 string::const_iterator p;
00037 for (p = str.begin(); p != str.end() && legal; ++p) {
00038 legal = (isalnum(*p) || *p=='-' || *p=='_' || *p=='#' || *p=='.');
00039 }
00040
00041 if (legal) {
00042 out << str;
00043
00044 } else {
00045 out << '"';
00046
00047 for (p = str.begin(); p != str.end(); ++p) {
00048 switch (*p) {
00049 case '"':
00050
00051 out << "'";
00052 break;
00053
00054 case '\n':
00055
00056
00057 out << "\"\n";
00058 indent(out, indent_level) << '"';
00059 break;
00060
00061 default:
00062 out << *p;
00063 }
00064 }
00065 out << '"';
00066 }
00067
00068 return out;
00069 }
00070
00071
00072
00073
00074
00075
00076
00077 void
00078 write_transform(ostream &out, const LMatrix3d &mat, int indent_level) {
00079 indent(out, indent_level) << "<Transform> {\n";
00080
00081 indent(out, indent_level+2) << "<Matrix3> {\n";
00082
00083 for (int r = 0; r < 3; r++) {
00084 indent(out, indent_level+3);
00085 for (int c = 0; c < 3; c++) {
00086 out << " " << mat(r, c);
00087 }
00088 out << "\n";
00089 }
00090 indent(out, indent_level+2) << "}\n";
00091 indent(out, indent_level) << "}\n";
00092 }
00093
00094
00095
00096
00097
00098
00099 void
00100 write_transform(ostream &out, const LMatrix4d &mat, int indent_level) {
00101 indent(out, indent_level) << "<Transform> {\n";
00102
00103 indent(out, indent_level+2) << "<Matrix4> {\n";
00104
00105 for (int r = 0; r < 4; r++) {
00106 indent(out, indent_level+3);
00107 for (int c = 0; c < 4; c++) {
00108 out << " " << mat(r, c);
00109 }
00110 out << "\n";
00111 }
00112 indent(out, indent_level+2) << "}\n";
00113 indent(out, indent_level) << "}\n";
00114 }