tools/rmcr.c: Add a tools to remove carriage returns and dangline whitespace at the end of lines.
This commit is contained in:
parent
a1304f494a
commit
713b3e3760
@ -79,14 +79,14 @@ all: b16$(HOSTEXEEXT) bdf-converter$(HOSTEXEEXT) cmpconfig$(HOSTEXEEXT) \
|
|||||||
mksymtab$(HOSTEXEEXT) mksyscall$(HOSTEXEEXT) mkversion$(HOSTEXEEXT) \
|
mksymtab$(HOSTEXEEXT) mksyscall$(HOSTEXEEXT) mkversion$(HOSTEXEEXT) \
|
||||||
cnvwindeps$(HOSTEXEEXT) nxstyle$(HOSTEXEEXT) initialconfig$(HOSTEXEEXT) \
|
cnvwindeps$(HOSTEXEEXT) nxstyle$(HOSTEXEEXT) initialconfig$(HOSTEXEEXT) \
|
||||||
logparser$(HOSTEXEEXT) gencromfs$(HOSTEXEEXT) convert-comments$(HOSTEXEEXT) \
|
logparser$(HOSTEXEEXT) gencromfs$(HOSTEXEEXT) convert-comments$(HOSTEXEEXT) \
|
||||||
lowhex$(HOSTEXEEXT) detab$(HOSTEXEEXT)
|
lowhex$(HOSTEXEEXT) detab$(HOSTEXEEXT) rmcr$(HOSTEXEEXT)
|
||||||
default: mkconfig$(HOSTEXEEXT) mksyscall$(HOSTEXEEXT) mkdeps$(HOSTEXEEXT) \
|
default: mkconfig$(HOSTEXEEXT) mksyscall$(HOSTEXEEXT) mkdeps$(HOSTEXEEXT) \
|
||||||
cnvwindeps$(HOSTEXEEXT)
|
cnvwindeps$(HOSTEXEEXT)
|
||||||
|
|
||||||
ifdef HOSTEXEEXT
|
ifdef HOSTEXEEXT
|
||||||
.PHONY: b16 bdf-converter cmpconfig clean configure kconfig2html mkconfig \
|
.PHONY: b16 bdf-converter cmpconfig clean configure kconfig2html mkconfig \
|
||||||
mkdeps mksymtab mksyscall mkversion cnvwindeps nxstyle initialconfig \
|
mkdeps mksymtab mksyscall mkversion cnvwindeps nxstyle initialconfig \
|
||||||
logparser gencromfs convert-comments lowhex detab
|
logparser gencromfs convert-comments lowhex detab rmcr
|
||||||
else
|
else
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
endif
|
endif
|
||||||
@ -237,6 +237,15 @@ ifdef HOSTEXEEXT
|
|||||||
detab: detab$(HOSTEXEEXT)
|
detab: detab$(HOSTEXEEXT)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# rmcr - Convert tabs to spaces
|
||||||
|
|
||||||
|
rmcr$(HOSTEXEEXT): rmcr.c
|
||||||
|
$(Q) $(HOSTCC) $(HOSTCFLAGS) -o rmcr$(HOSTEXEEXT) rmcr.c
|
||||||
|
|
||||||
|
ifdef HOSTEXEEXT
|
||||||
|
rmcr: rmcr$(HOSTEXEEXT)
|
||||||
|
endif
|
||||||
|
|
||||||
# cnvwindeps - Convert dependences generated by a Windows native toolchain
|
# cnvwindeps - Convert dependences generated by a Windows native toolchain
|
||||||
# for use in a Cygwin/POSIX build environment
|
# for use in a Cygwin/POSIX build environment
|
||||||
|
|
||||||
|
268
tools/README.txt
268
tools/README.txt
@ -7,21 +7,13 @@ The tools/ directory contains miscellaneous scripts and host C programs
|
|||||||
that are necessary parts of the NuttX build system. These files
|
that are necessary parts of the NuttX build system. These files
|
||||||
include:
|
include:
|
||||||
|
|
||||||
README.txt
|
cmpconfig.c
|
||||||
----------
|
-----------
|
||||||
|
|
||||||
This file!
|
This C file can be used to build a utility for comparing two NuttX
|
||||||
|
configuration files.
|
||||||
|
|
||||||
Makefile.*
|
Config.mk
|
||||||
----------
|
|
||||||
|
|
||||||
Makefile.unix is the Makefile used when building NuttX in Unix-like
|
|
||||||
systems. It is selected from the top-level Makefile.
|
|
||||||
|
|
||||||
Makefile.win is the Makefile used when building natively under
|
|
||||||
Windows. It is selected from the top-level Makefile.
|
|
||||||
|
|
||||||
*.mk
|
|
||||||
---------
|
---------
|
||||||
|
|
||||||
Config.mk contains common definitions used by many configuration files.
|
Config.mk contains common definitions used by many configuration files.
|
||||||
@ -34,11 +26,6 @@ Makefile.*
|
|||||||
Subsequent logic within the configuration-specific Make.defs file may then
|
Subsequent logic within the configuration-specific Make.defs file may then
|
||||||
override these default definitions as necessary.
|
override these default definitions as necessary.
|
||||||
|
|
||||||
Libraries.mk has the build rules for all NuttX libraries.
|
|
||||||
|
|
||||||
FlatLibs.mk, ProtectedLibs.mk, and KernelLib.mk: These control the
|
|
||||||
selection of libraries to be built, depending on the selected build mode.
|
|
||||||
|
|
||||||
configure.sh
|
configure.sh
|
||||||
configure.bat
|
configure.bat
|
||||||
configure.c, cfgparser.c, and cfgparser.h
|
configure.c, cfgparser.c, and cfgparser.h
|
||||||
@ -107,34 +94,6 @@ gencromfs.c
|
|||||||
be compiled in order to generate the binary CROMFS file system
|
be compiled in order to generate the binary CROMFS file system
|
||||||
image.
|
image.
|
||||||
|
|
||||||
lowhex.c
|
|
||||||
|
|
||||||
Convert hexadecimal representation in a file from upper- to lower-case.
|
|
||||||
Usage:
|
|
||||||
|
|
||||||
lowhex <source-file> <out-file>
|
|
||||||
|
|
||||||
mkconfig.c, cfgdefine.c, and cfgdefine.h
|
|
||||||
----------------------------------------
|
|
||||||
|
|
||||||
These are Cs file that are used to build mkconfig program. The mkconfig
|
|
||||||
program is used during the initial NuttX build.
|
|
||||||
|
|
||||||
When you configure NuttX, you will copy a configuration file called .config
|
|
||||||
in the top level NuttX directory (See configs/README.txt or
|
|
||||||
Documentation/NuttxPortingGuide.html). The first time you make NuttX,
|
|
||||||
the top-level makefile will build the mkconfig executable from mkconfig.c
|
|
||||||
(using Makefile.host). The top-level Makefile will then execute the
|
|
||||||
mkconfig program to convert the .config file in the top level directory
|
|
||||||
into include/nuttx/config.h. config.h is a another version of the
|
|
||||||
NuttX configuration that can be included by C files.
|
|
||||||
|
|
||||||
cmpconfig.c
|
|
||||||
-----------
|
|
||||||
|
|
||||||
This C file can be used to build a utility for comparing two NuttX
|
|
||||||
configuration files.
|
|
||||||
|
|
||||||
initialconfig.c
|
initialconfig.c
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
@ -176,6 +135,46 @@ kconfig2html.c
|
|||||||
|
|
||||||
make dirlinks
|
make dirlinks
|
||||||
|
|
||||||
|
Libraries.mk, FlatLibs.mk, ProtectedLibs.mk, and KernelLib.mk
|
||||||
|
-------------------------------------------------------------
|
||||||
|
|
||||||
|
Libraries.mk has the build rules for all NuttX libraries.
|
||||||
|
|
||||||
|
FlatLibs.mk, ProtectedLibs.mk, and KernelLib.mk: These control the
|
||||||
|
selection of libraries to be built, depending on the selected build mode.
|
||||||
|
|
||||||
|
lowhex.c
|
||||||
|
--------
|
||||||
|
|
||||||
|
Convert hexadecimal representation in a file from upper- to lower-case.
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
lowhex <source-file> <out-file>
|
||||||
|
|
||||||
|
Makefile.[unix|win]
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
Makefile.unix is the Makefile used when building NuttX in Unix-like
|
||||||
|
systems. It is selected from the top-level Makefile.
|
||||||
|
|
||||||
|
Makefile.win is the Makefile used when building natively under
|
||||||
|
Windows. It is selected from the top-level Makefile.
|
||||||
|
|
||||||
|
mkconfig.c, cfgdefine.c, and cfgdefine.h
|
||||||
|
----------------------------------------
|
||||||
|
|
||||||
|
These are Cs file that are used to build mkconfig program. The mkconfig
|
||||||
|
program is used during the initial NuttX build.
|
||||||
|
|
||||||
|
When you configure NuttX, you will copy a configuration file called .config
|
||||||
|
in the top level NuttX directory (See configs/README.txt or
|
||||||
|
Documentation/NuttxPortingGuide.html). The first time you make NuttX,
|
||||||
|
the top-level makefile will build the mkconfig executable from mkconfig.c
|
||||||
|
(using Makefile.host). The top-level Makefile will then execute the
|
||||||
|
mkconfig program to convert the .config file in the top level directory
|
||||||
|
into include/nuttx/config.h. config.h is a another version of the
|
||||||
|
NuttX configuration that can be included by C files.
|
||||||
|
|
||||||
mkconfigvars.sh
|
mkconfigvars.sh
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
@ -476,11 +475,8 @@ mkromfsimg.sh
|
|||||||
TIP: Edit the resulting header file and mark the generated data values
|
TIP: Edit the resulting header file and mark the generated data values
|
||||||
as 'const' so that they will be stored in FLASH.
|
as 'const' so that they will be stored in FLASH.
|
||||||
|
|
||||||
mkdeps.c
|
mkdeps.c, cnvwindeps.c, mkwindeps.sh, and mknulldeps.sh
|
||||||
cnvwindeps.c
|
-------------------------------------------------------
|
||||||
mkwindeps.sh
|
|
||||||
mknulldeps.sh
|
|
||||||
-------------
|
|
||||||
|
|
||||||
NuttX uses the GCC compilers capabilities to create Makefile dependencies.
|
NuttX uses the GCC compilers capabilities to create Makefile dependencies.
|
||||||
The program mkdeps is used to run GCC in order to create the dependencies.
|
The program mkdeps is used to run GCC in order to create the dependencies.
|
||||||
@ -512,9 +508,8 @@ mknulldeps.sh
|
|||||||
eventually be solvable but for now continue to use mkwindeps.sh in
|
eventually be solvable but for now continue to use mkwindeps.sh in
|
||||||
that mixed environment.
|
that mixed environment.
|
||||||
|
|
||||||
define.sh
|
define.sh and define.bat
|
||||||
define.bat
|
------------------------
|
||||||
---------
|
|
||||||
|
|
||||||
Different compilers have different conventions for specifying pre-
|
Different compilers have different conventions for specifying pre-
|
||||||
processor definitions on the compiler command line. This bash
|
processor definitions on the compiler command line. This bash
|
||||||
@ -622,9 +617,8 @@ ide_exporter.py
|
|||||||
Obsoleted/stm32f429i_disco/ltcd/template and at
|
Obsoleted/stm32f429i_disco/ltcd/template and at
|
||||||
Obsoleted/stm3220g-eval/template.
|
Obsoleted/stm3220g-eval/template.
|
||||||
|
|
||||||
incdir.sh
|
incdir.sh and incdir.bat
|
||||||
incdir.bat
|
------------------------
|
||||||
---------
|
|
||||||
|
|
||||||
Different compilers have different conventions for specifying lists
|
Different compilers have different conventions for specifying lists
|
||||||
of include file paths on the compiler command line. This incdir.sh
|
of include file paths on the compiler command line. This incdir.sh
|
||||||
@ -635,13 +629,38 @@ incdir.bat
|
|||||||
build. However, there is currently only one compiler supported in
|
build. However, there is currently only one compiler supported in
|
||||||
that context: MinGW-GCC.
|
that context: MinGW-GCC.
|
||||||
|
|
||||||
link.sh
|
kconfig.bat
|
||||||
link.bat
|
-----------
|
||||||
copydir.sh
|
|
||||||
copydir.bat
|
Recent versions of NuttX support building NuttX from a native Windows
|
||||||
unlink.sh
|
CMD.exe shell. But kconfig-frontends is a Linux tool and is not yet
|
||||||
unlink.bat
|
available in the pure CMD.exe environment. At this point, there are
|
||||||
----------
|
only a few options for the Windows user (see the top-level README.txt
|
||||||
|
file).
|
||||||
|
|
||||||
|
You can, with some effort, run the Cygwin kconfig-mconf tool directly
|
||||||
|
in the CMD.exe shell. In this case, you do not have to modify the
|
||||||
|
.config file, but there are other complexities: You need to
|
||||||
|
temporarily set the Cgywin directories in the PATH variable and
|
||||||
|
then run kconfig-mconf outside of the Make system.
|
||||||
|
|
||||||
|
kconfig.bat is a Windows batch file at tools/kconfig.bat that automates
|
||||||
|
these steps. It is used from the top-level NuttX directory like:
|
||||||
|
|
||||||
|
tools/kconfig menuconfig
|
||||||
|
|
||||||
|
NOTE: There is an currently an issue with accessing DOS environment
|
||||||
|
variables from the Cygwin kconfig-mconf running in the CMD.exe shell.
|
||||||
|
The following change to the top-level Kconfig file seems to work around
|
||||||
|
these problems:
|
||||||
|
|
||||||
|
config APPSDIR
|
||||||
|
string
|
||||||
|
- option env="APPSDIR"
|
||||||
|
+ default "../apps"
|
||||||
|
|
||||||
|
link.sh, link.bat, copydir.sh, copydir.bat, unlink.sh, and unlink.bat
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
|
||||||
Different file system have different capabilities for symbolic links.
|
Different file system have different capabilities for symbolic links.
|
||||||
Some windows file systems have no native support for symbolic links.
|
Some windows file systems have no native support for symbolic links.
|
||||||
@ -680,36 +699,6 @@ unlink.bat
|
|||||||
NTFS mklink.exe command instead of copying files. That logic, however,
|
NTFS mklink.exe command instead of copying files. That logic, however,
|
||||||
has not been verified as of this writing.
|
has not been verified as of this writing.
|
||||||
|
|
||||||
kconfig.bat
|
|
||||||
-----------
|
|
||||||
|
|
||||||
Recent versions of NuttX support building NuttX from a native Windows
|
|
||||||
CMD.exe shell. But kconfig-frontends is a Linux tool and is not yet
|
|
||||||
available in the pure CMD.exe environment. At this point, there are
|
|
||||||
only a few options for the Windows user (see the top-level README.txt
|
|
||||||
file).
|
|
||||||
|
|
||||||
You can, with some effort, run the Cygwin kconfig-mconf tool directly
|
|
||||||
in the CMD.exe shell. In this case, you do not have to modify the
|
|
||||||
.config file, but there are other complexities: You need to
|
|
||||||
temporarily set the Cgywin directories in the PATH variable and
|
|
||||||
then run kconfig-mconf outside of the Make system.
|
|
||||||
|
|
||||||
kconfig.bat is a Windows batch file at tools/kconfig.bat that automates
|
|
||||||
these steps. It is used from the top-level NuttX directory like:
|
|
||||||
|
|
||||||
tools/kconfig menuconfig
|
|
||||||
|
|
||||||
NOTE: There is an currently an issue with accessing DOS environment
|
|
||||||
variables from the Cygwin kconfig-mconf running in the CMD.exe shell.
|
|
||||||
The following change to the top-level Kconfig file seems to work around
|
|
||||||
these problems:
|
|
||||||
|
|
||||||
config APPSDIR
|
|
||||||
string
|
|
||||||
- option env="APPSDIR"
|
|
||||||
+ default "../apps"
|
|
||||||
|
|
||||||
logparser.c
|
logparser.c
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
@ -773,47 +762,10 @@ indent.sh
|
|||||||
|
|
||||||
See also nxstyle.c and uncrustify.cfg
|
See also nxstyle.c and uncrustify.cfg
|
||||||
|
|
||||||
sethost.sh
|
README.txt
|
||||||
----------
|
----------
|
||||||
|
|
||||||
Saved configurations may run on Linux, Cygwin (32- or 64-bit), or other
|
This file!
|
||||||
platforms. The platform characteristics can be changed use 'make
|
|
||||||
menuconfig'. Sometimes this can be confusing due to the differences
|
|
||||||
between the platforms. Enter sethost.sh
|
|
||||||
|
|
||||||
sethost.sh is a simple script that changes a configuration to your
|
|
||||||
host platform. This can greatly simplify life if you use many different
|
|
||||||
configurations. For example, if you are running on Linux and you
|
|
||||||
configure like this:
|
|
||||||
|
|
||||||
$ cd tools
|
|
||||||
$ ./configure.sh board/configuration
|
|
||||||
$ cd ..
|
|
||||||
|
|
||||||
The you can use the following command to both (1) make sure that the
|
|
||||||
configuration is up to date, AND (2) the configuration is set up
|
|
||||||
correctly for Linux:
|
|
||||||
|
|
||||||
$ tools/sethost.sh -l
|
|
||||||
|
|
||||||
Or, if you are on a Windows/Cygwin 64-bit platform:
|
|
||||||
|
|
||||||
$ tools/sethost.sh -w
|
|
||||||
|
|
||||||
Other options are available:
|
|
||||||
|
|
||||||
$ ./sethost.sh -h
|
|
||||||
|
|
||||||
USAGE: ./sethost.sh [-w|l|m] [-c|u|g|n] [-32|64] [<config>]
|
|
||||||
./sethost.sh -h
|
|
||||||
|
|
||||||
Where:
|
|
||||||
-w|l|m selects Windows (w), Linux (l), or macOS (m). Default: Linux
|
|
||||||
-c|u|g|n selects Windows environment option: Cygwin (c), Ubuntu under
|
|
||||||
Windows 10 (u), MSYS/MSYS2 (g) or Windows native (n). Default Cygwin
|
|
||||||
-32|64 selects 32- or 64-bit host. Default 64
|
|
||||||
-h will show this help test and terminate
|
|
||||||
<config> selects configuration file. Default: .config
|
|
||||||
|
|
||||||
refresh.sh
|
refresh.sh
|
||||||
----------
|
----------
|
||||||
@ -888,6 +840,56 @@ refresh.sh
|
|||||||
refresh.sh will prompt you first to avoid overwriting the
|
refresh.sh will prompt you first to avoid overwriting the
|
||||||
defconfig file with changes that you may not want.
|
defconfig file with changes that you may not want.
|
||||||
|
|
||||||
|
rmcr.c
|
||||||
|
------
|
||||||
|
|
||||||
|
Removes all white space from the end of lines. Whitespace here
|
||||||
|
includes space characters, TAB characters, horizontal and vertical
|
||||||
|
TABs, and carriage returns. Lines will be terminated with the
|
||||||
|
newline character only.
|
||||||
|
|
||||||
|
sethost.sh
|
||||||
|
----------
|
||||||
|
|
||||||
|
Saved configurations may run on Linux, Cygwin (32- or 64-bit), or other
|
||||||
|
platforms. The platform characteristics can be changed use 'make
|
||||||
|
menuconfig'. Sometimes this can be confusing due to the differences
|
||||||
|
between the platforms. Enter sethost.sh
|
||||||
|
|
||||||
|
sethost.sh is a simple script that changes a configuration to your
|
||||||
|
host platform. This can greatly simplify life if you use many different
|
||||||
|
configurations. For example, if you are running on Linux and you
|
||||||
|
configure like this:
|
||||||
|
|
||||||
|
$ cd tools
|
||||||
|
$ ./configure.sh board/configuration
|
||||||
|
$ cd ..
|
||||||
|
|
||||||
|
The you can use the following command to both (1) make sure that the
|
||||||
|
configuration is up to date, AND (2) the configuration is set up
|
||||||
|
correctly for Linux:
|
||||||
|
|
||||||
|
$ tools/sethost.sh -l
|
||||||
|
|
||||||
|
Or, if you are on a Windows/Cygwin 64-bit platform:
|
||||||
|
|
||||||
|
$ tools/sethost.sh -w
|
||||||
|
|
||||||
|
Other options are available:
|
||||||
|
|
||||||
|
$ ./sethost.sh -h
|
||||||
|
|
||||||
|
USAGE: ./sethost.sh [-w|l|m] [-c|u|g|n] [-32|64] [<config>]
|
||||||
|
./sethost.sh -h
|
||||||
|
|
||||||
|
Where:
|
||||||
|
-w|l|m selects Windows (w), Linux (l), or macOS (m). Default: Linux
|
||||||
|
-c|u|g|n selects Windows environment option: Cygwin (c), Ubuntu under
|
||||||
|
Windows 10 (u), MSYS/MSYS2 (g) or Windows native (n). Default Cygwin
|
||||||
|
-32|64 selects 32- or 64-bit host. Default 64
|
||||||
|
-h will show this help test and terminate
|
||||||
|
<config> selects configuration file. Default: .config
|
||||||
|
|
||||||
showsize.sh
|
showsize.sh
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
|
119
tools/rmcr.c
Normal file
119
tools/rmcr.c
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* tools/rmcr.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2019 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#define LINESIZE 1024
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static char g_line[LINESIZE];
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
FILE *instream;
|
||||||
|
FILE *outstream;
|
||||||
|
int len;
|
||||||
|
int ret = 1;
|
||||||
|
|
||||||
|
if (argc != 3)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: Two arguments expected\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Open the source file read-only */
|
||||||
|
|
||||||
|
instream = fopen(argv[1], "r");
|
||||||
|
if (instream == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: Failed to open %s for reading\n", argv[1]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Open the destination file write-only */
|
||||||
|
|
||||||
|
outstream = fopen(argv[2], "w");
|
||||||
|
if (outstream == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: Failed to open %s for reading\n", argv[2]);
|
||||||
|
goto errout_with_instream;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Process each line in the file */
|
||||||
|
|
||||||
|
while ((fgets(g_line, LINESIZE, instream) != NULL))
|
||||||
|
{
|
||||||
|
/* Remove all whitespace (including newline) from the end of the line */
|
||||||
|
|
||||||
|
len = strlen(g_line) - 1;
|
||||||
|
while (len >= 0 && isspace(g_line[len]))
|
||||||
|
{
|
||||||
|
len--;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Put the newline back. len is either -1, or points to the last, non-
|
||||||
|
* space character in the line.
|
||||||
|
*/
|
||||||
|
|
||||||
|
g_line[len + 1] = '\n';
|
||||||
|
g_line[len + 2] = '\0';
|
||||||
|
(void)fputs(g_line, outstream);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
fclose(outstream);
|
||||||
|
|
||||||
|
errout_with_instream:
|
||||||
|
fclose(instream);
|
||||||
|
return ret;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user