From: Denis PILAT <denis.pilat@st.com>
To: gdb-patches@sourceware.org
Subject: [RFC] usage of environment variable from the command line
Date: Wed, 19 Sep 2007 15:24:00 -0000 [thread overview]
Message-ID: <46F13F2A.8010507@st.com> (raw)
Hi,
I have a patch that allows to use environment variable when typing commands.
Environment variable must be surrounded by "%%" string.
(Ex: "file %%REPOSITORY%%/obj/a.out" would be supported.)
Is there any chance that such a patch could be accepted ?
I've read from the gdb mailing list that I'm not the only one who wants
to handle environment variable from the command line.
Thanks for your feedback,
--
Denis
Index: top.c
===================================================================
--- top.c (revision 598)
+++ top.c (working copy)
@@ -370,6 +370,46 @@ do_chdir_cleanup (void *old_dir)
}
#endif
+#define ENV_DELIMITOR "%%"
+static char*
+evaluate_environment_from_string(char* input)
+{
+ char *p1, *p2, *output, *env_var, *env_var_value;
+ int env_var_len;
+
+
+ p1 = (char *) strstr (input, ENV_DELIMITOR);
+ if (p1 == NULL)
+ return input;
+
+ p2 = (char *) strstr (p1+1, ENV_DELIMITOR);
+ if (p2 == NULL)
+ return input;
+
+ /* get the env var. */
+ env_var_len = p2 - p1 - strlen(ENV_DELIMITOR);
+ env_var = xmalloc (env_var_len + 1);
+ strncpy (env_var, p1 + strlen(ENV_DELIMITOR), env_var_len);
+ env_var[env_var_len] = 0;
+
+ /* get its value. */
+ env_var_value = getenv (env_var);
+ if (env_var_value == NULL) {
+ xfree (env_var);
+ return input;
+ }
+
+ /* replace this value into the original string. */
+ output = xmalloc (strlen (input) + strlen (env_var_value) - env_var_len - 2*strlen(ENV_DELIMITOR) + 1);
+ strncpy (output, input, p1-input);
+ strcpy (output+(p1-input), env_var_value);
+ strcat (output+(p1-input), p2 + strlen(ENV_DELIMITOR));
+
+ xfree (env_var);
+ return evaluate_environment_from_string(output);
+}
+
+
/* Execute the line P as a command.
Pass FROM_TTY as second argument to the defining function. */
/* Force cleanup of any alloca areas if using C alloca instead of
@@ -391,6 +431,8 @@ execute_command (char *p, int from_tty)
if (p == NULL)
return;
+ p = evaluate_environment_from_string (p);
+
serial_log_command (p);
while (*p == ' ' || *p == '\t')
next reply other threads:[~2007-09-19 15:24 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-19 15:24 Denis PILAT [this message]
2007-09-21 22:55 ` Daniel Jacobowitz
2007-09-22 7:16 ` Eli Zaretskii
2007-09-22 13:58 ` Daniel Jacobowitz
2007-09-24 15:05 ` Denis PILAT
2007-09-24 16:44 ` Jim Blandy
2007-09-24 21:41 ` Eli Zaretskii
2007-09-25 17:11 ` Jim Blandy
2007-09-25 21:38 ` Eli Zaretskii
2007-09-30 1:30 ` Daniel Jacobowitz
2007-09-30 7:17 ` Eli Zaretskii
2007-10-11 17:51 ` Daniel Jacobowitz
2007-12-21 15:31 ` Denis PILAT
2007-12-22 19:27 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=46F13F2A.8010507@st.com \
--to=denis.pilat@st.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox