remtab.c
来自「由8051/8096/8099/8048单片机汇编工具、 汇编语言、摩托罗拉m」· C语言 代码 · 共 64 行
C
64 行
/* remtab.c 12-4-91 Robert Mashlan, Public Domain
modified 28 mar 93 by Bob Stout
Filter for removing tabs. All tabs in the input will be replaced
with spaces. This filter takes one optional command line
parameter, which specifies the number spaces to replace for a tab.
If no size is specifies, it defaults to 8.
example usage:
remtab 6 < tabbed.c > untab.c
*/
#include <stdio.h>
#include <stdlib.h>
#define BUFSIZE 4096
int main(int argc, char **argv )
{
int tabsize = 8;
if (argc > 1) /* look for command line parameter */
{
tabsize = atoi(argv[1]);
if(0 == tabsize) tabsize = 9;
}
while (1)
{
char buf[BUFSIZE];
int nr, i, j, pos = 0;
nr = fread(buf, 1, sizeof(buf), stdin);
for (i = 0; i < nr; i++)
{
switch (buf[i])
{
case '\t': /* replace tabs with spaces */
for(j = pos % tabsize; j < tabsize; ++j)
{
putchar(' ');
++pos;
}
break;
case '\n': /* start a new line */
pos = -1; /* this will become 0 when... */
/* ...we fall through to... */
default:
putchar(buf[i]);/* send character through unchanged */
++pos;
}
}
if (nr < sizeof(buf))
break;
}
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?