⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dos2unix.c

📁 编码方式的解码示范uuencode and uudecode are in the public domain. dos2unix and unix2dos are hereby placed in
💻 C
字号:
/*
 *	This program strips the CRs from a file.  MSDOS uses CRLF for
 * \n while Unix uses only a LF.  In addition, ^Z characters are
 * stripped from the input file.  Unix does not use ^Z to mark the
 * EOF, while some MSDOS editors put a ^Z at the end of a file.
 * ^D characters are stripped from the file also.  Some PC products
 * which produce Postscript output put ^Ds in the file.  Some
 * Postscript printers will complain about these files and refuse
 * to print them.
 *
 * Kenneth J. Hendrickson
 */

#ifdef MSDOS
#include <fcntl.h>
#include <io.h>
#include <process.h>
#endif
#include <stdio.h>

#define CTRL_D	'\004'	/* EOT */
#define CTRL_M	'\015'	/* CR */
#define CTRL_Z	'\032'	/* SUB */

main(argc, argv)
int argc;
char **argv;

{
	FILE *in;
	char buffer[2];

	/* optional input arg */
	if (argc > 1) {
		if ((in = fopen(argv[1], "r")) == NULL) {
			(void) perror(argv[1]);
			exit(1);
		}
		argc--;
	} else
		in = stdin;

	if (argc != 1) {
		(void) fprintf(stderr, "Usage: dos2unix [infile]\n");
		exit(2);
	}

#ifdef MSDOS
	/* don't translate CRLF into LF when reading */
	(void) setmode(fileno(in), O_BINARY);

	/* don't translate LF into CRLF when writing */
	(void) setmode(fileno(stdout), O_BINARY);
#endif

	while (fread(buffer, sizeof (char), 1, in) == 1)
		if ( (buffer[0] != CTRL_D) && (buffer[0] != CTRL_M) && (buffer[0] != CTRL_Z) )
			(void) fputc(buffer[0], stdout);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -