LCOV - code coverage report
Current view: top level - src/plugins/gopts - gopts.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 17 23 73.9 %
Date: 2019-09-12 12:28:41 Functions: 2 3 66.7 %

          Line data    Source code
       1             : /**
       2             :  * @file
       3             :  *
       4             :  * @brief Source for opts plugin
       5             :  *
       6             :  * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
       7             :  *
       8             :  */
       9             : 
      10             : #include "gopts.h"
      11             : 
      12             : #include <kdbassert.h>
      13             : #include <kdberrors.h>
      14             : #include <kdbhelper.h>
      15             : #include <kdbmacros.h>
      16             : #include <kdbopts.h>
      17             : 
      18             : static int loadArgs (char *** argvp);
      19             : static char ** loadEnvp (void);
      20             : static void cleanupArgs (int argc, char ** argv);
      21             : static void cleanupEnvp (char ** envp);
      22             : 
      23             : #include "gopts_impl.c"
      24             : 
      25             : #if defined(ELEKTRA_GOPTS_PROCFS)
      26             : #include "gopts_procfs.h"
      27             : #elif defined(ELEKTRA_GOPTS_OSX)
      28             : #include "gopts_osx.h"
      29             : #elif defined(ELEKTRA_GOPTS_WIN32)
      30             : #include "gopts_win32.h"
      31             : #elif defined(ELEKTRA_GOPTS_SYSCTL)
      32             : #include "gopts_sysctl.h"
      33             : #else
      34             : #error "No implementation available"
      35             : #endif
      36             : 
      37             : 
      38         140 : int elektraGOptsGet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned, Key * parentKey)
      39             : {
      40         140 :         if (!elektraStrCmp (keyName (parentKey), "system/elektra/modules/gopts"))
      41             :         {
      42          34 :                 KeySet * contract =
      43          34 :                         ksNew (30, keyNew ("system/elektra/modules/gopts", KEY_VALUE, "gopts plugin waits for your orders", KEY_END),
      44             :                                keyNew ("system/elektra/modules/gopts/exports", KEY_END),
      45             :                                keyNew ("system/elektra/modules/gopts/exports/get", KEY_FUNC, elektraGOptsGet, KEY_END),
      46             : #include ELEKTRA_README
      47             :                                keyNew ("system/elektra/modules/gopts/infos/version", KEY_VALUE, PLUGINVERSION, KEY_END), KS_END);
      48          34 :                 ksAppend (returned, contract);
      49          34 :                 ksDel (contract);
      50             : 
      51          34 :                 return ELEKTRA_PLUGIN_STATUS_SUCCESS;
      52             :         }
      53             : 
      54         106 :         char ** argv = NULL;
      55         106 :         int argc = loadArgs (&argv);
      56         106 :         char ** envp = loadEnvp ();
      57             : 
      58         106 :         if (argv == NULL || envp == NULL)
      59             :         {
      60           0 :                 ELEKTRA_SET_INSTALLATION_ERROR (parentKey, "could not load current process' arguments");
      61           0 :                 return ELEKTRA_PLUGIN_STATUS_ERROR;
      62             :         }
      63             : 
      64         106 :         int ret = elektraGetOpts (returned, argc, (const char **) argv, (const char **) envp, parentKey);
      65             : 
      66         106 :         cleanupArgs (argc, argv);
      67             :         cleanupEnvp (envp);
      68             : 
      69         106 :         if (ret == -1)
      70             :         {
      71             :                 return ELEKTRA_PLUGIN_STATUS_ERROR;
      72             :         }
      73         106 :         else if (ret == 1)
      74             :         {
      75           0 :                 Key * helpKey = keyNew ("proc/elektra/gopts/help", KEY_VALUE, "1", KEY_END);
      76           0 :                 keyCopyAllMeta (helpKey, parentKey);
      77           0 :                 ksAppendKey (returned, helpKey);
      78           0 :                 return ELEKTRA_PLUGIN_STATUS_SUCCESS;
      79             :         }
      80             : 
      81             :         return ELEKTRA_PLUGIN_STATUS_SUCCESS;
      82             : }
      83             : 
      84         140 : Plugin * ELEKTRA_PLUGIN_EXPORT
      85             : {
      86             :         // clang-format off
      87         140 :         return elektraPluginExport ("gopts",
      88             :                 ELEKTRA_PLUGIN_GET,     &elektraGOptsGet,
      89             :                 ELEKTRA_PLUGIN_END);
      90             :         // clang-format on
      91             : }

Generated by: LCOV version 1.13