Internal APIs 内部 API 

There’s some common functionality found in many places like help, parsing values, sorting, extensible arrays, etc. Not all places are unified and use old code implementing it manually. Below is list of usable APIs that should be spread and updated where it’s still not. A need for new API might emerge from cleanups, then it should appear here. The text below gives pointers and is not extensive, search the definitions and actual use in other code too.
在许多地方都可以找到一些常见功能,比如帮助、解析值、排序、可扩展数组等。并非所有地方都统一使用旧代码手动实现它。以下是可用 API 列表,应该在仍未更新的地方进行传播和更新。从清理中可能会出现对新 API 的需求,然后它应该出现在这里。下面的文本提供了指针,但并不详尽,请在其他代码中搜索定义和实际用法。

Option parsing 选项解析

Files: common/help.h, common/parse-utils.h 文件: common/help.h , common/parse-utils.h

Global options need to be processed and consumed by clean_args_no_options, argument count by check_argc_*, usage_* for handling usage.
全局选项需要由 clean_args_no_options 处理和消耗,参数计数由 check_argc_* 处理,usage_* 用于处理用法。

Options are parsed by getopt or getopt_long. Individual values from options are recognized by parse_*, basic types and custom types are supported.
选项由 getopt 或 getopt_long 解析。从选项中识别出各个值,通过 parse_*,支持基本类型和自定义类型。

Size unit pretty printing
尺寸单位漂亮打印 

Files: common/units.h 文件: common/units.h

Many commands print byte sizes with suffixes and the output format can be affected by command line options. In the help text the options are specified by either HELPINFO_UNITS_SHORT_LONG (both long and short options) or just HELPINFO_UNITS_LONG in case the short option letters would conflict.
许多命令会使用后缀打印字节大小,并且输出格式可能会受到命令行选项的影响。在帮助文本中,选项由 HELPINFO_UNITS_SHORT_LONG(长短选项都有)或者只有 HELPINFO_UNITS_LONG(只有长选项)来指定,以防止短选项字母冲突。

Automatic parsing of the options from argv is done by get_unit_mode_from_arg. Printing options is done by pretty_size_mode which takes the value and option mode. Default mode is human readable, the macros defining the modes are from UNITS_* namespace.
通过 get_unit_mode_from_arg 自动解析来自 argv 的选项。打印选项由 pretty_size_mode 完成,它接受值和选项模式。默认模式是人类可读的,宏定义的模式来自 UNITS_*命名空间。

TODO 待办事项

Undocumented or incomplete APIs:
未记录或不完整的 API:

  • common/array.h 常见/array.h

  • common/cpu-utils.h 通用/cpu-utils.h

  • common/device-utils.h 通用/device-utils.h

  • common/messages.h 通用/messages.h

  • common/open-utils.h 通用/open-utils.h

  • common/path-utils.h 通用/path-utils.h

  • common/sort-utils.h 通用/sort-utils.h

  • common/string-table.h 常见/字符串表.h

  • common/string-table.h 常见/字符串表.h

  • common/task-utils.h 常见/任务工具.h