util - end = line.find_first_of (delimiters, start);...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include <cstdlib> #include <unistd.h> using namespace std; #include "util.h" } int exit_status::status = EXIT_SUCCESS; void exit_status::set (int new_status) { status = new_status; } int exit_status::get() { return status; } string execname() { string execname = getexecname(); TRACE ('u', execname); return execname.substr (execname.rfind ('/') + 1); } bool want_echo() { const int CIN_FD = 0; const int COUT_FD = 1; bool cin_isatty = isatty (CIN_FD); bool cout_isatty = isatty (COUT_FD); TRACE ('u', "cin_isatty = " << cin_isatty << ", cout_isatty = " << cout_isatty); return ! cin_isatty || ! cout_isatty; } wordvec words; int end = 0; // Loop over the string, splitting out words, and for each word // thus found, append it to the output wordvec. for (;;) { int start = line.find_first_not_of (delimiters, end); if (start == string::npos) break;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: end = line.find_first_of (delimiters, start); words.push_back (line.substr (start, end - start)); } TRACE ('u', words); return words; } ostream &amp;complain() { exit_status::set (EXIT_FAILURE); cerr &lt;&lt; execname() &lt;&lt; &quot;: &quot;; return cerr; } #ifdef __SUNPRO_CC ostream &amp;operator&lt;&lt; (ostream &amp;out, bool boolean){ out &lt;&lt; (boolean ? &quot;true&quot; : &quot;false&quot;); return out; } #endif template &lt;typename item_t&gt; ostream &amp;operator&lt;&lt; (ostream &amp;out, vector&lt;item_t&gt; vec) { typename vector&lt;item_t&gt;::iterator itor = vec.begin(); typename vector&lt;item_t&gt;::iterator end = vec.end(); // If the vector is empty, do nothing. if (itor != end) { // Print out the first element without a space. out &lt;&lt; *itor++; // Print out the rest of the elements each preceded by a space. while (itor != end) out &lt;&lt; &quot; &quot; &lt;&lt; *itor++; } return out; } RCSC(util_cc, &quot;$Id: util.cc,v 1.27 2010-01-04 14:37:56-08 - - $&quot;)...
View Full Document

This note was uploaded on 01/26/2010 for the course CMPS 109 taught by Professor Bailey,d during the Spring '08 term at UCSC.

Page1 / 2

util - end = line.find_first_of (delimiters, start);...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online