Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: optimize getopt() usage #147

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions src/applet/notification/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,9 @@ static int applet_main(int argc, char **argv)
int fret = 0;
int all = 0;
int autoremove = 0;
int argc_seq_offset = 1;
int opt = 0;

int opt = getopt(argc, argv, opt_string);
for (int i = 0; opt != -1; i++)
while ((opt = getopt(argc, argv, opt_string)) != -1)
{
switch (opt)
{
Expand All @@ -87,14 +86,10 @@ static int applet_main(int argc, char **argv)
printf("\t -r Automatically remove processed notifications\r\n");
return -1;
default:
goto run;
break;
}
argc_seq_offset++;
opt = getopt(argc, argv, opt_string);
}

run:
if (all)
{
struct es10b_notification_metadata_list *notifications, *rptr;
Expand All @@ -121,7 +116,7 @@ static int applet_main(int argc, char **argv)
}
else
{
for (int i = argc_seq_offset; i < argc; i++)
for (int i = optind; i < argc; i++)
{
unsigned long seqNumber;

Expand Down
11 changes: 3 additions & 8 deletions src/applet/notification/remove.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ static int applet_main(int argc, char **argv)

int fret = 0;
int all = 0;
int argc_seq_offset = 1;
int opt = 0;

int opt = getopt(argc, argv, opt_string);
for (int i = 0; opt != -1; i++)
while ((opt = getopt(argc, argv, opt_string)) != -1)
{
switch (opt)
{
Expand All @@ -57,14 +56,10 @@ static int applet_main(int argc, char **argv)
printf("\t -a All notifications\r\n");
return -1;
default:
goto run;
break;
}
argc_seq_offset++;
opt = getopt(argc, argv, opt_string);
}

run:
if (all)
{
struct es10b_notification_metadata_list *notifications, *rptr;
Expand All @@ -91,7 +86,7 @@ static int applet_main(int argc, char **argv)
}
else
{
for (int i = argc_seq_offset; i < argc; i++)
for (int i = optind; i < argc; i++)
{
unsigned long seqNumber;

Expand Down
3 changes: 1 addition & 2 deletions src/applet/profile/discovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ static int applet_main(int argc, char **argv)

cJSON *jdata = NULL;

opt = getopt(argc, argv, opt_string);
while (opt != -1)
while ((opt = getopt(argc, argv, opt_string)) != -1)
{
switch (opt)
{
Expand Down
4 changes: 1 addition & 3 deletions src/applet/profile/download.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ static int applet_main(int argc, char **argv)
cJSON *jmetadata = NULL;
struct es8p_metadata *profile_metadata = NULL;

opt = getopt(argc, argv, opt_string);
while (opt != -1)
while ((opt = getopt(argc, argv, opt_string)) != -1)
{
switch (opt)
{
Expand Down Expand Up @@ -90,7 +89,6 @@ static int applet_main(int argc, char **argv)
default:
break;
}
opt = getopt(argc, argv, opt_string);
}

if (activation_code != NULL)
Expand Down