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

Refactoring #7

Merged
merged 3 commits into from
Apr 16, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
fix #2
simo981 committed Apr 15, 2024
commit 74afa1af8fcacefb585a79878dc6cbf9bfdafb2e
28 changes: 6 additions & 22 deletions main.c
Original file line number Diff line number Diff line change
@@ -442,36 +442,20 @@ int main(int argc, char **argv)
}
case '?':
{
free_inputs_optind();
exit_usage("wrong parameters");
CHECK_TRUE(true, "wrong parameters");
break;
}
default:
{
free_inputs_optind();
perror("OPTARG FAILURE");
exit(EXIT_FAILURE);
CHECK_TRUE(true, "optarg failure");
}
}
}

// check if start or end are provided by the user
if (!min_len || !max_len)
{
free_inputs_optind();
exit_usage("start and end must be stated");
}
else
{
LOW("max_len must be greater than min_len", max_len, min_len);
}

// check if words are provided by the user
if (optind == argc)
{
free_inputs_optind();
exit_usage("Words after are not provided");
}
CHECK_TRUE(!min_len, "max_len must be stated");
CHECK_TRUE(!max_len, "min_len must be stated");
LOW("max_len must be greater than min_len", max_len, min_len);
CHECK_TRUE(optind == argc, "words not provided");

leet_map['a'] = leet_map['A'] = '4';
leet_map['e'] = leet_map['E'] = '3';
12 changes: 10 additions & 2 deletions main.h
Original file line number Diff line number Diff line change
@@ -17,6 +17,15 @@
copy_len; \
})

#define CHECK_TRUE(var, message) \
({ \
if (var) \
{ \
free_inputs_optind(); \
exit_usage(#message); \
} \
})

typedef struct bool_t
{
uint8_t leet_vowel : 1;
@@ -80,9 +89,8 @@ void exit_usage(char *plus)
#define LOW(NAME, VAR1, VAR2) \
if (VAR1 < VAR2) \
{ \
perror(#NAME); \
free_inputs_optind(); \
exit(EXIT_FAILURE); \
exit_usage(#NAME); \
}

#define exErr(NAME) \