Contents
- lib$cvt_from_internal_time, lib$convert_date_time, lib$free_date_time_context
- lib$cvt_vectim, lib$sys_asctim
- lib$delete_logical, lib$get_logical, lib$set_logical
- lib$delete_symbol, lib$get_symbol, lib$set_symbol
- lib$do_command
- lib$fid_to_name
- lib$get_accnam, lib$format_sogw_prot, lib$parse_access_code, lib$parse_sogw_prot
- lib$get_common, lib$put_common
- lib$getdvi
- lib$get_ef, lib$free_ef
- lib$get_input
Please don't directly port examples from Jim Duff's examples page and post them here. The license for Jim's examples prohibits modifying his code and republishing it. Obviously, you can use Jim's code for your own personal use.
Please keep the examples in alphabetic order.
lib$cvt_from_internal_time, lib$convert_date_time, lib$free_date_time_context
1 from vms.rtl.lib import (convert_date_string, free_date_time_context,
2 cvt_from_internal_time)
3 from vms.libdtdef import LIB_K_DAY_OF_YEAR
4
5 # Convert our ASCII formatted date/time to VMS internal time format
6 s, dt, ctxt, defflt = convert_date_string('13-JAN-1993 14:54:09.24')
7 s, ctxt = free_date_time_context(ctxt)
8
9 # Add 1 day, VMS clock resolution is 100ns
10 dt += 10000000L * 3600 * 24
11
12 s, day = cvt_from_internal_time(LIB_K_DAY_OF_YEAR, dt)
13 print 'The day after 13-JAN is the %d day of the year 1993' % (day,)
14
15 s, day = cvt_from_internal_time(LIB_K_DAY_OF_YEAR)
16 print 'We are the %d day of the year' % (day,)
lib$cvt_vectim, lib$sys_asctim
1 from vms.rtl.lib import cvt_vectim, sys_asctim
2
3 # Convert '13-JAN-1993 14:54:09.24' to a binary representation
4 s, resultant_time = cvt_vectim((1993, 1, 13, 14, 54, 9, 24))
5
6 # Convert the binary representation to the string one
7 s, resultant_string = sys_asctim(resultant_time)
8
9 print 'The text representation is:', resultant_string
lib$delete_logical, lib$get_logical, lib$set_logical
1 from vms.rtl.lib import delete_logical, get_logical, set_logical
2 from vms.ssdef import SS__SUPERSEDE
3
4 # Set the logical MY_LOGICAL to MY_VALUE in table LNM$JOB
5 s = set_logical('MY_LOGICAL', 'MY_VALUE', 'LNM$JOB')
6
7 if s == SS__SUPERSEDE:
8 print 'The previous definition of the logical name was replaced.'
9
10 # Retreive the value of the previously defined logical
11 s, resultant_string, max_index = get_logical('MY_LOGICAL', 'LNM$JOB')
12
13 print 'Logical MY_LOGICAL was translated into', resultant_string
14
15 # Delete the previously defined logical
16 s = delete_logical('MY_LOGICAL', 'LNM$JOB')
lib$delete_symbol, lib$get_symbol, lib$set_symbol
1 from vms.rtl.lib import delete_symbol, get_symbol, set_symbol
2 from vms.libclidef import LIB_K_CLI_LOCAL_SYM, LIB_K_CLI_GLOBAL_SYM
3
4 # Set the local symbol MY_SYMBOL to MY_VALUE
5 s = set_symbol('MY_SYMBOL', 'MY_VALUE', LIB_K_CLI_LOCAL_SYM)
6
7 # Retreive the value of the previously defined symbol
8 s, resultant_string, table_type_indicator = get_symbol('MY_SYMBOL')
9
10 libtbl = {LIB_K_CLI_LOCAL_SYM : 'Local', LIB_K_CLI_GLOBAL_SYM : 'Global'}
11 print '%s Symbol MY_SYMBOL was translated into %s ' % (
12 libtbl[table_type_indicator],
13 resultant_string)
14
15 # Delete the previously defined symbol
16 s = delete_symbol('MY_SYMBOL', LIB_K_CLI_LOCAL_SYM)
lib$do_command
1 from vms.rtl.lib import do_command
2 # This will normally stop the program and execute the command supply
3 # If successful (the call to do_command, not the called command...)
4 # it does not return control to the calling program.
5 do_command('SHOW USERS')
lib$fid_to_name
1 from vms.rms import getrmsattr, RMSATTR_K_FID
2 from vms.rtl.lib import fid_to_name
3 fid = getrmsattr('sys$login:login.com', RMSATTR_K_FID)
4 print 'The file ID of sys$login:login.com is', fid
5 fn = fid_to_name('sys$login',fid)[1]
6 print 'The file name for this file ID is', fn
lib$get_accnam, lib$format_sogw_prot, lib$parse_access_code, lib$parse_sogw_prot
1 from vms.rtl.lib import (format_sogw_prot, get_accnam, parse_access_code,
2 parse_sogw_prot)
3
4 # Get the access name table for the FILE object class
5 accnam = get_accnam('FILE')[1]
6 print accnam
7
8 # Translate a string of access names into a mask for a each ownership category.
9 #
10 ownership_system = 0x000F
11 ownership_owner = 0x00F0
12 ownership_group = 0x0F00
13 ownership_world = 0xF000
14
15 system_access = parse_access_code("RWED", ownership_system, accnam)[1]
16 owner_acces = parse_access_code("REW", ownership_owner, accnam)[1]
17 group_access = parse_access_code("RE", ownership_group)[1]
18 world_access = parse_access_code("", ownership_world)[1]
19
20 access = system_access + owner_acces + group_access + world_access
21
22 #
23 # The mask has bits set for the access requested for the specified
24 # ownership category.
25 # This is opposite the standard protection format where a set
26 # bit in the protection mask means no access.
27 #
28 protection_mask = ~access & 0xFFFF
29
30 # Translate the protection mask into a protection string
31 print 'Protection string: "%s"' % (format_sogw_prot(protection_mask,
32 access_names=accnam)[1],)
33
34 # Parse and translate the protection string into a protection mask
35 s, protection_mask, ownership_mask, end_position = \
parse_sogw_prot("SYSTEM=RWED,OWNER:RWED,GROUP,WORLD:R")
36
37 # Translate the protection mask into a protection string
38 print 'Protection string: "%s"' % (format_sogw_prot(protection_mask,
39 access_names=accnam)[1],)
lib$get_common, lib$put_common
1 from vms.rtl.lib import get_common, put_common
2 # Get the string in the common area.
3 s, resultant_string = get_common()
4 print 'Common area contains: "%s"' % resultant_string
5 # Copy the contents of a string into the common area.
6 s, resultant_length = put_common('My string')
7 print resultant_length, 'characters have been copied to the common area'
lib$getdvi
1 from vms.rtl.lib import getdvi
2 from vms.dvidef import DVI__FULLDEVNAM, DVI__FREEBLOCKS, DVI__LOGVOLNAM
3 disk = "SYS$SYSDEVICE"
4 # get the full device namme (node name and device name)
5 devnam = getdvi(DVI__FULLDEVNAM, device_name=disk)[2]
6 # get the logical name of the volume
7 logvolnam = getdvi(DVI__LOGVOLNAM, device_name=disk)[2]
8 # get the number of free blocks on the disk
9 freeblocks = getdvi(DVI__FREEBLOCKS, device_name=disk)[1]
10 # print results
11 print 'disk %s:\n\tlogical name %s\n\t%d free blocks' % (devnam, logvolnam, freeblocks)
lib$get_ef, lib$free_ef
1 from vms.rtl.lib import get_ef, free_ef
2 # Get an event flag
3 s, efn = get_ef()
4 print "Got event flag %u" % efn
5 # Free the event flag previously gotten.
6 free_ef(efn)
lib$get_input
1 from vms.rtl.lib import get_input
2 from vms.rmsdef import RMS__EOF
3
4 try:
5 s, input = get_input('Enter your input: ')
6 except VMSError, e:
7 if e.errno == RMS__EOF:
8 # CTRL-Z generate an eof which raise this error
9 print 'CTRL-Z used'
10 else:
11 # Any other error is raised again and terminate the program
12 raise
13 else:
14 print 'You have entered: "%s"' % input
