📄 nedit.c
字号:
InitServerCommunication(); /* Process events. */ if (IsServer) ServerMainLoop(context); else XtAppMainLoop(context); /* Not reached but this keeps some picky compilers happy */ return EXIT_SUCCESS;}static void nextArg(int argc, char **argv, int *argIndex){ if (*argIndex + 1 >= argc) {#ifdef VMS *argv[*argIndex] = '/';#endif /*VMS*/ fprintf(stderr, "NEdit: %s requires an argument\n%s", argv[*argIndex], cmdLineHelp); exit(EXIT_FAILURE); } (*argIndex)++;}/*** Return True if -do macro is valid, otherwise write an error on stderr*/static int checkDoMacroArg(const char *macro){ Program *prog; char *errMsg, *stoppedAt, *tMacro; int macroLen; /* Add a terminating newline (which command line users are likely to omit since they are typically invoking a single routine) */ macroLen = strlen(macro); tMacro = XtMalloc(strlen(macro)+2); strncpy(tMacro, macro, macroLen); tMacro[macroLen] = '\n'; tMacro[macroLen+1] = '\0'; /* Do a test parse */ prog = ParseMacro(tMacro, &errMsg, &stoppedAt); if (prog == NULL) { ParseError(NULL, tMacro, stoppedAt, "argument to -do", errMsg); return False; } FreeProgram(prog); return True;}/*** maskArgvKeywords and unmaskArgvKeywords mangle selected keywords by** replacing the '-' with a space, for the purpose of hiding them from** XtOpenDisplay's option processing. Why this silly scheme? XtOpenDisplay** really needs to see command line arguments, particularly -display, but** there's no way to change the option processing table it uses, to keep** it from consuming arguments which are meant to apply per-window, like** -geometry and -iconic.*/static void maskArgvKeywords(int argc, char **argv, const char **maskArgs){ int i, k; for (i=1; i<argc; i++) for (k=0; maskArgs[k]!=NULL; k++) if (!strcmp(argv[i], maskArgs[k])) argv[i][0] = ' ';}static void unmaskArgvKeywords(int argc, char **argv, const char **maskArgs){ int i, k; for (i=1; i<argc; i++) for (k=0; maskArgs[k]!=NULL; k++) if (argv[i][0]==' ' && !strcmp(&argv[i][1], &maskArgs[k][1])) argv[i][0] = '-';}/*** If we're not using the default visual, then some default resources in** the database (colors) are not valid, because they are indexes into the** default colormap. If we used them blindly, then we'd get "random"** unreadable colors. So we inspect the resource list, and use the** fallback "grey" color instead if this is the case.*/static void patchResourcesForVisual(void){ Cardinal i; Visual *visual; int depth; Colormap map; Boolean usingDefaultVisual; XrmDatabase db; if (!TheDisplay) return; db = XtDatabase(TheDisplay); usingDefaultVisual = FindBestVisual(TheDisplay, APP_NAME, APP_CLASS, &visual, &depth, &map); if (!usingDefaultVisual) {#ifndef LESSTIF_VERSION /* Drag-and-drop visuals do not work well when using a different visual. One some systems, you'll just get a funny-looking icon (maybe all-black) but on other systems it crashes with a BadMatch error. This appears to be an OSF Motif bug. It would be nicer to just disable the visual itself, instead of the entire drag operation. */ XrmPutStringResource(&db, "*dragInitiatorProtocolStyle", "DRAG_NONE");#endif for (i = 1; i < XtNumber(fallbackResources); ++i) { Cardinal resIndex = i - 1; if (strstr(fallbackResources[resIndex], "*background:") || strstr(fallbackResources[resIndex], "*foreground:")) { /* Qualify by application name to prevent them from being converted against the wrong colormap. */ char buf[1024] = "*" APP_NAME; strcat(buf, fallbackResources[resIndex]); XrmPutLineResource(&db, buf); } } }}/*** Several KDE version (2.x and 3.x) ship with a template application-default ** file for NEdit in which several strings have to be substituted in order to ** make it a valid .ad file. However, for some reason (a KDE bug?), the** template sometimes ends up in the resource db unmodified, such that several** invalid entries are present. This function checks for the presence of such** invalid entries and silently replaces them with NEdit's default values where** necessary. Without this, NEdit will typically write several warnings to ** the terminal (Cannot convert string "FONTLIST" to type FontStruct etc) and** fall back on some really ugly colors and fonts.*/static void patchResourcesForKDEbug(void){ /* * These are the resources found the Nedit.ad template shipped with KDE 3.0. */ static const char* buggyResources[][3] = { { "*fontList", "FONTLIST", NEDIT_DEFAULT_FONT }, { "*XmText.background", "BACKGROUND", NEDIT_DEFAULT_TEXT_BG }, { "*XmText.foreground", "FOREGROUND", NEDIT_DEFAULT_FG }, { "*XmTextField.background", "BACKGROUND", NEDIT_DEFAULT_TEXT_BG }, { "*XmTextField.foreground", "FOREGROUND", NEDIT_DEFAULT_FG }, { "*XmList.background", "BACKGROUND", NEDIT_DEFAULT_TEXT_BG }, { "*XmList.foreground", "FOREGROUND", NEDIT_DEFAULT_FG }, { "*helpText.background", "BACKGROUND", NEDIT_DEFAULT_HELP_BG }, { "*helpText.foreground", "FOREGROUND", NEDIT_DEFAULT_HELP_FG }, { "*background", "BACKGROUND", NEDIT_DEFAULT_BG }, { "*foreground", "FOREGROUND", NEDIT_DEFAULT_FG, }, { "*selectColor", "BACKGROUND", NEDIT_DEFAULT_SEL_BG }, { "*highlightColor", "BACKGROUND", NEDIT_DEFAULT_HI_BG }, { "*text.background", "WINDOW_BACKGROUND", NEDIT_DEFAULT_TEXT_BG }, { "*text.foreground", "WINDOW_FOREGROUND", NEDIT_DEFAULT_FG }, { "*text.selectBackground", "SELECT_BACKGROUND", NEDIT_DEFAULT_SEL_BG }, { "*text.selectForeground", "SELECT_FOREGROUND", NEDIT_DEFAULT_SEL_FG }, { "*text.cursorForeground", "WINDOW_FOREGROUND", NEDIT_DEFAULT_CURSOR_FG}, /* { "*remapDeleteKey", "False", }, OK */ /* { "!*text.heavyCursor", "True" }, OK */ /* { "!*BlinkRate", "0" }, OK */ /* { "*shell", "/bin/sh" }, OK */ { "*statsLine.background", "BACKGROUND", NEDIT_DEFAULT_BG }, { "*statsLine.foreground", "FOREGROUND", NEDIT_DEFAULT_FG }, { NULL, NULL, NULL } }; XrmDatabase db; int i; if (!TheDisplay) return; db = XtDatabase(TheDisplay); i = 0; while (buggyResources[i][0]) { const char* resource = buggyResources[i][0]; const char* buggyValue = buggyResources[i][1]; const char* defaultValue = buggyResources[i][2]; char name[128] = APP_NAME; char class[128] = APP_CLASS; char* type; XrmValue resValue; strcat(name, resource); strcat(class, resource); /* Is this ok ? */ if (XrmGetResource(db, name, class, &type, &resValue) && !strcmp(type, XmRString)) { /* Buggy value? Replace by the default. */ if (!strcmp(resValue.addr, buggyValue)) { XrmPutStringResource(&db, &name[0], (char*)defaultValue); } } ++i; }}/*** It seems OSF Motif cannot handle locales with UTF-8 at the end, crashing** in various places. The easiest one to find is to open the File Open** dialog box. So we lop off UTF-8 if it's there and continue. Newer ** versions of Linux distros (e.g., RedHat 8) set the default language to** to have "UTF-8" at the end, so users were seeing these crashes.*/static void patchLocaleForMotif(){#ifndef LESSTIF_VERSION const char *ctype; char ctypebuf[1024]; char *utf_start; /* We have to check LC_CTYPE specifically here, because the system might specify different locales for different categories (why anyone would want to do this is beyond me). As far as I can tell, only LC_CTYPE causes OSF Motif to crash. If it turns out others do, we'll have to iterate over a list of locale cateogries and patch every one of them. */ ctype = setlocale(LC_CTYPE, NULL); if (!ctype) return; strncpy(ctypebuf, ctype, sizeof ctypebuf); if ((utf_start = strstr(ctypebuf, ".utf8")) || (utf_start = strstr(ctypebuf, ".UTF-8"))) { *utf_start = '\0'; /* Samurai chop */ XtWarning("UTF8 locale not supported."); setlocale(LC_CTYPE, ctypebuf); }#endif}/*** Same as the default X language procedure, except we check if Motif can** handle the locale as well.*/static String neditLanguageProc(Display *dpy, String xnl, XtPointer closure){ /* "xnl" will be set if the user passes in a new language via the "-xnllanguage" flag. If it's empty, then setlocale will get the default locale by some system-dependent means (usually, reading some environment variables). */ if (! setlocale(LC_ALL, xnl)) { XtWarning("locale not supported by C library, locale unchanged"); } patchLocaleForMotif(); if (! XSupportsLocale()) { XtWarning("locale not supported by Xlib, locale set to C"); setlocale(LC_ALL, "C"); } if (! XSetLocaleModifiers("")) XtWarning("X locale modifiers not supported, using default"); return setlocale(LC_ALL, NULL); /* re-query in case overwritten */}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -