On Sat, Nov 21, 2009 at 7:14 PM, Zach Welch <z...@superlucidity.net> wrote: > On Sat, 2009-11-21 at 16:53 +0100, Andreas Fritiofson wrote: >> Add $HOME/.openocd as the first default script search directory, allowing >> the user to override the standard scripts. > > Comments are in-line and at the end. > >> Signed-off-by: Andreas Fritiofson <andreas.fritiof...@gmail.com> >> --- >> src/helper/options.c | 16 +++++++++++++++- >> 1 files changed, 15 insertions(+), 1 deletions(-) >> >> diff --git a/src/helper/options.c b/src/helper/options.c >> index 5792e11..2187ff7 100644 >> --- a/src/helper/options.c >> +++ b/src/helper/options.c >> @@ -29,6 +29,7 @@ >> #include "server.h" >> >> #include <getopt.h> >> +#include <stdlib.h> >> >> static int help_flag, version_flag; >> >> @@ -54,6 +55,10 @@ int configuration_output_handler(struct command_context >> *context, const char* li >> >> static void add_default_dirs(void) >> { >> +#ifndef MAX_PATH >> +#define MAX_PATH 1024 >> +#endif >> + > > PATH_MAX should be defined and available (in <limits.h>). Use it.
I did some research on the matter, and it seems that PATH_MAX is only defined if there actually is a limit, which apparently is not always the case. Even if defined, the value is often arbitrary or unsuitably large. So the #ifndef would have to stay, albeit with another name. Since MAX_PATH was already used in the WIN32 specific section, I decided to reuse that to avoid confusion with two different names. Of course, should PATH_MAX be equally valid on WIN32 even though it's an extension, that section could be changed to use it too if available. I can verify if that's the case earliest on Monday, since I have no Windows machine at home, and submit a clean-up patch after that. In the meantime, this should work perfectly, even if users with a >1K long home directory might be disappointed. :) > >> #ifdef _WIN32 >> /* Add the parent of the directory where openocd.exe resides to the >> * config script search path. >> @@ -101,7 +106,16 @@ static void add_default_dirs(void) >> * listed last in the built-in search order, so the user can >> * override these scripts with site-specific customizations. >> */ >> - /// @todo Implement @c add_script_search_dir("${HOME}/.openocd"). > > As the one who added that @todo item, thanks for doing this! :) > >> + >> + char *home = getenv("HOME"); >> + >> + if (home) { >> + char path[MAX_PATH]; >> + >> + if (snprintf(path, MAX_PATH, "%s/.openocd", home) < MAX_PATH) >> + add_script_search_dir(path); >> + } >> + >> add_script_search_dir(PKGDATADIR "/site"); >> add_script_search_dir(PKGDATADIR "/scripts"); >> #endif > > As others note, this deserves mention in doc/openocd.texi and NEWS. > I'll look into a patch for those soon-ish. /Andreas _______________________________________________ Openocd-development mailing list Openocd-development@lists.berlios.de https://lists.berlios.de/mailman/listinfo/openocd-development