home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-387-Vol-3of3.iso
/
e
/
epmmac2.zip
/
EPM_EA.E
< prev
next >
Wrap
Text File
|
1992-12-14
|
11KB
|
266 lines
; Various routines used for manipulating extended attributes. Used by EPM.
const
EAT_ASCII = \253\255 -- FFFD
EAT_MVMT = \223\255 -- FFDF
; Returns 1 if attribute name exists; sets VAR args. EA_SEG, EA_OFS =
; start of EA buffer. EA_PTR1, 2 = pointers to start of entry and value,
; respectively, if name was found. EA_LEN, EA_ENTRYLEN, EA_VALUELEN = length
; of EA area, of entry, and of value, respectively.
; Dependencies: None
defproc find_ea(name, var ea_seg, var ea_ofs, var ea_ptr1, var ea_ptr2, var ea_len, var ea_entrylen, var ea_valuelen) =
ea_long = atol(.eaarea)
; ea_seg = itoa(rightstr(ea_long,2),10)
ea_seg = ltoa(rightstr(ea_long,2)\0\0,10)
; ea_ofs = itoa(leftstr(ea_long,2),10)
ea_ofs = ltoa(leftstr(ea_long,2)\0\0,10)
if not .eaarea then return ''; endif
ea_len = ltoa(peek(ea_seg, ea_ofs, 4),10)
ea_end = ea_ofs + ea_len
ea_ptr1 = ea_ofs + 4 -- Point past length of FEAList
do while ea_ptr1 < ea_len
; ea_flag = itoa(peek(ea_seg, ea_ptr1, 1)\0,16)
compile if EVERSION < '6.00'
ea_namelen = asc(peek(ea_seg, ea_ptr1+1, 1))
; ea_valuelen = itoa(peek(ea_seg, ea_ptr1+2, 2),10)
ea_valuelen = ltoa(peek(ea_seg, ea_ptr1+2, 2)\0\0,10)
ea_entrylen = ea_namelen + 5 + ea_valuelen
if name = peekz(ea_seg, ea_ptr1+4) then
ea_ptr2 = ea_ptr1+5+ea_namelen -- Point to start of EA value
return 1
endif
compile else
ea_namelen = asc(peek(ea_seg, ea_ptr1+5, 1))
; ea_valuelen = itoa(peek(ea_seg, ea_ptr1+6, 2),10)
ea_valuelen = ltoa(peek(ea_seg, ea_ptr1+6, 2)\0\0,10)
ea_entrylen = ltoa(peek(ea_seg, ea_ptr1, 2)\0\0,10)
if not ea_entrylen then
ea_entrylen = ea_len - ea_ptr1
endif
if name = peekz(ea_seg, ea_ptr1+8) then
ea_ptr2 = ea_ptr1+9+ea_namelen -- Point to start of EA value
return 1
endif
compile endif
ea_ptr1 = ea_ptr1 + ea_entrylen -- Point to start of next entry
enddo
; Dependencies: None
defc addea, add_ea = -- Adds a single name / value pair to an existing EA list
parse arg name data
if name='' then
sayerror 'ADD_EA <name> <value> adds the extended attribute value specified to the current file.'
return
endif
name_len = length(name)
data_len = length(data)
ea_len_incr = 9 + name_len + data_len
compile if EVERSION >= '6.00'
ea_len_incr = ((ea_len_incr+3)%4)*4; -- align on 32bit boundary
compile endif
if .eaarea then
ea_long = atol(.eaarea)
; ea_seg = itoa(rightstr(ea_long,2),10)
ea_seg = ltoa(rightstr(ea_long,2)\0\0,10)
; ea_ofs = itoa(leftstr(ea_long,2),10)
ea_ofs = ltoa(leftstr(ea_long,2)\0\0,10)
ea_old_len = ltoa(peek(ea_seg, ea_ofs, 4),10)
compile if EPM32
dynalinkc(E_DLL,
'myrealloc',
ea_long ||
atol(ea_old_len+ea_len_incr) ||
atol(0),
2)
r = 0
compile else
r = dynalink('DOSCALLS', -- Dynamic link library name
'#38', -- DosReAllocSeg
atoi(ea_old_len+ea_len_incr) || -- Number of bytes requested
rightstr(ea_long,2) )
compile endif -- EPM32
ea_ptr = ea_seg
else
compile if EPM32
ea_buffer = atol(dynalinkc(E_DLL,
'mymalloc',
atol(ea_len_incr+4), 2))
ea_ptr = ltoa(substr(ea_buffer, 3, 2)\0\0, 10)
r = 0
compile else
ea_buffer = "00" -- Initialize string pointer.
r = dynalink('DOSCALLS', -- Dynamic link library name
'#34', -- DosAllocSeg
atoi(ea_len_incr+4) || -- Number of bytes requested
selector(ea_buffer) || -- String selector
offset(ea_buffer) || -- String offset
atoi(0) ) -- Share information
; ea_ptr = itoa(ea_buffer,10)
ea_ptr = ltoa(ea_buffer\0\0,10)
compile endif -- EPM32
ea_ofs = 0
ea_old_len = 4 -- Point past length field
endif
if r then sayerror ERROR__MSG r ALLOC_HALTED__MSG; stop; endif
poke ea_ptr, ea_ofs, atol(ea_old_len+ea_len_incr)
ea_ofs = ea_ofs + ea_old_len
compile if EVERSION < '6.00'
poke ea_ptr, ea_ofs , \0 -- Start of EA: flag byte
poke ea_ptr, ea_ofs+1, chr(name_len)
poke ea_ptr, ea_ofs+2, atoi(data_len + 4) -- Value length = len(data) + len(data_type) + len(data_len)
poke ea_ptr, ea_ofs+4, name
poke ea_ptr, ea_ofs+4+name_len, \0 -- Null byte after name
poke ea_ptr, ea_ofs+5+name_len, EAT_ASCII
poke ea_ptr, ea_ofs+7+name_len, atoi(data_len)
poke ea_ptr, ea_ofs+9+name_len, data
compile else
-- we need to make sure the last entry is marked with zero length
-- to find the last entry, just look for
-- a bogus entry. "\1\2\4\3\5" seems pretty unlikely.
call find_ea("\1\2\4\3\5", xx_seg, xx_ofs, xx_ptr1, xx_ptr2, xx_len, xx_entrylen, xx_valuelen);
if (xx_len>4) and xx_entrylen then
poke ea_ptr, xx_len-xx_entrylen, atol(xx_entrylen);
endif
poke ea_ptr, ea_ofs+0, atol(0) -- Start of EA: size (last one is always marked as zero)
poke ea_ptr, ea_ofs+4, \0 -- flag byte
poke ea_ptr, ea_ofs+5, chr(name_len)
poke ea_ptr, ea_ofs+6, atoi(data_len + 4) -- Value length = len(data) + len(data_type) + len(data_len)
poke ea_ptr, ea_ofs+8, name
poke ea_ptr, ea_ofs+8+name_len, \0 -- Null byte after name
poke ea_ptr, ea_ofs+9+name_len, EAT_ASCII
poke ea_ptr, ea_ofs+11+name_len, atoi(data_len)
poke ea_ptr, ea_ofs+13+name_len, data
compile endif
.eaarea = mpfrom2short(ea_ptr,0)
; Dependencies: find_ea
defproc get_EAT_ASCII_value(name) = -- Returns the value for a given attribute name
if find_ea(name, ea_seg, ea_ofs, ea_ptr1, ea_ptr2, ea_len, ea_entrylen, ea_valuelen) then
stuff = peek(ea_seg, ea_ptr2, min(ea_valuelen,4))
if leftstr(stuff,2) = EAT_ASCII & ea_valuelen > 4 then
return peek(ea_seg, ea_ptr2+4, min(itoa(substr(stuff,3,2),10),MAXCOL))
endif
endif
; Dependencies: find_ea()
defproc delete_ea(name) =
parse arg name .
if not find_ea(name, ea_seg, ea_ofs, ea_ptr1, ea_ptr2, ea_len, ea_entrylen, ea_valuelen) then
return
endif
newlen = ea_len - ea_entrylen
poke ea_seg, ea_ofs, atol(newlen)
compile if EVERSION < '5.21'
junk = 'junk' -- Avoid problem due to bug in MEMCPYX in EPM 5.20
compile endif
if ea_ptr1+ea_entrylen < ea_len then -- If in the middle, close it up
call memcpyx(atoi(ea_ptr1) || atoi(ea_seg), atoi(ea_ptr1+ea_entrylen) || atoi(ea_seg), ea_len - ea_ptr1 - ea_entrylen)
endif
compile if EPM32
-- call dynalinkc('DOSCALLS',
-- '#305', -- DosSetMem
-- atol(ea_seg\0\0) ||
-- atol(.eaarea) ||
-- atol(newlen) ||
-- atol(19) ) -- PAG_READ | PAG_WRITE | PAG_COMMIT
call dynalinkc(E_DLL,
'myrealloc',
\0\0 || ea_seg ||
atol(newlen) ||
atol(0),
2)
r = 0
compile else
call dynalink('DOSCALLS', -- Dynamic link library name
'#38', -- DosReAllocSeg
atoi(newlen) || -- Number of bytes requested
atoi(ea_seg) )
compile endif -- EPM32
; Dependencies: find_ea(), delete_ea(), add_ea
defc type =
found = find_ea('.TYPE', ea_seg, ea_ofs, ea_ptr1, ea_ptr2, ea_len, ea_entrylen, ea_valuelen)
if not found | ea_valuelen=0 then
answer = winmessagebox(TYPE_TITLE__MSG, NO_FILE_TYPE__MSG, 16388) -- YESNO + MOVEABLE
elseif peek(ea_seg, ea_ptr2, 2)=EAT_ASCII then
; type = peek(ea_seg, ea_ptr2+4, min(itoa(peek(ea_seg, ea_ptr2+2, 2), 10), MAXCOL))
type = peek(ea_seg, ea_ptr2+4, min(ltoa(peek(ea_seg, ea_ptr2+2, 2)\0\0, 10), MAXCOL))
answer = winmessagebox(TYPE_TITLE__MSG, ONE_FILE_TYPE__MSG\13 type\13\13CHANGE_QUERY__MSG, 16388) -- YESNO + MOVEABLE
elseif peek(ea_seg, ea_ptr2, 2)=EAT_MVMT then
; ea_numentries = itoa(peek(ea_seg, ea_ptr2+4, 2),10)
ea_numentries = ltoa(peek(ea_seg, ea_ptr2+4, 2)\0\0,10)
if ea_numentries=1 then
type = ONE_FILE_TYPE__MSG
else
type = MANY_FILE_TYPES__MSG
endif
ea_entry_ofs = ea_ptr2+6
do i=1 to ea_numentries
; ea_entrylen = itoa(peek(ea_seg, ea_entry_ofs+2, 2),10)
ea_entrylen = ltoa(peek(ea_seg, ea_entry_ofs+2, 2)\0\0,10)
if peek(ea_seg, ea_entry_ofs, 2)=EAT_ASCII then
type = type\13 || peek(ea_seg, ea_entry_ofs+4,min(ea_entrylen,MAXCOL))
else
type = type\13 || NON_ASCII__MSG
endif
ea_entry_ofs = ea_entry_ofs + ea_entrylen + 4
enddo
answer = winmessagebox(TYPE_TITLE__MSG, type\13\13CHANGE_QUERY__MSG, 16388) -- YESNO + MOVEABLE
else
answer = winmessagebox(TYPE_TITLE__MSG, NON_ASCII_TYPE__MSG\13CHANGE_QUERY__MSG, 16388) -- YESNO + MOVEABLE
endif
if answer=6 then
compile if EVERSION < 5.21
newtype = listbox(SELECT_TYPE__MSG, TYPE_LIST__MSG)
if newtype then
compile else
parse value listbox(TYPE_TITLE__MSG, TYPE_LIST__MSG, '/'SET__MSG'/'CANCEL__MSG'/'HELP__MSG, 0, 0, 0, 0,
atoi(1) || atoi(1) || atoi(6040) || gethwndc(APP_HANDLE) ||
SELECT_TYPE__MSG) with button 2 newtype \0
if newtype & (button=\1) then
compile endif
if found then call delete_ea('.TYPE'); endif
'add_ea .TYPE' newtype
endif
endif
; Dependencies: find_ea(), delete_ea(), add_ea
defc subject =
found = find_ea('.SUBJECT', ea_seg, ea_ofs, ea_ptr1, ea_ptr2, ea_len, ea_entrylen, ea_valuelen)
subj = ''
if not found | ea_valuelen=0 then
answer = winmessagebox(SUBJ_TITLE__MSG, NO_SUBJECT__MSG, 16388) -- YESNO + MOVEABLE
elseif peek(ea_seg, ea_ptr2, 2)=EAT_ASCII then
; subj = peek(ea_seg, ea_ptr2+4, min(itoa(peek(ea_seg, ea_ptr2+2, 2), 10), MAXCOL))
subj = peek(ea_seg, ea_ptr2+4, min(ltoa(peek(ea_seg, ea_ptr2+2, 2)\0\0, 10), MAXCOL))
answer = winmessagebox(SUBJ_TITLE__MSG, SUBJECT_IS__MSG\13 subj\13\13||CHANGE_QUERY__MSG, 16388) -- YESNO + MOVEABLE
else
answer = winmessagebox(SUBJ_TITLE__MSG, NON_ASCII_SUBJECT__MSG\13||CHANGE_QUERY__MSG, 16388) -- YESNO + MOVEABLE
endif
if answer=6 then
compile if EVERSION < 5.21 -- The old way
newsubj = entrybox(SELECT_SUBJECT__MSG, '', subj, 40, 40)
if newsubj then
compile else
parse value entrybox(SUBJ_TITLE__MSG, '/'SET__MSG'/'CANCEL__MSG'/'HELP__MSG, subj, 40, 40,
atoi(1) || atoi(6050) || gethwndc(APP_HANDLE) || SELECT_SUBJECT__MSG) with button 2 newsubj \0
if newsubj & (button=\1) then
compile endif
if found then call delete_ea('.SUBJECT'); endif
'add_ea .SUBJECT' newsubj
endif
endif