1   #include        &lsaquo stdio.h&rsaquo
2   #include        &lsaquo ctype.h&rsaquo
3   #include        &lsaquo stdlib.h&rsaquo
4   #include        &lsaquo string.h&rsaquo
5   #include        &lsaquo stdarg.h&rsaquo
6   #include        &lsaquo conio.h&rsaquo
7   #include        &lsaquo sys.h&rsaquo
8   #include        &lsaquo math.h&rsaquo
9   #include        &lsaquo float.h&rsaquo
10  
11   //  disable  unused  variable  warnings
12   //  the  compiler  will  optimize  them  away,  so  no  harm  is  done
13   #pragma  warning  disable  350
14  
15   /*
16     *      doprnt  -  versions  depends  on  conditional  compilation.
17     *      Can  be  customized  with  defines.
18     *
19     *      Copyright  (c)  2012  Microchip  Technology  Inc.  All  rights  reserved.
20     *
21     *      $Header$
22     *
23     */
24  
25   #ifndef CUSTOM_PRINTF
26  
27     //  define  all  flags,  thus  enabling  all  features
28  
29   #define BASEM    0xC0
30   #define OPTSIGN  0x00
31   #define SPCSIGN  0x01
32   #define MANSIGN  0x02
33   #define NEGSIGN  0x03
34   #define FILL     0x04
35   #define LEFT     0x08
36   #define LONG     0x10
37   #define UPCASE   0x20
38   #define TEN            0x00
39   #define EIGHT    0x40
40   #define SIXTEEN  0x80
41   #define UNSIGN   0xC0
42   #ifdef  __FLOAT
43   #define EFMT     0x100
44   #define GFMT     0x200
45   #define FFMT     0x400
46   #endif  //  __FLOAT
47   #define ALTERN   0x800
48   #define  POINTER 0x2000
49   #define  HEXUPCASE
50   #define  HEXLOWCASE
51  
52     //  defines  for  ifdef  only,  not  used  as  flags
53   #define WIDTH    1      //  width  used
54   #define STAR     1        //  width  or  precision  as  an  arg
55   #define STRING   1    //  %s  used
56   #define CHAR     1        //  %c  used
57   #define PERCPERC 1        //  %%  used
58   #define SPRINTF  1 //  sprintf  is  used
59   #define PRINTF   1    //  printf  is  used
60   #define MULTRAD  1 //  handle  multiple  radices
61   #define RETVALUE 1        //  return  value  is  needed
62  
63   #else   //  CUSTOM_PRINTF
64  
65   #if     defined(HEXUPCASE)  ||  defined(HEXLOWCASE)
66   #define SIXTEEN
67   #endif
68  
69   #if     defined(HEXUPCASE)  &&  defined(HEXLOWCASE)
70   #ifndef  UPCASE
71   #define UPCASE
72   #endif
73   #endif
74  
75     //  make  sure  we  have  the  right  values  for  each  define
76   #ifdef  OPTSIGN
77   #undef  OPTSIGN
78   #define OPTSIGN  0x00
79   #endif
80   #ifdef  SPCSIGN
81   #undef  SPCSIGN
82   #define SPCSIGN  0x01
83   #endif
84   #ifdef  MANSIGN
85   #undef  MANSIGN
86   #define MANSIGN  0x02
87   #define SPCSIGN  0x01
88   #endif
89   #ifdef  NEGSIGN
90   #undef  NEGSIGN
91   #define NEGSIGN  0x03
92   #endif
93   #ifdef  FILL
94   #define WIDTH    1
95   #undef  FILL
96   #define FILL     0x04
97   #endif
98   #ifdef  LEFT
99   #undef  LEFT
100     //  LEFT  without  WIDTH  is  meaningless
101   #ifdef  WIDTH
102   #define LEFT     0x08
103   #endif
104   #endif
105   #ifdef  LONG
106   #undef  LONG
107   #define LONG     0x10
108   #define __LONG   1
109   #endif
110   #ifdef  UPCASE
111   #undef  UPCASE
112   #define UPCASE   0x20
113   #endif
114   #ifdef  TEN      
115   #undef  TEN      
116   #define TEN            0x00
117   #endif
118   #ifdef  EIGHT
119   #undef  EIGHT
120   #define EIGHT    0x40
121   #endif
122   #ifdef  SIXTEEN
123   #undef  SIXTEEN
124   #define SIXTEEN  0x80
125   #endif
126   #ifdef  UNSIGN
127   #undef  UNSIGN
128   #define UNSIGN   0xC0
129   #endif
130   #ifdef  EFMT
131   #undef  EFMT
132   #define EFMT     0x100
133   #endif
134   #ifdef  GFMT
135   #undef  GFMT
136   #define GFMT     0x200
137   #endif
138   #ifdef  FFMT
139   #undef  FFMT
140   #define FFMT     0x400
141   #endif
142   #ifdef  ALTERN
143   #undef  ALTERN
144   #define ALTERN   0x800
145   #endif
146   #ifdef  POINTER
147   #undef  POINTER
148   #define  POINTER 0x2000
149   #ifndef SIXTEEN
150   #define SIXTEEN  0x80
151   #endif
152   #endif
153   #ifdef  PRECISION
154   #undef  PRECISION
155   #define  PRECISION       0x4000
156   #endif
157  
158   #if     defined(TEN)  &&  !defined(EIGHT)  &&  !defined(SIXTEEN)  &&  defined(UNSIGN)
159   #undef  UNSIGN
160   #define UNSIGN   0x40
161   #define BASEM    UNSIGN
162   #endif
163   #if     defined(UNSIGN)  &&  (defined(EIGHT)  ||  defined(SIXTEEN))
164   #define MULTRAD  1
165   #define BASEM    (UNSIGN)
166   #endif
167   #if     defined(TEN)  &&  !defined(SIXTEEN)  &&  defined(EIGHT)  &&  !defined(UNSIGN)
168   #define BASEM    EIGHT
169   #define MULTRAD  1
170   #endif
171   #if     defined(TEN)  &&  defined(SIXTEEN)  &&  !defined(EIGHT)  &&  !defined(UNSIGN)
172   #define BASEM    SIXTEEN
173   #define MULTRAD  1
174   #endif
175   #if     defined(SIXTEEN)  &&  defined(EIGHT)  &&  !defined(BASEM)
176   #define BASEM    (SIXTEEN|EIGHT)
177   #define MULTRAD  1
178   #endif
179  
180   #endif
181  
182     //  float  code  needs  these  flags
183   #if     defined(EFMT)  ||  defined(GFMT)  ||  defined(FFMT)
184   #ifndef __FLOAT
185   #define __FLOAT  1
186   #endif
187   #define FLOATFORMAT      0x700
188   #ifdef  PRECISION
189   #define DEFPREC  0x1000
190   #endif
191   #endif
192  
193   #ifdef  __FLOAT
194   //#ifndef       MANSIGN
195   //#define       MANSIGN        0x02
196   //#endif
197   //#ifndef       SPCSIGN
198   //#define       SPCSIGN        0x01
199   //#endif
200   #ifndef NEGSIGN
201   #define NEGSIGN  0x03
202   #endif
203   //#ifndef       WIDTH
204   //#define       WIDTH  1
205   //#endif
206   #endif
207  
208   #ifdef  SPCSIGN
209   #define putsign()        pputc(flag  &  SPCSIGN  ?  '-'  :  '+')
210   #else
211   #define putsign()        pputc('-')
212   #endif  //  SPCSIGN
213  
214   //  were  there  ANY  %  formats  defined?
215   #if     defined(FLOATFORMAT)  ||  defined(TEN)  ||  defined(EIGHT)  ||  defined(SIXTEEN)  ||  \
216           defined(CHAR)  ||  defined(POINTER)  ||  defined(STRING)  ||  defined(UNSIGN)  ||  defined(PERCPERC)
217   #define ANYFORMAT
218   #else
219   #undef  ANYFORMAT
220   #endif
221  
222   #ifdef  CHAR
223   #ifndef PERCPERC
224   #define PERCPERC
225   #endif
226   #endif
227  
228   #if     !defined(PRINTF)  &&  !defined(VPRINTF)  &&  !defined(SPRINTF)  &&  !defined(VSPRINTF)
229   #error  Must  define  at  least  one  of  PRINTF  SPRINTF  or  VSPRINTF
230   #endif
231  
232   #if     i8086  &&  SMALL_DATA
233   #define CONST    far
234   #else
235   #define CONST    const
236   #endif
237  
238     /*  we  don't  need  plus  signs,  use  minus  signs  only  if  we  have  floats  or  signed  ints  */
239  
240   #if     !defined(NEGSIGN)  &&  defined(TEN)
241   #define NEGSIGN  0x03
242   #endif
243  
244   #ifndef RETVALUE
245   #define INCR_CNT /*nix  */
246   #else
247   #define INCR_CNT ,(++ccnt)
248   #endif
249  
250   #if     defined(EFMT)  ||  defined(GFMT)  ||  defined(FFMT)  ||  defined(ALTERN)  ||  defined(DEFPREC)  ||  defined(POINTER)
251   #define FLAG_SIZE        unsigned  short
252   #else
253   #define FLAG_SIZE        unsigned  char
254   #endif
255  
256  
257   #if     (sizeof(long)  ==  sizeof(int)  ||  defined(__FLOAT))  &&  !defined(__LONG)
258   #define __LONG   1
259   #endif
260  
261   #if     sizeof(double)  ==  sizeof(long)  &&  DBL_MAX_EXP  ==  128
262   #undef  frexp
263   #define frexp(val,  ptr)  (void)(*(ptr)  =  (unsigned  char)((*(unsigned  long  *)&val &rsaquo &rsaquo   23)  &  255)  -  126)
264   #elif   defined(_PSOC_)
265   #undef  frexp
266   #define frexp(val,  ptr)  (void)(*(ptr)  =  ((unsigned  char)(*(unsigned  short  long  *)&val &rsaquo &rsaquo   15))  -  126)
267   #elif   sizeof(double)  ==  3  &&  DBL_MAX_EXP  ==  128
268   #undef  frexp
269   #define frexp(val,  ptr)  (void)(*(ptr)  =  ((*(unsigned  long  *)&val &rsaquo &rsaquo   15)  &  255)  -  126)
270   #endif
271  
272   #if     defined(__FLOAT)  &&  sizeof(double)  ==  8
273   #define DOUBLE   1
274  
275   extern  double   _dto64i(double);
276   extern  double   _64itod(double);
277   extern  double   _div64(double,  double);
278   extern  double   _divto64i(double,  double);
279   extern  unsigned _div64ir(double,  double);
280   extern  unsigned _mod64i10(double);
281  
282   #else
283   #define DOUBLE   0
284   #endif
285  
286   #ifdef  __LONG
287   #define value    long
288   #define NDIG     12      /*  max  number  of  digits  to  be  printed  */
289   #else
290   #define value    int
291   #define NDIG     6        /*  max  number  of  digits  to  be  printed  */
292   #endif
293  
294   #if     DOUBLE
295   union  {
296           unsigned  long   ul[40];
297           double    db[20];
298   }       _fdp  =
299   {
300   #if     !defined(BIG_ENDIAN)  &&  !defined(LITTLE_ENDIAN)
301   #error  Neither  BIG_ENDIAN  or  LITTLE_ENDIAN  has  been  set
302   #endif
303   #if     BIG_ENDIAN
304           0x00000000,0x00000001,
305           0x00000000,0x0000000A,
306           0x00000000,0x00000064,
307           0x00000000,0x000003E8,
308           0x00000000,0x00002710,
309           0x00000000,0x000186A0,
310           0x00000000,0x000F4240,
311           0x00000000,0x00989680,
312           0x00000000,0x05F5E100,
313           0x00000000,0x3B9ACA00,
314           0x00000002,0x540BE400,
315           0x00000017,0x4876E800,
316           0x000000E8,0xD4A51000,
317           0x00000918,0x4E72A000,
318           0x00005AF3,0x107A4000,
319           0x00038D7E,0xA4C68000,
320           0x002386F2,0x6FC10000,
321           0x01634578,0x5D8A0000,
322           0x0DE0B6B3,0xA7640000,
323           0x8AC72304,0x89E80000,
324   #else
325           0x00000001,0x00000000,
326           0x0000000A,0x00000000,
327           0x00000064,0x00000000,
328           0x000003E8,0x00000000,
329           0x00002710,0x00000000,
330           0x000186A0,0x00000000,
331           0x000F4240,0x00000000,
332           0x00989680,0x00000000,
333           0x05F5E100,0x00000000,
334           0x3B9ACA00,0x00000000,
335           0x540BE400,0x00000002,
336           0x4876E800,0x00000017,
337           0xD4A51000,0x000000E8,
338           0x4E72A000,0x00000918,
339           0x107A4000,0x00005AF3,
340           0xA4C68000,0x00038D7E,
341           0x6FC10000,0x002386F2,
342           0x5D8A0000,0x01634578,
343           0xA7640000,0x0DE0B6B3,
344           0x89E80000,0x8AC72304,
345   #endif
346   };
347  
348   #define fdpowers _fdp.db
349  
350   #else
351   #define fdpowers dpowers
352   #endif
353   #if  defined(TEN)  ||  defined(__FLOAT)  ||  defined  (UNSIGN)
354   const  static  unsigned  value     dpowers[]  =  {1,  10,  100,  1000,  10000,
355   #ifdef  __LONG
356                                                     100000,  1000000,  10000000,  100000000,
357                                                     1000000000
358   #endif
359                                                             };
360   #endif
361   #ifdef  SIXTEEN
362   const  static  unsigned  value     hexpowers[]  =        {1,  0x10,  0x100,  0x1000,
363   #if     __LONG
364                                                     0x10000,  0x100000,  0x1000000,  0x10000000
365   #endif
366                                                           };
367   #endif
368   #ifdef  EIGHT
369   const  static  unsigned  value     octpowers[]  =        {1,  010,  0100,  01000,  010000,  0100000,
370   #ifdef  __LONG
371                                                   01000000,
372                                                     010000000,  0100000000,  01000000000,  010000000000,
373                                                     0100000000000
374   #endif
375                                                           };
376   #endif
377  
378   #ifdef  __FLOAT
379  
380   #define NDDIG    (sizeof  fdpowers/sizeof  fdpowers[0])
381  
382   #if     DBL_MAX_10_EXP &rsaquo   120
383   #define expon    int
384   #else
385   #define expon    signed  char
386   #endif
387  
388   extern  const  double     _powers_[],  _npowers_[];
389   #ifdef  z80
390   #define _div_to_l_(a,  b) ((unsigned  long)((a)/(b)))
391   #else
392   extern  unsigned  long    _div_to_l_(double,  double);
393   #ifdef  _OMNI_CODE_
394   extern  unsigned  long    _tdiv_to_l_(float,  float);
395   #ifdef  _HTKC_
396   #pragma  callname  _div_to_l_  double
397   #pragma  callname  _tdiv_to_l_  float
398   #endif
399   #define div_to_l_(a,b)   ((sizeof(double)==  3)  ?  _tdiv_to_l_(a,b)  :  _div_to_l_(a,b))
400   #else
401   #define div_to_l_        _div_to_l_
402   #endif
403   #endif
404  
405   /*  this  routine  returns  a  value  to  round  to  the  number  of  decimal
406           places  specified  */
407   #if  __FLOAT
408   static  double
409   fround(unsigned  char  prec)
410   {
411           /*  prec  is  guaranteed  to  be  less  than  NDIG  */
412  
413           if(prec&rsaquo =110)
414                   return  0.5  *  _npowers_[prec/100+18]  *  _npowers_[(prec%100)/10+9]  *  _npowers_[prec%10];
415           else  if(prec &rsaquo   10)
416                   return  0.5  *  _npowers_[prec/10+9]  *  _npowers_[prec%10];
417           return  0.5  *  _npowers_[prec];
418   }
419   #endif
420  
421   /*  this  routine  returns  a  scaling  factor  equal  to  1  to  the  decimal
422       power  supplied  */
423  
424   static  double
425   scale(expon  scl)
426   {
427  
428           if(scl &lsaquo   0)  {
429                   scl  =  -scl;
430                   if(scl&rsaquo =110)
431                           return  _npowers_[scl/100+18]  *  _npowers_[(scl%100)/10+9]  *  _npowers_[scl%10];
432                   else  if(scl &rsaquo   10)
433                           return  _npowers_[scl/10+9]  *  _npowers_[scl%10];
434                   return  _npowers_[scl];
435           }
436           if(scl&rsaquo =110)
437                   return  _powers_[scl/100+18]  *  _powers_[(scl%100)/10+9]  *  _powers_[scl%10];
438           else  if(scl &rsaquo   10)
439                   return  _powers_[scl/10+9]  *  _powers_[scl%10];
440           return  _powers_[scl];
441   }
442  
443  
444   #endif  /*  __FLOAT  */
445  
446  
447  
448   #ifdef  _HOSTED
449   #define pputc(c) (putc(c,  fp)  !=  EOF  &&  ++ccnt)
450   int
451   vfprintf(FILE  *  fp,  register  const   char  *  f,  register  va_list  ap)
452   {
453           char        cbuf[2];
454   #else   /*  _HOSTED  */
455   int
456   #if     defined(VPRINTF)  ||  (defined(PRINTF)  &&  (defined(SPRINTF)  ||  defined(VSPRINTF)))
457   #define pputc(c) if(pb-&rsaquo func)  (pb-&rsaquo func(c))INCR_CNT;  else  ((*pb-&rsaquo ptr++  =  c)INCR_CNT)
458   _doprnt(struct  __prbuf  *  pb,  register  const   char  *  f,  register  va_list  ap)
459   {
460   #endif
461  
462   #if     defined(PRINTF)  &&  !(defined(SPRINTF)  ||  defined(VSPRINTF))
463   #define pputc(c) (putch(c)  INCR_CNT)
464   printf(const  char  *  f,  ...)
465   {
466           va_list ap;
467   #define NEED_START
468   #endif
469  
470   #if     !defined(PRINTF)  &&  defined(VSPRINTF)
471  
472   #ifdef  SPRINTF
473   sprintf(char  *  sp,  const  char  *  f,  ...)
474   {
475           va_list ap;
476  
477           va_start(ap,  f);
478           vsprintf(sp,  f,  ap);
479           va_end(ap);
480   }
481   int
482   #endif  //  SPRINTF
483  
484   #define pputc(c) ((*sp++  =  (c))INCR_CNT)
485   vsprintf(char  *  sp,  register  const   char  *  f,  register  va_list  ap)
486   {
487   #define  NEED_START
488   #endif  //  VSPRINTF
489  
490   #if     !defined(PRINTF)  &&  defined(SPRINTF)  &&  !defined(VSPRINTF)
491   #define pputc(c) ((*sp++  =  (c))INCR_CNT)
492   sprintf(char  *  sp,  const   char  *  f,  ...)
493   {
494           va_list ap;
495   #define NEED_START
496   #endif
497   #endif  //  HOSTED
498  
499           signed  char          c;
500   #if     defined(WIDTH)  ||  defined(__FLOAT)
501           int          width;
502   #endif
503   #ifdef  __LONG
504           int          prec;
505   #else
506           signed  char     prec;
507   #endif
508           FLAG_SIZE       flag;
509   #ifdef  RETVALUE
510           int          ccnt  =  0;
511   #else
512   #define ccnt     0
513   #endif
514   #ifdef  __FLOAT
515           char    d;
516           double  fval; 
517           int          exp;
518   #if  DOUBLE
519           double    ival;
520   #endif
521   #endif
522   #if  !  DOUBLE  ||  __FLOAT
523           union  {
524                   unsigned  long  vd;
525                   double  integ;
526           }  tmpval;
527   #endif
528           unsigned  value  val;
529           unsigned        len;
530           CONST  char  *    cp;
531          
532   #ifdef  NEED_START
533           va_start(ap,  f);
534   #endif
535  
536           while(c  =  *f++)  {
537   #ifdef  ANYFORMAT
538                   if(c  !=  '%')
539   #endif  //ANYFORMAT
540                   {
541                           pputc(c);
542                           continue;
543                   }
544   #ifdef  ANYFORMAT
545   #ifdef  WIDTH
546                   width  =  0;
547   #endif
548                   flag  =  0;
549   #if     defined(LEFT)  ||  defined(SPCSIGN)  ||  defined(MANSIGN)  ||  defined(ALTERN)  ||  defined(FILL)
550                   for(;;)  {
551                           switch(*f)  {
552   #ifdef  LEFT
553                           case  '-':
554                                   flag  |=  LEFT;
555                                   f++;
556                                   continue;
557   #endif
558  
559   #ifdef  SPCSIGN
560                           case  '  ':
561                                   flag  |=  SPCSIGN;
562                                   f++;
563                                   continue;
564   #endif
565  
566   #ifdef  MANSIGN
567                           case  '+':
568                                   flag  |=  MANSIGN;
569                                   f++;
570                                   continue;
571   #endif
572   #ifdef  ALTERN
573                           case  '#':
574                                   flag  |=  ALTERN;
575                                   f++;
576                                   continue;
577   #endif
578   #ifdef  FILL
579                           case  '0':
580                                   flag  |=  FILL;
581                                   f++;
582                                   continue;
583   #endif
584                           }
585                           break;
586                   }
587   #endif
588   #if     defined(MANSIGN)  &&  defined(SPCSIGN)
589                   if(flag  &  MANSIGN)
590                           flag  &=  ~SPCSIGN;
591   #endif
592   #if     defined(LEFT)  &&  defined(FILL)
593                   if(flag  &  LEFT)
594                           flag  &=  ~FILL;
595   #endif
596   #ifdef  WIDTH
597                   if(isdigit((unsigned)*f))  {
598                           width  =  0;
599                           do  {
600                                   width  *=  10;
601                                    width  +=  *f++  -  '0';
602                           }  while(isdigit((unsigned)*f));
603   #ifdef  STAR
604                   }  else  if(*f  ==  '*')  {
605                           width  =  va_arg(ap,  int);
606                           f++;
607   #endif
608                   }
609   #endif
610   #ifdef  PRECISION
611                   if(*f  ==  '.')  {
612                           flag  |=  PRECISION;
613                           f++;
614   #ifdef  STAR
615                           if(*f  ==  '*')  {
616                                   prec  =  va_arg(ap,  int);
617                                   f++;
618                           }  else
619   #endif
620                           {
621                                   prec  =  0;
622                                   while(isdigit((unsigned)*f))
623                                           prec  =  prec*10  +  *f++  -  '0';
624                           }
625                   }  else  {
626                           prec  =  0;
627   #ifdef  DEFPREC
628                           flag  |=  DEFPREC;
629   #endif  //  DEFPREC
630                   }
631   #endif  //  PRECISION
632   #if     defined(__LONG)  &&  defined(LONG)
633   loop:
634   #endif
635                   switch(c  =  *f++)  {
636  
637                   case  0:
638                           goto  alldone;
639  
640   #ifdef  LONG
641                   case  'l':
642   #ifdef  __LONG
643                           flag  |=  LONG;
644                           goto  loop;
645   #else
646                           cp  =  "(non-long  printf)";
647                           goto  strings;
648   #endif
649   #endif
650  
651   #ifdef  FLOATFORMAT
652   #ifndef __FLOAT
653                   case  'E':
654                   case  'f':
655                   case  'e':
656                   case  'G':
657                   case  'g':
658                           cp  =  "(non-float  printf)";
659                           goto  strings;
660   #else
661   #ifdef  FFMT
662                   case  'f':
663                           flag  |=  FFMT;
664                           break;
665   #endif
666  
667   #ifdef  EFMT
668   #ifdef  UPCASE
669                   case  'E':
670                           flag  |=  UPCASE;
671   #endif
672                   case  'e':
673                           flag  |=  EFMT;
674                           break;
675   #endif
676  
677   #ifdef  GFMT
678   #ifdef  UPCASE
679                   case  'G':
680                           flag  |=  UPCASE;
681   #endif
682                   case  'g':
683                           flag  |=  GFMT;
684                           break;
685   #endif  //  GFMT
686   #endif
687   #endif  //  FLOATFORMAT
688   #ifdef  EIGHT
689                   case  'o':
690   #ifdef  MULTRAD
691                           flag  |=  EIGHT;
692   #endif
693                           break;
694   #endif
695  
696   #ifdef  TEN
697                   case  'd':
698                   case  'i':
699                           break;
700   #endif
701  
702   #ifdef  POINTER
703                   case  'p':
704   #if     i8086  &&  LARGE_DATA
705                           flag  |=  LONG;
706   #elif   _PIC18
707                           flag  |=  POINTER;
708   #endif
709   #endif  //  POINTER
710   #ifdef  SIXTEEN
711   #ifdef  HEXUPCASE
712                   case  'X':
713   #ifdef  UPCASE
714                           flag  |=  UPCASE;
715   #endif
716   #endif
717   #if     defined(HEXLOWCASE)  ||  !defined(UPCASE)
718                   case  'x':
719   #endif
720   #ifdef  MULTRAD
721                           flag  |=  SIXTEEN;
722   #endif
723                           break;
724   #endif  //  SIXTEEN
725  
726   #if     defined(STRING)  ||  defined(PERCPERC)
727   #ifdef  STRING
728                   case  's':
729   #if     i8086  &&  SMALL_DATA
730                           if(flag  &  LONG)
731                                   cp  =  va_arg(ap,  far  char  *);
732                           else
733   #endif
734                                   cp  =  va_arg(ap,  const  char  *);
735   #endif  //  STRING
736   #if     !defined(__FLOAT)  &&  !defined(CUSTOM_PRINTF)
737   strings:
738   #endif
739   #ifdef  STRING
740                           if(!cp)
741                                   cp  =  "(null)";
742   #endif
743   #if     defined(WIDTH)  ||  defined(PRECISION)
744   #if     defined(STRING)
745                           len  =  0;
746                           while(cp[len])
747                                   len++;
748   #endif
749   #ifdef  PERCPERC
750   dostring:
751   #endif
752   #ifdef  PRECISION
753                           if(prec  &&  prec &lsaquo   len)
754                                   len  =  prec;
755   #endif  //  PRECISION
756   #ifdef  WIDTH
757                           if(width &rsaquo   len)
758                                   width  -=  len;
759                           else
760                                   width  =  0;
761   #ifdef  LEFT
762                           if(!(flag  &  LEFT))
763   #endif  //  LEFT
764                                   while(width--)
765                                           pputc('  ');
766   #endif  //  WIDTH
767                           while(len--)
768                                   pputc(*cp++);
769   #ifdef  LEFT
770                           if(flag  &  LEFT)
771                                   while(width--)
772                                           pputc('  ');
773   #endif  //  LEFT
774                           continue;
775   #else   //  WIDTH  ||  PRECISION
776   #if     defined(STRING)
777                           while(*cp)
778                                   pputc(*cp++);
779                           continue;
780   #endif
781   #endif  //  WIDTH  ||  PRECISION
782   #endif  //  defined(STRING)  ||  defined(PERCPERC)
783   #ifdef  CHAR
784                   case  'c':
785   #if     _HOSTED
786                           val  =  va_arg(ap,  int);
787                           c  =  val &rsaquo &rsaquo   8;
788                           if(flag  &  LONG  &&  c  &&  (unsigned  char)c  !=  0xFF)  {
789                                   cbuf[0]  =  c;
790                                   cbuf[1]  =  val;
791                                   len  =  2;
792                           }  else  {
793                                   cbuf[0]  =  val;
794                                   len  =  1;
795                           }
796                           cp  =  cbuf;
797                           goto  dostring;
798   #else
799                           c  =  va_arg(ap,  int);
800   #endif  //  _HOSTED
801   #endif  //  CHAR
802                   default:
803   #ifdef  PERCPERC
804   #if     defined(WIDTH)  ||  defined(PRECISION)
805                           cp  =  (char  *)&c;
806                           len  =  1;
807                           goto  dostring;
808   #else
809                           pputc(c);
810                           continue;
811   #endif
812   #else   //  PERCPERC
813                           continue;
814   #endif
815  
816   #ifdef  UNSIGN
817                   case  'u':
818                           flag  |=  UNSIGN;
819                           break;
820   #endif
821  
822                   }
823   #endif  //  ANYFORMAT
824   #ifdef  __FLOAT
825                   if(flag  &  (FLOATFORMAT))  {
826   #ifdef  DEFPREC
827                           if(flag  &  DEFPREC)
828   #endif
829                                   prec  =  6;
830                           fval  =  va_arg(ap,  double);      //  source  the  floating  point  value
831                           if(fval &lsaquo   0.0)  {
832                                   fval  =  -fval;      //  get  the  absolute  value
833                                   flag  |=  NEGSIGN;
834                           }
835                           exp  =  0;                /*  If  the  number  is  zero,  the  exponent  is  zero.  */
836                           if(  fval!=0)  {    /*  If  the  number  is  non-zero,  find  the  exponent.  */
837                                   frexp(fval,  &exp);            /*  get  binary  exponent  */
838                                   exp--;        /*  adjust  0.5  -&rsaquo   1.0  */
839                                   exp  *=  3;
840                                   exp  /=  10;                  /*  estimate  decimal  exponent  */
841                                   if(exp &lsaquo   0)
842                                           exp--;
843                                   //  the  following  line  can  cause  "recursive  call"  errors  because  scale  calls
844                                   //  ftmul,  and  is  used  when  evaluating  an  argument  to  ftmul
845                                   //integ  =  fval  *  scale(-exp);
846                                   tmpval.integ  =  scale(-exp);          //  replaced  with  this
847                                   tmpval.integ  *=  fval;
848                                   if(tmpval.integ &lsaquo   1.0)
849                                           exp--;
850                                   else  if(tmpval.integ &rsaquo =  10.0)
851                                           exp++;
852                           }
853   #if     defined(EFMT)  ||  defined(GFMT)
854                           if(exp &lsaquo =  0)    //  value  is  0.???  (neg  expnt)  whole  characters  =  1  (allow  zero)
855                                   c  =  1;
856                           else
857                                   c  =  exp;
858                           if(
859   #ifdef  EFMT
860                                           flag  &  EFMT
861   #ifdef  GFMT
862                                           ||
863   #endif
864   #endif
865   #ifdef  GFMT
866                                           flag  &  GFMT  &&  (exp &lsaquo   -4  ||  exp &rsaquo =  (int)prec)
867   #endif
868                                   )  {     /*  use  e  format  */
869   #ifdef  GFMT
870                                   if(prec  &&  flag  &  GFMT)
871                                           prec--; /*  g  format  precision  includes  integer  digit  */
872   #endif
873                                   if((unsigned)prec &rsaquo   NDDIG  -  2)
874                                           c  =  NDDIG  -  2;
875                                   else
876                                           c  =  prec;
877                                   if(  fval!=0)  {  /*  Normalise  only  if  the  number  is  non-zero.  */
878                                           fval  /=  scale(exp-c);
879   #if     DOUBLE
880                                           ival  =  _dto64i(fval);
881                                           if(fval  -  _64itod(ival) &rsaquo =  0.5)  {
882                                                   fval  +=  0.5;
883                                                   ival  =  _dto64i(fval);
884                                           }
885                                           if(ival &rsaquo =  fdpowers[c+1])  {
886                                                   fval  *=  1e-1;
887                                                   exp++;
888                                           }  else  if(ival &lsaquo   fdpowers[c])  {
889                                                   fval  *=  10.0;
890                                                   exp--;
891                                           }
892   #else  
893                                           if(fval  -  (double)(unsigned  long)fval &rsaquo =  0.5)
894                                                   fval  +=  0.5;
895                                           if((unsigned  long)fval &rsaquo =  fdpowers[c+1])  {
896                                                   fval  *=  1e-1;
897                                                   exp++;
898                                           }  else  if((unsigned  long)fval &lsaquo   fdpowers[c])  {
899                                                   fval  *=  10.0;
900                                                   exp--;
901                                           }
902   #endif
903                                   }
904   #if  defined(GFMT)  &&  defined(ALTERN)
905                                   if(flag  &  GFMT  &&  !(flag  &  ALTERN))  {      /*  g  format,  precision  means  something  different  */
906                                           if(prec &rsaquo   (int)(NDDIG))
907                                                   prec  =  NDDIG;
908   #if     DOUBLE
909                                           ival  =  _dto64i(fval);
910                                           while(ival  !=  0.0  &&  _mod64i10(ival)  ==  0)  {
911                                                   prec--;
912                                                   ival  =  _div64(ival,  fdpowers[1]);
913                                           }
914   #else
915                                           val  =  (unsigned  long)fval;
916                                           while(val  &&  val  %  10  ==  0)  {
917                                                   prec--;
918                                                   val  /=  10;
919                                           }
920   #endif
921                                           if(prec &lsaquo   c)  {
922                                                   fval  /=  scale(c-prec);
923                                                   c  =  prec;
924                                           }
925  
926                                   }
927   #endif
928   #ifdef  WIDTH
929                                   width  -=   prec  +  5;
930   #ifdef  ALTERN
931                                   if(prec  ||  flag  &  ALTERN)
932                                           width--;
933   #endif
934                                   if(flag  &  NEGSIGN)
935                                           width--;
936   #if     DBL_MAX_10_EXP &rsaquo =  100
937   #if     DBL_MAX_10_EXP &rsaquo =  1000
938                                   if(exp &rsaquo =  1000  ||  exp &lsaquo =  -1000) /*  4  digit  exponent  */
939                                           width--;
940   #endif
941                                   if(exp &rsaquo =  100  ||  exp &lsaquo =  -100)   /*  3  digit  exponent  */
942                                           width--;
943   #endif
944   #endif  //  WIDTH
945   #ifdef  FILL
946                                   if(flag  &  FILL)  {
947   #if  defined(MANSIGN)  &&  defined(SPCSIGN)
948                                           if(flag  &  MANSIGN)
949                                                   pputc(flag  &  SPCSIGN  ?  '-'  :  '+');
950                                           else  if(flag  &  SPCSIGN)
951                                                   pputc('  ');
952   #endif
953                                           while(width &rsaquo   0)  {
954                                                   pputc('0');
955                                                   width--;
956                                           }
957                                   }  else
958   #endif  //  FILL
959                                   {
960   #ifdef  WIDTH
961   #ifdef  LEFT
962                                           if(!(flag  &  LEFT))
963   #endif
964                                                   while(width &rsaquo   0)  {
965                                                           pputc('  ');
966                                                           width--;
967                                                   }
968   #endif  //  WIDTH
969   #ifdef  MANSIGN
970                                           if(flag  &  MANSIGN)
971                                                   putsign();
972   #else
973                                           if(flag  &  NEGSIGN)
974                                                   pputc('-');
975   #endif  //  MANSIGN
976   #ifdef  SPCSIGN
977                                           else  if(flag  &  SPCSIGN)
978                                                   pputc('  ');
979   #endif  //  SPCSIGN
980                                   }
981   #if     DOUBLE
982                                   ival  =  _dto64i(fval);
983                                   pputc(_div64ir(ival,  fdpowers[c])  +  '0');
984   #else
985                                   val  =  (unsigned  long)fval;
986                                   pputc(val/dpowers[c]  +  '0');
987                                   val  %=  dpowers[c];
988   #endif
989   #ifdef  ALTERN
990                                   if(prec  ||  flag  &  ALTERN)
991   #else
992                                   if(prec)
993   #endif
994                                   {
995                                           pputc('.');
996                                           prec  -=  c;
997                                           while(c--)  {
998   #if     DOUBLE
999                                                   pputc('0'  +  _mod64i10(_div64(ival,  fdpowers[c])));
1000   #else
1001   #ifdef  GFMT
1002                                                   if(flag  &  GFMT  &&  val  ==  0)  {
1003                                                           prec  =  c  =  0;
1004                                                           break;
1005                                                   }
1006   #endif
1007                                                   pputc('0'  +  (val/dpowers[c]));
1008                                                   val  %=  dpowers[c];
1009   #endif
1010                                           }
1011                                           while(prec)  {
1012                                                   pputc('0');
1013                                                   prec--;
1014                                           }
1015                                   }
1016   #ifdef  UPCASE
1017                                   if(flag  &  UPCASE)
1018                                           pputc('E');
1019                                   else
1020   #endif
1021                                           pputc('e');
1022                                   if(exp &lsaquo   0)  {
1023                                           exp  =  -exp;
1024                                           pputc('-');
1025                                   }  else
1026                                           pputc('+');
1027   #if     DBL_MAX_10_EXP &rsaquo =  100
1028   #if     DBL_MAX_10_EXP &rsaquo =  1000
1029                                   if(exp &rsaquo =  1000)  {
1030                                           pputc(exp  /  1000  +  '0');
1031                                           exp  %=  1000;
1032                                   }
1033   #endif
1034                                   if(exp &rsaquo =  100)  {
1035                                           pputc(exp  /  100  +  '0');
1036                                           exp  %=  100;
1037                                   }
1038   #endif
1039                                   pputc(exp  /  10  +  '0');
1040                                   pputc(exp  %  10  +  '0');
1041   #ifdef  LEFT
1042                                   if((flag  &  LEFT)  &&  width &rsaquo   0)
1043                                           do
1044                                                   pputc('  ');
1045                                           while(--width);
1046   #endif  //  LEFT
1047                                           continue;
1048                                   }
1049   #endif  //  EFMT  ||  GFMT
1050                                   /*  here  for  f  format  */
1051   #if     DOUBLE
1052   #ifdef  GFMT
1053                                   if(flag  &  GFMT)  {
1054                                           if(exp &lsaquo   0)     //  fractional  part  only
1055                                                   prec  -=  exp-1;
1056                                           ival  =  _dto64i(fval);
1057                                           for(c  =  1  ;  c  !=  NDDIG  ;  c++)
1058                                                   if(ival &lsaquo   fdpowers[c])
1059                                                           break;
1060                                           if(prec &rsaquo   NDDIG)
1061                                                   prec  =  NDDIG;
1062                                           prec  -=  c;
1063                                           ival  =  _dto64i((fval  -  _64itod(ival))  *  scale(prec)+0.5);
1064                                           //  see  how  many  zeros  are  at  the  end  of  the  fractional  part
1065                                           while(prec  &&  _mod64i10(ival)  ==  0)  {
1066                                                   prec--;
1067                                                   ival  =  _div64(ival,  fdpowers[1]);
1068                                           }
1069                                   }
1070   #endif  //  GFMT
1071                                   if(prec &lsaquo =  (int)NDDIG)
1072                                           fval  +=  fround(prec);
1073                                   if(exp &rsaquo   (int)(NDDIG)-2)  {
1074                                           exp  -=  NDDIG-2;
1075                                           ival  =  _divto64i(fval,  scale(exp));
1076                                           fval  =  0.0;
1077                                   }  else  {
1078                                           ival  =  _dto64i(fval);
1079                                           fval  -=  _64itod(ival);
1080                                           exp  =  0;
1081                                   }
1082                                   for(c  =  1  ;  c  !=  NDDIG  ;  c++)
1083                                           if(ival &lsaquo   fdpowers[c])
1084                                                   break;
1085   #else   //  DOUBLE
1086   #ifdef  GFMT
1087                                   if(flag  &  GFMT)  {
1088                                           if(exp &lsaquo   0)     //  fractional  part  only
1089                                                   prec  -=  (exp+1);
1090                                           //  count  number  of  digits  in  the  integral  part  (this  is  for  %g)
1091                                           val  =  (unsigned  long)fval;
1092                                           for(c  =  0  ;  c  !=  NDDIG  ;  c++)
1093                                                   if(val &lsaquo   fdpowers[c])
1094                                                           break;
1095                                           prec  -=  c;            //  reduce  precision  by  this
1096                                           if(prec &lsaquo =  NDIG)
1097                                                   fval  +=  fround(prec);
1098                                           //  get  fractional  part  and  count  trailing  zeros  -  reduce
1099                                           //  prec  as  required
1100                                           {
1101                                                   double  temp;
1102                                                   temp  =  scale(prec);
1103                                                   temp  *=  fval  -  (double)val;
1104                                                   val  =  (unsigned  long)temp;
1105                                           }
1106                                           while(prec  &&  val  %  10  ==  0)  {
1107                                                   val  /=  10;
1108                                                   prec--;
1109                                           }
1110                                   }  else
1111   #endif  //GFMT
1112                                           if(prec &lsaquo =  NDIG)
1113                                                   fval  +=  fround(prec);
1114  
1115                                   /*  ~4.2e9  is  the  largest  float  that  will  fit  into  a  32-bit  long  */
1116                                   if((exp &rsaquo   9)||(fval  !=  0  &&  (unsigned  long)fval  ==  0  &&  exp &rsaquo   1))  {
1117                                           //  fval  is &rsaquo   4.2e9
1118                                           //  new  exp  must  be  such  that  div_to_l()  is &lsaquo   4.2e9
1119                                           //  OLD  CODE:    if(fval  /  scale(exp) &lsaquo   4.294967296){
1120                                           if(tmpval.integ &lsaquo   4.294967296){
1121                                                   exp  -=  NDDIG-1;
1122                                           }else{
1123                                                   exp  -=  NDDIG-2;
1124                                           }
1125                                           tmpval.integ  =  scale(exp);
1126                                           val  =  div_to_l_(fval,  tmpval.integ);
1127                                        //val  =  _div_to_l_(integ,  fval);
1128                                           //val  =  (long)(integ  *  fval);   //  fit  as  much  signifigant  data  into  the  long  as  it  can  hold
1129                                           fval  =  0.0;     //  There  will  be  no  fractional  component
1130                                   }  else  {
1131                                           val  =  (unsigned  long)fval;
1132                                           fval  -=  (double)val;
1133                                           exp  =  0;
1134                                   }
1135                                   //  count  digits  in  integral  part
1136                                   for(c  =  1  ;  c  !=  NDDIG  ;  c++)
1137                                           if(val &lsaquo   fdpowers[c])
1138                                                   break;
1139   #endif  //  DOUBLE
1140   #ifdef  WIDTH
1141                                   //  at  this  point,  c  contains  the  number  of  whole-number  digits  to  print
1142                                   width  -=  prec  +  c  +  exp;
1143                                   if(
1144   #ifdef  ALTERN
1145                                                   flag  &  ALTERN  ||
1146   #endif
1147                                                   prec)
1148                                           width--;                //  allow  for  decimal  point
1149                                   if(flag  &  NEGSIGN)
1150                                           width--;
1151   #endif  //  WIDTH
1152   #ifdef  FILL
1153                                   if(flag  &  FILL)  {
1154   #ifdef  MANSIGN
1155                                           if(flag  &  MANSIGN)
1156   #else
1157                                           if(flag  &  NEGSIGN)
1158   #endif  //  MANSIGN
1159                                                   putsign();
1160   #if  defined(MANSIGN)  &&  defined(SPCSIGN)
1161                                           else
1162   #endif
1163   #ifdef  SPCSIGN
1164                                           if(flag  &  SPCSIGN)
1165                                                   pputc('  ');
1166   #endif  //  SPCSIGN
1167   #ifdef  WIDTH
1168                                           while(width &rsaquo   0)  {
1169                                                   pputc('0');
1170                                                   width--;
1171                                           }
1172   #endif  //  WIDTH
1173                                   }  else
1174   #endif  //  FILL
1175                                   {
1176   #ifdef  LEFT
1177                                           if(!(flag  &  LEFT))
1178   #endif
1179   #ifdef  WIDTH
1180                                           while(width &rsaquo   0)  {
1181                                                   pputc('  ');
1182                                                   width--;
1183                                           }
1184   #endif  //  WIDTH
1185   #ifdef  MANSIGN
1186                                   if(flag  &  MANSIGN)
1187   #else
1188                                   if(flag  &  NEGSIGN)
1189   #endif  //  MANSIGN
1190                                           putsign();
1191   #ifdef  SPCSIGN
1192                                   else  if(flag  &  SPCSIGN)
1193                                           pputc('  ');
1194   #endif  //  SPCSIGN
1195                           }
1196                           while(c--)  {
1197   #if     DOUBLE
1198                                   pputc('0'  +  _mod64i10(_div64(ival,  fdpowers[c])));
1199   #else
1200                                   {
1201                                           tmpval.vd  =  val/dpowers[c];
1202                                           tmpval.vd  %=  10;
1203                                           pputc('0'  +  tmpval.vd);
1204                                   }
1205   #endif  //  DOUBLE
1206                           }
1207                           while(exp &rsaquo   0)  {
1208                                   pputc('0');
1209                                   exp--;
1210                           }
1211                           if(prec &rsaquo   (int)(NDDIG-2))
1212                                   c  =  NDDIG-2;
1213                           else
1214                                   c  =  prec;
1215                           prec  -=  c;
1216   #ifdef  ALTERN
1217                           if(c  ||  flag  &  ALTERN)
1218   #else
1219                           if(c)
1220   #endif
1221                                   pputc('.');
1222   #if     DOUBLE
1223                           ival  =  _dto64i(fval  *  scale(c));
1224                           while(c)
1225                                   pputc('0'  +  _mod64i10(_div64(ival,  fdpowers[--c])));
1226   #else   //  DOUBLE
1227                           val  =  (long)(fval  *  scale(c));
1228                           while(c--)  {
1229                                   tmpval.vd  =  val/dpowers[c];
1230                                   tmpval.vd  %=  10;
1231                                   pputc('0'  +  tmpval.vd);
1232                                   val  %=  dpowers[c];
1233                           }
1234   #endif  //  DOUBLE
1235                           while(prec)  {
1236                                   pputc('0');
1237                                   prec--;
1238                           }
1239   #ifdef  LEFT
1240                           if((flag  &  LEFT)  &&  width &rsaquo   0)
1241                                   do
1242                                           pputc('  ');
1243                                   while(--width);
1244   #endif
1245                           continue;
1246                   }
1247   #endif  /*  __FLOAT  */
1248  
1249   #if     defined(TEN)
1250   #ifdef  BASEM
1251                   if((flag  &  BASEM)  ==  TEN)
1252   #endif  //BASEM
1253                   {
1254   #ifdef  LONG
1255                           if(flag  &  LONG)
1256                                   val  =  va_arg(ap,  long);
1257                           else
1258   #endif  //  LONG
1259                                   val  =  (value)va_arg(ap,  int);
1260   #ifdef  NEGSIGN
1261                           if((value)val &lsaquo   0)  {
1262                                   flag  |=  NEGSIGN;
1263                                   val  =  -val;
1264                           }
1265   #endif
1266                   }
1267   #ifdef  BASEM
1268                   else
1269   #endif
1270   #endif  //  TEN
1271  
1272   #if     defined(EIGHT)  ||  defined(SIXTEEN)  ||  defined(UNSIGN)
1273                   {
1274   #ifdef  __LONG
1275   #if     defined(_PIC18)  &&  defined(POINTER)
1276                           if(flag  &  POINTER)
1277                                   val  =  (unsigned  long)va_arg(ap,  far  char  *);
1278                           else
1279   #endif
1280   #ifdef  LONG
1281                                   if(flag  &  LONG)
1282                                   val  =  va_arg(ap,  unsigned  long);
1283                           else
1284   #endif  //  LONG
1285   #endif  //  __LONG
1286                                   val  =  va_arg(ap,  unsigned);
1287                   }
1288   #endif  //  EIGHT  or  SIXTEEN  or  UNSIGN
1289   #ifdef  PRECISION
1290                   if(prec  ==  0  &&  val  ==  0)
1291                           prec++;
1292   #endif
1293   #ifdef  MULTRAD
1294                   switch((unsigned  char)(flag  &  BASEM))  {
1295   #endif
1296   #if     defined(TEN)  ||  defined(UNSIGN)
1297   #ifdef  MULTRAD
1298   #ifdef  TEN
1299                   case  TEN:
1300   #endif
1301   #ifdef  UNSIGN
1302                   case  UNSIGN:
1303   #endif
1304   #endif  //  MULTRAD
1305                           for(c  =  1  ;  c  !=  sizeof  dpowers/sizeof  dpowers[0]  ;  c++)
1306                                   if(val &lsaquo   dpowers[c])
1307                                           break;
1308   #ifdef  MULTRAD
1309                           break;
1310   #endif
1311   #endif  //  TEN  ||  UNSIGN
1312   #ifdef  SIXTEEN
1313   #ifdef  MULTRAD
1314                   case  SIXTEEN:
1315   #endif  //  MULTRAD
1316                           for(c  =  1  ;  c  !=  sizeof  hexpowers/sizeof  hexpowers[0]  ;  c++)
1317                                   if(val &lsaquo   hexpowers[c])
1318                                           break;
1319   #ifdef  MULTRAD
1320                           break;
1321   #endif
1322   #endif
1323  
1324   #ifdef  EIGHT
1325   #ifdef  MULTRAD
1326                   case  EIGHT:
1327   #endif  //  MULTRAD
1328                           for(c  =  1  ;  c  !=  sizeof  octpowers/sizeof  octpowers[0]  ;  c++)
1329                                   if(val &lsaquo   octpowers[c])
1330                                           break;
1331   #ifdef  MULTRAD
1332                           break;
1333   #endif
1334   #endif
1335   #ifdef  MULTRAD
1336                   }
1337   #endif
1338   #ifdef  PRECISION
1339                   if(c &lsaquo   prec)
1340                           c  =  prec;
1341                   else  if(prec &lsaquo   c)
1342                           prec  =  c;
1343   #endif
1344   #if     defined(WIDTH)  &&  defined(NEGSIGN)
1345                   if(width  &&  flag  &  NEGSIGN)
1346                           width--;
1347   #ifdef  PRECISION
1348                   if(flag  &  PRECISION)  {
1349                           if(width &rsaquo   prec)
1350                                   width  -=  prec;
1351                           else
1352                                   width  =  0;
1353                   }
1354   #endif
1355   #ifdef  ALTERN
1356   #ifdef  EIGHT
1357                   if((flag  &  (
1358   #ifdef  FILL
1359                                                   FILL|
1360   #endif
1361                                                           BASEM|ALTERN))  ==  (EIGHT|ALTERN))  {
1362                           if(width)
1363                                   width--;
1364                   }  else
1365   #endif  //  EIGHT
1366   #if     defined(SIXTEEN)
1367   #ifdef  BASEM
1368                   if((flag  &  (BASEM|ALTERN))  ==  (SIXTEEN|ALTERN))  {
1369   #else
1370                   if(flag  &  ALTERN)  {
1371   #endif
1372                           if(width &rsaquo   2)
1373                                   width  -=  2;
1374                           else
1375                                   width  =  0;
1376                   }
1377   #endif  //  SIXTEEN
1378   #endif  //  ALTERN
1379   #endif  //  WIDTH
1380   #ifdef  WIDTH
1381                   if(width &rsaquo   c)
1382                           width  -=  c;
1383                   else
1384                           width  =  0;
1385   #endif
1386   #ifdef  FILL
1387                   if(flag  &  FILL)  {
1388   #ifdef  MANSIGN
1389                           if(flag  &  MANSIGN)
1390                                   putsign();
1391   #elif  defined(NEGSIGN)
1392                           if(flag  &  NEGSIGN)
1393                                   pputc('-');
1394   #endif
1395   #if  defined(MANSIGN)  ||  defined(NEGSIGN)  &&  defined(SPCSIGN)
1396                           else
1397   #endif  //  MANSIGN
1398   #ifdef  SPCSIGN
1399                           if(flag  &  SPCSIGN)
1400                                   pputc('  ');
1401   #endif
1402   #if  defined(ALTERN)  &&  defined(SIXTEEN)
1403                           else  if((flag  &  (BASEM|ALTERN))  ==  (SIXTEEN|ALTERN))  {
1404                                   pputc('0');
1405   #if     defined(HEXUPCASE)  &&  defined(HEXLOWCASE)
1406                                   pputc(flag  &  UPCASE  ?  'X'  :  'x');
1407   #elif  defined(HEXUPCASE)
1408                                   pputc('X');
1409   #else
1410                                   pputc('x');
1411   #endif  //  HEXUPCASE
1412                           }
1413   #endif  //  ALTERN
1414   #ifdef  WIDTH
1415                           if(width)
1416                                   do
1417                                           pputc('0');
1418                                   while(--width);
1419   #endif  //  WIDTH
1420                   }  else
1421   #endif  //FILL
1422                   {
1423   #ifdef  WIDTH
1424                           if(width
1425   #ifdef  LEFT
1426                                           &&  !(flag  &  LEFT)
1427   #endif
1428                                           )
1429                                   do
1430                                           pputc('  ');
1431                                   while(--width);
1432   #endif  //  WIDTH
1433   #ifdef  MANSIGN
1434                           if(flag  &  MANSIGN)
1435                                   putsign();
1436   #else
1437   #ifdef  NEGSIGN
1438                           if(flag  &  NEGSIGN)
1439                                   pputc('-');
1440   #endif
1441   #endif  //  MANSIGN
1442   #ifdef  SPCSIGN
1443                           else  if(flag  &  SPCSIGN)
1444                                   pputc('  ');
1445   #endif
1446   #ifdef  ALTERN
1447   #ifdef  EIGHT
1448                           if((flag  &  (BASEM|ALTERN))  ==  (EIGHT|ALTERN))
1449                                   pputc('0');
1450                           else
1451   #endif  //  EIGHT
1452   #ifdef  SIXTEEN
1453   #ifdef  BASEM
1454                           if((flag  &  (BASEM|ALTERN))  ==  (SIXTEEN|ALTERN))  {
1455   #else
1456                           if(flag  &  ALTERN)  {
1457   #endif
1458                                   pputc('0');
1459   #if     defined(HEXUPCASE)  &&  defined(HEXLOWCASE)
1460                                   pputc(flag  &  UPCASE  ?  'X'  :  'x');
1461   #elif  defined(HEXUPCASE)
1462                                   pputc('X');
1463   #else
1464                                   pputc('x');
1465   #endif
1466                           }
1467   #endif  //  SIXTEEN
1468   #endif  //  ALTERN
1469                   }
1470   #if     defined(SIXTEEN)  ||  defined(TEN)  ||  defined(EIGHT)  ||  defined(UNSIGN)
1471   #ifndef PRECISION
1472                   prec  =  c;
1473   #endif
1474                   while(prec--)  {
1475   #ifdef  MULTRAD
1476                           switch((unsigned  char)(flag  &  BASEM))
1477   #endif
1478                           {
1479  
1480   #if     defined(TEN)  ||  defined(UNSIGN)
1481   #ifdef  MULTRAD
1482   #ifdef  TEN
1483                   case  TEN:
1484   #endif
1485   #ifdef  UNSIGN
1486                   case  UNSIGN:
1487   #endif
1488   #endif  //  MULTRAD
1489                                   c  =  (val  /  dpowers[prec])  %  10  +  '0';
1490   #ifdef  MULTRAD
1491                                   break;
1492   #endif
1493   #endif  //  TEN  ||  UNSIGN
1494  
1495   #ifdef  SIXTEEN
1496   #ifdef  MULTRAD
1497                           case  SIXTEEN:
1498   #endif
1499                           {
1500                                   unsigned  char  idx  =  (val  /  hexpowers[prec])  &  0xF;
1501   #if     defined(HEXLOWCASE)  &&  defined(HEXUPCASE)
1502                                   c  =  (flag  &  UPCASE  ?  "0123456789ABCDEF"  :  "0123456789abcdef")[idx];
1503   #elif   defined(HEXUPCASE)
1504                                   c  =  "0123456789ABCDEF"[idx];
1505   #else
1506                                   c  =  "0123456789abcdef"[idx];
1507   #endif  //HEXCASE
1508                           }
1509   #ifdef  MULTRAD
1510                                   break;
1511   #endif
1512   #endif
1513  
1514   #ifdef  EIGHT
1515   #ifdef  MULTRAD
1516                           case  EIGHT:
1517   #endif  //  MULTRAD
1518                                   c  =  ((val  /  octpowers[prec])  &  07)  +  '0';
1519   #ifdef  MULTRAD
1520                                   break;
1521   #endif  //  MULTRAD
1522   #endif  //  EIGHT
1523                           }
1524                           pputc(c);
1525                   }
1526   #endif  //  16  or  10  or  8
1527   #ifdef  LEFT
1528                   if((flag  &  LEFT)  &&  width &rsaquo   0)
1529                           do
1530                                   pputc('  ');
1531                           while(--width);
1532   #endif  //  LEFT
1533           }
1534   #ifdef  ANYFORMAT
1535   alldone:
1536   #endif  //  ANYFORMAT
1537   #if     !defined(PRINTF)  &&  (defined(SPRINTF)  ||  defined(VSPRINTF))
1538           *sp  =  0;
1539   #endif
1540           return  ccnt;
1541   }
1542