All of lore.kernel.org
 help / color / mirror / Atom feed
From: Schrempf Frieder <frieder.schrempf@kontron.de>
To: u-boot@lists.denx.de
Subject: [PATCH v3 1/2] menu: Add a function to set the default by matching the item data
Date: Wed, 12 Feb 2020 10:36:13 +0000	[thread overview]
Message-ID: <73d00b13-f054-1c9f-619d-ef60dda20817@kontron.de> (raw)
In-Reply-To: <CAPnjgZ0A+K7mbnd7M0wuWhhsHAkpxeMfDQS+6Qg+xGwmf_kKuQ@mail.gmail.com>

On 06.02.20 18:46, Simon Glass wrote:
> Hi Schrempf,
> 
> On Thu, 6 Feb 2020 at 02:09, Schrempf Frieder
> <frieder.schrempf@kontron.de> wrote:
>>
>> From: Frieder Schrempf <frieder.schrempf@kontron.de>
>>
>> In order to make it possible to auto select a default entry by
>> matching the data of the menu entries by an external matching
>> function, we add some helpers and expose the
>> menu_set_default_by_item_data_match() function.
>>
>> Signed-off-by: Frieder Schrempf <frieder.schrempf@kontron.de>
>> ---
>> Changes in v3:
>> * Add a full function comment to describe menu_set_default_by_item_data_match().
>>
>> Changes in v2:
>> * Keep the menu structs private and instead only expose one additional
>>    function, that sets the default by calling an external matching
>>    function on each entry.
>> * Change the title and commit message to reflect the changes.
>> ---
>>   common/menu.c  | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++
>>   include/menu.h |  3 +++
>>   2 files changed, 57 insertions(+)
>>
>> diff --git a/common/menu.c b/common/menu.c
>> index 7b66d199a9..6110b2396c 100644
>> --- a/common/menu.c
>> +++ b/common/menu.c
>> @@ -160,6 +160,60 @@ static inline struct menu_item *menu_item_by_key(struct menu *m,
>>          return menu_items_iter(m, menu_item_key_match, item_key);
>>   }
>>
>> +/*
>> + * Find the first matching item, if any exists by calling a matching function
>> + * on the items data field.
>> + */
>> +static inline struct menu_item *menu_item_by_matching_fn(struct menu *m,
>> +                       int match(void *, void *), void * extra)
>> +{
>> +       struct list_head *pos, *n;
>> +       struct menu_item *item;
>> +       int ret;
>> +
>> +       list_for_each_safe(pos, n, &m->items) {
>> +               item = list_entry(pos, struct menu_item, list);
>> +               if (item->key) {
>> +                       ret = match(item->data, extra);
>> +                       if (ret == 1)
>> +                               return item;
>> +               }
>> +       }
>> +
>> +       return NULL;
>> +}
>> +
>> +/*
>> + * menu_set_default_by_item_data_match() - sets a menu default option by calling
>> + * a matching function on each of the menu items data field.
>> + *
>> + * m - Points to a menu created by menu_create().
>> + *
>> + * match - Points to a function that is passed a pointer to the items data field
>> + *         and a pointer to extra data to compare with. It should return 1 on a
>> + *         match.
>> + *
>> + * extra - Points to some data that is passed as a second parameter to the
>> + *         matching function.
>> + *
>> + * key - Points to a char array that will be set to hold the key of the matched
>> + *       menu item.
>> + *
>> + * Returns 0 if successful, or -ENOENT if no matching item was found.
> 
> Can you please update this to the correct comment style - e.g. see
> cmd_process_error() in command.h for example. Also since this is an
> exported function the comment should go in the header file.

Sure. Thanks for pointing me to the correct style and for reviewing in 
general!

> 
> Regards,
> SImon
> 

      reply	other threads:[~2020-02-12 10:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-06  9:09 [PATCH v3 1/2] menu: Add a function to set the default by matching the item data Schrempf Frieder
2020-02-06  9:09 ` [PATCH v3 2/2] pxe: Get default selection from board type if label matches Schrempf Frieder
2020-02-06 17:46   ` Simon Glass
2020-02-12 10:35     ` Schrempf Frieder
2020-02-06 17:46 ` [PATCH v3 1/2] menu: Add a function to set the default by matching the item data Simon Glass
2020-02-12 10:36   ` Schrempf Frieder [this message]

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=73d00b13-f054-1c9f-619d-ef60dda20817@kontron.de \
    --to=frieder.schrempf@kontron.de \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.