9front - general discussion about 9front
 help / color / mirror / Atom feed
* [patch] format messages for ircrc
@ 2020-04-21  8:13 Romano
  2020-05-05  3:08 ` Romano
  0 siblings, 1 reply; 5+ messages in thread
From: Romano @ 2020-04-21  8:13 UTC (permalink / raw)
  To: 9front

On #cat-v earlier, some of my messages were being chopped off. There was a discussion about possible ways to correct it using fmt. This patch adds a default message length of 100 and processes messages through fmt.


diff -r f9f922fd127d rc/bin/ircrc
--- a/rc/bin/ircrc	Mon Apr 20 00:08:35 2020 +0200
+++ b/rc/bin/ircrc	Tue Apr 21 01:03:56 2020 -0700
@@ -11,6 +11,7 @@
 pass=()
 tls=0
 serverpass=()
+msglen=100
 
 fn sighup {
 	exit 'hang up'
@@ -49,70 +50,100 @@
 			echo  QUIT : Leaving... > $netdir/data
 			exit
 		}
-		msg=()
-		out=()
-		switch ($cmd(1)) {
-		case /!
-			eval `{mshift $cmd} | while(rc=`{read})echo 'PRIVMSG '^$target^' :' $rc | tee $netdir/data
-		case /M
-			msg = (MODE `{mshift $cmd})
-		case /N
+		do_cmd
+	}
+}
+
+fn do_cmd {
+	msg=()
+	out=()
+	switch ($cmd(1)) {
+	case /!
+		eval `{mshift $cmd} | while(rc=`{read})echo 'PRIVMSG '^$target^' :' $rc | tee $netdir/data
+	case /M
+		msg = (MODE `{mshift $cmd})
+	case /N
+		cmd = `{mshift $cmd}
+		if (! ~ $#cmd 0)
+			msg = (NOTICE $cmd(1) : `{mshift $cmd})
+		case /T
+		msg = (TOPIC `{mshift $cmd})
+	case /W
+		msg = (WHOIS `{mshift $cmd})
+	case /a
+		msg =  (AWAY : `{mshift $cmd})
+	case /j
+		if (~ $#cmd 2) {
+			target=$cmd(2)
+			title
+			msg = (JOIN `{mshift $cmd})
+			if(~ $target *,*)
+				target = `{echo $target | awk -F',' '{print $NF}'}
+		}
+	case /l
+		msg = (LIST `{mshift $cmd})
+	case /m
+		cmd = `{mshift $cmd}
+		if (! ~ $#cmd 0) {
+			to = $cmd(1)
 			cmd = `{mshift $cmd}
-			if (! ~ $#cmd 0)
-				msg = (NOTICE $cmd(1) : `{mshift $cmd})
-		case /T
-			msg = (TOPIC `{mshift $cmd})
-		case /W
-			msg = (WHOIS `{mshift $cmd})
-		case /a
-			msg =  (AWAY : `{mshift $cmd})
-		case /j
-			if (~ $#cmd 2) {
-				target=$cmd(2)
-				title
-				msg = (JOIN `{mshift $cmd})
-				if(~ $target *,*)
-					target = `{echo $target | awk -F',' '{print $NF}'}
+			out =  '('^$to^')	⇐	'^$"cmd
+			msg = 'PRIVMSG '^$to^' :'^$"cmd
+		}
+	case /n
+		nick = `{mshift $cmd}
+		msg =  (NICK $nick)
+		case /p
+		cmd = `{mshift $cmd}
+		if (! ~ $#cmd 0)
+			msg = (PART $cmd(1) : `{mshift $cmd})
+	case /q
+		msg =  `{mshift $cmd}
+	case /t
+		target = `{mshift $cmd}
+		title
+	case /u
+		msg = (USERS `{mshift $cmd})
+	case /w
+		msg = (WHO `{mshift $cmd})
+	case /x
+		echo  QUIT : Leaving... > $netdir/data
+		exit
+	case /*
+		echo unknown command
+	case *
+		send_msg
+	}
+	if (! ~ $#msg 0)
+		echo $msg > $netdir/data
+	if (! ~ $#out 0)
+		echo `{etime}^' '^$out
+}
+
+fn send_msg {
+	if (test `{echo -n $cmd | wc -c} -gt $msglen) {
+		ifs_orig=$ifs
+		ifs='
+'
+		msgs=`{echo -n $cmd | fmt -l $msglen}
+		ifs=$ifs_orig
+		for (cmd in $msgs) {
+			if (~ $#msg 0 ) {
+				msg=('PRIVMSG '^$target^' :'^$"cmd)
+				out=('('^$target^')	⇐	'^$"cmd)
 			}
-		case /l
-			msg = (LIST `{mshift $cmd})
-		case /m
-			cmd = `{mshift $cmd}
-			if (! ~ $#cmd 0) {
-				to = $cmd(1)
-				cmd = `{mshift $cmd}
-				out =  '('^$to^')	⇐	'^$"cmd
-				msg = 'PRIVMSG '^$to^' :'^$"cmd
+			if not {
+				msg=($msg^'
+PRIVMSG '^$target^' :'^$"cmd)
+				out=($out^'
+('^$target^')	⇐	'^$"cmd)
 			}
-		case /n
-			nick = `{mshift $cmd}
-			msg =  (NICK $nick)
-		case /p
-			cmd = `{mshift $cmd}
-			if (! ~ $#cmd 0)
-				msg = (PART $cmd(1) : `{mshift $cmd})
-		case /q
-			msg =  `{mshift $cmd}
-		case /t
-			target = `{mshift $cmd}
-			title
-		case /u
-			msg = (USERS `{mshift $cmd})
-		case /w
-			msg = (WHO `{mshift $cmd})
-		case /x
-			echo  QUIT : Leaving... > $netdir/data
-			exit
-		case /*
-			echo unknown command
-		case *
-			msg = 'PRIVMSG '^$target^' :'^$"cmd
-			out = '('^$target^')	⇐	'^$"cmd
 		}
-		if (! ~ $#msg 0)
-			echo $msg > $netdir/data
-		if (! ~ $#out 0)
-			echo `{etime}^' '^$out
+		msgs=()
+	}
+	if not {
+		msg = 'PRIVMSG '^$target^' :'^$"cmd
+		out = '('^$target^')	⇐	'^$"cmd
 	}
 }
 
@@ -211,10 +242,13 @@
 	case -t
 		target=$2
 		shift
+	case -l
+		msglen=$2
+		shift
 	case -T
 		tls=1
 	case -*
-		echo 'usage: ircrc  [-p port] [-P server password] [-r realname] [-t target] [-n nick] [-T] [server]' >[1=2]
+		echo 'usage: ircrc  [-p port] [-P server password] [-r realname] [-t target] [-n nick] [-l message format length] [-T] [server]' >[1=2]
 		exit 'usage'	
 	}
 	shift
diff -r f9f922fd127d sys/man/1/ircrc
--- a/sys/man/1/ircrc	Mon Apr 20 00:08:35 2020 +0200
+++ b/sys/man/1/ircrc	Tue Apr 21 01:03:56 2020 -0700
@@ -23,6 +23,9 @@
 .B -n
 .I nick
 ]
+.B -l
+.I message format length
+]
 [
 .B -T
 ] [
@@ -70,6 +73,10 @@
 Change the default nickname
 .RB ( $user ).
 .TP
+.BI -l " length
+Change the message formatting length, piping the messages sent through fmt with the given length. The maximum broken UTF code length is around 510: messages may chopped if set higher.
+.RB ( 100 ).
+.TP
 .BI -T
 .br
 Use tls through


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [patch] format messages for ircrc
  2020-04-21  8:13 [patch] format messages for ircrc Romano
@ 2020-05-05  3:08 ` Romano
  2020-05-05  3:38   ` [9front] " ori
  0 siblings, 1 reply; 5+ messages in thread
From: Romano @ 2020-05-05  3:08 UTC (permalink / raw)
  To: 9front

Ping. Perhaps the -l option is too much. The whitespace below doesn't seem preserved, so I can post to okturing if needed.


On April 21, 2020 8:13:49 AM UTC, Romano <unobe@cpan.org> wrote:
>On #cat-v earlier, some of my messages were being chopped off. There
>was a discussion about possible ways to correct it using fmt. This
>patch adds a default message length of 100 and processes messages
>through fmt.
>
>
>diff -r f9f922fd127d rc/bin/ircrc
>--- a/rc/bin/ircrc	Mon Apr 20 00:08:35 2020 +0200
>+++ b/rc/bin/ircrc	Tue Apr 21 01:03:56 2020 -0700
>@@ -11,6 +11,7 @@
> pass=()
> tls=0
> serverpass=()
>+msglen=100
> 
> fn sighup {
> 	exit 'hang up'
>@@ -49,70 +50,100 @@
> 			echo  QUIT : Leaving... > $netdir/data
> 			exit
> 		}
>-		msg=()
>-		out=()
>-		switch ($cmd(1)) {
>-		case /!
>-			eval `{mshift $cmd} | while(rc=`{read})echo 'PRIVMSG '^$target^' :'
>$rc | tee $netdir/data
>-		case /M
>-			msg = (MODE `{mshift $cmd})
>-		case /N
>+		do_cmd
>+	}
>+}
>+
>+fn do_cmd {
>+	msg=()
>+	out=()
>+	switch ($cmd(1)) {
>+	case /!
>+		eval `{mshift $cmd} | while(rc=`{read})echo 'PRIVMSG '^$target^' :'
>$rc | tee $netdir/data
>+	case /M
>+		msg = (MODE `{mshift $cmd})
>+	case /N
>+		cmd = `{mshift $cmd}
>+		if (! ~ $#cmd 0)
>+			msg = (NOTICE $cmd(1) : `{mshift $cmd})
>+		case /T
>+		msg = (TOPIC `{mshift $cmd})
>+	case /W
>+		msg = (WHOIS `{mshift $cmd})
>+	case /a
>+		msg =  (AWAY : `{mshift $cmd})
>+	case /j
>+		if (~ $#cmd 2) {
>+			target=$cmd(2)
>+			title
>+			msg = (JOIN `{mshift $cmd})
>+			if(~ $target *,*)
>+				target = `{echo $target | awk -F',' '{print $NF}'}
>+		}
>+	case /l
>+		msg = (LIST `{mshift $cmd})
>+	case /m
>+		cmd = `{mshift $cmd}
>+		if (! ~ $#cmd 0) {
>+			to = $cmd(1)
> 			cmd = `{mshift $cmd}
>-			if (! ~ $#cmd 0)
>-				msg = (NOTICE $cmd(1) : `{mshift $cmd})
>-		case /T
>-			msg = (TOPIC `{mshift $cmd})
>-		case /W
>-			msg = (WHOIS `{mshift $cmd})
>-		case /a
>-			msg =  (AWAY : `{mshift $cmd})
>-		case /j
>-			if (~ $#cmd 2) {
>-				target=$cmd(2)
>-				title
>-				msg = (JOIN `{mshift $cmd})
>-				if(~ $target *,*)
>-					target = `{echo $target | awk -F',' '{print $NF}'}
>+			out =  '('^$to^')	⇐	'^$"cmd
>+			msg = 'PRIVMSG '^$to^' :'^$"cmd
>+		}
>+	case /n
>+		nick = `{mshift $cmd}
>+		msg =  (NICK $nick)
>+		case /p
>+		cmd = `{mshift $cmd}
>+		if (! ~ $#cmd 0)
>+			msg = (PART $cmd(1) : `{mshift $cmd})
>+	case /q
>+		msg =  `{mshift $cmd}
>+	case /t
>+		target = `{mshift $cmd}
>+		title
>+	case /u
>+		msg = (USERS `{mshift $cmd})
>+	case /w
>+		msg = (WHO `{mshift $cmd})
>+	case /x
>+		echo  QUIT : Leaving... > $netdir/data
>+		exit
>+	case /*
>+		echo unknown command
>+	case *
>+		send_msg
>+	}
>+	if (! ~ $#msg 0)
>+		echo $msg > $netdir/data
>+	if (! ~ $#out 0)
>+		echo `{etime}^' '^$out
>+}
>+
>+fn send_msg {
>+	if (test `{echo -n $cmd | wc -c} -gt $msglen) {
>+		ifs_orig=$ifs
>+		ifs='
>+'
>+		msgs=`{echo -n $cmd | fmt -l $msglen}
>+		ifs=$ifs_orig
>+		for (cmd in $msgs) {
>+			if (~ $#msg 0 ) {
>+				msg=('PRIVMSG '^$target^' :'^$"cmd)
>+				out=('('^$target^')	⇐	'^$"cmd)
> 			}
>-		case /l
>-			msg = (LIST `{mshift $cmd})
>-		case /m
>-			cmd = `{mshift $cmd}
>-			if (! ~ $#cmd 0) {
>-				to = $cmd(1)
>-				cmd = `{mshift $cmd}
>-				out =  '('^$to^')	⇐	'^$"cmd
>-				msg = 'PRIVMSG '^$to^' :'^$"cmd
>+			if not {
>+				msg=($msg^'
>+PRIVMSG '^$target^' :'^$"cmd)
>+				out=($out^'
>+('^$target^')	⇐	'^$"cmd)
> 			}
>-		case /n
>-			nick = `{mshift $cmd}
>-			msg =  (NICK $nick)
>-		case /p
>-			cmd = `{mshift $cmd}
>-			if (! ~ $#cmd 0)
>-				msg = (PART $cmd(1) : `{mshift $cmd})
>-		case /q
>-			msg =  `{mshift $cmd}
>-		case /t
>-			target = `{mshift $cmd}
>-			title
>-		case /u
>-			msg = (USERS `{mshift $cmd})
>-		case /w
>-			msg = (WHO `{mshift $cmd})
>-		case /x
>-			echo  QUIT : Leaving... > $netdir/data
>-			exit
>-		case /*
>-			echo unknown command
>-		case *
>-			msg = 'PRIVMSG '^$target^' :'^$"cmd
>-			out = '('^$target^')	⇐	'^$"cmd
> 		}
>-		if (! ~ $#msg 0)
>-			echo $msg > $netdir/data
>-		if (! ~ $#out 0)
>-			echo `{etime}^' '^$out
>+		msgs=()
>+	}
>+	if not {
>+		msg = 'PRIVMSG '^$target^' :'^$"cmd
>+		out = '('^$target^')	⇐	'^$"cmd
> 	}
> }
> 
>@@ -211,10 +242,13 @@
> 	case -t
> 		target=$2
> 		shift
>+	case -l
>+		msglen=$2
>+		shift
> 	case -T
> 		tls=1
> 	case -*
>-		echo 'usage: ircrc  [-p port] [-P server password] [-r realname] [-t
>target] [-n nick] [-T] [server]' >[1=2]
>+		echo 'usage: ircrc  [-p port] [-P server password] [-r realname] [-t
>target] [-n nick] [-l message format length] [-T] [server]' >[1=2]
> 		exit 'usage'	
> 	}
> 	shift
>diff -r f9f922fd127d sys/man/1/ircrc
>--- a/sys/man/1/ircrc	Mon Apr 20 00:08:35 2020 +0200
>+++ b/sys/man/1/ircrc	Tue Apr 21 01:03:56 2020 -0700
>@@ -23,6 +23,9 @@
> .B -n
> .I nick
> ]
>+.B -l
>+.I message format length
>+]
> [
> .B -T
> ] [
>@@ -70,6 +73,10 @@
> Change the default nickname
> .RB ( $user ).
> .TP
>+.BI -l " length
>+Change the message formatting length, piping the messages sent through
>fmt with the given length. The maximum broken UTF code length is around
>510: messages may chopped if set higher.
>+.RB ( 100 ).
>+.TP
> .BI -T
> .br
> Use tls through


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [9front] Re: [patch] format messages for ircrc
  2020-05-05  3:08 ` Romano
@ 2020-05-05  3:38   ` ori
  2020-05-05  7:43     ` Romano
  2020-06-13  0:09     ` Romano
  0 siblings, 2 replies; 5+ messages in thread
From: ori @ 2020-05-05  3:38 UTC (permalink / raw)
  To: unobe, 9front

> Ping. Perhaps the -l option is too much.

Agreed -- I'd compute it. That would probably look something like:

	linelen = `{hoc -e '510 - '`{echo 'PRIVMSG '^$target^' :' | wc -c }}

Another small bit of nitpicking (I'd be ok with committing it as is, but
I may as well register my preferences:

> +				msg=($msg^'
> +PRIVMSG '^$target^' :'^$"cmd)


I'd do this somewhere near the start of the program:

	nl='
	'

And construct strings using it like this:

	msg=($msg^$nl^'PRIVMSG '^$target^' :'^$"cmd)

Other than that, this looks fine to me.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [9front] Re: [patch] format messages for ircrc
  2020-05-05  3:38   ` [9front] " ori
@ 2020-05-05  7:43     ` Romano
  2020-06-13  0:09     ` Romano
  1 sibling, 0 replies; 5+ messages in thread
From: Romano @ 2020-05-05  7:43 UTC (permalink / raw)
  To: 9front

Thanks Ori!

I've updated the patch and tested it: see below (and it's also at http://okturing.com/src/8458/body). Note that 512 is the # of characters including the hostname (63 chars), command, the actual text message, and the final CR&LF required by the protocol. So the # of characters allowed per message text is 447, which I mention in the man page.

On Mon, May 4, 2020, at 8:38 PM, ori@eigenstate.org wrote:
> > Ping. Perhaps the -l option is too much.
> 
> Agreed -- I'd compute it. That would probably look something like:
> 
> 	linelen = `{hoc -e '510 - '`{echo 'PRIVMSG '^$target^' :' | wc -c }}
> 
> Another small bit of nitpicking (I'd be ok with committing it as is, but
> I may as well register my preferences:
> 
> > +				msg=($msg^'
> > +PRIVMSG '^$target^' :'^$"cmd)
> 
> 
> I'd do this somewhere near the start of the program:
> 
> 	nl='
> 	'
> 
> And construct strings using it like this:
> 
> 	msg=($msg^$nl^'PRIVMSG '^$target^' :'^$"cmd)
> 
> Other than that, this looks fine to me.
> 

diff -r 0ee17db5d86b rc/bin/ircrc
--- a/rc/bin/ircrc	Sat May 02 17:32:01 2020 +0200
+++ b/rc/bin/ircrc	Tue May 05 00:36:54 2020 -0700
@@ -49,71 +49,86 @@
 			echo  QUIT : Leaving... > $netdir/data
 			exit
 		}
-		msg=()
-		out=()
-		switch ($cmd(1)) {
-		case /!
-			eval `{mshift $cmd} | while(rc=`{read})echo 'PRIVMSG '^$target^' :' $rc | tee $netdir/data
-		case /M
-			msg = (MODE `{mshift $cmd})
-		case /N
+		do_cmd
+	}
+}
+
+fn do_cmd {
+	msg=()
+	out=()
+	switch ($cmd(1)) {
+	case /!
+		eval `{mshift $cmd} | while(rc=`{read})echo 'PRIVMSG '^$target^' :' $rc | tee $netdir/data
+	case /M
+		msg = (MODE `{mshift $cmd})
+	case /N
+		cmd = `{mshift $cmd}
+		if (! ~ $#cmd 0)
+			msg = (NOTICE $cmd(1) : `{mshift $cmd})
+	case /T
+		msg = (TOPIC `{mshift $cmd})
+	case /W
+		msg = (WHOIS `{mshift $cmd})
+	case /a
+		msg =  (AWAY : `{mshift $cmd})
+	case /j
+		if (~ $#cmd 2) {
+			target=$cmd(2)
+			title
+			msg = (JOIN `{mshift $cmd})
+			if(~ $target *,*)
+				target = `{echo $target | awk -F',' '{print $NF}'}
+		}
+	case /l
+		msg = (LIST `{mshift $cmd})
+	case /m
+		cmd = `{mshift $cmd}
+		if (! ~ $#cmd 0) {
+			target_orig=$target
+			target = $cmd(1)
 			cmd = `{mshift $cmd}
-			if (! ~ $#cmd 0)
-				msg = (NOTICE $cmd(1) : `{mshift $cmd})
-		case /T
-			msg = (TOPIC `{mshift $cmd})
-		case /W
-			msg = (WHOIS `{mshift $cmd})
-		case /a
-			msg =  (AWAY : `{mshift $cmd})
-		case /j
-			if (~ $#cmd 2) {
-				target=$cmd(2)
-				title
-				msg = (JOIN `{mshift $cmd})
-				if(~ $target *,*)
-					target = `{echo $target | awk -F',' '{print $NF}'}
-			}
-		case /l
-			msg = (LIST `{mshift $cmd})
-		case /m
-			cmd = `{mshift $cmd}
-			if (! ~ $#cmd 0) {
-				to = $cmd(1)
-				cmd = `{mshift $cmd}
-				out =  '('^$to^')	⇐	'^$"cmd
-				msg = 'PRIVMSG '^$to^' :'^$"cmd
-			}
-		case /n
-			nick = `{mshift $cmd}
-			msg =  (NICK $nick)
-		case /p
-			cmd = `{mshift $cmd}
-			if (! ~ $#cmd 0)
-				msg = (PART $cmd(1) : `{mshift $cmd})
-		case /q
-			msg =  `{mshift $cmd}
-		case /t
-			target = `{mshift $cmd}
-			title
-		case /u
-			msg = (USERS `{mshift $cmd})
-		case /w
-			msg = (WHO `{mshift $cmd})
-		case /x
-			echo  QUIT : Leaving... > $netdir/data
-			exit
-		case /*
-			echo unknown command
-		case *
-			msg = 'PRIVMSG '^$target^' :'^$"cmd
-			out = '('^$target^')	⇐	'^$"cmd
+			send_msg
+			target=$target_orig
 		}
-		if (! ~ $#msg 0)
-			echo $msg > $netdir/data
-		if (! ~ $#out 0)
-			echo `{etime}^' '^$out
+	case /n
+		nick = `{mshift $cmd}
+		msg =  (NICK $nick)
+	case /p
+		cmd = `{mshift $cmd}
+		if (! ~ $#cmd 0)
+			msg = (PART $cmd(1) : `{mshift $cmd})
+	case /q
+		msg =  `{mshift $cmd}
+	case /t
+		target = `{mshift $cmd}
+		title
+	case /u
+		msg = (USERS `{mshift $cmd})
+	case /w
+		msg = (WHO `{mshift $cmd})
+	case /x
+		echo  QUIT : Leaving... > $netdir/data
+		exit
+	case /*
+		echo unknown command
+	case *
+		send_msg
 	}
+	if (! ~ $#msg 0)
+		echo $msg > $netdir/data
+	if (! ~ $#out 0)
+		echo `{etime}^' '^$out
+}
+
+fn send_msg {
+	prefixmsg='PRIVMSG '^$target^' :'
+	prefixout='('^$target^')	⇐	'
+	linelen=`{hoc -e 447^'-'^`{echo -n $prefixmsg | wc -c} }
+	ifs_orig=$ifs
+	ifs='\x04'
+	msg=`{echo -n $cmd | fmt -l $linelen | awk '{ printf "%s%s\n", ENVIRON["prefixmsg"], $0 }' }
+	out=`{echo $msg | sed s/$prefixmsg/$prefixout/ }
+	ifs=$ifs_orig
 }
 
 fn misc {
diff -r 0ee17db5d86b sys/man/1/ircrc
--- a/sys/man/1/ircrc	Sat May 02 17:32:01 2020 +0200
+++ b/sys/man/1/ircrc	Tue May 05 00:36:54 2020 -0700
@@ -152,6 +152,10 @@
 command.
 Control-D also sends this command.
 .PP
+Any message containing more than the protocol's maximum allowed characters (447) is chunked into multiple messages using
+.I fmt(1)
+.
+.PP
 See RFC 1459 and RFC 2812 for detailed information about
 IRC commands.
 .SH EXAMPLES



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [9front] Re: [patch] format messages for ircrc
  2020-05-05  3:38   ` [9front] " ori
  2020-05-05  7:43     ` Romano
@ 2020-06-13  0:09     ` Romano
  1 sibling, 0 replies; 5+ messages in thread
From: Romano @ 2020-06-13  0:09 UTC (permalink / raw)
  To: 9front

[Re-sending]

Thanks Ori!

I've updated the patch and tested it: see below (and it's also at http://okturing.com/src/8458/body). Note that 512 is the # of characters including the hostname (63 chars), command, the actual text message, and the final CR&LF required by the protocol. So the # of characters allowed per message text is 447, which I mention in the man page.

On Mon, May 4, 2020, at 8:38 PM, ori@eigenstate.org wrote:
> > Ping. Perhaps the -l option is too much.
> 
> Agreed -- I'd compute it. That would probably look something like:
> 
> 	linelen = `{hoc -e '510 - '`{echo 'PRIVMSG '^$target^' :' | wc -c }}
> 
> Another small bit of nitpicking (I'd be ok with committing it as is, but
> I may as well register my preferences:
> 
> > +				msg=($msg^'
> > +PRIVMSG '^$target^' :'^$"cmd)
> 
> 
> I'd do this somewhere near the start of the program:
> 
> 	nl='
> 	'
> 
> And construct strings using it like this:
> 
> 	msg=($msg^$nl^'PRIVMSG '^$target^' :'^$"cmd)
> 
> Other than that, this looks fine to me.
> 

diff -r 0ee17db5d86b rc/bin/ircrc
--- a/rc/bin/ircrc	Sat May 02 17:32:01 2020 +0200
+++ b/rc/bin/ircrc	Tue May 05 00:36:54 2020 -0700
@@ -49,71 +49,86 @@
 			echo  QUIT : Leaving... > $netdir/data
 			exit
 		}
-		msg=()
-		out=()
-		switch ($cmd(1)) {
-		case /!
-			eval `{mshift $cmd} | while(rc=`{read})echo 'PRIVMSG '^$target^' :' $rc | tee $netdir/data
-		case /M
-			msg = (MODE `{mshift $cmd})
-		case /N
+		do_cmd
+	}
+}
+
+fn do_cmd {
+	msg=()
+	out=()
+	switch ($cmd(1)) {
+	case /!
+		eval `{mshift $cmd} | while(rc=`{read})echo 'PRIVMSG '^$target^' :' $rc | tee $netdir/data
+	case /M
+		msg = (MODE `{mshift $cmd})
+	case /N
+		cmd = `{mshift $cmd}
+		if (! ~ $#cmd 0)
+			msg = (NOTICE $cmd(1) : `{mshift $cmd})
+	case /T
+		msg = (TOPIC `{mshift $cmd})
+	case /W
+		msg = (WHOIS `{mshift $cmd})
+	case /a
+		msg =  (AWAY : `{mshift $cmd})
+	case /j
+		if (~ $#cmd 2) {
+			target=$cmd(2)
+			title
+			msg = (JOIN `{mshift $cmd})
+			if(~ $target *,*)
+				target = `{echo $target | awk -F',' '{print $NF}'}
+		}
+	case /l
+		msg = (LIST `{mshift $cmd})
+	case /m
+		cmd = `{mshift $cmd}
+		if (! ~ $#cmd 0) {
+			target_orig=$target
+			target = $cmd(1)
 			cmd = `{mshift $cmd}
-			if (! ~ $#cmd 0)
-				msg = (NOTICE $cmd(1) : `{mshift $cmd})
-		case /T
-			msg = (TOPIC `{mshift $cmd})
-		case /W
-			msg = (WHOIS `{mshift $cmd})
-		case /a
-			msg =  (AWAY : `{mshift $cmd})
-		case /j
-			if (~ $#cmd 2) {
-				target=$cmd(2)
-				title
-				msg = (JOIN `{mshift $cmd})
-				if(~ $target *,*)
-					target = `{echo $target | awk -F',' '{print $NF}'}
-			}
-		case /l
-			msg = (LIST `{mshift $cmd})
-		case /m
-			cmd = `{mshift $cmd}
-			if (! ~ $#cmd 0) {
-				to = $cmd(1)
-				cmd = `{mshift $cmd}
-				out =  '('^$to^')	⇐	'^$"cmd
-				msg = 'PRIVMSG '^$to^' :'^$"cmd
-			}
-		case /n
-			nick = `{mshift $cmd}
-			msg =  (NICK $nick)
-		case /p
-			cmd = `{mshift $cmd}
-			if (! ~ $#cmd 0)
-				msg = (PART $cmd(1) : `{mshift $cmd})
-		case /q
-			msg =  `{mshift $cmd}
-		case /t
-			target = `{mshift $cmd}
-			title
-		case /u
-			msg = (USERS `{mshift $cmd})
-		case /w
-			msg = (WHO `{mshift $cmd})
-		case /x
-			echo  QUIT : Leaving... > $netdir/data
-			exit
-		case /*
-			echo unknown command
-		case *
-			msg = 'PRIVMSG '^$target^' :'^$"cmd
-			out = '('^$target^')	⇐	'^$"cmd
+			send_msg
+			target=$target_orig
 		}
-		if (! ~ $#msg 0)
-			echo $msg > $netdir/data
-		if (! ~ $#out 0)
-			echo `{etime}^' '^$out
+	case /n
+		nick = `{mshift $cmd}
+		msg =  (NICK $nick)
+	case /p
+		cmd = `{mshift $cmd}
+		if (! ~ $#cmd 0)
+			msg = (PART $cmd(1) : `{mshift $cmd})
+	case /q
+		msg =  `{mshift $cmd}
+	case /t
+		target = `{mshift $cmd}
+		title
+	case /u
+		msg = (USERS `{mshift $cmd})
+	case /w
+		msg = (WHO `{mshift $cmd})
+	case /x
+		echo  QUIT : Leaving... > $netdir/data
+		exit
+	case /*
+		echo unknown command
+	case *
+		send_msg
 	}
+	if (! ~ $#msg 0)
+		echo $msg > $netdir/data
+	if (! ~ $#out 0)
+		echo `{etime}^' '^$out
+}
+
+fn send_msg {
+	prefixmsg='PRIVMSG '^$target^' :'
+	prefixout='('^$target^')	⇐	'
+	linelen=`{hoc -e 447^'-'^`{echo -n $prefixmsg | wc -c} }
+	ifs_orig=$ifs
+	ifs='\x04'
+	msg=`{echo -n $cmd | fmt -l $linelen | awk '{ printf "%s%s\n", ENVIRON["prefixmsg"], $0 }' }
+	out=`{echo $msg | sed s/$prefixmsg/$prefixout/ }
+	ifs=$ifs_orig
 }
 
 fn misc {
diff -r 0ee17db5d86b sys/man/1/ircrc
--- a/sys/man/1/ircrc	Sat May 02 17:32:01 2020 +0200
+++ b/sys/man/1/ircrc	Tue May 05 00:36:54 2020 -0700
@@ -152,6 +152,10 @@
 command.
 Control-D also sends this command.
 .PP
+Any message containing more than the protocol's maximum allowed characters (447) is chunked into multiple messages using
+.I fmt(1)
+.
+.PP
 See RFC 1459 and RFC 2812 for detailed information about
 IRC commands.
 .SH EXAMPLES



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-06-13  0:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-21  8:13 [patch] format messages for ircrc Romano
2020-05-05  3:08 ` Romano
2020-05-05  3:38   ` [9front] " ori
2020-05-05  7:43     ` Romano
2020-06-13  0:09     ` Romano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).