mesa: simplify dependencies in mmakefiles
[AROS.git] / test / locale / localetest.c
blob4c1f8868497b9542611a9de3b707dc67ce9d3f7b
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <proto/locale.h>
7 #include <proto/exec.h>
8 #include <proto/utility.h>
9 #include <utility/hooks.h>
10 #include <libraries/locale.h>
11 #include <dos/datetime.h>
12 #include <utility/date.h>
13 #include <aros/asmcall.h>
14 #include <stdio.h>
18 struct LocaleBase * LocaleBase;
19 struct UtilityBase * UtilityBase;
21 AROS_UFH3(void, printchar,
22 AROS_UFHA(struct Hook *, myhook, A0),
23 AROS_UFHA(struct Locale *, locale, A2),
24 AROS_UFHA(char, c, A1))
26 AROS_USERFUNC_INIT
28 if ('\0' != c) printf("%c",c);
30 AROS_USERFUNC_EXIT
33 struct Data
35 char * a;
36 char * b;
37 char * c;
38 char * d;
39 UWORD e;
40 UWORD f;
41 ULONG g;
42 } __packed;
44 void formatstring_test(struct Locale * locale)
46 struct Hook myhook;
47 char hello[] = {"Hello"};
48 char local[] = {"Locale"};
49 char welcomes[] = {"welcomes"};
50 char you[] = {"you"};
52 struct Data dataStream =
53 { hello,
54 local,
55 welcomes,
56 you,
57 1000,
58 20000,
59 0x1234ABCD};
61 myhook.h_Entry = (APTR)printchar;
63 printf("Doing a simple FormatString test!\n");
66 ** Just a simple test for FormatString
68 FormatString(locale, "%s! %s %s %s %u %u %lx!\n", (RAWARG)&dataStream, &myhook);
69 FormatString(locale, "%4$s! (%5$u %7$lX %6$u %6$U %7$lU) %1$.3s %2$20s %3$s %4$s!\n", (RAWARG)&dataStream, &myhook);
72 void formatdate_test(struct Locale * locale)
74 struct Hook myhook;
75 struct DateStamp date;
76 struct ClockData cdata;
77 ULONG seconds;
79 myhook.h_Entry = (APTR)printchar;
81 printf("Doing a simple FormatDate test!\n");
84 ** Just a simple test for FormatString
87 cdata.sec = 30;
88 cdata.min = 59;
89 cdata.hour = 8;
90 cdata.mday = 17;
91 cdata.month = 1;
92 cdata.year = 2000;
93 cdata.wday = 0; // don't care
95 seconds = Date2Amiga(&cdata);
96 date.ds_Days = seconds / 86400;
97 seconds = seconds % 86400;
98 date.ds_Minute = seconds / 60;
99 seconds = seconds % 60;
100 date.ds_Tick = seconds * 50;
102 FormatDate(locale, "24hour style (leading 0s): %H\n", &date, &myhook);
103 FormatDate(locale, "12hour style (leading 0s): %I\n", &date, &myhook);
104 FormatDate(locale, "24hour style: %q\n", &date, &myhook);
105 FormatDate(locale, "12hour style: %Q\n", &date, &myhook);
106 FormatDate(locale, "Number of seconds (leading 0s): %S\n", &date, &myhook);
107 FormatDate(locale, "H:M:S style (T): %T\n", &date, &myhook);
108 FormatDate(locale, "H:M:S style (X): %X\n", &date, &myhook);
111 cdata.sec = 30;
112 cdata.min = 59;
113 cdata.hour = 18;
114 cdata.mday = 30;
115 cdata.month = 7;
116 cdata.year = 2000;
117 cdata.wday = 0; // don't care
119 seconds = Date2Amiga(&cdata);
120 date.ds_Days = seconds / 86400;
121 seconds = seconds % 86400;
122 date.ds_Minute = seconds / 60;
123 seconds = seconds % 60;
124 date.ds_Tick = seconds * 50;
126 FormatDate(locale, "24hour style (leading 0s): %H\n", &date, &myhook);
127 FormatDate(locale, "12hour style (leading 0s): %I\n", &date, &myhook);
128 FormatDate(locale, "24hour style: %q\n", &date, &myhook);
129 FormatDate(locale, "12hour style: %Q\n", &date, &myhook);
130 FormatDate(locale, "Number of seconds (leading 0s): %S\n", &date, &myhook);
131 FormatDate(locale, "%%H:%%M:%%S style (T): %T\n", &date, &myhook);
132 FormatDate(locale, "%%H:%%M:%%S style (X): %X\n", &date, &myhook);
134 printf("\n");
135 FormatDate(locale, "%%a %%b %%d %%h:%%m:%%s %%y style: %c\n", &date, &myhook);
136 FormatDate(locale, "%%a %%b %%e %%T %%Z %%Y style: %C\n", &date, &myhook);
137 FormatDate(locale, "%%m/%%d/%%y style: %D\n", &date, &myhook);
139 FormatDate(locale, "Week number - Sunday first day of week: %U\n", &date, &myhook);
140 FormatDate(locale, "Week number - Monday first day of week: %W\n", &date, &myhook);
145 void getstringtest(struct Locale * locale)
147 struct Catalog * cat;
148 char catname[256];
150 printf("Please enter name of catalog: ");
151 scanf("%s",catname);
153 cat = OpenCatalogA(locale,catname,NULL);
154 if (cat)
156 int i = 0;
157 while (i < 65535)
159 CONST_STRPTR str = GetCatalogStr(cat, i, NULL);
160 if (str)
161 printf("ID: %d - string : %s\n",i,str);
163 i++;
166 CloseCatalog(cat);
170 int main(void)
172 LocaleBase = (struct LocaleBase *)OpenLibrary("locale.library",0);
173 UtilityBase = (struct UtilityBase *)OpenLibrary("utility.library",0);
175 if (LocaleBase)
177 struct Locale * locale;
178 locale = OpenLocale(NULL);
179 formatstring_test(locale);
180 formatdate_test(locale);
181 getstringtest(locale);
183 if (locale) CloseLocale(locale);
185 else
187 printf("A library could not be opened!\n");
190 if (LocaleBase) CloseLibrary((struct Library *)LocaleBase);
191 if (UtilityBase) CloseLibrary((struct Library *)UtilityBase);
192 return 0;