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

📄 path.c

📁 Graphviz - Graph Drawing Programs from AT&T Research and Lucent Bell Labs See doc/build.html for
💻 C
📖 第 1 页 / 共 2 页
字号:
/* $Id: Path.c,v 1.5 2005/11/13 01:35:10 ellson Exp $ $Revision: 1.5 $ *//* vim:set shiftwidth=4 ts=8: *//***********************************************************      This software is part of the graphviz package      **                http://www.graphviz.org/                 **                                                         **            Copyright (c) 1994-2004 AT&T Corp.           **                and is licensed under the                **            Common Public License, Version 1.0           **                      by AT&T Corp.                      **                                                         **        Information and Software Systems Research        **              AT&T Research, Florham Park NJ             ***********************************************************/#ifdef FEATURE_CS#include <ast.h>#endif/* * Copyright 1989 Software Research Associates, Inc., Tokyo, Japan * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose and without fee is hereby granted, provided * that the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting * documentation, and that the name of Software Research Associates not be used * in advertising or publicity pertaining to distribution of the software * without specific, written prior permission.  Software Research Associates * makes no representations about the suitability of this software for any * purpose.  It is provided "as is" without express or implied warranty. * * SOFTWARE RESEARCH ASSOCIATES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, * IN NO EVENT SHALL SOFTWARE RESEARCH ASSOCIATES BE LIABLE FOR ANY SPECIAL, * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. * * Author: Erik M. van der Poel *         Software Research Associates, Inc., Tokyo, Japan *         erik@sra.co.jp */#ifdef HAVE_CONFIG_H#include "config.h"#endif#include <stdio.h>#ifdef SEL_FILE_IGNORE_CASE#include <ctype.h>#endif /* def SEL_FILE_IGNORE_CASE */#include <X11/Xos.h>#include <pwd.h>#include "SFinternal.h"#include "xstat.h"#include <X11/Xaw/Scrollbar.h>#if defined (SVR4) || defined (SYSV) || defined (USG)extern uid_t getuid ();extern void qsort ();#endif /* defined (SVR4) || defined (SYSV) || defined (USG) */#ifdef HAVE_STDLIB_H#include <stdlib.h>#endif#include "SFDecls.h"#ifdef HAVE_STDINT_H#include <stdint.h>#endif#ifdef HAVE_INTTYPES_H#include <inttypes.h>#endif#ifdef HAVE_INTPTR_T#define INT2PTR(t,v) ((t)(intptr_t)(v))#define PTR2INT(v) ((Sflong_t)(intptr_t)(v))#else#define INT2PTR(t,v) ((t)(v))#define PTR2INT(v) ((Sflong_t)(v))#endiftypedef struct {    char *name;    char *dir;} SFLogin;SFDir *SFdirs = NULL;int SFdirEnd;int SFdirPtr;int SFbuttonPressed = 0;static int SFdoNotTouchDirPtr = 0;static int SFdoNotTouchVorigin = 0;static SFDir SFrootDir, SFhomeDir;static SFLogin *SFlogins;static int SFtwiddle = 0;void SFsetText (char *path);int SFchdir (char *path) {    int result;    result = 0;    if (strcmp (path, SFcurrentDir)) {        result = chdir (path);        if (!result) {            strcpy (SFcurrentDir, path);        }    }    return result;}static void SFfree (int i) {    SFDir *dir;    int   j;    dir = &(SFdirs[i]);    for (j = dir->nEntries - 1; j >= 0; j--) {        if (dir->entries[j].shown != dir->entries[j].real) {            XtFree (dir->entries[j].shown);        }        XtFree (dir->entries[j].real);    }    XtFree ((char *) dir->entries);    XtFree (dir->dir);    dir->dir = NULL;}static void SFstrdup (char **s1, char *s2) {    *s1 = strcpy (XtMalloc ((unsigned) (strlen (s2) + 1)), s2);}static void SFunreadableDir (SFDir *dir) {    char *cannotOpen = "<cannot open> ";    dir->entries = (SFEntry *) XtMalloc (sizeof (SFEntry));    dir->entries[0].statDone = 1;    SFstrdup (&dir->entries[0].real, cannotOpen);    dir->entries[0].shown = dir->entries[0].real;    dir->nEntries = 1;    dir->nChars = strlen (cannotOpen);}#ifdef SEL_FILE_IGNORE_CASEstatic int SFstrncmp (char *p, char *q, int n) {    char c1, c2;    char *psave, *qsave;    int  nsave;    psave = p;    qsave = q;    nsave = n;    c1 = *p++;    if (islower (c1)) {        c1 = toupper (c1);    }    c2 = *q++;    if (islower (c2)) {        c2 = toupper (c2);    }    while ((--n >= 0) && (c1 == c2)) {        if (!c1) {            return strncmp (psave, qsave, nsave);        }        c1 = *p++;        if (islower (c1)) {            c1 = toupper (c1);        }        c2 = *q++;        if (islower (c2)) {            c2 = toupper (c2);        }    }    if (n < 0) {        return strncmp (psave, qsave, nsave);    }    return c1 - c2;}#endif /* def SEL_FILE_IGNORE_CASE */static void SFreplaceText (SFDir *dir, char *str) {    int len;    *(dir->path) = 0;    len = strlen (str);    if (str[len - 1] == '/') {        strcat (SFcurrentPath, str);    } else {        strncat (SFcurrentPath, str, len - 1);    }    if (strncmp (SFcurrentPath, SFstartDir, strlen (SFstartDir))) {        SFsetText (SFcurrentPath);    } else {        SFsetText (& (SFcurrentPath[strlen (SFstartDir)]));    }    SFtextChanged ();}static void SFexpand (char *str) {    int     len;    int     cmp;    char    *name, *growing;    SFDir   *dir;    SFEntry *entry, *max;    len = strlen (str);    dir = &(SFdirs[SFdirEnd - 1]);    if (dir->beginSelection == -1) {        SFstrdup (&str, str);        SFreplaceText (dir, str);        XtFree (str);        return;    } else if (dir->beginSelection == dir->endSelection) {        SFreplaceText (dir, dir->entries[dir->beginSelection].shown);        return;    }    max = &(dir->entries[dir->endSelection + 1]);    name = dir->entries[dir->beginSelection].shown;    SFstrdup (&growing, name);    cmp = 0;    while (!cmp) {        entry = & (dir->entries[dir->beginSelection]);        while (entry < max) {            if ((cmp = strncmp (growing, entry->shown, len))) {                break;            }            entry++;        }        len++;    }    /* SFreplaceText () expects filename */    growing[len - 2] = ' ';    growing[len - 1] = 0;    SFreplaceText (dir, growing);    XtFree (growing);}static int SFfindFile (SFDir *dir, char *str) {    int     i, last, max;    char    *name, save;    SFEntry *entries;    int     len;    int     begin, end;    int     result;    len = strlen (str);    if (str[len - 1] == ' ') {        SFexpand (str);        return 1;    } else if (str[len - 1] == '/') {        len--;    }    max = dir->nEntries;    entries = dir->entries;    i = 0;    while (i < max) {        name = entries[i].shown;        last = strlen (name) - 1;        save = name[last];        name[last] = 0;#ifdef SEL_FILE_IGNORE_CASE        result = SFstrncmp (str, name, len);#else /* def SEL_FILE_IGNORE_CASE */        result = strncmp (str, name, len);#endif /* def SEL_FILE_IGNORE_CASE */        name[last] = save;        if (result <= 0) {            break;        }        i++;    }    begin = i;    while (i < max) {        name = entries[i].shown;        last = strlen (name) - 1;        save = name[last];        name[last] = 0;#ifdef SEL_FILE_IGNORE_CASE        result = SFstrncmp (str, name, len);#else /* def SEL_FILE_IGNORE_CASE */        result = strncmp (str, name, len);#endif /* def SEL_FILE_IGNORE_CASE */        name[last] = save;        if (result) {            break;        }        i++;    }    end = i;    if (begin != end) {        if ((dir->beginSelection != begin) || (dir->endSelection != end - 1)) {            dir->changed = 1;            dir->beginSelection = begin;            if (str[strlen (str) - 1] == '/') {                dir->endSelection = begin;            } else {                dir->endSelection = end - 1;            }        }    } else {        if (dir->beginSelection != -1) {            dir->changed = 1;            dir->beginSelection = -1;            dir->endSelection = -1;        }    }    if (        SFdoNotTouchVorigin ||        ((begin > dir->vOrigin) && (end < dir->vOrigin + SFlistSize))    ) {        SFdoNotTouchVorigin = 0;        return 0;    }    i = begin - 1;    if (i > max - SFlistSize) {        i = max - SFlistSize;    }    if (i < 0) {        i = 0;    }    if (dir->vOrigin != i) {        dir->vOrigin = i;        dir->changed = 1;    }    return 0;}static void SFunselect (void) {    SFDir *dir;    dir = &(SFdirs[SFdirEnd - 1]);    if (dir->beginSelection != -1) {        dir->changed = 1;    }    dir->beginSelection = -1;    dir->endSelection = -1;}static int SFcompareLogins (const void *vp, const void *vq) {    SFLogin *p = (SFLogin *) vp, *q = (SFLogin *) vq;    return strcmp (p->name, q->name);}static void SFgetHomeDirs (void) {    struct passwd *pw;    int           alloc;    int           i;    SFEntry       *entries = NULL;    int           len;    int           maxChars;    alloc = 1;    i = 1;    entries = (SFEntry *) XtMalloc (sizeof (SFEntry));    SFlogins = (SFLogin *) XtMalloc (sizeof (SFLogin));    entries[0].real = XtMalloc (3);    strcpy (entries[0].real, "~");    entries[0].shown = entries[0].real;    entries[0].statDone = 1;    SFlogins[0].name = "";    pw = getpwuid ((int) getuid ());    SFstrdup (&SFlogins[0].dir, pw ? pw->pw_dir : "/");    maxChars = 0;    setpwent ();    while ((pw = getpwent ()) && (*(pw->pw_name))) {        if (i >= alloc) {            alloc *= 2;            entries = (SFEntry *) XtRealloc (                (char *) entries, (unsigned) (alloc * sizeof (SFEntry))            );            SFlogins = (SFLogin *) XtRealloc (                (char *) SFlogins, (unsigned) (alloc * sizeof (SFLogin))            );        }        len = strlen (pw->pw_name);        entries[i].real = XtMalloc ((unsigned) (len + 3));        strcat (strcpy (entries[i].real, "~"), pw->pw_name);        entries[i].shown = entries[i].real;

⌨️ 快捷键说明

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