Added dynamic input allocation and cleaned up some trailing whitespace.

This commit is contained in:
Bryce Reitano 2014-04-24 20:33:09 -06:00
parent 3919a0045c
commit f65e527f9d

31
bar.c
View File

@ -329,7 +329,7 @@ parse (char *text)
case 'c': pos_x = 0; align = ALIGN_C; break; case 'c': pos_x = 0; align = ALIGN_C; break;
case 'r': pos_x = 0; align = ALIGN_R; break; case 'r': pos_x = 0; align = ALIGN_R; break;
case 'A': case 'A':
area_add(p, end, &p, cur_mon, pos_x, align); area_add(p, end, &p, cur_mon, pos_x, align);
break; break;
@ -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 */
@ -1030,7 +1051,7 @@ main (int argc, char **argv)
switch (ev->response_type & 0x7F) { switch (ev->response_type & 0x7F) {
case XCB_EXPOSE: case XCB_EXPOSE:
if (expose_ev->count == 0) if (expose_ev->count == 0)
redraw = true; redraw = true;
break; break;
case XCB_BUTTON_PRESS: case XCB_BUTTON_PRESS: