Added dynamic input allocation and cleaned up some trailing whitespace.
This commit is contained in:
parent
3919a0045c
commit
f65e527f9d
27
bar.c
27
bar.c
|
@ -939,6 +939,26 @@ parse_font_list (char *str)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char*
|
||||||
|
getInput(FILE* file, size_t size) {
|
||||||
|
char *input;
|
||||||
|
int ch;
|
||||||
|
size_t len = 0;
|
||||||
|
input = realloc(NULL, sizeof(char)*size);
|
||||||
|
|
||||||
|
if(!input)return input;
|
||||||
|
while(EOF!=(ch=fgetc(file)) && ch != '\n') {
|
||||||
|
input[len++]=ch;
|
||||||
|
if(len==size) {
|
||||||
|
input = realloc(input, sizeof(char)*(size*=2));
|
||||||
|
if(!input)return input;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
input[len++]='\0';
|
||||||
|
return realloc(input, sizeof(char)*len);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
@ -949,7 +969,7 @@ main (int argc, char **argv)
|
||||||
xcb_generic_event_t *ev;
|
xcb_generic_event_t *ev;
|
||||||
xcb_expose_event_t *expose_ev;
|
xcb_expose_event_t *expose_ev;
|
||||||
xcb_button_press_event_t *press_ev;
|
xcb_button_press_event_t *press_ev;
|
||||||
char input[2048] = {0, };
|
char *input;
|
||||||
bool permanent = false;
|
bool permanent = false;
|
||||||
int geom_v[4] = { -1, -1, 0, 0 };
|
int geom_v[4] = { -1, -1, 0, 0 };
|
||||||
|
|
||||||
|
@ -1018,10 +1038,11 @@ main (int argc, char **argv)
|
||||||
else break; /* ...bail out */
|
else break; /* ...bail out */
|
||||||
}
|
}
|
||||||
if (pollin[0].revents & POLLIN) { /* New input, process it */
|
if (pollin[0].revents & POLLIN) { /* New input, process it */
|
||||||
if (fgets(input, sizeof(input), stdin) == NULL)
|
input = getInput(stdin, 1024);
|
||||||
break; /* EOF received */
|
if (input == NULL) break; /* EOF recieved */
|
||||||
|
|
||||||
parse(input);
|
parse(input);
|
||||||
|
free(input);
|
||||||
redraw = true;
|
redraw = true;
|
||||||
}
|
}
|
||||||
if (pollin[1].revents & POLLIN) { /* Xserver broadcasted an event */
|
if (pollin[1].revents & POLLIN) { /* Xserver broadcasted an event */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user