added Item$ = "__SmIC__="+FileName$ to COLUMNBOX ADD, add a filemode: r+ ( read/write )

This commit is contained in:
Jim
2015-05-05 21:04:32 -07:00
parent cd2a1ddb30
commit 83339084fe
13 changed files with 639 additions and 348 deletions

View File

@@ -0,0 +1,62 @@
import fileblock
x=openfile("/boot/home/test.file", 150,3)
if x < 1 error "cannot open file"
ok=Field(x,1,"name",50)
ok=ok+Field(x,2,"address",50)
ok=ok+Field(x,3,"phonenumber",50)
if (!ok = 3 ) error "bad field"
// werite some blocks
for z=1 to 20
lset(x,"name", "Some dude")
lset(x,"address", "Some address")
rset(x,"phonenumber","123-456-7890")
y=write_block(-1, x) // -1 appends the data to the file.
next
// over-write a block with new data
lset(x,"name", "Some other dude")
lset(x,"address", "Some kewl address")
rset(x,"phonenumber","098-765-4321")
write_block(6, x)
// read back the over-written block
read_block(6, x)
// get the data from the read operation
name$=readfield$(x, "name")
address$=readfield$(x, "address")
phone$=readfield$(x, "phonenumber")
// show the data
print name$
print address$
print trim$(phone$)
// over write the block again
lset(x,"name", "")
lset(x,"address", "")
rset(x,"phonenumber","")
write_block(6, x)
//read back the over-written block
recno = read_block(6, x) // returns the read block that will next be read if called with -1 recordnumber
name$=readfield$(x, "name")
address$=readfield$(x, "address")
phone$=readfield$(x, "phonenumber")
print name$
print address$
print phone$
print recno
//read the next block
recno = read_block(-1, x)
name$=readfield$(x, "name")
address$=readfield$(x, "address")
phone$=readfield$(x, "phonenumber")
print name$
print address$
print phone$
print recno

View File

@@ -1,9 +1,12 @@
#!yab
import Filebox
dir$ = "/boot/home/"
window open 100,100 to 500,500, "Demo","Demo"
window open 100,100 to 500,500, "Demo",dir$
Filebox(10,10,350,390,"Filebox", 1, "Demo")
FileboxDirectory("Filebox", dir$, false)
button 360,10,390,30, "DirUp", "..", "Demo"
@@ -13,6 +16,7 @@ inloop = true
while(inloop)
n = split(message$, msg$(), "|")
for i=1 to n
print msg$(i)
// Quit
if(msg$(i) = "Demo:_QuitRequested") inloop = false
@@ -23,7 +27,9 @@ while(inloop)
t = t - 1
wend
dir$ = left$(dir$,t)
WINDOW SET "Demo", "Title", dir$
FileboxDirectory("Filebox", dir$, false)
endif
// An item is invoked
@@ -31,11 +37,12 @@ while(inloop)
position = val(right$(msg$(i),len(msg$(i))-16))
// if the item is a directory, then update the filebox else print the filename
if(FileboxIsDirectory("Filebox", position)) then
if(FileboxIsDirectory("Filebox", position,dir$)) then
dir$ = dir$ + FileboxName$("Filebox", position) + "/"
WINDOW SET "Demo", "Title", dir$
FileboxDirectory("Filebox", dir$, false)
else
print FileboxName$("Filebox", position)
print dir$+FileboxName$("Filebox", position)
endif
endif
next i

View File

@@ -26,10 +26,12 @@ export sub FileboxName$(ID$, position)
end sub
// return true, if the row position is a directory
export sub FileboxIsDirectory(ID$, position)
export sub FileboxIsDirectory(ID$, position,dir$)
local t$
t$ = columnbox get$ ID$, 1, position
if(t$ = "__Mime__=application/x-vnd.Be-directory") return true
t$ = columnbox get$ ID$, 2, position
print "t$ "+t$
//if(t$ = "__Path__="+path$+Name$"__Mime__=application/x-vnd.Be-directory") return true
if(system("test -d \""+ dir$+t$+"\"") = 0) system("addattr -t mime BEOS:TYPE application/x-vnd.Be-directory \""+dir$+t$+"\"") : return true
return false
end sub
@@ -50,48 +52,65 @@ export sub FileboxDirectory(ID$, dir$, showDot)
columnbox clear ID$
if(showDot) then
t$ = system$("ls --format=single-column --color=none -a "+dir$+" |sort -f")
t$ = system$("ls --format=single-column --color=none -aF \""+dir$+"\" |sort -f")
else
t$ = system$("ls --format=single-column --color=none "+dir$+" |sort -f")
t$ = system$("ls --format=single-column --color=none -F \""+dir$+"\" |sort -f")
endif
dim splitdir$(1)
n = split(t$, splitdir$(), "\n")
for i=1 to n-1
if(system("test -d \""+ dir$+splitdir$(i)+"\"") = 0) then
//print dir$+splitdir$(i)
//print dir$+splitdir$(i)
if (right$(splitdir$(i),1)="/") then
//if(system("test -d \""+ dir$+splitdir$(i)+"\"") = 0) then
// comment the if clause out if you want to have the direcotries "." and ".." listed
if(splitdir$(i)<>"." and splitdir$(i)<>"..") then
arraysizeDir = arraysizeDir + 1
dim directories$(arraysizeDir)
directories$(arraysizeDir-1) = splitdir$(i)
endif
// if(splitdir$(i)<>"." and splitdir$(i)<>"..") then
arraysizeDir = arraysizeDir + 1
dim directories$(arraysizeDir)
splitdir$(i) = left$(splitdir$(i),len( splitdir$(i))-1)
directories$(arraysizeDir-1) = splitdir$(i)
//endif
// handle files
else
arraysizeFiles = arraysizeFiles + 1
dim files$(arraysizeFiles)
files$(arraysizeFiles-1) = splitdir$(i)
endif
next i
for i=0 to arraysizeDir-1
FileboxAdd(ID$, directories$(i), true)
FileboxAdd(ID$, directories$(i), true,dir$)
next i
for i=0 to arraysizeFiles-1
FileboxAdd(ID$, files$(i), false)
FileboxAdd(ID$, files$(i), false,dir$)
next i
return
end sub
sub FileboxAdd(ID$, Name$, IsFolder)
sub FileboxAdd(ID$, Name$, IsFolder, path$)
local maxpos
maxpos = (columnbox count ID$) + 1
a$=""
if(IsFolder) then
columnbox add ID$, 1, maxpos, 18, "__Mime__=application/x-vnd.Be-directory"
columnbox add ID$, 1, maxpos, 18, "__SmIC__="+path$+Name$
else
columnbox add ID$, 1, maxpos, 18, "__Mime__=application/octet-stream"
columnbox add ID$, 1, maxpos, 18, "__SmIC__="+path$+Name$
//else
//columnbox add ID$, 1, maxpos, 18, "__Mime__=application/octet-stream"
endif
columnbox add ID$, 2, maxpos, 20, Name$
columnbox select ID$, 1
columnbox select ID$, 0
return
end sub

View File

@@ -0,0 +1,168 @@
export sub openfile(filename$, recordlength, numberoffields)
// specify the record(block) length and number of fields for the file
// returns the filehandle number used for other subs
static numfiles
x=open(filename$, "a")
if x=0 return 0 // error opening the file
close x
numfiles=numfiles+1
dim f$(numfiles,50,2) // f$(numfile,1-50=fieldname$
dim f(numfiles,52)
f$(numfiles,0,0)=filename$
f(numfiles,51)=recordlength
f(numfiles,52)=numberoffields
return numfiles
end sub
export sub Field( filehandle,fieldnumber, fieldname$, fieldlength)
//specify the field name and length for the field numbered fieldnumber
if fieldnumber <= f(filehandle,52) then
f$(filehandle,fieldnumber,0)=fieldname$
f(filehandle,fieldnumber)=fieldlength
f$(filehandle,fieldnumber,1)=blank$(f(filehandle,fieldnumber))
return 1
endif
return 0
end sub
export sub lset(filehandle,fieldname$,data$)
//sets data$ on the left end of the field, truncates the string if it is longer than the fieldlength
//use this to prepare the record for writing
l=len(data$)
x=0
for x=1 to 50
b$=f$(filehandle,x,0)
if (b$ = fieldname$) then
lf=f(filehandle,x)
dt$=data$
if( l > lf )dt$=left$(dt$,lf)
a$=blank$(lf-l)
if l<lf dt$=dt$+a$
f$(filehandle,x,1) = dt$
end if
next
end sub
export sub rset(filehandle,fieldname$,data$)
//sets data$ on the right end of the field, truncates the string if it is longer than the fieldlength
//use this to prepare the record for writing
l=len(data$)
x=0
for x=1 to 50
b$=f$(filehandle,x,0)
if (b$ = fieldname$) then
lf=f(filehandle,x)
dt$=data$
if( l > lf )dt$=left$(dt$,lf)
a$=blank$(lf-l)
if l<lf dt$=a$+dt$
f$(filehandle,x,1) = dt$
end if
next
end sub
export sub readfield$(File, fieldname$)
//returns the data held in fieldname$
local x
for x=1 to 50
if f$(File,x,0)=fieldname$ then
return f$(File,x,1)
end if
next
end sub
export sub write_block(recordnumber, filehandle)
// Writes all the fields to the file at this record location
// Uses seek recordnumber*recordlength before the write
// Clears the field data
// Recordnumbers start at 0. ie the first record is 0, the second is 1 etc.
filename$=f$(filehandle,0,0)
x=open(filename$, "r+")
if x=0 print "error":return 0 // error opening the file
if recordnumber = -1 then
seek x, 0, "end" // append data to the file
else
seek x, ((f(filehandle,51) +1) * (recordnumber))
endif
printstring$=""
for y=1 to f(filehandle,52)
printstring$=printstring$+f$(filehandle,y,1)
next
l=len(printstring$)
for y=1 to l
a$=left$(printstring$,1)
printstring$=right$(printstring$,len(printstring$)-1)
poke x, a$
next
poke x ,"\n"
for y=1 to f(filehandle,52)
f$(filehandle,y,1)=blank$(f(filehandle,y))
next
close x
end sub
export sub read_block(recordnumber, filehandle)
// Reads the data at this record, or the next record if recordnumber is -1
// Ffills the fields with the data
// Recordnumbers start at 0. ie the first record is 0, the second is 1 etc.
static rec
File=open(filename$, "rb")
if File=0 print "error":return -1 // error opening the file
if (recordnumber <> -1) then
rec = recordnumber
seek File, ((f(filehandle,51) +1) * (rec))
endif
a$=""
for z=1 to f(filehandle,51)
y=peek(File)
a$=a$+chr$(y)
next
for y=0 to f(filehandle,52)
f$(filehandle,y,1)= left$(a$,f(filehandle,y))
a$=right$(a$,len(a$)-f(filehandle,y))
next
rec=rec+1
return rec
end sub
sub blank$(num)
local s$
local x
s$=""
for x=1 to num
s$=s$+" "
next
return s$
end sub

View File

@@ -3436,6 +3436,7 @@ open -- open a file
Synopsis:
open a,"file","r"
open a, "File", "r+"
open #a,"file","w"
open "file" for reading as a
open "file" for writing as #a
@@ -3450,7 +3451,11 @@ The open-command opens a file for reading or writing for printing text. open com
For historical reasons the filenumber can be preceded by a hash ('#'). Note, that specifying a filenumber is optional; if it is omitted, the open-function will return a filenumber, which should then be stored in a variable for later reference. This filenumber can be a simple number or an arbitrary complex arithmetic expression, in which case braces might be necessary to save yab from getting confused.
filename -- In the synopsis above this is "file". This string specifies the name of the file to open (note the important caveat on specifying these filenames).
accessmode -- In the synopsis this is "r", "w", for reading or for writing. This string or clause specifies the mode in which the file is opened; it may be one of: "r"Open the file for reading (may also be written as for reading). If the file does not exist, the command will fail. This mode is the default, i.e. if no mode is specified with the open-command, the file will be opened with this mode.
accessmode -- In the synopsis this is "r", "w", for reading or for writing. This string or clause specifies the mode in which the file is opened; it may be one of: "r" Open the file for reading (may also be written as for reading). If the file does not exist, the command will fail. This mode is the default, i.e. if no mode is specified with the open-command, the file will be opened with this mode.
"r" -- Open the file for reading (may also be written as for reading). If the file does not exist, the command will fail.
"r+" -- Open the file for reading and writing. If the file does not exist, it will be created. Writing is limited to poke, print #a will not work in this mode.
"w" -- Open the file for writing (may also be written as for writing). If the file does not exist, it will be created.

View File

@@ -1,620 +1,620 @@
&Arithmetic
7337
7340
&
7339
7342
abs()
7345
7348
acos()
7712
7715
and()
8211
8214
asin()
9001
9004
atan()
9510
9513
bin$()
10409
10412
cos()
11015
11018
dec()
11280
11283
eor()
11799
11802
euler
12576
12579
exp()
12982
12985
frac()
13604
13607
int()
14285
14288
log()
14685
14688
max()
15344
15347
min()
16136
16139
mod()
16551
16554
or()
17264
17267
pi
18057
18060
ran()
18513
18516
sig()
19356
19359
sin()
20000
20003
sqr()
20525
20528
sqrt()
20896
20899
tan()
21248
21251
xor()
21611
21614
** or ^
22644
22647
&
23461
23464
and
23465
23468
break
23915
23918
case
24610
24613
continue
25107
25110
default
25776
25779
do
26896
26899
else
27440
27443
elsif
27979
27982
end
29449
29452
endif
30141
30144
false
30787
30790
fi
31354
31357
for
31668
31671
gosub
32630
32633
goto
33500
33503
if
34350
34353
label
36136
36139
loop
37125
37128
next
37612
37615
not
38171
38174
on gosub
38823
38826
on goto
40158
40161
on interrupt
41582
41585
logical or
42868
42871
pause
43271
43274
repeat
44499
44502
return
45186
45189
sleep
46885
46888
step
47260
47263
switch
47800
47803
then
49116
49119
true
49924
49927
until
50360
50363
wait
50967
50970
wend
51341
51344
while
51839
51842
:
52495
52498
&
53132
53135
arraydim()
53143
53146
arraysize()
54033
54036
data
56606
56609
dim
57558
57561
read
59075
59078
redim
59718
59721
restore
60157
60160
&
61226
61229
asc()
61232
61235
chr$()
62055
62058
glob()
62917
62920
abc matches a*
63878
63881
64066
64069
hex$()
64075
64078
instr()
64565
64568
left$()
65579
65582
len()
66880
66883
lower$()
67254
67257
ltrim$()
67662
67665
rtrim$()
68314
68317
mid$()
68962
68965
right$()
70230
70233
split()
71549
71552
Please enter a line: a
74186
74189
74680
74683
str$()
74706
74709
string | Result for converting 1000*pi | Description
76112
76115
79509
79512
token()
79811
79814
Please enter a line: a
82334
82337
82732
82735
trim$()
82759
82762
upper$()
83372
83375
val()
84020
84023
&
84734
84737
at()
84739
84742
clear screen
86030
86033
close
86746
86749
color
87217
87220
colour
88331
88334
eof
88478
88481
getscreen$()
89069
89072
inkey$
90217
90220
input
91436
91439
Please enter the name of a file to read: test.yab
92830
92833
92967
92970
line input
93002
93005
open
93844
93847
print
96665
96974
putscreen
99902
100211
reverse
100797
101106
screen
101576
101885
seek()
101806
102115
tell
103368
103677
using
104029
104338
#
105070
105379
at()
106443
106752
;
107722
108031
&
108368
108677
end sub
108376
108685
export
108808
109117
import foo
109855
110164
110153
110462
Calling subroutine foo.bar (okay) ...
110254
110563
110568
110877
import
111103
111412
rem Make the subroutine x easily available outside this library
112034
112343
112210
112519
0
112259
112568
112417
112726
local
112702
113011
numparams
114162
114471
return
115613
115922
static
117315
117624
1 1
118117
118426
118140
118449
sub
118335
118644
&
120614
120923
bind()
120621
120930
clipboard copy
121393
121702
clipboard paste$
122095
122404
compile
122717
123026
date$
123273
123582
doc
124998
125307
docu$
126153
126462
error
126975
127284
---Error in t.yab, line 2: Oh no ...
127618
127927
127674
127983
execute$()
127688
127997
print foo$(a$,b$)
128723
129032
128736
129045
execute()
128776
129085
exit
129181
129490
iscomputeron
129575
129884
pause
129963
130272
peek
131190
131499
peek$
136253
136562
3a
139214
139523
139235
139544
poke
139270
139579
rem
140508
140817
sleep
141622
141931
system$()
141981
142290
system()
142570
142879
thread get
143193
143502
thread remove
144542
144851
time$
145465
145774
to
146634
146943
//
147188
147497
:
147692
148001
&Drawing
148325
148634
&
148327
148636
draw circle
148339
148648
draw curve
148998
149307
draw dot
149983
150292
draw ellipse
150564
150873
draw flush
151303
151612
draw get
152433
152742
draw get$
154379
154688
draw image
155792
156101
draw line
157698
158007
draw rect
158270
158579
draw set
158926
159235
draw text
162295
162604
&
163465
163774
ismousein()
163477
163786
keyboard message$()
164199
164508
message$
166088
166397
message send
168421
168730
_Scripting:...|
169326
169635
169339
169648
mouse message$()
169566
169875
mousemove$
171590
171899
MOUSE SET Option$
172254
172563
shortcut
172760
173069
"S" for the shift key
173560
173869
173712
174021
"O" for ALT-O
173862
174171
173927
174236
ALT-X
174351
174660
174394
174703
&Printing
175345
175654
&
175347
175656
printer
175355
175664
printer setup
177728
178037
&
178752
179061
menu
178757
179066
Menu$ = "--"
179225
179534
then the menu item will be a separator line.
179282
179591
"S" for the shift key
179755
180064
These modifiers can be combined, but the following combinations do not work: "SO", "SC" and "SCO"
180004
180313
"O" for ALT-O
180055
180364
180120
180429
For the menu Head$ "File":
180918
181227
181168
181477
menu set
182260
182569
Option$ = "Disable" -- grey out the item so it cannot be selected anymore
183063
183372
183212
183521
popupmenu
184323
184632
submenu
185971
186280
Menu$ = "--"
186555
186864
then the submenu item will be a separator line.
186615
186924
"S" for the shift key
187091
187400
These modifiers can be combined, but the following combinations do not work: "SO", "SC" and "SCO"
187340
187649
"O" for ALT-O
187391
187700
187456
187765
submenu set
190342
190651
Option$ = "Disable" -- grey out the item so it cannot be selected anymore
191218
191527
191367
191676
&
192114
192423
boxview
192122
192431
stackview
193545
193854
stackview get
195659
195968
stackview set
195950
196259
&
196407
196716
button
196414
196723
button image
197729
198038
calendar
199470
199779
calendar get$
201137
201446
calendar set
201630
201939
checkbox
202055
202364
checkbox image
203312
203621
checkbox set
205539
205848
colorcontrol
205838
206147
colorcontrol get
207860
208169
colorcontrol set
208468
208777
columnbox
208804
209113
columnbox add
214014
214323
columnbox clear
215195
215504
columnbox color
215563
215872
columnbox column
216608
216917
columnbox count
217767
218076
columnbox get
218205
218514
columnbox get$
218740
219049
columnbox remove
219283
219592
columnbox select
219640
219949
listbox
220095
220404
listbox add
223060
223369
listbox clear
223538
223847
listbox count
223833
224142
listbox get
224229
224538
listbox get$
224716
225025
listbox remove
225134
225443
listbox select
225473
225782
listbox sort
226118
226427
radiobutton
226830
227139
radiobutton set
228564
228873
statusbar
228970
229279
statusbar set
230439
230748
text
230937
231246
text set
232125
232434
textedit
233243
233552
textedit add
233536
233845
textedit clear
233748
234057
textedit color
234090
234399
textedit get
234392
234701
textedit get$
234747
235056
textedit set
235021
235330
tooltip
237966
238275
tooltip color
239646
239955
&Localization
240934
241243
&
240936
241245
localize
240945
241254
# A comment starts with a #
242509
242818
242633
242942
translate$()
244199
244508
&Sound
244952
245261
&
244954
245263
beep
244959
245268
bell
245193
245502
sound play
245556
245865
sound stop
246481
246790
sound wait
246855
247164
&Window
247260
247569
&
247262
247571
alert
247268
247577
filepanel
249046
249355
window open
252336
252645
window close
255051
255360
window count
255543
255852
window get
256170
256479
window set
257891
258200