home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 509.lha / RexxExtraLibrary_v1.2 / rexx / Clips.rexx < prev    next >
OS/2 REXX Batch file  |  1991-05-06  |  2KB  |  92 lines

  1. /* Clips.rexx */
  2.  
  3. /*
  4.      Format
  5.  
  6.        CLIPS [SAVE | {RECALL|LOAD}] [LIST] [FILE <name>]
  7.  
  8.    List all elements in the ARexx clips list, or save or recall the
  9.    clips list. This allows saving of clips list entries from session
  10.    to session.
  11.  
  12. */
  13.  
  14. facility = 'Clips'
  15. retcode = 0
  16. /* add our own functions to ARexx */
  17. call addlib 'rexxextra.library',-20,-30,0
  18. args. = ''
  19. args.FILE = 's:Clips.dat'
  20. template = "SAVE/S,LOAD=RECALL/S,LIST/S,FILE/K"
  21. dtemplate = template
  22.  
  23. parse arg g_c
  24.  
  25. do while g_c='?'
  26.   options prompt dtemplate': ' /* this template is      */
  27.   parse pull g_c           /* displayed to the user */
  28.   if g_c='?' then do
  29.     g_s=sourceline(3)
  30.     if pos('/*',g_s)=0 then break; if pos('*/',g_s)>0 then break
  31.     say
  32.     g_s=sourceline(4)
  33.     do i=5 while pos('*/',g_s)=0; say g_s; g_s=sourceline(i); end
  34.     say
  35.     end
  36.   end
  37. interpret Cparse(g_c,template,'args')
  38. if args.ERRCODE > 1 then do; say facility'-E-BADARGS,' args.ERRTEXT; exit 5; end
  39.  
  40. if ~args.SAVE & ~args.LOAD then args.LIST = 1
  41. if args.SAVE then retcode = max(retcode,saveclips())
  42. if args.LOAD then retcode = max(retcode,recallclips())
  43. if args.LIST then retcode = max(retcode,listclips())
  44.  
  45. exit retcode
  46.  
  47. listclips:
  48.   width = (screencols()-30)%8
  49.   namewidth = 20
  50.   trailer = '1B'x || '[0m'
  51.   a = sortwords(show('c'))
  52.   do c = 1 to words(a)
  53.     b = word(a,c)
  54.     d = getclip(b)
  55.     if length(d) > width-namewidth-1 then
  56.       d = substr(d,1,width-namewidth-4) || '...'
  57.     say left(b,namewidth) d || trailer
  58.     end
  59.   return 0
  60.  
  61. saveclips:
  62.   if ~open('cfile',args.FILE,'W') then do
  63.     say facility'-E-OPENIN, Error writing to file' args.FILE
  64.     return 10
  65.     end
  66.   a = sortwords(show('c'))
  67.   do c = 1 to words(a)
  68.     b = word(a,c)
  69.     d = getclip(b)
  70.     call writeln('cfile',b)
  71.     call writeln('cfile',d)
  72.     end
  73.   call close('cfile')
  74.   return 0
  75.  
  76. recallclips:
  77.   if ~open('cfile',args.FILE,'R') then do
  78.     say facility'-E-NOTFND,' args.FILE 'not found.'
  79.     return 10
  80.     end
  81.   b = readln('cfile')
  82.   do while ~eof('cfile')
  83.     d = readln('cfile')
  84.     if b ~= '' & d ~= '' then
  85.       if ~setclip(b,d) then
  86.     say facility'-W-NOTSET, Clip entry "'b'" could not be set'
  87.     b = readln('cfile')
  88.     end
  89.   call close('cfile')
  90.   return 0
  91.  
  92.