?? mwm.c
字號:
#else#ifdef HAVE_WAIT3 while ((wait3(NULL, WNOHANG, NULL)) > 0);#else#error You lose: neither waitpid() nor wait3() is available!#endif#endif} * main - start of mwm */intmain(int argc, char **argv){ int i, len; char *display_string; Bool option_error = False; XtSetLanguageProc(NULL, NULL, NULL); toplevel = XtVaAppInitialize(&app, "Mwm", NULL, 0, &argc, argv, NULL, NULL); dpy = XtDisplay(toplevel); for (i = 1; i < argc; i++) { if (strncmp(argv[i], "-debug", 6) == 0) /* non-standard option */ { debugging = True; } else if (strncmp(argv[i], "-multiscreen", 12) == 0) { multiscreen = True; } else if (strncmp(argv[i], "-name", 5) == 0) { if (++i >= argc) usage(); mwm_name = argv[i]; } else if (strncmp(argv[i], "-screens", 8) == 0) { if (++i >= argc) usage(); fprintf(stderr, "-screens is not yet supported\n"); } else if (strncmp(argv[i], "-version", 8) == 0) /* non-standard option */ { fprintf(stdout, "Mwm Version %s\n", VERSION); } else { fprintf(stderr, "mwm: Unknown option: `%s'\n", argv[i]); option_error = True; } } if (option_error) usage(); g_argv = argv; if (signal(SIGINT, SIG_IGN) != SIG_IGN) signal(SIGINT, sig_done); if (signal(SIGHUP, SIG_IGN) != SIG_IGN) signal(SIGHUP, sig_done); if (signal(SIGQUIT, SIG_IGN) != SIG_IGN) signal(SIGQUIT, sig_done); if (signal(SIGTERM, SIG_IGN) != SIG_IGN) signal(SIGTERM, sig_done); signal(SIGUSR1, sig_restart); signal(SIGALRM, sig_alarm);#ifdef HAVE_SYSCONF fd_width = sysconf(_SC_OPEN_MAX);#else# ifdef HAVE_GETDTABLESIZE fd_width = getdtablesize();# else# ifdef HAVE_GETRLIMIT { struct rlimit rl; getrlimit(RLIMIT_NOFILE, &rl); fd_width = rl.rlim_cur; }# else# error You lose# endif# endif#endif#ifdef __CYGWIN__ /* * Ugly hack because sys/types.h defines FD_SETSIZE as 64, * when the comments there say it should be >= NOFILE in param.h, * which happens to be 8192. * * This drops fd_width to 64 to match FD_SETSIZE; */ if (fd_width > FD_SETSIZE) fd_width = FD_SETSIZE;#endif x_fd = XConnectionNumber(dpy); /* * this is enormously dangerous, but _is_ the original code. MLM */ if (fcntl(x_fd, F_SETFD, 1) == -1) { fprintf(stderr, "close-on-exec failed"); exit(1); } /* * Add a DISPLAY entry to the environment, in case we were started * with mwm -display term:0.0 */ len = strlen(XDisplayString(dpy)); display_string = XtMalloc(len + 10); sprintf(display_string, "DISPLAY=%s", XDisplayString(dpy)); SetEnvironment("DISPLAY", XDisplayString(dpy)); /* * Add a HOSTDISPLAY environment variable, which is the same as * DISPLAY, unless display = :0.0 or unix:0.0, in which case the full * host name will be used for ease in networking . */ if (strncmp(display_string, "DISPLAY=:", 9) == 0) { char client[MAXHOSTNAME], *rdisplay_string; gethostname(client, MAXHOSTNAME); rdisplay_string = XtMalloc(len + 14 + strlen(client)); sprintf(rdisplay_string, "%s:%s", client, &display_string[9]); SetEnvironment("HOSTDISPLAY", rdisplay_string); XtFree(rdisplay_string); } else if (strncmp(display_string, "DISPLAY=unix:", 13) == 0) { char client[MAXHOSTNAME], *rdisplay_string; gethostname(client, MAXHOSTNAME); rdisplay_string = XtMalloc(len + 14 + strlen(client)); sprintf(rdisplay_string, "%s:%s", client, &display_string[13]); SetEnvironment("HOSTDISPLAY", rdisplay_string); XtFree(rdisplay_string); } else { char *rdisplay_string; rdisplay_string = XtMalloc(len + 14); sprintf(rdisplay_string, "%s", XDisplayString(dpy)); SetEnvironment("HOSTDISPLAY", rdisplay_string); XtFree(rdisplay_string); } XtFree(display_string); initialize_mwm(); if (debugging) { MouseButton *MouseEntry = Mwm.screen_info[0]->buttons; fprintf(stderr, "Button Bindings:\n"); while (MouseEntry) { fprintf(stderr, "\tfunc %d %s button %d modifier %d context %s\n", MouseEntry->func, _MwmPrintF(MouseEntry->func), MouseEntry->button, MouseEntry->modifier, _MwmPrintC(MouseEntry->context)); MouseEntry = MouseEntry->next; } } while (True) { XEvent event; last_event_type = 0; if (EVENT_Next(&event)) { EVENT_Dispatch(&event); } } return(0);}extern intSetEnvironment(const char *key, const char *value)#ifdef HAVE_PUTENV{ char *str; int len, rc; len=strlen(key)+strlen(value)+2; str=(char *)malloc(len); strcpy(str, key); strcat(str, "="); strcat(str, value); rc=putenv(str); /* do not free 'str' here! */ return rc;}#else#ifdef HAVE_SETENV{ int rc; int overwrite=1; rc=setenv(key, value, overwrite); return rc;}#else#error You lose (neither putenv() nor setenv() are available!)#endif /* #ifdef HAVE_SETENV */#endif /* #ifdef HAVE_PUTENV *//* * find the config file *//* * The "Motif User's Guide [1]" didn't mention what to do if; a. configFile * is NOT defined, b. configFile IS defined but it does not refer to a proper file * (mulformed or unreadable), c. configFile does begin with "~" but not "~/". * The code below deals with these cases for conveniences. * * [1] (http://w3.pppl.gov/misc/motif/MotifUserGuide/en_US/Understanding_the_Resource_Description_File.html) */ extern char *find_config_file(void){ char *buf=NULL; char *head=NULL, *lang=NULL, *home=NULL; char *ptr=Mwm.config_file; struct stat st; Boolean rc=False;#if defined(HAVE_SYS_TYPES_H) && defined(HAVE_PWD_H) struct passwd *passwd;#endif home=getenv("HOME"); lang=getenv("LANG"); /* check for an absolute path in the given resource */#ifdef __EMX__ if ( Mwm.config_file[0]=='/' || (isalpha(Mwm.config_file[0]) && Mwm.config_file[0]==':') )#else if ( Mwm.config_file[0]=='/' )#endif { head = ""; ptr = Mwm.config_file; } else if (Mwm.config_file[0]=='~') { ptr++; if (Mwm.config_file[1] == '/') { /* ~ => $HOME */ head = home; ptr++; } else#if defined(HAVE_SYS_TYPES_H) && defined(HAVE_PWD_H) { /* ~hoge => hoge's home */ char *idx; /* copy user name from "~hoge/foo" */ idx = strchr(ptr, '/'); if (idx == NULL) head = NULL; else { char *tmpbuf; tmpbuf=XtMalloc(idx-ptr+1); strncpy(tmpbuf, ptr, idx-ptr); tmpbuf[idx-ptr]='\0'; passwd = getpwnam(tmpbuf); XtFree(tmpbuf); if (passwd != NULL) { head = XtNewString(passwd->pw_dir); ptr = idx+1; } else head = NULL; /* no such user "hoge" */ } }#else ; /* no <pwd.h>, no ~hoge */ head = NULL;#endif } else { /* search for the current dir */ head = getcwd(XtMalloc(MAX_PATH_LEN), MAX_PATH_LEN); }/* * Head is either * home directory, or * NULL, or * current directory */ if (head && lang) { buf=XtRealloc(buf, strlen(head) + strlen(lang) + strlen(ptr) + 3); sprintf(buf, "%s/%s/%s", head, lang, ptr); if (stat(buf, &st) == 0) { return buf; } } if (head) { buf=XtRealloc(buf, strlen(head) + strlen(ptr) + 2); sprintf(buf, "%s/%s", head, ptr); if (stat(buf, &st) == 0) { return buf; } } if (home && lang) { buf=XtRealloc(buf, strlen(home)+strlen(lang)+strlen(HOME_MWMRC)+3); sprintf(buf, "%s/%s/%s", home, lang, HOME_MWMRC); if (stat(buf, &st) == 0) { return buf; } } if (home) { buf=XtRealloc(buf, strlen(home)+strlen(HOME_MWMRC)+2); sprintf(buf, "%s/%s", home, HOME_MWMRC); if (stat(buf, &st) == 0) { return buf; } } if (lang) { buf=XtRealloc(buf, strlen(MWM_DDIR)+strlen(lang)+strlen(SYSTEM_MWMRC)+3); sprintf(buf, "%s/%s/%s", MWM_DDIR, lang, SYSTEM_MWMRC); if (stat(buf, &st) == 0) { return buf; } } buf=XtRealloc(buf, strlen(MWM_DDIR)+strlen(SYSTEM_MWMRC)+2); sprintf(buf, "%s/%s", MWM_DDIR, SYSTEM_MWMRC); if (stat(buf, &st) == 0) { return buf; } XtFree(buf); /* head is not always a pointer allocated in this function, let's leak those few bytes here ... */ return NULL;}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -