Add some code

windows
Nakidai 2023-11-19 17:14:42 +03:00
parent 56aeea219c
commit cb0f4619f4
1 changed files with 15 additions and 15 deletions

30
main.c
View File

@ -39,23 +39,14 @@ void getuptime(char *buffer, int max_length)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
if (argc > 2) die(1, "usage: %s [artname]\n", argv[0]);
struct utsname uname_buf;
char hostname[max_hostname_length];
char username[max_username_length];
char uptime[max_uptime_length];
int i;
char **art = NULL; char **art = NULL;
if (argc > 2)
gethostname(hostname, max_hostname_length);
getlogin_r(username, max_username_length);
getuptime(uptime, max_uptime_length);
if (argc == 2)
{ {
for (i = 0; i < sizeof(arts)/sizeof(struct art_entry); ++i) die(1, "usage: %s [artname]\n", argv[0]);
}
else if (argc == 2)
{
for (int i = 0; i < sizeof(arts)/sizeof(struct art_entry); ++i)
if (!strcmp(arts[i].name, argv[1])) { art = arts[i].art; break; } if (!strcmp(arts[i].name, argv[1])) { art = arts[i].art; break; }
if (!art) die(1, "Art %s not found\n", argv[1]); if (!art) die(1, "Art %s not found\n", argv[1]);
} else } else
@ -63,7 +54,16 @@ int main(int argc, char **argv)
art = arts[0].art; art = arts[0].art;
} }
struct utsname uname_buf;
char hostname[max_hostname_length];
char username[max_username_length];
char uptime[max_uptime_length];
gethostname(hostname, max_hostname_length);
getlogin_r(username, max_username_length);
getuptime(uptime, max_uptime_length);
uname(&uname_buf); uname(&uname_buf);
printf("%s %s@%s\n", art[0], username, hostname); printf("%s %s@%s\n", art[0], username, hostname);
printf("%s --\n", art[1]); printf("%s --\n", art[1]);
printf("%s %s %s\n", art[2], uname_buf.sysname, uname_buf.release); printf("%s %s %s\n", art[2], uname_buf.sysname, uname_buf.release);