Add dynamic length of the status bar

Add dynamic length of the status bar.
Fix going outside the array.
This commit is contained in:
Arseniy Romenskiy 2026-02-25 14:25:02 +03:00
parent 4b12d202b6
commit 773e6c99d7

20
main.c
View file

@ -5,24 +5,28 @@
#include <sys/wait.h>
#include <string.h>
#define MSGSIZE 64
char *SB = {"|||||||||| "};
int x = 20;
int main() {
char *SB = malloc(x*2);
for(int i = 0; i != x*2; i++){
if (i < x) SB[i] = '|';
else SB[i] = ' ';
}
int B[8];
int Bm[8] = {0};
int Bm_pre[8] = {0};
int ret;
int p[2], i;
pipe(p);
pid_t a = fork();
char *sas[] = {"cava", "-p", "/home/romenskiy2012/.config/cava/band8.conf", NULL};
char inbuf[MSGSIZE];
if (a == 0) {
if (dup2(p[1], STDOUT_FILENO) == -1) { perror("dup2"); _exit(127);}
close(p[0]); // A не читает
close(p[0]);
close(p[1]);
execvp(sas[0], sas);
_exit(127);
@ -31,12 +35,14 @@ int main() {
FILE *r = fdopen(p[0], "r");
for (int i = 0;1 == 1;i++){
fgets(inbuf, sizeof inbuf, r);
ret = sscanf(inbuf, "%i %i %i %i %i %i %i %i", &B[0], &B[1], &B[2], &B[3], &B[4], &B[5], &B[6], &B[7]);
for (int i = 0; i != 10; i++){
ret = sscanf(inbuf, "%i %i %i %i %i %i %i %i",
&B[0], &B[1], &B[2], &B[3], &B[4], &B[5], &B[6], &B[7]);
for (int i = 0; i != 8; i++){
if (B[i] > Bm_pre[i]) Bm_pre[i] = B[i];
}
for (int i = 0; i != 8; i++){
printf("B%i [%.*s] OUT: %3d PK: %3d\n",i, 10, SB + 10 + (B[i]/10*-1), B[i], Bm[i]);
printf("B%i [%.*s] OUT: %3d PK: %3d\n", i, x, SB + x + (B[i]*x/100*-1), B[i], Bm[i]);
}
printf("\033[2J\033[H");
if (i >= 10){