⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 misc.c

📁 nedit 是一款linux下的开发源码的功能强大的编辑器
💻 C
📖 第 1 页 / 共 5 页
字号:
    printf("passTxt = %s, startPos = %d, endPos = %d, txtBlkAddr = %d\n",	 passTxt, txtVerStr->startPos, txtVerStr->endPos, txtVerStr->text);    if (txtVerStr->text != NULL && txtVerStr->text->ptr != NULL)	printf("       string typed = %s, length = %d\n", txtVerStr->text->ptr,		txtVerStr->text->length);*/    /* If necessary, expand/compress passTxt and insert any new text */    if (txtVerStr->text != NULL && txtVerStr->text->ptr != NULL)	numCharsTyped = txtVerStr->text->length;    else	numCharsTyped = 0;    /* numCharsTyped = # chars to insert (that user typed) */    /* j = # chars to expand (+) or compress (-) the password string */    j = numCharsTyped - (txtVerStr->endPos - txtVerStr->startPos);    if (j > 0) 				/* expand case: start at ending null  */	for (pos = strlen(passTxt) + 1; pos >= txtVerStr->endPos; --pos)	    passTxt[pos+j] = passTxt[pos];    if (j < 0)				/* compress case */	for (pos = txtVerStr->startPos + numCharsTyped; 			     pos <= (int)strlen(passTxt)+1; ++pos)	    passTxt[pos] = passTxt[pos-j];    /* then copy text to be inserted into passTxt */    for (pos = txtVerStr->startPos, i = 0; i < numCharsTyped; ++i) {	passTxt[pos+i] = *(txtVerStr->text->ptr + i);	/* Replace text typed by user with asterisks (*) */	*(txtVerStr->text->ptr + i) = '*';    }/*    printf("  Password string now = %s\n", passTxt);  */}/*** Remove the white space (blanks and tabs) from a string*/static void removeWhiteSpace(char *string){    char *outPtr = string;        while (TRUE) {    	if (*string == 0) {	    *outPtr = 0;	    return;    	} else if (*string != ' ' && *string != '\t')	    *(outPtr++) = *(string++);	else	    string++;    }}/*** Compares two strings and return TRUE if the two strings** are the same, ignoring whitespace and case differences.*/static int stripCaseCmp(const char *str1, const char *str2){    const char *c1, *c2;        for (c1=str1, c2=str2; *c1!='\0' && *c2!='\0'; c1++, c2++) {	while (*c1 == ' ' || *c1 == '\t')	    c1++;	while (*c2 == ' ' || *c2 == '\t')	    c2++;    	if (toupper((unsigned char)*c1) != toupper((unsigned char)*c2))    	    return FALSE;    }    return *c1 == '\0' && *c2 == '\0';}static void warnHandlerCB(String message){    if (strstr(message, "XtRemoveGrab"))    	return;    if (strstr(message, "Attempt to remove non-existant passive grab"))    	return;    fputs(message, stderr);    fputc('\n', stderr);}static XModifierKeymap *getKeyboardMapping(Display *display) {    static XModifierKeymap *keyboardMap = NULL;    if (keyboardMap == NULL) {        keyboardMap = XGetModifierMapping(display);    }    return(keyboardMap);}/*** get mask for a modifier***/static Modifiers findModifierMapping(Display *display, KeyCode keyCode) {    int i, j;    KeyCode *mapentry;    XModifierKeymap *modMap = getKeyboardMapping(display);    if (modMap == NULL || keyCode == 0) {        return(0);    }    mapentry = modMap->modifiermap;    for (i = 0; i < 8; ++i) {        for (j = 0; j < (modMap->max_keypermod); ++j) {            if (keyCode == *mapentry) {                return(1 << ((mapentry - modMap->modifiermap) / modMap->max_keypermod));            }            ++mapentry;        }    }    return(0);}Modifiers GetNumLockModMask(Display *display) {    static int numLockMask = -1;    if (numLockMask == -1) {        numLockMask = findModifierMapping(display, XKeysymToKeycode(display, XK_Num_Lock));    }    return(numLockMask);}/*** Grab a key regardless of caps-lock and other silly latching keys.***/static void reallyGrabAKey(Widget dialog, int keyCode, Modifiers mask) {    Modifiers numLockMask = GetNumLockModMask(XtDisplay(dialog));    if (keyCode == 0)  /* No anykey grabs, sorry */        return;    XtGrabKey(dialog, keyCode, mask, True, GrabModeAsync, GrabModeAsync);    XtGrabKey(dialog, keyCode, mask|LockMask, True, GrabModeAsync, GrabModeAsync);    if (numLockMask && numLockMask != LockMask) {        XtGrabKey(dialog, keyCode, mask|numLockMask, True, GrabModeAsync, GrabModeAsync);        XtGrabKey(dialog, keyCode, mask|LockMask|numLockMask, True, GrabModeAsync, GrabModeAsync);    }}/*** Part of dialog mnemonic processing.  Search the widget tree under w** for widgets with mnemonics.  When found, add a passive grab to the** dialog widget for the mnemonic character, thus directing mnemonic** events to the dialog widget.*/static void addMnemonicGrabs(Widget dialog, Widget w, int unmodifiedToo){    char mneString[2];    WidgetList children;    Cardinal numChildren;    int i, isMenu;    KeySym mnemonic = '\0';    unsigned char rowColType;    unsigned int keyCode;        if (XtIsComposite(w)) {	if (XtClass(w) == xmRowColumnWidgetClass) {	    XtVaGetValues(w, XmNrowColumnType, &rowColType, NULL);	    isMenu = rowColType != XmWORK_AREA;	} else	    isMenu = False;	if (!isMenu) {	    XtVaGetValues(w, XmNchildren, &children, XmNnumChildren,		    &numChildren, NULL);	    for (i=0; i<(int)numChildren; i++)    		addMnemonicGrabs(dialog, children[i], unmodifiedToo);    	}    } else {	XtVaGetValues(w, XmNmnemonic, &mnemonic, NULL);	if (mnemonic != XK_VoidSymbol && mnemonic != '\0') {	    mneString[0] = mnemonic; mneString[1] = '\0';	    keyCode = XKeysymToKeycode(XtDisplay(dialog),	    	    XStringToKeysym(mneString));            reallyGrabAKey(dialog, keyCode, Mod1Mask);            if (unmodifiedToo)                reallyGrabAKey(dialog, keyCode, 0);	}    }}/*** Callback routine for dialog mnemonic processing.*/static void mnemonicCB(Widget w, XtPointer callData, XKeyEvent *event){    findAndActivateMnemonic(w, event->keycode);}/*** Look for a widget in the widget tree w, with a mnemonic matching** keycode.  When one is found, simulate a button press on that widget** and give it the keyboard focus.  If the mnemonic is on a label,** look in the userData field of the label to see if it points to** another widget, and give that the focus.  This routine is just** sufficient for NEdit, no doubt it will need to be extended for** mnemonics on widgets other than just buttons and text fields.*/static void findAndActivateMnemonic(Widget w, unsigned int keycode){    WidgetList children;    Cardinal numChildren;    int i, isMenu;    KeySym mnemonic = '\0';    char mneString[2];    Widget userData;    unsigned char rowColType;        if (XtIsComposite(w)) {	if (XtClass(w) == xmRowColumnWidgetClass) {	    XtVaGetValues(w, XmNrowColumnType, &rowColType, NULL);	    isMenu = rowColType != XmWORK_AREA;	} else	    isMenu = False;	if (!isMenu) {	    XtVaGetValues(w, XmNchildren, &children, XmNnumChildren,		    &numChildren, NULL);	    for (i=0; i<(int)numChildren; i++)    		findAndActivateMnemonic(children[i], keycode);    	}    } else {	XtVaGetValues(w, XmNmnemonic, &mnemonic, NULL);	if (mnemonic != '\0') {	    mneString[0] = mnemonic; mneString[1] = '\0';	    if (XKeysymToKeycode(XtDisplay(XtParent(w)),	    	    XStringToKeysym(mneString)) == keycode) {	    	if (XtClass(w) == xmLabelWidgetClass ||	    		XtClass(w) == xmLabelGadgetClass) {	    	    XtVaGetValues(w, XmNuserData, &userData, NULL);	    	    if (userData!=NULL && XtIsWidget(userData) &&                         XmIsTraversable(userData))	    	    	XmProcessTraversal(userData, XmTRAVERSE_CURRENT);	    	} else if (XmIsTraversable(w)) {	    	    XmProcessTraversal(w, XmTRAVERSE_CURRENT);	    	    SimulateButtonPress(w);	    	}	    }	}    }}/*** Part of workaround for Motif Caps/Num Lock bug.  Search the widget tree** under w for widgets with accelerators.  When found, add three passive** grabs to topWidget, one for the accelerator keysym + modifiers + Caps** Lock, one for Num Lock, and one for both, thus directing lock +** accelerator events to topWidget.*/static void addAccelGrabs(Widget topWidget, Widget w){    WidgetList children;    Widget menu;    Cardinal numChildren;    int i;        if (XtIsComposite(w)) {	XtVaGetValues(w, XmNchildren, &children, XmNnumChildren,		&numChildren, NULL);	for (i=0; i<(int)numChildren; i++)    	    addAccelGrabs(topWidget, children[i]);    } else if (XtClass(w) == xmCascadeButtonWidgetClass) {	XtVaGetValues(w, XmNsubMenuId, &menu, NULL);	if (menu != NULL)	    addAccelGrabs(topWidget, menu);    } else	addAccelGrab(topWidget, w);}/*** Grabs the key + modifier defined in the widget's accelerator resource,** in combination with the Caps Lock and Num Lock accelerators.*/static void addAccelGrab(Widget topWidget, Widget w){    char *accelString = NULL;    KeySym keysym;    unsigned int modifiers;    KeyCode code;    Modifiers numLockMask = GetNumLockModMask(XtDisplay(topWidget));        XtVaGetValues(w, XmNaccelerator, &accelString, NULL);    if (accelString == NULL || *accelString == '\0') {        if (accelString != NULL) XtFree(accelString);	return;    }        if (!parseAccelString(XtDisplay(topWidget), accelString, &keysym, &modifiers)) {        XtFree(accelString);	return;    }    XtFree(accelString);    /* Check to see if this server has this key mapped.  Some cruddy PC X       servers (Xoftware) have terrible default keymaps. If not,       XKeysymToKeycode will return 0.  However, it's bad news to pass       that to XtGrabKey because 0 is really "AnyKey" which is definitely       not what we want!! */           code = XKeysymToKeycode(XtDisplay(topWidget), keysym);    if (code == 0)        return;            XtGrabKey(topWidget, code,	    modifiers | LockMask, True, GrabModeAsync, GrabModeAsync);    if (numLockMask && numLockMask != LockMask) {        XtGrabKey(topWidget, code,	        modifiers | numLockMask, True, GrabModeAsync, GrabModeAsync);        XtGrabKey(topWidget, code,	        modifiers | LockMask | numLockMask, True, GrabModeAsync, GrabModeAsync);    }}/*** Read a Motif accelerator string and translate it into a keysym + modifiers.** Returns TRUE if the parse was successful, FALSE, if not.*/static int parseAccelString(Display *display, const char *string, KeySym *keySym,	unsigned int *modifiers){#define N_MODIFIERS 12    /*... Is NumLock always Mod3? */    static char *modifierNames[N_MODIFIERS] = {"Ctrl", "Shift", "Alt", "Mod2",	    "Mod3", "Mod4", "Mod5", "Button1", "Button2", "Button3", "Button4",	    "Button5"};    static unsigned int modifierMasks[N_MODIFIERS] = {ControlMask, ShiftMask,	    Mod1Mask, Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask, Button1Mask, Button2Mask,	    Button3Mask, Button4Mask, Button5Mask};    Modifiers numLockMask = GetNumLockModMask(display);    char modStr[MAX_ACCEL_LEN];    char evtStr[MAX_ACCEL_LEN];    char keyStr[MAX_ACCEL_LEN];    const char *c, *evtStart, *keyStart;    int i;        if (strlen(string) >= MAX_ACCEL_LEN)	return FALSE;        /* Get the modifier part */    for (c = string; *c != '<'; c++)	if (*c == '\0')	    return FALSE;    strncpy(modStr, string, c - string);    modStr[c - string] = '\0';        /* Verify the <key> or <keypress> part */    evtStart = c;    for ( ; *c != '>'; c++)	if (*c == '\0')	    return FALSE;    c++;    strncpy(evtStr, evtStart, c - evtStart);    evtStr[c - evtStart] = '\0';    if (!stripCaseCmp(evtStr, "<key>") && !stripCaseCmp(evtStr, "<keypress>"))	return FALSE;        /* Get the keysym part */    keyStart = c;    for ( ; *c != '\0'; c++);    strncpy(keyStr, keyStart, c - keyStart);    keyStr[c - keyStart] = '\0';    *keySym = XStringToKeysym(keyStr);        /* Parse the modifier part */    *modifiers = 0;    c = modStr;    while (*c != '\0') {	while (*c == ' ' || *c == '\t')	    c++;	if (*c == '\0')	    break;	for (i = 0; i < N_MODIFIERS; i++) {	    if (!strncmp(c, modifierNames[i], strlen(modifierNames[i]))) {	    	c += strlen(modifierNames[i]);                if (modifierMasks[i] != numLockMask) {		    *modifiers |= modifierMasks[i];                }		break;	    }	}	if (i == N_MODIFIERS)	    r

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -