make sure "S" is generated.
[AROS-Contrib.git] / rexx / progs / gudemo.r
blob489d7eda27bb661126435d7fa3c8bc317d17ed12
1 /*
2 ||
3 || A simple "Phone Book" BRexx program
4 || Just an example of "guiutils.r" library usage.
5 ||
6 || 02/05/1999 by Generoso Martello
7 || generoso@martello.com
8 || Catanzaro Lido (ITALY)
9 ||
12 call load 'guiutils.r'
14 rxEnter=d2c(13)
15 rxEsc=d2c(27)
17 call loadPhoneBook()
20 || Main program... isn't it very short ? :)
22 fr=0 ; op=0 ; ch='' ; call ansiSetCursor('OFF')
23 do while ch~=rxEsc
25 call ansiColor('LIGHTCYAN','BLACK')
26 call ansiCls
28 call ansiMenu 42,4,35,6,'Command List'
29 call ansiColor('LIGHTCYAN','BLUE')
30 call ansiGoto 54,6 ; say ' A = Add'
31 call ansiGoto 54,7 ; say ' E = Edit'
32 call ansiGoto 54,8 ; say ' D = Delete'
33 call ansiGoto 54,9 ; say 'Enter = View'
34 call ansiGoto 54,10 ; say ' Esc = Exit'
36 call ansiColor('WHITE','BLACK')
38 call ansiGoto 13,1 ; say 'PHONE BOOK v 1.0'
39 call ansiGoto 11,2 ; say 'by Generoso Martello'
40 call ansiGoto 42,14 ; say 'This is an example application which'
41 call ansiGoto 42,15 ; say 'uses my "guiutils.r" library.'
42 call ansiGoto 42,17 ; say 'The library is supposed to work with'
43 call ansiGoto 42,18 ; say 'the 32-bit DOS version of Brexx.'
44 call ansiGoto 42,20 ; say 'Through this library you can "dress"'
45 call ansiGoto 42,21 ; say 'your programs with colourful menus,'
46 call ansiGoto 42,22 ; say 'lists, input boxes, requesters...'
47 call ansiGoto 42,23 ; say '... Enjoy it! :)'
49 ch=ansiList(2,4,35,19,fr,op,'Available Phone Books','A=Add|E=Edit|D=Delete|Enter=Open|Esc=Exit','GUlist','I','')
51 op=subword(ch,1,1) ; fr=subword(ch,2,1) ; ch=subword(ch,3,1)
53 if ch=rxEnter & GUlist.count>0 then do
54 fr1=0 ; op1=0 ; ch=''
55 do while ch~=rxEsc
56 ch=ansiList(20,12,55,10,fr1,op1,'"'GUlist.op'" Phone Book','A=Add|E=Edit|D=Delete|Enter=View|Esc=Exit','GUlist.'op,'','')
57 op1=subword(ch,1,1) ; fr1=subword(ch,2,1) ; ch=subword(ch,3,1)
58 if ch='A' | (ch='E' & GUlist.op.count>0) then do
59 if ch='A' then do
60 name=''
61 phon='+39-'
62 note=''
63 end
64 else do
65 parse var GUlist.op.op1 name' ³ 'phon' ³ 'note
66 name=strip(name)
67 phon=strip(phon)
68 note=strip(note)
69 end
70 call ansiMenu 20,12,55,10,'Add/Modify Record - "'GUlist.op'"'
71 call ansiColor 'WHITE','BLUE'
72 call ansiGoto 22,15 ; say 'First Name and Last Name'
73 call ansiGoto 22,17 ; say 'Telephone number'
74 call ansiGoto 22,19 ; say 'Note'
75 call ansiColor 'BLACK','WHITE'
76 call ansiOLine 22,16,53,' '
77 call ansiOLine 22,18,53,' '
78 call ansiOLine 22,20,53,' '
79 call ansiOLine 22,21,53,' '
80 call ansiGoto 22,16 ; say name'ee'
81 call ansiGoto 22,18 ; say phon
82 call ansiGoto 22,20 ; say substr(note,1,52)
83 call ansiGoto 22,21 ; say substr(note,53)
85 name=ansiInputLine(22,16,1,0,25,name)
86 phon=ansiInputLine(22,18,1,0,25,phon)
87 note=ansiInputLine(22,20,2,0,52,note)
89 if strip(name)~='' then do
90 if ch='A' then do
91 cn=GUlist.op.count
92 GUlist.op.cn=left(name,25)' ³ 'left(phon,25)' ³ 'note
93 GUlist.op.count=cn+1
94 end
95 else GUlist.op.op1=left(name,25)' ³ 'left(phon,25)' ³ 'note
97 /* BUBBLE SORT ... un po' di ordine... :) */
98 ordinato = 0 ; do while ~ordinato
99 ordinato=1
100 do curr=0 for GUlist.op.count-1
101 next=curr+1
102 if GUlist.op.curr > GUlist.op.next then do
103 p=GUlist.op.curr
104 GUlist.op.curr=GUlist.op.next
105 GUlist.op.next=p
106 ordinato=0
113 else if ch='D' & GUlist.op.count>0 then do
114 if ansiRequest(32,14,30,"ARE YOU SURE ?","Delete this entry ?","Yes","No") then do
115 do x=op1+fr1-1 for GUlist.op.count
116 next=x+1
117 GUlist.op.x=GUlist.op.next
119 GUlist.op.count=GUlist.op.count-1
122 else if ch=rxEnter & GUlist.op.count>0 then do
123 parse var GUlist.op.op1 name' ³ 'phon' ³ 'note
124 call ansiMenu 20,12,55,10,'Record Details - Hit any key to exit'
125 call ansiColor 'WHITE','BLUE'
126 call ansiGoto 22,15 ; say 'First Name and Last Name'
127 call ansiGoto 22,17 ; say 'Telephone number'
128 call ansiGoto 22,19 ; say 'Note'
129 call ansiColor 'BLACK','WHITE'
130 call ansiOLine 22,16,53,' '
131 call ansiOLine 22,18,53,' '
132 call ansiOLine 22,20,53,' '
133 call ansiOLine 22,21,53,' '
134 call ansiGoto 22,16 ; say name
135 call ansiGoto 22,18 ; say phon
136 call ansiGoto 22,20 ; say substr(note,1,52)
137 call ansiGoto 22,21 ; say substr(note,53)
138 dummy=getch()
141 ch=''
143 else if ch='A' | (ch='E' & GUlist.count>0) then do
144 if ch='A' then name=''
145 else name=GUlist.op
146 call ansiMenu 20,12,32,5,'Add/Modify Phone Book'
147 call ansiColor 'WHITE','BLUE'
148 call ansiGoto 22,15 ; say 'Phone Book Name'
149 call ansiColor 'BLACK','WHITE'
150 name=ansiInputLine(22,16,1,0,30,name)
151 if strip(name)~='' then do
152 if ch='A' then do
153 cn=GUlist.count
154 GUlist.cn=name ; GUlist.cn.count=0
155 GUlist.count=cn+1
157 else GUlist.op=name
160 else if ch='D' & GUlist.count>0 then do
161 if ansiRequest(26,12,30,"ARE YOU SURE ?","Delete this section ?","Yes","No") then do
162 GUlist.op.flag='D'
163 call savePhoneBook()
164 call loadPhoneBook()
165 fr=0 ; op=0
170 byebebe:
171 call ansiColor 'BLACK','BLACK'
172 call ansiBox 42,12,35,11
173 call savePhoneBook()
174 call ansiColor 'LIGHTRED','BLACK'
175 call ansiGoto 42,20 ; say 'Done! Press any key to exit.'
176 dummy=getch()
177 call ansiColor('WHITE','BLACK') ; call ansiCls
178 call ansiSetCursor("NORMAL")
179 exit
182 || Loads my phonebook data
184 loadPhoneBook: procedure expose GUlist.
185 lc=0
186 fd=open('gudemo.dat','r')
187 if fd>0 then do
188 l=read(fd)
189 do while ~eof(fd)
190 if l~='' then GUlist.lc=l
191 ic=0 ; if ~eof(fd) then l=read(fd)
192 do while subword(l,1,1)~='#' & ~eof(fd)
193 GUlist.lc.ic=l ; ic=ic+1
194 l=read(fd)
196 GUlist.lc.count=ic ; lc=lc+1
197 if ~eof(fd) then l=read(fd)
199 call close fd
201 GUlist.count=lc
202 return 0
205 || Saves my phonebook data
207 savePhoneBook: procedure expose GUlist.
208 fd=open('gudemo.dat','w')
209 if fd>0 then do
210 call ansiMenu 14,11,56,6,'Updating Phone Book data...'
211 call ansiColor 'YELLOW','BLUE'
212 call ansiGoto 16,14 ; say 'Sections'
213 call ansiGoto 16,16 ; say ' Records'
214 do x=0 for GUlist.count
215 call ansiProgressBar 25,14,((x+1)*100)/GUlist.count,38
216 if GUlist.x.flag~='D' then do
217 call write fd,GUlist.x,'nl'
218 do y=0 for GUlist.x.count
219 call ansiProgressBar 25,16,((y+1)*100)/GUlist.x.count,38
220 call write fd,GUlist.x.y,'nl'
222 call write fd,'#','nl'
225 call close fd
227 return 0