****************************************************************************** * * OPEN.FILE.B - Used to open file to named common variable. * (catalog name OPEN$UV$FILE) * * Module %M% Version %I% Date %H% * * (c) Copyright 1998 Ardent Software Inc. - All Rights Reserved * This is unpublished proprietary source code of Ardent Software Inc. * The copyright notice above does not evidence any actual or intended * publication of such source code. * ******************************************************************************* * * Maintenence log - insert most recent change descriptions at top * * Date.... GTAR# WHO Description........................................ * 10/14/98 23801 SAP Change copyrights. * 11/04/92 10327 WLC Updated comments. * 10/12/92 10327 WLC Initial Release. ******************************************************************************* * * This subroutine replaces a standard UniVerse BASIC OPEN * statement. It checks a table to see if the given file * has previously been opened. If not, the file is opened. * If it was, no open is done. In both instances, the file * status is returned. * SUBROUTINE OPEN$UV$FILE(DICT.VAL,DATA.VAL,FILE.VAL,VAR.STAMP) * * DICT.VAL : 'DICT' if dict is opened, otherwise null * DATA.VAL : data file name. if null, then default open * FILE.VAL : what this file is opened to (returned) * VAR.STAMP : string containing the variable name file is opened * to, with _# appended. The # uniquely identifies this * variable from variables in other source files. The * numbers used are stored in OPEN.UNIQUE file in the * uniVerse home account. * * A status code is set prior to exiting this subroutine. The * UniVerse internal '@' (at) value @USER.RETURN.CODE is set * to the following: * * 0: if the file could not be opened. * 1: if the file was opened. * 2: if the file was previously opened. * * * * * Equates * * TABLE.MAX: This is the MAXIMUM number of entries that ONE * user can make. Basically, the maximum number * of files that can be "held" open. * This equate is defined in OPEN.TOOLS.H. * * RESET.ON.LOGTO: This is used to CLEAR the file table when a user * performs a LOGTO and then calls this subroutine. * This equate is defined in OPEN.TOOLS.H. * * The following values can be given for RESET.ON.LOGTO: * * 0 (zero) or NO: DO NOT reset tables. This is the default. * * 1 (non-zero) : When the user LOGTO's another account and * or YES calls this subroutine the first time, the * tables are cleared. * $INCLUDE UNIVERSE.INCLUDE OPEN.TOOLS.H * $OPTIONS PICK * * Declare named common * COMMON /UV$open$files/ FILE$VARS(TABLE.MAX),FILE$TABLE(5),curr$UV$ACCOUNT * * FILE$VARS : contains actual filevars that are returned * FILE$TABLE : 5 elements * element 1 : list of opened file names ascending left (multi valued) * element 2 : pointer into file$vars array (multi valued) * element 3 : current number of open files (single value) * element 4 : file open requests (multi valued) * element 5 : variable stamp - unique identifier for the file variable * * curr$UV$ACCOUNT : the name of the account in which these files * were opened. * * * Equates * EQU FAILURE TO 0 ;* if open fails EQU SUCCESS TO 1 ;* if request for new open EQU ALREADY.OPENED TO 2 ;* if file was already opened EQU FILES.NOW.OPENED TO FILE$TABLE(1) EQU TABLE.POINTER TO FILE$TABLE(2) EQU TABLE.COUNTER TO FILE$TABLE(3) EQU OPEN.REQUESTS TO FILE$TABLE(4) EQU VARIABLE.LIST TO FILE$TABLE(5) EQU NO TO 0 EQU YES TO 1 * * * Declare variables * whole.file.name="" field.loc=0 * * Find out if user is in a NEW account. If YES, nuke the tables. * if (curr$UV$ACCOUNT # @who) AND (RESET.ON.LOGTO = YES) then RESET.TABLES = YES end else RESET.TABLES = NO end * * If common has not been used, clean it all up * if not(TABLE.COUNTER) or RESET.TABLES then mat FILE$VARS="" FILES.NOW.OPENED="" TABLE.POINTER="" TABLE.COUNTER=0 curr$UV$ACCOUNT=@who end * * Assume we will be successful opening file * @user.return.code=SUCCESS * * Clean up input data * DICT.VAL=upcase(trim(DICT.VAL)) DATA.VAL=trim(DATA.VAL) * * Build whole file * if DICT.VAL = "DICT" then whole.file.name="D_" if DATA.VAL # "" then whole.file.name:=DATA.VAL * * Extend Name further by PREpending with account name * if RESET.ON.LOGTO then whole.file.name=curr$UV$ACCOUNT:"*":whole.file.name end * * See if TABLE.MAX has been exceeded * if TABLE.COUNTER < TABLE.MAX then * * Check to see if file has been previously opened * locate(whole.file.name,FILES.NOW.OPENED ; field.loc ; 'al') then * * File was previously opened. See if it's the same file variable name * if VARIABLE.LIST = VAR.STAMP then FILE.VAL=FILE$VARS(TABLE.POINTER) OPEN.REQUESTS=OPEN.REQUESTS+1 @user.return.code=ALREADY.OPENED return end end * * Check to see if this variable was previously used as file var and close first * locate VAR.STAMP in VARIABLE.LIST setting var.loc else var.loc=0 if var.loc and whole.file.name # FILES.NOW.OPENED then CLOSE FILE$VARS(TABLE.POINTER) TABLE.POINTER=delete(TABLE.POINTER, var.loc) FILES.NOW.OPENED=delete(FILES.NOW.OPENED, var.loc) OPEN.REQUESTS=delete(OPEN.REQUESTS, var.loc) VARIABLE.LIST=delete(VARIABLE.LIST, var.loc) end * * File was NOT previously opened or it's a new variable name. Do it now. * open DICT.VAL,DATA.VAL to FILE$VARS(TABLE.COUNTER+1) then ins whole.file.name before FILES.NOW.OPENED ins TABLE.COUNTER+1 before TABLE.POINTER ins "1" before OPEN.REQUESTS ins VAR.STAMP before VARIABLE.LIST FILE.VAL=FILE$VARS(TABLE.COUNTER+1) TABLE.COUNTER+=1 ;* open succeeded end else @user.return.code=FAILURE ;* open failed end end else * * TABLE.MAX value was exceeded. Just open the file normally * open DICT.VAL,DATA.VAL to FILE.VAL else @user.return.code=FAILURE ;* open failed end end * * Return to calling program * return * * End of subroutine * END