Tips for Host-Based Qedit

Merging Lines Horizontally

By François Desrochers

Qedit's Merge command brings two versions of the same file together. It tries to match lines in the current workfile with lines from the merged file based on the line numbers.

By default, if a line number exists in both files, the line from the merged file is copied into the current workfile, replacing the existing line. Extra lines in the merged file (line number does not exist in the current workfile) are inserted at appropriate locations.

In Qedit version 5.4.12, the new Justified option appends the corresponding line from the merged file instead of replacing. Text is appended immediately after the last non-blank character if Set Work Trailingspaces is disabled. If Trailingspaces is enabled, text is appended immediately after the last significant trailing space.

Let's say the current workfile contains:

and the external file contains:
A MergeJ would result in:
If the resulting merged line is too long for the current length, the merged line is truncated. To make sure you get everything from the merged file, you may have to change the Language (Set Language) and the line length (Set Length).

If we use the 2 files above and set the maximum length to 5, the resulting file would be:

   /mergej mynum
       1     11111

   Warning:  Result line will be too long.  Truncating merged text.
       2     22222

   Warning:  Result line will be too long.  Truncating merged text.
       3     33333

   Warning:  Result line will be too long.  Truncating merged text.
   3 lines merged
   /l all
       1     abc11
       2     def22
       3     ghj33

Excluding Lines From Qedit Visual Mode Display

By Bob Green

HP may have stopped taking orders for the HP 3000, but there are still thousands of MPE systems in production and Robelle continues to aggressively update our software products for the platform.

In August 2003 (Qedit version 5.4.10) we added the XX indicators to Visual Mode. They mark lines that you do not want displayed in full screen mode. This new feature makes it possible to display the data declarations and the code that work on them at the same time. For example:

You can see in the figure above that the excluded block of text is replaced with a single line.

--- Excluded Area --- 7/18.6

An excluded area setting is saved in the workfile, so it's preserved across Open/Shut commands.

To reset the excluded area and see the original lines again, type .xx on the Homeline and press Enter or F7. You can also define the excluded area using Set Visual XX (and confirm it with Verify Visual).

Restrictions: The Excluded Area line must not be removed, altered or used in any way. This also means that you can not enter any indicators in the cut-and-paste area. An excluded area can not be included in any other block operation such as ZZ, CC, MM or another XX.

New Column Handling in Qedit

By François Desrochers

Recently, we received a number of questions related to column operations in Qedit. Some people used QUAD (a contributed library editor) on the HP3000 and were transitioning to an HP9000. They found themselves without their favorite editor as QUAD is not available on HP-UX. They turned to Qedit but quickly discovered that Qedit missed some QUAD features. More specifically, they were looking for an easy way to copy or move columns on a single line.

Although this could be done with Qedit command files, this solution had limitations. We, at Robelle, decided to provide the functionality as Qedit native commands. That's how the Colcopy and Colmove commands came to be. Since people were already familiar with QUAD's operation, we decided to match its implementation as closely as possible.

Copy Columns

COLCOPY source [ /source2 ] destination1 [ /destination2 ] [ rangelist ]
The Colcopy command copies text in columns specified by source1 and source2 to the destination columns specified by destination1 and destination2 in the lines of rangelist. Even though Colcopy can modify multiple lines using a rangelist, it really operates on one line at a time. The default rangelist is the current line. You cannot copy columns from one line to another, although you can accomplish this with Set Left and Right with the Hold file.

Source and destination columns always represent the original location. All changes are based on that assumption.

If you only specify source1, Qedit copies just that column (length of 1). If you only specify destination1, Qedit inserts the source columns at that location. If you wish to replace a single column, enter a destination range where destination1 and destination2 are the same, e.g. Colcopy 1 10/10.

/list 1
   1     abcdefghijklmnopqrstuvwxyz
/colcopy 1 10          { insert column 1 at column 10 }
   1     abcdefghiajklmnopqrstuvwxyz
1 line changed
/colcopy 1/5 10        { insert columns 1/5 at column 10 }
   1     abcdefghiabcdejklmnopqrstuvwxyz
1 line changed
If you specify both destination1 and destination2, Qedit replaces the text in these columns with the source text. If the source text is narrower or wider, Qedit shortens or expands the line, as needed.
/colcopy 1 10/15     { copy column 1 to columns 10/15 }
   1     abcdefghiapqrstuvwxyz
1 line changed
/colcopy 1/5 10/11   { copy columns 1/5 to 10/11. Line expands. }
   1     abcdefghiabcdelmnopqrstuvwxyz
1 line changed
/colcopy 1/5 10/20   { copy columns 1/5 to 10/20. Line shortens. }
   1     abcdefghiabcdeuvwxyz
1 line changed
Trailing spaces on the line are not significant. This means that a line can expand until a non-space character reaches the current right margin (Set Right). However, trailing spaces from the source text are significant and are copied in the operation. If the line cannot be expanded further, Qedit displays a warning message and allows the user to modify it.
/list 2
   2     abcd     efghiabcdeuvwxyz
/colcopy 1/8 20        { insert columns 1/8 at 20 }
   1     abcd     efghiabcdeabcd    uvwxyz
1 line changed
/Set right 30
/colcopy 1/5 30        { insert columns 1/5 at 30 }

Warning: Source columns could not be inserted. Please modify. (Warning 2)
   1     abcd     efghiabcdeabcd    uvwxyz
1 line modified
When source and destination columns do not overlap, the results are straightforward. If source and destination columns overlap partially or completely, the results might not be as you expect. Keep in mind that: Use the COLJ command to give yourself approval over each change before it is updated. With COLJ, Qedit displays the line as it would be and asks you for a Yes, No, or Modify answer.

Cobol tags are short strings stored in columns 73 to 80 of CobX source files. The Cobol tag value is defined using the Set X command. Once enabled, Qedit automatically updates the tag as lines are updated and added. The tags can also be modified manually with custom tag values. In its regular form, the Colcopy command affects only the text area in COBOL columns 7 to 72. If you wish to make changes to Cobol tags, use the T suffix. You can think of it as the Tag option. This option operates only on the tag area itself, columns 73 to 80.

/ColT 73/74 79/80 all   { copies content of columns 73 and 74 }
                        { into columns 79/80                  }
/ColT 73/74 75 all      { inserts content of columns 73 and 74     }
                        { in column 75. Columns 76-80 are shifted. }
By default, Colcopy displays the lines as they are modified. If you don't want to the changes, use the Q suffix.

Move Columns

COLMOVE source [ /source2 ] destination1 [ /destination2 ] [ rangelist ]
The Colmove command shares Colcopy's syntax. It moves text in columns specified by source1 and source2 to the destination columns specified by destination1 and destination2 in the lines of rangelist. But it also removes the source columns from their original location.

A move means the original columns are removed and the line is shifted left. Then the source text is inserted at the destination.

/list 1
   1     abcdefghijklmnopqrstuvwxyz
/colmove 1 10          { move column 1 to column 10 }
   1     bcdefghiajklmnopqrstuvwxyz
1 line changed
/colmove 1/5 10        { move columns 1/5 to column 10 }
   1     fghiabcdejklmnopqrstuvwxyz
1 line changed
When source and destination columns do not overlap, the results are straightforward. If source and destination columns overlap partially or completely, the results might not be as you expect. Keep in mind that: Here is an example:
/list 1
   1     abcdefghijklmnopqrstuvwxyz
/colm 6/20 15
   1     abcdefghijklmnopqrstuvwxyz
1 line changed
Apparently, nothing has changed but, in fact, something did happen to the line. Qedit removed the source columns "fghijklmnopqrst" and tried to insert the original text where column 15 used to be. Column 15 was part of the area that has been removed, so Qedit inserts the text where it should have been i.e. between "e" and "u". So, it's putting the original text back where it was. The specified destination columns can exceed the current right margin. In this case, Qedit assumes the columns should be moved to the end of the line. Effectively, the source columns are right-justified at the right margin of the line (see example below). The destination columns do not have a precise value, as long as they are larger than the current right margin. If the right margin is currently set at 80, the following commands yield the same results.
/v right
Set Right 50
   2     abcdefghijklmnopqrstuvwxyz
/colm 1/5 51
   2     fghijklmnopqrstuvwxyz                        abcde
1 line changed
/colm 1/5 88/90
   2     fghijklmnopqrstuvwxyz                        abcde
1 line changed
This feature was added to Qedit for MPE and HP-UX in August 2003 (version 5.4.10). Users on current support can download the new versions (email support@robelle.com).

Qedit Column Move Command File

One HP3000-l subscriber needed to move columns around using Qedit. Qedit does not yet have a built-in command to do it. However, it is possible to design a command file to do it. Paul Christidis took on the challenge and came up with the command file below. Good job Paul and thank you on behalf of Robelle and all Qedit users.
parm FromCol=0, ToCol=0, Len=0, Range="*"
# QEDIT command file for moving columns of data.
#     Author: Paul Christidis   Date: 7/16/2003
# It defines a window "W" involved in the move as two columns (one
# of width "Len" and one as "W - Len") and then swaps the order
# of the columns using regular expressions.  Since Qedit ignores
# trailing spaces multiple 'change' commands were used.
if MIN(!FromCol, !ToCol, !Len) <= 0 then
 echo Usage: ![BASENAME(hpfile)] FromCol, ToCol, Length, [Range]
 echo  FromCol - "From" Character position.
 echo  ToCol   - "To" Character position.
 echo  Length  - Number of characters to move.
 echo  Range   - Range in file to perform the move.
 echo             (default = "*" (current record))
 echo *NOTE* Since Qedit ignores trailing spaces in a record, a means of
 echo    making spaces 'visible' was needed in order for the column move
 echo    to work correctly.  Spaces are changed to '%377' prior to the
 echo    move and back to spaces after the move.  Thus, if you wish to
 echo    'undo' the column move, you MUST undo the last three changes.
 echo      Also moves that are more than 74 characters apart will fail
 echo    because of Qedit's 80 character limit on its 'change' string.
/set right; set left
# Determine 'window' size, build the regular expression and issue the
# change commands. (NOTE: '_qe_w2', for now, is ONLY informational)
setvar Right2 MAX(!ToCol, (!FromCol + !Len -1))
setvar Left2  MIN(!ToCol,  !FromCol)
setvar ToCh ' "\2\1" '
if !FromCol <= !ToCol then
  setvar _qe_w1 !Len
  setvar _qe_w2 !Right2 - (!Left2 + !Len -1)
  setvar _qe_w1 !FromCol - !ToCol
  setvar _qe_w2 !Len
setvar Ccmd 'CQ "(' + "![RPT(".",![_qe_w1])]" + ')(.*)"(reg)'
if _qe_w1 <= 74 then
 /set right !Right2; set left !Left2     {Adjust margins}
 /CQ " ","![CHR(255)]" !Range >$null     {Change ' ' to '%377'}
 /!Ccmd !ToCh !Range                     {Swap columns}
 /CQ "![CHR(255)]"," " !Range >$null     {Change '%377' back to " "}
 echo ** NOT Moved: Columns more than 74 characters apart.
# Now reset margins and clean up.
/set right; set left
if BOUND(traceon) AND traceon then
  showvar   Right2, Left2, _qe_w1, _qe_w2, ToCh, Ccmd
  deletevar Right2, Left2, _qe_w1, _qe_w2, ToCh, Ccmd >$null

Change Trailing Spaces to Leading Zeroes

If you have an Ascii fixed-column flat file that contains a column with left-justified numerics and you wish to change those numerics to be right-justified with leading zeros, there are two ways to do it. One uses Qedit and the other uses MPE commands.

For example, if you have a file that contains the following records:

xxxxxx1234    other data
yyyyyy66      more stuff
zzzzzz98765   last record

and you want it to look like:

xxxxxx00001234other data
yyyyyy00000066more stuff
zzzzzz00098765last record

you can use one of the following two methods:

METHOD 1: Using Qedit:

   /Text datafile
   /Set left 7   { first digit }
   /Set right 14  { last digit  }
   /Justify right @
   /C " "0" @
   /Set left      { reset to start of line }
   /Set right     { reset to last column of the file }

METHOD 2: Using an MPE command file:

parm infile="~", entry="Main", eofparm=0

if "!entry" = "Main"
  setvar start_pos 7
  setvar field_len 8
  # build a temporary, "randomly"-named  holding file
  # for the updated data
  setvar tmp_outfile  "T" + rht("0000000" + "!HPCPUMSECS",7)
  setvar in_eof finfo('!infile','eof')
  setvar in_recsize finfo('!infile','byterecsize')
  build !tmp_outfile;rec=-!in_recsize,,f,ascii;disc=!in_eof
  file outfile=!tmp_outfile,old
  # run this command again with the alternate entry point
  xeq !hpfile dummy, Replace, !in_eof < !infile
  purge !infile
  rename !tmp_outfile, !infile
  reset outfile
  deletevar tmp_outfile, in_eof, in_recsize, i, &
            file_rec, start_pos, field_len,     &
            first_part, new_field, last_part

if "!entry" = "Replace"
  setvar i 0
  while setvar (i, i+1) <= !eofparm
     input file_rec
     setvar first_part str(file_rec, 1, start_pos-1)
     setvar new_field  rht( rpt("0",field_len) +                         &
                               rtrim(str(file_rec,start_pos,field_len)), &
                            field_len )
     setvar last_part  str(file_rec,                            &
                           start_pos + field_len,               &
                           in_recsize - start_pos - field_len )
     echo !first_part!new_field!last_part>>*outfile

Here is how you would use the command file (assuming the command file is named "zerofill" and the data file is named "mydata"):



Both methods require that the user change the starting position and the length or ending position to fit their needs.

Further, the command file method requires that the input record size must be less than or equal to the lesser of

Credits: The MPE command file solution is from Barry Lake at Allegro and the Qedit solution is from Francois Desrochers of Robelle.

A Permanent Redo Stack for Qedit

One of the most frustrating little things about MPE is that when you log off after a day of heavy programming, your "redo stack" with all of its built up history of commands and file names, is lost.

It was the same in Qedit as well, which emulates MPE's Redo. Commands entered at the Qedit prompt are saved in something called the redo stack. You can recall commands from this stack by using the Redo, Do and Listredo commands. The redo stack was stored in a temporary file and discarded as soon as you left Qedit. This did not allow the stack to be preserved across Qedit invocations.

But then Alfredo Rego of Adager insisted that Qedit could be much better: it could save the redo commands in a permanent file almost as easily as a temporary file. So now the Set Redo command allows you to assign a permanent file as your redo stack. For example, to assign "myredo" as the persistent redo stack, enter:

   /set redo myredo

If the file does not exist, Qedit creates it. Otherwise, Qedit uses the existing file. All your subsequent commands are written to the persistent redo stack. If you want to use a persistent stack every time you run Qedit, you just insert the Set Redo command in one of our Qeditmgr configuration files.

P.S. Suprtool now has persistent Redo as well.

Word Processing Tips

Host-based Qedit may not have the fancy UI of Qedit for Windows, but it does have two very nice features for word processing: the Justify command to flow text into even paragraphs, and the Spell command to check the spelling of words in your text. For more details, visit the link above.

Editing Multiple Files At Once

When Qedit was originally written, its ability to edit one file at a time and make it lightning fast to switch between files was more than adequate. That is how we came up with the space-saving, instant open Qedit workfile that allows you to do Open XXX, edit, Open YYY, edit, then Open * to switch between the files in a second. But when we wrote Qedit for Windows, we needed multiple files in edit windows at the same time. So we added a similar feature to host-based Qedit.

By default, Qedit uses the temporary file called Qeditscr as its workfile. There are times, however, when you can lose your temporary Qeditscr workfile. This can happen when you have a poor modem line or when some other condition makes you lose your session. Another problem is not being able to run Qedit from within Qedit because Qeditscr is already in use. A third problem is that you may want to have multiple scratch files open at once as you are editing a group of related files.

Random permanent workfiles are the answer to all of these situations. You can force Qedit to always use them by adding Set Work Random On to your Qeditmgr configuration file, or you can use the Info parameter on the Run command without using the Parm parameter.

     :run qedit.pub.robelle;info="filename"
     :run qedit.pub.robelle;info="-p 3"
     :run qedit.pub.robelle;info="-c visual filename"
There is one drawback to this solution: these random workfiles get purged when you exit Qedit. The temporary Qeditscr workfiles, however, do not get purged until you end your MPE session. Thus, your workfile is still available when you run Qedit later on in the session. If you are working on MPE, do a LISTF qed#####,3 to list all your permanent scratch files along with their creation date (among other things).

If you are working on HP-UX, you would typically do ll /var/tmp/qscr*. Because HP-UX scratch files for all Qedit users are saved in the default system temporary directory, you should check the userid on each file to determine which are yours.

Multiple edit files. What if you want to edit two or more files and move lines between them? You could Text the first file, Hold the desired lines, Keep your changes then Text the second file, insert the lines and Keep these changes. You would then repeat the process until all the lines have been moved. With this approach, the constant Text and Keep operations are inconvenient.

Instead, with permanent scratch files, you can text all the files at the same time using the "New" keyword on the Text command (i.e., /Text mysource,new).

This copies each file into an extra scratch file of its own. Then use the Open ?, Open *-1, Open *-2, ... commands to switch quickly among them. And if you like this, consider upgrading to Qedit for Windows where you can actually see them all on the screen at the same time.

Hint: you can also create extra scratch files by doing a New command with no parameters, but beware: New;Text mysource,new creates 2 scratch files where the first one is empty!