source: uKadecot/trunk/ssp/syssvc/log_output.c@ 101

Last change on this file since 101 was 101, checked in by coas-nagasima, 8 years ago

TOPPERS/uKadecotのソースコードを追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/plain
File size: 5.1 KB
Line 
1/*
2 * TOPPERS Software
3 * Toyohashi Open Platform for Embedded Real-Time Systems
4 *
5 * Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory
6 * Toyohashi Univ. of Technology, JAPAN
7 * Copyright (C) 2004-2008 by Embedded and Real-Time Systems Laboratory
8 * Graduate School of Information Science, Nagoya Univ., JAPAN
9 * Copyright (C) 2015 by Naoki Saito
10 * Nagoya Municipal Industrial Research Institute, JAPAN
11 *
12 * ã‹L’˜ìŒ ŽÒ‚́CˆÈ‰º‚Ì(1)`(4)‚ÌðŒ‚ð–ž‚½‚·ê‡‚ÉŒÀ‚èC–{ƒ\ƒtƒgƒEƒF
13 * ƒAi–{ƒ\ƒtƒgƒEƒFƒA‚ð‰ü•Ï‚µ‚½‚à‚Ì‚ðŠÜ‚ށDˆÈ‰º“¯‚¶j‚ðŽg—pE•¡»E‰ü
14 * •ÏEÄ”z•ziˆÈ‰ºC—˜—p‚ƌĂԁj‚·‚邱‚Ƃ𖳏ž‚Å‹–‘ø‚·‚éD
15 * (1) –{ƒ\ƒtƒgƒEƒFƒA‚ðƒ\[ƒXƒR[ƒh‚ÌŒ`‚Å—˜—p‚·‚éê‡‚ɂ́Cã‹L‚Ì’˜ì
16 * Œ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’肪C‚»‚Ì‚Ü‚Ü‚ÌŒ`‚Ń\[
17 * ƒXƒR[ƒh’†‚ÉŠÜ‚Ü‚ê‚Ä‚¢‚邱‚ƁD
18 * (2) –{ƒ\ƒtƒgƒEƒFƒA‚ðCƒ‰ƒCƒuƒ‰ƒŠŒ`Ž®‚ȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
19 * —p‚Å‚«‚éŒ`‚ōĔz•z‚·‚éê‡‚ɂ́CÄ”z•z‚É”º‚¤ƒhƒLƒ…
20ƒƒ“ƒgi—˜—p
21 * ŽÒƒ}ƒjƒ…
22ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L
23 * ‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
24 * (3) –{ƒ\ƒtƒgƒEƒFƒA‚ðC‹@Ší‚É‘g‚ݍž‚ނȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
25 * —p‚Å‚«‚È‚¢Œ`‚ōĔz•z‚·‚éê‡‚ɂ́CŽŸ‚Ì‚¢‚¸‚ê‚©‚ÌðŒ‚ð–ž‚½‚·‚±
26 * ‚ƁD
27 * (a) Ä”z•z‚É”º‚¤ƒhƒLƒ…
28ƒƒ“ƒgi—˜—pŽÒƒ}ƒjƒ…
29ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜
30 * ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
31 * (b) Ä”z•z‚ÌŒ`‘Ô‚ðC•Ê‚É’è‚ß‚é•û–@‚É‚æ‚Á‚āCTOPPERSƒvƒƒWƒFƒNƒg‚É
32 * •ñ‚·‚邱‚ƁD
33 * (4) –{ƒ\ƒtƒgƒEƒFƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚é‚¢‚©‚Ȃ鑹
34 * ŠQ‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð–Ɛӂ·‚邱‚ƁD
35 * ‚Ü‚½C–{ƒ\ƒtƒgƒEƒFƒA‚̃†[ƒU‚Ü‚½‚̓Gƒ“ƒhƒ†[ƒU‚©‚ç‚Ì‚¢‚©‚Ȃ闝
36 * —R‚ÉŠî‚­¿‹‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð
37 * –Ɛӂ·‚邱‚ƁD
38 *
39 * –{ƒ\ƒtƒgƒEƒFƒA‚́C–³•ÛØ‚Å’ñ‹Ÿ‚³‚ê‚Ä‚¢‚é‚à‚Ì‚Å‚ ‚éDã‹L’˜ìŒ ŽÒ‚¨
40 * ‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚́C–{ƒ\ƒtƒgƒEƒFƒA‚ÉŠÖ‚µ‚āC“Á’è‚ÌŽg—p–Ú“I
41 * ‚ɑ΂·‚é“K‡«‚àŠÜ‚߂āC‚¢‚©‚È‚é•ÛØ‚às‚í‚È‚¢D‚Ü‚½C–{ƒ\ƒtƒgƒEƒF
42 * ƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚½‚¢‚©‚Ȃ鑹ŠQ‚ÉŠÖ‚µ‚Ä‚àC‚»
43 * ‚̐ӔC‚𕉂í‚È‚¢D
44 *
45 * @(#) $Id: log_output.c 101 2015-06-02 15:37:23Z coas-nagasima $
46 */
47
48/*
49 * ƒVƒXƒeƒ€ƒƒO‚̃tƒH[ƒ}ƒbƒgo—Í
50 */
51
52#include <t_stddef.h>
53#include <t_syslog.h>
54
55/*
56 * ”’l‚𕶎š—ñ‚É•ÏŠ·
57 */
58#define CONVERT_BUFLEN ((sizeof(uintptr_t) * CHAR_BIT + 2) / 3)
59 /* uintptr_tŒ^‚̐”’l‚̍ő啶Žš” */
60static void
61convert(uintptr_t val, uint_t radix, const char *radchar,
62 uint_t width, bool_t minus, bool_t padzero, void (*putc)(char))
63{
64 char buf[CONVERT_BUFLEN];
65 uint_t i, j;
66
67 i = 0U;
68 do {
69 buf[i++] = radchar[val % radix];
70 val /= radix;
71 } while (i < CONVERT_BUFLEN && val != 0);
72
73 if (minus && width > 0U) {
74 width -= 1U;
75 }
76 if (minus && padzero) {
77 (*putc)('-');
78 }
79 for (j = i; j < width; j++) {
80 (*putc)((char)(padzero ? '0' : ' '));
81 }
82 if (minus && !padzero) {
83 (*putc)('-');
84 }
85 while (i > 0U) {
86 (*putc)(buf[--i]);
87 }
88}
89
90/*
91 * •¶Žš—ñ®Œ`o—Í
92 */
93static const char raddec[] = "0123456789";
94static const char radhex[] = "0123456789abcdef";
95static const char radHEX[] = "0123456789ABCDEF";
96
97void
98syslog_printf(const char *format, const intptr_t *p_args, void (*putc)(char))
99{
100 char c;
101 uint_t width;
102 bool_t padzero;
103 intptr_t val;
104 const char *str;
105
106 while ((c = *format++) != '\0') {
107 if (c != '%') {
108 (*putc)(c);
109 continue;
110 }
111
112 width = 0U;
113 padzero = false;
114 if ((c = *format++) == '0') {
115 padzero = true;
116 c = *format++;
117 }
118 while ('0' <= c && c <= '9') {
119 width = width * 10U + c - '0';
120 c = *format++;
121 }
122 if (c == 'l') {
123 c = *format++;
124 }
125 switch (c) {
126 case 'd':
127 val = (intptr_t)(*p_args++);
128 if (val >= 0) {
129 convert((uintptr_t) val, 10U, raddec,
130 width, false, padzero, putc);
131 }
132 else {
133 convert((uintptr_t)(-val), 10U, raddec,
134 width, true, padzero, putc);
135 }
136 break;
137 case 'u':
138 val = (intptr_t)(*p_args++);
139 convert((uintptr_t) val, 10U, raddec, width, false, padzero, putc);
140 break;
141 case 'x':
142 case 'p':
143 val = (intptr_t)(*p_args++);
144 convert((uintptr_t) val, 16U, radhex, width, false, padzero, putc);
145 break;
146 case 'X':
147 val = (intptr_t)(*p_args++);
148 convert((uintptr_t) val, 16U, radHEX, width, false, padzero, putc);
149 break;
150 case 'c':
151 (*putc)((char)(intptr_t)(*p_args++));
152 break;
153 case 's':
154 str = (const char *)(*p_args++);
155 while ((c = *str++) != '\0') {
156 (*putc)(c);
157 }
158 break;
159 case '%':
160 (*putc)('%');
161 break;
162 case '\0':
163 format--;
164 break;
165 default:
166 break;
167 }
168 }
169}
170
171/*
172 * ƒƒOî•ñ‚̏o—Í
173 */
174void
175syslog_print(const SYSLOG *p_syslog, void (*putc)(char))
176{
177 switch (p_syslog->logtype) {
178 case LOG_TYPE_COMMENT:
179 syslog_printf((const char *)(p_syslog->loginfo[0]),
180 &(p_syslog->loginfo[1]), putc);
181 break;
182 case LOG_TYPE_ASSERT:
183 syslog_printf("%s:%u: Assertion `%s' failed.",
184 &(p_syslog->loginfo[0]), putc);
185 break;
186 default:
187 // •s–¾‚ÈŽí•Ê‚̏ꍇ‚́C‰½‚à‚µ‚È‚¢
188 break;
189 }
190}
191
192/*
193 * ƒƒOî•ñ‘rŽ¸ƒƒbƒZ[ƒW‚̏o—Í
194 */
195void
196syslog_lostmsg(uint_t lost, void (*putc)(char))
197{
198 intptr_t lostinfo[1];
199
200 lostinfo[0] = (intptr_t) lost;
201 syslog_printf("%d messages are lost.", lostinfo, putc);
202 (*putc)('\n');
203}
Note: See TracBrowser for help on using the repository browser.