Merge remote branch 'osp/only-directories' into homework
[pantumic.git] / src / clipboard.c
blobec4ba7472595b9651839d3c9a97c1bd68e73d765
1 /*
2 Util for external clipboard.
4 Copyright (C) 2009 The Free Software Foundation, Inc.
6 Written by:
7 Ilia Maslakon <il.smind@gmail.com>, 2010.
9 This file is part of the Midnight Commander.
11 The Midnight Commander is free software; you can redistribute it
12 and/or modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation; either version 2 of the
14 License, or (at your option) any later version.
16 The Midnight Commander is distributed in the hope that it will be
17 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
18 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24 MA 02110-1301, USA.
27 #include <config.h>
29 #include <stdio.h>
30 #include <stdlib.h>
32 #include "lib/global.h"
33 #include "lib/fileloc.h"
34 #include "lib/mcconfig.h"
35 #include "lib/util.h"
37 #include "main.h"
38 #include "src/execute.h"
40 #include "clipboard.h"
42 /*** global variables ****************************************************************************/
44 /* path to X clipboard utility */
45 char *clipboard_store_path = NULL;
46 char *clipboard_paste_path = NULL;
48 /*** file scope macro definitions ****************************************************************/
50 /*** file scope type declarations ****************************************************************/
52 /*** file scope variables ************************************************************************/
54 /*** file scope functions ************************************************************************/
55 /* --------------------------------------------------------------------------------------------- */
57 /* --------------------------------------------------------------------------------------------- */
58 /*** public functions ****************************************************************************/
59 /* --------------------------------------------------------------------------------------------- */
61 gboolean
62 copy_file_to_ext_clip (void)
64 char *tmp, *cmd;
65 int res = 0;
66 const char *d = getenv ("DISPLAY");
68 if (d == NULL || clipboard_store_path == NULL || clipboard_store_path[0] == '\0')
69 return FALSE;
71 tmp = concat_dir_and_file (mc_config_get_cache_path (), EDIT_CLIP_FILE);
72 cmd = g_strconcat (clipboard_store_path, " ", tmp, " 2>/dev/null", (char *) NULL);
74 if (cmd != NULL)
75 res = my_system (EXECUTE_AS_SHELL, shell, cmd);
77 g_free (cmd);
78 g_free (tmp);
79 return TRUE;
82 /* --------------------------------------------------------------------------------------------- */
84 gboolean
85 paste_to_file_from_ext_clip (void)
87 char *tmp, *cmd;
88 int res = 0;
89 const char *d = getenv ("DISPLAY");
91 if (d == NULL || clipboard_paste_path == NULL || clipboard_paste_path[0] == '\0')
92 return FALSE;
94 tmp = concat_dir_and_file (mc_config_get_cache_path (), EDIT_CLIP_FILE);
95 cmd = g_strconcat (clipboard_paste_path, " > ", tmp, " 2>/dev/null", (char *) NULL);
97 if (cmd != NULL)
98 res = my_system (EXECUTE_AS_SHELL, shell, cmd);
100 g_free (cmd);
101 g_free (tmp);
102 return TRUE;
105 /* --------------------------------------------------------------------------------------------- */