File: fxscanf.cpp

package info (click to toggle)
gogglesmm 1.2.5-6
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 16,812 kB
  • sloc: cpp: 231,960; ansic: 893; xml: 222; makefile: 33
file content (724 lines) | stat: -rw-r--r-- 27,102 bytes parent folder | download | duplicates (2)
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
/********************************************************************************
*                                                                               *
*                   V a r a r g s   S c a n f   R o u t i n e s                 *
*                                                                               *
*********************************************************************************
* Copyright (C) 2002,2022 by Jeroen van der Zijp.   All Rights Reserved.        *
*********************************************************************************
* This library is free software; you can redistribute it and/or modify          *
* it under the terms of the GNU Lesser General Public License as published by   *
* the Free Software Foundation; either version 3 of the License, or             *
* (at your option) any later version.                                           *
*                                                                               *
* This library is distributed in the hope that it will be useful,               *
* but WITHOUT ANY WARRANTY; without even the implied warranty of                *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 *
* GNU Lesser General Public License for more details.                           *
*                                                                               *
* You should have received a copy of the GNU Lesser General Public License      *
* along with this program.  If not, see <http://www.gnu.org/licenses/>          *
********************************************************************************/
#include "xincs.h"
#include "fxver.h"
#include "fxdefs.h"
#include "fxmath.h"
#include "fxascii.h"
#include "FXString.h"


/*
  Notes:
  - It may be not perfect, but at least its the same on all platforms.
  - Handles conversions of the form:

        % [*'] [digits$] [width] [l|ll|h|hh|L|q|t|z] [n|p|d|u|i|x|X|o|D|c|s|[SET]|e|E|f|G|g|b]

  - Assignment suppression and number-grouping:
     '*'        When '*' is passed assignment of the matching quantity is suppressed.
     '''        Commas for thousands, like 1,000,000.

  - Positional argument:
     'digits$'  A sequence of decimal digits indication the position in the parameter
                list, followed by '$'.  The first parameter starts at 1.

  - Width:
     digits     Specifies field width to read, not counting spaces [except for %[] and
                %c and %n directives where spaces do count].

  - Interpretation of size parameters:

     'hh'       convert to FXchar
     'h'        convert to FXshort
     ''         convert to FXint (or FXfloat if real)
     'l'        convert to long (or FXdouble if real)
     'll'       convert to FXlong (64-bit number)
     'L'        ditto
     'q'        ditto
     't'        convert to FXival (size depends on pointer size)
     'z'        convert to FXuval (size depends on pointer size)

  - Conversion specifiers:

     'd'        Decimal integer conversion.
     'b'        Binary integer conversion.
     'i'        Integer conversion from octal, hex, or decimal number.
     'o'        Octal integer conversion.
     'u'        Unsigned decimal integer conversion.
     'x' or 'X' Hexadecimal conversion.
     'c'        String conversion.
     's'        String conversion of printing characters [no spaces].
     'n'        Assign number of characters scanned so far.
     'p'        Hexadecimal pointer conversion.
     [SET]      String conversion of characters in set only.
     'e', 'E',  Floating point conversion.
     'f', 'F'   Floating point conversion.
     'g', 'G'   Floating point conversion.
     'a', 'A'   Floating point conversion.

  - In the case of string (%s or %[...]), do not report a conversion unless at
    least one character is returned.

  - Algorithm accumulate up to 16 digits from the string, starting from most
    significant digit; then convert to real and adjust exponent as necessary.

  - Background: integer numbers larger than 2**53 (52 bits plus one hidden bit)
    can not be represented exactly as double-precision real number, so any
    additional digits past 10**16 are only useful for rounding purposes.

  - Some special numeric values:

    2**53   =     9007199254740992  =  Largest representable mantissa, plus 1.
    10**16  =    10000000000000000  =  Power of 10 slightly larger than 2**53.
    10**18  =  1000000000000000000  =  Power of 10 less than 2**63.
    2**63   =  9223372036854775808  =  Largest 64-bit signed integer, plus 1
    10**19  = 10000000000000000000  =  Power of 10 slightly less than 2**64.
    2**64   = 18446744073709551616  =  Largest 64-bit unsigned integer, plus 1.
*/

#if defined(WIN32)
#ifndef va_copy
#define va_copy(arg,list) ((arg)=(list))
#endif
#endif


using namespace FX;

/*******************************************************************************/

namespace FX {


// Type modifiers
enum {
  ARG_HALFHALF,         // 'hh'
  ARG_HALF,             // 'h'
  ARG_DEFAULT,          // (No specifier)
  ARG_LONG,             // 'l'
  ARG_LONGLONG,         // 'll' / 'L' / 'q'
  ARG_VARIABLE          // Depending on size of pointer
  };


// Some floating point magick
static const union{ FXulong u; FXdouble f; } dblinf={FXULONG(0x7ff0000000000000)};
static const union{ FXulong u; FXdouble f; } dblnan={FXULONG(0x7fffffffffffffff)};

// Normal mode (non-ascii character)
const FXint NORMAL=0x100;

// Thousands separator
const FXint COMMA=',';

// Declarations
extern FXAPI FXint __sscanf(const FXchar* string,const FXchar* format,...);
extern FXAPI FXint __vsscanf(const FXchar* string,const FXchar* format,va_list arg_ptr);

/*******************************************************************************/

// Make double from sign, exponent, and mantissa
static inline FXdouble fpMake(FXlong m,FXlong exp){
  union{ FXulong u; FXdouble f; } z={(m&FXULONG(0x000fffffffffffff)) | (((exp+1023)&0x7ff)<<52)};
  return z.f;
  }

#if 0
// Fast hex digit '0'..'9', 'A'..'F', 'a'..'f' to int
// Otherwise bad values
static inline FXint htoi(FXint x){
  return (x>>6)*9+(x&15);
  }
#endif

// Scan with va_list arguments
FXint __vsscanf(const FXchar* string,const FXchar* format,va_list args){
  FXint modifier,width,convert,comma,base,digits,count,exponent,expo,done,neg,nex,pos,ww,v;
  const FXchar *start=string;
  const FXchar *ss;
  FXdouble dvalue;
  FXulong  ivalue;
  FXulong  imult;
  FXchar   set[256];
  FXchar  *ptr;
  FXuchar  ch,nn;
  va_list  ag;

  count=0;

  // Process format string
  va_copy(ag,args);
  while((ch=*format++)!='\0'){

    // Check for format-characters
    if(ch=='%'){

      // Get next format character
      ch=*format++;

      // Check for '%%'
      if(ch=='%') goto nml;

      // Default settings
      modifier=ARG_DEFAULT;
      width=0;
      convert=1;
      done=0;
      comma=NORMAL;
      base=0;

      // Parse format specifier
flg:  switch(ch){
        case '*':                                               // Suppress conversion
          convert=0;
          ch=*format++;
          goto flg;
        case '\'':                                              // Print thousandths
          comma=COMMA;                                          // Thousands grouping character
          ch=*format++;
          goto flg;
        case '0':                                               // Width or positional parameter
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
          width=ch-'0';
          ch=*format++;
          while(Ascii::isDigit(ch)){
            width=width*10+ch-'0';
            ch=*format++;
            }
          if(ch=='$'){                                          // Positional parameter
            ch=*format++;
            if(width<=0) goto x;                                // Not a legal parameter position
            va_copy(ag,args);
            for(pos=1; pos<width; ++pos){                       // Advance to position prior to arg
              (void)va_arg(ag,void*);
              }
            width=0;                                            // Reset width
            }
          goto flg;
        case 'l':                                               // Long
          modifier=ARG_LONG;
          ch=*format++;
          if(ch=='l'){                                          // Long Long
            modifier=ARG_LONGLONG;
            ch=*format++;
            }
          goto flg;
        case 'h':                                               // Short
          modifier=ARG_HALF;
          ch=*format++;
          if(ch=='h'){                                          // Char
            modifier=ARG_HALFHALF;
            ch=*format++;
            }
          goto flg;
        case 'L':                                               // Long Long
        case 'q':
          modifier=ARG_LONGLONG;
          ch=*format++;
          goto flg;
        case 't':                                               // Size depends on pointer
        case 'z':
          modifier=ARG_VARIABLE;
          ch=*format++;
          goto flg;
        case 'n':                                               // Consumed characters till here
          ivalue=string-start;
          if(convert){
            if(modifier==ARG_DEFAULT){                          // 32-bit always
              *va_arg(ag,FXint*)=(FXint)ivalue;
              }
            else if(modifier==ARG_LONG){                        // Whatever size a long is
              *va_arg(ag,long*)=(long)ivalue;
              }
            else if(modifier==ARG_LONGLONG){                    // 64-bit always
              *va_arg(ag,FXlong*)=ivalue;
              }
            else if(modifier==ARG_HALF){                        // 16-bit always
              *va_arg(ag,FXshort*)=(FXshort)ivalue;
              }
            else if(modifier==ARG_HALFHALF){                    // 8-bit always
              *va_arg(ag,FXchar*)=(FXchar)ivalue;
              }
            else{                                               // Whatever size a pointer is
              *va_arg(ag,FXival*)=(FXival)ivalue;
              }
            }
          break;
        case 'p':                                               // Hex pointer
          modifier=ARG_VARIABLE;
          base=16;
          comma=NORMAL;
          goto integer;
        case 'x':                                               // Hex
        case 'X':
          base=16;
          comma=NORMAL;
          goto integer;
        case 'o':                                               // Octal
          base=8;
          comma=NORMAL;
          goto integer;
        case 'b':                                               // Binary
          base=2;
          comma=NORMAL;
          goto integer;
        case 'd':                                               // Decimal
        case 'u':
          base=10;
        case 'i':                                               // Integer
integer:  ivalue=0;
          digits=0;
          if(width<1) width=2147483647;                         // Width at least 1
          while(Ascii::isSpace(string[0])) string++;            // Skip white space; not included in field width
          if((neg=(string[0]=='-')) || (string[0]=='+')){
            string++;
            width--;
            }
          if(0<width && string[0]=='0'){                        // Got "0"
            if(1<width && (string[1]|0x20)=='x'){               // Got a "0x"
              if(base==0 || base==16){                          // Its hex
                comma=NORMAL;
                base=16;
                string+=2;
                width-=2;
                }
              }
            else if(1<width && (string[1]|0x20)=='b'){          // Got a "0b"
              if(base==0 || base==2){                           // Its binary
                comma=NORMAL;
                base=2;
                string+=2;
                width-=2;
                }
              }
            else{                                               // Got a "0"
              if(base==0 || base==8){                           // Its octal
                comma=NORMAL;
                base=8;
                }
              }
            }
          else{                                                 // Got something else
            if(base==0){                                        // If not set, its decimal now
              base=10;
              }
            }
          while(0<width && 0<=(v=Ascii::digitValue(string[0])) && v<base){
            ivalue=ivalue*base+v;
            string++;
            width--;
            digits++;
            }
          if(3<width && string[0]==comma && 0<digits && digits<4){ // Thousands group is ',ddd' or nothing
            do{
              if((ch=string[1])<'0' || ch>'9') break;
              if((ch=string[2])<'0' || ch>'9') break;
              if((ch=string[3])<'0' || ch>'9') break;
              ivalue=((ivalue*10+string[1])*10+string[2])*10+string[3]-5328;
              string+=4;
              width-=4;
              digits+=3;
              }
            while(3<width && string[0]==comma);
            }
          if(!digits) goto x;                                   // No digits seen!
          if(neg){                                              // Apply sign
            ivalue=0-ivalue;
            }
          if(convert){
            if(modifier==ARG_DEFAULT){                          // 32-bit always
              *va_arg(ag,FXint*)=(FXint)ivalue;
              }
            else if(modifier==ARG_LONG){                        // Whatever size a long is
              *va_arg(ag,long*)=(long)ivalue;
              }
            else if(modifier==ARG_LONGLONG){                    // 64-bit always
              *va_arg(ag,FXlong*)=ivalue;
              }
            else if(modifier==ARG_HALF){                        // 16-bit always
              *va_arg(ag,FXshort*)=(FXshort)ivalue;
              }
            else if(modifier==ARG_HALFHALF){                    // 8-bit always
              *va_arg(ag,FXchar*)=(FXchar)ivalue;
              }
            else{                                               // Whatever size a pointer is
              *va_arg(ag,FXival*)=(FXival)ivalue;
              }
            count++;
            }
          break;
        case 'a':                                               // Floating point
        case 'A':
        case 'e':
        case 'E':
        case 'f':
        case 'F':
        case 'g':
        case 'G':
          dvalue=0.0;
          ivalue=0;
          digits=0;
          if(width<1) width=2147483647;                         // Width at least 1
          while(Ascii::isSpace(string[0])) string++;            // Skip white space; not included in field width
          if((neg=(string[0]=='-')) || (string[0]=='+')){
            string++;
            width--;
            }
          if(2<width && (string[0]|0x20)=='n'){                 // NaN
            if((string[1]|0x20)!='a') goto x;
            if((string[2]|0x20)!='n') goto x;
            string+=3;
            dvalue=dblnan.f;
            }
          else if(2<width && (string[0]|0x20)=='i'){            // Inf{inity}
            if((string[1]|0x20)!='n') goto x;
            if((string[2]|0x20)!='f') goto x;
            if(7<width && (string[3]|0x20)=='i' && (string[4]|0x20)=='n' && (string[5]|0x20)=='i' && (string[6]|0x20)=='t' && (string[7]|0x20)=='y'){
              string+=5;
              }
            string+=3;
            dvalue=dblinf.f;
            }
          else if(1<width && string[0]=='0' && (string[1]|0x20)=='x'){  // Hexadecimal float
            string+=2;
            width-=2;
            exponent=-4;
            imult=FXLONG(0x0010000000000000);
            while(0<width && string[0]=='0'){
              string++;
              width--;
              digits++;
              }
            while(0<width && 0<=(v=Ascii::digitValue(string[0])) && v<16){
              ivalue+=imult*v;
              imult>>=4;
              exponent+=4;
              string++;
              width--;
              digits++;
              }
            if(0<width && string[0]=='.'){                      // Hexadecimals following '.'
              string++;
              width--;
              if(ivalue==0){
                while(0<width && string[0]=='0'){
                  exponent-=4;
                  string++;
                  width--;
                  digits++;
                  }
                }
              while(0<width && 0<=(v=Ascii::digitValue(string[0])) && v<16){
                ivalue+=imult*v;
                imult>>=4;
                string++;
                width--;
                digits++;
                }
              }
            if(!digits) goto x;                                 // No digits seen!
            if(1<width && (string[0]|0x20)=='p'){               // Handle exponent, tentatively
              ss=string;                                        // Rewind point if no match
              ww=width;
              ss++;
              ww--;
              expo=0;
              if((nex=(ss[0]=='-')) || (ss[0]=='+')){           // Handle exponent sign
                ss++;
                ww--;
                }
              if(0<ww && '0'<=ss[0] && ss[0]<='9'){             // Have exponent?
                while(0<ww && '0'<=(ch=ss[0]) && ch<='9'){
                  expo=expo*10+(ch-'0');
                  ss++;
                  ww--;
                  }
                if(nex){
                  exponent-=expo;
                  }
                else{
                  exponent+=expo;
                  }
                string=ss;                                      // Eat exponent characters
                }
              }
            if(ivalue!=0){
              while(FXLONG(0x001fffffffffffff)<ivalue){         // Adjust to get hidden 1-bit in place
                ivalue>>=1;                                     // Shift up to 3 times
                exponent++;
                }
              if(1024<=exponent){                               // Check for overflow
                if((1024<exponent) || (FXLONG(0x0010000000000000)<=ivalue)){
                  ivalue=FXLONG(0x0010000000000000);
                  exponent=1024;
                  }
                }
              if(exponent<-1022){                               // Check for denormal or underflow
                if(exponent<-1074){
                  ivalue=0;
                  exponent=0;
                  }
                v=-exponent-1022;                               // Shift mantissa to fix exponent
                ivalue>>=v;
                exponent=-1023;
                }
              dvalue=fpMake(ivalue,exponent);                   // Assemble double
              }
            }
          else{                                                 // Decimal float
            ivalue=0;
            imult=FXLONG(10000000000000000);
            exponent=-1;
            while(0<width && string[0]=='0'){
              string++;
              width--;
              digits++;
              }
            while(0<width && '0'<=(ch=string[0]) && ch<='9'){
              ivalue+=(ch-'0')*imult;
              imult/=10;
              exponent++;
              string++;
              width--;
              digits++;
              }
            if(3<width && string[0]==comma && 0<digits && digits<4){ // Thousands group is ',ddd' or nothing
              do{
                if((ch=string[1])<'0' || ch>'9') break;
                if((ch=string[2])<'0' || ch>'9') break;
                if((ch=string[3])<'0' || ch>'9') break;
                ivalue+=(string[1]-'0')*imult;
                if(ivalue){imult/=10;exponent++;}
                ivalue+=(string[2]-'0')*imult;
                if(ivalue){imult/=10;exponent++;}
                ivalue+=(string[3]-'0')*imult;
                if(ivalue){imult/=10;exponent++;}
                string+=4;
                width-=4;
                digits+=3;
                }
              while(3<width && string[0]==comma);
              }
            if(0<width && string[0]=='.'){                      // Decimals following '.'
              string++;
              width--;
              if(ivalue==0){
                while(0<width && string[0]=='0'){
                  exponent--;
                  string++;
                  width--;
                  digits++;
                  }
                }
              while(0<width && '0'<=(ch=string[0]) && ch<='9'){
                ivalue+=(ch-'0')*imult;
                imult/=10;
                string++;
                width--;
                digits++;
                }
              }
            if(!digits) goto x;                                 // No digits seen!
            if(1<width && (string[0]|0x20)=='e'){               // Handle exponent, tentatively
              ss=string;                                        // Rewind point if no match
              ww=width;
              ss++;
              ww--;
              expo=0;
              if((nex=(ss[0]=='-')) || (ss[0]=='+')){           // Handle exponent sign
                ss++;
                ww--;
                }
              if(0<ww && '0'<=ss[0] && ss[0]<='9'){             // Have exponent?
                while(0<ww && '0'<=(ch=ss[0]) && ch<='9'){
                  expo=expo*10+(ch-'0');
                  ss++;
                  ww--;
                  }
                if(nex){
                  exponent-=expo;
                  }
                else{
                  exponent+=expo;
                  }
                string=ss;                                      // Eat exponent characters
                }
              }
            dvalue=1.0E-16*(FXlong)ivalue;                      // Convert to 64-bit integer to 64-bit real
            if(dvalue!=0.0){
              if(308<=exponent){                                // Check for overflow
                if((308<exponent) || (1.79769313486231570815<=dvalue)){
                  dvalue=1.79769313486231570815E+308;
                  exponent=0;
                  }
                }
              if(exponent<-308){                                // Check for denormal or underflow
                if((exponent<-324) || ((exponent==-324) && (dvalue<=4.94065645841246544177))){
                  dvalue=0.0;
                  exponent=0;
                  }
                dvalue*=1.0E-16;
                exponent+=16;
                }
              dvalue*=Math::pow10i(exponent);                   // Exponent in range
              }
            }
          if(neg){                                              // Apply sign
            dvalue=-dvalue;
            }
          if(convert){
            if(modifier==ARG_DEFAULT){
              *va_arg(ag,FXfloat*)=(FXfloat)dvalue;             // 32-bit float
              }
            else{
              *va_arg(ag,FXdouble*)=dvalue;                     // 64-bit double
              }
            count++;
            }
          break;
        case 'c':                                               // Character(s)
          if(width<1) width=1;                                  // Width at least 1
          if(convert){
            ptr=va_arg(ag,FXchar*);
            while(0<width && (ch=string[0])!='\0'){
              *ptr++=ch;
              string++;
              width--;
              done=1;
              }
            count+=done;
            }
          else{
            while(0<width && string[0]!='\0'){
              string++;
              width--;
              }
            }
          break;
        case 's':                                               // String
          if(width<1) width=2147483647;                         // Width at least 1
          while(Ascii::isSpace(string[0])) string++;            // Skip white space
          if(convert){
            ptr=va_arg(ag,FXchar*);
            while(0<width && (ch=string[0])!='\0' && !Ascii::isSpace(ch)){
              *ptr++=ch;
              string++;
              width--;
              done=1;
              }
            *ptr='\0';
            count+=done;
            }
          else{
            while(0<width && (ch=string[0])!='\0' && !Ascii::isSpace(ch)){
              string++;
              width--;
              }
            }
          break;
        case '[':                                               // Character set
          if(width<1) width=2147483647;                         // Width at least 1
          ch=(FXuchar)*format++;
          v=1;                                                  // Add characters to set
          if(ch=='^'){                                          // Negated character set
            ch=(FXuchar)*format++;
            v=0;                                                // Remove characters from set
            }
          memset(set,1-v,sizeof(set));                          // Initialize set
          if(ch=='\0') goto x;                                  // Format error
          for(;;){                                              // Parse set
            set[ch]=v;
            nn=(FXuchar)*format++;
            if(nn=='\0') goto x;                                // Format error
            if(nn==']') break;
            if(nn=='-'){
              nn=(FXuchar)*format;
              if(nn!=']' && ch<=nn){                            // Range if not at end
                while(ch<nn){ set[++ch]=v; }
                format++;
                }
              else{                                             // Otherwise just '-'
                nn='-';
                }
              }
            ch=nn;
            }
          if(convert){
            ptr=va_arg(ag,FXchar*);
            while(0<width && (ch=*string)!='\0' && set[(FXuchar)ch]){
              *ptr++=ch;
              string++;
              width--;
              done=1;
              }
            *ptr='\0';
            count+=done;
            }
          else{
            while(0<width && (ch=*string)!='\0' && set[(FXuchar)ch]){
              string++;
              width--;
              }
            }
          break;
        default:                                                // Format error
          goto x;
        }
      continue;
      }

    // Check for spaces
nml:if(Ascii::isSpace(ch)){
      while(Ascii::isSpace(*format)) format++;
      while(Ascii::isSpace(*string)) string++;
      continue;
      }

    // Regular characters must match
    if(*string!=ch) break;

    // Next regular character
    string++;
    }
x:va_end(ag);
  return count;
  }


// Scan with variable number of arguments
FXint __sscanf(const FXchar* string,const FXchar* format,...){
  va_list args;
  va_start(args,format);
  FXint result=__vsscanf(string,format,args);
  va_end(args);
  return result;
  }

}