Added some (default) icons for files/dirs used by boot floppies.
[cake.git] / test / localetest.c
blob26647eddd549b64f1aae9f6d2479a16917ab253e
1 #include <proto/locale.h>
2 #include <proto/exec.h>
3 #include <proto/utility.h>
4 #include <utility/hooks.h>
5 #include <libraries/locale.h>
6 #include <dos/datetime.h>
7 #include <utility/date.h>
8 #include <aros/asmcall.h>
9 #include <stdio.h>
13 struct LocaleBase * LocaleBase;
14 struct UtilityBase * UtilityBase;
16 AROS_UFH3(void, printchar,
17 AROS_UFHA(struct Hook *, myhook, A0),
18 AROS_UFHA(struct Locale *, locale, A2),
19 AROS_UFHA(char, c, A1))
21 AROS_USERFUNC_INIT
23 if ('\0' != c) printf("%c",c);
25 AROS_USERFUNC_EXIT
28 struct Data
30 char * a;
31 char * b;
32 char * c;
33 char * d;
34 UWORD e;
35 UWORD f;
36 ULONG g;
40 void formatstring_test(struct Locale * locale)
42 struct Hook myhook;
43 char hello[] = {"Hello"};
44 char local[] = {"Locale"};
45 char welcomes[] = {"welcomes"};
46 char you[] = {"you"};
48 struct Data dataStream =
49 { hello,
50 local,
51 welcomes,
52 you,
53 1000,
54 20000,
55 0x1234ABCD};
57 myhook.h_Entry = (APTR)printchar;
59 printf("Doing a simple FormatString test!\n");
62 ** Just a simple test for FormatString
64 FormatString(locale, "%s! %s %s %s %u %u %lx!\n", &dataStream, &myhook);
65 FormatString(locale, "%4$s! (%5$u %7$lX %6$u %6$U %7$lU) %1$.3s %2$20s %3$s %4$s!\n", &dataStream, &myhook);
68 void formatdate_test(struct Locale * locale)
70 struct Hook myhook;
71 struct DateStamp date;
72 struct ClockData cdata;
73 ULONG seconds;
75 myhook.h_Entry = (APTR)printchar;
77 printf("Doing a simple FormatDate test!\n");
80 ** Just a simple test for FormatString
83 cdata.sec = 30;
84 cdata.min = 59;
85 cdata.hour = 8;
86 cdata.mday = 17;
87 cdata.month = 1;
88 cdata.year = 2000;
89 cdata.wday = 0; // don't care
91 seconds = Date2Amiga(&cdata);
92 date.ds_Days = seconds / 86400;
93 seconds = seconds % 86400;
94 date.ds_Minute = seconds / 60;
95 seconds = seconds % 60;
96 date.ds_Tick = seconds * 50;
98 FormatDate(locale, "24hour style (leading 0s): %H\n", &date, &myhook);
99 FormatDate(locale, "12hour style (leading 0s): %I\n", &date, &myhook);
100 FormatDate(locale, "24hour style: %q\n", &date, &myhook);
101 FormatDate(locale, "12hour style: %Q\n", &date, &myhook);
102 FormatDate(locale, "Number of seconds (leading 0s): %S\n", &date, &myhook);
103 FormatDate(locale, "H:M:S style (T): %T\n", &date, &myhook);
104 FormatDate(locale, "H:M:S style (X): %X\n", &date, &myhook);
107 cdata.sec = 30;
108 cdata.min = 59;
109 cdata.hour = 18;
110 cdata.mday = 30;
111 cdata.month = 7;
112 cdata.year = 2000;
113 cdata.wday = 0; // don't care
115 seconds = Date2Amiga(&cdata);
116 date.ds_Days = seconds / 86400;
117 seconds = seconds % 86400;
118 date.ds_Minute = seconds / 60;
119 seconds = seconds % 60;
120 date.ds_Tick = seconds * 50;
122 FormatDate(locale, "24hour style (leading 0s): %H\n", &date, &myhook);
123 FormatDate(locale, "12hour style (leading 0s): %I\n", &date, &myhook);
124 FormatDate(locale, "24hour style: %q\n", &date, &myhook);
125 FormatDate(locale, "12hour style: %Q\n", &date, &myhook);
126 FormatDate(locale, "Number of seconds (leading 0s): %S\n", &date, &myhook);
127 FormatDate(locale, "%%H:%%M:%%S style (T): %T\n", &date, &myhook);
128 FormatDate(locale, "%%H:%%M:%%S style (X): %X\n", &date, &myhook);
130 printf("\n");
131 FormatDate(locale, "%%a %%b %%d %%h:%%m:%%s %%y style: %c\n", &date, &myhook);
132 FormatDate(locale, "%%a %%b %%e %%T %%Z %%Y style: %C\n", &date, &myhook);
133 FormatDate(locale, "%%m/%%d/%%y style: %D\n", &date, &myhook);
135 FormatDate(locale, "Week number - Sunday first day of week: %U\n", &date, &myhook);
136 FormatDate(locale, "Week number - Monday first day of week: %W\n", &date, &myhook);
141 void getstringtest(struct Locale * locale)
143 struct Catalog * cat;
144 char catname[256];
146 printf("Please enter name of catalog: ");
147 scanf("%s",catname);
149 cat = OpenCatalogA(locale,catname,NULL);
150 if (cat)
152 int i = 0;
153 while (i < 65535)
155 CONST_STRPTR str = GetCatalogStr(cat, i, NULL);
156 if (str)
157 printf("ID: %d - string : %s\n",i,str);
159 i++;
162 CloseCatalog(cat);
166 int main(void)
168 LocaleBase = (struct LocaleBase *)OpenLibrary("locale.library",0);
169 UtilityBase = (struct UtilityBase *)OpenLibrary("utility.library",0);
171 if (LocaleBase)
173 struct Locale * locale;
174 locale = OpenLocale(NULL);
175 formatstring_test(locale);
176 formatdate_test(locale);
177 getstringtest(locale);
179 if (locale) CloseLocale(locale);
181 else
183 printf("A library could not be opened!\n");
186 if (LocaleBase) CloseLibrary((struct Library *)LocaleBase);
187 if (UtilityBase) CloseLibrary((struct Library *)UtilityBase);
188 return 0;