|
commit 05ddf0f600904f4b5678687fd64a97838755457b
Author: Albrecht Schlosser <albrechts.fltk@online.de>
AuthorDate: Tue Apr 2 17:02:01 2024 +0200
Commit: Albrecht Schlosser <albrechts.fltk@online.de>
CommitDate: Tue Apr 2 17:02:01 2024 +0200
Move test/fromdos.c to misc/fromdos.c where it belongs
This is a test file for developers only. Use with caution.
misc/fromdos.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
test/fromdos.c | 65 ----------------------------------------------------------
2 files changed, 65 insertions(+), 65 deletions(-)
diff --git misc/fromdos.c misc/fromdos.c
new file mode 100644
index 0000000..1345021
--- /dev/null
+++ misc/fromdos.c
@@ -0,0 +1,65 @@
+/* fromdos.c : strip the stupid ^M characters without mistakes! */
+
+/* this can do in-place conversion or be used as a pipe... */
+
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <string.h>
+
+int main(int argc, char** argv) {
+ int f,c;
+ if (argc <= 1) {
+ if (isatty(0)) {
+ fprintf(stderr,"usage : %s <files>\nStrips ^M characters.\nCan do in-place conversion of many files or can be used in a pipe\n",argv[0]);
+ return 1;
+ }
+ for (;;) {
+ c = getchar();
+ while (c == '\r') {
+ c = getchar();
+ if (c != '\n') putchar(c);
+ }
+ if (c < 0) break;
+ putchar(c);
+ }
+ return 0;
+ }
+ for (f = 1; f < argc; f++) {
+ char* fname = argv[f];
+ char tempname[1024];
+ FILE* in = fopen(fname,"rb");
+ FILE* out;
+ int mod = 0;
+ if (!in) {
+ fprintf(stderr,"%s : %s\n", fname, strerror(errno));
+ return 1;
+ }
+ strcpy(tempname, fname);
+ strcat(tempname, ".temp");
+ out = fopen(tempname, "wb");
+ if (!out) {
+ fprintf(stderr,"%s : %s\n", fname, strerror(errno));
+ return 1;
+ }
+ for (;;) {
+ c = getc(in);
+ while (c == '\r') {
+ c = getc(in);
+ if (c == '\n') mod=1; else putc(c,out);
+ }
+ if (c < 0) break;
+ putc(c,out);
+ }
+ fclose(in);
+ fclose(out);
+ if (!mod) {
+ fprintf(stderr,"%s : no change\n", fname);
+ unlink(tempname);
+ } else if (rename(tempname, fname)) {
+ fprintf(stderr,"Can't mv %s %s : %s\n",tempname,fname,strerror(errno));
+ return 1;
+ }
+ }
+ return 0;
+}
diff --git test/fromdos.c test/fromdos.c
deleted file mode 100644
index 1345021..0000000
--- test/fromdos.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/* fromdos.c : strip the stupid ^M characters without mistakes! */
-
-/* this can do in-place conversion or be used as a pipe... */
-
-#include <stdio.h>
-#include <errno.h>
-#include <unistd.h>
-#include <string.h>
-
-int main(int argc, char** argv) {
- int f,c;
- if (argc <= 1) {
- if (isatty(0)) {
- fprintf(stderr,"usage : %s <files>\nStrips ^M characters.\nCan do in-place conversion of many files or can be used in a pipe\n",argv[0]);
- return 1;
- }
- for (;;) {
- c = getchar();
- while (c == '\r') {
- c = getchar();
- if (c != '\n') putchar(c);
- }
- if (c < 0) break;
- putchar(c);
- }
- return 0;
- }
- for (f = 1; f < argc; f++) {
- char* fname = argv[f];
- char tempname[1024];
- FILE* in = fopen(fname,"rb");
- FILE* out;
- int mod = 0;
- if (!in) {
- fprintf(stderr,"%s : %s\n", fname, strerror(errno));
- return 1;
- }
- strcpy(tempname, fname);
- strcat(tempname, ".temp");
- out = fopen(tempname, "wb");
- if (!out) {
- fprintf(stderr,"%s : %s\n", fname, strerror(errno));
- return 1;
- }
- for (;;) {
- c = getc(in);
- while (c == '\r') {
- c = getc(in);
- if (c == '\n') mod=1; else putc(c,out);
- }
- if (c < 0) break;
- putc(c,out);
- }
- fclose(in);
- fclose(out);
- if (!mod) {
- fprintf(stderr,"%s : no change\n", fname);
- unlink(tempname);
- } else if (rename(tempname, fname)) {
- fprintf(stderr,"Can't mv %s %s : %s\n",tempname,fname,strerror(errno));
- return 1;
- }
- }
- return 0;
-}
[ Direct Link to Message ] | |