46 inline void add_screen_spaces(std::string &
str, std::string::size_type size, std::string::size_type indent)
48 std::stringstream ss(str.substr(indent));
50 std::string::size_type words =0;
52 while (ss >> word){words++;}
56 std::string::size_type to_add = (size - str.length())/(words);
57 std::string::size_type extras = (size - str.length())%(words);
58 std::string::size_type extras_even = words/2;
59 std::string::size_type extras_odd = words - extras_even;
60 if (extras > extras_odd)
62 extras_even = extras - extras_odd;
70 std::string::size_type pos = str.find_first_not_of(
" ", indent);
71 pos = str.find_first_of(
" ", pos);
73 while (pos != std::string::npos)
76 if (i%2 == 0 && extras_even > 0)
78 str.insert(pos, to_add + 1,
' ');
81 else if (i%2 == 1 && extras_odd > 0)
83 str.insert(pos, to_add + 1,
' ');
88 str.insert(pos, to_add,
' ');
91 pos = str.find_first_not_of(
" ", pos);
92 pos = str.find_first_of(
" ", pos);
103 std::string output_string,
str;
104 std::stringstream ss(input_string);
108 std::string::size_type cols_pos = cols;
109 while (std::getline(ss, str))
112 std::string line =
str;
114 if (str.length() >= 16 && str.substr(0, 16) ==
"#remove_newlines")
116 bool ck_space =
false;
119 while(std::getline(ss, str))
121 if (str.length() >= 21 && str.substr(0, 21) ==
"#dont_remove_newlines")
125 else if (str.find_first_not_of(
" ") == std::string::npos)
130 else if (!(str.length() > 0 && str[0] ==
'#'))
140 if (str[str.length()-1] !=
' ')
148 std::string::size_type len = line.find_last_not_of(
" ");
149 if (len == std::string::npos || line.length() == 0)
151 output_string +=
"\n";
153 else if (!(line.length() > 0 && line[0] ==
'#'))
155 line = line.substr(0, len+1);
157 std::string::size_type cols_corr = line.find_first_of(
"\x1b");
158 std::string::size_type indent = line.find_first_not_of(
" ");
159 std::string::size_type colon_indent = line.find_first_of(
":");
161 if (colon_indent != std::string::npos && 2*colon_indent < cols_pos)
163 indent = line.find_first_not_of(
" ", colon_indent +1);
168 if ((cols_corr == std::string::npos) && (line.length() > cols_pos))
172 output_string += temp +
"\n";
176 output_string += line +
"\n";
182 output_string +=
"\n";
188 while(std::getline(ss, str))
190 if (!(str.length() > 0 && str[0] ==
'#'))
192 str = str.substr(0, str.find_last_not_of(
" ")+1);
193 output_string += str +
"\n";
198 return output_string;
208 char temp_file[20] =
"_gambit_temp_XXXXXX";
209 int err = mkstemp(temp_file);
211 std::ofstream out(temp_file);
212 out << file << std::flush;
213 if (std::system(
"command -v less >/dev/null"))
215 err = std::system((std::string(
"more -d ") + std::string(temp_file)).c_str());
220 err = std::system((std::string(
"less -S -R -P\"Gambit diagnostic ") + name + std::string(
" line %l (press h for help or q to quit)\" ") + std::string(temp_file)).c_str());
223 err = std::system((
"rm -f " + std::string(temp_file) +
" >/dev/null").c_str());
General small utility macros.
EXPORT_SYMBOLS error & utils_error()
Utility errors.
void add_screen_spaces(std::string &str, std::string::size_type size, std::string::size_type indent)
Utility Functions for the Gambit Scanner.
std::string separate_line(std::string &line, std::string::size_type indent, std::string::size_type cols_pos)
std::string str
Shorthand for a standard string.
Exception objects required for standalone compilation.
TODO: see if we can use this one:
std::string format_for_screen(const std::string &input_string)
void print_to_screen(const std::string &file_in, const std::string &name)