VirtualBox

Changeset 2163 in kBuild for trunk


Ignore:
Timestamp:
Dec 30, 2008 12:57:13 AM (16 years ago)
Author:
bird
Message:

kmk: Added a $(select ) function for handling switch like stuff. Fixes #74.

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/kBuild/doc/QuickReference-kmk.html

    r2161 r2163  
    841841</pre>
    842842</blockquote>
    843 <p>(Mostly) Boolean Functions:</p>
     843<p>Boolean and Conditional Functions:</p>
    844844<blockquote>
    845845<p>Condition is false if the <tt class="docutils literal"><span class="pre">condition</span></tt> evaluates to an empty string
     
    879879<p>Same as <tt class="docutils literal"><span class="pre">$(if</span> <span class="pre">)</span></tt> execpt that the condition is a <tt class="docutils literal"><span class="pre">kmk</span></tt> expression:</p>
    880880<pre class="literal-block">
    881 $(if kmk-expression,true-part[,false-part])
     881$(if-expr kmk-expression,true-part[,false-part])
     882</pre>
     883<p>Select the first true condition (<tt class="docutils literal"><span class="pre">kmk</span></tt> expression) and expand the
     884following body. Special condition strings <tt class="docutils literal"><span class="pre">default</span></tt> and <tt class="docutils literal"><span class="pre">otherwise</span></tt>:</p>
     885<pre class="literal-block">
     886$(select when1-cond, when1-body[, whenN-cond, whenN-body])
    882887</pre>
    883888<p>Evalutate the <tt class="docutils literal"><span class="pre">kmk</span></tt> expression returning what it evalues as. This is
  • trunk/kBuild/doc/QuickReference-kmk.txt

    r2161 r2163  
    482482
    483483
    484 (Mostly) Boolean Functions:
     484Boolean and Conditional Functions:
    485485
    486486    Condition is false if the ``condition`` evaluates to an empty string
     
    521521    Same as ``$(if )`` execpt that the condition is a ``kmk`` expression::
    522522
    523         $(if kmk-expression,true-part[,false-part])
     523        $(if-expr kmk-expression,true-part[,false-part])
     524
     525    Select the first true condition (``kmk`` expression) and expand the
     526    following body. Special condition strings ``default`` and ``otherwise``::
     527
     528        $(select when1-cond, when1-body[, whenN-cond, whenN-body])
    524529
    525530    Evalutate the ``kmk`` expression returning what it evalues as. This is
  • trunk/src/kmk/function.c

    r2161 r2163  
    41404140  to_expand = rc == 0 ? argv[1] : argv[2];
    41414141  if (*to_expand)
    4142     {
    4143       char *expansion = expand_argument (to_expand, NULL);
    4144 
    4145       o = variable_buffer_output (o, expansion, strlen (expansion));
    4146 
    4147       free (expansion);
     4142    variable_expand_string_2 (o, to_expand, -1, &o);
     4143
     4144  return o;
     4145}
     4146
     4147/*
     4148  $(select when1-cond, when1-body[,whenN-cond, whenN-body]).
     4149  */
     4150static char *
     4151func_select (char *o, char **argv, const char *funcname UNUSED)
     4152{
     4153  int i;
     4154
     4155  /* Test WHEN-CONDs until one matches. The check for 'otherwise[:]'
     4156     and 'default[:]' make this a bit more fun... */
     4157
     4158  for (i = 0; argv[i] != NULL; i += 2)
     4159    {
     4160      const char *cond = argv[i];
     4161      int is_otherwise = 0;
     4162
     4163      if (argv[i + 1] == NULL)
     4164        fatal (NILF, _("$(select ): not an even argument count\n"));
     4165
     4166      while (isspace ((unsigned char)*cond))
     4167        cond++;
     4168      if (   (*cond == 'o' && strncmp (cond, "otherwise", 9) == 0)
     4169          || (*cond == 'd' && strncmp (cond, "default",   7) == 0))
     4170        {
     4171          const char *end = cond + (*cond == 'o' ? 9 : 7);
     4172          while (isspace ((unsigned char)*end))
     4173            end++;
     4174          if (*end == ':')
     4175            do end++;
     4176            while (isspace ((unsigned char)*end));
     4177          is_otherwise = *end == '\0';
     4178        }
     4179
     4180      if (   is_otherwise
     4181          || expr_eval_if_conditionals (cond, NULL) == 0 /* true */)
     4182        {
     4183          variable_expand_string_2 (o, argv[i + 1], -1, &o);
     4184          break;
     4185        }
    41484186    }
    41494187
     
    50305068  { STRING_SIZE_TUPLE("expr"),          1,  1,  0,  func_expr},
    50315069  { STRING_SIZE_TUPLE("if-expr"),       2,  3,  0,  func_if_expr},
     5070  { STRING_SIZE_TUPLE("select"),        2,  0,  0,  func_select},
    50325071#endif
    50335072#ifdef CONFIG_WITH_SET_CONDITIONALS
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette