board1.0.muf.gz

snippets · 3.0 KB · 2010-03-30

Note board program in MUF (board.muf 1.0).

Download   « Back to the snippets list

@prog board.muf

1 999 d
1 i

(********************
$Id: board.muf,v 1.1 1991/08/23 19:47:05 claudius Exp claudius $
To send: /lib/cpp -P < board.muf > board.muf.new then send board.muf.new
	board.muf - by claudius@zeus.calpoly.edu
	has various facilities for a bullitin board system.
	the commands:
		help		- get help
		list		- list all the titles, and who submitted them
		read {n}	- read item n
		[you have to have authorization to use these commands]
		add		- add a new item
		delete {n}	- delete item n
	The messages are stored on the action, so that you may have multiple
	message boards from the same object and same program.

	The property "_authorized" contains a space-seperated list of authorized
	users [ones that can use add and delete].

	The actual board messages are stored on the action in this format:
	property	use
	--------	---
	_headerN	holds the subject of the item
	_fromN		holds the dbref # of the poster
	_body-N-X	line X of item #N...starting with 1
 *** $Log: board.muf,v $
 *** Revision 1.1  1991/08/23  19:47:05  claudius
 *** Initial revision
 ***
********************)

#define ME	"me" match
#define TRIGGER	trigger @
#define NOTHING	#-1
#define MATCH_MANY #-2
#define AUTHORIZED "_authorized"
#define HEADER "_header"
#define BODY "_body"
#define FROM "_from"

(* define if you have the echo facility also written by
   claudius@zeus.calpoly.edu *)
(* #define ECHOES *)
#ifdef ECHOES
#define ECHO "_pecho"
#define ECHONAME "_pecho_name"
#define ECHOVERBOSE "_echo_verbose"

(* find termination of an echo destination *)
: echofollow ( d -- d )
	dup ok? if ( . )
		dup exit? if ( . )
			getlink ( . )
			echofollow ( . )
		then ( . )
		dup room? not ( s i d i )
		over player? not and ( . )
		if ( s i d )
			location ( . )
			echofollow ( . )
		then ( . )
	then ( . )
;

(* notify other rooms if _pecho properties exist. *)
: notify_echo_recurse ( s d i -- )
	over over ( s d i d i )
	ECHO swap intostr strcat getpropstr ( s d i s )
	dup strlen if ( . )
		atoi dbref ( s d i d )
		dup ok? if ( . )
			ME ECHOVERBOSE getpropstr ( s d i d s )
			strlen if ( s d i d )
				"Echo #" 3 pick intostr strcat ( s d i d s )
				":" strcat ( . )
				over name strcat ME swap notify ( s d i d )
			then ( . )

			echofollow ( . )
			4 pick ( s d i d s )
			4 pick ECHONAME ( s d i d s d s )
			5 pick intostr strcat ( . )
			getpropstr ( s d i d s s )
			dup strlen not if ( . )
				pop 4 pick ECHONAME getpropstr ( . )
				dup strlen not if ( . )
					pop ( s d i d s )
				else ( s d i s d s )
					" (" swap strcat ")" strcat ( . )
					strcat ( s d i d s )
				then ( . )
			else ( s d i d s s )
				" (" swap strcat ")" strcat strcat ( s d i d s )
			then ( . )

			over player? if ( . )
				notify ( s d i )
			else ( s d i d s )
				NOTHING swap ( s d i d d s )
				notify_except ( s d i )
			then ( . )
		else ( s d i s d )
			pop pop ( s d i )
		then ( . )
		1 + ( . )
		notify_echo_recurse ( )
	else
		pop pop pop pop
	then
;

: notify_echo ( d d s -- )
	3 pick 3 pick 3 pick notify_except
	-3 rotate pop 1 notify_echo_recurse
;
#endif (* ECHOES *)

: explode_eat ( s ... i -- )
	dup 0 > if
		1 - ( s ... i-1 )
		swap ( s ... i-1 s )
		pop ( s ... i-1 )
		explode_eat
	else
		pop
	then
;

: board_validate_list ( s1 ... sN N -- i )
(********************
 ** subroutine
********************)
	dup if ( s1 ... sN N )
		1 - ( s1 ... sN N-1 )
		swap ( s1 ...sN-1 N-1 sN )
		ME name stringcmp not if ( s1 ... sN-1 N-1 )
			board_validate_list ( i )
			pop ( )
			1 ( i )
		else ( s1 ... sN-1 N-1 )
			board_validate_list ( i )
		then ( i )
	then ( i )
;

: board_validate ( -- i )
(********************
 ** validates me 
 ** Returns: 1 if valid
********************)
	ME TRIGGER owner dbcmp ( i )
	TRIGGER AUTHORIZED getpropstr " " explode ( i s1 ... sN N )
	board_validate_list or ( i )
;

: mlrecurse ( i s -- )
(********************
 ** subroutine
********************)
	over intostr ( i i s s )
	over swap ( i i s s s )
	strcat ( i i s s )
	TRIGGER swap ( i i s d s )
	getpropstr ( i i s s )
	dup strlen 0 > if ( . )
		4 pick if ( . )
			3 pick intostr "> " strcat swap strcat ( . )
		then ( . )
		ME swap notify ( i i s )
		swap 1 + swap ( . )
		mlrecurse ( )
	else ( i i s s )
		pop pop pop pop ( )
	then ( . )
;

: mlnotify ( i s -- )
(********************
 ** outputs a multi-line property list
 ** Requires: whether or not to list the # before the line
 **           name of list of properties
********************)
	1 swap ( i i s )
	mlrecurse ( )
;

: board_help ( -- )
(********************
 ** display help information
********************)
	ME TRIGGER name " HELP" strcat notify ( )
	ME TRIGGER name " help     - this" strcat notify ( . )
	ME TRIGGER name " list     - list items" strcat notify ( . )
	ME TRIGGER name " read N   - read item N" strcat notify ( . )
	ME TRIGGER name " add      - add new item *" strcat notify ( . )
	ME TRIGGER name " delete N - delete item N *" strcat notify ( . )
	ME TRIGGER name ( d s )
	"* - these commands you have to be authorized to use." strcat ( . )
	notify ( )
;

: board_title ( i -- )
(********************
 ** notify user of the title of a message
********************)
	TRIGGER over FROM swap intostr strcat getpropstr ( i s )
	atoi dbref ( i d )
	dup ok? if ( . )
		name ( i s )
	else ( i d )
		pop "NOBODY" ( i s )
	then ( . )
	"(" swap strcat ") " strcat ( . )
	over intostr "> " strcat swap strcat ( . )
	swap TRIGGER swap HEADER swap intostr strcat getpropstr ( i s s )
	strcat ( i s ) 
;

: board_list_recurse ( i -- )
(********************
 ** subroutine
********************)
	TRIGGER over FROM swap intostr strcat getpropstr ( i s )
	strlen if ( i )
		dup board_title ( i s )
		ME swap notify ( i )
		1 + ( . )
		board_list_recurse ( )
	else ( i )
		pop ( )
	then ( . )
;

: board_list ( s -- s )
(********************
 ** list headers
********************)
	ME location ME dup name " looks at the " strcat
	TRIGGER location name strcat " board." strcat
#ifdef ECHOES
	notify_echo
#else (* ECHOES *)
	notify_except
#endif (* ECHOES *)
	1 board_list_recurse ( s )
;

: board_read ( s -- )
(********************
 ** read an item
 ** Requires: a string [format "read N"]
********************)
	dup " " explode ( s1 ... sN N )
	dup 2 = if ( s1 s2 2 )
		pop ( s s )
		pop ( s )
		atoi ( i )
		dup FROM swap ( i s i )
		intostr strcat ( i s )
		TRIGGER swap getpropstr ( . )
		strlen if ( i )
			dup board_title ( i s )
			ME location over ME swap ( i s d d s )
			ME name " is reading:" ( i s d d s s s )
			strcat swap strcat ( i s d d s )
			" (on the " strcat ( . )
			trigger @ location name strcat ( . )
			" board)" strcat ( . )
#ifdef ECHOES
			notify_echo ( i s )
#else (* ECHOES *)
			notify_except ( i s )
#endif (* ECHOES *)
			ME swap notify ( i )
			BODY swap intostr strcat "-" strcat ( s )
			0 swap mlnotify ( )
		else ( i )
			pop ( )
		then ( . )
	else ( s1 ... sN N )
		ME "Error:" TRIGGER name strcat ( s1 ... sN N d s )
		" read {#}" strcat notify ( s1 ... sN N )
		explode_eat ( )
	then ( . )
;

: board_findlast ( i -- i )
(********************
 ** finds last item on board
 ** Requires: 1
 ** Returns: last item
********************)
	FROM over intostr strcat ( i s )
	TRIGGER swap ( i d s )
	getpropstr strlen if ( i )
		1 + ( . )
		board_findlast ( . )
	then ( . )
;

: board_addread ( i s -- )
(********************
 ** subroutine
********************)
	over over swap ( i s s i )
	intostr strcat ( i s s )
	TRIGGER swap ( i s d s )
	read ( i s d s s )
	dup "." strcmp 0 = not if ( i s d s s )
		1 addprop ( i s )
		swap 1 + swap ( i s )
		board_addread ( )
	else
		pop pop pop pop pop ( )
	then
;

: board_add ( s -- s )
(********************
 ** adds a new entry onto the board
********************)
	board_validate if ( s )
		1 board_findlast ( s i )
		TRIGGER over FROM swap intostr strcat ( s i d s )
		ME int intostr 1 addprop ( s i )
		ME "Enter subject:" notify ( . )
		read ( s i s )
		over HEADER swap intostr strcat swap ( s i s s )
		TRIGGER rot rot ( s i d s s )
		1 addprop ( s i )
		ME ( s i d )
		"Enter message, ending with a . on it's own line.:" ( s i d s )
		notify ( s i )
		BODY swap intostr ( s s s )
		strcat "-" strcat ( s s )
		1 swap ( s i s )
		board_addread ( s )
	else ( . )
		ME "Sorry, you don't have permission to add items." ( s d s )
		notify ( s )
	then ( . )
;

: board_dmclear ( i i -- )
(********************
 ** subroutine
********************)
	over intostr over intostr ( i i s s )
	"-" swap strcat strcat BODY swap strcat dup ( . )
	TRIGGER swap getpropstr ( . )
	strlen if ( i i s )
		TRIGGER swap remove_prop ( i i )
		1 + board_dmclear ( )
	else ( i i s )
		pop pop pop ( )
	then ( . )
;

: board_dmrecurse ( i i -- )
(********************
 ** subroutine
********************)
	over over ( i i i i )
	over intostr over intostr ( i i i i s s )
	"-" swap strcat strcat ( i i i i s )
	BODY swap strcat ( i i i i s )
	swap rot ( i i s i i )
	1 + intostr "-" strcat ( i i s i s )
	swap intostr strcat ( i i s s )
	BODY swap strcat ( i i s s )
	TRIGGER swap getpropstr ( i i s s )
	dup strlen if ( i i s s )
		TRIGGER rot rot ( i i d s s )
		1 addprop ( i i )
		1 + ( i i )
		board_dmrecurse ( )
	else ( i i s s )
		pop pop ( i i )
		board_dmclear ( )
	then ( )
;

: board_delete_move ( i -- )
(********************
 ** subroutine
********************)
	dup HEADER swap ( i s i )
	1 + intostr strcat ( i s )
	TRIGGER swap getpropstr ( . )
	dup strlen if ( . )
		over HEADER swap intostr strcat ( i s s )
		TRIGGER rot rot swap 1 ( i d s s i )
		addprop ( i )
		TRIGGER over 1 + FROM swap intostr strcat ( i d s )
		getpropstr ( i s )
		over FROM swap intostr strcat swap ( i s s )
		1 TRIGGER -4 rotate ( i d s s i )
		addprop ( i )
		dup 1 ( i i i )
		board_dmclear ( i )
		dup 1 ( i i i )
		board_dmrecurse ( i )
		1 + ( . )
		board_delete_move ( )
	else ( i s )
		pop ( i )
		HEADER over intostr strcat TRIGGER swap remove_prop ( . )
		FROM over intostr strcat TRIGGER swap remove_prop ( . )
		1 board_dmclear ( )
	then ( )
;

: board_delete ( s -- s )
(********************
 ** deletes a board item
 ** Requires:the arguement, preferably in the form "action delete N"
 ** Returns:same
********************)
	board_validate if ( s )
		dup " " explode ( s s1 ... sN N )
		dup 2 = if ( s s1 s2 2 )
			pop pop ( s s )
			atoi ( s i )
			dup FROM swap ( s i s i )
			intostr strcat ( s i s )
			TRIGGER swap ( s i d s )
			getpropstr ( s i s )
			strlen if ( s i )
				dup board_delete_move ( s i )
				ME swap "Item #" swap intostr strcat ( s d s )
				" has been deleted." strcat notify ( s )
			else ( s i )
				ME swap "Item #" swap intostr strcat ( s d s )
				" doesn't exist." strcat notify ( s )
			then ( . )
		else ( s s1 ... sN N )
			explode_eat ( s )
			ME "Error:" TRIGGER name strcat ( s d s )
				" delete {item #}" strcat notify ( s )
		then ( s )
	else ( s )
		ME ( s d )
		"Sorry, you don't have permission to delete items." notify ( s )
	then ( s )
;

: board_command ( s -- )
(********************
 ** this is the main function, nothin' fancy
********************)
	dup "list" strcmp not if ( s )
		board_list ( . )
	else dup "read" 4 strncmp not if ( . )
		board_read ( . )
	else dup "add" strcmp not if ( . )
		board_add ( . )
	else dup "delete" 6 strncmp not if ( . )
		board_delete ( . )
	else
		board_help ( . )
	then ( delete )
	then ( add )
	then ( read )
	then ( list )
	pop
;
.
c
q

Site Stats

Snippets: 1791
Codebases: 571