Cleanup, renaming other fn to be general.
This commit is contained in:
parent
f5036783f9
commit
fac37b8b40
27
main.c
27
main.c
@ -50,7 +50,7 @@ FILE *fopenHostsFile(char *mode)
|
|||||||
* @param newhost
|
* @param newhost
|
||||||
* @param hostsFile
|
* @param hostsFile
|
||||||
*/
|
*/
|
||||||
void replacehost(char *oldhost, char *newhost, int deleteHost) {
|
void modifyHostsFile(char *oldhost, char *newhost, int deleteHost) {
|
||||||
FILE *hostsFile = fopenHostsFile("r");
|
FILE *hostsFile = fopenHostsFile("r");
|
||||||
char buf[256];
|
char buf[256];
|
||||||
char *ptr, *f;
|
char *ptr, *f;
|
||||||
@ -109,9 +109,12 @@ void blockHost(char *host)
|
|||||||
|
|
||||||
void deleteHost(char *host)
|
void deleteHost(char *host)
|
||||||
{
|
{
|
||||||
replacehost(host, NULL, 1);
|
modifyHostsFile(host, NULL, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void replaceHost(char *oldhost, char *newhost) {
|
||||||
|
modifyHostsFile(oldhost, newhost, 0);
|
||||||
|
}
|
||||||
|
|
||||||
void showHosts()
|
void showHosts()
|
||||||
{
|
{
|
||||||
@ -244,11 +247,9 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Process our command line arguments.
|
// Process our command line arguments.
|
||||||
for (int i = 0; i < argc; i++)
|
for (int i = 0; i < argc; i++) {
|
||||||
{
|
|
||||||
// Opens a hosts file in append mode, adding a host.
|
// Opens a hosts file in append mode, adding a host.
|
||||||
if (ARG_IS("add"))
|
if (ARG_IS("add")) {
|
||||||
{
|
|
||||||
if (argc < 3) {
|
if (argc < 3) {
|
||||||
printf("Please provide a host!\n");
|
printf("Please provide a host!\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -256,25 +257,21 @@ int main(int argc, char **argv)
|
|||||||
blockHost(argv[++i]);
|
blockHost(argv[++i]);
|
||||||
}
|
}
|
||||||
// Replaces a host
|
// Replaces a host
|
||||||
else if (ARG_IS("edit"))
|
else if (ARG_IS("edit")) {
|
||||||
{
|
replacehost(argv[i + 1], argv[i + 2], 0);
|
||||||
replacehost(argv[i + 1], argv[i + 2]);
|
|
||||||
i += 2;
|
i += 2;
|
||||||
}
|
}
|
||||||
// Deletes a host.
|
// Deletes a host.
|
||||||
else if (ARG_IS("delete"))
|
else if (ARG_IS("delete")) {
|
||||||
{
|
|
||||||
fprintf(stdout, "Soon to be implemented!\n");
|
fprintf(stdout, "Soon to be implemented!\n");
|
||||||
}
|
}
|
||||||
// Shows usage.
|
// Shows usage.
|
||||||
else if (ARG_IS("-h"))
|
else if (ARG_IS("-h")) {
|
||||||
{
|
|
||||||
usage();
|
usage();
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
// Show the entire hosts file.
|
// Show the entire hosts file.
|
||||||
else if (ARG_IS("show"))
|
else if (ARG_IS("show")) {
|
||||||
{
|
|
||||||
showHosts();
|
showHosts();
|
||||||
}
|
}
|
||||||
else if (ARG_IS("-config")) {
|
else if (ARG_IS("-config")) {
|
||||||
|
Loading…
Reference in New Issue
Block a user