-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrint.c
More file actions
217 lines (182 loc) · 4.81 KB
/
Print.c
File metadata and controls
217 lines (182 loc) · 4.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
////////////////////////////////////////////////////////////////////////////////
//
// Global including files.
//
// Including the files for the system.
//
// These including files are generally used in different operation system.
//
////////////////////////////////////////////////////////////////////////////////
#include "Global.h"
////////////////////////////////////////////////////////////////////////////////
//
// Special including files.
//
// Including the files for the specifal operation system.
//
// These including files are used for the specifal operation system.
//
////////////////////////////////////////////////////////////////////////////////
//ANSI C standard.
#include <stdarg.h>
////////////////////////////////////////////////////////////////////////////////
//
// Defination for end of a line.
//
// Different system has different defination for end of a line.
//
////////////////////////////////////////////////////////////////////////////////
//For windows.
#ifdef _MICROSOFT_WINDOWS
#define END_OF_LINE "\r\n"
#endif
//For linux.
#ifdef _REDHAT_LINUX
#define END_OF_LINE "\n"
#endif
//For machintosh
#ifdef _MACHINTOSH_MAC_OS
#define END_OF_LINE "\r"
#endif
////////////////////////////////////////////////////////////////////////////////
//
// Print.
//
////////////////////////////////////////////////////////////////////////////////
_INT32 Print(FILE* lpFile,_STRING lpstrFormat,...)
{
//Size.
_INT32 nSize = 0;
//Parameter list.
va_list argp;
#ifdef _DEBUG
assert(lpFile != NULL && lpstrFormat != NULL);
#endif
//Initialize variable arguments.
va_start(argp,lpstrFormat);
//Print variable arguments.
nSize = vfprintf(lpFile,lpstrFormat,argp);
//Reset variable arguments.
va_end(argp);
//Return size.
return nSize;
}
////////////////////////////////////////////////////////////////////////////////
//
// Print line.
//
////////////////////////////////////////////////////////////////////////////////
_INT32 PrintLine(FILE* lpFile,_STRING lpstrFormat,...)
{
//Size.
_INT32 nSize = 0;
//Parameter list.
va_list argp;
#ifdef _DEBUG
assert(lpFile != NULL && lpstrFormat != NULL);
#endif
//Initialize variable arguments.
va_start(argp,lpstrFormat);
//Print variable arguments.
nSize = vfprintf(lpFile,lpstrFormat,argp);
//Reset variable arguments.
va_end(argp);
//Print end of line.
fprintf(lpFile,END_OF_LINE);
//Return size.
return nSize;
}
////////////////////////////////////////////////////////////////////////////////
//
// Format.
//
////////////////////////////////////////////////////////////////////////////////
_STRING Format(_STRING lpstrContent,_STRING lpstrFormat,...)
{
//Parameter list.
va_list argp;
#ifdef _DEBUG
assert(lpstrContent != NULL && lpstrFormat != NULL);
#endif
//Initialize variable arguments.
va_start(argp,lpstrFormat);
//Format variable arguments.
vsprintf(lpstrContent,lpstrFormat,argp);
//Reset variable arguments.
va_end(argp);
//Move pointer.
lpstrContent += strlen(lpstrContent);
//Return pointer.
return lpstrContent;
}
////////////////////////////////////////////////////////////////////////////////
//
// Format line.
//
////////////////////////////////////////////////////////////////////////////////
_STRING FormatLine(_STRING lpstrContent,_STRING lpstrFormat,...)
{
//Parameter list.
va_list argp;
#ifdef _DEBUG
assert(lpstrContent != NULL && lpstrFormat != NULL);
#endif
//Initialize variable arguments.
va_start(argp,lpstrFormat);
//Format variable arguments.
vsprintf(lpstrContent,lpstrFormat,argp);
//Reset variable arguments.
va_end(argp);
//Format end of line.
strcat(lpstrContent,END_OF_LINE);
//Move pointer.
lpstrContent += strlen(lpstrContent);
//Return pointer.
return lpstrContent;
}
////////////////////////////////////////////////////////////////////////////////
//
// Is end with new line.
//
////////////////////////////////////////////////////////////////////////////////
_BOOL IsEndWithNewLine(_STRING lpstrContent)
{
#ifdef _DEBUG
assert(lpstrContent != NULL);
#endif
lpstrContent += strlen(lpstrContent) - sizeof(END_OF_LINE);
//Check end with new line.
if(strncmp(lpstrContent,END_OF_LINE,sizeof(END_OF_LINE)) == 0)
{
return _TRUE;
}
return _FALSE;
}
////////////////////////////////////////////////////////////////////////////////
//
// Clear end with new line.
//
////////////////////////////////////////////////////////////////////////////////
void ClearEndWithNewLine(_STRING lpstrContent)
{
_STRING lpstrEnd;
#ifdef _DEBUG
assert(lpstrContent != NULL);
#endif
//Move to end.
lpstrEnd = lpstrContent + strlen(lpstrContent);
//Check result.
while(lpstrEnd > lpstrContent)
{
//Backward.
lpstrEnd -= strlen(END_OF_LINE);
//Check end with new line.
if(strncmp(lpstrEnd,END_OF_LINE,strlen(END_OF_LINE)) != 0)
{
//Break.
break;
}
//Set end of line.
*lpstrEnd = '\0';
}
}