Skip to content

Commit ef3989d

Browse files
committed
CommandOption: refactors code with ffStrbufSeparatedContainIgnCaseS
1 parent 3079b44 commit ef3989d

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

src/common/commandoption.c

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,42 +71,35 @@ bool ffParseModuleOptions(const char* key, const char* value)
7171

7272
void ffPrepareCommandOption(FFdata* data)
7373
{
74-
//If we don't have a custom structure, use the default one
75-
if(data->structure.length == 0)
76-
ffStrbufAppendS(&data->structure, FASTFETCH_DATATEXT_STRUCTURE); // Cannot use `ffStrbufSetStatic` here because we will modify the string
77-
78-
if(ffStrbufContainIgnCaseS(&data->structure, FF_CPUUSAGE_MODULE_NAME))
74+
if(ffStrbufSeparatedContainIgnCaseS(&data->structure, FF_CPUUSAGE_MODULE_NAME, ':'))
7975
ffPrepareCPUUsage();
8076

81-
if(ffStrbufContainIgnCaseS(&data->structure, FF_DISKIO_MODULE_NAME))
77+
if(ffStrbufSeparatedContainIgnCaseS(&data->structure, FF_DISKIO_MODULE_NAME, ':'))
8278
{
8379
__attribute__((__cleanup__(ffDestroyDiskIOOptions))) FFDiskIOOptions options;
8480
ffInitDiskIOOptions(&options);
8581
ffPrepareDiskIO(&options);
8682
}
8783

88-
if(ffStrbufContainIgnCaseS(&data->structure, FF_NETIO_MODULE_NAME))
84+
if(ffStrbufSeparatedContainIgnCaseS(&data->structure, FF_NETIO_MODULE_NAME, ':'))
8985
{
9086
__attribute__((__cleanup__(ffDestroyNetIOOptions))) FFNetIOOptions options;
9187
ffInitNetIOOptions(&options);
9288
ffPrepareNetIO(&options);
9389
}
9490

95-
if(instance.config.general.multithreading)
91+
if(ffStrbufSeparatedContainIgnCaseS(&data->structure, FF_PUBLICIP_MODULE_NAME, ':'))
9692
{
97-
if(ffStrbufContainIgnCaseS(&data->structure, FF_PUBLICIP_MODULE_NAME))
98-
{
99-
__attribute__((__cleanup__(ffDestroyPublicIpOptions))) FFPublicIPOptions options;
100-
ffInitPublicIpOptions(&options);
101-
ffPreparePublicIp(&options);
102-
}
93+
__attribute__((__cleanup__(ffDestroyPublicIpOptions))) FFPublicIPOptions options;
94+
ffInitPublicIpOptions(&options);
95+
ffPreparePublicIp(&options);
96+
}
10397

104-
if(ffStrbufContainIgnCaseS(&data->structure, FF_WEATHER_MODULE_NAME))
105-
{
106-
__attribute__((__cleanup__(ffDestroyWeatherOptions))) FFWeatherOptions options;
107-
ffInitWeatherOptions(&options);
108-
ffPrepareWeather(&options);
109-
}
98+
if(ffStrbufSeparatedContainIgnCaseS(&data->structure, FF_WEATHER_MODULE_NAME, ':'))
99+
{
100+
__attribute__((__cleanup__(ffDestroyWeatherOptions))) FFWeatherOptions options;
101+
ffInitWeatherOptions(&options);
102+
ffPrepareWeather(&options);
110103
}
111104
}
112105

src/fastfetch.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,12 @@ static void run(FFdata* data)
749749
if (useJsonConfig)
750750
ffPrintJsonConfig(true /* prepare */, instance.state.resultDoc);
751751
else
752+
{
753+
//If we don't have a custom structure, use the default one
754+
if(data->structure.length == 0)
755+
ffStrbufAppendS(&data->structure, FASTFETCH_DATATEXT_STRUCTURE); // Cannot use `ffStrbufSetStatic` here because we will modify the string
752756
ffPrepareCommandOption(data);
757+
}
753758

754759
ffStart();
755760

0 commit comments

Comments
 (0)