#!/usr/bin/env bash # nc-tclgen.sh — generate TCL UPOC scaffolding from intent. Skeletons for # common Cloverleaf TPS/Xlate use cases. Output is ready-to-edit TCL. # # Larry can write your full UPOC for you via prompt; this tool gives you a # clean, lint-free starting point with the right argument handling and # boilerplate. Useful when offline or when you want to start from a template. # # Subcommands: # tps-presc [--description TXT] PreSC TPS proc skeleton # tps-postsc [--description TXT] PostSC TPS proc skeleton # tps-iclkill [--description TXT] a proc that calls hcitpsmsgkill # xlate-helper [--description TXT] xlate helper function skeleton # trxid [--description TXT] trxid (routing key) extractor # ack [--description TXT] raw ACK generator # field-rewrite --segment SEG --field N --to VALUE small field setter # list-templates # # Output: TCL source to stdout (or --out PATH). set -o pipefail usage() { sed -n '2,20p' "$0"; exit 0; } die() { printf 'nc-tclgen: %s\n' "$*" >&2; exit 1; } header() { local proc="$1" desc="$2" template="$3" cat </dev/null || date) # Author: ${USER:-larry-anywhere} ######################################################################## EOF } emit_tps_presc() { local proc="$1" desc="${2:-PreSC handler — runs before service send}" header "$proc" "$desc" "PreSC" cat </dev/null OUT_FILE="" PROC="" DESC="" SEG=""; FNUM=""; TO="" # Parse common flags while [ $# -gt 0 ]; do case "$1" in --description) shift; DESC="$1" ;; --out) shift; OUT_FILE="$1" ;; --segment) shift; SEG="$1" ;; --field) shift; FNUM="$1" ;; --to) shift; TO="$1" ;; -h|--help) usage ;; -*) die "unknown flag: $1" ;; *) [ -z "$PROC" ] && PROC="$1" || die "extra arg: $1" ;; esac shift done run_emit() { if [ -n "$OUT_FILE" ]; then mkdir -p "$(dirname "$OUT_FILE")" 2>/dev/null "$@" > "$OUT_FILE" printf 'wrote %s\n' "$OUT_FILE" >&2 else "$@" fi } case "$SUB" in tps-presc) [ -n "$PROC" ] || die "needs PROC name"; run_emit emit_tps_presc "$PROC" "$DESC" ;; tps-postsc) [ -n "$PROC" ] || die "needs PROC name"; run_emit emit_tps_postsc "$PROC" "$DESC" ;; tps-iclkill) [ -n "$PROC" ] || die "needs PROC name"; run_emit emit_tps_iclkill "$PROC" "$DESC" ;; xlate-helper) [ -n "$PROC" ] || die "needs PROC name"; run_emit emit_xlate_helper "$PROC" "$DESC" ;; trxid) [ -n "$PROC" ] || die "needs PROC name"; run_emit emit_trxid "$PROC" "$DESC" ;; ack) [ -n "$PROC" ] || die "needs PROC name"; run_emit emit_ack "$PROC" "$DESC" ;; field-rewrite) [ -n "$PROC" ] && [ -n "$SEG" ] && [ -n "$FNUM" ] && [ -n "$TO" ] \ || die "needs PROC + --segment SEG --field N --to VALUE" run_emit emit_field_rewrite "$PROC" "$SEG" "$FNUM" "$TO" ;; list-templates|list) list_templates ;; help|-h|--help) usage ;; *) die "unknown subcommand: $SUB" ;; esac