FreeCalypso > hg > fc-magnetite
comparison src/gpf2/misc/printtofile.c @ 294:cd37d228dae0
src/gpf2/{misc,tst}: import from TCS211 semi-src
with CRLF line endings and directory name capitalization cleaned up
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 21 Oct 2017 01:12:15 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
293:5b2ebc94cae4 | 294:cd37d228dae0 |
---|---|
1 /* | |
2 +------------------------------------------------------------------------------ | |
3 | File: printToFile.c | |
4 +------------------------------------------------------------------------------ | |
5 | Copyright 2002 Texas Instruments Berlin, AG | |
6 | All rights reserved. | |
7 | | |
8 | This file is confidential and a trade secret of Texas | |
9 | Instruments Berlin, AG | |
10 | The receipt of or possession of this file does not convey | |
11 | any rights to reproduce or disclose its contents or to | |
12 | manufacture, use, or sell anything it may describe, in | |
13 | whole, or in part, without the specific written consent of | |
14 | Texas Instruments Berlin, AG. | |
15 +----------------------------------------------------------------------------- | |
16 | Purpose: This module implements some stream output functions. | |
17 +----------------------------------------------------------------------------- | |
18 */ | |
19 | |
20 #ifndef __PRINTTOFILE_C__ | |
21 #define __PRINTTOFILE_C__ | |
22 #endif | |
23 | |
24 #ifndef _TARGET_ | |
25 | |
26 /*==== INCLUDES ===================================================*/ | |
27 | |
28 #include "printtofile.h" | |
29 | |
30 #include "typedefs.h" | |
31 #ifndef _LINUX_ | |
32 #include <string.h> | |
33 #include <ctype.h> | |
34 #include <stdarg.h> | |
35 #include <stdio.h> | |
36 #include "windows.h" | |
37 #include "vsi.h" | |
38 #include "time.h" | |
39 #include <sys/types.h> | |
40 #include <sys/timeb.h> | |
41 #endif /* _LINUX_ */ | |
42 | |
43 /*==== TYPES ======================================================*/ | |
44 | |
45 | |
46 /*==== CONSTANTS ==================================================*/ | |
47 | |
48 | |
49 /*==== EXTERNALS ==================================================*/ | |
50 | |
51 | |
52 /*==== VARIABLES ==================================================*/ | |
53 | |
54 #ifndef _LINUX_ | |
55 static HANDLE mutEx; | |
56 #endif /* _LINUX_ */ | |
57 | |
58 /*==== FUNCTIONS ==================================================*/ | |
59 | |
60 #ifndef RUN_INT_RAM | |
61 /* | |
62 +------------------------------------------------------------------------------ | |
63 | Function : PrintToFile | |
64 +------------------------------------------------------------------------------ | |
65 | Description : print to file xx and do a printf() with ident. arguments | |
66 | | |
67 | Parameters : const char *format, ... variable parameter list | |
68 | | |
69 | Return : printf retval | |
70 | | |
71 +------------------------------------------------------------------------------ | |
72 */ | |
73 void initPrintToFile() | |
74 { | |
75 #ifdef _LINUX_ | |
76 return; | |
77 #else /* _LINUX_ */ | |
78 #ifndef _TARGET_ | |
79 #ifdef _DEBUG | |
80 FILE *fp; | |
81 #endif | |
82 | |
83 if ( (mutEx = OpenMutex (MUTEX_ALL_ACCESS, FALSE, "PrintToFile")) == NULL ) | |
84 { | |
85 mutEx = CreateMutex( NULL, FALSE, "PrintToFile"); | |
86 #ifdef _DEBUG | |
87 fp = fopen("\\gpf\\BIN\\debug\\tstlog.txt", "w"); | |
88 PrintToFile("\n\nStart logging:\n"); | |
89 #endif | |
90 } | |
91 | |
92 if (mutEx == 0) | |
93 { | |
94 printf("PrintToFile semaphore creation failed!\n"); | |
95 } | |
96 #endif /* _LINUX_ */ | |
97 #endif | |
98 } | |
99 #endif | |
100 | |
101 #ifndef RUN_INT_RAM | |
102 /* | |
103 +------------------------------------------------------------------------------ | |
104 | Function : PrintToFile | |
105 +------------------------------------------------------------------------------ | |
106 | Description : print to file xx and do a printf() with ident. arguments | |
107 | | |
108 | Parameters : const char *format, ... variable parameter list | |
109 | | |
110 | Return : printf retval | |
111 | | |
112 +------------------------------------------------------------------------------ | |
113 */ | |
114 int PrintToFile(const char *format, ... ) | |
115 { | |
116 int retval = 0; | |
117 #ifndef _LINUX_ | |
118 #ifndef _TARGET_ | |
119 va_list unamedArgumentList; | |
120 char* nextChar; | |
121 int ival; | |
122 char* sval; | |
123 #ifdef _DEBUG | |
124 FILE *fp; | |
125 struct _timeb timebuf; | |
126 time_t seconds; | |
127 unsigned long int t; | |
128 #endif | |
129 | |
130 if ( WaitForSingleObject (mutEx, INFINITE) == WAIT_FAILED ) | |
131 { | |
132 printf("PrintToFile semaphore request failed! Is TST.exe up & running?\n"); | |
133 return -1; | |
134 } | |
135 va_start(unamedArgumentList, format); | |
136 #ifdef _DEBUG | |
137 fp = fopen("\\gpf\\BIN\\debug\\tstlog.txt", "a"); | |
138 if ( fp != 0 ) | |
139 { | |
140 time( &seconds ); // seconds after 1.1.70 GMT | |
141 _ftime( &timebuf ); | |
142 t = (unsigned long int)(seconds * 1000) + timebuf.millitm; | |
143 | |
144 /*lint -e668 */ | |
145 /*lint -e559 */ | |
146 #ifdef _TOOLS_ | |
147 fprintf(fp, "TST (%u): ", (unsigned int)t); | |
148 #else | |
149 fprintf(fp, "Stack (%u): ", (unsigned int)t); | |
150 #endif | |
151 } | |
152 #endif /* _DEBUG */ | |
153 | |
154 /*lint -e662 */ | |
155 for (nextChar = (char*) format; *nextChar; nextChar++) | |
156 { | |
157 if (*nextChar != '%') | |
158 { | |
159 putchar(*nextChar); | |
160 #ifdef _DEBUG | |
161 if (fp != 0) | |
162 { | |
163 fputc(*nextChar,fp); | |
164 } | |
165 #endif | |
166 continue; | |
167 } | |
168 | |
169 switch (*++nextChar) | |
170 { | |
171 case 'd': | |
172 ival = va_arg(unamedArgumentList, int); | |
173 printf("%d", ival); | |
174 #ifdef _DEBUG | |
175 if (fp != 0) | |
176 { | |
177 fprintf(fp, "%d", ival); | |
178 } | |
179 #endif | |
180 break; | |
181 case 'x': | |
182 ival = va_arg(unamedArgumentList, int); | |
183 printf("%x", ival); | |
184 #ifdef _DEBUG | |
185 if (fp != 0) | |
186 { | |
187 fprintf(fp, "%x", ival); | |
188 } | |
189 #endif | |
190 break; | |
191 case 's': | |
192 for(sval = va_arg(unamedArgumentList, char*); *sval; sval++) | |
193 { | |
194 putchar(*sval); | |
195 #ifdef _DEBUG | |
196 if (fp != 0) | |
197 { | |
198 fputc(*sval,fp); | |
199 } | |
200 #endif | |
201 } | |
202 break; | |
203 default: | |
204 putchar(*nextChar); | |
205 #ifdef _DEBUG | |
206 if (fp != 0) | |
207 { | |
208 fputc(*nextChar,fp); | |
209 } | |
210 #endif | |
211 break; | |
212 } | |
213 } | |
214 /*lint +e662 */ | |
215 va_end(unamedArgumentList); | |
216 #ifdef _DEBUG | |
217 if (fp != 0) | |
218 { | |
219 fclose(fp); | |
220 } | |
221 #endif | |
222 ReleaseMutex(mutEx); | |
223 #endif /* !_LINUX_ */ | |
224 #endif /* _TARGET_ */ | |
225 return retval; | |
226 } | |
227 #endif | |
228 #endif |