?? parser.c
字號:
return NULL; /* can't have any more options */#if 0 case 'r': trace("-r some Digital Unix thing about warnings...\n"); trace(" or SCO's option to chroot() for new /proc and /dev.\n"); return "The -r option is reserved."; break;#endif case 's': /* end */ trace("-s Select processes belonging to the sessions given.\n"); arg=get_opt_arg(); if(!arg) return "List of session IDs must follow -s."; err=parse_list(arg, parse_pid); if(err) return err; selection_list->typecode = SEL_SESS; return NULL; /* can't have any more options */ case 't': /* end */ trace("-t select by tty.\n"); arg=get_opt_arg(); if(!arg) return "List of terminals (pty, tty...) must follow -t."; err=parse_list(arg, parse_tty); if(err) return err; selection_list->typecode = SEL_TTY; return NULL; /* can't have any more options */ case 'u': /* end */ trace("-u select by user ID (the EUID?) (supports names).\n"); arg=get_opt_arg(); if(!arg) return "List of users must follow -u."; err=parse_list(arg, parse_uid); if(err) return err; selection_list->typecode = SEL_EUID; return NULL; /* can't have any more options */ case 'w': trace("-w wide output.\n"); w_count++; break; case 'x': /* behind personality until "ps -ax" habit is uncommon */ if(personality & PER_SVR4_x){ // Same as -y, but for System V Release 4 MP trace("-x works like Sun Solaris & SCO Unixware -y option\n"); format_modifiers |= FM_y; break; } if(personality & PER_HPUX_x){ trace("-x extends the command line\n"); w_count += 2; unix_f_option = 1; break; } return "Must set personality to get -x option."; case 'y': /* Sun's -l hack (also: Irix "lnode" resource control info) */ trace("-y Print lnone info in UID/USER column or do Sun -l hack.\n"); format_modifiers |= FM_y; break;#if 0 // This must be verified against SVR4-MP (UnixWare or Powermax) case 'z': /* alias of Mandatory Access Control level info */ trace("-z shows aliased MAC info\n"); format_modifiers |= FM_M; break; // Solaris 10 does this case 'z': /* select by zone */ trace("-z secects by zone\n"); arg=get_opt_arg(); if(!arg) return "List of zones (contexts, labels, whatever?) must follow -z."; err=parse_list(arg, parse_zone); if(err) return err; selection_list->typecode = SEL_ZONE; return NULL; /* can't have any more options */#endif case '-': return "Embedded '-' among SysV options makes no sense."; break; case '\0': return "Please report the \"SysV \\0 can't happen\" bug."; break; default: return "Unsupported SysV option."; } /* switch */ } /* while */ return NULL;}/************************* parse BSD options **********************/static const char *parse_bsd_option(void){ const char *arg; const char *err; flagptr = ps_argv[thisarg]; /* assume we _have_ a '-' */ if(flagptr[0]=='-'){ if(!force_bsd) return "Can't happen! Problem #1."; }else{ flagptr--; /* off beginning, will increment before use */ if(personality & PER_FORCE_BSD){ if(!force_bsd) return "Can't happen! Problem #2."; }else{ if(force_bsd) return "2nd chance parse failed, not BSD or SysV."; } } while(*++flagptr){ switch(*flagptr){ case '0' ... '9': /* end */ trace("0..9 Old BSD-style select by process ID\n"); arg=flagptr; err=parse_list(arg, parse_pid); if(err) return err; selection_list->typecode = SEL_PID; return NULL; /* can't have any more options */#if 0 case 'A': /* maybe this just does a larger malloc() ? */ trace("A Increases the argument space (Digital Unix)\n"); return "Option A is reserved."; break; case 'C': /* should divide result by 1-(e**(foo*log(bar))) */ trace("C Use raw CPU time for %%CPU instead of decaying ave\n"); return "Option C is reserved."; break;#endif case 'H': // The FreeBSD way (NetBSD:s OpenBSD:k FreeBSD:H -- NIH???) trace("H Print LWP (thread) info.\n"); // was: Use /vmcore as c-dumpfile\n"); thread_flags |= TF_B_H; //format_modifiers |= FM_L; // FIXME: determine if we need something like this break; case 'L': /* single */ trace("L List all format specifiers\n"); exclusive("L"); print_format_specifiers(); exit(0); case 'M': // undocumented for now: these are proliferating! trace("M MacOS X thread display, like AIX/Tru64\n"); thread_flags |= TF_B_m; break; case 'N': /* end */ trace("N Specify namelist file\n"); arg=get_opt_arg(); if(!arg) return "Alternate System.map file must follow N."; namelist_file = arg; return NULL; /* can't have any more options */ case 'O': /* end */ trace("O Like o + defaults, add new columns after PID. Also sort.\n"); arg=get_opt_arg(); if(!arg) return "Format or sort specification must follow O."; defer_sf_option(arg, SF_B_O); return NULL; /* can't have any more options */ break; case 'S': trace("S include dead kids in sum\n"); include_dead_children = 1; break; case 'T': trace("T Select all processes on this terminal\n"); /* put our tty on a tiny list */ { selection_node *node; node = malloc(sizeof(selection_node)); node->u = malloc(sizeof(sel_union)); node->u[0].tty = cached_tty; node->typecode = SEL_TTY; node->n = 1; node->next = selection_list; selection_list = node; } break; case 'U': /* end */ trace("U Select processes for specified users.\n"); arg=get_opt_arg(); if(!arg) return "List of users must follow U."; err=parse_list(arg, parse_uid); if(err) return err; selection_list->typecode = SEL_EUID; return NULL; /* can't have any more options */ case 'V': /* single */ trace("V show version info\n"); exclusive("V"); display_version(); exit(0); case 'W': trace("W N/A get swap info from ... not /dev/drum.\n"); return "Obsolete W option not supported. (You have a /dev/drum?)"; break; case 'X': trace("X Old Linux i386 register format\n"); format_flags |= FF_LX; break; case 'Z': /* FreeBSD does MAC like SGI's Irix does it */ trace("Z Print security label for Mandatory Access Control.\n"); format_modifiers |= FM_M; break; case 'a': trace("a Select all w/tty, including other users\n"); simple_select |= SS_B_a; break; case 'c': trace("c true command name\n"); bsd_c_option = 1; break; case 'e': trace("e environment\n"); bsd_e_option = 1; break; case 'f': trace("f ASCII art forest\n"); forest_type = 'b'; break; case 'g': trace("g _all_, even group leaders!.\n"); simple_select |= SS_B_g; break; case 'h': trace("h Repeat header... yow.\n"); if(header_type) return "Only one heading option may be specified."; if(personality & PER_BSD_h) header_type = HEAD_MULTI; else header_type = HEAD_NONE; break; case 'j': trace("j job control format\n"); format_flags |= FF_Bj; break; case 'k': // OpenBSD: don't hide "kernel threads" -- like the swapper? // trace("k Print LWP (thread) info.\n"); // was: Use /vmcore as c-dumpfile\n"); // NetBSD, and soon (?) FreeBSD: sort-by-keyword trace("k Specify sorting keywords.\n"); arg=get_opt_arg(); if(!arg) return "Long sort specification must follow 'k'."; defer_sf_option(arg, SF_G_sort); return NULL; /* can't have any more options */ case 'l': trace("l Display long format\n"); format_flags |= FF_Bl; break; case 'm': trace("m all threads, sort on mem use, show mem info\n"); if(personality & PER_OLD_m){ format_flags |= FF_Lm; break; } if(personality & PER_BSD_m){ defer_sf_option("pmem", SF_B_m); break; } thread_flags |= TF_B_m; break; case 'n': trace("n Numeric output for WCHAN, and USER replaced by UID\n"); wchan_is_number = 1; user_is_number = 1; /* TODO add tty_is_number too? */ break; case 'o': /* end */ trace("o Specify user-defined format\n"); arg=get_opt_arg(); if(!arg) return "Format specification must follow o."; defer_sf_option(arg, SF_B_o); return NULL; /* can't have any more options */ case 'p': /* end */ trace("p Select by process ID\n"); arg=get_opt_arg(); if(!arg) return "List of process IDs must follow p."; err=parse_list(arg, parse_pid); if(err) return err; selection_list->typecode = SEL_PID; return NULL; /* can't have any more options */ case 'r': trace("r Select running processes\n"); running_only = 1; break; case 's': trace("s Display signal format\n"); format_flags |= FF_Bs; break; case 't': /* end */ trace("t Select by tty.\n"); /* List of terminals (tty, pty...) _should_ follow t. */ arg=get_opt_arg(); if(!arg){ /* Wow, obsolete BSD syntax. Put our tty on a tiny list. */ selection_node *node; node = malloc(sizeof(selection_node)); node->u = malloc(sizeof(sel_union)); node->u[0].tty = cached_tty; node->typecode = SEL_TTY; node->n = 1; node->next = selection_list; selection_list = node; return NULL; } err=parse_list(arg, parse_tty); if(err) return err; selection_list->typecode = SEL_TTY; return NULL; /* can't have any more options */ case 'u': trace("u Display user-oriented\n"); format_flags |= FF_Bu; break; case 'v': trace("v Display virtual memory\n"); format_flags |= FF_Bv; break; case 'w': trace("w wide output\n"); w_count++; break; case 'x': trace("x Select processes without controlling ttys\n"); simple_select |= SS_B_x; break;#if 0 case 'y': // DragonFlyBSD iac (interactivity measure) format // uid,pid,ppid,cpu,pri,iac,nice,wchan,state,tt,time,command // (they use 'Y' to sort by this "iac" thing; 'y' implies 'Y') // Range is -127 .. 127, with lower numbers being more // interactive and higher numbers more batch-like. trace("y Display interactivity measure\n"); format_flags |= FF_Bv; break;#endif case '-': return "Embedded '-' among BSD options makes no sense."; break; case '\0': return "Please report the \"BSD \\0 can't happen\" bug."; break; default: return "Unsupported option (BSD syntax)"; } /* switch */ } /* while */ return NULL;}/*************** gnu long options **********************//* * Return the argument or NULL */static const char *grab_gnu_arg(void){ switch(*flagptr){ /* argument is part of ps_argv[thisarg] */ default: return NULL; /* something bad */ case '=': case ':': if(*++flagptr) return flagptr; /* found it */ return NULL; /* empty '=' or ':' */ case '\0': /* try next argv[] */ ; } if(thisarg+2 > ps_argc) return NULL; /* there is nothing left */ /* argument follows ps_argv[thisarg] */ if(*(ps_argv[thisarg+1]) == '\0') return NULL; return ps_argv[++thisarg];}typedef struct gnu_table_struct { const char *name; /* long option name */ const void *jump; /* See gcc extension info. :-) */} gnu_table_struct;static int compare_gnu_table_structs(const void *a, const void *b){ return strcmp(((const gnu_table_struct*)a)->name,((const gnu_table_struct*)b)->name);}/* Option arguments are after ':', after '=', or in argv[n+1] */static const char *parse_gnu_option(void){ const char *arg; const char *err; char *s; size_t sl; char buf[16]; gnu_table_struct findme = { buf, NULL}; gnu_table_struct *found; static const gnu_table_struct gnu_table[] = { {"Group", &&case_Group}, /* rgid */ {"User", &&case_User}, /* ruid */ {"cols", &&case_cols}, {"columns", &&case_columns}, {"context", &&case_context}, {"cumulative", &&case_cumulative}, {"deselect", &&case_deselect}, /* -N */ {"forest", &&case_forest}, /* f -H */ {"format", &&case_format}, {"group", &&case_group}, /* egid */ {"header", &&case_header}, {"headers", &&case_headers}, {"heading", &&case_heading}, {"headings", &&case_headings}, {"help", &&case_help}, {"info", &&case_info}, {"lines", &&case_lines}, {"no-header", &&case_no_header}, {"no-headers", &&case_no_headers}, {"no-heading", &&case_no_heading}, {"no-headings", &&case_no_headings}, {"noheader", &&case_noheader}, {"noheaders", &&case_noheaders}, {"noheading", &&case_noheading}, {"noheadings", &&case_noheadings}, {"pid", &&case_pid}, {"ppid", &&case_ppid}, {"rows", &&case_rows}, {"sid", &&case_sid}, {"sort", &&case_sort}, {"tty", &&case_tty}, {"user", &&case_user}, /* euid */ {"version", &&case_version}, {"width", &&case_width}, }; const int gnu_table_count = sizeof(gnu_table)/sizeof(gnu_table_struct); s = ps_argv[thisarg]+2; sl = strcspn(s,":="); if(sl > 15) return "Unknown gnu long option."; strncpy(buf, s, sl); buf[sl] = '\0'; flagptr = s+sl; found = bsearch(&findme, gnu_table, gnu_table_count,
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -