Beispiel #1
0
/**
 * Very simplistic console input
 */
static void console_input(void)
{
	TCHAR inp;
	DWORD read;
	if(!ReadConsole(events[1], &inp, 1, &read, NULL))
		return;

	switch(inp) {
	case 8:
		if(console_ptr > 0) {
			console_ptr--;
			printf("\b \b");
		}
		break;
	case 13:
		printf("\n\r");
		console_buf[console_ptr++] = 0;
		console_ptr = 0;
		enable_console = 0;
		cmd_exec_unparsed(console_buf);
		break;

	default:
		if(console_ptr < sizeof(console_buf) - 1) {
			printf("%c", (char)inp);
			console_buf[console_ptr++] = inp;
		}
		break;
	}
}
/**
 * Very simplistic console input
 */
static void console_input(void)
{
	TCHAR inp;
	DWORD read;
	INPUT_RECORD rec;

	if(!ReadConsoleInput(events[1], &rec, 1, &read))
		return;

	if(read == 0)
		return;

	if(rec.EventType != KEY_EVENT)
		return;

	if(!rec.Event.KeyEvent.bKeyDown)
		return;

	inp = rec.Event.KeyEvent.uChar.AsciiChar;


	switch(inp) {
	case 8:
		if(console_ptr > 0) {
			console_ptr--;
			printf("\b \b");
		}
		break;
	case 13:
		printf("\n\r");
		console_buf[console_ptr++] = 0;
		console_ptr = 0;
		enable_console = 0;
		cmd_exec_unparsed(console_buf);
		break;

	default:
		if(console_ptr < sizeof(console_buf) - 1) {
			printf("%c", (char)inp);
			console_buf[console_ptr++] = inp;
		}
		break;
	}
}
int main(int argc, char **argv)
{
	const char *username = argc > 1 ? argv[1] : NULL;
	const char *password = argc > 2 ? argv[2] : NULL;
	int selftest = argc > 3 ? !strcmp(argv[3], "selftest") : 0;
	char username_buf[256];
	int r;
	int next_timeout = 0;

	printf("Using libspotify %s\n", sp_build_id());

	if (username == NULL) {
		printf("Username (just press enter to login with stored credentials): ");
		fflush(stdout);
		fgets(username_buf, sizeof(username_buf), stdin);
		trim(username_buf);
		if(username_buf[0] == 0) {
			username = NULL;
		} else {
			username = username_buf;
		}
	}

	if (username != NULL && password == NULL)
		password = getpass("Password: "******"Logged out\n");
	sp_session_release(g_session);
	printf("Exiting...\n");
	return 0;
}
Beispiel #4
0
int main(int argc, char **argv)
{
	const char *username = argc > 1 ? argv[1] : NULL;
	const char *password = argc > 2 ? argv[2] : NULL;
	char username_buf[256];
	int r;
	int next_timeout = 0;

	if (username == NULL) {
		printf("Username: "******"Password: ");

	pthread_mutex_init(&notify_mutex, NULL);
	pthread_cond_init(&notify_cond, NULL);
	pthread_cond_init(&prompt_cond, NULL);

	if ((r = spshell_init(username, password)) != 0)
		exit(r);

	pthread_mutex_lock(&notify_mutex);

	for (;;) {
		// Release prompt

		if (next_timeout == 0) {
			while(!notify_events && !cmdline)
				pthread_cond_wait(&notify_cond, &notify_mutex);
		} else {
			struct timespec ts;

#if _POSIX_TIMERS > 0
			clock_gettime(CLOCK_REALTIME, &ts);
#else
			struct timeval tv;
			gettimeofday(&tv, NULL);
			TIMEVAL_TO_TIMESPEC(&tv, &ts);
#endif

			ts.tv_sec += next_timeout / 1000;
			ts.tv_nsec += (next_timeout % 1000) * 1000000;

			while(!notify_events && !cmdline) {
				if(pthread_cond_timedwait(&notify_cond, &notify_mutex, &ts))
					break;
			}
		}

		// Process input from prompt
		if(cmdline) {
			char *l = cmdline;
			cmdline = NULL;
		
			pthread_mutex_unlock(&notify_mutex);
			cmd_exec_unparsed(l);
			free(l);
			pthread_mutex_lock(&notify_mutex);
		}

		// Process libspotify events
		notify_events = 0;
		pthread_mutex_unlock(&notify_mutex);

		do {
			sp_session_process_events(g_session, &next_timeout);
		} while (next_timeout == 0);

		pthread_mutex_lock(&notify_mutex);
	}
	return 0;
}