4 * Copyright 1993-1998 Lucent Technologies, Inc.
6 * Permission to use, copy, modify, and distribute this software and
7 * its documentation for any purpose and without fee is hereby
8 * granted, provided that the above copyright notice appear in all
9 * copies and that both that the copyright notice and warranty
10 * disclaimer appear in supporting documentation, and that the names
11 * of Lucent Technologies any of their entities not be used in
12 * advertising or publicity pertaining to distribution of the software
13 * without specific, written prior permission.
15 * Lucent Technologies disclaims all warranties with regard to this
16 * software, including all implied warranties of merchantability and
17 * fitness. In no event shall Lucent Technologies be liable for any
18 * special, indirect or consequential damages or any damages
19 * whatsoever resulting from loss of use, data or profits, whether in
20 * an action of contract, negligence or other tortuous action, arising
21 * out of or in connection with the use or performance of this
30 #include <X11/Xproto.h>
34 GetCutNumber(interp, string, bufferPtr)
41 if (Tcl_GetInt(interp, string, &number) != TCL_OK) {
44 if ((number < 0) || (number > 7)) {
45 Tcl_AppendResult(interp, "bad buffer # \"", string, "\"", (char *)NULL);
54 RotateErrorProc(clientData, errEventPtr)
55 ClientData clientData;
56 XErrorEvent *errEventPtr;
58 int *errorPtr = clientData;
60 *errorPtr = TCL_ERROR;
65 GetOp(interp, tkwin, argc, argv)
77 if (GetCutNumber(interp, argv[2], &buffer) != TCL_OK) {
81 string = XFetchBuffer(Tk_Display(tkwin), &nBytes, buffer);
88 if (string[nBytes - 1] == '\0') {
93 for (p = string, i = 0; i < limit; i++, p++) {
94 c = (unsigned char)*p;
96 *p = ' '; /* Convert embedded NUL bytes */
99 if (limit == nBytes) {
103 * Need to copy the string into a bigger buffer so we can
104 * add a NUL byte on the end.
106 newPtr = Blt_Malloc(nBytes + 1);
108 memcpy(newPtr, string, nBytes);
109 newPtr[nBytes] = '\0';
113 Tcl_SetResult(interp, string, TCL_DYNAMIC);
119 RotateOp(interp, tkwin, argc, argv)
127 Tk_ErrorHandler handler;
129 count = 1; /* Default: rotate one position */
131 if (Tcl_GetInt(interp, argv[2], &count) != TCL_OK) {
134 if ((count < 0) || (count > 8)) {
135 Tcl_AppendResult(interp, "bad rotate count \"", argv[2], "\"",
141 handler = Tk_CreateErrorHandler(Tk_Display(tkwin), BadMatch,
142 X_RotateProperties, -1, RotateErrorProc, &result);
143 XRotateBuffers(Tk_Display(tkwin), count);
144 Tk_DeleteErrorHandler(handler);
145 XSync(Tk_Display(tkwin), False);
146 if (result != TCL_OK) {
147 Tcl_AppendResult(interp, "can't rotate cutbuffers unless all are set",
156 SetOp(interp, tkwin, argc, argv)
166 if (GetCutNumber(interp, argv[3], &buffer) != TCL_OK) {
170 XStoreBuffer(Tk_Display(tkwin), argv[2], strlen(argv[2]) + 1, buffer);
175 *--------------------------------------------------------------
177 * BLT Sub-command specification:
179 * - Name of the sub-command.
180 * - Minimum number of characters needed to unambiguously
181 * recognize the sub-command.
182 * - Pointer to the function to be called for the sub-command.
183 * - Minimum number of arguments accepted.
184 * - Maximum number of arguments accepted.
185 * - String to be displayed for usage.
187 *--------------------------------------------------------------
189 static Blt_OpSpec cbOps[] =
191 {"get", 1, (Blt_Op)GetOp, 2, 3, "?buffer?",},
192 {"rotate", 1, (Blt_Op)RotateOp, 2, 3, "?count?",},
193 {"set", 1, (Blt_Op)SetOp, 3, 4, "value ?buffer?",},
195 static int numCbOps = sizeof(cbOps) / sizeof(Blt_OpSpec);
199 *----------------------------------------------------------------------
203 * This procedure is invoked to process the "cutbuffer" Tcl
204 * command. See the user documentation for details on what it does.
207 * A standard Tcl result.
212 *----------------------------------------------------------------------
216 CutbufferCmd(clientData, interp, argc, argv)
217 ClientData clientData; /* Main window associated with
219 Tcl_Interp *interp; /* Current interpreter. */
220 int argc; /* Number of arguments. */
221 char **argv; /* Argument strings. */
227 proc = Blt_GetOp(interp, numCbOps, cbOps, BLT_OP_ARG1, argc, argv, 0);
231 tkwin = Tk_MainWindow(interp);
232 result = (*proc) (interp, tkwin, argc, argv);
237 *----------------------------------------------------------------------
239 * Blt_CutbufferInit --
241 * This procedure is invoked to initialize the "cutbuffer" Tcl
242 * command. See the user documentation for details on what it does.
245 * A standard Tcl result.
250 *----------------------------------------------------------------------
253 Blt_CutbufferInit(interp)
256 static Blt_CmdSpec cmdSpec =
257 {"cutbuffer", CutbufferCmd,};
259 if (Blt_InitCmd(interp, "blt", &cmdSpec) == NULL) {
265 #endif /* NO_CUTBUFFER */