void print(int s) { /* Print the contents of the stack for the user. */ char buf[FILEPATH_MAX]; int i, stack_size; soc_w(s, CMD_SIZE); soc_r(s, buf, MSG_MAX); stack_size = atoi(buf); printf("%d file%s in stack\n", stack_size, PLURALS(stack_size)); for( i = 0; i < stack_size; i++ ) { soc_w(s, CMD_PICK); if( !read_status_okay(s) ) { soc_r(s, buf, FILEPATH_MAX); printf("received error `%s'\n", buf); exit(EXIT_FAILURE); } sprintf(buf, "%d", i); soc_w(s, buf); if( !read_status_okay(s) ) { soc_r(s, buf, FILEPATH_MAX); printf("error: `%s'\n", buf); exit(EXIT_FAILURE); } soc_r(s, buf, FILEPATH_MAX); char *filecolr = color_string(COLR_PATH, buf); printf("%d: %s\n", i+1, filecolr); free(filecolr); } }
static void fill_buffer(char *buf, int b) { char line[BUFFERSIZE/2]; if (b>0) { sprintf(buf, "%d bottle%s of beer on the wall, %d bottle%s of beer.\n" \ "Take one down and pass it around, ", b, PLURALS(b), b, PLURALS(b)); if (b==1) strcat(buf, "no more bottles of beer on the wall.\n"); else { sprintf(line, "%d bottle%s of beer on the wall.\n", b-1, PLURALS(b-1)); strcat(buf, line); } } else { sprintf(buf, "No more bottles of beer on the wall, no more bottles of beer.\n" \ "Go to the store and buy some more, 99 bottles of beer on the wall.\n"); } }
void multidrop(int s, int num) { /* Drop <num> files from stack. */ char buf[MSG_MAX]; int i, instack; soc_w(s, CMD_SIZE); soc_r(s, buf, MSG_MAX); instack = atoi(buf); if( num > instack ) { if( instack == 0 ) fprintf(stderr, "%s: cannot pop, file stack empty\n", program_name); else fprintf(stderr, "%s: asked to drop %d file%s, only %d in stack\n", program_name, num, PLURALS(num), instack); exit(EXIT_FAILURE); } for( i = 0; i < num; i++ ) { if( !drop(s) ) { printf("popped %d file%s\n", i, PLURALS(i)); exit(EXIT_FAILURE); } } }