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