shithub: fsgen

Download patch

ref: bbd7d4c6742817c8627f5fb5f55a14c796642234
parent: 27925e85e49baf91a5d7db61072913e781b85844
author: sirjofri <sirjofri@sirjofri.de>
date: Fri Feb 13 10:54:20 EST 2026

adjusts test filesystem

--- a/test/test.fs
+++ b/test/test.fs
@@ -17,9 +17,28 @@
 #
 
 
+# normal "preamble" C code
 
 %{
 #include "fns.h"
+
+static int
+validfile(char *fname, Req *r)
+{
+	int a;
+	if (strncmp("File", fname, 4) != 0) {
+		werrstr("invalid file: %s", fname);
+		responderror(r);
+		return 1;
+	}
+	a = atoi(&fname[4]);
+	if (a < 0 || a > 3) {
+		respond(r, "invalid file number");
+		return 1;
+	}
+	return 0;
+}
+
 %}
 
 # lines starting with a # are comments.
@@ -28,25 +47,19 @@
 /test/{fname}
 r{
 	char buf[512];
-	int a;
 	
-	if (strncmp("File", fname, 4) != 0) {
-		respond(r, "invalid filename");
+	if (validfile(fname, r))
 		return;
-	}
 	
-	a = atoi(&fname[4]);
-	if (a < 0 || a > 3) {
-		respond(r, "invalid file entry");
-		return;
-	}
-	
 	snprint(buf, sizeof buf, "read: %s\n", fname);
 	readstr(r, buf);
 	respond(r, nil);
 r}
 w{
-	respond(r, "write prohibited");
+	if (validfile(fname, r))
+		return;
+	werrstr("write: %s\n", fname);
+	responderror(r);
 w}
 
 /multi/{one}/{two}
--