Skip to content

traditional C codestyle #15

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

Merged
merged 1 commit into from
Jan 18, 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
26 changes: 18 additions & 8 deletions src/cpu/cpu_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

#include "cpu_info.h"

void print_cpu_info(void) {
void print_cpu_info(void)
{
FILE *cpu_file;

printf(" ____________\n");
Expand All @@ -20,21 +21,26 @@ void print_cpu_info(void) {
printf("|\n");

cpu_file = fopen("/proc/cpuinfo", "r");
if (cpu_file) {
if (cpu_file)
{
char line[128];
int lines = 0;
while (fgets(line, sizeof(line), cpu_file) && lines < 19) {
while (fgets(line, sizeof(line), cpu_file) && lines < 19)
{
printf("| %s", line);
lines++;
}
fclose(cpu_file);
printf("|____________\n\n");
} else {
}
else
{
printf("Error opening /proc/cpuinfo\n");
}
}

void print_full_cpu_info(void) {
void print_full_cpu_info(void)
{
FILE *cpu_file;

printf(" ____________\n");
Expand All @@ -44,14 +50,18 @@ void print_full_cpu_info(void) {
printf("|\n");

cpu_file = fopen("/proc/cpuinfo", "r");
if (cpu_file) {
if (cpu_file)
{
char line[128];
while (fgets(line, sizeof(line), cpu_file)) {
while (fgets(line, sizeof(line), cpu_file))
{
printf("| %s", line);
}
fclose(cpu_file);
printf("|____________\n\n");
} else {
}
else
{
printf("Error opening /proc/cpuinfo\n");
}
}
Expand Down
15 changes: 10 additions & 5 deletions src/hlp/hlp_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

#include "hlp_info.h"

void print_banner(void){
void print_banner(void)
{
printf("\n \
____ _\n \
/ ___| _ __ _ _ _ __ (_)_ __\n \
Expand All @@ -20,7 +21,8 @@ void print_banner(void){
|_| |___/\n\n");
}

void print_logo(void) {
void print_logo(void)
{
printf("MMMMMMMMMMMMMMMMMMMMMMMMMMMMMWNK0OkxxdddddxkkO0KNWMMMMMMMMMMMMMMMMMMMMMMMMMMMMM\n\
MMMMMMMMMMMMMMMMMMMMMMMWXKOxdoc:;,,''''''''',,;:codxOKXWMMMMMMMMMMMMMMMMMMMMMMM\n\
MMMMMMMMMMMMMMMMMMMWKOdl;,'',;:clooooddddoooollc:;''',:ldOKWMMMMMMMMMMMMMMMMMMM\n\
Expand Down Expand Up @@ -63,11 +65,13 @@ MMMMMMMMMMMMMMMMMMMMMMWNKOdl:,'... ...',:ldOKNWMMMMMMMMMMMMMMMMMMMMMM\
MMMMMMMMMMMMMMMMMMMMMMMMMMMMWNKOkdlc:::::::cldkOKNWMMMMMMMMMMMMMMMMMMMMMMMMMMMM\n");
}

void print_err_info(void) {
void print_err_info(void)
{
printf("Use spynix -h or spynix --help to display all valid options\n");
}

void print_hlp_info(void) {
void print_hlp_info(void)
{
print_banner();
printf("Spynix is a commandline tool for gathering info about hardware.\n\n\
\t\tInfo:\n\
Expand All @@ -86,7 +90,8 @@ void print_hlp_info(void) {
\t\t-cpu -f or -cpu --full \t- show full Central Processing Unit info\n");
}

void print_ver_info(void) {
void print_ver_info(void)
{
print_banner();
printf("spynix v4.0.0\n\nFor more info visit: https://github.com/git-user-cpp/spynix\n");
}
68 changes: 50 additions & 18 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,51 +16,83 @@
#include "hlp/hlp_info.h"
#include "net/net_info.h"

int main(int argc, char **argv) {
if(argc == 1) {
int main(int argc, char **argv)
{
if(argc == 1)
{
print_sys_info();
print_cpu_info();
print_ram_info();
print_rom_info();
} else if (argc == 2) {
if(strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) {
}
else if (argc == 2)
{
if(strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0)
{
print_hlp_info();
} else if(strcmp(argv[1], "-a") == 0 || strcmp(argv[1], "--all") == 0) {
}
else if(strcmp(argv[1], "-a") == 0 || strcmp(argv[1], "--all") == 0)
{
print_sys_info();
print_cpu_info();
print_ram_info();
print_rom_info();
} else if(strcmp(argv[1], "-sys") == 0) {
}
else if(strcmp(argv[1], "-sys") == 0)
{
print_sys_info();
} else if(strcmp(argv[1], "-cpu") == 0) {
}
else if(strcmp(argv[1], "-cpu") == 0)
{
print_cpu_info();
} else if(strcmp(argv[1], "-ram") == 0) {
}
else if(strcmp(argv[1], "-ram") == 0)
{
print_ram_info();
} else if(strcmp(argv[1], "-rom") == 0) {
}
else if(strcmp(argv[1], "-rom") == 0)
{
print_rom_info();
} else if(strcmp(argv[1], "-net") == 0) {
}
else if(strcmp(argv[1], "-net") == 0)
{
char host_name[100];
printf("Enter a hostname or IP address: ");
fgets(host_name, sizeof(host_name), stdin);
host_name[strcspn(host_name, "\n")] = '\0';

print_net_info(host_name);
} else if(strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0) {
}
else if(strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0)
{
print_ver_info();
} else if(strcmp(argv[1], "-b") == 0 || strcmp(argv[1], "--banner") == 0) {
}
else if(strcmp(argv[1], "-b") == 0 || strcmp(argv[1], "--banner") == 0)
{
print_banner();
} else if(strcmp(argv[1], "-l") == 0 || strcmp(argv[1], "--logo") == 0) {
}
else if(strcmp(argv[1], "-l") == 0 || strcmp(argv[1], "--logo") == 0)
{
print_logo();
} else {
}
else
{
print_err_info();
}
} else if(argc == 3){
if((strcmp(argv[1], "-cpu") == 0) && ((strcmp(argv[2], "-f") == 0) || (strcmp(argv[2], "--full") == 0))) {
}
else if(argc == 3)
{
if((strcmp(argv[1], "-cpu") == 0) && ((strcmp(argv[2], "-f") == 0) || (strcmp(argv[2], "--full") == 0)))
{
print_full_cpu_info();
} else {
}
else
{
print_err_info();
}
} else {
}
else
{
print_err_info();
}

Expand Down
22 changes: 15 additions & 7 deletions src/net/net_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,37 @@

#include "net_info.h"

void print_net_info(char *hostname){
void print_net_info(char *hostname)
{
struct hostent *host = gethostbyname(hostname);
struct ifaddrs *ifaddr, *ifa;
int i;

if(host == NULL){
if(host == NULL)
{
perror("gethostbyname");
exit(1);
} else {
}
else
{
printf("Host Name: %s\n", host->h_name);
printf("IP Address: ");
for(i = 0; host->h_addr_list[i] != NULL; i++){
for(i = 0; host->h_addr_list[i] != NULL; i++)
{
printf("%s ", inet_ntoa(*(struct in_addr *)host->h_addr_list[i]));
}
printf("\n");
}

if(getifaddrs(&ifaddr) == -1) {
if(getifaddrs(&ifaddr) == -1)
{
perror("getifaddrs");
exit(1);
}
for(ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next){
if(ifa->ifa_addr != NULL && ifa->ifa_addr->sa_family == AF_INET){
for(ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next)
{
if(ifa->ifa_addr != NULL && ifa->ifa_addr->sa_family == AF_INET)
{
printf("Interface: %s\n", ifa->ifa_name);
printf("Address: %s\n", inet_ntoa(((struct sockaddr_in*)ifa->ifa_addr)->sin_addr));
printf("Netmask: %s\n", inet_ntoa(((struct sockaddr_in*)ifa->ifa_netmask)->sin_addr));
Expand Down
3 changes: 2 additions & 1 deletion src/ram/ram_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

#include "ram_info.h"

void print_ram_info(void) {
void print_ram_info(void)
{
struct sysinfo sys_info;
sysinfo(&sys_info);
printf(" ____________\n");
Expand Down
6 changes: 4 additions & 2 deletions src/rom/rom_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@

#include "rom_info.h"

void print_rom_info(void) {
void print_rom_info(void)
{
struct statvfs fs_info;

printf(" ____________\n");
printf("|\n");
printf("| ROM Info:\n");
printf("|____________\n");
printf("|\n");
if (statvfs("/", &fs_info) == 0) {
if (statvfs("/", &fs_info) == 0)
{
printf("| Total Disk Space: %ld MiB\n", fs_info.f_blocks * fs_info.f_bsize
/ 1024 / 1024);
printf("| Free Disk Space: %ld MiB\n", fs_info.f_bfree * fs_info.f_bsize /
Expand Down
3 changes: 2 additions & 1 deletion src/sys/sys_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

#include "sys_info.h"

void print_sys_info(void) {
void print_sys_info(void)
{
struct utsname sys_info;
uname(&sys_info);
printf(" ____________\n");
Expand Down