/** * @brief Called with mpd's init_settings method. */ void scrob_init(void) { last_artist[0] = '\0'; last_title[0] = '\0'; last_etime = 0; last_ttime = 0; scrob_shaked = 0; scrob_sessionid[0] = '\0'; scrob_host = get_char_key("mpd", "scrob_host", NULL); scrob_port = get_int_key("mpd", "scrob_port", 80); scrob_enabled = get_bool_key("mpd", "scrob_enabled", 0); scrob_user = get_char_key("mpd", "scrob_user", NULL); scrob_pass = get_char_key("mpd", "scrob_pass", NULL); if (scrob_host == NULL) scrob_enabled = 0; if (scrob_enabled) { if ((hptr = gethostbyname(scrob_host)) == NULL) { fprintf(stderr, "mpdscrob: Could not gethostbyname(%s)\n", scrob_host); scrob_enabled = 0; return; } memcpy(&server.sin_addr, hptr->h_addr_list[0], hptr->h_length); server.sin_family = AF_INET; server.sin_port = htons((short) scrob_port); } }
void print_telephone_words_(char* prefix, int prefix_size, int remaining[], int remain_size) { if (remain_size == 0) { printf("%s\n", prefix); return; } int* remaining_new = (int*)malloc(sizeof(int)*remain_size-1); int i; for(i=0; i<remain_size-1;i++) remaining_new[i] = remaining[i+1]; // can declare this outside of the loop since new_prefix wont get overwritten // until next loop iteration at which point the recursive call has completed // and the word has been printed. would not work if words were returned in // base case unless prefix was copied into new str char* new_prefix = (char*)malloc(sizeof(char)*prefix_size+2); for(i=0; i<LETTERS_PER_KEY; i++) { char letter = get_char_key(remaining[0], i); sprintf(new_prefix, "%s%c", prefix, letter); // terminates with NULL print_telephone_words_(new_prefix, prefix_size+1, remaining_new, remain_size-1); } free(remaining_new); free(new_prefix); }
/** * @brief Start listening on the configured host and port. */ static int donky_listen(void) { const char *host = get_char_key("daemon", "host", "0.0.0.0"); int port = get_int_key("daemon", "port", 7000); donky_sock = create_tcp_listener(host, port); return donky_sock; }