home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / the25.zip / the25O_w32.zip / append.the next >
Text File  |  1997-09-10  |  3KB  |  68 lines

  1. /*
  2. $Id: append.the 2.1 1995/06/24 16:28:29 MH Rel MH $
  3. */
  4. /***********************************************************************/
  5. /* Description: REXX macro to append a string to a line.               */
  6. /* Syntax:      append target string                                   */
  7. /* Notes:       This macro appends the supplied string to the lines    */
  8. /*              specified in the target.                               */
  9. /*              Full XEDIT/KEDIT/THE targets are supported.            */
  10. /*              A single character delimits the beginning of the string*/
  11. /*              to be appended.                                        */
  12. /*              eg. append /fred/ | /bob/ xyz                          */
  13. /*                                       ^ 1 space                     */
  14. /*                  will append 'xyz' to the end of each line          */
  15. /*              eg. append /fred/ | /bob/  xyz                         */
  16. /*                                       ^^ 2 spaces                   */
  17. /*                  will append ' xyz' to the end of each line         */
  18. /*              eg. append /fred/ | /bob/xyz                           */
  19. /*                                      ^ no spaces                    */
  20. /*                  will append 'yz' to the end of each line           */
  21. /***********************************************************************/
  22. Trace o
  23. arg1 = Arg(1)
  24. noargs = Arg()
  25. If noargs = 0 Then arg1 = '1'               /* no args - assume 1 line */
  26. forward = 1                  /* assume direction is forward by default */
  27. 'EXTRACT /LINE/SIZE/STAY/FTYPE/FNAME/'            /* get various stuff */
  28. current_line = line.1                   /* save current line for later */
  29. reply = valid_target(arg1,spare)           /* validate supplied target */
  30. If reply = 'ERROR' Then
  31.    Do
  32.      'EMSG Error: 17 Invalid target' arg1
  33.      Exit
  34.    End
  35. If reply = 'NOTFOUND' Then
  36.    Do
  37.      'EMSG Error: 17 Target not found' arg1
  38.      Exit
  39.    End
  40. 'preserve'
  41. start_line = Word(reply,1)                        /* get starting line */
  42. nolines = Word(reply,2)                         /* get number of lines */
  43. start_string = Wordindex(reply,2) + Wordlength(reply,2) + 2
  44. string = Substr(reply,start_string) /* rest of argument is append string */
  45. If nolines < 0 Then Do                /* if target before current line */
  46.    forward = 0                    /* indicate direction to be backward */
  47.    nolines = nolines * -1                     /* make nolines positive */
  48. End
  49. ':'||start_line                                    /* go to first line */
  50. totlines = 0                             /* reset changed line counter */
  51. Do nolines                              /* for each line to target ... */
  52.    'EXTRACT /CURLINE/TOF/EOF/'       /* get current line contents, etc.*/
  53.    If tof.1 = 'ON',                    /* ignore line if on TOF or EOF */
  54.    |  eof.1 = 'ON' Then nop
  55.    Else
  56.      Do
  57.        'REPLACE' curline.3||string
  58.        totlines = totlines + 1
  59.      End
  60.    If forward = 1 Then 'N'          /* if going forward, get next line */
  61.    Else 'U'                   /* if going backwards, get previous line */
  62.    If rc \= 0 Then Leave                         /* shouldn't get here */
  63. End
  64. 'EMSG' "'"||string||"'" 'appended to' totlines 'lines' /* say how many lines changed */
  65. If stay.1 = 'ON' Then ':'||current_line 
  66. 'restore'
  67. Return                                               /* go back to THE */
  68.