quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

easygetopt.c (2574B)


      1 /***************************************************************************
      2  *                                  _   _ ____  _
      3  *  Project                     ___| | | |  _ \| |
      4  *                             / __| | | | |_) | |
      5  *                            | (__| |_| |  _ <| |___
      6  *                             \___|\___/|_| \_\_____|
      7  *
      8  * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
      9  *
     10  * This software is licensed as described in the file COPYING, which
     11  * you should have received as part of this distribution. The terms
     12  * are also available at https://curl.se/docs/copyright.html.
     13  *
     14  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
     15  * copies of the Software, and permit persons to whom the Software is
     16  * furnished to do so, under the terms of the COPYING file.
     17  *
     18  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
     19  * KIND, either express or implied.
     20  *
     21  * SPDX-License-Identifier: curl
     22  *
     23  ***************************************************************************/
     24 
     25 #include "curl_setup.h"
     26 #include "easyoptions.h"
     27 
     28 #ifndef CURL_DISABLE_GETOPTIONS
     29 
     30 /* Lookups easy options at runtime */
     31 static const struct curl_easyoption *lookup(const char *name, CURLoption id)
     32 {
     33   DEBUGASSERT(name || id);
     34   DEBUGASSERT(!Curl_easyopts_check());
     35   if(name || id) {
     36     const struct curl_easyoption *o = &Curl_easyopts[0];
     37     do {
     38       if(name) {
     39         if(curl_strequal(o->name, name))
     40           return o;
     41       }
     42       else {
     43         if((o->id == id) && !(o->flags & CURLOT_FLAG_ALIAS))
     44           /* do not match alias options */
     45           return o;
     46       }
     47       o++;
     48     } while(o->name);
     49   }
     50   return NULL;
     51 }
     52 
     53 const struct curl_easyoption *curl_easy_option_by_name(const char *name)
     54 {
     55   /* when name is used, the id argument is ignored */
     56   return lookup(name, CURLOPT_LASTENTRY);
     57 }
     58 
     59 const struct curl_easyoption *curl_easy_option_by_id(CURLoption id)
     60 {
     61   return lookup(NULL, id);
     62 }
     63 
     64 /* Iterates over available options */
     65 const struct curl_easyoption *
     66 curl_easy_option_next(const struct curl_easyoption *prev)
     67 {
     68   if(prev && prev->name) {
     69     prev++;
     70     if(prev->name)
     71       return prev;
     72   }
     73   else if(!prev)
     74     return &Curl_easyopts[0];
     75   return NULL;
     76 }
     77 
     78 #else
     79 const struct curl_easyoption *curl_easy_option_by_name(const char *name)
     80 {
     81   (void)name;
     82   return NULL;
     83 }
     84 
     85 const struct curl_easyoption *curl_easy_option_by_id (CURLoption id)
     86 {
     87   (void)id;
     88   return NULL;
     89 }
     90 
     91 const struct curl_easyoption *
     92 curl_easy_option_next(const struct curl_easyoption *prev)
     93 {
     94   (void)prev;
     95   return NULL;
     96 }
     97 #endif