quarta-feira, 31 de agosto de 2011

Listar usuários conectados 2

_global usuarios_conectados <<
_proc(_optional write?)
    ## This proc lists out the users (username@machine_name)
    ## connected to smallworld at that instance.
    ##
    ## The argument write? is defaulted to _true. If given false, it doesn't
    ## write at the magik prompt.
    ##
    ## Anycase it returns a simple_vector of user names.
    write? << write?.default(_true)
    mv << message_handler.view
    fl << mv.files.an_element()
    _local log_fl << fl.current_logical_file
    us << log_fl.users
    us << us.map(_proc (id)
               _import log_fl

               >> log_fl.user_details(id)
             _endproc)
    _if write?
    _then

        gr << equality_hash_table.new()
        guser << equality_hash_table.new()
        _for u _over us.fast_elements()
        _loop
            pos_arroba << u.index_of_seq("@")

            user << u.subseq(1,pos_arroba-1)
            machine << u.subseq(pos_arroba+1,u.size-pos_arroba)

            _if gr[machine.as_symbol()]_is _unset
            _then
                gr[machine.as_symbol()] << 1
            _else
                gr[machine.as_symbol()] +<< 1
            _endif

            _if guser[user.as_symbol()]_is _unset
            _then
                guser[user.as_symbol()] << 1
            _else
                guser[user.as_symbol()] +<< 1
            _endif

            write(u," -> ",user," - ",machine)
        _endloop

        _for i,k _over gr.keys_and_elements()
        _loop
            write(i," count: ",k)
        _endloop

        _for i,k _over guser.keys_and_elements()
        _loop
            write(i," count: ",k)
        _endloop
    _endif
    >> us
_endproc
$

Nenhum comentário :

Postar um comentário

Related Posts Plugin for WordPress, Blogger...