home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epmmac2.zip / GROUPS.E < prev    next >
Text File  |  1996-05-21  |  12KB  |  305 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.x 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 = 'GROUPS.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.  
  29. defmain
  30.    ''arg(1)
  31. compile endif  -- not defined(SMALL)
  32.  
  33. const
  34. compile if not defined(INCLUDE_DESKTOP_SUPPORT)
  35.    INCLUDE_DESKTOP_SUPPORT = 1
  36. compile endif
  37.    CO_FAILIFEXISTS    = 0
  38.    CO_REPLACEIFEXISTS = 1
  39.    CO_UPDATEIFEXISTS  = 2
  40.    GROUPS__MSG =    'Groups'  -- Messagebox title
  41.    GR_SAVE_PROMPT = 'Save edit ring as a group - optionally to the desktop.'
  42.    GR_SAVE_PROMPT2 = 'The names and cursor positions of all files loaded will be saved..'
  43.    GR_LOAD_PROMPT = 'Load a previously saved group.'
  44.    GR_DELETE_PROMPT = 'OK to delete group:'
  45.    GR_NONE_FOUND = 'No saved groups found!'
  46.  
  47. defc groups_actionlist
  48. universal ActionsList_FileID  -- This is the fileid that gets the line(s)
  49.  
  50. insertline '|group_savegroup|'GR_SAVE_PROMPT'  'GR_SAVE_PROMPT2'|groups|', ActionsList_FileID.last+1, ActionsList_FileID
  51. insertline '|group_loadgroup|'GR_LOAD_PROMPT'|groups|', ActionsList_FileID.last+1, ActionsList_FileID
  52.  
  53. defc group_savegroup
  54.    if arg(1) = 'S' then       -- button Selected
  55.       sayerror 0
  56.       'savegroup'
  57.    elseif arg(1) = 'I' then   -- button Initialized
  58.       display -8
  59.       sayerror GR_SAVE_PROMPT
  60.       display 8
  61.    elseif arg(1) = 'H' then   -- button Help
  62.       call winmessagebox(GROUPS__MSG, GR_SAVE_PROMPT, MB_OK + MB_INFORMATION + MB_MOVEABLE)
  63.    elseif arg(1) = 'E' then   -- button End
  64. ;;    sayerror 0
  65.    endif
  66.  
  67. defc group_loadgroup
  68.    if arg(1) = 'S' then       -- button Selected
  69.       sayerror 0
  70.       'loadgroup'
  71.    elseif arg(1) = 'I' then   -- button Initialized
  72.       display -8
  73.       sayerror GR_LOAD_PROMPT
  74.       display 8
  75.    elseif arg(1) = 'H' then   -- button Help
  76.       call winmessagebox(GROUPS__MSG, GR_LOAD_PROMPT, MB_OK + MB_INFORMATION + MB_MOVEABLE)
  77.    elseif arg(1) = 'E' then   -- button End
  78. ;;    sayerror 0
  79.    endif
  80.  
  81. compile if not defined(SMALL)  -- If being separately compiled separately, LOADGROUP command
  82.                                -- might not be known - execute via our DEFMAIN.
  83.    define loadgroup_cmd = 'groups loadgroup'
  84. compile else
  85.    define loadgroup_cmd = 'loadgroup'
  86. compile endif
  87.  
  88. defc savegroup =
  89.    universal app_hini
  90.    getfileid startfid
  91.    do i=1 to filesinring(1)  -- Provide an upper limit; prevent looping forever
  92.       if .filename=UNNAMED_FILE_NAME then
  93.          if .last<>1 or textline(1)<>'' then
  94.             activatefile startfid
  95.             sayerror 'An unnamed file exists in the ring; it must have a name to save the ring.'
  96.             return
  97.          endif
  98.       endif
  99.       next_file
  100.       getfileid curfile
  101.       if curfile = startfid then leave; endif
  102.    enddo  -- Loop through all files in ring
  103.  
  104.    group_name = arg(1)
  105.    if group_name='' then
  106.       group_name = entrybox('Group name')
  107.    endif
  108.    if group_name='' then
  109.       return
  110.    endif
  111.    tempstr = queryprofile( app_hini,  group_name, 'ENTRIES')
  112.    if tempstr<>'' then
  113.       if MBID_OK <> winmessagebox('Save Group', 'Group already exists.  OK to replace it?', 16417) then  -- MB_OKCANCEL + MB_ICONEXCLAMATION + MB_MOVEABLE
  114.          return
  115.       endif
  116.    endif
  117.  
  118.    do i=1 to filesinring(1)  -- Provide an upper limit; prevent looping forever
  119.       call setprofile(app_hini, group_name, 'FILE'i, .filename)
  120.       call setprofile(app_hini, group_name, 'POSN'i, .line .col .cursorx .cursory)
  121.       next_file
  122.       getfileid curfile
  123.       if curfile = startfid then leave; endif
  124.    enddo  -- Loop through all files in ring
  125.    call setprofile(app_hini, group_name, 'ENTRIES', i)
  126.  
  127.    if tempstr<>'' & tempstr>i then
  128.       do j = i+1 to tempstr
  129.          call setprofile(app_hini, group_name, 'FILE'j, '')
  130.          call setprofile(app_hini, group_name, 'POSN'j, '')
  131.       enddo
  132.    endif
  133. compile if INCLUDE_DESKTOP_SUPPORT -- Ask whether to include on Desktop?
  134.    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
  135.       tib_ptr = 1234                /* 4-byte place to put a far pointer */
  136.       pib_ptr = 1234
  137.       call dynalink32('DOSCALLS',           /* dynamic link library name   */
  138.                     '#312',               /* ordinal value for DOS32GETINFOBLOCKS */
  139.                     address(tib_ptr) ||
  140.                     address(pib_ptr) )
  141. ;     sayerror 'tib_ptr =' c2x(tib_ptr) 'pib_ptr =' c2x(pib_ptr)
  142.       pib = peek(itoa(rightstr(pib_ptr,2),10), itoa(leftstr(pib_ptr,2),10), 28)
  143.       epm_cmd = peekz(substr(pib, 13, 4))
  144.  
  145.       class_name = "WPProgram"\0
  146.                       /* ^ = ASCII 94 = 'hat' */
  147.       title = "EPM Group:^"group_name\0
  148.       setup_string = "EXENAME="epm_cmd";PROGTYPE=PM;STARTUPDIR="directory()";PARAMETERS='"loadgroup_cmd group_name"';"\0
  149.       location = "<WP_DESKTOP>"\0
  150.       rc = 0
  151.       hobj=dynalink32('PMWP',           /* dynamic link library name   */
  152.                       '#281',           -- 'WinCreateObject'
  153.                       address(class_name)   ||
  154.                       address(title)        ||
  155.                       address(setup_string) ||
  156.                       address(location)     ||
  157.                       atol(CO_REPLACEIFEXISTS), 2)
  158. ;     if rc then hobj = hobj'; rc='rc '-' sayerrortext(rc); endif
  159. ;     sayerror 'hobject =' hobj
  160.       if not hobj then
  161.          sayerror 'Unable to create the program object in the Desktop folder'
  162.       endif
  163.    endif
  164. compile endif  -- INCLUDE_DESKTOP_SUPPORT
  165.  
  166. defc loadgroup =
  167.    universal app_hini
  168.    getfileid startfid
  169.    group_name = arg(1)
  170.    if group_name='' then
  171.       parse value entrybox('Group name',
  172.                            '/'OK__MSG'/'LIST__MSG'/'Cancel__MSG'/',
  173.                            '', '', 64,                -- Entrytext, cols, maxchars
  174.                            atoi(1) || atoi(0000) || gethwndc(APP_HANDLE)) with button 2 group_name \0
  175.       if button=\2 then -- User asked for a list
  176.          bufhndl = buffer(CREATEBUF, 'groups', MAXBUFSIZE, 1 )  -- Create a private buffer
  177. compile if EPM32
  178.          retlen = \0\0\0\0
  179.          l = dynalink32('PMSHAPI',
  180.                         '#115',               -- PRF32QUERYPROFILESTRING
  181.                         atol(app_hini)    ||  -- HINI_PROFILE
  182.                         atol(0)           ||  -- Application name is NULL; returns all apps
  183.                         atol(0)           ||  -- Key name
  184.                         atol(0)           ||  -- Default return string is NULL
  185.                         atoi(0) || atoi(bufhndl)  ||  -- pointer to returned string buffer
  186.                         atol(65535)       ||       -- max length of returned string
  187.                         address(retlen), 2)         -- length of returned string
  188. compile else
  189.          l =  dynalink( 'PMSHAPI',
  190.                         'PRFQUERYPROFILESTRING',
  191.                         atol_swap(app_hini) ||  -- HINI_PROFILE
  192.                         atol(0)             ||  -- Application name is NULL; returns all apps
  193.                         atol(0)             ||  -- Key name is NULL; returns all keys
  194.                         atol(0)             ||  -- Default return string is NULL
  195.                         address(inidata)    ||  -- pointer to returned string buffer
  196.                         atoi(bufhndl) || atoi(0)  ||  -- pointer to returned string buffer
  197.                         atol_swap(65535), 2)        -- max length of returned string
  198. compile endif
  199.          poke bufhndl, 65535, \0
  200.          if not l then sayerror 'Nothing in .INI file???'; return; endif
  201.          getfileid startfid
  202.          'xcom e /c /q tempfile'
  203.          if rc<>-282 then  -- sayerror('New file')
  204.             sayerror ERROR__MSG rc BAD_TMP_FILE__MSG sayerrortext(rc)
  205.             call buffer(FREEBUF, bufhndl)
  206.             return
  207.          endif
  208.          .autosave = 0
  209.          browse_mode = browse()     -- query current state
  210.          if browse_mode then call browse(0); endif
  211.          buf_ofs = 0
  212.          do while buf_ofs < l
  213.             this_group = peekz(bufhndl, buf_ofs)
  214.             entries = queryprofile(app_hini, this_group, 'ENTRIES')
  215.             if entries <> '' then
  216.                insertline this_group, .last+1
  217.             endif
  218.             buf_ofs = buf_ofs + length(this_group) + 1
  219.          enddo
  220.          call buffer(FREEBUF, bufhndl)
  221.          if .last>2 then
  222.             getfileid fileid
  223.             call sort(2, .last, 1, 40, fileid, 'I')
  224.          endif
  225.          if browse_mode then call browse(1); endif  -- restore browse state
  226.          if .last=1 then
  227.             'xcom quit'
  228.             call winmessagebox(GROUPS__MSG, GR_NONE_FOUND, MB_CANCEL + MB_ICONEXCLAMATION + MB_MOVEABLE)
  229.             return
  230.          endif
  231.  
  232.          if listbox_buffer_from_file(startfid, bufhndl, noflines, usedsize) then return; endif
  233. compile if EPM32
  234.          parse value listbox('Select group name', \0 || atol(usedsize) || atoi(32) || atoi(bufhndl),
  235. compile else
  236.          parse value listbox('Select group name', \0 || atoi(usedsize) || atoi(bufhndl) || atoi(32),
  237. compile endif
  238.                                    '/~Load/~Delete.../'Cancel__MSG, 1, 35, min(noflines,12), 0,   -- Buttons, row, col, height, width
  239.   compile if EVERSION >= 5.60
  240.                                    gethwndc(APP_HANDLE) || atoi(1) || atoi(1) || atoi(0000)) with button 2 group_name \0
  241.   compile else
  242.                                    atoi(1) || atoi(1) || atoi(0000) || gethwndc(APP_HANDLE)) with button 2 group_name \0
  243.   compile endif
  244.          call buffer(FREEBUF, bufhndl)
  245.          if button=\2 then -- 'Delete' selected
  246.             if MBID_OK <> winmessagebox(GROUPS__MSG, GR_DELETE_PROMPT\10 group_name, MB_OKCANCEL + MB_QUERY + MB_MOVEABLE) then
  247.                return
  248.             endif
  249.             call setprofile( app_hini, group_name, '', '')
  250.          endif
  251.       endif  -- button = \2
  252.       if button <> \1 then
  253.          return
  254.       endif
  255.    endif
  256.    if group_name='' then
  257.       return
  258.    endif
  259.    howmany = queryprofile( app_hini,  group_name, 'ENTRIES')
  260.    if howmany='' then
  261.       sayerror 'Group unknown.'
  262.       return
  263.    endif
  264.    do i=1 to howmany
  265.       display -8
  266.       sayerror 'Loading file' i 'of' howmany
  267.       display 8
  268.       this_file = queryprofile(app_hini, group_name, 'FILE'i)
  269.       if leftstr(this_file, 5)='.DOS ' then
  270.          subword(this_file, 2)  -- execute the command
  271.       elseif this_file=UNNAMED_FILE_NAME then
  272.          'xcom e /n'
  273.       else
  274.          'e "'this_file'"'
  275.       endif
  276.       if not rc | rc=sayerror('Lines truncated') then
  277.          call prestore_pos(queryprofile(app_hini, group_name, 'POSN'i))
  278.       endif
  279.    enddo
  280.    activatefile startfid
  281.    nextfile
  282.  
  283. defc listgroups =
  284.    universal app_hini
  285.    groups = ''
  286.    applications = queryprofile(app_hini, '', '')
  287.    do while applications <> ''
  288.       parse value applications with app \0 applications
  289.       group_entries =  queryprofile(app_hini, app, 'ENTRIES')
  290.       if group_entries<>'' then
  291.          groups = groups app
  292.       endif
  293.    enddo
  294.    sayerror 'List of groups is:' groups
  295.  
  296. defc killgroup =
  297.    universal app_hini
  298.    parse arg group
  299.    group_entries =  queryprofile(app_hini, group, 'ENTRIES')
  300.    if group_entries='' then  -- Make sure we don't delete something important!
  301.       sayerror 'Not a group.'
  302.       return
  303.    endif
  304.    call setprofile(app_hini, group, '', '')  -- Delete the entire application
  305.