-
Notifications
You must be signed in to change notification settings - Fork 0
/
citeme_collect.c
152 lines (111 loc) · 2.65 KB
/
citeme_collect.c
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
#include <stdarg.h>
#include <stdio.h>
#include <citeme.h>
#include <citeme_lib.h>
#ifdef __cplusplus
extern "C"
{
#endif
/* CitationError RegisterCitation(const CitationType _type,...){ return Ok; } */
/**
This global function should be visible for the outside!
*/
CitationError RegisterCitation( const CitationType _type, ... )
{
va_list ap;
CitationStruct* _struct;
BannerFunction _banner;
CitationError retVal = Ok;
va_start(ap, _type);
switch (_type)
{
case ViaStuct:
{
_struct = va_arg(ap, CitationStruct*);
printf( "%s\n", _struct->banner );
break;
}
case ViaBanner:
{
_banner = va_arg(ap, BannerFunction);
printf( "%s\n", (*_banner)(GetBannerMessage) );
break;
}
default:
{
retVal = ErrorWrongArgs;
break;
}
}
va_end(ap);
return retVal;
}
#ifdef __cplusplus
}
#endif /* __cplusplus */
static CitationStruct _about = { "MainApplication", "0.0", "BSD", "Oleksandr", "Hi, this is an example _main_ application,\nwhich _provides_ the RegisterCitation interface\nIt also _uses_ the example library\nHave Fun!", "...some latex code0..." };
static const char* _banner( const BannerType _type )
{
switch (_type)
{
case GetName:
{
return _about.name;
break;
}
case GetAuthors:
{
return _about.authors;
break;
}
case GetBannerMessage:
{
return _about.banner;
break;
}
case GetBibItem:
{
return _about.bibitem;
break;
}
default:
{
return NULL;
break;
}
}
}
static int test1()
{
CitationError ret;
// init citation DB.
printf("Trying to cite with a struct: \n");
ret = RegisterCitation(ViaStuct, &_about);
if( ret >= Ok )
printf("Fine citation....!\n");
else
printf("Bad citation.... (error code: %d)\n", ret);
printf("Trying to cite with a banner: \n");
ret = RegisterCitation(ViaBanner, &_banner);
if( ret >= Ok )
printf("Fine citation....!\n");
else
printf("Bad citation.... (error code: %d)\n", ret);
printf("Trying to cite in some otherway: \n");
ret = RegisterCitation(Otherwise);
if( ret >= Ok )
printf("Fine citation....!\n");
else
printf("Bad citation.... (error code: %d)\n", ret);
return ret;
}
int main ()
{
int ret = 0;
printf("Main banner: \n%s\n", _banner(GetBannerMessage) );
printf("Setting up the main application...: \n");
/* let's init the much _needed_ library */
ret = initme(); /**< Init the data provider (used library) */
printf("That's it!\n");
return ret;
}