home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epmsmp.zip / GROUP.E < prev    next >
Text File  |  1993-05-14  |  8KB  |  203 lines

  1. ; Group.e, by Larry Margolis
  2. ;
  3. ; Defines a SaveGroup command which saves the contents of the edit ring
  4. ; as a group, and a LoadGroup command which reloads that group, positioning
  5. ; each file as it was when the SaveGroup was executed.  For OS/2 2.0 users,
  6. ; optionally creates a desktop icon for the group.  EPM 6.0 can do this
  7. ; directly; users of other versions must extract the command file at the
  8. ; end and save it as a MAKEGRP.CMD in the PATH.
  9.  
  10. compile if not defined(SMALL)  -- If SMALL not defined, then being separately compiled
  11.  include 'stdconst.e'            -- (needed for MB_ constants)
  12.  define INCLUDING_FILE = 'GROUP.E'
  13. const
  14.    tryinclude 'MYCNF.E'        -- The user's configuration customizations.
  15.  
  16.  compile if not defined(SITE_CONFIG)
  17.     const SITE_CONFIG = 'SITECNF.E'
  18.  compile endif
  19.  compile if SITE_CONFIG
  20.     tryinclude SITE_CONFIG
  21.  compile endif
  22.  
  23. const
  24.  compile if not defined(NLS_LANGUAGE)
  25.    NLS_LANGUAGE = 'ENGLISH'
  26.  compile endif
  27. include NLS_LANGUAGE'.e'          -- Needed for UNNAMED_FILE_NAME
  28. compile endif  -- not defined(SMALL)
  29.  
  30. const
  31. compile if not defined(INCLUDE_DESKTOP_SUPPORT)
  32.    INCLUDE_DESKTOP_SUPPORT = 1
  33. compile endif
  34. compile if EVERSION >= 6
  35.    CO_FAILIFEXISTS    = 0
  36.    CO_REPLACEIFEXISTS = 1
  37.    CO_UPDATEIFEXISTS  = 2
  38. compile endif
  39.  
  40. defc savegroup =
  41.    universal app_hini
  42.    getfileid startfid
  43.    do i=1 to filesinring(1)  -- Provide an upper limit; prevent looping forever
  44.       if .filename=UNNAMED_FILE_NAME then
  45.          if .last<>1 or textline(1)<>'' then
  46.             activatefile startfid
  47.             sayerror 'An unnamed file exists in the ring; it must have a name to save the ring.'
  48.             return
  49.          endif
  50.       endif
  51.       next_file
  52.       getfileid curfile
  53.       if curfile = startfid then leave; endif
  54.    enddo  -- Loop through all files in ring
  55.  
  56.    group_name = arg(1)
  57.    if group_name='' then
  58.       group_name = entrybox('Group name')
  59.    endif
  60.    if group_name='' then
  61.       return
  62.    endif
  63.    tempstr = queryprofile( app_hini,  group_name, 'ENTRIES')
  64.    if tempstr<>'' then
  65.       if MBID_OK <> winmessagebox('Save Group', 'Group already exists.  OK to replace it?', 16417) then  -- MB_OKCANCEL + MB_ICONEXCLAMATION + MB_MOVEABLE
  66.          return
  67.       endif
  68.    endif
  69.  
  70.    do i=1 to filesinring(1)  -- Provide an upper limit; prevent looping forever
  71.       call setprofile(app_hini, group_name, 'FILE'i, .filename)
  72.       call setprofile(app_hini, group_name, 'POSN'i, .line .col .cursorx .cursory)
  73.       next_file
  74.       getfileid curfile
  75.       if curfile = startfid then leave; endif
  76.    enddo  -- Loop through all files in ring
  77.    call setprofile(app_hini, group_name, 'ENTRIES', i)
  78.  
  79.    if tempstr<>'' & tempstr>i then
  80.       do j = i+1 to tempstr
  81.          call setprofile(app_hini, group_name, 'FILE'j, '')
  82.          call setprofile(app_hini, group_name, 'POSN'j, '')
  83.       enddo
  84.    endif
  85. compile if INCLUDE_DESKTOP_SUPPORT -- Ask whether to include on Desktop?
  86.  compile if EVERSION < 6  -- Don't need to check if EPM 6.00!
  87.    if dos_version() >= 2000 then  -- 1.3 doesn't have desktop
  88.  compile endif
  89.    if MBID_YES = winmessagebox('Save Group', 'Add a program object to the OS/2 desktop for this group?', 16404) then  -- MB_YESNO + MB_ICONQUESTION + MB_MOVEABLE
  90.  compile if EVERSION>=6
  91.       tib_ptr = 1234                /* 4-byte place to put a far pointer */
  92.       pib_ptr = 1234
  93.       call dynalink32('DOSCALLS',           /* dynamic link library name   */
  94.                     '#312',               /* ordinal value for DOS32GETINFOBLOCKS */
  95.                     address(tib_ptr) ||
  96.                     address(pib_ptr) )
  97.       sayerror 'tib_ptr =' c2x(tib_ptr) 'pib_ptr =' c2x(pib_ptr)
  98.       pib = peek(itoa(rightstr(pib_ptr,2),10), itoa(leftstr(pib_ptr,2),10), 28)
  99.       epm_cmd = peekz(substr(pib, 13, 4))
  100.  
  101.       class_name = "WPProgram"\0
  102.                       /* ^ = ASCII 94 = 'hat' */
  103.       title = "EPM Group:^"group_name\0
  104.       setup_string = "EXENAME="epm_cmd";PROGTYPE=PM;STARTUPDIR="directory()";PARAMETERS='loadgroup" group_name"';"\0
  105.       location = "<WP_DESKTOP>"\0
  106.       rc = 0
  107.       hobj=dynalink32('PMWP',           /* dynamic link library name   */
  108.                       '#281',           -- 'WinCreateObject'
  109.                       address(class_name)   ||
  110.                       address(title)        ||
  111.                       address(setup_string) ||
  112.                       address(location)     ||
  113.                       atol(CO_REPLACEIFEXISTS), 2)
  114. ;     if rc then hobj = hobj'; rc='rc '-' sayerrortext(rc); endif
  115. ;     sayerror 'hobject =' hobj
  116.       if not hobj then
  117.          sayerror 'Unable to create the program object in the Desktop folder'
  118.       endif
  119.  compile else  -- Can't do it directly; call a command file:
  120.       seg_ptr = 1234                /* 4-byte place to put a far pointer */
  121.       cmd_ptr = 1234
  122.       call dynalink('DOSCALLS',           /* dynamic link library name   */
  123.                     '#91',                /* ordinal value for DOSGETENV */
  124.                     selector(seg_ptr) ||  /* pointer to env. segment     */
  125.                     offset(seg_ptr)   ||
  126.                     selector(cmd_ptr) ||  /* pointer to offset after     */
  127.                     offset(cmd_ptr)     ) /*    COMSPEC; we don't need   */
  128.       env_seg=itoa(seg_ptr,10)
  129.       cmd_ofs=ltoa(cmd_ptr,10)
  130.       epm_cmd=peekz(env_seg, cmd_ofs)
  131.       'rx makegrp' epm_cmd'*'group_name  -- Requires separate MakeGrp.erx
  132.  compile endif
  133.    endif
  134.  compile if EVERSION < 6
  135.    endif  -- dos_version()
  136.  compile endif
  137. compile endif  -- INCLUDE_DESKTOP_SUPPORT
  138.  
  139. defc loadgroup =
  140.    universal app_hini
  141.    getfileid startfid
  142.    group_name = arg(1)
  143.    if group_name='' then
  144.       group_name = entrybox('Group name')
  145.    endif
  146.    if group_name='' then
  147.       return
  148.    endif
  149.    howmany = queryprofile( app_hini,  group_name, 'ENTRIES')
  150.    if howmany='' then
  151.       sayerror 'Group unknown.'
  152.       return
  153.    endif
  154.    do i=1 to howmany
  155.  compile if EVERSION >= '5.21'
  156.       display -8
  157.  compile endif
  158.       sayerror 'Loading file' i 'of' howmany
  159.  compile if EVERSION >= '5.21'
  160.       display 8
  161.  compile endif
  162.       this_file = queryprofile(app_hini, group_name, 'FILE'i)
  163.       if leftstr(this_file, 5)='.DOS ' then
  164.          subword(this_file, 2)  -- execute the command
  165.       elseif this_file=UNNAMED_FILE_NAME then
  166.          'xcom e /n'
  167.       else
  168.          'e' this_file
  169.       endif
  170.       if not rc | rc=sayerror('Lines truncated') then
  171.          call prestore_pos(queryprofile(app_hini, group_name, 'POSN'i))
  172.       endif
  173.    enddo
  174.    activatefile startfid
  175.    nextfile
  176.  
  177. /*------------ Cut here --------------------------------------
  178.  
  179. /***********************************************************/
  180. /* MakeGrp.erx, for use by EPM's SaveFldr command.         */
  181. /***********************************************************/
  182.  
  183. parse arg epm_cmd'*'group_name
  184. if group_name='' then
  185.    parse source . . me .
  186.    'sayerror 'me':  Missing group name.'
  187.    exit 4
  188. endif
  189.  
  190. If RxFuncQuery('SysLoadFuncs') Then Do
  191.   Call RxFuncAdd 'SysLoadFuncs', 'REXXUTIL', 'SysLoadFuncs'
  192.   Call SysLoadFuncs
  193. End
  194.                                           /* ^ = ASCII 94 = 'hat' */
  195. Call SysCreateObject "WPProgram", "EPM Group:^"group_name, "<WP_DESKTOP>",,
  196.     "EXENAME="epm_cmd";PROGTYPE=PM;STARTUPDIR="directory() || ,
  197.     ";PARAMETERS='loadgroup" group_name"';", "U"
  198. If Result <> 1 Then "Sayerror Unable to create the program object in the Desktop folder"
  199.  
  200. Exit 0
  201.  
  202. -----------------------  Cut here --------------------------*/
  203.