C..FingMaint.For			Maintain  finger shared commons
C..					R. Garland / C.U.Chemistry / 7-Oct-1983
C - Fixed  3-Mar-89 by TMK to allow up to 99999 of any one object in reports
C - Fixed 30-Mar-89 by TMK to add /STATISTICS to SHOW command
C - Fixed  3-Jul-89 by TMK for 31-character personal names and to give proper
c			   error message if user says 'ADD/MUMBLE'
c - Fixed 20-Aug-89 by TMK to include Craig Watkins' fix for ADD/UAF speedup
c - Fixed 3-Mar-94 by Leonardo J. Miceli %FORT-I-NOPATH, No path to this
c                  statement during compile.

	Program	FingMaint

	Include		'($RMSDEF)'

	Integer		I_Length
	Integer		Cli$Dcl_Parse, Cli$Dispatch
	Character	Line*255
	Integer		Lib$Get_Input
	Character	Lib$Get_Foreign*255
	External	Shr_Cld, Signal_Handler
	logical forever

	data forever /.true./

	Call Lib$Establish(Signal_Handler)

	Line = Lib$Get_Foreign(,I_Length)
	If ( I_Length .gt. 0 ) then
	    If ( Cli$Dcl_Parse(Line(:I_Length),Shr_Cld) )
	1	Call Cli$Dispatch
	    Call Exit
	End if

	Do while (forever)
	    If ( Lib$Get_Input(Line,'Finger Maintain> ',I_length)
	1	.eq. Rms$_Eof ) Call Exit
	    If ( I_Length .gt. 0 ) then
		If ( Cli$Dcl_Parse(Line(:I_Length),Shr_Cld) )
	1	Call Cli$Dispatch
	    End if
	End do

	End

c------------------------------------------------------------------------------
	Integer Function Shr_Add

	Include		'Fingercom.for'
	Include		'Fingerdef.inc'

	Character       UAF_Record*(UAF$K_Length)
	Character       UAF_Username*(UAF$S_Username)
	Equivalence     (UAF_Username,UAF_Record(UAF$T_Username+1:))
	Character       UAF_Owner*(UAF$S_Owner)
	Equivalence     (UAF_Owner,UAF_Record(Uaf$T_Owner+1:))

	Character*12	UserName
	Character*31	Owner, PersonalName
	Character	Terminal*8, Location*25, TTType*25
	Character	Host*32, Type*1, Link*32, Route*72
	Character	Network*20, Local_Host*32, Organization*72
	Integer		Cli$Present
	Integer		Cli$Get_Value

	Shr_Add = 1

	If ( Cli$Present('USER') ) then
c	  Add User(s)
	    If ( Cli$Present('UAF') ) then
c	      Create the username database (shareable image) from the UAF
		Open(	Unit = 10,
	1	    File = 'SYSUAF',
	2	    Default File = 'SYS$SYSTEM:.DAT',
	4	    Status = 'Old',
	5	    Organization = 'Indexed',
	6	    Access = 'Keyed',
	7	    Form = 'Formatted',
	8	    Readonly, 
	9	    Shared)
		ii = 1
		Do while (.true.)
		    Read(10,1000,End= 200) UAF_Record

	 	    Usr$C_Username(ii) = UAF_Username
	 	    Usr$C_Personalname(ii) = UAF_Owner

	 	    ii = ii + 1
	 	    If ( ii .eq. Usr$I_Max ) Goto 180
		End do
		Goto 200
180		Write(6,2000)
200		Continue
		Usr$I_Last = ii - 1
		Return
	    End if
	    If ( .not. Cli$Get_Value('USER',UserName) ) Return
	    If ( .not. Cli$Get_Value('PERSONALNAME',Owner) ) Return
	    If ( Usr$I_Last .ge. Usr$I_Max ) Goto 300
	    Usr$I_Last = Usr$I_Last + 1
	    Usr$C_Username(Usr$I_Last) = UserName
	    Usr$C_Personalname(Usr$I_Last) = Owner
	    Return
	Else if ( Cli$Present('TERMINAL') ) then
	    If ( .not. Cli$Get_Value('TERMINAL',Terminal) ) Return
	    If ( .not. Cli$Get_Value('LOCATION',Location) ) Return
	    If ( .not. Cli$Get_Value('TTType',TTType) ) TTType = ' '
	    If ( Loc$I_Last .ge. Loc$I_max ) Goto 300
	    Loc$I_Last = Loc$I_Last + 1
	    Loc$C_Terminal(Loc$I_Last) = Terminal
	    Loc$C_Location(Loc$I_Last) = Location
	    Loc$C_TTType(Loc$I_Last) = TTType
	    Return
	Else if ( Cli$Present('HOST') ) then
	    If ( .not. Cli$Get_Value('HOST',Host) ) Return
	    If ( Host$I_Last .ge. Host$I_max ) Goto 300
	    If ( .not. Cli$Get_Value('TYPE',Type) ) Type = 'D'
	    If ( .not. Cli$Get_Value('LINK',Link) ) Link = ' '
	    If ( .not. Cli$Get_Value('ROUTE',Route) ) Route = ' '
	    Host$I_Last = Host$I_Last + 1
	    Host$C_Host(Host$I_Last) = Host
	    Host$C_Type(Host$I_Last) = Type
	    Host$C_Link(Host$I_Last) = Link
	    Host$C_Route(Host$I_Last) = Route
	    Return
	Else if ( Cli$Present('NETWORK') ) then
	    If ( .not. Cli$Get_Value('NETWORK',Network) ) Return
	    If ( .not. Cli$Get_Value('TYPE',Type) ) Return
	    If ( Net$I_Last .ge. Net$I_max ) Goto 300
	    Net$I_Last = Net$I_Last + 1
	    Net$C_Name(Net$I_Last) = Network
	    Net$C_Type(Net$I_Last) = Type
	    Return
	Else if ( Cli$Present('ROUTER_HOST') ) then
	    If ( .not. Cli$Get_Value('ROUTER_HOST',Host) ) Return
	    If ( .not. Cli$Get_Value('TYPE',Type) ) Type = 'D'
	    If ( .not. Cli$Get_Value('ROUTE',Route) ) Route = ' '
	    Net$C_Router_Host = Host
	    Net$C_Router_Type = Type
	    Net$C_Router_Route = Route
	    Return
	Else if ( Cli$Present('LOCAL_HOST') ) then
	    If ( .not. Cli$Get_Value('LOCAL_HOST',Local_Host) ) Return
	    Net$C_Local_Host_Name = Local_Host
	    Return
	Else if ( Cli$Present('ORGANIZATION') ) then
	    If ( .not. Cli$Get_Value('ORGANIZATION',Organization) ) Return
	    Net$C_Organization = Organization
	    Return
	Else
	    Write(6,2001)
	    Return
	End if

300	Write(6,2000)
	Return

1000    Format(A)
2000	Format(1X,'%FINGMAINT-W-EXCEED, exceeded item storage space.')
2001	Format(1X,'%FINGMAINT-W-INVQUAL, unrecognized qualifier in ADD.')
	End

c------------------------------------------------------------------------------
	Integer Function Shr_Show

	Include		'Fingercom.for'

	Character	Username*12, Terminal*8, Host*32
	Character	Network*20
	Integer		Cli$Present
	Integer		Cli$Get_Value

	Shr_Show = 1

	If ( Cli$Present('USER') ) then
	    If ( Cli$Present('ALL') ) then
		Write(6,1001) Usr$I_Last, Usr$I_Max
		Do ii = 1,Usr$I_Last
		    Write(6,1002) ii, Usr$C_Username(ii),
	1		Usr$C_Personalname(ii)
		End do
	    Else if ( Cli$Get_Value('USER',Username) ) then
		Do ii = 1,Usr$I_Last
		    If ( Username .eq. Usr$C_Username(ii) ) then
			Write(6,1002) ii, Usr$C_Username(ii),
	2		    Usr$C_Personalname(ii)
			Return
		    End if
	 	End do
		Write(6,4001)
	    End if
	End if
	If ( Cli$Present('TERMINAL') ) then
	    If ( Cli$Present('ALL') ) then
		Write(6,2001) Loc$I_Last, Loc$I_Max
		Do ii = 1,Loc$I_Last
		    Write(6,2002) ii, Loc$C_Terminal(ii),
	1		Loc$C_Location(ii),
	2		Loc$C_TTType(ii)
		End do
	    Else if ( Cli$Get_Value('TERMINAL',Terminal) ) then
		Do ii = 1,Loc$I_Last
		    If ( Terminal .eq. Loc$C_Terminal(ii) ) then
			Write(6,2002) ii, Loc$C_Terminal(ii),
	2		    Loc$C_Location(ii),
	3		    Loc$C_TTType(ii)
			Return
		    End if
		End do
		Write(6,4001)
	    End if
	End if
	If ( Cli$Present('HOST') ) then
	    If ( Cli$Present('ALL') ) then
		Write(6,3001) Host$I_Last, Host$I_Max
		Do ii = 1,Host$I_Last
		    Write(6,3002) ii, Host$C_Host(ii),
	1		Host$C_Type(ii)
		    Write(6,3008) Host$C_Link(ii),
	1		Host$C_Route(ii)
		End do
	    Else if ( Cli$Get_Value('HOST',Host) ) then
		Do ii = 1,Host$I_Last
		    If ( Host .eq. Host$C_Host(ii) ) then
			Write(6,3002) ii, Host$C_Host(ii),
	1		Host$C_Type(ii)
			Write(6,3008) Host$C_Link(ii),
	1		Host$C_Route(ii)
			Return
		    End if
		End do
		Write(6,4001)
	    End if
	End if
	If ( Cli$Present('ROUTER_HOST') ) then
	    Write(6,3010) Net$C_Router_Host,
	1	Net$C_Router_Type,
	3	Net$C_Router_Route
	End if
	If ( Cli$Present('STATISTICS') ) then
	    Write(6,5001) Usr$I_Last, Usr$I_Max,
	1	100-ifix(float(Usr$I_Last)/float(Usr$I_Max)*100.)
	    Write(6,5002) Loc$I_Last, Loc$I_Max,
	1	100-ifix(float(Loc$I_Last)/float(Loc$I_Max)*100.)
	    Write(6,5003) Host$I_Last, Host$I_Max,
	1	100-ifix(float(Host$I_Last)/float(Host$I_Max)*100.)
	    Write(6,5004) Net$I_Last, Net$I_Max,
	1	100-ifix(float(Net$I_Last)/float(Net$I_Max)*100.)
	End if
	If ( Cli$Present('NETWORK') ) then
	    If ( Cli$Present('ALL') ) then
		Write(6,3004) Net$I_Last, Net$I_Max
		Do ii = 1,Net$I_Last
		    Write(6,3003) ii, Net$C_Name(ii),
	1		Net$C_Type(ii)
		End do
	    Else if ( Cli$Get_Value('NETWORK',Network) ) then
		Do ii = 1,Net$I_Last
		    If ( Network .eq. Net$C_Name(ii) ) then
			Write(6,3003) ii, Net$C_Name(ii),
	1		Net$C_Type(ii)
			Return
		    End if
		End do
		Write(6,4001)
	    End if
	Else if ( Cli$Present('LOCAL_HOST') ) then
	    If ( Net$C_Local_Host_Name .eq. ' ' ) then
		Write(6,3005) 'Local Host name'
	    Else
		Write(6,3006) Net$C_Local_Host_Name
	    End if
	    Return
	Else if ( Cli$Present('ORGANIZATION') ) then
	    If ( Net$C_Organization .eq. ' ' ) then
		Write(6,3005) 'Organization'
	    Else
		Write(6,3007) Net$C_Organization
	    End if
	    Return
	End if
		

1001	Format(1X,'Number users: ',I5,', Maximum storage: ',I5)
1002	Format(1X,'(',I5,') Username: ',A,' Personal name: ',A)
2001	Format(1X,'Number terminals: ',I5,', Maximum storage: ',I5)
2002	Format(1X,'(',I5,') Terminal: ',A,' Location: ',A,
	1	' Type: ',A)
3001	Format(1X,'Number hosts: ',I5,', Maximum storage: ',I5)
3002	Format(1X,'(',I5,') Host: ',A,' Type: ',A)
3008	Format(1x,'        Link: ',A,' Route: ',A)
3003	Format(1X,'(',I5,') Network: ',A,' Type: ',A)
3004	Format(1X,'Number Networks: ',I5,', Maximum storage: ',I5)
3005	Format(1X,A,' not defined.')
3006	Format(1X,'Local Host name: ',A)
3007	Format(1X,'Organization name: ',A)
3010	Format(1X,'Router Host: ',A,' Type: ',A,' Route: ',A)
4001	Format(1X,'Entry not found.')
5001	Format(1X,'Active users: ',I5,', Maximum users: ',I5,', ',I3,
	1 '% free')
5002	Format(1X,'Active terms: ',I5,', Maximum terms: ',I5,', ',I3,
	1 '% free')
5003	Format(1X,'Active hosts: ',I5,', Maximum hosts: ',I5,', ',I3,
	1 '% free')
5004	Format(1X,'Active nets:  ',I5,', Maximum nets:  ',I5,', ',I3,
	1 '% free')
	End

c------------------------------------------------------------------------------
	Integer Function Shr_Clear

	Include		'Fingercom.for'

	Integer		Cli$Present
	Integer		Cli$Get_Value

	Shr_Clear = 1

	If ( Cli$Present('USER') ) then
	    Usr$I_Last = 0
	    Usr$I_Max = max_users
	End if
	If ( Cli$Present('TERMINAL') ) then
	    Loc$I_Last = 0
	    Loc$I_Max = max_terms
	End if
	If ( Cli$Present('HOST') ) then
	    Host$I_Last = 0
	    Host$I_Max = max_hosts
	End if
	If ( Cli$Present('NETWORK') ) then
	    Net$I_Last = 0
	    Net$I_Max = max_networks
	End if
	If ( Cli$Present('ROUTER_HOST') ) then
	    Net$C_Router_Host = ' '
	End if
	If ( Cli$Present('LOCAL_HOST') ) then
	    Net$C_Local_Host_Name = ' '
	End if
	If ( Cli$Present('ORGANIZATION') ) then
	    Net$C_Organization = ' '
	End if
	If ( Cli$Present('ALL') ) then
	    Usr$I_Last = 0
	    Usr$I_Max = max_users
	    Loc$I_Last = 0
	    Loc$I_Max = max_terms
	    Host$I_Last = 0
	    Host$I_Max = max_hosts
	    Net$I_Last = 0
	    Net$C_Router_Host = ' '
	    Net$I_Max = max_networks
	    Net$C_Local_Host_Name = ' '
	    Net$C_Organization = ' '
	End if

	Return

	End

c------------------------------------------------------------------------------
	Integer Function Shr_Help

	Integer		Lbr$Output_Help
	Character	Line*132
	Character	HelpLibrary*18 /'SYS$HELP:FINGMAINT'/
	External	Lib$Get_Input, Lib$Put_Output

	Call Cli$Get_Value('HELP_LINE',Line)
c  call help librarian
	Shr_Help = Lbr$Output_Help(Lib$Put_Output,,Line,
	1	HelpLibrary,,Lib$Get_Input)

	Return

	End

c------------------------------------------------------------------------------
	Integer Function Shr_Exit
c
	shr_exit=1
	Call Exit

	End

c------------------------------------------------------------------------------
	Integer Function Signal_Handler(
	1	SignalVector,MechanismVector)

	Integer		SignalVector(8),	MechanismVector(5)
	Integer		SS$_Status,	SS$_Normal/1/
	Integer		MsgLen
	Character	Msg*132

	Signal_Handler = SS$_Normal	! Continue after condition
	SS$_Status = SignalVector(2)
	If ( SS$_Status .eq. SS$_Normal ) Return

	Call Sys$Getmsg(%Val(SS$_Status),Msglen,Msg,%VAL(1),)
	Call Lib$Put_Output(Msg(:Msglen))

	Return

1001	Format(1X,A)
	End
