summaryrefslogtreecommitdiffstats
path: root/tk8.6/macosx/tkMacOSXKeyEvent.c
diff options
context:
space:
mode:
Diffstat (limited to 'tk8.6/macosx/tkMacOSXKeyEvent.c')
-rw-r--r--tk8.6/macosx/tkMacOSXKeyEvent.c743
1 files changed, 0 insertions, 743 deletions
diff --git a/tk8.6/macosx/tkMacOSXKeyEvent.c b/tk8.6/macosx/tkMacOSXKeyEvent.c
deleted file mode 100644
index 31fffa1..0000000
--- a/tk8.6/macosx/tkMacOSXKeyEvent.c
+++ /dev/null
@@ -1,743 +0,0 @@
-/*
- * tkMacOSXKeyEvent.c --
- *
- * This file implements functions that decode & handle keyboard events on
- * MacOS X.
- *
- * Copyright 2001-2009, Apple Inc.
- * Copyright (c) 2006-2009 Daniel A. Steffen <das@users.sourceforge.net>
- * Copyright (c) 2012 Adrian Robert.
- * Copyright 2015 Marc Culler.
- *
- * See the file "license.terms" for information on usage and redistribution of
- * this file, and for a DISCLAIMER OF ALL WARRANTIES.
- */
-
-#include "tkMacOSXPrivate.h"
-#include "tkMacOSXEvent.h"
-#include "tkMacOSXConstants.h"
-
-/*
-#ifdef TK_MAC_DEBUG
-#define TK_MAC_DEBUG_KEYBOARD
-#endif
-*/
-#define NS_KEYLOG 0
-
-
-static Tk_Window grabWinPtr = NULL;
- /* Current grab window, NULL if no grab. */
-static Tk_Window keyboardGrabWinPtr = NULL;
- /* Current keyboard grab window. */
-static NSWindow *keyboardGrabNSWindow = nil;
- /* NSWindow for the current keyboard grab window. */
-static NSModalSession modalSession = nil;
-
-static BOOL processingCompose = NO;
-static BOOL finishedCompose = NO;
-
-static int caret_x = 0, caret_y = 0, caret_height = 0;
-
-static void setupXEvent(XEvent *xEvent, NSWindow *w, unsigned int state);
-static unsigned isFunctionKey(unsigned int code);
-
-unsigned short releaseCode;
-
-
-#pragma mark TKApplication(TKKeyEvent)
-
-@implementation TKApplication(TKKeyEvent)
-
-- (NSEvent *) tkProcessKeyEvent: (NSEvent *) theEvent
-{
-#ifdef TK_MAC_DEBUG_EVENTS
- TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, theEvent);
-#endif
- NSWindow* w;
- NSEventType type = [theEvent type];
- NSUInteger modifiers, len = 0;
- BOOL repeat = NO;
- unsigned short keyCode;
- NSString *characters = nil, *charactersIgnoringModifiers = nil;
- static NSUInteger savedModifiers = 0;
- static NSMutableArray *nsEvArray;
-
- if (nsEvArray == nil)
- {
- nsEvArray = [[NSMutableArray alloc] initWithCapacity: 1];
- processingCompose = NO;
- }
-
- w = [theEvent window];
- TkWindow *winPtr = TkMacOSXGetTkWindow(w);
- Tk_Window tkwin = (Tk_Window) winPtr;
- XEvent xEvent;
-
- if (!winPtr) {
- return theEvent;
- }
-
- switch (type) {
- case NSKeyUp:
- /*Fix for bug #1ba71a86bb: key release firing on key press.*/
- setupXEvent(&xEvent, w, 0);
- xEvent.xany.type = KeyRelease;
- xEvent.xkey.keycode = releaseCode;
- xEvent.xany.serial = LastKnownRequestProcessed(Tk_Display(tkwin));
- case NSKeyDown:
- repeat = [theEvent isARepeat];
- characters = [theEvent characters];
- charactersIgnoringModifiers = [theEvent charactersIgnoringModifiers];
- len = [charactersIgnoringModifiers length];
- case NSFlagsChanged:
- modifiers = [theEvent modifierFlags];
- keyCode = [theEvent keyCode];
-
-#if defined(TK_MAC_DEBUG_EVENTS) || NS_KEYLOG == 1
- TKLog(@"-[%@(%p) %s] r=%d mods=%u '%@' '%@' code=%u c=%d %@ %d", [self class], self, _cmd, repeat, modifiers, characters, charactersIgnoringModifiers, keyCode,([charactersIgnoringModifiers length] == 0) ? 0 : [charactersIgnoringModifiers characterAtIndex: 0], w, type);
-#endif
- break;
-
- default:
- return theEvent; /* Unrecognized key event. */
- }
-
- /* Create an Xevent to add to the Tk queue. */
- if (!processingCompose) {
- unsigned int state = 0;
-
- if (modifiers & NSAlphaShiftKeyMask) {
- state |= LockMask;
- }
- if (modifiers & NSShiftKeyMask) {
- state |= ShiftMask;
- }
- if (modifiers & NSControlKeyMask) {
- state |= ControlMask;
- }
- if (modifiers & NSCommandKeyMask) {
- state |= Mod1Mask; /* command key */
- }
- if (modifiers & NSAlternateKeyMask) {
- state |= Mod2Mask; /* option key */
- }
- if (modifiers & NSNumericPadKeyMask) {
- state |= Mod3Mask;
- }
- if (modifiers & NSFunctionKeyMask) {
- state |= Mod4Mask;
- }
-
- /*
- * The focus must be in the FrontWindow on the Macintosh. We then query Tk
- * to determine the exact Tk window that owns the focus.
- */
-
- TkWindow *winPtr = TkMacOSXGetTkWindow(w);
- Tk_Window tkwin = (Tk_Window) winPtr;
-
- if (!tkwin) {
- TkMacOSXDbgMsg("tkwin == NULL");
- return theEvent;
- }
- tkwin = (Tk_Window) winPtr->dispPtr->focusPtr;
- if (!tkwin) {
- TkMacOSXDbgMsg("tkwin == NULL");
- return theEvent; /* Give up. No window for this event. */
- }
-
- /*
- * If it's a function key, or we have modifiers other than Shift or Alt,
- * pass it straight to Tk. Otherwise we'll send for input processing.
- */
- int code = (len == 0) ?
- 0 : [charactersIgnoringModifiers characterAtIndex: 0];
- if (type != NSKeyDown || isFunctionKey(code)
- || (len > 0 && state & (ControlMask | Mod1Mask | Mod3Mask | Mod4Mask))) {
-
- XEvent xEvent;
- setupXEvent(&xEvent, w, state);
-
- if (type == NSFlagsChanged) {
- if (savedModifiers > modifiers) {
- xEvent.xany.type = KeyRelease;
- } else {
- xEvent.xany.type = KeyPress;
- }
-
- /*
- * Use special '-1' to signify a special keycode to our platform
- * specific code in tkMacOSXKeyboard.c. This is rather like what
- * happens on Windows.
- */
-
- xEvent.xany.send_event = -1;
-
- /*
- * Set keycode (which was zero) to the changed modifier
- */
-
- xEvent.xkey.keycode = (modifiers ^ savedModifiers);
- } else {
- if (type == NSKeyUp || repeat) {
- xEvent.xany.type = KeyRelease;
- } else {
- xEvent.xany.type = KeyPress;
- }
-
- /* For command key, take input manager's word so things
- like dvorak / qwerty layout work. */
- if ((modifiers & NSCommandKeyMask) == NSCommandKeyMask
- && (modifiers & NSAlternateKeyMask) != NSAlternateKeyMask
- && len > 0 && !isFunctionKey(code)) {
- // head off keycode-based translation in tkMacOSXKeyboard.c
- xEvent.xkey.nbytes = [characters length]; //len
- }
-
- if ([characters length] > 0) {
- xEvent.xkey.keycode =
- (keyCode << 16) | (UInt16) [characters characterAtIndex:0];
- if (![characters getCString:xEvent.xkey.trans_chars
- maxLength:XMaxTransChars encoding:NSUTF8StringEncoding]) {
- /* prevent SF bug 2907388 (crash on some composite chars) */
- //PENDING: we might not need this anymore
- TkMacOSXDbgMsg("characters too long");
- return theEvent;
- }
- }
-
- if (repeat) {
- Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL);
- xEvent.xany.type = KeyPress;
- xEvent.xany.serial = LastKnownRequestProcessed(Tk_Display(tkwin));
- }
- }
- Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL);
- savedModifiers = modifiers;
- return theEvent;
- } /* if send straight to TK */
-
- } /* if not processing compose */
-
- if (type == NSKeyDown) {
- if (NS_KEYLOG)
- fprintf (stderr, "keyDown: %s compose sequence.\n",
- processingCompose == YES ? "Continue" : "Begin");
- processingCompose = YES;
- [nsEvArray addObject: theEvent];
- [[w contentView] interpretKeyEvents: nsEvArray];
- [nsEvArray removeObject: theEvent];
- }
-
- savedModifiers = modifiers;
-
- return theEvent;
-}
-@end
-
-
-
-@implementation TKContentView
-/* <NSTextInput> implementation (called through interpretKeyEvents:]). */
-
-/* <NSTextInput>: called when done composing;
- NOTE: also called when we delete over working text, followed immed.
- by doCommandBySelector: deleteBackward: */
-- (void)insertText: (id)aString
-{
- int i, len = [(NSString *)aString length];
- XEvent xEvent;
-
- if (NS_KEYLOG)
- TKLog (@"insertText '%@'\tlen = %d", aString, len);
- processingCompose = NO;
- finishedCompose = YES;
-
- /* first, clear any working text */
- if (privateWorkingText != nil)
- [self deleteWorkingText];
-
- /* now insert the string as keystrokes */
- setupXEvent(&xEvent, [self window], 0);
- xEvent.xany.type = KeyPress;
-
- for (i =0; i<len; i++)
- {
- xEvent.xkey.keycode = (UInt16) [aString characterAtIndex: i];
- [[aString substringWithRange: NSMakeRange(i,1)]
- getCString: xEvent.xkey.trans_chars
- maxLength: XMaxTransChars encoding: NSUTF8StringEncoding];
- xEvent.xkey.nbytes = strlen(xEvent.xkey.trans_chars);
- xEvent.xany.type = KeyPress;
- releaseCode = (UInt16) [aString characterAtIndex: 0];
- Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL);
- }
- releaseCode = (UInt16) [aString characterAtIndex: 0];
-}
-
-
-/* <NSTextInput>: inserts display of composing characters */
-- (void)setMarkedText: (id)aString selectedRange: (NSRange)selRange
-{
- NSString *str = [aString respondsToSelector: @selector (string)] ?
- [aString string] : aString;
- if (NS_KEYLOG)
- TKLog (@"setMarkedText '%@' len =%lu range %lu from %lu", str,
- (unsigned long) [str length], (unsigned long) selRange.length,
- (unsigned long) selRange.location);
-
- if (privateWorkingText != nil)
- [self deleteWorkingText];
- if ([str length] == 0)
- return;
-
- processingCompose = YES;
- privateWorkingText = [str copy];
-
- //PENDING: insert workingText underlined
-}
-
-
-- (BOOL)hasMarkedText
-{
- return privateWorkingText != nil;
-}
-
-
-- (NSRange)markedRange
-{
- NSRange rng = privateWorkingText != nil
- ? NSMakeRange (0, [privateWorkingText length]) : NSMakeRange (NSNotFound, 0);
- if (NS_KEYLOG)
- TKLog (@"markedRange request");
- return rng;
-}
-
-
-- (void)unmarkText
-{
- if (NS_KEYLOG)
- TKLog (@"unmark (accept) text");
- [self deleteWorkingText];
- processingCompose = NO;
-}
-
-
-/* used to position char selection windows, etc. */
-- (NSRect)firstRectForCharacterRange: (NSRange)theRange
-{
- NSRect rect;
- NSPoint pt;
-
- pt.x = caret_x;
- pt.y = caret_y;
-
- pt = [self convertPoint: pt toView: nil];
- pt = [[self window] tkConvertPointToScreen: pt];
- pt.y -= caret_height;
-
- rect.origin = pt;
- rect.size.width = caret_height;
- rect.size.height = caret_height;
- return rect;
-}
-
-
-- (NSInteger)conversationIdentifier
-{
- return (NSInteger)self;
-}
-
-
-- (void)doCommandBySelector: (SEL)aSelector
-{
- if (NS_KEYLOG)
- TKLog (@"doCommandBySelector: %@", NSStringFromSelector (aSelector));
- processingCompose = NO;
- if (aSelector == @selector (deleteBackward:))
- {
- /* happens when user backspaces over an ongoing composition:
- throw a 'delete' into the event queue */
- XEvent xEvent;
- setupXEvent(&xEvent, [self window], 0);
- xEvent.xany.type = KeyPress;
- xEvent.xkey.nbytes = 1;
- xEvent.xkey.keycode = (0x33 << 16) | 0x7F;
- xEvent.xkey.trans_chars[0] = 0x7F;
- xEvent.xkey.trans_chars[1] = 0x0;
- Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL);
- }
-}
-
-
-- (NSArray *)validAttributesForMarkedText
-{
- static NSArray *arr = nil;
- if (arr == nil) arr = [NSArray new];
- /* [[NSArray arrayWithObject: NSUnderlineStyleAttributeName] retain]; */
- return arr;
-}
-
-
-- (NSRange)selectedRange
-{
- if (NS_KEYLOG)
- TKLog (@"selectedRange request");
- return NSMakeRange (NSNotFound, 0);
-}
-
-
-- (NSUInteger)characterIndexForPoint: (NSPoint)thePoint
-{
- if (NS_KEYLOG)
- TKLog (@"characterIndexForPoint request");
- return 0;
-}
-
-
-- (NSAttributedString *)attributedSubstringFromRange: (NSRange)theRange
-{
- static NSAttributedString *str = nil;
- if (str == nil) str = [NSAttributedString new];
- if (NS_KEYLOG)
- TKLog (@"attributedSubstringFromRange request");
- return str;
-}
-/* End <NSTextInput> impl. */
-@end
-
-
-@implementation TKContentView(TKKeyEvent)
-/* delete display of composing characters [not in <NSTextInput>] */
-- (void)deleteWorkingText
-{
- if (privateWorkingText == nil)
- return;
- if (NS_KEYLOG)
- TKLog(@"deleteWorkingText len = %lu\n",
- (unsigned long)[privateWorkingText length]);
- [privateWorkingText release];
- privateWorkingText = nil;
- processingCompose = NO;
-
- //PENDING: delete working text
-}
-@end
-
-
-
-/*
- * Set up basic fields in xevent for keyboard input.
- */
-static void
-setupXEvent(XEvent *xEvent, NSWindow *w, unsigned int state)
-{
- TkWindow *winPtr = TkMacOSXGetTkWindow(w);
- Tk_Window tkwin = (Tk_Window) winPtr;
- if (!winPtr) {
- return;
- }
-
- memset(xEvent, 0, sizeof(XEvent));
- xEvent->xany.serial = LastKnownRequestProcessed(Tk_Display(tkwin));
- xEvent->xany.send_event = false;
- xEvent->xany.display = Tk_Display(tkwin);
- xEvent->xany.window = Tk_WindowId(tkwin);
-
- xEvent->xkey.root = XRootWindow(Tk_Display(tkwin), 0);
- xEvent->xkey.subwindow = None;
- xEvent->xkey.time = TkpGetMS();
- xEvent->xkey.state = state;
- xEvent->xkey.same_screen = true;
- xEvent->xkey.trans_chars[0] = 0;
- xEvent->xkey.nbytes = 0;
-}
-
-#pragma mark -
-
-/*
- *----------------------------------------------------------------------
- *
- * XGrabKeyboard --
- *
- * Simulates a keyboard grab by setting the focus.
- *
- * Results:
- * Always returns GrabSuccess.
- *
- * Side effects:
- * Sets the keyboard focus to the specified window.
- *
- *----------------------------------------------------------------------
- */
-
-int
-XGrabKeyboard(
- Display* display,
- Window grab_window,
- Bool owner_events,
- int pointer_mode,
- int keyboard_mode,
- Time time)
-{
- keyboardGrabWinPtr = Tk_IdToWindow(display, grab_window);
- if (keyboardGrabWinPtr && grabWinPtr) {
- NSWindow *w = TkMacOSXDrawableWindow(grab_window);
- MacDrawable *macWin = (MacDrawable *) grab_window;
-
- if (w && macWin->toplevel->winPtr == (TkWindow*) grabWinPtr) {
- if (modalSession) {
- Tcl_Panic("XGrabKeyboard: already grabbed");
- }
- keyboardGrabNSWindow = w;
- [w retain];
- modalSession = [NSApp beginModalSessionForWindow:w];
- }
- }
- return GrabSuccess;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * XUngrabKeyboard --
- *
- * Releases the simulated keyboard grab.
- *
- * Results:
- * None.
- *
- * Side effects:
- * Sets the keyboard focus back to the value before the grab.
- *
- *----------------------------------------------------------------------
- */
-
-void
-XUngrabKeyboard(
- Display* display,
- Time time)
-{
- if (modalSession) {
- [NSApp endModalSession:modalSession];
- modalSession = nil;
- }
- if (keyboardGrabNSWindow) {
- [keyboardGrabNSWindow release];
- keyboardGrabNSWindow = nil;
- }
- keyboardGrabWinPtr = NULL;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * TkMacOSXGetCapture --
- *
- * Results:
- * Returns the current grab window
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-Tk_Window
-TkMacOSXGetCapture(void)
-{
- return grabWinPtr;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * TkMacOSXGetModalSession --
- *
- * Results:
- * Returns the current modal session
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-MODULE_SCOPE NSModalSession
-TkMacOSXGetModalSession(void)
-{
- return modalSession;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * TkpSetCapture --
- *
- * This function captures the mouse so that all future events will be
- * reported to this window, even if the mouse is outside the window. If
- * the specified window is NULL, then the mouse is released.
- *
- * Results:
- * None.
- *
- * Side effects:
- * Sets the capture flag and captures the mouse.
- *
- *----------------------------------------------------------------------
- */
-
-void
-TkpSetCapture(
- TkWindow *winPtr) /* Capture window, or NULL. */
-{
- while (winPtr && !Tk_IsTopLevel(winPtr)) {
- winPtr = winPtr->parentPtr;
- }
- grabWinPtr = (Tk_Window) winPtr;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * Tk_SetCaretPos --
- *
- * This enables correct placement of the XIM caret. This is called by
- * widgets to indicate their cursor placement, and the caret location is
- * used by TkpGetString to place the XIM caret.
- *
- * Results:
- * None
- *
- * Side effects:
- * None
- *
- *----------------------------------------------------------------------
- */
-
-void
-Tk_SetCaretPos(
- Tk_Window tkwin,
- int x,
- int y,
- int height)
- {
- TkCaret *caretPtr = &(((TkWindow *) tkwin)->dispPtr->caret);
-
- /*
- * Prevent processing anything if the values haven't changed. Windows only
- * has one display, so we can do this with statics.
- */
-
- if ((caretPtr->winPtr == ((TkWindow *) tkwin))
- && (caretPtr->x == x) && (caretPtr->y == y)) {
- return;
- }
-
- caretPtr->winPtr = ((TkWindow *) tkwin);
- caretPtr->x = x;
- caretPtr->y = y;
- caretPtr->height = height;
-
- /*
- * As in Windows, adjust to the toplevel to get the coords right.
- */
-
- while (!Tk_IsTopLevel(tkwin)) {
- x += Tk_X(tkwin);
- y += Tk_Y(tkwin);
- tkwin = Tk_Parent(tkwin);
- if (tkwin == NULL) {
- return;
- }
- }
-
- /* But adjust for fact that NS uses flipped view. */
- y = Tk_Height(tkwin) - y;
-
- caret_x = x;
- caret_y = y;
- caret_height = height;
-}
-
-
-static unsigned convert_ns_to_X_keysym[] =
-{
- NSHomeFunctionKey, 0x50,
- NSLeftArrowFunctionKey, 0x51,
- NSUpArrowFunctionKey, 0x52,
- NSRightArrowFunctionKey, 0x53,
- NSDownArrowFunctionKey, 0x54,
- NSPageUpFunctionKey, 0x55,
- NSPageDownFunctionKey, 0x56,
- NSEndFunctionKey, 0x57,
- NSBeginFunctionKey, 0x58,
- NSSelectFunctionKey, 0x60,
- NSPrintFunctionKey, 0x61,
- NSExecuteFunctionKey, 0x62,
- NSInsertFunctionKey, 0x63,
- NSUndoFunctionKey, 0x65,
- NSRedoFunctionKey, 0x66,
- NSMenuFunctionKey, 0x67,
- NSFindFunctionKey, 0x68,
- NSHelpFunctionKey, 0x6A,
- NSBreakFunctionKey, 0x6B,
-
- NSF1FunctionKey, 0xBE,
- NSF2FunctionKey, 0xBF,
- NSF3FunctionKey, 0xC0,
- NSF4FunctionKey, 0xC1,
- NSF5FunctionKey, 0xC2,
- NSF6FunctionKey, 0xC3,
- NSF7FunctionKey, 0xC4,
- NSF8FunctionKey, 0xC5,
- NSF9FunctionKey, 0xC6,
- NSF10FunctionKey, 0xC7,
- NSF11FunctionKey, 0xC8,
- NSF12FunctionKey, 0xC9,
- NSF13FunctionKey, 0xCA,
- NSF14FunctionKey, 0xCB,
- NSF15FunctionKey, 0xCC,
- NSF16FunctionKey, 0xCD,
- NSF17FunctionKey, 0xCE,
- NSF18FunctionKey, 0xCF,
- NSF19FunctionKey, 0xD0,
- NSF20FunctionKey, 0xD1,
- NSF21FunctionKey, 0xD2,
- NSF22FunctionKey, 0xD3,
- NSF23FunctionKey, 0xD4,
- NSF24FunctionKey, 0xD5,
-
- NSBackspaceCharacter, 0x08, /* 8: Not on some KBs. */
- NSDeleteCharacter, 0xFF, /* 127: Big 'delete' key upper right. */
- NSDeleteFunctionKey, 0x9F, /* 63272: Del forw key off main array. */
-
- NSTabCharacter, 0x09,
- 0x19, 0x09, /* left tab->regular since pass shift */
- NSCarriageReturnCharacter, 0x0D,
- NSNewlineCharacter, 0x0D,
- NSEnterCharacter, 0x8D,
-
- 0x1B, 0x1B /* escape */
-};
-
-
-static unsigned isFunctionKey(unsigned code)
-{
- const unsigned last_keysym = (sizeof (convert_ns_to_X_keysym)
- / sizeof (convert_ns_to_X_keysym[0]));
- unsigned keysym;
- for (keysym = 0; keysym < last_keysym; keysym += 2)
- if (code == convert_ns_to_X_keysym[keysym])
- return 0xFF00 | convert_ns_to_X_keysym[keysym+1];
- return 0;
- }
-
-/*
- * Local Variables:
- * mode: objc
- * c-basic-offset: 4
- * fill-column: 79
- * coding: utf-8
- * End:
- */
sc">\n", indent * 2, "", min); H5free_memory(maj); H5free_memory(min); return 0; error: if(maj) H5free_memory(maj); if(min) H5free_memory(min); return -1; } /*------------------------------------------------------------------------- * Function: test_error1 * * Purpose: Test the backward compatibility of H5Eset/get_auto. * * Return: Success: 0 * * Failure: -1 * * Programmer: Raymond Lu * 17 September 2010 * * * Modifications: * *------------------------------------------------------------------------- */ static herr_t test_error1(void) { hid_t dataset, space; hsize_t dims[2]; H5E_auto1_t old_func1; H5E_auto2_t old_func2; void *old_data; herr_t ret; TESTING("error API H5Eset/get_auto"); HDfprintf(stderr, "\n"); /* Create the data space */ dims[0] = DIM0; dims[1] = DIM1; if ((space = H5Screate_simple(2, dims, NULL))<0) TEST_ERROR; /* Use H5Eget_auto2 to query the default printing function. The library *should indicate H5Eprint2 as the default. */ if (H5Eget_auto2(H5E_DEFAULT, &old_func2, &old_data)<0) TEST_ERROR; if (old_data != NULL) TEST_ERROR; if (!old_func2 || (H5E_auto2_t)H5Eprint2 != old_func2) TEST_ERROR; /* This function sets the default printing function to be H5Eprint2. */ if(H5Eset_auto2(H5E_DEFAULT, old_func2, old_data)<0) TEST_ERROR; /* Try the printing function. Dataset creation should fail because the file * doesn't exist. */ dataset = H5Dcreate2(FAKE_ID, DSET_NAME, H5T_STD_I32BE, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); if(dataset >= 0) TEST_ERROR; /* This call should work. It simply returns H5Eprint1. */ if((ret = H5Eget_auto1(&old_func1, &old_data))<0) TEST_ERROR; if (old_data != NULL) TEST_ERROR; if (!old_func1 || (H5E_auto1_t)H5Eprint1 != old_func1) TEST_ERROR; /* This function changes the old-style printing function to be user_print1. */ if(H5Eset_auto1((H5E_auto1_t)user_print1, stderr)<0) TEST_ERROR; /* Try the printing function. Dataset creation should fail because the file * doesn't exist. */ dataset = H5Dcreate2(FAKE_ID, DSET_NAME, H5T_STD_I32BE, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); if(dataset >= 0) TEST_ERROR; /* This call should fail because the test mixes H5Eget_auto2 with H5Eset_auto1. * Once the H5Eset_auto1 is called with a user-defined printing function, * a call to H5Eget_auto2 will fail. But keep in mind the printing function is * user_print1. */ if((ret = H5Eget_auto2(H5E_DEFAULT, &old_func2, &old_data))>=0) TEST_ERROR; /* This function changes the new-style printing function to be user_print2. */ if(H5Eset_auto2(H5E_DEFAULT, (H5E_auto2_t)user_print2, stderr)<0) TEST_ERROR; /* Try the printing function. Dataset creation should fail because the file * doesn't exist. */ dataset = H5Dcreate2(FAKE_ID, DSET_NAME, H5T_STD_I32BE, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); if(dataset >= 0) TEST_ERROR; /* This function changes the new-style printing function back to the default H5Eprint2. */ if(H5Eset_auto2(H5E_DEFAULT, (H5E_auto2_t)H5Eprint2, NULL)<0) TEST_ERROR; /* This call should work because the H5Eset_auto2 above restored the default printing * function H5Eprint2. It simply returns user_print1. */ if((ret = H5Eget_auto1(&old_func1, &old_data))<0) TEST_ERROR; if (old_data != NULL) TEST_ERROR; if (!old_func1 || (H5E_auto1_t)user_print1 != old_func1) TEST_ERROR; /* This function changes the new-style printing function back to the default H5Eprint1. */ if(H5Eset_auto1((H5E_auto1_t)H5Eprint1, NULL)<0) TEST_ERROR; /* This call should work because the H5Eset_auto1 above restored the default printing * function H5Eprint1. It simply returns H5Eprint2. */ if((ret = H5Eget_auto2(H5E_DEFAULT, &old_func2, &old_data))<0) TEST_ERROR; if (old_data != NULL) TEST_ERROR; if (!old_func2 || (H5E_auto2_t)H5Eprint2 != old_func2) TEST_ERROR; /* Try the printing function. Dataset creation should fail because the file * doesn't exist. */ dataset = H5Dcreate2(FAKE_ID, DSET_NAME, H5T_STD_I32BE, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); if(dataset >= 0) TEST_ERROR; return 0; error: return -1; } /*------------------------------------------------------------------------- * Function: test_error2 * * Purpose: Test error API functions, mainly on H5Epush1. * * Return: Success: 0 * * Failure: -1 * * Programmer: Raymond Lu * July 10, 2003 * * * Modifications: * *------------------------------------------------------------------------- */ static herr_t test_error2(hid_t file) { hid_t dataset, space; hsize_t dims[2]; const char *FUNC_test_error="test_error2"; TESTING("error API based on data I/O"); HDfprintf(stderr, "\n"); /* Create the data space */ dims[0] = DIM0; dims[1] = DIM1; if ((space = H5Screate_simple(2, dims, NULL))<0) TEST_ERROR; /* Test H5E_BEGIN_TRY */ H5E_BEGIN_TRY { dataset = H5Dcreate2(FAKE_ID, DSET_NAME, H5T_STD_I32BE, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); } H5E_END_TRY; /* Create the dataset */ if ((dataset = H5Dcreate2(file, DSET_NAME, H5T_STD_I32BE, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { H5Epush1(__FILE__, FUNC_test_error, __LINE__, H5E_ERROR, H5E_CANTCREATE, "H5Dcreate2 failed"); goto error; } /* Disable the library's default printing function */ #ifdef H5_USE_16_API_DEFAULT if(H5Eset_auto(NULL, NULL)<0) #else if(H5Eset_auto(H5E_DEFAULT, NULL, NULL)<0) #endif TEST_ERROR; /* Make H5Dwrite fail, verify default print is disabled */ if (H5Dwrite(FAKE_ID, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, ipoints2)<0) { H5Epush1(__FILE__, FUNC_test_error, __LINE__, H5E_ERROR, H5E_WRITEERROR, "H5Dwrite shouldn't succeed"); goto error; } /* In case program comes to this point, close dataset */ if(H5Dclose(dataset)<0) TEST_ERROR; TEST_ERROR; error: return -1; } /*------------------------------------------------------------------------- * Function: dump_error * * Purpose: Prints error stack in default and customized ways. * * Return: Success: 0 * * Failure: -1 * * Programmer: Raymond Lu * July 17, 2003 * * * Modifications: * *------------------------------------------------------------------------- */ static herr_t dump_error(void) { /* Print errors in library default way */ HDfprintf(stderr, "********* Print error stack in HDF5 default way *********\n"); if(H5Eprint1(stderr) < 0) TEST_ERROR; /* Customized way to print errors */ HDfprintf(stderr, "\n********* Print error stack in customized way *********\n"); if(H5Ewalk1(H5E_WALK_UPWARD, custom_print_cb1, stderr) < 0) TEST_ERROR; return 0; error: return -1; } /*------------------------------------------------------------------------- * Function: main * * Purpose: Test error API. * * Programmer: Raymond Lu * July 10, 2003 * * Modifications: * *------------------------------------------------------------------------- */ int main(void) { hid_t file, fapl; char filename[1024]; const char *FUNC_main="main"; HDfprintf(stderr, " This program tests the Error API compatible with HDF5 v1.6. There are supposed to be some error messages\n"); fapl = h5_fileaccess(); h5_fixname(FILENAME[0], fapl, filename, sizeof filename); if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR ; /* Test error stack */ /* Push an error onto error stack */ H5Epush1(__FILE__, FUNC_main, __LINE__, H5E_ERROR, H5E_BADVALUE, "Error test failed"); /* Print out the errors on stack */ dump_error(); /* Empty error stack */ H5Eclear1(); /* Test error API */ if(test_error1() < 0) TEST_ERROR ; if(test_error2(file) < 0) { H5Epush1(__FILE__, FUNC_main, __LINE__, H5E_ERROR, H5E_BADMESG, "Error test failed"); H5Eprint1(stderr); } if(H5Fclose(file) < 0) TEST_ERROR ; h5_clean_files(FILENAME, fapl); HDprintf("All error API tests passed.\n"); return 0; error: HDprintf("***** ERROR TEST FAILED! *****\n"); return 1; } #endif /* H5_NO_DEPRECATED_SYMBOLS */