From 76f8be9be1deb17580b5208f50f90adef61cc56f Mon Sep 17 00:00:00 2001 From: Luc Maranget Date: Fri, 31 Jul 2026 14:11:21 +0200 Subject: [PATCH] [herd] Add special clause `include $dirname...` in configuration file If the argument to the include directive starts with the string $dirname, then the effect is replacing `$dirname` with the the directory of the configuration file and adding the resulting string to **herd7** search path. --- doc/herd.tex | 6 +++++- herd/lexConf_herd.mll | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/doc/herd.tex b/doc/herd.tex index 7af8ce717c..529efb10f3 100644 --- a/doc/herd.tex +++ b/doc/herd.tex @@ -2051,7 +2051,11 @@ \subsection{\label{herd:configfile}{Configuration files}} as setting the value of parameter~\textit{key} to \textit{arg}. Each parameter has a corresponding option, usually \opt{-}\textit{key}, except for the single letter -option \opt{-v} whose parameter is \opt{verbose}. +options \opt{-v} whose parameter is \opt{verbose} and +\opt{-I} whose parameter is \opt{include}. Additionally, +the special syntax \opt{include $dirname} is recognised +when being a prefix of the argument of the parameter~\opt{include}. +This prefix stands for the directory name of the configuration file. As command line option are processed left-to-right, settings from a configuration file (option \opt{-conf}) diff --git a/herd/lexConf_herd.mll b/herd/lexConf_herd.mll index cf9655991e..acd2b1648c 100644 --- a/herd/lexConf_herd.mll +++ b/herd/lexConf_herd.mll @@ -119,7 +119,13 @@ let handle_key dir main key arg = match key with | "verbose" -> lex_int verbose arg | "suffix" -> suffix := arg | "include" -> - includes := !includes @ [arg] + let arg = + let pat = "$dirname" in + if String.starts_with ~prefix:pat arg then + let lpat = String.length pat in + dir ^ String.sub arg lpat (String.length arg - lpat) + else arg in + includes := !includes @ [arg] | "timeout" -> lex_float_opt timeout arg | "debug" ->