Initial revision
[ssr] / StraySrc / SapphToys / !CApp / c / capp
1 /*
2 * capp.c
3 *
4 * A Sapphire application in C!
5 *
6 * © 1995-1998 Straylight
7 */
8
9 /*----- Licensing note ----------------------------------------------------*
10 *
11 * CApp is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
14 * any later version.
15 *
16 * CApp is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with CApp. If not, write to the Free Software Foundation,
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 */
25
26 /*----- External dependencies ---------------------------------------------*/
27
28 /* --- Header files --- */
29
30 #include "sapphire.h"
31 #include "swis.h"
32
33 /* --- Sapphire routines --- *
34 *
35 * Currently we have to declare these by hand. Maybe things will get better
36 * in the future.
37 */
38
39 #include "defHandler.h"
40 #include "errorBox.h"
41 #include "event.h"
42 #include "ibicon.h"
43 #include "menu.h"
44 #include "menuDefs.h"
45 #include "progInfo.h"
46 #include "resources.h"
47
48 /* --- A SWI --- */
49
50 __swi(OS_Exit) void os_exit(void);
51
52 /* --- Version strings --- */
53
54 extern char cright[];
55 extern char version[];
56
57 /*----- Main code ---------------------------------------------------------*/
58
59 /* --- The application name --- *
60 *
61 * This is picked up by start.s and passed to sapphire_init.
62 */
63
64 char appname[]="CApp";
65
66 /* --- capp__menuHandler --- *
67 *
68 * The menu handling routine. This is fairly straightforward. Equipped
69 * with os_exit, we can quit the program on a `Quit' event, and progInfo
70 * displays a dialogue if you choose `Info...'.
71 */
72
73 static _sapph(capp__menuHandler)(regset *r)
74 {
75 switch (r->r[0])
76 {
77 case mEvent_select:
78 case mEvent_subMenu:
79 switch (r->r[1])
80 {
81 case 0:
82 _call(progInfo,_inr(0,2),
83 msgs_lookup("caPUR"),cright,version);
84 break;
85 case 1:
86 os_exit();
87 break;
88 }
89 }
90 return (0);
91 }
92
93 /* --- capp__ibHandler --- *
94 *
95 * Handles events on the icon bar. Select displays a `Hello, world!'
96 * message. Menu displays a menu. The menu is contained within the
97 * hexgorp below.
98 */
99
100 static _sapph(capp__ibHandler)(regset *r)
101 {
102 static const unsigned menu[]={ /* Yuk! */
103
104 0x00000000, /* Default title style */
105 0x70704143, /* `CApp' */
106 0x00000000,
107
108 0x00000200, /* Send subwarn events */
109 0x4E496163, /* `caINF' */
110 0x00000046,
111
112 0x00000000, /* Normal item style */
113 0x55516163, /* `caQUIT' */
114 0x00005449,
115
116 0x80000000, /* End of the block */
117
118 };
119
120 switch (r->r[0])
121 {
122 case ibEvent_select:
123 _call(errorBox,_inr(0,1),
124 strerror(1,"Hello, world! %i0",(int)scratchpad/24),
125 1);
126 break;
127 case ibEvent_menu:
128 _call(menu_create,_inr(0,3),menu,capp__menuHandler,0,0);
129 break;
130 case ibEvent_adjust:
131 _swi(Wimp_ReportError,_inr(0,2),
132 strerror(1,"%0 seems to be working",appname),1,appname);
133 break;
134 }
135
136 return (0);
137 }
138
139
140 /* --- sapph_main --- *
141 *
142 * This is the main program. Well, almost. I couldn't use `main' because
143 * the compiler messes up the output. The code initialises the library
144 * units (yes! we can start executing C code before most of Sapphire is
145 * awake!), creates an icon on the icon bar, and handles events until
146 * something kills the application.
147 */
148
149 _sapph(sapph_main)(void)
150 {
151 char pollblock[256];
152 int e;
153
154 _call(resources_init,0);
155 _call(sapphire_libInit,0);
156 _call(ibicon_create,_inr(0,6),
157 "application",0,
158 -1,0,
159 capp__ibHandler,0,0);
160
161 for (;;)
162 {
163 /* --- Use _call here -- it needs testing --- */
164
165 if (!(_call(event_poll,_inr(0,1)|_out(0)|_return(_flags),
166 1,pollblock, &e) & _c))
167 _call(defHandler,_inr(0,1),e,pollblock);
168 }
169
170 return (0);
171 }
172
173 /*----- That's all, folks -------------------------------------------------*/