equal
deleted
inserted
replaced
34 |
34 |
35 |
35 |
36 // #include <stdio.h> /* required for NULL */ |
36 // #include <stdio.h> /* required for NULL */ |
37 #include <string> |
37 #include <string> |
38 #include <iostream> |
38 #include <iostream> |
39 |
39 #include <fstream> |
40 |
|
41 |
40 |
42 |
41 |
43 #include "stage4.hh" |
42 #include "stage4.hh" |
44 |
43 |
45 |
44 |
46 |
45 |
47 |
46 |
48 |
47 |
49 |
48 |
50 stage4out_c::stage4out_c(std::string indent_level) { |
49 stage4out_c::stage4out_c(std::string indent_level): |
|
50 m_file(NULL) { |
|
51 out = &std::cout; |
51 this->indent_level = indent_level; |
52 this->indent_level = indent_level; |
52 this->indent_spaces = ""; |
53 this->indent_spaces = ""; |
53 } |
54 } |
54 |
55 |
55 stage4out_c::~stage4out_c(void) {} |
56 stage4out_c::stage4out_c(const char *radix, const char *extension, std::string indent_level) { |
|
57 std::string filename(radix); |
|
58 filename += "."; |
|
59 filename += extension; |
|
60 std::fstream *file = new std::fstream(filename.c_str(), std::fstream::out); |
|
61 out = file; |
|
62 m_file = file; |
|
63 this->indent_level = indent_level; |
|
64 this->indent_spaces = ""; |
|
65 } |
|
66 |
|
67 stage4out_c::~stage4out_c(void) { |
|
68 if(m_file) |
|
69 { |
|
70 m_file->close(); |
|
71 delete m_file; |
|
72 } |
|
73 } |
56 |
74 |
57 |
75 |
58 void stage4out_c::indent_right(void) { |
76 void stage4out_c::indent_right(void) { |
59 indent_spaces+=indent_level; |
77 indent_spaces+=indent_level; |
60 } |
78 } |
66 indent_spaces.erase(); |
84 indent_spaces.erase(); |
67 } |
85 } |
68 |
86 |
69 |
87 |
70 void *stage4out_c::print(const char *str) { |
88 void *stage4out_c::print(const char *str) { |
71 std::cout << str; |
89 *out << str; |
72 return NULL; |
90 return NULL; |
73 } |
91 } |
74 |
92 |
75 |
93 |
76 void *stage4out_c::printupper(const char *str) { |
94 void *stage4out_c::printupper(const char *str) { |
77 for (int i = 0; str[i] != '\0'; i++) |
95 for (int i = 0; str[i] != '\0'; i++) |
78 std::cout << (unsigned char)toupper(str[i]); |
96 *out << (unsigned char)toupper(str[i]); |
79 return NULL; |
97 return NULL; |
80 } |
98 } |
81 |
99 |
82 void *stage4out_c::printlocation(const char *str) { |
100 void *stage4out_c::printlocation(const char *str) { |
83 std::cout << "__"; |
101 *out << "__"; |
84 for (int i = 0; str[i] != '\0'; i++) |
102 for (int i = 0; str[i] != '\0'; i++) |
85 if(str[i] == '.') |
103 if(str[i] == '.') |
86 std::cout << '_'; |
104 *out << '_'; |
87 else |
105 else |
88 std::cout << (unsigned char)toupper(str[i]); |
106 *out << (unsigned char)toupper(str[i]); |
89 return NULL; |
107 return NULL; |
90 } |
108 } |
91 |
109 |
92 void *stage4out_c::print(std::string str) { |
110 void *stage4out_c::print(std::string str) { |
93 std::cout << str; |
111 *out << str; |
94 return NULL; |
112 return NULL; |
95 } |
113 } |
96 |
114 |
97 |
115 |
98 void *stage4out_c::printupper(std::string str) { |
116 void *stage4out_c::printupper(std::string str) { |
100 * We have to do it ourselves, a character at a time... |
118 * We have to do it ourselves, a character at a time... |
101 */ |
119 */ |
102 #if 0 |
120 #if 0 |
103 /* The C++ way of doint things... */ |
121 /* The C++ way of doint things... */ |
104 for (string::const_iterator p = str.begin(); p != str.end(); ++p) |
122 for (string::const_iterator p = str.begin(); p != str.end(); ++p) |
105 std::cout << (unsigned char)toupper(*p); |
123 *out << (unsigned char)toupper(*p); |
106 #else |
124 #else |
107 /* Or more simply... */ |
125 /* Or more simply... */ |
108 printupper(str.c_str()); |
126 printupper(str.c_str()); |
109 #endif |
127 #endif |
110 return NULL; |
128 return NULL; |
111 } |
129 } |
112 void *stage4out_c::printlocation(std::string str) { |
130 void *stage4out_c::printlocation(std::string str) { |
113 printlocation(str.c_str()); |
131 return printlocation(str.c_str()); |
114 } |
132 } |
115 |
133 |
116 |
134 |
117 /***********************************************************************/ |
135 /***********************************************************************/ |
118 /***********************************************************************/ |
136 /***********************************************************************/ |