fordon_greeman / sfetch

fix build system Browse files
theidioticdev committed 27d ago parent 8ac9cc1 commit 2e3254aff8262e42834ce4913d033388126452b4
Showing 3 changed files with 23 additions and 137 deletions. UnifiedSplit
+23 −26 bs.c
@@ -8,33 +8,31 @@
8 #define PROG_NAME "sfetch" 8 #define PROG_NAME "sfetch"
9 #define DEST "/usr/local/bin" 9 #define DEST "/usr/local/bin"
10 10
11 -/* helper fn for running commands via execvp */
12 int 11 int
13 runCmd (char *const argv[]) 12 runCmd (char *const argv[])
14 { 13 {
15 - pid_t pid = fork(); 14 + pid_t pid = fork();
16 - if (pid == 0) 15 + if (pid == 0)
17 - { 16 + {
18 - execvp(argv[0], argv); 17 + execvp(argv[0], argv);
19 - perror("execvp failed"); 18 + perror("execvp failed");
20 - _exit(1); 19 + _exit(1);
21 - } else if (pid > 0) { 20 + } else if (pid > 0) {
22 - int status; 21 + int status;
23 - waitpid(pid, &status, 0); 22 + waitpid(pid, &status, 0);
24 - return WIFEXITED(status) && WEXITSTATUS(status) == 0; 23 + return WIFEXITED(status) && WEXITSTATUS(status) == 0;
25 - } 24 + }
26 - return 0; 25 + return 0;
27 } 26 }
28 27
29 -/* build fn */
30 int 28 int
31 build (void) 29 build (void)
32 { 30 {
33 char *const buildCmd[] = { 31 char *const buildCmd[] = {
34 - CC, "-Wall", "-Wextra", "-O3", "src/main.c", "-o", PROG_NAME, NULL 32 + CC, "-O3", "sfetch.c", "-o", PROG_NAME, NULL
35 }; 33 };
36 34
37 - printf ("[BUILD]: " CC " -Wall -Wextra -O3 src/main.c -o %s\n", PROG_NAME); 35 + printf ("[BUILD]: " CC " -O3 sfetch.c -o %s\n", PROG_NAME);
38 if (!runCmd (buildCmd)) 36 if (!runCmd (buildCmd))
39 { 37 {
40 fprintf (stderr, "[ERROR]: compilation failed\n"); 38 fprintf (stderr, "[ERROR]: compilation failed\n");
@@ -43,7 +41,7 @@ build (void)
43 printf ("[SUCCESS]: compiled successfully\n"); 41 printf ("[SUCCESS]: compiled successfully\n");
44 return 1; 42 return 1;
45 } 43 }
46 -/* install fn */ 44 +
47 int 45 int
48 install (void) 46 install (void)
49 { 47 {
@@ -64,15 +62,14 @@ install (void)
64 return 1; 62 return 1;
65 } 63 }
66 64
67 -/* uninstall fn */
68 int 65 int
69 uninstall (void) 66 uninstall (void)
70 { 67 {
71 if (remove(DEST "/" PROG_NAME) != 0) 68 if (remove(DEST "/" PROG_NAME) != 0)
72 - { 69 +{
73 fprintf(stderr, "[ERROR]: uninstall failed.\n"); 70 fprintf(stderr, "[ERROR]: uninstall failed.\n");
74 return 0; 71 return 0;
75 - } 72 + }
76 printf("[SUCCESS]: uninstalled successfully\n"); 73 printf("[SUCCESS]: uninstalled successfully\n");
77 return 1; 74 return 1;
78 } 75 }
@@ -81,19 +78,19 @@ int
81 main (int argc, char **argv) 78 main (int argc, char **argv)
82 { 79 {
83 if (argc < 2 || strcmp(argv[1], "--build-only") == 0) 80 if (argc < 2 || strcmp(argv[1], "--build-only") == 0)
84 - { 81 + {
85 return build() ? 0 : 1; 82 return build() ? 0 : 1;
86 - } 83 + }
87 84
88 if (strcmp(argv[1], "--install") == 0) 85 if (strcmp(argv[1], "--install") == 0)
89 - { 86 + {
90 return install() ? 0 : 1; 87 return install() ? 0 : 1;
91 - } 88 + }
92 89
93 if (strcmp(argv[1], "--uninstall") == 0) 90 if (strcmp(argv[1], "--uninstall") == 0)
94 - { 91 + {
95 return uninstall() ? 0 : 1; 92 return uninstall() ? 0 : 1;
96 - } 93 + }
97 fprintf(stderr, "Unknown argument: %s\n", argv[1]); 94 fprintf(stderr, "Unknown argument: %s\n", argv[1]);
98 return 1; 95 return 1;
99 } 96 }
+0 −0 build Binary files a/build and b/build differ
+0 −111 src/main.c deleted file mode 100755
@@ -1,111 +0,0 @@
1 -#include <stdio.h>
2 -#include <sys/utsname.h>
3 -#include <string.h>
4 -#include <unistd.h>
5 -#include <stdlib.h>
6 -
7 -#define C_RESET "\033[0m"
8 -#define C_BOLD "\033[1m"
9 -#define C_BLUE "\033[1;34m"
10 -#define C_YELLOW "\033[1;33m"
11 -#define C_CYAN "\033[1;36m"
12 -#define C_GREEN "\033[1;32m"
13 -#define C_RED "\033[1;31m"
14 -#define C_PURPLE "\033[1;35m"
15 -
16 -#define ENABLE_ASCII 1
17 -
18 -const char *version = "0.1.5";
19 -
20 -void
21 -printAscii(void)
22 -{
23 -#if ENABLE_ASCII
24 - static const char asciiArt[] =
25 - " ___ \n"
26 - " (.. | \n"
27 - " (<> | \n"
28 - " / __ \\ \n"
29 - " ( / \\ /| \n"
30 - " _/\\ __)/_) \n"
31 - " \\/-____\\/ ";
32 - printf(C_YELLOW "%s" C_RESET "\n\n", asciiArt);
33 -#endif
34 -}
35 -void
36 -printOS(void)
37 -{
38 -#ifdef __linux__
39 - FILE *fp = fopen("/etc/os-release", "r");
40 - if (!fp)
41 - {
42 - printf(C_CYAN "OS: " C_RESET "Generic Linux\n");
43 - return;
44 - }
45 - char line[512];
46 - while (fgets(line, sizeof(line), fp))
47 - {
48 - if(strncmp(line, "PRETTY_NAME=", 12) == 0)
49 - {
50 - char *name = line + 12;
51 - if (*name == '"') name++;
52 - size_t len = strlen(name);
53 - if (len > 0 && name[len - 1] == '\n') name[--len] = '\0';
54 - if (len > 0 && name[len - 1] == '"') name[--len] = '\0';
55 - printf(C_CYAN "OS: " C_RESET "%s\n", name);
56 - fclose(fp);
57 - return;
58 - }
59 - }
60 - fclose(fp);
61 - printf(C_CYAN "OS: " C_RESET "Generic Linux\n");
62 -#else
63 - struct utsname otherOS;
64 - if (uname(&otherOS) != 0)
65 - {
66 - perror("uname");
67 - return;
68 - }
69 - printf(C_CYAN "OS: " C_RESET "%s\n", otherOS.sysname);
70 -#endif
71 -}
72 -
73 -int
74 -printStats(void)
75 -{
76 - char *wm = getenv("XDG_CURRENT_DESKTOP");
77 - if (!wm)
78 - {
79 - wm = getenv("DESKTOP_SESSION");
80 - }
81 - char *session = getenv("XDG_SESSION_TYPE");
82 - struct utsname info;
83 - if (uname(&info) != 0)
84 - {
85 - perror("uname");
86 - return 1;
87 - }
88 - printOS();
89 - printf(C_GREEN "Kernel: " C_RESET "%s %s\n",info.sysname, info.release);
90 - printf(C_BLUE "Host: " C_RESET "%s\n", info.nodename);
91 - printf(C_RED "WM: " C_RESET "%s (%s)\n", wm ? wm : "unknown / tty", session ? session : "unknown");
92 - return 0;
93 -}
94 -
95 -int
96 -main(int argc, char **argv)
97 -{
98 - for (int i = 1; i < argc; i++)
99 - {
100 - if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0)
101 - {
102 - printf("sfetch-%s\n", version);
103 - return 0;
104 - }
105 - fprintf(stderr, "unknown argument: %s\nusage: %s [-v]\n", argv[i], argv[0]);
106 - return 1;
107 - }
108 - printAscii();
109 - printStats();
110 - return 0;
111 -}