• Aucun résultat trouvé

MAKING CHANGES TO A FILE

Dans le document The Michigan Terminal System (Page 112-116)

FILES AND DEVICES

MAKING CHANGES TO A FILE

.

. lines to be put into file .

.

{end-of-file signal or null line}

STOP

For further details, seeMTS Volume 18: The MTS File Editor, Reference R1018.

MAKING CHANGES TO A FILE

There are two basic methods of making changes to a file: using the MTS commands to make changes to the file on a line-by-line basis, and using the MTS File Editor to make changes either on a line basis or on a context basis.

Changes Using MTS Commands

MTS commands can be used to change one line of a line file, a group of lines of a line file, or to empty or destroy an entire file. Sequential files can be changed only by adding on to the end of the file, or by emptying or destroying the file. Single lines or groups of lines in a line file can be changed by using the same basic two methods that may be used to put information into a file.

The COPY command can be used to copy lines or groups of lines from a file to itself or another file.

Thus,

COPY A+B C

enters the contents of A, followed by the contents of B, into file C (or if C is sequential, adds to the end of C). If either A or B are line files, then the “contents” are only the lines with numbers greater than or equal to 1, which is not necessarily the entire contents of the file. If C is a line file, lines that are not replaced by the copy operation are not affected. Thus,

COPY A(1,5)+(99,99)+(1000) B

copies from A lines 1 through 5, 99, and 1000 through the end of A into B, starting at line 1 in B, if B is a line file, or adding to the end of B, if B is sequential. File A must be a line file in this example. Note that if the example were

COPY A(1,5) B

then A could be either a line file or a sequential file.

COPY A(10,15) A(100)

makes a copy in A of the lines in the range of 10 through 15, starting at line 100. Remember that the range of 10 through 15 is the same as 10.000 through 15.000 and can contain anywhere from 0 to 5001 lines. The increment between the copied lines starting at line 100 is 1 (the default).

A copy operation from a file to itself specifying overlapping line-number ranges can be done, but should be used with care. For example,

COPY A(1,9) A(2)

results in line 1 being replicated in lines 2 through 10, since line 1 is copied into line 2, and then line 2 (which is now a copy of line 1) is copied into line 3, etc.

Once a file has been created, it may be emptied, truncated, expanded, renumbered (line files only), renamed, or destroyed at any time. This applies both to permanent files and to temporary files.

Permanent files exist until the user destroys them; temporary files exist until the user destroys them or signs off.

An exact copy of a file can be made by issuing the DUPLICATE command. For example, DUPLICATE A B

writes an exact copy of the file A into the file B. The file B will be created automatically if it does not exist with the same characteristics as file A; if it does exist, it will be emptied first. Conversational users are prompted for confirmation before the file is emptied.

To empty a file, the command EMPTY filename

should be issued. This discards the contents of the file, but preserves allstorage space allocations (including expansions). Future references to the file will reuse the file space. If a command to empty a permanent file is issued from a terminal, the user must confirm that the contents of the file are to be discarded. The message printed is

File "filename" is to be emptied. Please confirm:

The user should respond with “OK” to empty the file. A response of “NO” or “CANCEL” cancels the

command. Any other response is an error and the message is repeated. Confirmation is not requested for temporary files, nor for any files in batch runs.

It should be noted that the EMPTY command empties the whole file; parts of a file cannot be emptied by attaching a line-number range to the file name in the command. Thus,

EMPTY A(10,50) is an error, whereas

EMPTY A

empties all of file A. To partially empty a file, the parts to be saved should be copied to another file.

The original file may then be destroyed and the new file may be renamed to the original name.

To truncate a file, the command TRUNCATE filename

should be issued. Any unused space at the end of the file is deallocated. This decreases the size of the file and decreases the storage charge for the space used by the file. In the case of a line file, truncating doesnotcompact or optimize the space used by the actual data in the file.

To change the absolute size of a line file, the user may issue the command CONTROL filename SIZE={n | nP}

or, to add to or subtract from the current file size CONTROL filename SIZEINC=[±]{n | nP}

To change the absolute maximum size of a line file, the user may issue the command CONTROL filename MAXSIZE={n | nP}

or, to add to or subtract from the maximum file size CONTROL filename MAXSIZEINC=[±]{n | nP}

To renumber alinefile, the command RENUMBER filename

should be issued. The line numbers in the file are renumbered. By default, the entire file is renumbered starting at line number 1 and by increments of 1. An explicit line-number range to be renumbered as well as an explicit new beginning line number and increment may be specified (see the RENUMBER command description).

To rename a file, the command RENAME filename1 filename2

should be issued. The file “filename1” is renamed to “filename2”. If this command is issued from a terminal and “filename1” is a permanent file, confirmation is requested. The message is:

File "filename1" is to be renamed as "filename2". Please confirm:

The user should respond with “OK” to rename the file; confirmation is not requested for temporary files, nor for any files renamed during batch runs. A temporary file may be changed to a permanent file, and vice versa, by renaming it.

To destroy a file, the command DESTROY filename

should be issued. All space allocated for the file is deallocated. If this command is issued from a terminal and the file is a permanent file, confirmation is requested:

File "filename" is to be destroyed. Please confirm:

The user should respond with “OK” to destroy the file. A response of “NO” or “CANCEL” cancels the command. Any other response is an error and the message is repeated. Confirmation is not requested for temporary files, nor for any files in batch runs.

Changes Using the File Editor

The MTS File Editor can be used to edit files on a line-number basis. Single lines or a range of lines may be deleted, new lines may be inserted between existing lines, and existing lines may be replaced by new lines. The File Editor can also be used on a context basis, scanning for lines with certain character strings in them, replacing characters in a line with other characters, etc. For example, on a line-number basis, the following sample edit session replaces line 2, deletes line 7, and inserts two lines after line 8 of the file being edited (the first character is the prefix character; input from the user is in lowercase, File Editor output is in uppercase):

:replace 2 'new second line' : 2 NEW SECOND LINE :delete 7

:insert 8

?eighth and a quarter

?eighth and a half

? {null input line}

:

On a context basis, the following example illustrates a scan through the file searching for the characters “ABC#D”:

:scan /file 'abc#d'

and then the following command alters “C#D” to “XYZ”:

:alter /file 'c#d'xyz'

The File Editor is invoked from MTS command mode by the EDIT command. The Editor has its own command language. Complete details on using the Editor are given inMTS Volume 18: The MTS File Editor, Reference R1018.

Changes Using CDUPATE

The program *CDUPDATE may be used to update a file. *CDUPDATE is a “context-directed”

program that applies updates to an “old master file” to produce a new “updated master file.” It is typically used in maintaining a program in the form of a “base-level source” and a set of updates to be applied to produce the current version. *CDUPDATE is further described inMTS Volume 2: Public File Descriptions, Reference R1002.

Dans le document The Michigan Terminal System (Page 112-116)