From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5156 invoked by alias); 21 Dec 2007 14:31:38 -0000 Received: (qmail 5147 invoked by uid 22791); 21 Dec 2007 14:31:37 -0000 X-Spam-Check-By: sourceware.org Received: from s200aog12.obsmtp.com (HELO psmtp.com) (207.126.144.126) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 21 Dec 2007 14:31:23 +0000 Received: from source ([164.129.1.35]) (using TLSv1) by eu1sys200aob012.postini.com ([207.126.147.11]) with SMTP; Fri, 21 Dec 2007 14:31:14 UTC Received: from zeta.dmz-eu.st.com (ns2.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 40444DCB7; Fri, 21 Dec 2007 14:31:14 +0000 (GMT) Received: from mail2.cro.st.com (mail2.cro.st.com [164.129.40.132]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id EEA674C207; Fri, 21 Dec 2007 14:31:13 +0000 (GMT) Received: from crx595.cro.st.com (crx595.cro.st.com [164.129.44.95]) by mail2.cro.st.com (MOS 3.7.5a-GA) with ESMTP id CKC24283 (AUTH "denis pilat"); Fri, 21 Dec 2007 15:31:12 +0100 (CET) Message-ID: <476BCE30.50803@st.com> Date: Fri, 21 Dec 2007 15:31:00 -0000 From: Denis PILAT User-Agent: Thunderbird 2.0.0.9 (X11/20071031) MIME-Version: 1.0 To: Eli Zaretskii , Daniel Jacobowitz Cc: gdb-patches@sourceware.org Subject: [RFC] usage of environment variable from the command line References: <46F13F2A.8010507@st.com> <20070921225527.GA28500@caradoc.them.org> <20070922135839.GA6285@caradoc.them.org> <20070930012955.GA29254@caradoc.them.org> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2007-12/txt/msg00373.txt.bz2 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')