home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / prodtool / epm / e_macros / epm_ea.e < prev    next >
Encoding:
Text File  |  1992-08-13  |  8.4 KB  |  190 lines

  1. ; Various routines used for manipulating extended attributes.  Used by EPM.
  2.  
  3. const
  4.    EAT_ASCII    = \253\255    -- FFFD
  5.    EAT_MVMT     = \223\255    -- FFDF
  6.  
  7. ;  Returns 1 if attribute name exists; sets VAR args.  EA_SEG, EA_OFS =
  8. ; start of EA buffer.  EA_PTR1, 2 = pointers to start of entry and value,
  9. ; respectively, if name was found.  EA_LEN, EA_ENTRYLEN, EA_VALUELEN = length
  10. ; of EA area, of entry, and of value, respectively.
  11. ; Dependencies:  None
  12. 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) =
  13.    ea_long = atol(.eaarea)
  14. ;  ea_seg = itoa(rightstr(ea_long,2),10)
  15.    ea_seg = ltoa(rightstr(ea_long,2)\0\0,10)
  16. ;  ea_ofs = itoa(leftstr(ea_long,2),10)
  17.    ea_ofs = ltoa(leftstr(ea_long,2)\0\0,10)
  18.    if not .eaarea then return ''; endif
  19.    ea_len  = ltoa(peek(ea_seg, ea_ofs, 4),10)
  20.    ea_end = ea_ofs + ea_len
  21.    ea_ptr1 = ea_ofs + 4                     -- Point past length of FEAList
  22.    do while ea_ptr1 < ea_len
  23. ;     ea_flag = itoa(peek(ea_seg, ea_ptr1, 1)\0,16)
  24.       ea_namelen  = asc(peek(ea_seg, ea_ptr1+1, 1))
  25. ;     ea_valuelen = itoa(peek(ea_seg, ea_ptr1+2, 2),10)
  26.       ea_valuelen = ltoa(peek(ea_seg, ea_ptr1+2, 2)\0\0,10)
  27.       ea_entrylen = ea_namelen + 5 + ea_valuelen
  28.       if name = peekz(ea_seg, ea_ptr1+4) then
  29.          ea_ptr2 = ea_ptr1+5+ea_namelen  -- Point to start of EA value
  30.          return 1
  31.       endif
  32.       ea_ptr1 = ea_ptr1 + ea_entrylen       -- Point to start of next entry
  33.    enddo
  34.  
  35.  
  36. ; Dependencies:  None
  37. defc addea, add_ea =                 -- Adds a single name / value pair to an existing EA list
  38.    parse arg name data
  39.    if name='' then
  40.       sayerror 'ADD_EA <name> <value> adds the extended attribute value specified to the current file.'
  41.       return
  42.    endif
  43.    name_len = length(name)
  44.    data_len = length(data)
  45.    ea_len_incr = 9 + name_len + data_len
  46.    if .eaarea then
  47.       ea_long = atol(.eaarea)
  48. ;     ea_seg = itoa(rightstr(ea_long,2),10)
  49.       ea_seg = ltoa(rightstr(ea_long,2)\0\0,10)
  50. ;     ea_ofs = itoa(leftstr(ea_long,2),10)
  51.       ea_ofs = ltoa(leftstr(ea_long,2)\0\0,10)
  52.       ea_old_len  = ltoa(peek(ea_seg, ea_ofs, 4),10)
  53.       r =  dynalink('DOSCALLS',           -- Dynamic link library name
  54.                '#38',                     -- DosReAllocSeg
  55.                atoi(ea_old_len+ea_len_incr) ||  -- Number of bytes requested
  56.                rightstr(ea_long,2) )
  57.       ea_ptr = ea_seg
  58.    else
  59.       ea_buffer = "00"                    -- Initialize string pointer.
  60.       r =  dynalink('DOSCALLS',           -- Dynamic link library name
  61.                '#34',                     -- DosAllocSeg
  62.                atoi(ea_len_incr+4)    ||  -- Number of bytes requested
  63.                selector(ea_buffer)    ||  -- String selector
  64.                offset(ea_buffer)      ||  -- String offset
  65.                atoi(0) )                  -- Share information
  66. ;     ea_ptr = itoa(ea_buffer,10)
  67.       ea_ptr = ltoa(ea_buffer\0\0,10)
  68.       ea_ofs = 0
  69.       ea_old_len  = 4           -- Point past length field
  70.    endif
  71.  
  72.    if r then sayerror ERROR__MSG r ALLOC_HALTED__MSG; stop; endif
  73.    poke ea_ptr, ea_ofs, atol(ea_old_len+ea_len_incr)
  74.    ea_ofs = ea_ofs + ea_old_len
  75.    poke ea_ptr, ea_ofs  , \0              -- Start of EA:  flag byte
  76.    poke ea_ptr, ea_ofs+1, chr(name_len)
  77.    poke ea_ptr, ea_ofs+2, atoi(data_len + 4)     -- Value length = len(data) + len(data_type) + len(data_len)
  78.    poke ea_ptr, ea_ofs+4, name
  79.    poke ea_ptr, ea_ofs+4+name_len, \0     -- Null byte after name
  80.    poke ea_ptr, ea_ofs+5+name_len, EAT_ASCII
  81.    poke ea_ptr, ea_ofs+7+name_len, atoi(data_len)
  82.    poke ea_ptr, ea_ofs+9+name_len, data
  83.    .eaarea = mpfrom2short(ea_ptr,0)
  84.  
  85.  
  86. ; Dependencies:  find_ea
  87. defproc get_EAT_ASCII_value(name) =  -- Returns the value for a given attribute name
  88.    if find_ea(name, ea_seg, ea_ofs, ea_ptr1, ea_ptr2, ea_len, ea_entrylen, ea_valuelen) then
  89.       stuff = peek(ea_seg, ea_ptr2, min(ea_valuelen,4))
  90.       if leftstr(stuff,2) = EAT_ASCII & ea_valuelen > 4 then
  91.          return peek(ea_seg, ea_ptr2+4, min(itoa(substr(stuff,3,2),10),MAXCOL))
  92.       endif
  93.    endif
  94.  
  95.  
  96. ; Dependencies:  find_ea()
  97. defproc delete_ea(name) =
  98.    parse arg name .
  99.    if not find_ea(name, ea_seg, ea_ofs, ea_ptr1, ea_ptr2, ea_len, ea_entrylen, ea_valuelen) then
  100.       return
  101.    endif
  102.    newlen = ea_len - ea_entrylen
  103.    poke ea_seg, ea_ofs, atol(newlen)
  104. compile if EVERSION < '5.21'
  105.    junk = 'junk'  -- Avoid problem due to bug in MEMCPYX in EPM 5.20
  106. compile endif
  107.    if ea_ptr1+ea_entrylen < ea_len then  -- If in the middle, close it up
  108.       call memcpyx(atoi(ea_ptr1) || atoi(ea_seg), atoi(ea_ptr1+ea_entrylen) || atoi(ea_seg), ea_len - ea_ptr1 - ea_entrylen)
  109.    endif
  110.    call dynalink('DOSCALLS',           -- Dynamic link library name
  111.             '#38',                     -- DosReAllocSeg
  112.             atoi(newlen)           ||  -- Number of bytes requested
  113.             atoi(ea_seg) )
  114.  
  115.  
  116. ; Dependencies:  find_ea(), delete_ea(), add_ea
  117. defc type =
  118.    found = find_ea('.TYPE', ea_seg, ea_ofs, ea_ptr1, ea_ptr2, ea_len, ea_entrylen, ea_valuelen)
  119.    if not found | ea_valuelen=0 then
  120.       answer = winmessagebox(TYPE_TITLE__MSG, NO_FILE_TYPE__MSG, 16388) -- YESNO + MOVEABLE
  121.    elseif peek(ea_seg, ea_ptr2, 2)=EAT_ASCII then
  122. ;     type = peek(ea_seg, ea_ptr2+4, min(itoa(peek(ea_seg, ea_ptr2+2, 2), 10), MAXCOL))
  123.       type = peek(ea_seg, ea_ptr2+4, min(ltoa(peek(ea_seg, ea_ptr2+2, 2)\0\0, 10), MAXCOL))
  124.       answer = winmessagebox(TYPE_TITLE__MSG, ONE_FILE_TYPE__MSG\13 type\13\13CHANGE_QUERY__MSG, 16388) -- YESNO + MOVEABLE
  125.    elseif peek(ea_seg, ea_ptr2, 2)=EAT_MVMT then
  126. ;     ea_numentries = itoa(peek(ea_seg, ea_ptr2+4, 2),10)
  127.       ea_numentries = ltoa(peek(ea_seg, ea_ptr2+4, 2)\0\0,10)
  128.       if ea_numentries=1 then
  129.          type = ONE_FILE_TYPE__MSG
  130.       else
  131.          type = MANY_FILE_TYPES__MSG
  132.       endif
  133.       ea_entry_ofs = ea_ptr2+6
  134.       do i=1 to ea_numentries
  135. ;        ea_entrylen = itoa(peek(ea_seg, ea_entry_ofs+2, 2),10)
  136.          ea_entrylen = ltoa(peek(ea_seg, ea_entry_ofs+2, 2)\0\0,10)
  137.          if peek(ea_seg, ea_entry_ofs, 2)=EAT_ASCII then
  138.             type = type\13 || peek(ea_seg, ea_entry_ofs+4,min(ea_entrylen,MAXCOL))
  139.          else
  140.             type = type\13 || NON_ASCII__MSG
  141.          endif
  142.          ea_entry_ofs = ea_entry_ofs + ea_entrylen + 4
  143.       enddo
  144.       answer = winmessagebox(TYPE_TITLE__MSG, type\13\13CHANGE_QUERY__MSG, 16388) -- YESNO + MOVEABLE
  145.    else
  146.       answer = winmessagebox(TYPE_TITLE__MSG, NON_ASCII_TYPE__MSG\13CHANGE_QUERY__MSG, 16388) -- YESNO + MOVEABLE
  147.    endif
  148.    if answer=6 then
  149. compile if EVERSION < 5.21
  150.       newtype = listbox(SELECT_TYPE__MSG, TYPE_LIST__MSG)
  151.       if newtype then
  152. compile else
  153.       parse value listbox(TYPE_TITLE__MSG, TYPE_LIST__MSG, '/'SET__MSG'/'CANCEL__MSG'/'HELP__MSG, 0, 0, 0, 0,
  154.                           atoi(1) || atoi(1) || atoi(6040) || gethwndc(APP_HANDLE) ||
  155.                           SELECT_TYPE__MSG) with button 2 newtype \0
  156.       if newtype & (button=\1) then
  157. compile endif
  158.          if found then call delete_ea('.TYPE'); endif
  159.          'add_ea .TYPE' newtype
  160.       endif
  161.    endif
  162.  
  163.  
  164. ; Dependencies:  find_ea(), delete_ea(), add_ea
  165. defc subject =
  166.    found = find_ea('.SUBJECT', ea_seg, ea_ofs, ea_ptr1, ea_ptr2, ea_len, ea_entrylen, ea_valuelen)
  167.    subj = ''
  168.    if not found | ea_valuelen=0 then
  169.       answer = winmessagebox(SUBJ_TITLE__MSG, NO_SUBJECT__MSG, 16388) -- YESNO + MOVEABLE
  170.    elseif peek(ea_seg, ea_ptr2, 2)=EAT_ASCII then
  171. ;     subj = peek(ea_seg, ea_ptr2+4, min(itoa(peek(ea_seg, ea_ptr2+2, 2), 10), MAXCOL))
  172.       subj = peek(ea_seg, ea_ptr2+4, min(ltoa(peek(ea_seg, ea_ptr2+2, 2)\0\0, 10), MAXCOL))
  173.       answer = winmessagebox(SUBJ_TITLE__MSG, SUBJECT_IS__MSG\13 subj\13\13||CHANGE_QUERY__MSG, 16388) -- YESNO + MOVEABLE
  174.    else
  175.       answer = winmessagebox(SUBJ_TITLE__MSG, NON_ASCII_SUBJECT__MSG\13||CHANGE_QUERY__MSG, 16388) -- YESNO + MOVEABLE
  176.    endif
  177.    if answer=6 then
  178. compile if EVERSION < 5.21  -- The old way
  179.       newsubj = entrybox(SELECT_SUBJECT__MSG, '', subj, 40, 40)
  180.       if newsubj then
  181. compile else
  182.       parse value entrybox(SUBJ_TITLE__MSG, '/'SET__MSG'/'CANCEL__MSG'/'HELP__MSG, subj, 40, 40,
  183.              atoi(1) || atoi(6050) || gethwndc(APP_HANDLE) || SELECT_SUBJECT__MSG) with button 2 newsubj \0
  184.       if newsubj & (button=\1) then
  185. compile endif
  186.          if found then call delete_ea('.SUBJECT'); endif
  187.          'add_ea .SUBJECT' newsubj
  188.       endif
  189.    endif
  190.