Subversion Repositories HelenOS-historic

Rev

Rev 1604 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1604 Rev 1702
1
/*
1
/*
2
 * Copyright (C) 2001-2004 Jakub Jermar
2
 * Copyright (C) 2001-2004 Jakub Jermar
3
 * Copyright (C) 2006 Josef Cejka
3
 * Copyright (C) 2006 Josef Cejka
4
 * All rights reserved.
4
 * All rights reserved.
5
 *
5
 *
6
 * Redistribution and use in source and binary forms, with or without
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions
7
 * modification, are permitted provided that the following conditions
8
 * are met:
8
 * are met:
9
 *
9
 *
10
 * - Redistributions of source code must retain the above copyright
10
 * - Redistributions of source code must retain the above copyright
11
 *   notice, this list of conditions and the following disclaimer.
11
 *   notice, this list of conditions and the following disclaimer.
12
 * - Redistributions in binary form must reproduce the above copyright
12
 * - Redistributions in binary form must reproduce the above copyright
13
 *   notice, this list of conditions and the following disclaimer in the
13
 *   notice, this list of conditions and the following disclaimer in the
14
 *   documentation and/or other materials provided with the distribution.
14
 *   documentation and/or other materials provided with the distribution.
15
 * - The name of the author may not be used to endorse or promote products
15
 * - The name of the author may not be used to endorse or promote products
16
 *   derived from this software without specific prior written permission.
16
 *   derived from this software without specific prior written permission.
17
 *
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 */
28
 */
29
 
29
 
-
 
30
 /** @addtogroup generic   
-
 
31
 * @{
-
 
32
 */
30
/**
33
/**
31
 * @file    print.c
34
 * @file
32
 * @brief   Printing functions.
35
 * @brief   Printing functions.
33
 */
36
 */
34
 
37
 
35
#include <printf/printf_core.h>
38
#include <printf/printf_core.h>
36
#include <putchar.h>
39
#include <putchar.h>
37
#include <print.h>
40
#include <print.h>
38
#include <synch/spinlock.h>
41
#include <synch/spinlock.h>
39
#include <arch/arg.h>
42
#include <arch/arg.h>
40
#include <arch/asm.h>
43
#include <arch/asm.h>
41
 
44
 
42
#include <arch.h>
45
#include <arch.h>
43
 
46
 
44
SPINLOCK_INITIALIZE(printflock);            /**< printf spinlock */
47
SPINLOCK_INITIALIZE(printflock);            /**< printf spinlock */
45
 
48
 
46
#define __PRINTF_FLAG_PREFIX        0x00000001  /**< show prefixes 0x or 0*/
49
#define __PRINTF_FLAG_PREFIX        0x00000001  /**< show prefixes 0x or 0*/
47
#define __PRINTF_FLAG_SIGNED        0x00000002  /**< signed / unsigned number */
50
#define __PRINTF_FLAG_SIGNED        0x00000002  /**< signed / unsigned number */
48
#define __PRINTF_FLAG_ZEROPADDED    0x00000004  /**< print leading zeroes */
51
#define __PRINTF_FLAG_ZEROPADDED    0x00000004  /**< print leading zeroes */
49
#define __PRINTF_FLAG_LEFTALIGNED   0x00000010  /**< align to left */
52
#define __PRINTF_FLAG_LEFTALIGNED   0x00000010  /**< align to left */
50
#define __PRINTF_FLAG_SHOWPLUS      0x00000020  /**< always show + sign */
53
#define __PRINTF_FLAG_SHOWPLUS      0x00000020  /**< always show + sign */
51
#define __PRINTF_FLAG_SPACESIGN     0x00000040  /**< print space instead of plus */
54
#define __PRINTF_FLAG_SPACESIGN     0x00000040  /**< print space instead of plus */
52
#define __PRINTF_FLAG_BIGCHARS      0x00000080  /**< show big characters */
55
#define __PRINTF_FLAG_BIGCHARS      0x00000080  /**< show big characters */
53
#define __PRINTF_FLAG_NEGATIVE      0x00000100  /**< number has - sign */
56
#define __PRINTF_FLAG_NEGATIVE      0x00000100  /**< number has - sign */
54
 
57
 
55
#define PRINT_NUMBER_BUFFER_SIZE    (64+5)      /**< Buffer big enought for 64 bit number
58
#define PRINT_NUMBER_BUFFER_SIZE    (64+5)      /**< Buffer big enought for 64 bit number
56
                             * printed in base 2, sign, prefix and
59
                             * printed in base 2, sign, prefix and
57
                             * 0 to terminate string.. (last one is only for better testing
60
                             * 0 to terminate string.. (last one is only for better testing
58
                             * end of buffer by zero-filling subroutine)*/
61
                             * end of buffer by zero-filling subroutine)*/
59
 
62
 
60
/** Enumeration of possible arguments types.
63
/** Enumeration of possible arguments types.
61
 */
64
 */
62
typedef enum {
65
typedef enum {
63
    PrintfQualifierByte = 0,
66
    PrintfQualifierByte = 0,
64
    PrintfQualifierShort,
67
    PrintfQualifierShort,
65
    PrintfQualifierInt,
68
    PrintfQualifierInt,
66
    PrintfQualifierLong,
69
    PrintfQualifierLong,
67
    PrintfQualifierLongLong,
70
    PrintfQualifierLongLong,
68
    PrintfQualifierNative,
71
    PrintfQualifierNative,
69
    PrintfQualifierPointer
72
    PrintfQualifierPointer
70
} qualifier_t;
73
} qualifier_t;
71
 
74
 
72
static char digits_small[] = "0123456789abcdef";    /**< Small hexadecimal characters */
75
static char digits_small[] = "0123456789abcdef";    /**< Small hexadecimal characters */
73
static char digits_big[] = "0123456789ABCDEF";  /**< Big hexadecimal characters */
76
static char digits_big[] = "0123456789ABCDEF";  /**< Big hexadecimal characters */
74
 
77
 
75
/** Checks c for a digit.
78
/** Checks c for a digit.
76
 * @param c One character.
79
 * @param c One character.
77
 * @return nonzero if c is from interval '0 to '9'.
80
 * @return nonzero if c is from interval '0 to '9'.
78
 */
81
 */
79
static inline int isdigit(int c)
82
static inline int isdigit(int c)
80
{
83
{
81
    return ((c >= '0' )&&( c <= '9'));
84
    return ((c >= '0' )&&( c <= '9'));
82
}
85
}
83
 
86
 
84
/** Compute length of given zero terminated string.
87
/** Compute length of given zero terminated string.
85
 * @param str Pointer to valid string.
88
 * @param str Pointer to valid string.
86
 * @return string length without trailing zero.
89
 * @return string length without trailing zero.
87
 */
90
 */
88
static __native strlen(const char *str)
91
static __native strlen(const char *str)
89
{
92
{
90
    __native counter = 0;
93
    __native counter = 0;
91
 
94
 
92
    while (str[counter] != 0) {
95
    while (str[counter] != 0) {
93
        counter++;
96
        counter++;
94
    }
97
    }
95
 
98
 
96
    return counter;
99
    return counter;
97
}
100
}
98
 
101
 
99
/** Print count chars from buffer without adding newline
102
/** Print count chars from buffer without adding newline
100
 * @param buf Buffer with size at least count bytes - NULL pointer NOT allowed!
103
 * @param buf Buffer with size at least count bytes - NULL pointer NOT allowed!
101
 * @param count
104
 * @param count
102
 * @param ps output method and its data
105
 * @param ps output method and its data
103
 * @return number or printed characters
106
 * @return number of printed characters
104
 */
107
 */
105
static int printf_putnchars(const char * buf, size_t count, struct printf_spec *ps)
108
static int printf_putnchars(const char * buf, size_t count, struct printf_spec *ps)
106
{
109
{
107
    return ps->write((void *)buf, count, ps->data);
110
    return ps->write((void *)buf, count, ps->data);
108
}
111
}
109
 
112
 
110
/** Print string without added newline
113
/** Print string without added newline
111
 * @param str string to print
114
 * @param str string to print
112
 * @param ps write function specification and support data
115
 * @param ps write function specification and support data
113
 * @return number or printed characters
116
 * @return number of printed characters
114
 */
117
 */
115
static int printf_putstr(const char * str, struct printf_spec *ps)
118
static int printf_putstr(const char * str, struct printf_spec *ps)
116
{
119
{
117
    size_t count;
120
    size_t count;
118
   
121
   
119
    if (str == NULL) {
122
    if (str == NULL) {
120
        return printf_putnchars("(NULL)", 6, ps);
123
        return printf_putnchars("(NULL)", 6, ps);
121
    }
124
    }
122
 
125
 
123
    count = strlen(str);
126
    count = strlen(str);
124
 
127
 
125
    return ps->write((void *) str, count, ps->data);
128
    return ps->write((void *) str, count, ps->data);
126
}
129
}
127
 
130
 
128
/** Print one character to output
131
/** Print one character to output
129
 * @param c one character
132
 * @param c one character
130
 * @param ps output method
133
 * @param ps output method
131
 * @return number or printed characters
134
 * @return number of printed characters
132
 */
135
 */
133
static int printf_putchar(int c, struct printf_spec *ps)
136
static int printf_putchar(int c, struct printf_spec *ps)
134
{
137
{
135
    unsigned char ch = c;
138
    unsigned char ch = c;
136
   
139
   
137
    return ps->write((void *) &ch, 1, ps->data);
140
    return ps->write((void *) &ch, 1, ps->data);
138
}
141
}
139
 
142
 
140
/** Print one formatted character
143
/** Print one formatted character
141
 * @param c character to print
144
 * @param c character to print
142
 * @param width
145
 * @param width
143
 * @param flags
146
 * @param flags
144
 * @return number of printed characters, negative value on fail
147
 * @return number of printed characters, negative value on fail
145
 */
148
 */
146
static int print_char(char c, int width, __u64 flags, struct printf_spec *ps)
149
static int print_char(char c, int width, __u64 flags, struct printf_spec *ps)
147
{
150
{
148
    int counter = 0;
151
    int counter = 0;
149
   
152
   
150
    if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) {
153
    if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) {
151
        while (--width > 0) {   /* one space is consumed by character itself hence predecrement */
154
        while (--width > 0) {   /* one space is consumed by character itself hence predecrement */
152
            /* FIXME: painful slow */
-
 
153
            if (printf_putchar(' ', ps) > 0)   
155
            if (printf_putchar(' ', ps) > 0)   
154
                ++counter;
156
                ++counter;
155
        }
157
        }
156
    }
158
    }
157
   
159
   
158
    if (printf_putchar(c, ps) > 0)
160
    if (printf_putchar(c, ps) > 0)
159
        counter++;
161
        counter++;
160
 
162
 
161
    while (--width > 0) { /* one space is consumed by character itself hence predecrement */
163
    while (--width > 0) { /* one space is consumed by character itself hence predecrement */
162
        if (printf_putchar(' ', ps) > 0)
164
        if (printf_putchar(' ', ps) > 0)
163
            ++counter;
165
            ++counter;
164
    }
166
    }
165
   
167
   
166
    return ++counter;
168
    return ++counter;
167
}
169
}
168
 
170
 
169
/** Print one string
171
/** Print one string
170
 * @param s string
172
 * @param s string
171
 * @param width
173
 * @param width
172
 * @param precision
174
 * @param precision
173
 * @param flags
175
 * @param flags
174
 * @return number of printed characters or negative value on fail
176
 * @return number of printed characters or negative value on fail
175
 */
177
 */
176
                       
178
                       
177
static int print_string(char *s, int width, int precision, __u64 flags, struct printf_spec *ps)
179
static int print_string(char *s, int width, int precision, __u64 flags, struct printf_spec *ps)
178
{
180
{
179
    int counter = 0;
181
    int counter = 0;
180
    size_t size;
182
    size_t size;
181
    int retval;
183
    int retval;
182
 
184
 
183
    if (s == NULL) {
185
    if (s == NULL) {
184
        return printf_putstr("(NULL)", ps);
186
        return printf_putstr("(NULL)", ps);
185
    }
187
    }
186
   
188
   
187
    size = strlen(s);
189
    size = strlen(s);
188
 
190
 
189
    /* print leading spaces */
191
    /* print leading spaces */
190
 
192
 
191
    if (precision == 0)
193
    if (precision == 0)
192
        precision = size;
194
        precision = size;
193
 
195
 
194
    width -= precision;
196
    width -= precision;
195
   
197
   
196
    if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) {
198
    if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) {
197
        while (width-- > 0) {  
199
        while (width-- > 0) {  
198
            if (printf_putchar(' ', ps) == 1)  
200
            if (printf_putchar(' ', ps) == 1)  
199
                counter++;
201
                counter++;
200
        }
202
        }
201
    }
203
    }
202
 
204
 
203
    while (precision > size) {
205
    while (precision > size) {
204
        precision--;
206
        precision--;
205
        if (printf_putchar(' ', ps) == 1)  
207
        if (printf_putchar(' ', ps) == 1)  
206
            ++counter;
208
            ++counter;
207
    }
209
    }
208
   
210
   
209
    if ((retval = printf_putnchars(s, precision, ps)) < 0) {
211
    if ((retval = printf_putnchars(s, precision, ps)) < 0) {
210
        return -counter;
212
        return -counter;
211
    }
213
    }
212
    counter += retval; 
214
    counter += retval; 
213
 
215
 
214
    while (width-- > 0) {
216
    while (width-- > 0) {
215
        if (printf_putchar(' ', ps) == 1)  
217
        if (printf_putchar(' ', ps) == 1)  
216
            ++counter;
218
            ++counter;
217
    }
219
    }
218
   
220
   
219
    return counter;
221
    return counter;
220
}
222
}
221
 
223
 
222
 
224
 
223
/** Print number in given base
225
/** Print number in given base
224
 *
226
 *
225
 * Print significant digits of a number in given
227
 * Print significant digits of a number in given
226
 * base.
228
 * base.
227
 *
229
 *
228
 * @param num  Number to print.
230
 * @param num  Number to print.
229
 * @param width
231
 * @param width
230
 * @param precision
232
 * @param precision
231
 * @param base Base to print the number in (should
233
 * @param base Base to print the number in (should
232
 *             be in range 2 .. 16).
234
 *             be in range 2 .. 16).
233
 * @param flags output modifiers
235
 * @param flags output modifiers
234
 * @return number of written characters or EOF
236
 * @return number of written characters or EOF
235
 *
237
 *
236
 */
238
 */
237
static int print_number(__u64 num, int width, int precision, int base , __u64 flags, struct printf_spec *ps)
239
static int print_number(__u64 num, int width, int precision, int base , __u64 flags, struct printf_spec *ps)
238
{
240
{
239
    char *digits = digits_small;
241
    char *digits = digits_small;
240
    char d[PRINT_NUMBER_BUFFER_SIZE];   /* this is good enough even for base == 2, prefix and sign */
242
    char d[PRINT_NUMBER_BUFFER_SIZE];   /* this is good enough even for base == 2, prefix and sign */
241
    char *ptr = &d[PRINT_NUMBER_BUFFER_SIZE - 1];
243
    char *ptr = &d[PRINT_NUMBER_BUFFER_SIZE - 1];
242
    int size = 0; /* size of number with all prefixes and signs */
244
    int size = 0; /* size of number with all prefixes and signs */
243
    int number_size; /* size of plain number */
245
    int number_size; /* size of plain number */
244
    char sgn;
246
    char sgn;
245
    int retval;
247
    int retval;
246
    int counter = 0;
248
    int counter = 0;
247
   
249
   
248
    if (flags & __PRINTF_FLAG_BIGCHARS)
250
    if (flags & __PRINTF_FLAG_BIGCHARS)
249
        digits = digits_big;   
251
        digits = digits_big;   
250
   
252
   
251
    *ptr-- = 0; /* Put zero at end of string */
253
    *ptr-- = 0; /* Put zero at end of string */
252
 
254
 
253
    if (num == 0) {
255
    if (num == 0) {
254
        *ptr-- = '0';
256
        *ptr-- = '0';
255
        size++;
257
        size++;
256
    } else {
258
    } else {
257
        do {
259
        do {
258
            *ptr-- = digits[num % base];
260
            *ptr-- = digits[num % base];
259
            size++;
261
            size++;
260
        } while (num /= base);
262
        } while (num /= base);
261
    }
263
    }
262
   
264
   
263
    number_size = size;
265
    number_size = size;
264
 
266
 
265
    /* Collect sum of all prefixes/signs/... to calculate padding and leading zeroes */
267
    /* Collect sum of all prefixes/signs/... to calculate padding and leading zeroes */
266
    if (flags & __PRINTF_FLAG_PREFIX) {
268
    if (flags & __PRINTF_FLAG_PREFIX) {
267
        switch(base) {
269
        switch(base) {
268
            case 2: /* Binary formating is not standard, but usefull */
270
            case 2: /* Binary formating is not standard, but usefull */
269
                size += 2;
271
                size += 2;
270
                break;
272
                break;
271
            case 8:
273
            case 8:
272
                size++;
274
                size++;
273
                break;
275
                break;
274
            case 16:
276
            case 16:
275
                size += 2;
277
                size += 2;
276
                break;
278
                break;
277
        }
279
        }
278
    }
280
    }
279
 
281
 
280
    sgn = 0;
282
    sgn = 0;
281
    if (flags & __PRINTF_FLAG_SIGNED) {
283
    if (flags & __PRINTF_FLAG_SIGNED) {
282
        if (flags & __PRINTF_FLAG_NEGATIVE) {
284
        if (flags & __PRINTF_FLAG_NEGATIVE) {
283
            sgn = '-';
285
            sgn = '-';
284
            size++;
286
            size++;
285
        } else if (flags & __PRINTF_FLAG_SHOWPLUS) {
287
        } else if (flags & __PRINTF_FLAG_SHOWPLUS) {
286
                sgn = '+';
288
                sgn = '+';
287
                size++;
289
                size++;
288
            } else if (flags & __PRINTF_FLAG_SPACESIGN) {
290
            } else if (flags & __PRINTF_FLAG_SPACESIGN) {
289
                    sgn = ' ';
291
                    sgn = ' ';
290
                    size++;
292
                    size++;
291
                }
293
                }
292
    }
294
    }
293
 
295
 
294
    if (flags & __PRINTF_FLAG_LEFTALIGNED) {
296
    if (flags & __PRINTF_FLAG_LEFTALIGNED) {
295
        flags &= ~__PRINTF_FLAG_ZEROPADDED;
297
        flags &= ~__PRINTF_FLAG_ZEROPADDED;
296
    }
298
    }
297
 
299
 
298
    /* if number is leftaligned or precision is specified then zeropadding is ignored */
300
    /* if number is leftaligned or precision is specified then zeropadding is ignored */
299
    if (flags & __PRINTF_FLAG_ZEROPADDED) {
301
    if (flags & __PRINTF_FLAG_ZEROPADDED) {
300
        if ((precision == 0) && (width > size)) {
302
        if ((precision == 0) && (width > size)) {
301
            precision = width - size + number_size;
303
            precision = width - size + number_size;
302
        }
304
        }
303
    }
305
    }
304
 
306
 
305
    /* print leading spaces */
307
    /* print leading spaces */
306
    if (number_size > precision) /* We must print whole number not only a part */
308
    if (number_size > precision) /* We must print whole number not only a part */
307
        precision = number_size;
309
        precision = number_size;
308
 
310
 
309
    width -= precision + size - number_size;
311
    width -= precision + size - number_size;
310
   
312
   
311
    if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) {
313
    if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) {
312
        while (width-- > 0) {  
314
        while (width-- > 0) {  
313
            if (printf_putchar(' ', ps) == 1)  
315
            if (printf_putchar(' ', ps) == 1)  
314
                counter++;
316
                counter++;
315
        }
317
        }
316
    }
318
    }
317
   
319
   
318
   
320
   
319
    /* print sign */
321
    /* print sign */
320
    if (sgn) {
322
    if (sgn) {
321
        if (printf_putchar(sgn, ps) == 1)
323
        if (printf_putchar(sgn, ps) == 1)
322
            counter++;
324
            counter++;
323
    }
325
    }
324
   
326
   
325
    /* print prefix */
327
    /* print prefix */
326
   
328
   
327
    if (flags & __PRINTF_FLAG_PREFIX) {
329
    if (flags & __PRINTF_FLAG_PREFIX) {
328
        switch(base) {
330
        switch(base) {
329
            case 2: /* Binary formating is not standard, but usefull */
331
            case 2: /* Binary formating is not standard, but usefull */
330
                if (printf_putchar('0', ps) == 1)
332
                if (printf_putchar('0', ps) == 1)
331
                    counter++;
333
                    counter++;
332
                if (flags & __PRINTF_FLAG_BIGCHARS) {
334
                if (flags & __PRINTF_FLAG_BIGCHARS) {
333
                    if (printf_putchar('B', ps) == 1)
335
                    if (printf_putchar('B', ps) == 1)
334
                        counter++;
336
                        counter++;
335
                } else {
337
                } else {
336
                    if (printf_putchar('b', ps) == 1)
338
                    if (printf_putchar('b', ps) == 1)
337
                        counter++;
339
                        counter++;
338
                }
340
                }
339
                break;
341
                break;
340
            case 8:
342
            case 8:
341
                if (printf_putchar('o', ps) == 1)
343
                if (printf_putchar('o', ps) == 1)
342
                    counter++;
344
                    counter++;
343
                break;
345
                break;
344
            case 16:
346
            case 16:
345
                if (printf_putchar('0', ps) == 1)
347
                if (printf_putchar('0', ps) == 1)
346
                    counter++;
348
                    counter++;
347
                if (flags & __PRINTF_FLAG_BIGCHARS) {
349
                if (flags & __PRINTF_FLAG_BIGCHARS) {
348
                    if (printf_putchar('X', ps) == 1)
350
                    if (printf_putchar('X', ps) == 1)
349
                        counter++;
351
                        counter++;
350
                } else {
352
                } else {
351
                    if (printf_putchar('x', ps) == 1)
353
                    if (printf_putchar('x', ps) == 1)
352
                        counter++;
354
                        counter++;
353
                }
355
                }
354
                break;
356
                break;
355
        }
357
        }
356
    }
358
    }
357
 
359
 
358
    /* print leading zeroes */
360
    /* print leading zeroes */
359
    precision -= number_size;
361
    precision -= number_size;
360
    while (precision-- > 0) {  
362
    while (precision-- > 0) {  
361
        if (printf_putchar('0', ps) == 1)
363
        if (printf_putchar('0', ps) == 1)
362
            counter++;
364
            counter++;
363
    }
365
    }
364
 
366
 
365
   
367
   
366
    /* print number itself */
368
    /* print number itself */
367
 
369
 
368
    if ((retval = printf_putstr(++ptr, ps)) > 0) {
370
    if ((retval = printf_putstr(++ptr, ps)) > 0) {
369
        counter += retval;
371
        counter += retval;
370
    }
372
    }
371
   
373
   
372
    /* print ending spaces */
374
    /* print ending spaces */
373
   
375
   
374
    while (width-- > 0) {  
376
    while (width-- > 0) {  
375
        if (printf_putchar(' ', ps) == 1)  
377
        if (printf_putchar(' ', ps) == 1)  
376
            counter++;
378
            counter++;
377
    }
379
    }
378
 
380
 
379
    return counter;
381
    return counter;
380
}
382
}
381
 
383
 
382
 
384
 
383
/** Print formatted string.
385
/** Print formatted string.
384
 *
386
 *
385
 * Print string formatted according to the fmt parameter
387
 * Print string formatted according to the fmt parameter
386
 * and variadic arguments. Each formatting directive
388
 * and variadic arguments. Each formatting directive
387
 * must have the following form:
389
 * must have the following form:
388
 *
390
 *
389
 *  \% [ FLAGS ] [ WIDTH ] [ .PRECISION ] [ TYPE ] CONVERSION
391
 *  \% [ FLAGS ] [ WIDTH ] [ .PRECISION ] [ TYPE ] CONVERSION
390
 *
392
 *
391
 * FLAGS:@n
393
 * FLAGS:@n
392
 *  - "#" Force to print prefix.
394
 *  - "#" Force to print prefix.
393
 *  For conversion \%o the prefix is 0, for %x and \%X prefixes are 0x and 0X
395
 *  For conversion \%o the prefix is 0, for %x and \%X prefixes are 0x and 0X
394
 *  and for conversion \%b the prefix is 0b.
396
 *  and for conversion \%b the prefix is 0b.
395
 *
397
 *
396
 *  - "-"   Align to left.
398
 *  - "-"   Align to left.
397
 *
399
 *
398
 *  - "+"   Print positive sign just as negative.
400
 *  - "+"   Print positive sign just as negative.
399
 *
401
 *
400
 *  - " "   If the printed number is positive and "+" flag is not set, print space in
402
 *  - " "   If the printed number is positive and "+" flag is not set, print space in
401
 *  place of sign.
403
 *  place of sign.
402
 *
404
 *
403
 *  - "0"   Print 0 as padding instead of spaces. Zeroes are placed between sign and the
405
 *  - "0"   Print 0 as padding instead of spaces. Zeroes are placed between sign and the
404
 *  rest of the number. This flag is ignored if "-" flag is specified.
406
 *  rest of the number. This flag is ignored if "-" flag is specified.
405
 *
407
 *
406
 * WIDTH:@n
408
 * WIDTH:@n
407
 *  - Specify minimal width of printed argument. If it is bigger, width is ignored.
409
 *  - Specify minimal width of printed argument. If it is bigger, width is ignored.
408
 * If width is specified with a "*" character instead of number, width is taken from
410
 * If width is specified with a "*" character instead of number, width is taken from
409
 * parameter list. And integer parameter is expected before parameter for processed
411
 * parameter list. And integer parameter is expected before parameter for processed
410
 * conversion specification. If this value is negative its absolute value is taken
412
 * conversion specification. If this value is negative its absolute value is taken
411
 * and the "-" flag is set.
413
 * and the "-" flag is set.
412
 *
414
 *
413
 * PRECISION:@n
415
 * PRECISION:@n
414
 *  - Value precision. For numbers it specifies minimum valid numbers.
416
 *  - Value precision. For numbers it specifies minimum valid numbers.
415
 * Smaller numbers are printed with leading zeroes. Bigger numbers are not affected.
417
 * Smaller numbers are printed with leading zeroes. Bigger numbers are not affected.
416
 * Strings with more than precision characters are cut off.
418
 * Strings with more than precision characters are cut off.
417
 * Just as with width, an "*" can be used used instead of a number.
419
 * Just as with width, an "*" can be used used instead of a number.
418
 * An integer value is then expected in parameters. When both width and precision
420
 * An integer value is then expected in parameters. When both width and precision
419
 * are specified using "*", the first parameter is used for width and the second one
421
 * are specified using "*", the first parameter is used for width and the second one
420
 * for precision.
422
 * for precision.
421
 *
423
 *
422
 * TYPE:@n
424
 * TYPE:@n
423
 *  - "hh"  Signed or unsigned char.@n
425
 *  - "hh"  Signed or unsigned char.@n
424
 *  - "h"   Signed or usigned short.@n
426
 *  - "h"   Signed or usigned short.@n
425
 *  - ""    Signed or usigned int (default value).@n
427
 *  - ""    Signed or usigned int (default value).@n
426
 *  - "l"   Signed or usigned long int.@n
428
 *  - "l"   Signed or usigned long int.@n
427
 *  - "ll"  Signed or usigned long long int.@n
429
 *  - "ll"  Signed or usigned long long int.@n
428
 *  - "z"   __native (non-standard extension).@n
430
 *  - "z"   __native (non-standard extension).@n
429
 *
431
 *
430
 *
432
 *
431
 * CONVERSION:@n
433
 * CONVERSION:@n
432
 *  - % Print percentile character itself.
434
 *  - % Print percentile character itself.
433
 *
435
 *
434
 *  - c Print single character.
436
 *  - c Print single character.
435
 *
437
 *
436
 *  - s Print zero terminated string. If a NULL value is passed as value, "(NULL)" is printed instead.
438
 *  - s Print zero terminated string. If a NULL value is passed as value, "(NULL)" is printed instead.
437
 *
439
 *
438
 *  - P, p  Print value of a pointer. Void * value is expected and it is printed in hexadecimal notation with prefix
440
 *  - P, p  Print value of a pointer. Void * value is expected and it is printed in hexadecimal notation with prefix
439
 *  (as with \%#X or \%#x for 32bit or \%#X / \%#x for 64bit long pointers).
441
 *  (as with \%#X or \%#x for 32bit or \%#X / \%#x for 64bit long pointers).
440
 *
442
 *
441
 *  - b Print value as unsigned binary number. Prefix is not printed by default. (Nonstandard extension.)
443
 *  - b Print value as unsigned binary number. Prefix is not printed by default. (Nonstandard extension.)
442
 *
444
 *
443
 *  - o Print value as unsigned octal number. Prefix is not printed by default.
445
 *  - o Print value as unsigned octal number. Prefix is not printed by default.
444
 *
446
 *
445
 *  - d,i   Print signed decimal number. There is no difference between d and i conversion.
447
 *  - d,i   Print signed decimal number. There is no difference between d and i conversion.
446
 *
448
 *
447
 *  - u Print unsigned decimal number.
449
 *  - u Print unsigned decimal number.
448
 *
450
 *
449
 *  - X, x  Print hexadecimal number with upper- or lower-case. Prefix is not printed by default.
451
 *  - X, x  Print hexadecimal number with upper- or lower-case. Prefix is not printed by default.
450
 *
452
 *
451
 * All other characters from fmt except the formatting directives
453
 * All other characters from fmt except the formatting directives
452
 * are printed in verbatim.
454
 * are printed in verbatim.
453
 *
455
 *
454
 * @param fmt Formatting NULL terminated string.
456
 * @param fmt Formatting NULL terminated string.
455
 * @return Number of printed characters or negative value on failure.
457
 * @return Number of printed characters or negative value on failure.
456
 */
458
 */
457
int printf_core(const char *fmt, struct printf_spec *ps, va_list ap)
459
int printf_core(const char *fmt, struct printf_spec *ps, va_list ap)
458
{
460
{
459
    int irqpri;
461
    int irqpri;
460
    int i = 0, j = 0; /**< i is index of currently processed char from fmt, j is index to the first not printed nonformating character */
462
    int i = 0, j = 0; /**< i is index of currently processed char from fmt, j is index to the first not printed nonformating character */
461
    int end;
463
    int end;
462
    int counter; /**< counter of printed characters */
464
    int counter; /**< counter of printed characters */
463
    int retval; /**< used to store return values from called functions */
465
    int retval; /**< used to store return values from called functions */
464
    char c;
466
    char c;
465
    qualifier_t qualifier;  /* type of argument */
467
    qualifier_t qualifier;  /* type of argument */
466
    int base;   /**< base in which will be parameter (numbers only) printed */
468
    int base;   /**< base in which will be parameter (numbers only) printed */
467
    __u64 number; /**< argument value */
469
    __u64 number; /**< argument value */
468
    size_t  size; /**< byte size of integer parameter */
470
    size_t  size; /**< byte size of integer parameter */
469
    int width, precision;
471
    int width, precision;
470
    __u64 flags;
472
    __u64 flags;
471
   
473
   
472
    counter = 0;
474
    counter = 0;
473
   
475
   
474
    irqpri = interrupts_disable();
476
    irqpri = interrupts_disable();
475
    spinlock_lock(&printflock);
477
    spinlock_lock(&printflock);
476
 
478
 
477
    while ((c = fmt[i])) {
479
    while ((c = fmt[i])) {
478
        /* control character */
480
        /* control character */
479
        if (c == '%' ) {
481
        if (c == '%' ) {
480
            /* print common characters if any processed */ 
482
            /* print common characters if any processed */ 
481
            if (i > j) {
483
            if (i > j) {
482
                if ((retval = printf_putnchars(&fmt[j], (size_t)(i - j), ps)) < 0) { /* error */
484
                if ((retval = printf_putnchars(&fmt[j], (size_t)(i - j), ps)) < 0) { /* error */
483
                    counter = -counter;
485
                    counter = -counter;
484
                    goto out;
486
                    goto out;
485
                }
487
                }
486
                counter += retval;
488
                counter += retval;
487
            }
489
            }
488
       
490
       
489
            j = i;
491
            j = i;
490
            /* parse modifiers */
492
            /* parse modifiers */
491
            flags = 0;
493
            flags = 0;
492
            end = 0;
494
            end = 0;
493
           
495
           
494
            do {
496
            do {
495
                ++i;
497
                ++i;
496
                switch (c = fmt[i]) {
498
                switch (c = fmt[i]) {
497
                    case '#': flags |= __PRINTF_FLAG_PREFIX; break;
499
                    case '#': flags |= __PRINTF_FLAG_PREFIX; break;
498
                    case '-': flags |= __PRINTF_FLAG_LEFTALIGNED; break;
500
                    case '-': flags |= __PRINTF_FLAG_LEFTALIGNED; break;
499
                    case '+': flags |= __PRINTF_FLAG_SHOWPLUS; break;
501
                    case '+': flags |= __PRINTF_FLAG_SHOWPLUS; break;
500
                    case ' ': flags |= __PRINTF_FLAG_SPACESIGN; break;
502
                    case ' ': flags |= __PRINTF_FLAG_SPACESIGN; break;
501
                    case '0': flags |= __PRINTF_FLAG_ZEROPADDED; break;
503
                    case '0': flags |= __PRINTF_FLAG_ZEROPADDED; break;
502
                    default: end = 1;
504
                    default: end = 1;
503
                }; 
505
                }; 
504
               
506
               
505
            } while (end == 0);
507
            } while (end == 0);
506
           
508
           
507
            /* width & '*' operator */
509
            /* width & '*' operator */
508
            width = 0;
510
            width = 0;
509
            if (isdigit(fmt[i])) {
511
            if (isdigit(fmt[i])) {
510
                while (isdigit(fmt[i])) {
512
                while (isdigit(fmt[i])) {
511
                    width *= 10;
513
                    width *= 10;
512
                    width += fmt[i++] - '0';
514
                    width += fmt[i++] - '0';
513
                }
515
                }
514
            } else if (fmt[i] == '*') {
516
            } else if (fmt[i] == '*') {
515
                /* get width value from argument list*/
517
                /* get width value from argument list*/
516
                i++;
518
                i++;
517
                width = (int)va_arg(ap, int);
519
                width = (int)va_arg(ap, int);
518
                if (width < 0) {
520
                if (width < 0) {
519
                    /* negative width means to set '-' flag */
521
                    /* negative width means to set '-' flag */
520
                    width *= -1;
522
                    width *= -1;
521
                    flags |= __PRINTF_FLAG_LEFTALIGNED;
523
                    flags |= __PRINTF_FLAG_LEFTALIGNED;
522
                }
524
                }
523
            }
525
            }
524
           
526
           
525
            /* precision and '*' operator */   
527
            /* precision and '*' operator */   
526
            precision = 0;
528
            precision = 0;
527
            if (fmt[i] == '.') {
529
            if (fmt[i] == '.') {
528
                ++i;
530
                ++i;
529
                if (isdigit(fmt[i])) {
531
                if (isdigit(fmt[i])) {
530
                    while (isdigit(fmt[i])) {
532
                    while (isdigit(fmt[i])) {
531
                        precision *= 10;
533
                        precision *= 10;
532
                        precision += fmt[i++] - '0';
534
                        precision += fmt[i++] - '0';
533
                    }
535
                    }
534
                } else if (fmt[i] == '*') {
536
                } else if (fmt[i] == '*') {
535
                    /* get precision value from argument list*/
537
                    /* get precision value from argument list*/
536
                    i++;
538
                    i++;
537
                    precision = (int)va_arg(ap, int);
539
                    precision = (int)va_arg(ap, int);
538
                    if (precision < 0) {
540
                    if (precision < 0) {
539
                        /* negative precision means to ignore it */
541
                        /* negative precision means to ignore it */
540
                        precision = 0;
542
                        precision = 0;
541
                    }
543
                    }
542
                }
544
                }
543
            }
545
            }
544
 
546
 
545
            switch (fmt[i++]) {
547
            switch (fmt[i++]) {
546
                /** TODO: unimplemented qualifiers:
548
                /** TODO: unimplemented qualifiers:
547
                 * t ptrdiff_t - ISO C 99
549
                 * t ptrdiff_t - ISO C 99
548
                 */
550
                 */
549
                case 'h':   /* char or short */
551
                case 'h':   /* char or short */
550
                    qualifier = PrintfQualifierShort;
552
                    qualifier = PrintfQualifierShort;
551
                    if (fmt[i] == 'h') {
553
                    if (fmt[i] == 'h') {
552
                        i++;
554
                        i++;
553
                        qualifier = PrintfQualifierByte;
555
                        qualifier = PrintfQualifierByte;
554
                    }
556
                    }
555
                    break;
557
                    break;
556
                case 'l':   /* long or long long*/
558
                case 'l':   /* long or long long*/
557
                    qualifier = PrintfQualifierLong;
559
                    qualifier = PrintfQualifierLong;
558
                    if (fmt[i] == 'l') {
560
                    if (fmt[i] == 'l') {
559
                        i++;
561
                        i++;
560
                        qualifier = PrintfQualifierLongLong;
562
                        qualifier = PrintfQualifierLongLong;
561
                    }
563
                    }
562
                    break;
564
                    break;
563
                case 'z':   /* __native */
565
                case 'z':   /* __native */
564
                    qualifier = PrintfQualifierNative;
566
                    qualifier = PrintfQualifierNative;
565
                    break;
567
                    break;
566
                default:
568
                default:
567
                    qualifier = PrintfQualifierInt; /* default type */
569
                    qualifier = PrintfQualifierInt; /* default type */
568
                    --i;
570
                    --i;
569
            }  
571
            }  
570
           
572
           
571
            base = 10;
573
            base = 10;
572
 
574
 
573
            switch (c = fmt[i]) {
575
            switch (c = fmt[i]) {
574
 
576
 
575
                /*
577
                /*
576
                * String and character conversions.
578
                * String and character conversions.
577
                */
579
                */
578
                case 's':
580
                case 's':
579
                    if ((retval = print_string(va_arg(ap, char*), width, precision, flags, ps)) < 0) {
581
                    if ((retval = print_string(va_arg(ap, char*), width, precision, flags, ps)) < 0) {
580
                        counter = -counter;
582
                        counter = -counter;
581
                        goto out;
583
                        goto out;
582
                    };
584
                    };
583
                   
585
                   
584
                    counter += retval;
586
                    counter += retval;
585
                    j = i + 1;
587
                    j = i + 1;
586
                    goto next_char;
588
                    goto next_char;
587
                case 'c':
589
                case 'c':
588
                    c = va_arg(ap, unsigned int);
590
                    c = va_arg(ap, unsigned int);
589
                    if ((retval = print_char(c, width, flags, ps)) < 0) {
591
                    if ((retval = print_char(c, width, flags, ps)) < 0) {
590
                        counter = -counter;
592
                        counter = -counter;
591
                        goto out;
593
                        goto out;
592
                    };
594
                    };
593
                   
595
                   
594
                    counter += retval;
596
                    counter += retval;
595
                    j = i + 1;
597
                    j = i + 1;
596
                    goto next_char;
598
                    goto next_char;
597
 
599
 
598
                /*
600
                /*
599
                 * Integer values
601
                 * Integer values
600
                */
602
                */
601
                case 'P': /* pointer */
603
                case 'P': /* pointer */
602
                        flags |= __PRINTF_FLAG_BIGCHARS;
604
                        flags |= __PRINTF_FLAG_BIGCHARS;
603
                case 'p':
605
                case 'p':
604
                    flags |= __PRINTF_FLAG_PREFIX;
606
                    flags |= __PRINTF_FLAG_PREFIX;
605
                    base = 16;
607
                    base = 16;
606
                    qualifier = PrintfQualifierPointer;
608
                    qualifier = PrintfQualifierPointer;
607
                    break; 
609
                    break; 
608
                case 'b':
610
                case 'b':
609
                    base = 2;
611
                    base = 2;
610
                    break;
612
                    break;
611
                case 'o':
613
                case 'o':
612
                    base = 8;
614
                    base = 8;
613
                    break;
615
                    break;
614
                case 'd':
616
                case 'd':
615
                case 'i':
617
                case 'i':
616
                    flags |= __PRINTF_FLAG_SIGNED;  
618
                    flags |= __PRINTF_FLAG_SIGNED;  
617
                case 'u':
619
                case 'u':
618
                    break;
620
                    break;
619
                case 'X':
621
                case 'X':
620
                    flags |= __PRINTF_FLAG_BIGCHARS;
622
                    flags |= __PRINTF_FLAG_BIGCHARS;
621
                case 'x':
623
                case 'x':
622
                    base = 16;
624
                    base = 16;
623
                    break;
625
                    break;
624
                /* percentile itself */
626
                /* percentile itself */
625
                case '%':
627
                case '%':
626
                    j = i;
628
                    j = i;
627
                    goto next_char;
629
                    goto next_char;
628
                /*
630
                /*
629
                * Bad formatting.
631
                * Bad formatting.
630
                */
632
                */
631
                default:
633
                default:
632
                    /* Unknown format
634
                    /* Unknown format
633
                     *  now, the j is index of '%' so we will
635
                     *  now, the j is index of '%' so we will
634
                     * print whole bad format sequence
636
                     * print whole bad format sequence
635
                     */
637
                     */
636
                    goto next_char;    
638
                    goto next_char;    
637
            }
639
            }
638
       
640
       
639
       
641
       
640
        /* Print integers */
642
        /* Print integers */
641
            /* print number */
643
            /* print number */
642
            switch (qualifier) {
644
            switch (qualifier) {
643
                case PrintfQualifierByte:
645
                case PrintfQualifierByte:
644
                    size = sizeof(unsigned char);
646
                    size = sizeof(unsigned char);
645
                    number = (__u64)va_arg(ap, unsigned int);
647
                    number = (__u64)va_arg(ap, unsigned int);
646
                    break;
648
                    break;
647
                case PrintfQualifierShort:
649
                case PrintfQualifierShort:
648
                    size = sizeof(unsigned short);
650
                    size = sizeof(unsigned short);
649
                    number = (__u64)va_arg(ap, unsigned int);
651
                    number = (__u64)va_arg(ap, unsigned int);
650
                    break;
652
                    break;
651
                case PrintfQualifierInt:
653
                case PrintfQualifierInt:
652
                    size = sizeof(unsigned int);
654
                    size = sizeof(unsigned int);
653
                    number = (__u64)va_arg(ap, unsigned int);
655
                    number = (__u64)va_arg(ap, unsigned int);
654
                    break;
656
                    break;
655
                case PrintfQualifierLong:
657
                case PrintfQualifierLong:
656
                    size = sizeof(unsigned long);
658
                    size = sizeof(unsigned long);
657
                    number = (__u64)va_arg(ap, unsigned long);
659
                    number = (__u64)va_arg(ap, unsigned long);
658
                    break;
660
                    break;
659
                case PrintfQualifierLongLong:
661
                case PrintfQualifierLongLong:
660
                    size = sizeof(unsigned long long);
662
                    size = sizeof(unsigned long long);
661
                    number = (__u64)va_arg(ap, unsigned long long);
663
                    number = (__u64)va_arg(ap, unsigned long long);
662
                    break;
664
                    break;
663
                case PrintfQualifierPointer:
665
                case PrintfQualifierPointer:
664
                    size = sizeof(void *);
666
                    size = sizeof(void *);
665
                    number = (__u64)(unsigned long)va_arg(ap, void *);
667
                    number = (__u64)(unsigned long)va_arg(ap, void *);
666
                    break;
668
                    break;
667
                case PrintfQualifierNative:
669
                case PrintfQualifierNative:
668
                    size = sizeof(__native);
670
                    size = sizeof(__native);
669
                    number = (__u64)va_arg(ap, __native);
671
                    number = (__u64)va_arg(ap, __native);
670
                    break;
672
                    break;
671
                default: /* Unknown qualifier */
673
                default: /* Unknown qualifier */
672
                    counter = -counter;
674
                    counter = -counter;
673
                    goto out;
675
                    goto out;
674
            }
676
            }
675
           
677
           
676
            if (flags & __PRINTF_FLAG_SIGNED) {
678
            if (flags & __PRINTF_FLAG_SIGNED) {
677
                if (number & (0x1 << (size*8 - 1))) {
679
                if (number & (0x1 << (size*8 - 1))) {
678
                    flags |= __PRINTF_FLAG_NEGATIVE;
680
                    flags |= __PRINTF_FLAG_NEGATIVE;
679
               
681
               
680
                    if (size == sizeof(__u64)) {
682
                    if (size == sizeof(__u64)) {
681
                        number = -((__s64)number);
683
                        number = -((__s64)number);
682
                    } else {
684
                    } else {
683
                        number = ~number;
685
                        number = ~number;
684
                        number &= (~((0xFFFFFFFFFFFFFFFFll) <<  (size * 8)));
686
                        number &= (~((0xFFFFFFFFFFFFFFFFll) <<  (size * 8)));
685
                        number++;
687
                        number++;
686
                    }
688
                    }
687
                }
689
                }
688
            }
690
            }
689
 
691
 
690
            if ((retval = print_number(number, width, precision, base, flags, ps)) < 0) {
692
            if ((retval = print_number(number, width, precision, base, flags, ps)) < 0) {
691
                counter = -counter;
693
                counter = -counter;
692
                goto out;
694
                goto out;
693
            };
695
            };
694
 
696
 
695
            counter += retval;
697
            counter += retval;
696
            j = i + 1;
698
            j = i + 1;
697
        }  
699
        }  
698
next_char:
700
next_char:
699
           
701
           
700
        ++i;
702
        ++i;
701
    }
703
    }
702
   
704
   
703
    if (i > j) {
705
    if (i > j) {
704
        if ((retval = printf_putnchars(&fmt[j], (__native)(i - j), ps)) < 0) { /* error */
706
        if ((retval = printf_putnchars(&fmt[j], (__native)(i - j), ps)) < 0) { /* error */
705
            counter = -counter;
707
            counter = -counter;
706
            goto out;
708
            goto out;
707
           
709
           
708
        }
710
        }
709
        counter += retval;
711
        counter += retval;
710
    }
712
    }
711
 
713
 
712
out:
714
out:
713
    spinlock_unlock(&printflock);
715
    spinlock_unlock(&printflock);
714
    interrupts_restore(irqpri);
716
    interrupts_restore(irqpri);
715
   
717
   
716
    return counter;
718
    return counter;
717
}
719
}
718
 
720
 
-
 
721
 
-
 
722
 /** @}
-
 
723
 */
-
 
724
 
719
 
725