1
2 #include "studiox_includes.h"
3
4 #ifdef _DEBUG
5 #define new DEBUG_NEW
6 #endif
7
8 #define COMMENT_START_COLUMN 45
9 #define COMMENT_END_COLUMN 80
10 extern CString studiox_version_string;
11
12 CString CommentBlockEnd(""
13 "/*******************************************************************************/\n"
14 "\n\n"
15 );
16
17
WriteCommentBlock(CString & comment)18 void studio_source_writer::WriteCommentBlock(CString &comment)
19 {
20 CString out;
21 time_t osTime;
22 time(&osTime);
23 CTime time(osTime);
24
25 FileWrite(comment);
26
27 out.Format(_T("/* GUIX Studio Revision %s */\n"), studiox_version_string);
28 FileWrite(out);
29
30 out.Format(_T("/* Date (dd.mm.yyyy): %2d.%2d.%4d Time (hh:mm): %02d:%02d */\n"),
31 time.GetDay(), time.GetMonth(), time.GetYear(), time.GetHour(), time.GetMinute());
32 FileWrite(out);
33
34 FileWrite(CommentBlockEnd);
35 }
36
FileWrite(CString & out)37 void studio_source_writer::FileWrite(CString &out)
38 {
39 CString copy(out);
40 CString line;
41 CString formatted;
42 BOOL AddLineEnd;
43
44 while(1)
45 {
46 if (copy.IsEmpty())
47 {
48 return;
49 }
50
51 int newline = copy.Find('\n');
52
53 if (newline == 0)
54 {
55 m_outfile->Write("\r\n", 2);
56 copy = copy.Mid(1);
57 continue;
58 }
59
60 if (newline > 0)
61 {
62 line = copy.Left(newline);
63 copy = copy.Mid(newline + 1);
64 AddLineEnd = TRUE;
65 }
66 else
67 {
68 line = copy;
69 copy.Empty();
70 AddLineEnd = FALSE;
71 }
72
73 formatted = line;
74 int index = line.Find(_T("/*"));
75 int space;
76
77 if (index > 2 && index < COMMENT_START_COLUMN)
78 {
79 formatted = line.Left(index);
80 space = index;
81
82 while(space < COMMENT_START_COLUMN)
83 {
84 formatted += " ";
85 space++;
86 }
87
88 formatted += line.Mid(index);
89 }
90
91 line = formatted;
92 index = line.Find(_T("*/"));
93
94 if (index > 0 && index < (COMMENT_END_COLUMN - 1))
95 {
96 formatted = line.Left(index);
97 space = index;
98
99 while(space < (COMMENT_END_COLUMN - 1))
100 {
101 formatted += " ";
102 space++;
103 }
104
105 formatted += line.Mid(index);
106 }
107 if (AddLineEnd)
108 {
109 formatted += "\r\n";
110 }
111
112 m_outfile->Write(CT2A(formatted.GetString()), formatted.GetLength());
113 }
114 }
115
FileWrite(const void * lpBuf,UINT nCount)116 void studio_source_writer::FileWrite(const void *lpBuf, UINT nCount)
117 {
118 m_outfile->Write(lpBuf, nCount);
119 }
120
BlankLine()121 void studio_source_writer::BlankLine()
122 {
123 FileWrite(CString("\n"));
124 }
125
WriteComment(char * comment)126 void studio_source_writer::WriteComment(char *comment)
127 {
128 CString out("\n/* ");
129 out += CString(comment);
130 out += CString(" */\n\n");
131 FileWrite(out);
132 }
133
WriteAdditionalHeaders(CString & headers)134 void studio_source_writer::WriteAdditionalHeaders(CString &headers)
135 {
136 int index;
137 CString str = headers;
138 CString one_header;
139
140 while (!str.IsEmpty())
141 {
142 index = str.Find(_T(";"));
143
144 if (index < 0)
145 {
146 index = str.GetLength();
147 }
148
149 one_header = str.Left(index);
150 str = str.Mid(index + 1);
151
152 while (one_header.GetAt(0) == ' ')
153 {
154 one_header = one_header.Mid(1);
155 }
156
157 while (one_header.GetAt(one_header.GetLength() - 1) == ' ')
158 {
159 one_header = one_header.Left(one_header.GetLength() - 1);
160 }
161
162 CString write;
163 write.Format(CString("#include \"%s\"\n"), one_header);
164 FileWrite(write);
165 }
166 }