From: Denis PILAT <denis.pilat@st.com>
To: Eli Zaretskii <eliz@gnu.org>, Daniel Jacobowitz <drow@false.org>
Cc: gdb-patches@sourceware.org
Subject: [RFC] usage of environment variable from the command line
Date: Fri, 21 Dec 2007 15:31:00 -0000 [thread overview]
Message-ID: <476BCE30.50803@st.com> (raw)
In-Reply-To: <uir5sbp1y.fsf@gnu.org>
Hi everyone,
I'going back to the patch proposed a few months ago.
I'm now having a patch that use the suggested syntax "${...}" and
transform commands at the beginning of top.c/execute_command() only if
the ${...} match an environment variable.
It works as well for scripts that can contains env. variables.
Anything from the command line is transformed, there is no limit to the
kind of commands that can use env. variables.
Attached is the patch, I know that you won't accept it but it's just to
discuss. I guess it's not generic enough and may be does not cover some
language ..., but what's sure is that it does not involved any
regression in the full testsuite.
The old discussion was here:
http://sources.redhat.com/ml/gdb-patches/2007-09/msg00430.html
My point is:
- What do you mean by a specification ?
- You also told about quoting issues, could you please be more precise ?
I don't see any issue in my patch (like in every patches I've done ... ;-) )
Thanks,
Denis
Index: top.c
===================================================================
--- top.c (revision 624)
+++ top.c (working copy)
@@ -364,6 +364,49 @@ do_chdir_cleanup (void *old_dir)
}
#endif
+
+#define ENV_DELIMITOR_BEGIN "${"
+#define ENV_DELIMITOR_END "}"
+static char*
+evaluate_environment_from_string(char* input)
+{
+ char *p1, *p2, *output, *env_var, *env_var_value;
+ int env_var_len, delimitor_begin_len, delimitor_end_len;
+
+ p1 = (char *) strstr (input, ENV_DELIMITOR_BEGIN);
+ if (p1 == NULL)
+ return input;
+
+ p2 = (char *) strstr (p1+1, ENV_DELIMITOR_END);
+ if (p2 == NULL)
+ return input;
+
+ delimitor_begin_len = strlen(ENV_DELIMITOR_BEGIN);
+ delimitor_end_len = strlen(ENV_DELIMITOR_END);
+ /* get the env var. */
+ env_var_len = p2 - p1 - delimitor_begin_len;
+ env_var = xmalloc (env_var_len + 1);
+ strncpy (env_var, p1 + delimitor_begin_len, 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 - delimitor_begin_len - delimitor_end_len + 1);
+ strncpy (output, input, p1-input);
+ strcpy (output+(p1-input), env_var_value);
+ strcat (output+(p1-input), p2 + delimitor_end_len);
+
+ 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. */
@@ -385,6 +428,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 prev parent reply other threads:[~2007-12-21 14:31 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-19 15:24 Denis PILAT
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 [this message]
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=476BCE30.50803@st.com \
--to=denis.pilat@st.com \
--cc=drow@false.org \
--cc=eliz@gnu.org \
--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