aboutsummaryrefslogtreecommitdiffstats
path: root/sway/main.c
diff options
context:
space:
mode:
authorLibravatar Ian Fan <ianfan0@gmail.com>2018-12-09 12:09:11 +0000
committerLibravatar Ian Fan <ianfan0@gmail.com>2019-01-01 09:01:25 +0000
commita82b8a3c14e45697708e57f8cb27a8fc6cf31839 (patch)
tree5e30327566fb6f30bd6d319f7b8a96226683e986 /sway/main.c
parentstringop.c: rewrite strip_whitespace (diff)
downloadsway-a82b8a3c14e45697708e57f8cb27a8fc6cf31839.tar.gz
sway-a82b8a3c14e45697708e57f8cb27a8fc6cf31839.tar.zst
sway-a82b8a3c14e45697708e57f8cb27a8fc6cf31839.zip
Remove readline.c
All occurrences of read_line have been replaced by getline. peek_line has been absorbed into detect_brace.
Diffstat (limited to 'sway/main.c')
-rw-r--r--sway/main.c68
1 files changed, 28 insertions, 40 deletions
diff --git a/sway/main.c b/sway/main.c
index f70e751d..d08c0457 100644
--- a/sway/main.c
+++ b/sway/main.c
@@ -3,6 +3,7 @@
3#include <pango/pangocairo.h> 3#include <pango/pangocairo.h>
4#include <signal.h> 4#include <signal.h>
5#include <stdbool.h> 5#include <stdbool.h>
6#include <stdio.h>
6#include <stdlib.h> 7#include <stdlib.h>
7#include <stdio.h> 8#include <stdio.h>
8#include <string.h> 9#include <string.h>
@@ -22,7 +23,6 @@
22#include "sway/ipc-server.h" 23#include "sway/ipc-server.h"
23#include "ipc-client.h" 24#include "ipc-client.h"
24#include "log.h" 25#include "log.h"
25#include "readline.h"
26#include "stringop.h" 26#include "stringop.h"
27#include "util.h" 27#include "util.h"
28 28
@@ -47,31 +47,28 @@ void detect_raspi(void) {
47 if (!f) { 47 if (!f) {
48 return; 48 return;
49 } 49 }
50 char *line; 50 char *line = NULL;
51 while(!feof(f)) { 51 size_t line_size = 0;
52 if (!(line = read_line(f))) { 52 while (getline(&line, &line_size, f) != -1) {
53 break;
54 }
55 if (strstr(line, "Raspberry Pi")) { 53 if (strstr(line, "Raspberry Pi")) {
56 raspi = true; 54 raspi = true;
55 break;
57 } 56 }
58 free(line);
59 } 57 }
60 fclose(f); 58 fclose(f);
61 FILE *g = fopen("/proc/modules", "r"); 59 FILE *g = fopen("/proc/modules", "r");
62 if (!g) { 60 if (!g) {
61 free(line);
63 return; 62 return;
64 } 63 }
65 bool vc4 = false; 64 bool vc4 = false;
66 while (!feof(g)) { 65 while (getline(&line, &line_size, g) != -1) {
67 if (!(line = read_line(g))) {
68 break;
69 }
70 if (strstr(line, "vc4")) { 66 if (strstr(line, "vc4")) {
71 vc4 = true; 67 vc4 = true;
68 break;
72 } 69 }
73 free(line);
74 } 70 }
71 free(line);
75 fclose(g); 72 fclose(g);
76 if (!vc4 && raspi) { 73 if (!vc4 && raspi) {
77 fprintf(stderr, "\x1B[1;31mWarning: You have a " 74 fprintf(stderr, "\x1B[1;31mWarning: You have a "
@@ -86,13 +83,10 @@ void detect_proprietary(int allow_unsupported_gpu) {
86 if (!f) { 83 if (!f) {
87 return; 84 return;
88 } 85 }
89 while (!feof(f)) { 86 char *line = NULL;
90 char *line; 87 size_t line_size = 0;
91 if (!(line = read_line(f))) { 88 while (getline(&line, &line_size, f) != -1) {
92 break;
93 }
94 if (strstr(line, "nvidia")) { 89 if (strstr(line, "nvidia")) {
95 free(line);
96 if (allow_unsupported_gpu) { 90 if (allow_unsupported_gpu) {
97 wlr_log(WLR_ERROR, 91 wlr_log(WLR_ERROR,
98 "!!! Proprietary Nvidia drivers are in use !!!"); 92 "!!! Proprietary Nvidia drivers are in use !!!");
@@ -106,7 +100,6 @@ void detect_proprietary(int allow_unsupported_gpu) {
106 break; 100 break;
107 } 101 }
108 if (strstr(line, "fglrx")) { 102 if (strstr(line, "fglrx")) {
109 free(line);
110 if (allow_unsupported_gpu) { 103 if (allow_unsupported_gpu) {
111 wlr_log(WLR_ERROR, 104 wlr_log(WLR_ERROR,
112 "!!! Proprietary AMD drivers are in use !!!"); 105 "!!! Proprietary AMD drivers are in use !!!");
@@ -118,8 +111,8 @@ void detect_proprietary(int allow_unsupported_gpu) {
118 } 111 }
119 break; 112 break;
120 } 113 }
121 free(line);
122 } 114 }
115 free(line);
123 fclose(f); 116 fclose(f);
124} 117}
125 118
@@ -146,6 +139,19 @@ static void log_env(void) {
146 } 139 }
147} 140}
148 141
142static void log_file(FILE *f) {
143 char *line = NULL;
144 size_t line_size = 0;
145 ssize_t nread;
146 while ((nread = getline(&line, &line_size, f)) != -1) {
147 if (line[nread - 1] == '\n') {
148 line[nread - 1] = '\0';
149 }
150 wlr_log(WLR_INFO, "%s", line);
151 }
152 free(line);
153}
154
149static void log_distro(void) { 155static void log_distro(void) {
150 const char *paths[] = { 156 const char *paths[] = {
151 "/etc/lsb-release", 157 "/etc/lsb-release",
@@ -158,16 +164,7 @@ static void log_distro(void) {
158 FILE *f = fopen(paths[i], "r"); 164 FILE *f = fopen(paths[i], "r");
159 if (f) { 165 if (f) {
160 wlr_log(WLR_INFO, "Contents of %s:", paths[i]); 166 wlr_log(WLR_INFO, "Contents of %s:", paths[i]);
161 while (!feof(f)) { 167 log_file(f);
162 char *line;
163 if (!(line = read_line(f))) {
164 break;
165 }
166 if (*line) {
167 wlr_log(WLR_INFO, "%s", line);
168 }
169 free(line);
170 }
171 fclose(f); 168 fclose(f);
172 } 169 }
173 } 170 }
@@ -179,16 +176,7 @@ static void log_kernel(void) {
179 wlr_log(WLR_INFO, "Unable to determine kernel version"); 176 wlr_log(WLR_INFO, "Unable to determine kernel version");
180 return; 177 return;
181 } 178 }
182 while (!feof(f)) { 179 log_file(f);
183 char *line;
184 if (!(line = read_line(f))) {
185 break;
186 }
187 if (*line) {
188 wlr_log(WLR_INFO, "%s", line);
189 }
190 free(line);
191 }
192 pclose(f); 180 pclose(f);
193} 181}
194 182