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

📄 windowtitle.c

📁 nedit 是一款linux下的开发源码的功能强大的编辑器
💻 C
📖 第 1 页 / 共 4 页
字号:
static const char CVSID[] = "$Id: windowTitle.c,v 1.11 2003/05/09 17:43:48 edg Exp $";/********************************************************************************                                                                              ** windowTitle.c -- Nirvana Editor window title customization                   **                                                                              ** Copyright (C) 2001, Arne Forlie                                              **                                                                              ** This is free software; you can redistribute it and/or modify it under the    ** terms of the GNU General Public License as published by the Free Software    ** Foundation; either version 2 of the License, or (at your option) any later   ** version.                                                                     **                                                                              ** This software is distributed in the hope that it will be useful, but WITHOUT ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or        ** FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License ** for more details.                                                            **                                                                              ** You should have received a copy of the GNU General Public License along with ** software; if not, write to the Free Software Foundation, Inc., 59 Temple     ** Place, Suite 330, Boston, MA  02111-1307 USA                                 **                                                                              ** Nirvana Text Editor                                                          ** July 31, 2001                                                                **                                                                              ** Written by Arne Forlie, http://arne.forlie.com                               **                                                                              ********************************************************************************/#ifdef HAVE_CONFIG_H#include "../config.h"#endif#include "windowTitle.h"#include "textBuf.h"#include "nedit.h"#include "preferences.h"#include "help.h"#include "../util/prefFile.h"#include "../util/misc.h"#include "../util/DialogF.h"#include "../util/utils.h"#include "../util/fileUtils.h"#include <stdlib.h>#include <stdio.h>#include <ctype.h>#include <string.h>#ifdef VMS#include "../util/VMSparam.h"#else#ifndef __MVS__#include <sys/param.h>#endif#include "../util/clearcase.h"#endif /*VMS*/#include <Xm/Xm.h>#include <Xm/SelectioB.h>#include <Xm/Form.h>#include <Xm/List.h>#include <Xm/SeparatoG.h>#include <Xm/LabelG.h>#include <Xm/PushBG.h>#include <Xm/PushB.h>#include <Xm/ToggleBG.h>#include <Xm/ToggleB.h>#include <Xm/RowColumn.h>#include <Xm/CascadeBG.h>#include <Xm/Frame.h>#include <Xm/Text.h>#include <Xm/TextF.h>#ifdef HAVE_DEBUG_H#include "../debug.h"#endif#define WINDOWTITLE_MAX_LEN 500/* Customize window title dialog information */static struct {    Widget      form;    Widget      shell;    WindowInfo* window;    Widget      previewW;    Widget      formatW;        Widget      ccW;    Widget      fileW;    Widget      hostW;    Widget      dirW;    Widget      statusW;    Widget      shortStatusW;    Widget      serverW;    Widget      nameW;    Widget      mdirW;    Widget      ndirW;        Widget      oDirW;    Widget      oCcViewTagW;    Widget      oServerNameW;    Widget      oFileChangedW;    Widget      oFileLockedW;    Widget      oFileReadOnlyW;    Widget      oServerEqualViewW;        char	filename[MAXPATHLEN];    char	path[MAXPATHLEN];    char	viewTag[MAXPATHLEN];    char	serverName[MAXPATHLEN];    int         isServer;    int         filenameSet;    int         lockReasons;    int         fileChanged;        int 	suppressFormatUpdate;} etDialog = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,              NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,              NULL,NULL,"","","","",0,0,0,0,0};static char* removeSequence(char* sourcePtr, char c){    while (*sourcePtr == c) {        sourcePtr++;    }    return(sourcePtr);}/*** Two functions for performing safe insertions into a finite** size buffer so that we don't get any memory overruns.*/static char* safeStrCpy(char* dest, char* destEnd, const char* source){   int len = (int)strlen(source);   if (len <= (destEnd - dest)) {       strcpy(dest, source);       return(dest + len);   }   else {       strncpy(dest, source, destEnd - dest);       *destEnd = '\0';       return(destEnd);   }}static char* safeCharAdd(char* dest, char* destEnd, char c){   if (destEnd - dest > 0)   {      *dest++ = c;      *dest = '\0';   }   return(dest);}/*** Remove empty paranthesis pairs and multiple spaces in a row** with one space.** Also remove leading and trailing spaces and dashes.*/static void compressWindowTitle(char *title){    /* Compress the title */    int modified;    do {        char *sourcePtr = title;        char *destPtr   = sourcePtr;        char c = *sourcePtr++;        modified = False;        /* Remove leading spaces and dashes */        while (c == ' ' || c == '-') {            c= *sourcePtr++;        }        /* Remove empty constructs */        while (c != '\0') {            switch (c) {                /* remove sequences */                case ' ':                case '-':                    sourcePtr = removeSequence(sourcePtr, c);                    *destPtr++ = c; /* leave one */                    break;                /* remove empty paranthesis pairs */                case '(':                    if (*sourcePtr == ')') {                        modified = True;                        sourcePtr++;                    }                    else *destPtr++ = c;                    sourcePtr = removeSequence(sourcePtr, ' ');                    break;                case '[':                    if (*sourcePtr == ']') {                        modified = True;                        sourcePtr++;                    }                    else *destPtr++ = c;                    sourcePtr = removeSequence(sourcePtr, ' ');                    break;                case '{':                    if (*sourcePtr == '}') {                        modified = True;                        sourcePtr++;                    }                    else *destPtr++ = c;                    sourcePtr = removeSequence(sourcePtr, ' ');                    break;                                    default:                    *destPtr++ = c;                    break;            }            c = *sourcePtr++;            *destPtr = '\0';        }        /* Remove trailing spaces and dashes */        while (destPtr-- > title) {            if (*destPtr != ' ' && *destPtr != '-')                break;            *destPtr = '\0';        }    } while (modified == True);}/*** Format the windows title using a printf like formatting string.** The following flags are recognised:**  %c    : ClearCase view tag**  %s    : server name**  %[n]d : directory, with one optional digit specifying the max number**          of trailing directory components to display. Skipped components are**          replaced by an ellipsis (...).**  %f    : file name**  %h    : host name**  %S    : file status**  %u    : user name****  if the ClearCase view tag and server name are identical, only the first one**  specified in the formatting string will be displayed. */char *FormatWindowTitle(const char* filename,                        const char* path,                        const char* clearCaseViewTag,                        const char* serverName,                        int isServer,                        int filenameSet,                        int lockReasons,                        int fileChanged,                        const char* titleFormat){    static char title[WINDOWTITLE_MAX_LEN];    char *titlePtr = title;    char* titleEnd = title + WINDOWTITLE_MAX_LEN - 1;            /* Flags to supress one of these if both are specified and they are identical */    int serverNameSeen = False;    int clearCaseViewTagSeen = False;        int fileNamePresent = False;    int hostNamePresent = False;    int userNamePresent = False;    int serverNamePresent = False;    int clearCasePresent = False;    int fileStatusPresent = False;    int dirNamePresent = False;    int noOfComponents = -1;    int shortStatus = False;        *titlePtr = '\0';  /* always start with an empty string */    while (*titleFormat != '\0' && titlePtr < titleEnd) {        char c = *titleFormat++;        if (c == '%') {            c = *titleFormat++;            if (c == '\0')            {                titlePtr = safeCharAdd(titlePtr, titleEnd, '%');                break;            }              switch (c) {                case 'c': /* ClearCase view tag */		    clearCasePresent = True;                    if (clearCaseViewTag != NULL) {                        if (serverNameSeen == False ||                            strcmp(serverName, clearCaseViewTag) != 0) {                            titlePtr = safeStrCpy(titlePtr, titleEnd, clearCaseViewTag);                            clearCaseViewTagSeen = True;                        }                    }                    break;                                   case 's': /* server name */		    serverNamePresent = True;                    if (isServer && serverName[0] != '\0') { /* only applicable for servers */                         if (clearCaseViewTagSeen == False ||                            strcmp(serverName, clearCaseViewTag) != 0) {                            titlePtr = safeStrCpy(titlePtr, titleEnd, serverName);                            serverNameSeen = True;                        }                    }                    break;                                   case 'd': /* directory without any limit to no. of components */		    dirNamePresent = True;                    if (filenameSet) {                       titlePtr = safeStrCpy(titlePtr, titleEnd, path);                    }                    break;                                   case '0': /* directory with limited no. of components */               case '1':               case '2':               case '3':               case '4':               case '5':               case '6':               case '7':               case '8':               case '9':                   if (*titleFormat == 'd') {                       dirNamePresent = True;                       noOfComponents = c - '0';                       titleFormat++; /* delete the argument */                       if (filenameSet) {                           const char* trailingPath = GetTrailingPathComponents(path,                                                                                noOfComponents);                           /* prefix with ellipsis if components were skipped */                           if (trailingPath > path) {                               titlePtr = safeStrCpy(titlePtr, titleEnd, "...");                           }                           titlePtr = safeStrCpy(titlePtr, titleEnd, trailingPath);                       }                    }                    break;                                    case 'f': /* file name */		    fileNamePresent = True;                    titlePtr = safeStrCpy(titlePtr, titleEnd, filename);                    break;                                    case 'h': /* host name */		    hostNamePresent = True;		    titlePtr = safeStrCpy(titlePtr, titleEnd, GetNameOfHost());                    break;		                    case 'S': /* file status */                    fileStatusPresent = True;                    if (IS_ANY_LOCKED_IGNORING_USER(lockReasons) && fileChanged)                       titlePtr = safeStrCpy(titlePtr, titleEnd, "read only, modified");                    else if (IS_ANY_LOCKED_IGNORING_USER(lockReasons))                       titlePtr = safeStrCpy(titlePtr, titleEnd, "read only");                    else if (IS_USER_LOCKED(lockReasons) && fileChanged)                       titlePtr = safeStrCpy(titlePtr, titleEnd, "locked, modified");                    else if (IS_USER_LOCKED(lockReasons))                       titlePtr = safeStrCpy(titlePtr, titleEnd, "locked");                    else if (fileChanged)                       titlePtr = safeStrCpy(titlePtr, titleEnd, "modified");                    break;                                    case 'u': /* user name */		    userNamePresent = True;

⌨️ 快捷键说明

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