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

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).