home *** CD-ROM | disk | FTP | other *** search
/ Hacker Chronicles 1 / HACKER1.ISO / phrk3 / phrack35.7 < prev    next >
Text File  |  1992-09-26  |  55KB  |  1,316 lines

  1.  
  2.                                 ==Phrack Inc.==
  3.  
  4.                 Volume Three, Issue Thirty-five, File 7 of 13
  5.  
  6.       <:=--=:><:=--=:><:=--=:><:=--=:>\|/<:=--=:><:=--=:><:=--=:><:=--=:>
  7.       <:=--=:>                                                   <:=--=:>
  8.       <:=--=:>    >>>>>=-*  Users Guide to VAX/VMS  *-=<<<<<     <:=--=:>
  9.       <:=--=:>                                                   <:=--=:>
  10.       <:=--=:>                   Part I of III                   <:=--=:>
  11.       <:=--=:>                                                   <:=--=:>
  12.       <:=--=:>            Part A:  Basic Information             <:=--=:>
  13.       <:=--=:>         Part B:  Programming the VAX/VMS          <:=--=:>
  14.       <:=--=:>                                                   <:=--=:>
  15.       <:=--=:>                   By: Black Kat                   <:=--=:>
  16.       <:=--=:>                                                   <:=--=:>
  17.       <:=--=:><:=--=:><:=--=:><:=--=:>/|\<:=--=:><:=--=:><:=--=:><:=--=:>
  18.  
  19.  
  20. Index
  21. ~~~~
  22. Part A contains information on the following topics:
  23.  
  24.    o  Background                          o  Logical Names
  25.    o  Terminal Control Keys               o  System Default Logical Names
  26.    o  Logging in                          o  Logical Name Tables
  27.    o  Digital Command Language (DCL)      o  User Environment
  28.    o  Error Messages                      o  Terminal Characteristics
  29.    o  Command Line Editing                o  File Security
  30.    o  Files and Directories               o  EDT Text Editor
  31.    o  File Operations                     o  EDT Help manual
  32.  
  33. Part B contains information on the following topics:
  34.  
  35.    o  Programming VAX/VMS              o  Parameters
  36.    o  DCL Expressions                  o  Terminal I/O
  37.    o  Command Procedures               o  File I/O
  38.    o  Writing Command Procedures       o  Redirecting Command Procedure I/O
  39.    o  Comments                         o  Branching and Conditionals
  40.    o  Labels                           o  Loops
  41.    o  Debugging                        o  Subroutines
  42.    o  Invoking Command Procedures      o  Error Handling
  43.    o  Symbols                          o  Termination
  44.    o  Lexical Functions                o  Example Command Procedures
  45.  
  46.  
  47.                    <:=- Part A : Basic Information -=:>
  48.  
  49. Introduction
  50. ~~~~~~~~~~~
  51. VAX is an acronym for Virtual Address eXtension, a 32-bit computer developed by
  52. Digital in the 1970's.  The VAX architecture supports multiprogramming, where
  53. many users running different programs can use the VAX simultaneously and each
  54. appears to have full control of the computer's resources.  The multiprocessing
  55. VAX functions vary differently from the old timesharing systems, which would
  56. allocate a slice of CPU time to each user of the system in a rotating fashion,
  57. whether the time slice was required or not.  The VAX/VMS environment, however,
  58. provides each user an allocation of processor time based on the user's needs
  59. and priority. If a user does not need his quantum of time, or a portion of it,
  60. it is given to the next user.  This scheduling method is very efficient when
  61. compared to the old method of timesharing.
  62.  
  63. The VAX is capable of addressing more than four billion addresses, through a
  64. method known as virtual memory addressing.  Because the memory is virtual
  65. however, there is no need to have four billion bytes of physical memory.  The
  66. VAX executes programs by a technique known as paging, whereby a single "page"
  67. of the program is read into memory at a time, and when a new page is needed,
  68. the old one is "swapped" back out to disk to make room for the new one.  The
  69. VMS operating system ties everything together.  The user interacts with VMS
  70. (Virtual Memory System) through a Command Language Interpreter (CLI), usually
  71. the Digital Command Language (DCL).
  72.  
  73. When you use VAX/VMS, you are known to the system as a process, which is
  74. created when you log in to the system and deleted when you log out.  This
  75. process carries with it various attributes to identify you from other system
  76. users (process name, identification, user identification code, privileges,
  77. etc).
  78.  
  79.  
  80. Terminal Control Keys
  81. ~~~~~~~~~~~~~~~~~~~
  82. Ctrl-A      Allows you to insert, rather than overstrike, characters on a
  83.             DCL command line that you're editing.
  84. Ctrl-B      Displays DCL commands that you've previously entered.
  85. Ctrl-C      Interrupts the coessed or the program being executed.
  86. Ctrl-E      Positions the cursor at the end of the line.
  87. Ctrl-H      Positions the cursor at the beginning of the line.
  88. Ctrl-I      Tab
  89. Ctrl-O      Alternately suppresses and continues the display of the output
  90.             terminal.
  91. Ctrl-Q      Enables (toggles on) output to the display after CTRL-S.
  92. Ctrl-R      Retypes the current input line and repositions the cursor atthe
  93.             end of the retyped line.
  94. Ctrl-S      Disables (toggles off) output to the display until CTRL-Q is
  95.             pressed.
  96. Ctrl-T      Displays process statistics.
  97. Ctrl-U      Discards the current input line and performs carriage return.
  98. Ctrl-W      Refreshes the screen.
  99. Ctrl-X      Flushes the type-ahead buffer.
  100. Ctrl-Y      Interrupts command or program execution and returns control to
  101.             the DCL command line interpreter.
  102. Ctrl-Z      Indicates end of file for data entered from terminal.
  103.  
  104.  
  105. Logging in
  106. ~~~~~~~~
  107. Most VAX systems prompt you with something like this:
  108.  
  109.    Welcome to VAX1
  110.    Username:
  111.  
  112. Type your username and press <enter>.  You'll then be prompted for your
  113. password.  If you enter the correct username/password combination, you'll
  114. be given something like the following:
  115.  
  116.           Welcome to VAX/VMS V4.4
  117.    Last interactive login on Monday, 16-JUL-87  16:12
  118.    Last non-interactive login on Friday, 13-JUL-87  00:14
  119.    $
  120.  
  121. If you entered an incorrect username and password, you'll receive the
  122. message:
  123.  
  124.    User authorization failure
  125.  
  126. Just hit <enter> and you'll be prompted for your username again.  Once
  127. you're logged in, you'll be given the DCL prompt ($).  This indicates that
  128. the system is ready to accept interactive commands.
  129.  
  130. To log out, use the command:
  131.  
  132.    $ LOGOUT
  133.  
  134.  
  135. The Digital Command Language (DCL)
  136. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  137. DCL is comprised of more than 200 commands called verbs.  Each DCL verb acts on
  138. a parameter or assumed parameter, and the action of these verbs and the scope
  139. of their parameters can be modified with qualifiers.  The basic command
  140. structure is:
  141.  
  142. $ LABEL: COMMAND-NAME PARAMETER(S) /QUALIFIER(S) !COMMENT
  143.     |           |         |             |           |
  144.     |           |         |             |           +-- Optional Comment
  145.     |           |         |             |
  146.     |           |         |             +-------------- Command modifier(s)
  147.     |           |         |
  148.     |           |         +---------------------------- Object of the
  149. Command
  150.     |           |
  151.     |           +-------------------------------------- DCL command verb
  152.     |
  153.     +-------------------------------------------------- Optional Label
  154.  
  155. A label is an optional, user-specified string with a maximum length of
  156. 255 characters.  It is most commonly used in command procedures.
  157.  
  158. A DCL command verb defines the action the VAX will take when the command
  159. line is interpreted.
  160.  
  161. Parameter(s) specify the object or a list of objects the DCL command verb
  162. will act upon.  Multiple parameters may be specified but must be separated
  163. from one another by a space, multiple spaces, or a tab.  If you enter a DCL
  164. command that requires parameters, but you don't enter them on the command
  165. line, the DCL interpreter will prompt you for them automatically.
  166.  
  167. Qualifiers further define or modify the function the DCL command will
  168. perform.  They consist of a keyword followed by a value or a list of
  169. values.
  170.  
  171. The qualifier keyword must be preceded by a slash (/).  Multiple qualifiers
  172. may be specified, but each must be preceded with a slash.  Qualifiers
  173. usually aren't required.  There are three kinds of qualifiers:  parameter,
  174. positional, and command.  A command qualifier applies to the whole command.
  175. Generally, these are placed at the end of the command.  For example:
  176.  
  177.    $ DIRECTORY [BYNON],[BYNON.DECPRO]/FULL
  178.  
  179. This displays a full listing of two directories, using the /FULL qualifier of
  180. the DIRECTORY command.  A positional qualifier takes on a different meaning
  181. based on where it is located in the command.  If a positional qualifier is
  182. placed after the command verb, but before the first parameter, the qualifier
  183. will affect the entire command.  If the same positional qualifier is placed
  184. after a parameter, only that parameter will be affected.  For example:
  185.  
  186.    $ PRINT/COPIES=3 MEMO1.TXT,MEMO2.TXT
  187.    $ PRINT MEMO1.TXT/COPIES=2,MEMO2.TXT
  188.  
  189. The first command prints three copies of each file.  The second command prints
  190. two copies of the first file, but only one copy of the second.  A parameter
  191. qualifier affects only the parameter it follows.  In the following example,
  192. MEMO1.TXT is sent to the queue LASER and MEMO2.TXT is sent to queue FAST_PRINT:
  193.  
  194.    $ PRINT MEMO1.TXT/QUEUE=LASER,MEMO2.TXT/QUEUE=FAST_PRINT
  195.  
  196. A comment is an optional, user-specified comment about the command.  It is
  197. commonly used in command procedures to document the command.
  198.  
  199.  
  200. Error Messages
  201. ~~~~~~~~~~~~
  202. Generally, error messages are of the format:
  203.  
  204.    % FACILIT-L-IDENT, TEXT
  205.    |   |     |   |      |
  206.    |   |     |   |      +-- explanation of the error message
  207.    |   |     |   |
  208.    |   |     |   +--------- abbreviated message text, for reference
  209.    |   |     |
  210.    |   |     +------------- error severity
  211.    |   |
  212.    |   +------------------- Vax/VMS facility or component (error source)
  213.    |
  214.    +----------------------- message number: "%" = first, "-" = subsequent
  215.  
  216. A percent sign (%) indicates the first error message for a given command.
  217. All subsequent errors for that command are preceded with a hyphen (-).
  218.  
  219. The facility indicates the source of the error.  The source may be the DCL
  220. command line interpreter, one of the various VMS utilities, or a program
  221. image.
  222.  
  223. The severity level indicator (L) will have one of the following values:
  224. S (successful completion), I (information), W (warning), E (error), or
  225. F (fatal or severe error).
  226.  
  227. The ident is an abbreviation of the error message text.  It can be referenced
  228. in the VAX/VMS System Messages manual.
  229.  
  230. The text provides an explanation of the error message.
  231.  
  232.  
  233. Command line editing
  234. ~~~~~~~~~~~~~~~~~~
  235. DCL stores the last 20 command lines entered.  You can display a list of them
  236. with:
  237.  
  238.    $ RECALL /ALL
  239.  
  240. The resulting display might look like:
  241.  
  242.    1  DIR
  243.    2  COPY VAX1::$1$DUA5:[BYNON]LOGIN.COM LOGIN.COM;1
  244.    3  EDIT LOGIN.COM
  245.    $
  246.  
  247. To recall a specific command from the recall buffer, use the DCL RECALL
  248. command with a command line number as a parameter.  For example:
  249.  
  250.    $ RECALL 2
  251.    $ COPY VAX1::$1$6DUA5:[BYNON]LOGIN.COM LOGIN.COM;1
  252.  
  253.  
  254. Files and Directories
  255. ~~~~~~~~~~~~~~~~~~~~
  256. Files are organized much like MS-DOS, with a directory-tree structure.  The
  257. user's default directory (assigned by the system administrator) is the "root"
  258. directory.  Up to seven subdirectories may be created, each containing as many
  259. subdirectories as you like.  The complete file specification looks like:
  260.  
  261.    VAX1 :: DUA0 : [BYNON.PROGRAMMING.FORTRAN]WINDOWS.FOR;3
  262.     |       |                |                  |     |  |
  263.     |       |                |                  |     |  |
  264.    node   device         directory          filename  |  version
  265.                                                      type
  266.                                                      
  267. The node name identifies a computer system in a network.  If no node name is
  268. specified, VMS assumes the file is located on the local node where you're
  269. logged in.
  270.  
  271. The device name is the physical device where the file is stored.  It is a
  272. four-character alphanumeric code which identifies the device type, hardware
  273. controller to which it is attached, and the unit number of the device on the
  274. controller.  If you omit the device name from a file specification, VMS assumes
  275. you are referring to your default device.
  276.  
  277. The directory entry is enclosed in brackets, and is the name of the directory
  278. that contains the file.  If you omit the directory name from a file
  279. specification, VMS will assume you are referring to your default directory.
  280.  
  281. The filename may consist of up to 39 alphanumeric characters.
  282.  
  283. The file type is a code consisting of up to 39 alphanumeric characters, and it
  284. generally indicates the type of information supplied in the file.  Some system
  285. programs and utilities supply a three character default file type.
  286.  
  287. The version number is a 1 to 5 digit number the system assigns to every file by
  288. default.  When a file is created, it is assigned a version number of 1.  Each
  289. time the file is edited or another version of it is created, the version number
  290. is automatically incremented by 1.  Alternatively, you may specify a version
  291. number of your choice.
  292.  
  293. No blank spaces are allowed within any portion of a file specification.  In
  294. VMS Version 4.x, the maximum lengths are as follows:
  295.  
  296.    node name           up to 6 characters
  297.    device name         four characters
  298.    directory name      up to 39 characters
  299.    subdirectory name   up to 39 characters
  300.    file name           up to 39 characters
  301.    file type           up to 39 characters
  302.    version number      up to 5 decimal digits with a value between 1
  303.                        and 32,767
  304.  
  305. File specifications must be unique; no two files can have completely identical
  306. specifications.  It's conceivable to have many copies of NOTES.TXT in a
  307. subdirectory, but only one NOTES.TXT;8 may exist in the same subdirectory.
  308.  
  309. Wildcards are similar to those in MS-DOS, with an asterisk (*) representing
  310. a filename or filetype, and a percent sign (%) indicating a single
  311. character.
  312.  
  313.  
  314. File operations
  315. ~~~~~~~~~~~~~~
  316. Creating and modifying files:  $ CREATE TEMP.DAT
  317.                                TEMP 1
  318.                                TEMP 2
  319.                                <CTRL-Z>
  320.  
  321. Renaming files:   $ RENAME TEMP.DAT NEW.DAT
  322.                   $ RENAME TEMP.DAT [BYNON.PROG]TEMP.DAT
  323.                   Note: you cannot rename files across devices, just
  324.                   directories.
  325.  
  326. Copying files:    $ COPY TEMP.DAT NEW.DAT
  327.                   $ COPY TEMP.DAT,TEST.DAT NEW.DAT
  328.  
  329. Appending files:  $ APPEND TEMP.DAT NEW.DAT
  330.  
  331. Deleting files:   $ DELETE TEMP.DAT;1
  332.                   $ DELETE *.DAT;*
  333.                   $ DELETE /CONFIRM .DAT;*  (confirm each file)
  334.  
  335. Displaying files: $ TYPE /PAGE TEMP.DATE    (one page at a time)
  336.  
  337. Directories:      $ DIRECTORY
  338.                   $ DIRECTORY DJA1:[BYNON.PROG]
  339.  
  340. Printing files:   $ PRINT TEMP.DAT
  341.  
  342. Purging files:    $ PURGE *.DAT   (erase all but latest version of .DAT files)
  343.  
  344. Create a dir:     $ CREATE/DIRECTORY [.BUDGET]
  345.  
  346. Set default dir:  $ SET DEFAULT [BYNON.PROG]
  347.                   $ SET DEFAULT [.PROG]
  348.  
  349. Delete a dir:     $ SET DEFAULT [BYNON.PROG]
  350.                   $ DELETE *.*;*
  351.                   $ SET DEFAULT [BYNON]
  352.                   $ SET PROTECTION=(0:D) PROG.DIR;1
  353.                   $ DELETE BUDGET.DIR;1
  354.  
  355.  
  356. Logical Names
  357. ~~~~~~~~~~~~
  358. A logical name is a substitute for a file specification, portion of a file
  359. specification, or another logical name.  They provide two primary functions:
  360. file and device independence and file specification shorthand.
  361.  
  362. File and device independence means that you are not constrained by a physical
  363. element, such as a disk or printer name.  If you use files nested deeply in
  364. subdirectories, with long names, or on devices or nodes other than your
  365. default, you can define a meaningful logical name to represent it.  These
  366. shorthand names are faster to type and easier to remember.
  367.  
  368. To define a logical name:
  369.  
  370.    $ DEFINE PARTS_DBF DJA2:[DATABASES]PARTS.DAT
  371.  
  372. This example will associate the logical name PARTS_DBF with the file
  373. specification  DJA2 : [DATABASES]PARTS.DAT.  Now, PARTS_DBF may be used
  374. anywhere as a substitute for the complete file specification.
  375.  
  376. Other commands also can be used to assign logical names.
  377.  
  378. Assign  :  Associates equivalence names with a logical name
  379. Mount   :  Mounts a disk or tape volume and assigns a system logical for the
  380.            volume.
  381. Allocate:  Allocates a system device for private use and optionally (command
  382.            qualifier) assigns a logical name to the device.
  383. Open    :  Opens a file for read or write operations and assigns a logical
  384.            name to the file specification.
  385.  
  386. To display the logical name translations: $ SHOW LOGICAL PARTS_DBF will
  387. display: "PARTS_DBF" = "DJA2:[DATABASES]PARTS.DAT"  (LNM$PROCESS_TABLE).
  388.  
  389. To deassign a logical name:  $ DEASSIGN  PARTS_DBF
  390.  
  391.  
  392. System default logical names
  393. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  394. SYS$COMMAND   The initial file, or input stream, from which the DCL command
  395.               line interpreter reads input data.  The logical name
  396.               SYS$COMMAND is equated to your terminal for interactive
  397.               processes.
  398. SYS$DISK      Your default disk as assigned in the UAF.
  399. SYS$ERROR     The device on which the system displays all error and
  400.               informational messages.  By default, SYS$ERROR is assigned
  401.               to your terminal for interactive processes, and to the batch
  402.               job log file for any batch processes.
  403. SYS$INPUT     The default file or input stream from which data and commands
  404.               are read by either the DCL command line interpreter or
  405.               programs executing in your account.  By default, SYS$INPUT is
  406.               equated to your terminal for interactive processes and to the
  407.               batch job stream (or command procedure) for batch processes.
  408.  
  409.  
  410. Logical Name Tables
  411. ~~~~~~~~~~~~~~~~~
  412. Logical names are stored in system files called logical name tables.
  413. The following are the four most commonly used:
  414.  
  415. Group table  :  Contains the logical names available to all users in your
  416.                 UIC (User Identification Code) group.
  417. Job table    :  Contains the logical names available to your process and
  418.                 any subprocess it creates.
  419. Process table:  Contains the logical names available to your process only.
  420. System table :  Contains the logical names that may be used by all users
  421.                 of the system.
  422.  
  423.  
  424. User Environment
  425. ~~~~~~~~~~~~~~
  426. The User Authorization File (UAF) is a system file controlled and modified
  427. by the system manager.  A record for each system user is contained in the
  428. UAF.
  429.  
  430. A User Identification Code (UIC) is an identifier used by VAX/VMS to identify
  431. users and groups of users.  It is used to identify processes, directories,
  432. files, and other objects in the system.  A UIC may be specified numerically or
  433. alphanumerically, and is made up of two parts, a group and a member, specified
  434. in the format: [group,member].  For example, UIC [10,14] identifies group 10,
  435. user 14.  The group number is an octal number in the range 1-37776, and the
  436. member is an octal number in the range 0-177776.  An alphanumeric UIC contains
  437. a member name and optionally, a group name in the format: [member] or
  438. [group,member].  The group and member names in an alphanumeric UIC may contain
  439. 1 to 31 alphanumeric characters (A-Z, 0-9, underscore, dollar sign).
  440.  
  441. Each user of the system is limited in the consumption of system
  442. resources, and these limits control the rate at which your process or
  443. any subprocesses you create may consume a resource.  There are 32 levels
  444. of priority in the VAX/VMS system, 0 through 31, the highest being 31.
  445. The priorities are divided into two ranges: timesharing (0-15) and
  446. real-time (16-31).  The default user priority is 4.  Depending on how
  447. heavily the system is being used, your priority may be raised above the
  448. default, but never lowered below it.  VAX/VMS maintains 35 privileges,
  449. divided into the following seven categories classified by how much
  450. damage could be done to the system by possessing them:
  451.  
  452. None    No privileges.
  453. Normal  The minimum privilege needed to use the system effectively.
  454. Group   The ability to effect members of the same UIC group.
  455. Devour  The potential to consume noncritical system-wide resources.
  456. System  The ability to interfere with normal system operation.
  457. File    The potential to bypass file protection security.
  458. All     The ability to take over the entire system.
  459.  
  460. VAX/VMS systems keep a record of overall computer system use by account
  461. holder in a system file called ACCOUNTING.DAT.  The system manager uses
  462. this file to produce reports with the Accounting Utility.  This can be
  463. used to learn more about how the system is being used, how it performs,
  464. and how a particular user is using the system.  It can also be used to
  465. bill users for system time.
  466.  
  467.  
  468. Terminal Characteristics
  469. ~~~~~~~~~~~~~~~~~~~~~~
  470. Setting display width:  $ SET TERMINAL/WIDTH=132
  471.  
  472. Shutting messages off:  $ SET TERMINAL/NOBROADCAST
  473.   This prevents other users from phoning you, sending mail messages, and
  474.   some system messages from appearing on your screen.  If you just want
  475.   mail and phone messages screened, use: $ SET BROADCAST=(NOMAIL,NOPHONE).
  476.  
  477. Increasing type-ahead buffer:  $ SET TERMINAL/ALTYPEHD/PERMANENT
  478.  
  479. Line editing modes:  $ SET TERMINAL/INSERT or $ SET TERMINAL/OVERSTRIKE
  480.  
  481. Defining keys:  $ DEFINE/KEY PF1 "SET DEFAULT DUA3:[INV.SUP]"
  482.                 % DCL-I-DEFKEY, DEFAULT key PF1 has been defined
  483.  
  484. Showing keys:   $ SHOW KEY PF1      (or $ SHOW KEY ALL)
  485.                 DEFAULT keypad definitions:
  486.                    PF1 = "SET DEFAULT DUA3:[INV.SUP]"
  487.  
  488. Deleting keys:  $ DELETE/KEY PF1    (or $ DELETE/KEY ALL)
  489.                 % DCL-I-DELKEY, DEFAULT key PF1 has been deleted
  490.  
  491.  
  492. Changing prompt:  $ SET PROMPT = "What now?"
  493.  
  494. Displaying process information:  $ SHOW PROCESS  (add a qualifier)
  495.  
  496. Changing process information:  $ SET PROCESS/NAME="Bob"
  497.                                $ SET PROCESS/PRIVILEGES=OPER
  498.  
  499.  
  500. File Security
  501. ~~~~~~~~~~~~
  502. UIC-based protection permits access to be granted or denied based on
  503. protection codes that reflect four user categories:
  504.  
  505. System:  system manager
  506. Owner :  account owner
  507. Group :  users in same UIC group
  508. World :  all users of system, regardless of UIC
  509.  
  510. Four type of file access can be granted or denied to members of these user
  511. categories:
  512.  
  513. Read    (R): read the file
  514. Write   (W): create or modify the file
  515. Execute (E): run a program
  516. Delete  (D): delete the file
  517.  
  518. Generally, any category of user can be granted or denied file access
  519. with this protection scheme.  However, you can read a file in a
  520. subdirectory with EXECUTE access if you know its filename and filetype.
  521. Also, since SYSTEM privileges include the ability to bypass all file
  522. protection, anyone within the SYSTEM category can read a file.
  523.  
  524. CONTROL access, or the ability to change the protection and ownership of
  525. a volume, is never specified in the UIC-based protection code.  This is
  526. the fifth type of protection that can be specified in an access control
  527. list (ACL).  It's automatically granted to two user categories when VMS
  528. examines UIC-based protection.  Users in the SYSTEM and OWNER categories
  529. receive CONTROL access by default while GROUP and WORLD categories are
  530. denied CONTROL access.
  531.  
  532. File protection defaults are as follows:
  533.  
  534. System:  RWED
  535. Owner :  RWED
  536. Group :  RE
  537. World :  No access
  538.  
  539. To determine the existing or default protection of a file, use the SHOW
  540. PROTECTION command.  The default in the previous example would be:
  541.    $ SHOW PROTECTION
  542.        SYSTEM=RWED, OWNER=RWED, GROUP=RE, WORLD=NO ACCESS
  543.  
  544. If you want to see file protection in directories, use the /PROTECTION
  545. qualifier with the DIRECTORY command.
  546.  
  547. To change the protection of a file, use the command:
  548.  
  549.    $ SET PROTECTION=(O:RWE,G,W) LOGIN.COM
  550.  
  551. In this example, the account owner has READ, WRITE, and EXECUTE access
  552. to his LOGIN.COM file.  The GROUP and WORLD categories have no access
  553. and SYSTEM access remains unchanged.
  554.  
  555. Rules for specifying protection codes:
  556. 1.  Access types must be abbreviated with one letter: R, W, E, or D.
  557. 2.  User categories may be spelled out or abbreviated.
  558. 3.  Each user category must be separated from its access types with a colon.
  559. 4.  If you specify multiple user categories, separate each with a comma
  560.     and enclose the entire code in parenthesis.
  561. 5.  User categories and access types may be specified in any order.
  562. 6.  If you include a user category, but do not specify an access type
  563.     for that category, access is automatically denied.
  564. 7.  If you omit a user category entirely, protection for that category
  565.     is unchanged.
  566.  
  567. Remember that VAX/VMS evaluates directory protection before file
  568. protection.  If you grant WORLD:R access to a file, but the file is in a
  569. directory without WORLD:R access, another user couldn't read the file.
  570.  
  571.  
  572. EDT Text Editor
  573. ~~~~~~~~~~~~~~
  574. When you enter EDT, you automatically enter line mode, indicated by the
  575. EDT prompt, an asterisk (*).  All line mode commands are made at the
  576. asterisk prompt and terminated by pressing <Return>.  Lines that you
  577. input are numbered sequentially by the editor.  You can reference a line
  578. or group of li^S^Qnes based on the line number or range of line numbers.  A
  579. list of basic EDT commands follows.  Each command may be abbreviated to
  580. the characters in parenthesis.  Complete information on all EDT line
  581. mode commands can be found through the use of the line mode EDT HELP
  582. command.
  583.  
  584. Commands          Function
  585. ~~~~~~~         
  586. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  587. Change (C)        Change from line to keypad mode.  To switch back from
  588.                   keypad mode to line mode, press <Ctrl-Z>.
  589. Copy (CO)         Copy a line or group of lines from one place to another.
  590.                   If you enter the command CO 5 to 10, line 5 will be
  591.                   copied to the line immediately preceding line 10.  The
  592.                   command CO 5:10 to 20 would copy the contents of lines 5
  593.                   through 10 into the area immediately preceding line 20.
  594. Delete (D)        Delete a line or group of lines.  The command D13 would
  595.                   delete line 13, while D13:20 will delete lines 13 to 20.
  596. Exit (EX)         Terminates the EDT session, saving all changes.  This
  597.                   also creates a new version of the file being edited.
  598. Help (H)          Display on-line help on all EDT line mode commands.  The
  599.                   help messages will not be included in the file being edited.
  600. Include (INC)     Copy text from an external file into the file being edited.
  601.                   When the EDT command INCLUDE FILENAME.TYPE is executed,
  602.                   the contents of FILENAME.TYPE are copied into the file
  603.                   being edited.
  604. Insert (I)        Inserts specified text directly before the current
  605.                   position in the file.  While inserting text, you will
  606.                   not receive the EDT "*" prompt.  Press <Ctrl-Z> to
  607.                   return to the "*" prompt when you're finished inserting.
  608. Move (M)          You can't cut and paste with a line-oriented editor.
  609.                   Text will be moved to the area immediately preceding a
  610.                   specified line.  The command M 10:15 to 50 would move
  611.                   lines 10 through 15 to the area immediately preceding
  612.                   line 50.
  613. Quit (QUI)        Exit the EDT editor without saving changes.
  614. Replace (R)       Deletes a specified line or group of lines and enters the
  615.                   INSERT mode so you can add text in that place.  The
  616.                   command R5:10 would delete lines 5 through 10 and switch
  617.                   to the INSERT mode to permit you to enter new text.  To
  618.                   exit the INSERT mode, press <Ctrl-Z>.
  619. Resequence (RES)  Numbers all of the lines in the file that you're
  620.                   editing in increments of 1.  This is useful because
  621.                   text insertion, movement, or deletion causes the file
  622.                   to lose numeric sequence.
  623. Substitute (S)    Substitute a new text element for an old one in the
  624.                   format s/oldtext/newtext/range.  The old and new text
  625.                   elements must be enclosed in angle bracket (< >)
  626.                   delimiters and the range must be specified.
  627. Write (WR)        Write a given range of text to a new file.
  628.                   WRHISTORY.TXT 50:100 would write lines 50 through 100 to
  629.                   a new file called HISTORY.TXT.
  630.  
  631.  
  632. EDT Help Manual
  633. ~~~~~~~~~~~~~
  634. To dump the entire EDT Help file to disk, enter the following DCL command
  635. during a terminal session:  $ ASSIGN EDTHELP.FIL SYS$OUTPUT.  Now, enter
  636. line mode EDT and type:  * HELP *.  Now exit EDT and enter the DCL
  637. command: $ ASSIGN TTnn: SYS$OUTPUTT (TTnn: is your terminal number).
  638.  
  639.  
  640.                   <:=- Part B : Programming VAX/VMS -=:>
  641.  
  642. Introduction
  643. ~~~~~~~~~~~
  644. A symbol is a name chosen to represent a string of characters, a numeric value,
  645. or a logical (true/false) value.  A symbol may be used wherever the value it
  646. represents would normally be found, and can be up to 255 characters long.
  647. Symbols must begin with a character, dollar sign, or underscore, and are not
  648. case-sensitive.  Symbols are created like this:
  649.  
  650.    symbol_name = value    (local symbol)
  651.    symbol_name == value   (global symbol)
  652.  
  653. A global symbol may be used at any command level, but local symbols are lost
  654. when command procedures are finished.  For example:
  655.  
  656.    $ WIDE = "SET TERMINAL/WIDTH=132"
  657.  
  658. Now, anytime you type WIDE at the DCL command line, the terminal width will
  659. be changed to 132 characters.  To show the contents of a symbol:
  660.  
  661.    $ SHOW SYMBOL ANSWER
  662.       ANSWER = 1584    HEX = 00000630    OCTAL = 000000003060
  663.  
  664. The SHOW SYMBOL command uses the local symbol table by default.  To show
  665. the value of a global symbol, use the /GLOBAL qualifier.  To show all
  666. symbols, use the /ALL qualifier (or /GLOBAL/ALL).  To delete symbols,
  667. use: $ DELETE/SYMBOL symbol_name command (with /GLOBAL if it's global).
  668.  
  669. When a DCL command is executed, symbols in the following positions are
  670. automatically translated:
  671.  
  672.   o  the beginning of the command
  673.   o  in a lexical function
  674.   o  in a WRITE or IF statement
  675.   o  on the right side of an = or == assignment statement
  676.   o  inside brackets on the left side of an assignment statement when
  677.      you're preforming string substitution
  678.  
  679. If none of these cases fits, apostrophes will force the translation:
  680.    $ DIRECTORY 'PARTS'  (after $ PARTS = "DJA2:[DBA]PARTS.DAT")
  681.  
  682. Symbols are commonly used for shorthand.  For example, to clear the screen:
  683.  
  684.    $ ESC[0,8] == 27
  685.    $ CLEAR == "[J"
  686.    $ HOME  == "[H"
  687.    $ CLR == WRITE SYS$OUTPUT ESC,HOME,ESC,CLEAR
  688.  
  689. Now, anytime you enter CLR, the screen will be cleared.  Symbols can also be
  690. used to execute command procedures:
  691.  
  692.    $ NETBACK == "@SYS$LOGIN:NETBACKUP"
  693.  
  694. Finally, foreign commands unknown to DCL can be executed by using symbols:
  695.  
  696.    $ KERMIT == RUN SYS$$SYSTEM:KERMIT
  697.  
  698.  
  699. DCL Expressions
  700. ~~~~~~~~~~~~~~
  701. Expressions are built by combining data elements with operators.  A logical
  702. comparison evaluates the relationship between two components as true or
  703. false (True = 1, False = 0).
  704.  
  705. Lexical functions are VAX/VMS routines that return process or system
  706. information, or manipulate user-supplied data.  Lexical functions are unique
  707. because the result is returned in the function name, allowing it to be used as
  708. a symbol (much like Pascal).  Lexical functions are called with the following
  709. format:
  710.  
  711.    F$function_name(parameter, parameter...)
  712.  
  713. For example, the following lexical function manipulates user-supplied data:
  714.  
  715.    $ STRING = "Go     home    right      now!"
  716.    $ STRING = F$EDIT(STRING, "COMPRESS, UPCASE")
  717.    $ SHOW SYMBOL STRING
  718.       STRING = "GO HOME RIGHT NOW!"
  719.  
  720.  
  721. Command Procedures
  722. ~~~~~~~~~~~~~~~~~
  723. A command procedure is a file consisting of a sequence of DCL commands which
  724. can be executed interactively or as a batch job (like a .BAT file in MS-DOS or
  725. a REXX EXEC in VM/SP).  Command procedures are used in VAX/VMS to perform
  726. repetitive or complex tasks and to save time.  With a command procedure, you
  727. can execute many DCL commands with a single statement.
  728.  
  729. Command procedures aren't bound by simple lists of DCL commands executed in
  730. sequence.  They can take advantage of labels, lexical functions, symbols and
  731. relational operators to build sophisticated procedures which act like VAX/VMS
  732. programs.  Command procedures are flexible.  They can be written to take
  733. specific actions based on responses to questions, or even to perform a given
  734. function depending on the time or date.
  735.  
  736.  
  737. Writing Command Procedures
  738. ~~~~~~~~~~~~~~~~~~~~~~~
  739. A text editor such as EDT or EVE is used to create and edit command procedures,
  740. which should be named "PROCEDURE_NAME.COM".  The file type ".COM" is the
  741. default procedure file type, and if a different file type is included, it must
  742. be included when the procedure is invoked.
  743.  
  744. Each new command line must begin with a dollar sign ($).  Multiple spaces or
  745. tabs may be included after the "$" for readability, and command lines may be
  746. extended past a single line by ending the previous line with a hyphen (-) and
  747. not starting the next line with a dollar sign.
  748.  
  749. Data input to programs, such as responses, must be entered without the dollar
  750. sign.  Data lines are used by the program running and are not processed by the
  751. DCL command line interpreter.  For example:
  752.  
  753.    $ MAIL         <--- invokes the Mail Utility
  754.    SEND           <--- Mail SEND command
  755.    JONES, BOB     <--- response to Mail prompt "To:"
  756.    Memo           <--- response to Mail prompt "Subj:"
  757.    Bob,           <--- Mail message
  758.  
  759.    How's it going?'?
  760.  
  761.    Joe
  762.    $              <--- terminates Mail program
  763.    $ EXIT         <--- terminates command procedure
  764.  
  765.  
  766. Comments
  767. ~~~~~
  768. Comments may be included by preceding them with an exclamation point (!),
  769. which causes everything to the right of it to be ignored by the DCL command
  770. interpreter.  Comments make command procedures easier to debug and modify
  771. later.  Spelling DCL commands out rather than using the abbreviations also
  772. makes the command procedure more readable.
  773.  
  774.  
  775. Labels
  776. ~~~
  777. Labels are used by the DCL command line interpreter for conditional
  778. processing and repetitive looping.  Labels should be placed on separate
  779. lines, making them easier to find.  Labels can be 255 characters long, may
  780. not contain blanks, and must be terminated with a colon (:).
  781.  
  782.  
  783. Debugging
  784. ~~~~~~
  785. The SET VERIFY command tells DCL to display each command as it processes it.
  786. This allows you to see where errors are generated, and how strings are
  787. translated.  SET NOVERIFY turns the verify mode off.
  788.  
  789. The SHOW SYMBOL command displays the contents of defined symbols, and is
  790. used to show the contents of a symbol in a command procedure as it is being
  791. executed.
  792.  
  793.  
  794. Invoking Command Procedures
  795. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  796. Command procedures may be invoked interactively by typing the "at" sign (@)
  797. followed by the procedure name.  The file type must also be included if it is
  798. not ".COM" (the default).  Command procedures may be invoked at the command
  799. line or from within another command procedure, called nesting.  The DCL SUBMIT
  800. command will place your command (job) in a batch queue with other jobs waiting
  801. to be run.  Command procedures are generally submitted as batch jobs when you
  802. want them to execute at a specific time, they will take a long time to run, or
  803. when a job must run at a reduced priority.  The following command submits the
  804. command procedure ACCOUNT.COM to the VAX/VMS batch processor:
  805.  
  806.    $ SUBMIT ACCOUNT
  807.    Job ACCOUNT (queue SYS$BATCH, entry 103) started on SYS$BATCH
  808.  
  809. The SYS$BATCH queue is the default and is used unless otherwise specified with
  810. the /QUEUE qualifier.  When VAX/VMS runs this job, a process with your rights
  811. and privileges will be created and the procedure executed within that process.
  812.  
  813.  
  814. Symbols
  815. ~~~~~~
  816. Symbols may be local (single equal sign) or global (double equal sign).
  817. Local symbols are recognized by DCL only at the command level at which it
  818. was defined and more deeply nested levels (subsequently called command
  819. procedures).  Global symbols are recognized at any command level.  Local
  820. symbols should be used when the symbols is only needed for the duration of
  821. the command procedure employing it.  You should only define global symbols
  822. if you're going to use them in other command procedures or for the duration
  823. of your login session.
  824.  
  825. An asterisk can be used to tell the command line interpreter (CLI) to accept
  826. abbreviations.  For example:
  827.  
  828.    $ NO*TES == "@SYS$LOGIN:NOTES"
  829.  
  830. This tells the CLI to accept NO, NOT, NOTE, or NOTES as a valid abbreviation
  831. for the NOTES command.  This notation is usevul for long symbol names.
  832.  
  833.  
  834. Lexical Functions
  835. ~~~~~~~~~~~~~~~~
  836. Lexical functions allow you to obtain basically the same information as DCL
  837. SHOW commands.  However, it's easier to manipulate information which comes
  838. from a lexical function.  As an example, the following two command give the
  839. same information:
  840.  
  841.    $ SHOW TIME                  ! DCL SHOW TIME command
  842.        12-JUN-1989 14:29:23
  843.    $ WRITE SYS$OUTPUT F$TIME()  ! lexical function
  844.        12-JUN-1989 14:29:25.17
  845.  
  846. The second command is more usable, however:
  847.  
  848.    $!  Show_Date.COM
  849.    $!
  850.    $ TIME&DATE = F$TIME()
  851.    $ DATE = F$EXTRACT(0,11,TIME&DATE)
  852.    $ WRITE SYS$OUTPUT DATE
  853.  
  854. This procedure displays only the date portion of the string returned by the
  855. lexical function F$TIME().  (Use @SHOW_DATE to invoke it) VAX/VMS supports
  856. lexical functions to manipulate text strings, convert data types, and return
  857. information about the system, your process, symbols, files and devices.
  858.  
  859.  
  860. Parameters
  861. ~~~~~~~~~
  862. Eight reserved symbols (P1 through P8) are available to command procedures to
  863. supply data to process.  By using these parameters in a command procedure,
  864. different data can be specified each time it's run.  Parameter specification is
  865. done on the command line where the procedure is called.  Unless designed to,
  866. the command procedure will not prompt for parameters.  Parameters are separated
  867. with spaces and may be character strings, integers, or symbols.  If you want to
  868. skip a parameter, us a null string (" ").
  869.  
  870.    $! Add.Com
  871.    $! command procedure to demonstrate passing parameters
  872.    $! (add the first and third parameter)
  873.    $!
  874.    $  WRITE SYS$OUTPUT P1+P3
  875.  
  876.    $ @ADD 12 " " 14
  877.    26
  878.  
  879. If a command procedure requires multiple letters or words as a single
  880. parameter, enclose it in quotes and it will be treated as one parameter and
  881. not converted to uppercase.
  882.  
  883.  
  884. Terminal Output
  885. ~~~~~~~~~~~~
  886. The WRITE and TYPE commands send data to the terminal.  TYPE is used to
  887. display the contents of a file, but may also be used to print lines of text
  888. from within a command procedure.  TYPE may only be used to output text
  889. strings.  Since the WRITE command is processed be DCL, expressions, symbols
  890. and lexical functions are evaluated before the data is sent to the
  891. terminal.
  892.  
  893. The output expression must translate to a string and be sent to the logical
  894. device SYS$OUTPUT, but may be a string, lexical function, symbol, or any
  895. combination of the three.  Here's an example of a command procedure that
  896. uses terminal output:
  897.  
  898.    $! Writing a simple text string
  899.    $!
  900.    $  WRITE SYS$OUTPUT "This is a test..."
  901.    $!
  902.    $! Displaying multiple lines at the terminal
  903.    $!
  904.    $  TYPE SYS$OUTPUT Warning!
  905.           It's been 30 days since you changed
  906.           your password.  Change it now!
  907.    $!
  908.    $! Writing a string with a lexical function
  909.    $!
  910.    $  WRITE SYS$OUTPUT " "HI' You are in directory "F$DIRECTORY()' "
  911.  
  912.  
  913. Terminal Input
  914. ~~~~~~~~~~~
  915. The INQUIRE command's default device is the terminal keyboard, while the
  916. READ command must be told where to accept data from.  The INQUIRE command
  917. prompts for input, reads data and assigns it to a symbol.  All data is
  918. accepted as a character string and is converted to uppercase and compressed
  919. (extra blanks removed).  The READ command prompts for input if the /PROMPT
  920. qualifier is used, accepts data from a specified source and assigns it to a
  921. symbol.  The data is accepted with no string conversion or compression
  922. occurring.  Here's an example of a command procedure that uses terminal
  923. input:
  924.  
  925.    $! Puts whatever you type in the symbol NAME
  926.    $! the /NOPUNCTUATION qualifier will suppress the colon
  927.    $! and space INQUIRE puts at the end of the prompt
  928.    $!
  929.    $  INQUIRE /NOPUNCTUATION NAME "What is your name? "
  930.    $!
  931.    $! Example of READ using SYS$INPUT (terminal) for data
  932.    $!
  933.    $  READ /PROMPT = "First value: " SYS$INPUT VALUE_1
  934.    $  READ /PROMPT = "Second value: " SYS$INPUT VALUE_2
  935.    $  WRITE SYS$OUTPUT VALUE_1," + ",VALUE_2," = ",VALUE_1+VALUE_2
  936.  
  937.  
  938. File I/O
  939. ~~~~~~~
  940. The basic steps to read and write files from within command procedures are
  941. similar to most other languages.  Use the OPEN command to open the file.  If it
  942. does not exist, OPEN will create it.  Use the READ or WRITE commands to read or
  943. write text records from the file.  Use the CLOSE command to close the
  944.  file when you're done.
  945.  
  946. To open a file for writing, you must use the /APPEND or /WRITE qualifier.  The
  947. /WRITE qualifier creates a new file and places the record pointer at the
  948. beginning of the file.  If the file already exists, a new version will be
  949. created by OPEN/WRITE.  The /APPEND qualifier is used to add records to the end
  950. of an existing file.  The file must already exist before using the OPEN/APPEND
  951. command, and when the file is opened, the record pointer is placed at the end
  952. of the file.
  953.  
  954. To open a file for reading, use the /READ qualifier (the default for the
  955. OPEN command).  A file opened for reading may not be written to, and the
  956. record pointer will initially be placed at the first record in the file.
  957. Each time a record is read, the pointer is moved down to the next record.
  958. The WRITE/UPDATE must be used to write over an existing record. Here's an
  959. example of a command procedure using file input and output:
  960.  
  961.    $ OPEN/APPEND OUTPUT_FILE NEW.DAT
  962.    $ OPEN/READ INPUT_FILE OLD.DAT
  963.    $ READ INPUT_FILE RECORD
  964.    $ WRITE SYS$OUTPUT "First record from OLD.DAT - ",RECORD
  965.    $ WRITE OUTPUT_FILE "First record from OLD.DAT - ",RECORD
  966.  
  967. To open a file for both reading and writing, use both the /READ and /WRITE
  968. qualifiers.  The record pointer will be placed at the first record in the file.
  969. Using this method, however, you can only overwrite the record you most recently
  970. read, and records you replace must be the same length.
  971.                                                    
  972.  
  973. Redirecting Command Procedure I/O
  974. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  975. Command procedures often invoke VAX/VMS utilities, and these programs will
  976. normally get input from the logical device SYS$INPUT.  While executing a
  977. command procedure, SYS$INPUT is directed to the command procedure itself, and
  978. this is why you can put command and data lines for a utility or program
  979. directly in the procedure.  SYS$COMMAND defaults to the terminal from where a
  980. command procedure is being executed, and by redirecting SYS$INPUT to
  981. SYS$COMMAND you can use utilities and other programs interactively from command
  982. procedures:
  983.  
  984.    $ DEFINE/USER_MODE SYS$INPUT SYS$COMMAND:
  985.    $ EDIT JUNK.DAT
  986.  
  987. The /USER_MODE qualifier causes the re-assignment to be in effect only for
  988. the next command.
  989.  
  990. Normally command procedure output is displayed at your terminal.  You may
  991. redirect output to a file by using the /OUTPUT qualifier:
  992.  
  993.     $ @SHOW_TIME/OUTPUT = TIME.DAT
  994.  
  995. By default, DCL error and severe error messages are directed to the file
  996. represented by the logical name SYS$ERROR, which usually points to your
  997. terminal.  If you want to log error messages, simply redirect SYS$ERROR to
  998. a file.  If you redirect SYS$ERROR without also redirecting SYS$OUTPUT, DCL
  999. will send error messages to both, and you'll receive the error messages
  1000. twice -- at your terminal and in the file.
  1001.  
  1002. To completely suppress error messages you can redirect both SYS$ERROR
  1003. and SYS$OUTPUT to the null device (NL:) or you can use the SET MESSAGE
  1004. command to turn off all message output.  To suppress all messages, use:
  1005. SET MESSAGE/NOTEXT/NOIDENTIFICATION/NOFACILITY/NOSEVERITY.
  1006.  
  1007.  
  1008. Branching and Conditionals
  1009. ~~~~~~~~~~~~~~~~~~~~~~~~~
  1010. You can use the DCL IF/THEN statements and conditional operators withing
  1011. command procedures to cause the execution of a command based on the
  1012. evaluation of a condition.  The basic use is:  $ IF condition THEN command.
  1013. The condition is a Boolean expression (True or False) and the command is
  1014. any legal DCL command.  The following is a list of conditional operators:
  1015.  
  1016. Operator        Function
  1017. ~~~~~~~       
  1018. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1019. .EQ. / .EQS.    Determines if two numbers/character strings are equal
  1020. .GE. / .GES.    Tests to see whether the first number/character string is
  1021.                 greater than or equal to the second
  1022. .GT. / .GTS.    Determines if the first number/character string is greater
  1023.                 than the second
  1024. .LE. / .LES.    Tests to see if the first number/character string is less
  1025.                 than or equal to the second
  1026. .LT. / .LTS.    Determines if the first number/character string is less than
  1027.                 the second
  1028. .NE. / .NES.    Tests to see whether the two numbers/character strings are
  1029.                 not equal
  1030. .AND.           Combines two numbers with a logical AND   (boolean algebra)
  1031. .OR.            Combines two numbers with a logical OR    (boolean algebra)
  1032. .NOT.           Logically negates a value
  1033.  
  1034. The following is a command procedure using conditional branching:
  1035.  
  1036.    $! Time.Com
  1037.    $!
  1038.    $    TIME = F$TIME()
  1039.    $    HOUR = F$EXTRACT(12,2,TIME)
  1040.    $    IF HOUR .LT. 12 THEN GOTO MORNING
  1041.    $    IF HOUR .LT. 17 THEN GOTO AFTERNOON
  1042.    $    IF HOUR .LT. 18 THEN GOTO EVENING
  1043.    $    GOTO END
  1044.    $  MORNING:
  1045.    $    WRITE SYS$OUTPUT "Good morning!"
  1046.    $  AFTERNOON:
  1047.    $    WRITE SYS$OUTPUT "Good afternoon!"
  1048.    $  EVENING:
  1049.    $    WRITE SYS$OUTPUT "Good evening!"
  1050.    $  END:
  1051.    $    EXIT
  1052.  
  1053.  
  1054. Loops
  1055. ~~
  1056. Loops are used to repeat a statement or group of statements until a
  1057. given condition is met.  DCL supports both DO WHILE and DO UNTIL loops.
  1058. The DO WHILE loop tests the condition before evaluation:
  1059.  
  1060.    $ LOOP:
  1061.    $    IF .NOT. condition THEN GOTO END
  1062.      .
  1063.      .
  1064.      .
  1065.    $    GOTO LOOP
  1066.    $ END:
  1067.    $    EXIT
  1068.  
  1069. The DO UNTIL loop executes the statement(s) and then tests the condition:
  1070.  
  1071.    $ LOOP:
  1072.      .
  1073.      .
  1074.      .
  1075.    $    IF condition THEN GOTO LOOP
  1076.    $    EXIT
  1077.  
  1078.  
  1079. Subroutines
  1080. ~~~~~~~~
  1081. The DCL command GOSUB transfers execution control to a label and the RETURN
  1082. command terminates subroutine execution, returning control to the statement
  1083. after the GOSUB command.  Subroutines are useful where you need to do the same
  1084. series of commands repeatedly in different parts of a command procedure.  They
  1085. also make procedures easier to read and more compact.  The DCL commands GOSUB
  1086. and RETURN are not supported in VAX/VMS versions before VAX/VMS Version 4.4.
  1087. The following is an example procedure using a subroutine:
  1088.  
  1089.    $! Personal.Com
  1090.    $!
  1091.    $!     opens the personal info file
  1092.    $!
  1093.    $  OPEN/WRITE OUTPUT_FILE PERINFO.DAT
  1094.    $!
  1095.    $!     collect info
  1096.    $!
  1097.    $  INQUIRE RECORD "Enter full name"
  1098.    $  GOSUB WRITE_FILE
  1099.    $  INQUIRE RECORD "Enter address"
  1100.    $  GOSUB WRITE_FILE
  1101.    $  INQUIRE RECORD "Enter phone number"
  1102.    $  GOSUB WRITE_FILE
  1103.    $  CLOSE OUTPUT_FILE
  1104.    $  EXIT
  1105.    $!
  1106.    $!     subroutine WRITE_FILE
  1107.    $!
  1108.    $  WRITE_FILE:
  1109.    $      WRITE OUTPUT_FILE RECORD
  1110.    $      RETURN
  1111.  
  1112.  
  1113. Error Handling
  1114. ~~~~~~~~~~~~~
  1115. The command interpreter will execute an EXIT command if a severe error occurs,
  1116. terminating the procedure and returning control to the previous command level,
  1117. unless the DCL ON command is used to specify an action for the command
  1118. interpreter to take.  The ON command supports the three keywords WARNING,
  1119. ERROR, and SEVERE_ERROR.  To override error handling for procedure warnings,
  1120. for example, use something like this:
  1121.  
  1122.    $ ON WARNING THEN EXIT
  1123.      or
  1124.    $ ON WARNING THEN GOTO label
  1125.  
  1126. WARNING causes the command procedure to take action if a warning, error, or
  1127. severe error occurs.  ERROR causes the action if an error or severe error
  1128. occurs, and SEVERE_ERROR causes the action only if a fatal error occurs.
  1129.  
  1130. $STATUS and $SEVERITY are reserved DCL global symbols, and each time a command
  1131. is executed, values are assigned to these symbols. $STATUS holds the full
  1132. condition code of the last statement and $SEVERITY holds an error severity
  1133. level.  The condition code in $STATUS is valid to the VAX/VMS MESSAGE facility
  1134. and can be used in conjunction with F$MESSAGE to obtain the actual text message
  1135. associated with the code:
  1136.  
  1137.    $ SET DEFAULT DUB1:[BYNON]
  1138.    $ WRITE SYS$OUTPUT $STATUS $X00000001
  1139.    $ WRITE SYS$OUTPUT F$MESSAGE(%X00000001)
  1140.    % SYSTEM-S-NORMAL, normal successful completion
  1141.  
  1142. All DCL commands will return a condition code, but not all condition codes
  1143. have text messages.  Condition codes without text messages will return the
  1144. message "%NONAME-E-NOMSG Message number (8-digit code)".
  1145.  
  1146. The message text isn't very useful for making conditional decisions though, so
  1147. $SEVERITY is used.  It contains one of five possible values extracted from the
  1148. first three bits of $STATUS.  Here are the codes:
  1149.  
  1150. Code  Definition
  1151. ~~~  ~~~~~~~~~~
  1152.  0    Warning
  1153.  1    Success
  1154.  2    Error
  1155.  3    Information
  1156.  4    Severe Error
  1157.  
  1158. Odd values (1,3) indicate success while even values (0,2,4) indicate failure.
  1159. There are basically two ways to use the status and severity codes to handle
  1160. errors.  The first is to treat $STATUS as a Boolean value:
  1161.  
  1162.    $ SET NOON
  1163.    $ command                         ! a DCL command
  1164.    $ IF $STATUS THEN GOTO NO_ERR     ! test $STATUS for T or F
  1165.      .
  1166.      .                               ! handle the error
  1167.      .
  1168.    $ NO_ERR                          ! continue processing
  1169.      .
  1170.      .
  1171.      .
  1172.    $ EXIT
  1173.  
  1174. The second method is to trap the error with the ON WARNING command, then use
  1175. the severity level to determine an appropriate course of action:
  1176.  
  1177.    $ SET NOON
  1178.    $ ON WARNING GOTO ERR_TRAP
  1179.    $ command                         ! a DCL command
  1180.    $ command                         ! a DCL command
  1181.      .
  1182.      .
  1183.      .
  1184.    $ EXIT
  1185.    $!
  1186.    $! error trap code
  1187.    $!
  1188.    $ ERR_TRAP:
  1189.    $    SEVERITY = $SEVERITY             ! save the error code
  1190.    $    IF SEVERITY = 0 THEN command     ! if warning...
  1191.    $    GOTO DONE
  1192.    $    IF SEVERITY = 2 THEN command     ! if error...
  1193.    $    GOTO DONE
  1194.    $    IF SEVERITY = 4 THEN command     ! if severe error...
  1195.    $ DONE:
  1196.      .
  1197.      .
  1198.      .
  1199.    $ EXIT
  1200.  
  1201. Error checking can be completely disabled with the SET NOON command.  When
  1202. this is in effect, the command interpreter continues updating the condition
  1203. code, but does not perform any error checking.  The DCL command SET ON
  1204. restors error checking to normal.  For example:
  1205.  
  1206.    $ SET NOON      ! turn off error checking
  1207.    $ command       ! a DCL command
  1208.    $ SET ON        ! restor error checking
  1209.  
  1210.  
  1211. Termination
  1212. ~~~~~~~~~~
  1213. The EXIT command will terminate the current command procedure and return
  1214. control to the command level that called it while the STOP command terminates
  1215. all command procedures (if nested) and returns control to DCL.
  1216.  
  1217.  
  1218. Example Command Procedures
  1219. ~~~~~~~~~~~~~~~~~~~~~~~~~
  1220. The following are two example command procedures to demonstrate some of
  1221. the previously discussed techniques.
  1222.  
  1223. Login.Com
  1224. ~~~~~~~~
  1225.    $! Login.Com - executed each time you log in
  1226.    $!
  1227.    $! Check for a network or batch login
  1228.    $!
  1229.    $      IF F$MODE() .EQS. "NETWORK" THEN GOTO NETWORK
  1230.    $      IF F$MODE() .EQS. "BATCH" THEN GOTO BATCH
  1231.    $!
  1232.    $! Define process permanent symbols for convenience
  1233.    $!
  1234.    $      SD == "SET DEFAULT"
  1235.    $      SH == "SET HOST"
  1236.    $      WI*DE == "SET TERMINAL/WIDTH=132"
  1237.    $      NA*RROW == "SET TERMINAL/WIDTH=80"
  1238.    $      DIR*ECTORY == "DIRECTORY/SIZE"
  1239.    $      PU*RGE == "PURGE/LOG/KEEP=2"            ! keep latest 2 version
  1240.    $      HO*ME == "SET DEFAULT SYS$LOGIN:"
  1241.    $      WHO == "SHOW USERS"
  1242.    $      EVE == "EDIT/TPU"
  1243.    $      EDT == "EDIT/EDT/COMMAND=SYS$LOGIN:EDTINI.EDT"
  1244.    $      BR*OWSE == "TYPE/PAGE"
  1245.    $!
  1246.    $! Define special keys
  1247.    $!
  1248.    $      DEFINE/KEY/NOLOG/TERM PF1 "DIR"         ! term ends with <enter>
  1249.    $      DEFINE/KEY/NOLOG PF2 "EDIT"
  1250.    $      DEFINE/KEY/NOLOG/TERM/NOECHO PF3 "LOGOUT"
  1251.    $      DEFINE/KEY/NOLOG/TERM/NOECHO HELP "SHOW KEY/ALL"
  1252.    $!
  1253.    $! Modify terminal characteristics
  1254.    $!
  1255.    $      SET TERMINAL/INSERT     ! insert mode
  1256.    $      SET PROMPT = "[BYNON]> "
  1257.    $!
  1258.    $! Show time and quit
  1259.    $!
  1260.    $      SHOW TIME
  1261.    $      EXIT
  1262.    $!
  1263.    $! If it's a network login, we can now
  1264.    $! perform some other commands if desired.
  1265.    $! Just quit for now though.
  1266.    $!
  1267.    $  NETWORK:
  1268.    $      EXIT
  1269.    $!
  1270.    $! If it's a batch job login, set verification on and quit.
  1271.    $!
  1272.    $  BATCH:
  1273.    $      SET VERIFY
  1274.    $      EXIT
  1275.  
  1276.  
  1277. Subdir.Com
  1278. ~~~~~~~~~
  1279.    $! Subdir.Com - how to search and parse character strings
  1280.    $!
  1281.    $      WRITE SYS$OUTPUT F$DIRECTORY()+ " Subdirectories:"
  1282.    $      WRITE SYS$OUTPUT " "
  1283.    $!
  1284.    $! Search for subdirectory names and display them on the terminal
  1285.    $!
  1286.    $  DIR$LOOP:
  1287.    $      FILE = F$SEARCH("*.DIR")
  1288.    $!
  1289.    $! If DCL returns a null string (" ") we're done
  1290.    $!
  1291.    $      IF FILE .EQS. " "THEN GOTO END$DIR$LOOP
  1292.    $!
  1293.    $! Find the position of the period
  1294.    $!
  1295.    $      DOT = F$LOCATE(".",FILE)
  1296.    $!
  1297.    $! Find the position of the right bracket
  1298.    $!
  1299.    $      BRACKET = F$LOCATE("]",FILE)
  1300.    $!
  1301.    $! Extract the string between the dot and bracket
  1302.    $!
  1303.    $      FILE = F$EXTRACT(BRACKET+1,DOT-BRACKET-1,FILE)
  1304.    $!
  1305.    $! Display the subdirectory name and start over
  1306.    $!
  1307.    $      WRITE SYS$OUTPUT "      ' 'FILE' "
  1308.    $      GOTO DIR$LOOP
  1309.    $  END$DIR$LOOP:
  1310.    $      EXIT                                              
  1311.  
  1312. <END PART I>
  1313. ______________________________________________________________________________
  1314.  
  1315. Downloaded From P-80 International Information Systems 304-744-2253 12yrs+
  1316.