MCPcopy Create free account
hub / github.com/apache/nuttx / main

Function main

tools/rmcr.c:52–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50 ****************************************************************************/
51
52int main(int argc, char **argv)
53{
54 FILE *instream;
55 FILE *outstream;
56 int len;
57 int ret = 1;
58
59 if (argc != 3)
60 {
61 fprintf(stderr, "ERROR: Two arguments expected\n");
62 return 1;
63 }
64
65 /* Open the source file read-only */
66
67 instream = fopen(argv[1], "r");
68 if (instream == NULL)
69 {
70 fprintf(stderr, "ERROR: Failed to open %s for reading\n", argv[1]);
71 return 1;
72 }
73
74 /* Open the destination file write-only */
75
76 outstream = fopen(argv[2], "w");
77 if (outstream == NULL)
78 {
79 fprintf(stderr, "ERROR: Failed to open %s for reading\n", argv[2]);
80 goto errout_with_instream;
81 }
82
83 /* Process each line in the file */
84
85 while ((fgets(g_line, LINESIZE, instream) != NULL))
86 {
87 /* Remove all whitespace (including newline) from the end of the line */
88
89 len = strlen(g_line) - 1;
90 while (len >= 0 && isspace(g_line[len]))
91 {
92 len--;
93 }
94
95 /* Put the newline back. len is either -1, or points to the last, non-
96 * space character in the line.
97 */
98
99 g_line[len + 1] = '\n';
100 g_line[len + 2] = '\0';
101 fputs(g_line, outstream);
102 }
103
104 ret = 0;
105 fclose(outstream);
106
107errout_with_instream:
108 fclose(instream);
109 return ret;

Callers

nothing calls this directly

Calls 7

fprintfFunction · 0.85
fopenFunction · 0.85
fputsFunction · 0.85
fcloseFunction · 0.85
fgetsFunction · 0.50
strlenFunction · 0.50
isspaceFunction · 0.50

Tested by

no test coverage detected