git: 9front

Download patch

ref: 8a309819457c3d0b1a248eac4d6effb1e989423d
parent: 506936b403e585829a614942bfd40ca1a16b5324
author: Ori Bernstein <ori@eigenstate.org>
date: Mon Sep 22 19:54:46 EDT 2025

ape: remove fmtdoquote

we shouldn't leave the footguns; however, here, we can
remove it entirely. No ape programs use it, and it's not
even useful for code shared between ape and 9front on
account of the different names.

--- a/sys/include/ape/fmt.h
+++ b/sys/include/ape/fmt.h
@@ -92,8 +92,6 @@
 
 extern	int	quotestrfmt(Fmt *f);
 extern	void	quotefmtinstall(void);
-extern	int	(*fmtdoquote)(int);
-
 
 extern	int	fmtinstall(int, int (*)(Fmt*));
 extern	int	dofmt(Fmt*, char*);
--- a/sys/src/ape/lib/fmt/fmt.c
+++ b/sys/src/ape/lib/fmt/fmt.c
@@ -70,9 +70,6 @@
 	0,	nil,
 };
 
-
-int	(*fmtdoquote)(int);
-
 /*
  * __fmtlock() must be set
  */
--- a/sys/src/ape/lib/fmt/fmtquote.c
+++ b/sys/src/ape/lib/fmt/fmtquote.c
@@ -30,6 +30,17 @@
  * *ninp is set to number of input bytes accepted.
  * nin may be <0 initially, to avoid checking input by count.
  */
+
+static int
+fmtdoquote(int c)
+{
+	if(c <= ' ')
+		return 1;
+	if(utfrune("`^#*[]=|\\?${}()'<>&;", c))
+		return 1;
+	return 0;
+}
+
 void
 __quotesetup(char *s, Rune *r, int nin, int nout, Quoteinfo *q, int sharp, int runesout)
 {
@@ -66,7 +77,7 @@
 				break;
 		}
 
-		if((c <= L' ') || (c == L'\'') || (fmtdoquote!=nil && fmtdoquote(c))){
+		if((c <= L' ') || (c == L'\'') || fmtdoquote(c)){
 			if(!q->quoted){
 				if(runesout){
 					if(1+q->nrunesout+1+1 > nout)	/* no room for quotes */
--