aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2024-09-01 11:15:54 -0400
committerSam Anthony <sam@samanthony.xyz>2024-09-01 11:16:23 -0400
commitd82ac9563ec49adbf9f961f6b30c478171373109 (patch)
tree7a5de615b4385723e6363fa0fe94dc4286f77ba2
parent79c548d59a9f6879b0418bbb6112c81d02349f29 (diff)
downloadbin-d82ac9563ec49adbf9f961f6b30c478171373109.zip
fmtcmt - format C99 comments
-rwxr-xr-xfmtcmt21
1 files changed, 21 insertions, 0 deletions
diff --git a/fmtcmt b/fmtcmt
new file mode 100755
index 0000000..5012c65
--- /dev/null
+++ b/fmtcmt
@@ -0,0 +1,21 @@
+#!/usr/bin/sh
+
+# fmtcmt: format C99-style `//' comments
+# Usage: fmtcmt [ -w n ]
+# Options:
+# -w n Wrap lines to n characters, including `// ' (default 90).
+
+defaultwidth=90
+
+# parse -w
+if [ "$#" -ge 2 ] && [ $1 = "-w" ]; then
+ width=$2
+else
+ width=$defaultwidth
+fi
+
+sed 's/^\/\///' | # strip //
+ sed -e 's/^ *//' -e 's/ *$//' | # strip leading and trailing blanks
+ fmt -w $(expr $width - 3) | # wrap (-3 for "// ")
+ awk '{ print "// " $0 }' | # prepend //
+ sed -z '$ s/\n*$//' # strip tailing \n \ No newline at end of file