📄 main.c
字号:
# ifdef XFT_SUPPORT free (r->XftColors); r->XftColors = NULL;# endif free (r->h); r->h = NULL; free (r); r = NULL;/* #endif */ /* DEBUG */ exit(EXIT_SUCCESS);}/* ------------------------------------------------------------------------- * * MEMORY ALLOCATION WRAPPERS * * ------------------------------------------------------------------------- *//* EXTPROTO */void*rxvt_malloc(size_t size){ void* p; /* see AC_FUNC_MALLOC macro in autoconf documentation */ if (0 == size) size = 1; p = malloc(size); if (p) return p; fprintf(stderr, APL_NAME ": memory allocation failure. Aborting"); exit(EXIT_FAILURE); /* NOTREACHED */}/* EXTPROTO */void*rxvt_calloc(size_t number, size_t size){ void* p; p = calloc(number, size); if (p) return p; fprintf(stderr, APL_NAME ": memory allocation failure. Aborting"); exit(EXIT_FAILURE); /* NOTREACHED */}/* EXTPROTO */void*rxvt_realloc(void *ptr, size_t size){ void* p; if (ptr) p = realloc(ptr, size); else p = malloc(size); if (p) return p; fprintf(stderr, APL_NAME ": memory allocation failure. Aborting"); exit(EXIT_FAILURE); /* NOTREACHED */}/* ------------------------------------------------------------------------- * * PRIVILEGED OPERATIONS * * ------------------------------------------------------------------------- */#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(OS_CYGWIN)static uid_t g_euid;static gid_t g_egid;#endif/* take care of suid/sgid super-user (root) privileges *//* EXTPROTO */voidrxvt_privileges(int mode){#if !defined(OS_CYGWIN)# if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID)/* setreuid() is the poor man's setuid(), seteuid() */# define seteuid(a) setreuid(-1, (a))# define setegid(a) setregid(-1, (a))# define HAVE_SETEUID# endif# ifdef HAVE_SETEUID switch (mode) { case IGNORE: /* * change effective uid/gid - not real uid/gid - so we can switch * back to root later, as required */ seteuid(getuid()); setegid(getgid()); break; case SAVE: g_euid = geteuid(); g_egid = getegid(); break; case RESTORE: seteuid(g_euid); setegid(g_egid); break; }# else switch (mode) { case IGNORE: if (setuid(getuid()) < 0) exit (EXIT_FAILURE); if (setgid(getgid()) < 0) exit (EXIT_FAILURE); /* FALLTHROUGH */ case SAVE: /* FALLTHROUGH */ case RESTORE: break; }# endif#endif}#ifdef UTMP_SUPPORT/* EXTPROTO */voidrxvt_privileged_utmp(rxvt_t* r, int page, char action){ DBG_MSG(1,(stderr, "rxvt_privileged_utmp %d (%c); waiting for: %c (pid: %d)\n", page, action, PVTS(r, page)->next_utmp_action, (int) getpid())); if (PVTS(r, page)->next_utmp_action != action || (action != SAVE && action != RESTORE) || (r->Options & Opt_utmpInhibit) || PVTS(r, page)->ttydev == NULL || *(PVTS(r, page)->ttydev) == (char) 0) return; rxvt_privileges(RESTORE); if (action == SAVE) { PVTS(r, page)->next_utmp_action = RESTORE; rxvt_makeutent(r, page, PVTS(r, page)->ttydev, r->h->rs[Rs_display_name]); } else /* action == RESTORE */ { PVTS(r, page)->next_utmp_action = IGNORE; rxvt_cleanutent(r, page); } rxvt_privileges(IGNORE);}#endif#ifndef NO_SETOWNER_TTYDEV/* EXTPROTO */voidrxvt_privileged_ttydev(rxvt_t* r, int page, char action){ DBG_MSG(1,(stderr, "rxvt_privileged_ttydev %d (r, %c); waiting for: %c (pid: %d)\n", page, action, PVTS(r, page)->next_tty_action, getpid())); if (PVTS(r, page)->next_tty_action != action || (action != SAVE && action != RESTORE) || PVTS(r, page)->ttydev == NULL || *(PVTS(r, page)->ttydev) == (char) 0) return; rxvt_privileges(RESTORE); if (action == SAVE) { PVTS(r, page)->next_tty_action = RESTORE;# ifndef RESET_TTY_TO_COMMON_DEFAULTS/* store original tty status for restoration rxvt_clean_exit() -- rgg 04/12/95 */ if (lstat(PVTS(r, page)->ttydev, &h->ttyfd_stat) < 0) /* you lose out */ PVTS(r, page)->next_tty_action = IGNORE; else# endif { /* fail silently */ chown(PVTS(r, page)->ttydev, getuid(), r->h->ttygid); chmod(PVTS(r, page)->ttydev, PVTS(r, page)->ttymode);# ifdef HAVE_REVOKE revoke(PVTS(r, page)->ttydev);# endif } } else /* action == RESTORE */ { PVTS(r, page)->next_tty_action = IGNORE;# ifndef RESET_TTY_TO_COMMON_DEFAULTS chmod(PVTS(r, page)->ttydev, PVTS(r, page)->ttyfd_stat.st_mode); chown(PVTS(r, page)->ttydev, PVTS(r, page)->ttyfd_stat.st_uid, PVTS(r, page)->ttyfd_stat.st_gid);# else chmod(PVTS(r, page)->ttydev, (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)); chown(PVTS(r, page)->ttydev, 0, 0);# endif } rxvt_privileges(IGNORE);# ifndef RESET_TTY_TO_COMMON_DEFAULTS DBG_MSG(1,(stderr, "%s \"%s\": mode %03o, uid %d, gid %d\n", action == RESTORE ? "Restoring" : (action == SAVE ? "Saving" : "UNKNOWN ERROR for"), PVTS(r, page)->ttydev, PVTS(r, page)->ttyfd_stat.st_mode, PVTS(r, page)->ttyfd_stat.st_uid, PVTS(r, page)->ttyfd_stat.st_gid));# endif}#endif/*----------------------------------------------------------------------*//* * Tell the teletype handler what size the window is. * Called after a window size change. *//* EXTPROTO */voidrxvt_tt_winsize(int fd, unsigned short col, unsigned short row, pid_t pid){ struct winsize ws; if (fd < 0) return; ws.ws_col = col; ws.ws_row = row; ws.ws_xpixel = ws.ws_ypixel = 0;#ifndef DEBUG (void)ioctl(fd, TIOCSWINSZ, &ws);#else if (ioctl(fd, TIOCSWINSZ, &ws) < 0) { DBG_MSG(1,(stderr, "Failed to send TIOCSWINSZ to fd %d\n", fd)); }# ifdef SIGWINCH else if (pid) /* force through to the command */ kill(pid, SIGWINCH);# endif#endif /* DEBUG */}#define IDX2FNUM(i) ((FONT0_IDX + i) % MAX_NFONTS)#define FNUM2IDX(f) ((FONT0_IDX + f) % MAX_NFONTS)#ifdef XFT_SUPPORT# ifndef NO_BOLDFONT/* INTPROTO */voidrxvt_init_bfont_xft (rxvt_t* r, XftPattern* xpold){ XftResult fr; XftPattern* xp;# ifdef DEBUG FT_Face face;# endif if (r->h->rs[Rs_xftwt] && !STRCASECMP(r->h->rs[Rs_xftwt], "bold")) return ; xp = XftPatternDuplicate (xpold); if (NULL == xp) return ; /* set font weight */ XftPatternDel (xp, XFT_WEIGHT); XftPatternAddInteger (xp, XFT_WEIGHT, XFT_WEIGHT_BOLD); r->TermWin.xftbpattern = XftFontMatch (r->Xdisplay, XSCREEN, xp, &fr); if (NULL != r->TermWin.xftbpattern) { r->TermWin.xftbfont = XftFontOpenPattern (r->Xdisplay, r->TermWin.xftbpattern); if (NULL == r->TermWin.xftbfont) { /* fall back to normal font */ XftPatternDestroy (r->TermWin.xftbpattern); r->TermWin.xftbpattern = NULL; }# ifdef DEBUG else { face = XftLockFace (r->TermWin.xftbfont); XftUnlockFace (r->TermWin.xftbfont); }# endif } XftPatternDestroy (xp);}# endif /* NO_BOLDFONT */# ifdef MULTICHAR_SET/* INTPROTO */intrxvt_init_mfont_xft (rxvt_t* r, XftPattern* xp, const char* ofname){ XftResult fr; int len, olen; /* font name length */ char* mfname; /* mfont name to open */ char* omfname = NULL; /* actually opened mfont name */ int width, height;# ifdef DEBUG FT_Face face;# endif /* temporary XftPattern */ assert (NULL != xp); /* actually opened normal font name */ assert (NULL != ofname); /* ** Now try to open freetype mfont */ DBG_MSG(2,(stderr, "load freetype mfont\n")); /* font family */ mfname = (char*) r->h->rs[Rs_xftmfont]; if (NULL == mfname) mfname = rxvt_fallback_mfont_xft (r); /* * If we should not use mfont, then we always use normal font */ if (r->Options2 & Opt2_xftNomFont) { r->TermWin.xftmpattern = r->TermWin.xftpattern; r->TermWin.xftmfont = r->TermWin.xftfont; return 1; } /* * shortcut: * mfont is the same as font, just alias mfont to font */ if (0 == STRCASECMP (ofname, mfname)) { r->TermWin.xftmpattern = r->TermWin.xftpattern; r->TermWin.xftmfont = r->TermWin.xftfont; return 1; } /* font family */ XftPatternDel (xp, XFT_FAMILY); XftPatternAddString (xp, XFT_FAMILY, mfname); XftPatternDel (xp, XFT_SIZE); /* * 2006-02-11 gi1242: This is however HORRIBLE for regular fonts. It's * probably better to fall back to xftsz. Thus the random user who knows * nothing about mrxvt (or encodings) will get a reasonable looking terminal * by default. */#if 0 /* this seems to be optimal for simsun font */ XftPatternAddDouble (xp, XFT_SIZE, r->h->rs[Rs_xftmsz] ? (double) r->TermWin.xftmsize : (double) (r->TermWin.xftfont->height - 1));#endif XftPatternAddDouble( xp, XFT_SIZE, (r->h->rs[Rs_xftmsz] ? (double) r->TermWin.xftmsize : (double) r->TermWin.xftsize)); /* * XXX 2006-01-26 gi1242: I don't know anything about mfont. Not sure if it * should be monospaced or not. Original mrxvt code did not have mono space * for any font, so I remove it here for the mfont. */#if 0 XftPatternDel (xp, XFT_SPACING);#endif /* font pattern */ r->TermWin.xftmpattern = XftFontMatch (r->Xdisplay, XSCREEN, xp, &fr); if (NULL == r->TermWin.xftmpattern) return 0; /* globaladvance */ if (r->Options2 & Opt2_xftGlobalAdvance) { XftPatternDel (r->TermWin.xftmpattern, FC_GLOBAL_ADVANCE); XftPatternAddBool (r->TermWin.xftmpattern, FC_GLOBAL_ADVANCE, FcTrue); }# ifdef DEBUG_VERBOSE FcPatternPrint (r->TermWin.xftmpattern);# endif /* * Print a warning if our matched mfont is different from the user supplied * font. */ XftPatternGetString (r->TermWin.xftmpattern, XFT_FAMILY, 0, &omfname); assert (NULL != omfname); /* shouldn't be NULL */ len = STRLEN(mfname); olen = STRLEN(omfname); if( STRCMP( mfname, DEFAULT_XFT_FONT_NAME) /* Not the default font */ /* Not opened font */ && (len != olen || STRNCASECMP(omfname, mfname, len)) ) rxvt_print_error ("Cannot open mfont '%s'. Using mfont '%s' instead.", mfname, omfname); DBG_MSG(1, (stderr, "create xftmpattern = 0x%x on mfont %d\n", (unsigned int) r->TermWin.xftmpattern, r->h->rs[Rs_xftmsz] ? r->TermWin.xftmsize : r->TermWin.xftfont->height-1)); /* * Actually open the mfont. */ r->TermWin.xftmfont = XftFontOpenPattern(r->Xdisplay, r->TermWin.xftmpattern); if (NULL == r->TermWin.xftmfont) goto Failure;# ifdef DEBUG face = XftLockFace (r->TermWin.xftmfont); XftUnlockFace (r->TermWin.xftmfont);# endif width = r->TermWin.xftmfont->max_advance_width; if ((width & 0x01) == 1) /* in case width is not even */ r->TermWin.xftmono = 0; else if ( STRCASECMP (ofname, omfname) && (r->TermWin.fwidth != (width >> 1)) ) r->TermWin.xftmono = 0; else if (r->Options2 & Opt2_xftSlowOutput) r->TermWin.xftmono = 0; DBG_MSG(1, (stderr, "xftmono is %d\n", r->TermWin.xftmono)); MAX_IT (r->TermWin.fwidth, (width >> 1)); if( !r->TermWin.xftpfont ) r->TermWin.pwidth = r->TermWin.fwidth; height = r->TermWin.xftmfont->ascent + r->TermWin.xftmfont->descent;# ifndef NO_LINESPACE height += r->TermWin.lineSpace;# endif MAX_IT (r->TermWin.fheight, height); if( !r->TermWin.xftpfont ) r->TermWin.pheight = r->TermWin.fheight; return 1;Failure: if (r->TermWin.xftmpattern) { XftPatternDestroy (r->TermWin.xftmpattern); r->TermWin.xftmpattern = NULL; } return 0;}# endif /* MULTICHAR_SET *//* EXTPROTO */intrxvt_init_font_xft (rxvt_t* r){ XftResult fr; XftPattern* xp; XGlyphInfo ext1, ext2; int len, olen; /* font name length */ char* fname; /* font name to open */ char* ofname = NULL; /* actually opened font name */# ifdef DEBUG FT_Face face;# endif DBG_MSG(2,(stderr, "rxvt_init_font_xft\n")); DBG_MSG(2,(stderr, "load freetype font\n")); xp = XftPatternCreate (); if (NULL == xp) return 0; /* font family */ fname = (char*) r->h->rs[Rs_xftfont]; if (NULL == fname) fname = DEFAULT_XFT_FONT_NAME; XftPatternAddString (xp, XFT_FAMILY, fname); /* No spacing between lines */ XftPatternAddBool (xp, XFT_MINSPACE, FcFalse); /* antialias */ if (r->Options2 & Opt2_xftAntialias) XftPatternAddBool (xp, XFT_ANTIALIAS, FcTrue); else XftPatternAddBool (xp, XFT_ANTIALIAS, FcFalse); /* hinting */ if (r->Options2 & Opt2_xftHinting) XftPatternAddBool (xp, FC_HINTING, FcTrue); else XftPatternAddBool (xp, FC_HINTING, FcFalse); /* autohint */ if (r->Options2 & Opt2_xftAutoHint) XftPatternAddBool (xp, FC_AUTOHINT, FcTrue); else XftPatternAddBool (xp, FC_AUTOHINT, FcFalse); /* font size, we always set it. if it's not set by the user, we ** have chosen a default value (12) for it */ XftPatternAddDouble (xp, XFT_SIZE, (double) r->TermWin.xftsize); /* Enforce Size/Pixel_Size = 1.0 */ XftPatternAddDouble (xp, XFT_SCALE, (double) 1.0); /* font width */ if (r->h->rs[Rs_xftwd])
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -