Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/tests/sfio/tfmt.c
1810 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1999-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* *
19
***********************************************************************/
20
#include "sftest.h"
21
22
static char *Mystr = "abc";
23
#if __STD_C
24
int myprint(Sfio_t* f, Void_t* v, Sffmt_t* fe)
25
#else
26
int myprint(f, v, fe)
27
Sfio_t* f;
28
Void_t* v;
29
Sffmt_t* fe;
30
#endif
31
{
32
switch(fe->fmt)
33
{
34
case 's' :
35
*((char**)v) = Mystr;
36
fe->flags |= SFFMT_VALUE;
37
return 0;
38
}
39
40
return 0;
41
}
42
43
tmain()
44
{
45
char buf1[1024], buf2[1024];
46
Sffmt_t fe;
47
48
memset(&fe, 0, sizeof(Sffmt_t));
49
fe.version = SFIO_VERSION;
50
fe.form = "%1$s";
51
fe.extf = myprint;
52
53
sfsprintf(buf1,sizeof(buf1),"%s",Mystr);
54
sfsprintf(buf2,sizeof(buf2),"%!", &fe);
55
if(strcmp(buf1,buf2) != 0)
56
terror("Failed testing $position");
57
58
return 0;
59
}
60
61