00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "helper.h"
00024
00025
00026
00027 #ifdef FAUDES_WINEXTRA
00028 #include "winextra.h"
00029 #endif
00030
00031
00032 namespace faudes {
00033
00034
00035 std::string ToStringInteger(long int number) {
00036 std::string res;
00037 std::stringstream sstr;
00038 sstr << number;
00039 sstr >> res;
00040 return res;
00041 }
00042
00043
00044 std::string ToStringInteger16(long int number) {
00045 std::string res;
00046 std::stringstream sstr;
00047 sstr << "0x" << std::setbase(16) << number;
00048 sstr >> res;
00049 return res;
00050 }
00051
00052
00053
00054 std::string ToStringFloat(double number) {
00055 if(number == (long int) number)
00056 return(ToStringInteger((long int) number));
00057 std::string res;
00058 std::stringstream sstr;
00059 sstr << std::fixed;
00060 sstr << number;
00061 sstr >> res;
00062 return res;
00063 }
00064
00065
00066 std::string ExpandString(const std::string& rString, unsigned int len) {
00067 std::string res;
00068 res = rString;
00069 std::string::size_type xtra = (std::string::size_type) len - rString.length();
00070 if ((xtra > 0) && (xtra < 10000)) {
00071 res.append(xtra, ' ');
00072 }
00073 return res;
00074 }
00075
00076
00077 std::string CollapsString(const std::string& rString, unsigned int len) {
00078 if(len <0) return rString;
00079 if(rString.length() < len) return rString;
00080 int head = len/2;
00081 int tail = len/2;
00082 return rString.substr(0,head) + "..." + rString.substr(len-tail,tail);
00083 }
00084
00085
00086 Idx ToIdx(const std::string& rString) {
00087 char * end;
00088 unsigned long ul = strtoul (rString.c_str(), &end, 0);
00089 unsigned long idxmax = std::numeric_limits<Idx>::max();
00090 if (ul > idxmax) {
00091 throw Exception("atoidx", "Idx overflow", 600);
00092 }
00093 else {
00094 return (Idx) ul;
00095 }
00096 }
00097
00098
00099 std::string FDVersionString() {
00100 return std::string(FAUDES_VERSION);
00101 }
00102
00103
00104 std::string FDPluginsString() {
00105 return std::string(FAUDES_PLUGINS);
00106 }
00107
00108
00109 std::string FDContributorsString() {
00110 return
00111 "Berndt, Breindel, Doerr, Duevel, Franchi, Hellenschmidt, Moor, Musunoi, "
00112 "Opitz, Perk, Rempel, Ritter, Schlein, Schmidt, Zaddach, et al";
00113 }
00114
00115
00116
00117 void ProcessDot(const std::string& rDotFile,
00118 const std::string& rOutFile, const std::string& rOutFormat, const std::string& rDotExec)
00119 {
00120 std::string format=rOutFormat;
00121
00122 if(format=="") {
00123 if(rOutFile.rfind('.')+1 < rOutFile.size()) {
00124 format=rOutFile.substr(rOutFile.rfind('.')+1);
00125 }
00126 }
00127
00128 if (format == "canon");
00129 else if (format == "dot");
00130 else if (format == "xdot");
00131 else if (format == "cmap");
00132 else if (format == "dia");
00133 else if (format == "fig");
00134 else if (format == "gd");
00135 else if (format == "gd2");
00136 else if (format == "gif");
00137 else if (format == "hpgl");
00138 else if (format == "imap");
00139 else if (format == "cmapx");
00140 else if (format == "ismap");
00141 else if (format == "jpg");
00142 else if (format == "jpeg");
00143 else if (format == "mif");
00144 else if (format == "mp");
00145 else if (format == "pcl");
00146 else if (format == "pic");
00147 else if (format == "plain");
00148 else if (format == "plain-ext");
00149 else if (format == "png");
00150 else if (format == "ps");
00151 else if (format == "ps2");
00152 else if (format == "svg");
00153 else if (format == "svgz");
00154 else if (format == "vrml");
00155 else if (format == "vtx");
00156 else if (format == "wbmp");
00157 else {
00158 std::stringstream errstr;
00159 errstr << "Dot output format \"" << format << "\" unknown";
00160 throw Exception("faudes::ProcessDot", errstr.str(), 3);
00161 }
00162 std::string dotcommand = rDotExec + " -T"+format+" \""+rDotFile+"\" -o \""+rOutFile+"\"";
00163 if (system(dotcommand.c_str()) != 0) {
00164 throw Exception("faudes::ProcessDot",
00165 "Error in running dot", 3);
00166 }
00167 }
00168
00169
00170
00171
00172 std::string CreateTempFile(void) {
00173 char filename[]= "faudes_temp_XXXXXX";
00174 int filedes = mkstemp(filename);
00175 if(filedes==-1) {
00176 FD_DF("faudes::CreateTempFile(): error");
00177 return "";
00178 }
00179 close(filedes);
00180 std::string res(filename);
00181 FD_DF("faudes::CreateTempFile(): " << res);
00182 return(res);
00183 }
00184
00185
00186
00187
00188 bool RemoveFile(const std::string& rFileName) {
00189 return std::remove(rFileName.c_str()) == 0;
00190 }
00191
00192
00193
00194
00195 }