src/pspg.c
static void
check_clipboard_app(Options *opts, bool *force_refresh)
{
	*force_refresh = false;

	if (opts->clipboard_app)
		clipboard_application_id = opts->clipboard_app;

	if (!clipboard_application_id)
	{
		FILE	   *f;
		char	   *line = NULL;
		size_t		size = 0;
		int			status;
		bool		isokstr = false;
		int			retval;

		/* check wl-clipboard https://github.com/bugaevc/wl-clipboard.git */
		errno = 0;
		f = popen("wl-copy -v 2>/dev/null", "r");
		if (f)
		{
			retval = getline(&line, &size, f);
			if (retval >= 0 && line)
			{
				if (strncmp(line, "wl-clipboard", 12) == 0)
					isokstr = true;

				free(line);
				line = NULL;
				size = 0;
			}

			status = pclose(f);
			if (status == 0 && isokstr)
			{
				clipboard_application_id = 1;
				return;
			}
		}

		*force_refresh = true;

		errno = 0;
		f = popen("xclip -version 2>&1", "r");
		if (f)
		{
			retval = getline(&line, &size, f);
			if (retval >= 0 && line)
			{
				if (strncmp(line, "xclip", 5) == 0)
					isokstr = true;

				free(line);
				line = NULL;
				size = 0;
			}

			status = pclose(f);
			if (status == 0 && isokstr)
			{
				clipboard_application_id = 2;
				return;
			}
		}

		/*
		 * pbcopy has not an argument for returning
		 * version info, and without arguments, it
		 * is waiting for data. We can try to just
		 * open pipe, and close this pipe, and check
		 * the status.
		 */
		errno = 0;
		f = popen("pbcopy", "w");
		if (f)
		{
			status = pclose(f);
			if (status == 0)
			{
				clipboard_application_id = 3;
				return;
			}
		}
	}
}
/*
 * When error is detected, then better to clean screen
 */
When error is detected, then better to clean screen
When error is detected then better to clean screen
static void
check_clipboard_app(Options *opts, bool *force_refresh)
{
	*force_refresh = false;
	if (opts->clipboard_app)
		clipboard_application_id = opts->clipboard_app;
	if (!clipboard_application_id)
	{
		FILE	   *f;
		char	   *line = NULL;
		size_t		size = 0;
		int			status;
		bool		isokstr = false;
		int			retval;
		errno = 0;
		f = popen("wl-copy -v 2>/dev/null", "r");
		if (f)
		{
			retval = getline(&line, &size, f);
			if (retval >= 0 && line)
			{
				if (strncmp(line, "wl-clipboard", 12) == 0)
					isokstr = true;
				free(line);
				line = NULL;
				size = 0;
			}
			status = pclose(f);
			if (status == 0 && isokstr)
			{
				clipboard_application_id = 1;
				return;
			}
		}
		*force_refresh = true;
		errno = 0;
		f = popen("xclip -version 2>&1", "r");
		if (f)
		{
			retval = getline(&line, &size, f);
			if (retval >= 0 && line)
			{
				if (strncmp(line, "xclip", 5) == 0)
					isokstr = true;
				free(line);
				line = NULL;
				size = 0;
			}
			status = pclose(f);
			if (status == 0 && isokstr)
			{
				clipboard_application_id = 2;
				return;
			}
		}
		errno = 0;
		f = popen("pbcopy", "w");
		if (f)
		{
			status = pclose(f);
			if (status == 0)
			{
				clipboard_application_id = 3;
				return;
			}
		}
	}
}
static void check_clipboard_app ( Options * opts , bool * force_refresh ) { * force_refresh = false ; if ( opts -> clipboard_app ) clipboard_application_id = opts -> clipboard_app ; if ( ! clipboard_application_id ) { FILE * f ; char * line = NULL ; size_t size = 0 ; int status ; bool isokstr = false ; int retval ; errno = 0 ; f = popen ( " " , " " ) ; if ( f ) { retval = getline ( & line , & size , f ) ; if ( retval >= 0 && line ) { if ( strncmp ( line , " " , 12 ) == 0 ) isokstr = true ; free ( line ) ; line = NULL ; size = 0 ; } status = pclose ( f ) ; if ( status == 0 && isokstr ) { clipboard_application_id = 1 ; return ; } } * force_refresh = true ; errno = 0 ; f = popen ( " " , " " ) ; if ( f ) { retval = getline ( & line , & size , f ) ; if ( retval >= 0 && line ) { if ( strncmp ( line , " " , 5 ) == 0 ) isokstr = true ; free ( line ) ; line = NULL ; size = 0 ; } status = pclose ( f ) ; if ( status == 0 && isokstr ) { clipboard_application_id = 2 ; return ; } } errno = 0 ; f = popen ( " " , " " ) ; if ( f ) { status = pclose ( f ) ; if ( status == 0 ) { clipboard_application_id = 3 ; return ; } } } }
When error is detected, then better to clean screen
When error is detected then better to clean screen
/* check wl-clipboard https://github.com/bugaevc/wl-clipboard.git */ /*
		 * pbcopy has not an argument for returning
		 * version info, and without arguments, it
		 * is waiting for data. We can try to just
		 * open pipe, and close this pipe, and check
		 * the status.
		 */