coreutils4.5.1 uname.c代码分析
今天把以前读过的代码又快速的阅读一次,感觉真是书读百遍,其义自现。代码重读一次,又有了新的收获。
在uname.c中,其中没有复杂的逻辑,但其中处理打印选项时,很有意思。它是如何实现的呢?
/* Values that are bitwise or'd into `toprint'. */
/* Kernel name. */
#define PRINT_KERNEL_NAME 1
/* Node name on a communications network. */
#define PRINT_NODENAME 2
/* Kernel release. */
#define PRINT_KERNEL_RELEASE 4
/* Kernel version. */
#define PRINT_KERNEL_VERSION 8
/* Machine hardware name. */
#define PRINT_MACHINE 16
/* Processor type. */
#define PRINT_PROCESSOR 32
/* Hardware platform. */
#define PRINT_HARDWARE_PLATFORM 64
看到没,作者设置了许多位,然后根据选项,对这些位进行设置。在main
case 'a':
toprint = -1;
break;
case 's':
toprint |= PRINT_KERNEL_NAME;
break;
case 'n':
toprint |= PRINT_NODENAME;
break;
case 'r':
toprint |= PRINT_KERNEL_RELEASE;
break;
也就是说,作者用一个整数中的不同位,表示不同选项,打印时,根据设置的位,来打开位。
作者太有才了。看代码能学到不少东西呢。
这个gvim的字太小了,我要上网百度一下,如何对gvim设置字体大小。