00001 #include <stdio.h>
00002
00003
00004
00005
00006
00007
00008
00009
00010 # define PUTCHAR(c) putc((c),stream)
00011 # define PRINTN(n,b) printn(stream,(n),(b))
00012
00013 void
00014 fgenf(stream,fmt)
00015 FILE *stream;
00016 char *fmt;
00017 {
00018 register char *s;
00019 register int *adx;
00020 register int c;
00021 int argno;
00022 char cmd;
00023 long num;
00024 int base;
00025
00026 while( (c = *fmt++) != 0 ) {
00027 switch(c) {
00028 case '%':
00029 argno = 0;
00030 while( ((c = *fmt) >= '0') && (c <= '9') ) {
00031 argno = (argno * 10) + (c - '0');
00032 fmt++;
00033 }
00034 adx = ((int *)(&fmt)) + argno;
00035 switch( cmd = *fmt++ ) {
00036 case 'd':
00037 PRINTN((long)(*adx),10);
00038 break;
00039 case 'u':
00040 PRINTN((long)((unsigned)(*adx)),10);
00041 break;
00042 case 'o':
00043 PRINTN((long)(*adx),8);
00044 break;
00045 case 'x':
00046 PRINTN((long)(*adx),16);
00047 break;
00048 case 'D':
00049 case 'U':
00050 PRINTN(*((long *)adx),10);
00051 break;
00052 case 'O':
00053 PRINTN(*((long *)adx),8);
00054 break;
00055 case 'X':
00056 PRINTN(*((long *)adx),16);
00057 break;
00058 case 's':
00059 s = (char *)(*adx);
00060 while((c = *s++) != 0 ) {
00061 PUTCHAR(c);
00062 }
00063 break;
00064 case 'c':
00065 c = *adx;
00066 PUTCHAR( c );
00067 break;
00068 }
00069 break;
00070 default:
00071 PUTCHAR(c);
00072 break;
00073 }
00074 }
00075
00076 }
00077
00078
00079
00080
00081 printn(stream,n,b)
00082 FILE *stream;
00083 long n;
00084 unsigned b;
00085 {
00086 long a;
00087
00088 if( n < 0 ) {
00089 PUTCHAR('-');
00090 n = (long)(-n);
00091 }
00092 if( (a = n/b) != 0 )
00093 printn(a,b);
00094 PUTCHAR( (unsigned)((n % b) + '0') );
00095 }