xref: /OK3568_Linux_fs/external/xserver/hw/xwin/winclipboard/xwinclip.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved.
3  *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved.
4  *Copyright (C) Colin Harrison 2005-2008
5  *
6  *Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files (the
8  *"Software"), to deal in the Software without restriction, including
9  *without limitation the rights to use, copy, modify, merge, publish,
10  *distribute, sublicense, and/or sell copies of the Software, and to
11  *permit persons to whom the Software is furnished to do so, subject to
12  *the following conditions:
13  *
14  *The above copyright notice and this permission notice shall be
15  *included in all copies or substantial portions of the Software.
16  *
17  *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20  *NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
21  *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
22  *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23  *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  *
25  *Except as contained in this notice, the name of the copyright holder(s)
26  *and author(s) shall not be used in advertising or otherwise to promote
27  *the sale, use or other dealings in this Software without prior written
28  *authorization from the copyright holder(s) and author(s).
29  *
30  * Authors:	Harold L Hunt II
31  *              Colin Harrison
32  */
33 
34 #ifdef HAVE_XWIN_CONFIG_H
35 #include <xwin-config.h>
36 #endif
37 
38 /*
39  * Including any server header might define the macro _XSERVER64 on 64 bit machines.
40  * That macro must _NOT_ be defined for Xlib client code, otherwise bad things happen.
41  * So let's undef that macro if necessary.
42  */
43 #ifdef _XSERVER64
44 #undef _XSERVER64
45 #endif
46 
47 #include <stdio.h>
48 #include <stdlib.h>
49 #include <string.h>
50 
51 /* X headers */
52 #include <X11/Xlib.h>
53 #ifdef X_LOCALE
54 #include <X11/Xlocale.h>
55 #else /* X_LOCALE */
56 #include <locale.h>
57 #endif /* X_LOCALE */
58 
59 #include "winclipboard.h"
60 
61 /*
62  * Main function
63  */
64 
65 int
main(int argc,char * argv[])66 main (int argc, char *argv[])
67 {
68   int			i;
69   char			*pszDisplay = NULL;
70   int			fUnicodeClipboard = 1;
71 
72   /* Parse command-line parameters */
73   for (i = 1; i < argc; ++i)
74     {
75       /* Look for -display "display_name" or --display "display_name" */
76       if (i < argc - 1
77 	  && (!strcmp (argv[i], "-display")
78 	      || !strcmp (argv[i], "--display")))
79 	{
80 	  /* Grab a pointer to the display parameter */
81 	  pszDisplay = argv[i + 1];
82 
83 	  /* Skip the display argument */
84 	  i++;
85 	  continue;
86 	}
87 
88       /* Look for -nounicodeclipboard */
89       if (!strcmp (argv[i], "-nounicodeclipboard"))
90 	{
91 	  fUnicodeClipboard = 0;
92 	  continue;
93 	}
94 
95       /* Look for -noprimary */
96       if (!strcmp (argv[i], "-noprimary"))
97 	{
98 	  fPrimarySelection = False;
99 	  continue;
100 	}
101 
102       /* Yack when we find a parameter that we don't know about */
103       printf ("Unknown parameter: %s\nExiting.\n", argv[i]);
104       exit (1);
105     }
106 
107   /* Do we have Unicode support? */
108   if (fUnicodeClipboard)
109     {
110       printf ("Unicode clipboard I/O\n");
111     }
112   else
113     {
114       printf ("Non Unicode clipboard I/O\n");
115     }
116 
117   /* Apply locale specified in the LANG environment variable */
118   if (!setlocale (LC_ALL, ""))
119     {
120       printf ("setlocale() error\n");
121       exit (1);
122     }
123 
124   /* See if X supports the current locale */
125   if (XSupportsLocale () == False)
126     {
127       printf ("Locale not supported by X, falling back to 'C' locale.\n");
128       setlocale(LC_ALL, "C");
129     }
130 
131   winClipboardProc(fUnicodeClipboard, pszDisplay);
132 
133   return 0;
134 }
135