find中的数据结构

  1. struct predicate
  2. {
  3. /* Pointer to the function that implements this predicate. */
  4. PRED_FUNC pred_func;
  5. /* Used for debugging */
  6. const char *p_name;
  7. /* The type of this node. There are two kinds. The first is real
  8. predicates ("primaries") such as -perm, -print, or -exec. The
  9. other kind is operators for combining predicates. */
  10. enum predicate_type p_type;
  11. /* The precedence of this node. Only has meaning for operators. */
  12. enum predicate_precedence p_prec;
  13. /* True if this predicate node produces side effects.
  14. If side_effects are produced
  15. then optimization will not be performed */
  16. bool side_effects;
  17. /* True if this predicate node requires default print be turned off. */
  18. bool no_default_print;
  19. /* True if this predicate node requires a stat system call to execute. */
  20. bool need_stat;
  21. /* True if this predicate node requires knowledge of the file type. */
  22. bool need_type;
  23. /* True if this predicate node requires knowledge of the inode number. */
  24. bool need_inum;
  25. enum EvaluationCost p_cost;
  26. /* est_success_rate is a number between 0.0 and 1.0 */
  27. float est_success_rate;
  28. /* True if this predicate should display control characters literally */
  29. bool literal_control_chars;
  30. /* True if this predicate didn't originate from the user. */
  31. bool artificial;
  32. /* The raw text of the argument of this predicate. */
  33. const char *arg_text;
  34. /* Information needed by the predicate processor.
  35. Next to each member are listed the predicates that use it. */
  36. union
  37. {
  38. const char *str; /* fstype [i]lname [i]name [i]path */
  39. struct re_pattern_buffer *regex; /* regex */
  40. struct exec_val exec_vec; /* exec ok */
  41. struct long_val numinfo; /* gid inum links uid */
  42. struct size_val size; /* size */
  43. uid_t uid; /* user */
  44. gid_t gid; /* group */
  45. struct time_val reftime; /* newer newerXY anewer cnewer mtime atime ctime mmin amin cmin */
  46. struct perm_val perm; /* perm */
  47. struct samefile_file_id samefileid; /* samefile */
  48. bool types[FTYPE_COUNT]; /* file type(s) */
  49. struct format_val printf_vec; /* printf fprintf fprint ls fls print0 fprint0 print */
  50. char *scontext; /* security context */
  51. } args;
  52. /* The next predicate in the user input sequence,
  53. which represents the order in which the user supplied the
  54. predicates on the command line. */
  55. struct predicate *pred_next;
  56. /* The right and left branches from this node in the expression
  57. tree, which represents the order in which the nodes should be
  58. processed. */
  59. struct predicate *pred_left;
  60. struct predicate *pred_right;
  61. struct predicate_performance_info perf;
  62. const struct parser_table* parser_entry;
  63. };
  1. struct parser_table
  2. {
  3. enum arg_type type;
  4. const char *parser_name;
  5. PARSE_FUNC parser_func;
  6. PRED_FUNC pred_func;
  7. };
  1. static struct parser_table const parse_table[] =
  2. {
  3. PARSE_PUNCTUATION("!", negate), /* POSIX */
  4. PARSE_PUNCTUATION("not", negate), /* GNU */
  5. PARSE_PUNCTUATION("(", openparen), /* POSIX */
  6. PARSE_PUNCTUATION(")", closeparen), /* POSIX */
  7. PARSE_PUNCTUATION(",", comma), /* GNU */
  8. PARSE_PUNCTUATION("a", and), /* POSIX */
  9. PARSE_TEST ("amin", amin), /* GNU */
  10. PARSE_PUNCTUATION("and", and), /* GNU */
  11. PARSE_TEST ("anewer", anewer), /* GNU */
  12. {ARG_TEST, "atime", parse_time, pred_atime}, /* POSIX */
  13. PARSE_TEST ("cmin", cmin), /* GNU */
  14. PARSE_TEST ("cnewer", cnewer), /* GNU */
  15. {ARG_TEST, "ctime", parse_time, pred_ctime}, /* POSIX */
  16. PARSE_TEST ("context", context), /* GNU */
  17. PARSE_POSOPT ("daystart", daystart), /* GNU */
  18. PARSE_ACTION ("delete", delete), /* GNU, Mac OS, FreeBSD */
  19. PARSE_OPTION ("d", d), /* Mac OS X, FreeBSD, NetBSD, OpenBSD, but deprecated in favour of -depth */
  20. PARSE_OPTION ("depth", depth), /* POSIX */
  21. PARSE_TEST ("empty", empty), /* GNU */
  22. {ARG_ACTION, "exec", parse_exec, pred_exec}, /* POSIX */
  23. {ARG_TEST, "executable", parse_accesscheck, pred_executable}, /* GNU, 4.3.0+ */
  24. PARSE_ACTION ("execdir", execdir), /* *BSD, GNU */
  25. PARSE_ACTION ("fls", fls), /* GNU */
  26. PARSE_POSOPT ("follow", follow), /* GNU, Unix */
  27. PARSE_ACTION ("fprint", fprint), /* GNU */
  28. PARSE_ACTION ("fprint0", fprint0), /* GNU */
  29. {ARG_ACTION, "fprintf", parse_fprintf, pred_fprintf}, /* GNU */
  30. PARSE_TEST ("fstype", fstype), /* GNU, Unix */
  31. PARSE_TEST ("gid", gid), /* GNU */
  32. PARSE_TEST ("group", group), /* POSIX */
  33. PARSE_OPTION ("ignore_readdir_race", ignore_race), /* GNU */
  34. PARSE_TEST ("ilname", ilname), /* GNU */
  35. PARSE_TEST ("iname", iname), /* GNU */
  36. PARSE_TEST ("inum", inum), /* GNU, Unix */
  37. PARSE_TEST ("ipath", ipath), /* GNU, deprecated in favour of iwholename */
  38. PARSE_TEST_NP ("iregex", iregex), /* GNU */
  39. PARSE_TEST_NP ("iwholename", iwholename), /* GNU */
  40. PARSE_TEST ("links", links), /* POSIX */
  41. PARSE_TEST ("lname", lname), /* GNU */
  42. PARSE_ACTION ("ls", ls), /* GNU, Unix */
  43. PARSE_OPTION ("maxdepth", maxdepth), /* GNU */
  44. PARSE_OPTION ("mindepth", mindepth), /* GNU */
  45. PARSE_TEST ("mmin", mmin), /* GNU */
  46. PARSE_OPTION ("mount", xdev), /* Unix */
  47. {ARG_TEST, "mtime", parse_time, pred_mtime}, /* POSIX */
  48. PARSE_TEST ("name", name),
  49. #ifdef UNIMPLEMENTED_UNIX
  50. PARSE(ARG_UNIMPLEMENTED, "ncpio", ncpio), /* Unix */
  51. #endif
  52. PARSE_TEST ("newer", newer), /* POSIX */
  53. {ARG_TEST, "atime", parse_time, pred_atime}, /* POSIX */
  54. PARSE_OPTION ("noleaf", noleaf), /* GNU */
  55. PARSE_TEST ("nogroup", nogroup), /* POSIX */
  56. PARSE_TEST ("nouser", nouser), /* POSIX */
  57. PARSE_OPTION ("noignore_readdir_race", noignore_race), /* GNU */
  58. PARSE_POSOPT ("nowarn", nowarn), /* GNU */
  59. PARSE_POSOPT ("warn", warn), /* GNU */
  60. PARSE_PUNCTUATION("o", or), /* POSIX */
  61. PARSE_PUNCTUATION("or", or), /* GNU */
  62. PARSE_ACTION ("ok", ok), /* POSIX */
  63. PARSE_ACTION ("okdir", okdir), /* GNU (-execdir is BSD) */
  64. PARSE_TEST ("path", path), /* POSIX */
  65. PARSE_TEST ("perm", perm), /* POSIX */
  66. PARSE_ACTION ("print", print), /* POSIX */
  67. PARSE_ACTION ("print0", print0), /* GNU */
  68. {ARG_ACTION, "printf", parse_printf, NULL}, /* GNU */
  69. PARSE_ACTION ("prune", prune), /* POSIX */
  70. PARSE_ACTION ("quit", quit), /* GNU */
  71. {ARG_TEST, "readable", parse_accesscheck, pred_readable}, /* GNU, 4.3.0+ */
  72. PARSE_TEST ("regex", regex), /* GNU */
  73. PARSE_POSOPT ("regextype", regextype), /* GNU */
  74. PARSE_TEST ("samefile", samefile), /* GNU */
  75. #if 0
  76. PARSE_OPTION ("show-control-chars", show_control_chars), /* GNU, 4.3.0+ */
  77. #endif
  78. PARSE_TEST ("size", size), /* POSIX */
  79. PARSE_TEST ("type", type), /* POSIX */
  80. PARSE_TEST ("uid", uid), /* GNU */
  81. PARSE_TEST ("used", used), /* GNU */
  82. PARSE_TEST ("user", user), /* POSIX */
  83. PARSE_TEST_NP ("wholename", wholename), /* GNU, replaced -path, but now -path is standardized since POSIX 2008 */
  84. {ARG_TEST, "writable", parse_accesscheck, pred_writable}, /* GNU, 4.3.0+ */
  85. PARSE_OPTION ("xdev", xdev), /* POSIX */
  86. PARSE_OPTION ("xautofs", xautofs),
  87. PARSE_TEST ("xtype", xtype), /* GNU */
  88. #ifdef UNIMPLEMENTED_UNIX
  89. /* It's pretty ugly for find to know about archive formats.
  90. Plus what it could do with cpio archives is very limited.
  91. Better to leave it out. */
  92. PARSE(ARG_UNIMPLEMENTED, "cpio", cpio), /* Unix */
  93. #endif
  94. /* gnulib's stdbool.h might have made true and false into macros,
  95. * so we can't leave named 'true' and 'false' tokens, so we have
  96. * to expeant the relevant entries longhand.
  97. */
  98. {ARG_TEST, "false", parse_false, pred_false}, /* GNU */
  99. {ARG_TEST, "true", parse_true, pred_true }, /* GNU */
  100. /* Internal pseudo-option, therefore 3 minus: ---noop. */
  101. {ARG_NOOP, "--noop", NULL, pred_true }, /* GNU, internal use only */
  102. /* Various other cases that don't fit neatly into our macro scheme. */
  103. {ARG_TEST, "help", parse_help, NULL}, /* GNU */
  104. {ARG_TEST, "-help", parse_help, NULL}, /* GNU */
  105. {ARG_TEST, "version", parse_version, NULL}, /* GNU */
  106. {ARG_TEST, "-version", parse_version, NULL}, /* GNU */
  107. {0, 0, 0, 0}
  108. };

xargs中的数据结构

  1. struct buildcmd_state
  2. {
  3. /* Number of valid elements in `cmd_argv', including terminating NULL. */
  4. size_t cmd_argc; /* 0 */
  5. /* The list of args being built. */
  6. char **cmd_argv; /* NULL */
  7. /* Number of elements allocated for `cmd_argv'. */
  8. size_t cmd_argv_alloc;
  9. /* Storage for elements of `cmd_argv'. */
  10. char *argbuf;
  11. /* Number of chars being used in `cmd_argv'. */
  12. size_t cmd_argv_chars;
  13. /* Number of chars being used in `cmd_argv' for the initial args.. */
  14. size_t cmd_initial_argv_chars;
  15. /* User context information. */
  16. void *usercontext;
  17. /* to-do flag. */
  18. int todo;
  19. /* Directory in which to perform the exec. */
  20. int dir_fd;
  21. /* Summary of what we think the argv limits are. */
  22. size_t largest_successful_arg_count;
  23. size_t smallest_failed_arg_count;
  24. };
  1. struct option
  2. {
  3. const char *name;
  4. /* has_arg can't be an enum because some compilers complain about
  5. type mismatches in all the code that assumes it is an int. */
  6. int has_arg;
  7. int *flag;
  8. int val;
  9. };
  10. static struct option const longopts[] =
  11. {
  12. {"null", no_argument, NULL, '0'},
  13. {"arg-file", required_argument, NULL, 'a'},
  14. {"delimiter", required_argument, NULL, 'd'},
  15. {"eof", optional_argument, NULL, 'e'},
  16. {"replace", optional_argument, NULL, 'I'},
  17. {"max-lines", optional_argument, NULL, 'l'},
  18. {"max-args", required_argument, NULL, 'n'},
  19. {"open-tty", no_argument, NULL, 'o'},
  20. {"interactive", no_argument, NULL, 'p'},
  21. {"no-run-if-empty", no_argument, NULL, 'r'},
  22. {"max-chars", required_argument, NULL, 's'},
  23. {"verbose", no_argument, NULL, 't'},
  24. {"show-limits", no_argument, NULL, 'S'},
  25. {"exit", no_argument, NULL, 'x'},
  26. {"max-procs", required_argument, NULL, 'P'},
  27. {"process-slot-var", required_argument, NULL, PROCESS_SLOT_VAR},
  28. {"version", no_argument, NULL, 'v'},
  29. {"help", no_argument, NULL, 'h'},
  30. {NULL, no_argument, NULL, 0}
  31. };