head 1.3; access; symbols SFIO_1999:1.1.1.3 SFIO_1998:1.1.1.2 SFIO_1997:1.1.1.1 ATT:1.1.1; locks; strict; comment @ * @; 1.3 date 99.09.11.13.20.43; author rse; state Exp; branches; next 1.2; 1.2 date 99.09.11.12.42.11; author rse; state Exp; branches; next 1.1; 1.1 date 96.11.30.22.28.35; author rse; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 96.11.30.22.28.35; author rse; state Exp; branches; next 1.1.1.2; 1.1.1.2 date 98.05.20.01.35.45; author rse; state Exp; branches; next 1.1.1.3; 1.1.1.3 date 99.08.04.17.53.22; author rse; state Exp; branches; next ; desc @@ 1.3 log @Merge in Sfio 1999 changes @ text @#include "sftest.h" /* static char Buf[128]; */ typedef struct _coord_ { int x; int y; } Coord_t; Coord_t Coord; #if __STD_C static int coordprint(Sfio_t* f, Void_t* v, Sffmt_t* fe) #else static int coordprint(f, v, fe) Sfio_t* f; Void_t* v; Sffmt_t* fe; #endif { char type[128]; Coord_t* cp; if(fe->fmt != 'c') return -1; cp = va_arg(fe->args,Coord_t*); memcpy(type,fe->t_str,fe->n_str); type[fe->n_str] = 0; *((char**)v) = sfprints(type,cp->x,cp->y); fe->fmt = 's'; fe->size = sfslen(); fe->flags |= SFFMT_VALUE; return 0; } int OXcount; #if __STD_C static int OXprint(Sfio_t* f, Void_t* v, Sffmt_t* fe) #else static int OXprint(f, v, fe) Sfio_t* f; Void_t* v; Sffmt_t* fe; #endif { OXcount += 1; switch(fe->fmt) { case 'd' : *((int*)v) = 10; fe->flags |= SFFMT_VALUE; return 0; case 'O' : fe->fmt = 'o'; *((int*)v) = 11; fe->flags |= SFFMT_VALUE; return 0; case 'X' : fe->fmt = 'x'; *((int*)v) = 12; fe->flags |= SFFMT_VALUE; return 0; } return 0; } #if __STD_C static int abprint(Sfio_t* f, Void_t* v, Sffmt_t* fe) #else static int abprint(f, v, fe) Sfio_t* f; Void_t* v; Sffmt_t* fe; #endif { switch(fe->fmt) { case 'a' : fe->fmt = 'u'; return 0; case 'b' : fe->fmt = 'd'; return 0; case 'z' : /* test return value of extension function */ fe->size = 10; fe->fmt = 's'; return 0; case 'Z' : /* terminate format processing */ default : return -1; } } #if __STD_C static int intarg(Sfio_t* f, Void_t* val, Sffmt_t* fe) #else static int intarg(f, val, fe) Sfio_t* f; Void_t* val; Sffmt_t* fe; #endif { static int i = 1; *((int*)val) = i++; fe->flags |= SFFMT_VALUE; return 0; } #if __STD_C static int shortarg(Sfio_t* f, Void_t* val, Sffmt_t* fe) #else static int shortarg(f, val, fe) Sfio_t* f; Void_t* val; Sffmt_t* fe; #endif { static short i = -2; *((short*)val) = i++; fe->size = sizeof(short); fe->flags |= SFFMT_VALUE; return 0; } #if __STD_C static int transarg(Sfio_t* f, Void_t* val, Sffmt_t* fe) #else static int transarg(f, val, fe) Sfio_t* f; Void_t* val; Sffmt_t* fe; #endif { switch(fe->fmt) { case 'D' : fe->fmt = 'd'; return 0; case 'O' : fe->fmt = 'o'; return 0; case 'F' : fe->fmt = 'f'; return 0; case 'S' : fe->fmt = 's'; return 0; case 'C' : fe->fmt = 'c'; return 0; default : return -1; } } #if __STD_C static void stkprint(char* buf, int n, char* form, ...) #else static void stkprint(buf,n,form,va_alist) char* buf; int n; char* form; va_dcl #endif { va_list args; Sffmt_t fe; #if __STD_C va_start(args,form); #else va_start(args); #endif fe.form = form; va_copy(fe.args,args); fe.extf = NIL(Sffmtext_f); fe.eventf = NIL(Sffmtevent_f); sfsprintf(buf,n,"%! %d %d",&fe,3,4); va_end(args); } int main() { char buf1[1024], buf2[1024], *list[4], *s; double x=0.0051; int i, j; long k; Sffmt_t fe; Sfio_t* f; f = sfopen(NIL(Sfio_t*), Kpv[0], "w+"); unlink(Kpv[0]); sfsetbuf(f,buf1,10); sfprintf(f,"%40s\n","0123456789"); sfsprintf(buf2,sizeof(buf2),"%40s","0123456789"); sfseek(f,(Sfoff_t)0,0); if(!(s = sfgetr(f,'\n',1)) ) terror("Failed getting string\n"); if(strcmp(s,buf2) != 0) terror("Failed formatting %%s\n"); sfsprintf(buf1,sizeof(buf1),"%4d %4o %4x", 10, 11, 11); sfsprintf(buf2,sizeof(buf2),"%2$4d %1$4o %1$4x", 11, 10); if(strcmp(buf1,buf2) != 0) terror("Failed testing $position\n"); sfsprintf(buf1,sizeof(buf1),"%d %1$d %.*d %1$d", 10, 5, 300); sfsprintf(buf2,sizeof(buf2),"%d %1$d %3$.*2$d %1$d", 10, 5, 300); if(strcmp(buf1,buf2) != 0) terror("Failed testing $position with precision\n"); fe.version = SFIO_VERSION; fe.form = NIL(char*); fe.extf = OXprint; fe.eventf = NIL(Sffmtevent_f); sfsprintf(buf1,sizeof(buf1),"%4d %4o %4x %4o %4x", 10, 11, 12, 11, 10); sfsprintf(buf2,sizeof(buf2),"%!%2$4d %3$4O %4$4X %3$4O %2$4x", &fe); if(strcmp(buf1,buf2) != 0) terror("Failed testing $position2\n"); if(OXcount != 3) terror("Failed OXprint called wrong number of times %d\n",OXcount); sfsprintf(buf1,sizeof(buf1),"%6.2f",x); if(strcmp(buf1," 0.01") != 0) terror("%%f rounding wrong\n"); fe.version = SFIO_VERSION; fe.form = NIL(char*); fe.extf = abprint; fe.eventf = NIL(Sffmtevent_f); sfsprintf(buf1,sizeof(buf1),"%%sX%%d%..4u %..4d9876543210",-1,-1); sfsprintf(buf2,sizeof(buf2),"%!%%sX%%d%..4a %..4b%z%Zxxx", &fe, -1, -1, "9876543210yyyy" ); if(strcmp(buf1,buf2) != 0) terror("%%!: Extension function failed1\n"); fe.form = NIL(char*); fe.extf = intarg; sfsprintf(buf1,sizeof(buf1),"%d %d%",1,2); sfsprintf(buf2,sizeof(buf2),"%!%d %d%",&fe); if(strcmp(buf1,buf2) != 0) terror("%%!: Extension function failed2\n"); fe.form = NIL(char*); sfsprintf(buf1,sizeof(buf1),"%d %d%%",3,4); sfsprintf(buf2,sizeof(buf2),"%!%d %d%%",&fe); if(strcmp(buf1,buf2) != 0) terror("%%!: Extension function failed3\n"); fe.form = NIL(char*); fe.extf = shortarg; sfsprintf(buf1,sizeof(buf1),"%hu %ho %hi %hu %ho %hd", -2, -1, 0, 1, 2, 3); sfsprintf(buf2,sizeof(buf2),"%!%u %o %i %u %o %d",&fe); if(strcmp(buf1,buf2) != 0) terror("%%!: Extension function failed4\n"); /* test extf translation */ fe.form = NIL(char*); fe.extf = transarg; sfsprintf(buf1,sizeof(buf1),"%d %o %f %s %c", -1, -1, -1., "s", 'c'); sfsprintf(buf2,sizeof(buf2),"%!%D %O %F %S %C",&fe, -1, -1, -1., "s", 'c'); if(strcmp(buf1,buf2) != 0) terror("%%!: Extension function failed5\n"); k = 1234567890; sfsprintf(buf1,sizeof(buf1),"%I*d",sizeof(k),k); if(strcmp(buf1,"1234567890") != 0) terror("%%I*d failed\n"); Coord.x = 5; Coord.y = 7; sfsprintf(buf1,sizeof(buf1),"%d %d",Coord.x,Coord.y); fe.form = NIL(char*); fe.extf = coordprint; sfsprintf(buf2,sizeof(buf2),"%!%(%d %d)c",&fe,&Coord); if(strcmp(buf1,buf2) != 0) terror("%%()c failed\n"); sfsprintf(buf1,sizeof(buf1),"%d %d %d %d",1,2,3,4); stkprint(buf2,sizeof(buf2),"%d %d",1,2); if(strcmp(buf1,buf2) != 0) terror("%%!: Stack function failed\n"); sfsprintf(buf1,sizeof(buf1),"% +G",-1.2345); sfsprintf(buf2,sizeof(buf2),"-1.2345"); if(strcmp(buf1,buf2) != 0) terror("Failed %% +G test\n"); if(sizeof(int) == 4 && sizeof(short) == 2) { char* ss = sfprints("%hx",0xffffffff); if(!ss || strcmp(ss,"ffff") != 0) terror("Failed %%hx test\n"); } sfsprintf(buf1,sizeof(buf1),"%#..16d",-0xabc); if(strcmp(buf1,"-16#abc") != 0) terror("Failed %%..16d test\n"); sfsprintf(buf1,sizeof(buf1),"%#..16lu",(long)0xc2c01576); if(strcmp(buf1,"16#c2c01576") != 0) terror("Failed %%..16u test\n"); sfsprintf(buf1,sizeof(buf1),"%0#4o",077); if(strcmp(buf1,"0077") != 0) terror("Failed %%0#4o test\n"); sfsprintf(buf1,sizeof(buf1),"%0#4x",0xc); if(strcmp(buf1,"0x000c") != 0) terror("Failed %%0#4x test\n"); sfsprintf(buf1,sizeof(buf1),"%c%c%c",'a','b','c'); if(strcmp(buf1,"abc") != 0) terror("Failed %%c test\n"); sfsprintf(buf1,sizeof(buf1),"%.4c",'a'); if(strcmp(buf1,"aaaa") != 0) terror("Failed %%.4c test\n"); sfsprintf(buf1,sizeof(buf1),"%hd%c%hd%ld",(short)1,'1',(short)1,1L); if(strcmp(buf1,"1111") != 0) terror("Failed %%hd test\n"); sfsprintf(buf1,sizeof(buf1),"%10.5E",(double)0.0000625); if(strcmp(buf1,"6.25000E-05") != 0) terror("Failed %%E test\n"); sfsprintf(buf1,sizeof(buf1),"%10.5f",(double)0.0000625); if(strcmp(buf1," 0.00006") != 0) terror("Failed %%f test\n"); sfsprintf(buf1,sizeof(buf1),"%10.5G",(double)0.0000625); if(strcmp(buf1," 6.25E-05") != 0) terror("Failed %%G test\n"); list[0] = "0"; list[1] = "1"; list[2] = "2"; list[3] = 0; sfsprintf(buf1,sizeof(buf1),"%..*s", ',', list); if(strcmp(buf1,"0,1,2") != 0) terror("Failed %%..*s test\n"); sfsprintf(buf1,sizeof(buf1),"%.2.*c", ',', "012"); if(strcmp(buf1,"00,11,22") != 0) terror("Failed %%..*c test\n"); sfsprintf(buf1,sizeof(buf1),"A%.0dB", 0); if(strcmp(buf1,"AB") != 0) terror("Failed precision+0 test\n"); sfsprintf(buf1,sizeof(buf1),"A%.0dB", 1); if(strcmp(buf1,"A1B") != 0) terror("Failed precision+1 test\n"); sfsprintf(buf1,sizeof(buf1),"A%4.0dB", 12345); if(strcmp(buf1,"A12345B") != 0) terror("Failed exceeding width test\n"); sfsprintf(buf1,sizeof(buf1),"A%3dB",33); if(strcmp(buf1,"A 33B") != 0) terror("Failed justification test\n"); sfsprintf(buf1,sizeof(buf1),"A%04dB",-1); if(strcmp(buf1,"A-001B") != 0) terror("Failed zero filling test\n"); sfsprintf(buf1,sizeof(buf1),"A%+04dB",1); if(strcmp(buf1,"A+001B") != 0) terror("Failed signed and zero-filled test\n"); sfsprintf(buf1,sizeof(buf1),"A% .0dB", -1); if(strcmp(buf1,"A-1B") != 0) terror("Failed blank and precision test\n"); sfsprintf(buf1,sizeof(buf1),"A%+ .0dB", 1); if(strcmp(buf1,"A+1B") != 0) terror("Failed +,blank and precision test\n"); sfsprintf(buf1,sizeof(buf1),"A%010.2fB", 1.2); if(strcmp(buf1,"A0000001.20B") != 0) terror("Failed floating point and zero-filled test\n"); sfsprintf(buf1,sizeof(buf1),"A%-010.2fB", 1.2); if(strcmp(buf1,"A1.20 B") != 0) terror("Failed floating point and left justification test\n"); sfsprintf(buf1,sizeof(buf1),"A%-#XB", 0xab); if(strcmp(buf1,"A0XABB") != 0) terror("Failed %%-#X conversion test\n"); #if !_ast_intmax_long { Sflong_t ll; char buf[128]; char* ss = sfprints("%#..16llu",~((Sflong_t)0)); sfsscanf(ss,"%lli", &ll); if(ll != (~((Sflong_t)0)) ) terror("Failed inverting printf/scanf Sflong_t\n"); ss = sfprints("%#..18lld",~((Sflong_t)0)); sfsscanf(ss,"%lli", &ll); if(ll != (~((Sflong_t)0)) ) terror("Failed inverting printf/scanf Sflong_t\n"); ss = sfprints("%#..lli",~((Sflong_t)0)); sfsscanf(ss,"%lli", &ll); if(ll != (~((Sflong_t)0)) ) terror("Failed inverting printf/scanf Sflong_t\n"); sfsprintf(buf,sizeof(buf), "%llu", (~((Sflong_t)0)/2) ); s = sfprints("%Iu", (~((Sflong_t)0)/2) ); if(strcmp(buf,s) != 0) terror("Failed conversion with I flag\n"); } #endif i = (int)(~(~((uint)0) >> 1)); s = sfprints("%d",i); j = atoi(s); if(i != j) terror("Failed converting highbit\n"); for(i = -10000; i < 10000; i += 123) { s = sfprints("%d",i); j = atoi(s); if(j != i) terror("Failed integer conversion\n"); } /* test I flag for strings */ { char *ls[3]; ls[0] = "0123456789"; ls[1] = "abcdefghij"; ls[2] = 0; s = sfprints("%I5..*s", 0, ls); if(strcmp(s, "01234abcde") != 0) terror("Failed I flag with %%s\n"); } /* test justification */ sfsprintf(buf1,sizeof(buf1),"%-10.5s","abcdefghij"); sfsprintf(buf2,sizeof(buf2),"%*.5s",-10,"abcdefghij"); if(strcmp(buf1,buf2) != 0) terror("Left-justification is wrong\n"); sfsprintf(buf1,sizeof(buf1),"%10.5s","abcdefghij"); sfsprintf(buf2,sizeof(buf2),"%*.5s",10,"abcdefghij"); if(strcmp(buf1,buf2) != 0) terror("Justification is wrong\n"); return 0; } @ 1.2 log @Incorporate stuff from RSE's Sfio98 variant @ text @d181 1 a181 1 float x=0.0051; d187 2 a188 1 f = sfopen(NIL(Sfio_t*),"xxx","w+"); d391 2 a392 1 char* ss = sfprints("%#..16llu",~((Sflong_t)0)); d406 5 d426 21 @ 1.1 log @Initial revision @ text @d3 1 a3 1 static char Buf[128]; d13 1 a13 1 coordarg(Sfio_t* f, Void_t* val, Sffmt_t* fe) d15 1 a15 1 coordarg(f,val,fe) d17 1 a17 1 Void_t* val; d20 14 a33 3 { *((Coord_t**)val) = &Coord; return 1; d36 1 d38 1 a38 1 abCprint(Sfio_t* f, Void_t* v, int width, Sffmt_t* fe) d40 1 a40 1 abCprint(f, v, width, fe) a42 1 int width; d46 1 a46 3 Coord_t* cp; int p; char mytype[128]; d50 32 d83 2 a84 6 if(fe->base > 0) sfsprintf(Buf,sizeof(Buf),"%..*u",fe->base,(unsigned int)v); else sfsprintf(Buf,sizeof(Buf),"%u",(unsigned int)v); fe->t_str = Buf; fe->n_str = sfslen(); return 1; d86 2 a87 18 if(fe->base > 0) sfsprintf(Buf,sizeof(Buf),"%..*d",fe->base,(int)v); else sfsprintf(Buf,sizeof(Buf),"%d",(int)v); fe->t_str = Buf; fe->n_str = sfslen(); return 1; case 'C' : cp = (Coord_t*)v; for(p = 0; ; ++p) if(fe->t_str[p] != '(' ) break; fe->t_str += p; fe->n_str -= 2*p; memcpy(mytype,fe->t_str,fe->n_str); mytype[fe->n_str] = 0; sfsprintf(Buf,sizeof(Buf),mytype,cp->x,cp->y); fe->t_str = Buf; fe->n_str = sfslen(); return 1; d89 3 a91 3 fe->t_str = (char*)v; fe->n_str = 10; return 1; d99 1 a99 1 intarg(Sfio_t* f, Void_t* val, Sffmt_t* fe) d101 1 a101 1 intarg(f, val, fe) d108 43 a150 1 return 1; d155 1 a155 1 void stkprint(char* buf, int n, char* form, ...) d157 1 a157 1 void stkprint(buf,n,form,va_alist) d172 2 a173 2 fe.argf = NIL(Sfarg_f); fe.extf = NIL(Sfext_f); d178 1 a178 1 main() d183 1 d185 33 d223 1 d225 5 a229 12 fe.argf = NIL(Sfarg_f); fe.extf = abCprint; sfsprintf(buf1,sizeof(buf1),"%..4u %..4d9876543210",-1,-1); sfsprintf(buf2,sizeof(buf2),"%!%..4a %..4b%z%Zxxx", &fe,-1,-1,"98765432109876543210",0); if(strcmp(buf1,buf2) != 0) terror("%%!: Extension function failed\n"); fe.argf = intarg; fe.extf = NIL(Sfext_f); sfsprintf(buf1,sizeof(buf1),"%d %d",1,2); sfsprintf(buf2,sizeof(buf2),"%!%d %d",&fe); d231 34 a264 1 terror("%%!: Getarg function failed\n"); d270 3 a272 8 fe.argf = NIL(Sfarg_f); fe.extf = abCprint; sfsprintf(buf2,sizeof(buf2),"%!%((%d %d))C",&fe,&Coord); if(strcmp(buf1,buf2) != 0) terror("%%()C failed\n"); fe.argf = coordarg; sfsprintf(buf2,sizeof(buf2),"%!%((%d %d))C",&fe); d274 1 a274 1 terror("%%()C failed2\n"); d282 1 a282 9 #if _lib_locale { int decpoint = 0; struct lconv* lv; GETDECIMAL(decpoint,lv); sfsprintf(buf2,sizeof(buf2),"-1%c2345",decpoint); } #else sfsprintf(buf2,sizeof(buf2),"-1.2345"); #endif d287 2 a288 2 { char* s = sfprints("%hx",0xffffffff); if(!s || strcmp(s,"ffff") != 0) d344 60 a403 16 #if _typ_long_long { long long ll; char* s = sfprints("%#..16llu",~((long long)0)); sfsscanf(s,"%lli", &ll); if(ll != (~((long long)0)) ) terror("Failed inverting printf/scanf long long1\n"); s = sfprints("%#..18lld",~((long long)0)); sfsscanf(s,"%lli", &ll); if(ll != (~((long long)0)) ) terror("Failed inverting printf/scanf long long2\n"); s = sfprints("%#..lli",~((long long)0)); sfsscanf(s,"%lli", &ll); if(ll != (~((long long)0)) ) terror("Failed inverting printf/scanf long long3\n"); @ 1.1.1.1 log @Import of Sfio1997 @ text @@ 1.1.1.2 log @Import of Sfio1998 @ text @d13 1 a13 1 coordprint(Sfio_t* f, Void_t* v, Sffmt_t* fe) d15 1 a15 1 coordprint(f, v, fe) d17 1 a17 1 Void_t* v; d20 3 a22 14 { char type[128]; Coord_t* cp; if(fe->fmt != 'c') return -1; cp = va_arg(fe->args,Coord_t*); memcpy(type,fe->t_str,fe->n_str); type[fe->n_str] = 0; *((char**)v) = sfprints(type,cp->x,cp->y); fe->fmt = 's'; fe->size = sfslen(); fe->flags |= SFFMT_VALUE; return 0; a24 1 int OXcount; d26 1 a26 1 OXprint(Sfio_t* f, Void_t* v, Sffmt_t* fe) d28 1 a28 1 OXprint(f, v, fe) d31 1 d35 3 a37 1 OXcount += 1; a40 32 case 'd' : *((int*)v) = 10; fe->flags |= SFFMT_VALUE; return 0; case 'O' : fe->fmt = 'o'; *((int*)v) = 11; fe->flags |= SFFMT_VALUE; return 0; case 'X' : fe->fmt = 'x'; *((int*)v) = 12; fe->flags |= SFFMT_VALUE; return 0; } return 0; } #if __STD_C abprint(Sfio_t* f, Void_t* v, Sffmt_t* fe) #else abprint(f, v, fe) Sfio_t* f; Void_t* v; Sffmt_t* fe; #endif { switch(fe->fmt) { d42 6 a47 2 fe->fmt = 'u'; return 0; d49 18 a66 2 fe->fmt = 'd'; return 0; d68 3 a70 3 fe->size = 10; fe->fmt = 's'; return 0; d87 1 a87 43 fe->flags |= SFFMT_VALUE; return 0; } #if __STD_C shortarg(Sfio_t* f, Void_t* val, Sffmt_t* fe) #else shortarg(f, val, fe) Sfio_t* f; Void_t* val; Sffmt_t* fe; #endif { static short i = -2; *((short*)val) = i++; fe->size = sizeof(short); fe->flags |= SFFMT_VALUE; return 0; } #if __STD_C transarg(Sfio_t* f, Void_t* val, Sffmt_t* fe) #else transarg(f, val, fe) Sfio_t* f; Void_t* val; Sffmt_t* fe; #endif { switch(fe->fmt) { case 'D' : fe->fmt = 'd'; return 0; case 'O' : fe->fmt = 'o'; return 0; case 'F' : fe->fmt = 'f'; return 0; case 'S' : fe->fmt = 's'; return 0; case 'C' : fe->fmt = 'c'; return 0; default : return -1; } d109 2 a110 2 fe.extf = NIL(Sffmtext_f); fe.eventf = NIL(Sffmtevent_f); a119 1 long k; a120 33 Sfio_t* f; f = sfopen(NIL(Sfio_t*),"xxx","w+"); sfsetbuf(f,buf1,10); sfprintf(f,"%40s\n","0123456789"); sfsprintf(buf2,sizeof(buf2),"%40s","0123456789"); sfseek(f,(Sfoff_t)0,0); if(!(s = sfgetr(f,'\n',1)) ) terror("Failed getting string\n"); if(strcmp(s,buf2) != 0) terror("Failed formatting %%s\n"); sfsprintf(buf1,sizeof(buf1),"%4d %4o %4x", 10, 11, 11); sfsprintf(buf2,sizeof(buf2),"%2$4d %1$4o %1$4x", 11, 10); if(strcmp(buf1,buf2) != 0) terror("Failed testing $position\n"); sfsprintf(buf1,sizeof(buf1),"%d %1$d %.*d %1$d", 10, 5, 300); sfsprintf(buf2,sizeof(buf2),"%d %1$d %3$.*2$d %1$d", 10, 5, 300); if(strcmp(buf1,buf2) != 0) terror("Failed testing $position with precision\n"); fe.version = SFIO_VERSION; fe.form = NIL(char*); fe.extf = OXprint; fe.eventf = NIL(Sffmtevent_f); sfsprintf(buf1,sizeof(buf1),"%4d %4o %4x %4o %4x", 10, 11, 12, 11, 10); sfsprintf(buf2,sizeof(buf2),"%!%2$4d %3$4O %4$4X %3$4O %2$4x", &fe); if(strcmp(buf1,buf2) != 0) terror("Failed testing $position2\n"); if(OXcount != 3) terror("Failed OXprint called wrong number of times %d\n",OXcount); a125 1 fe.version = SFIO_VERSION; d127 12 a138 5 fe.extf = abprint; fe.eventf = NIL(Sffmtevent_f); sfsprintf(buf1,sizeof(buf1),"%%sX%%d%..4u %..4d9876543210",-1,-1); sfsprintf(buf2,sizeof(buf2),"%!%%sX%%d%..4a %..4b%z%Zxxx", &fe, -1, -1, "9876543210yyyy" ); d140 1 a140 34 terror("%%!: Extension function failed1\n"); fe.form = NIL(char*); fe.extf = intarg; sfsprintf(buf1,sizeof(buf1),"%d %d%",1,2); sfsprintf(buf2,sizeof(buf2),"%!%d %d%",&fe); if(strcmp(buf1,buf2) != 0) terror("%%!: Extension function failed2\n"); fe.form = NIL(char*); sfsprintf(buf1,sizeof(buf1),"%d %d%%",3,4); sfsprintf(buf2,sizeof(buf2),"%!%d %d%%",&fe); if(strcmp(buf1,buf2) != 0) terror("%%!: Extension function failed3\n"); fe.form = NIL(char*); fe.extf = shortarg; sfsprintf(buf1,sizeof(buf1),"%hu %ho %hi %hu %ho %hd", -2, -1, 0, 1, 2, 3); sfsprintf(buf2,sizeof(buf2),"%!%u %o %i %u %o %d",&fe); if(strcmp(buf1,buf2) != 0) terror("%%!: Extension function failed4\n"); /* test extf translation */ fe.form = NIL(char*); fe.extf = transarg; sfsprintf(buf1,sizeof(buf1),"%d %o %f %s %c", -1, -1, -1., "s", 'c'); sfsprintf(buf2,sizeof(buf2),"%!%D %O %F %S %C",&fe, -1, -1, -1., "s", 'c'); if(strcmp(buf1,buf2) != 0) terror("%%!: Extension function failed5\n"); k = 1234567890; sfsprintf(buf1,sizeof(buf1),"%I*d",sizeof(k),k); if(strcmp(buf1,"1234567890") != 0) terror("%%I*d failed\n"); d146 8 a153 3 fe.form = NIL(char*); fe.extf = coordprint; sfsprintf(buf2,sizeof(buf2),"%!%(%d %d)c",&fe,&Coord); d155 1 a155 1 terror("%%()c failed\n"); d163 9 a171 1 sfsprintf(buf2,sizeof(buf2),"-1.2345"); d233 3 a235 47 sfsprintf(buf1,sizeof(buf1),"A%.0dB", 0); if(strcmp(buf1,"AB") != 0) terror("Failed precision+0 test\n"); sfsprintf(buf1,sizeof(buf1),"A%.0dB", 1); if(strcmp(buf1,"A1B") != 0) terror("Failed precision+1 test\n"); sfsprintf(buf1,sizeof(buf1),"A%4.0dB", 12345); if(strcmp(buf1,"A12345B") != 0) terror("Failed exceeding width test\n"); sfsprintf(buf1,sizeof(buf1),"A%3dB",33); if(strcmp(buf1,"A 33B") != 0) terror("Failed justification test\n"); sfsprintf(buf1,sizeof(buf1),"A%04dB",-1); if(strcmp(buf1,"A-001B") != 0) terror("Failed zero filling test\n"); sfsprintf(buf1,sizeof(buf1),"A%+04dB",1); if(strcmp(buf1,"A+001B") != 0) terror("Failed signed and zero-filled test\n"); sfsprintf(buf1,sizeof(buf1),"A% .0dB", -1); if(strcmp(buf1,"A-1B") != 0) terror("Failed blank and precision test\n"); sfsprintf(buf1,sizeof(buf1),"A%+ .0dB", 1); if(strcmp(buf1,"A+1B") != 0) terror("Failed +,blank and precision test\n"); sfsprintf(buf1,sizeof(buf1),"A%010.2fB", 1.2); if(strcmp(buf1,"A0000001.20B") != 0) terror("Failed floating point and zero-filled test\n"); sfsprintf(buf1,sizeof(buf1),"A%-010.2fB", 1.2); if(strcmp(buf1,"A1.20 B") != 0) terror("Failed floating point and left justification test\n"); sfsprintf(buf1,sizeof(buf1),"A%-#XB", 0xab); if(strcmp(buf1,"A0XABB") != 0) terror("Failed %%-#X conversion test\n"); #if !_ast_intmax_long { Sflong_t ll; char* s = sfprints("%#..16llu",~((Sflong_t)0)); d237 2 a238 2 if(ll != (~((Sflong_t)0)) ) terror("Failed inverting printf/scanf Sflong_t\n"); d240 1 a240 1 s = sfprints("%#..18lld",~((Sflong_t)0)); d242 2 a243 2 if(ll != (~((Sflong_t)0)) ) terror("Failed inverting printf/scanf Sflong_t\n"); d245 1 a245 1 s = sfprints("%#..lli",~((Sflong_t)0)); d247 2 a248 2 if(ll != (~((Sflong_t)0)) ) terror("Failed inverting printf/scanf Sflong_t\n"); @ 1.1.1.3 log @Import of Sfio1999 @ text @d181 1 a181 1 double x=0.0051; d187 1 a187 2 f = sfopen(NIL(Sfio_t*), Kpv[0], "w+"); unlink(Kpv[0]); d390 1 a390 2 char buf[128]; char* s = sfprints("%#..16llu",~((Sflong_t)0)); a403 5 sfsprintf(buf,sizeof(buf), "%llu", (~((Sflong_t)0)/2) ); s = sfprints("%Iu", (~((Sflong_t)0)/2) ); if(strcmp(buf,s) != 0) terror("Failed conversion with I flag\n"); a418 21 /* test I flag for strings */ { char *ls[3]; ls[0] = "0123456789"; ls[1] = "abcdefghij"; ls[2] = 0; s = sfprints("%I5..*s", 0, ls); if(strcmp(s, "01234abcde") != 0) terror("Failed I flag with %%s\n"); } /* test justification */ sfsprintf(buf1,sizeof(buf1),"%-10.5s","abcdefghij"); sfsprintf(buf2,sizeof(buf2),"%*.5s",-10,"abcdefghij"); if(strcmp(buf1,buf2) != 0) terror("Left-justification is wrong\n"); sfsprintf(buf1,sizeof(buf1),"%10.5s","abcdefghij"); sfsprintf(buf2,sizeof(buf2),"%*.5s",10,"abcdefghij"); if(strcmp(buf1,buf2) != 0) terror("Justification is wrong\n"); @