C..FingMaint.For			Maintain  finger shared commons
C..					R. Garland / C.U.Chemistry / 7-Oct-1983

	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

	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(.true.)
	    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.for'

	Byte		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*25	Owner, PersonalName
	Character	Terminal*8, Location*25, TTType*25
	Character	Host*12, Type*1, Link*12, Route*72
	Character	Network*20, Local_Host*12, 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 200
		End do
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 ) Return
	    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 ) Return
	    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 ) Return
	    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 ) Return
	    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
	End if

1000	Format(<UAF$K_Length>A1)

	End

c------------------------------------------------------------------------------
	Integer Function Shr_Show

	Include		'Fingercom.for'

	Character	Username*12, Terminal*8, Host*12
	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),
	2		Host$C_Link(ii),
	3		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),
	2		Host$C_Link(ii),
	3		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('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: ',I3,', Maximum storage: ',I3)
1002	Format(1X,'(',I3,') Username: ',A,' Personal name: ',A)
2001	Format(1X,'Number terminals: ',I3,', Maximum storage: ',I3)
2002	Format(1X,'(',I3,') Terminal: ',A,' Location: ',A,
	1	' Type: ',A)
3001	Format(1X,'Number hosts: ',I3,', Maximum storage: ',I3)
3002	Format(1X,'(',I3,') Host: ',A,' Type: ',A,
	1	' Link: ',A,' Route: ',A)
3003	Format(1X,'(',I3,') Network: ',A,' Type: ',A)
3004	Format(1X,'Number Networks: ',I3,', Maximum storage: ',I3)
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.')
	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

	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
