diff options
| -rw-r--r-- | Config.h | 5 | ||||
| -rw-r--r-- | applets.h | 2 | ||||
| -rw-r--r-- | coreutils/dos2unix.c | 182 | ||||
| -rw-r--r-- | dos2unix.c | 182 | ||||
| -rw-r--r-- | include/applets.h | 2 | ||||
| -rw-r--r-- | init.c | 3 | ||||
| -rw-r--r-- | init/init.c | 3 |
7 files changed, 296 insertions, 83 deletions
| @@ -113,7 +113,6 @@ | |||
| 113 | #define BB_UMOUNT | 113 | #define BB_UMOUNT |
| 114 | #define BB_UNIQ | 114 | #define BB_UNIQ |
| 115 | #define BB_UNAME | 115 | #define BB_UNAME |
| 116 | //#define BB_UNIX2DOS | ||
| 117 | //#define BB_UPDATE | 116 | //#define BB_UPDATE |
| 118 | #define BB_UPTIME | 117 | #define BB_UPTIME |
| 119 | //#define BB_USLEEP | 118 | //#define BB_USLEEP |
| @@ -400,3 +399,7 @@ | |||
| 400 | #define BB_FEATURE_NEW_MODULE_INTERFACE | 399 | #define BB_FEATURE_NEW_MODULE_INTERFACE |
| 401 | #endif | 400 | #endif |
| 402 | #endif | 401 | #endif |
| 402 | // | ||
| 403 | #if defined BB_DOS2UNIX | ||
| 404 | #define BB_UNIX2DOS | ||
| 405 | #endif | ||
| @@ -374,7 +374,7 @@ | |||
| 374 | APPLET(uniq, uniq_main, _BB_DIR_USR_BIN) | 374 | APPLET(uniq, uniq_main, _BB_DIR_USR_BIN) |
| 375 | #endif | 375 | #endif |
| 376 | #ifdef BB_UNIX2DOS | 376 | #ifdef BB_UNIX2DOS |
| 377 | APPLET(unix2dos, unix2dos_main, _BB_DIR_USR_BIN) | 377 | APPLET(unix2dos, dos2unix_main, _BB_DIR_USR_BIN) |
| 378 | #endif | 378 | #endif |
| 379 | #ifdef BB_UPDATE | 379 | #ifdef BB_UPDATE |
| 380 | APPLET(update, update_main, _BB_DIR_SBIN) | 380 | APPLET(update, update_main, _BB_DIR_SBIN) |
diff --git a/coreutils/dos2unix.c b/coreutils/dos2unix.c index 222c8f6a4..7f1c5617d 100644 --- a/coreutils/dos2unix.c +++ b/coreutils/dos2unix.c | |||
| @@ -1,46 +1,152 @@ | |||
| 1 | /* | 1 | /* |
| 2 | Mini dos2unix implementation for busybox | 2 | * dos2unix for BusyBox |
| 3 | 3 | * | |
| 4 | Copyright 1994,1995 Patrick Volkerding, Moorhead, Minnesota USA | 4 | * dos2unix '\n' convertor 0.5.0 |
| 5 | All rights reserved. | 5 | * based on Unix2Dos 0.9.0 by Peter Hanecak (made 19.2.1997) |
| 6 | 6 | * Copyright 1997,.. by Peter Hanecak <hanecak@megaloman.sk>. | |
| 7 | Redistribution and use of this source code, with or without modification, is | 7 | * All rights reserved. |
| 8 | permitted provided that the following condition is met: | 8 | * |
| 9 | 9 | * dos2unix filters reading input from stdin and writing output to stdout. | |
| 10 | 1. Redistributions of this source code must retain the above copyright | 10 | * Without arguments it reverts the format (e.i. if source is in UNIX format, |
| 11 | notice, this condition, and the following disclaimer. | 11 | * output is in DOS format and vice versa). |
| 12 | 12 | * | |
| 13 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED | 13 | * This program is free software; you can redistribute it and/or |
| 14 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | 14 | * modify it under the terms of the GNU General Public License |
| 15 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | 15 | * as published by the Free Software Foundation; either version 2 |
| 16 | EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 16 | * of the License, or (at your option) any later version. |
| 17 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 17 | * |
| 18 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | 18 | * This program is distributed in the hope that it will be useful, |
| 19 | OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | 21 | * GNU General Public License for more details. |
| 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 | * |
| 23 | */ | 23 | * You should have received a copy of the GNU General Public License |
| 24 | * along with this program; if not, write to the Free Software | ||
| 25 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
| 26 | * | ||
| 27 | * See the COPYING file for license information. | ||
| 28 | */ | ||
| 24 | 29 | ||
| 25 | #include <stdio.h> | 30 | #include <stdio.h> |
| 26 | #include <stdlib.h> | 31 | #include <stdlib.h> |
| 32 | #include <string.h> | ||
| 33 | #include <errno.h> | ||
| 34 | #include <getopt.h> | ||
| 27 | #include "busybox.h" | 35 | #include "busybox.h" |
| 28 | 36 | ||
| 29 | int dos2unix_main( int argc, char **argv ) { | 37 | #define CT_AUTO 0 |
| 30 | int c; | 38 | #define CT_UNIX2DOS 1 |
| 31 | if (argc > 1) { | 39 | #define CT_DOS2UNIX 2 |
| 32 | c = *argv[1]; | 40 | |
| 33 | if (c == '-') { | 41 | int convert(char *fn, int ConvType); |
| 34 | show_usage(); | 42 | |
| 35 | } | 43 | int dos2unix_main(int argc, char *argv[]) { |
| 44 | int ConvType = CT_AUTO; | ||
| 45 | int o; | ||
| 46 | |||
| 47 | // process parameters | ||
| 48 | while ((o = getopt(argc, argv, "du")) != EOF) { | ||
| 49 | switch (o) { | ||
| 50 | case 'd': | ||
| 51 | ConvType = CT_UNIX2DOS; | ||
| 52 | break; | ||
| 53 | case 'u': | ||
| 54 | ConvType = CT_DOS2UNIX; | ||
| 55 | break; | ||
| 56 | default: | ||
| 57 | show_usage(); | ||
| 58 | } | ||
| 59 | } | ||
| 60 | |||
| 61 | if (optind < argc) { | ||
| 62 | while(optind < argc) | ||
| 63 | if ((o = convert(argv[optind++], ConvType)) < 0) | ||
| 64 | break; | ||
| 65 | } | ||
| 66 | else | ||
| 67 | o = convert(NULL, ConvType); | ||
| 68 | |||
| 69 | return o; | ||
| 70 | } | ||
| 71 | |||
| 72 | // if fn is NULL then input is stdin and output is stdout | ||
| 73 | int convert(char *fn, int ConvType) { | ||
| 74 | char c; | ||
| 75 | char *tempFn = NULL; | ||
| 76 | FILE *in = stdin, *out = stdout; | ||
| 77 | |||
| 78 | if (fn != NULL) { | ||
| 79 | if ((in = fopen(fn, "r")) == NULL) { | ||
| 80 | perror_msg(fn); | ||
| 81 | return -1; | ||
| 82 | } | ||
| 83 | tempFn = tmpnam(NULL); | ||
| 84 | if (tempFn == NULL || (out = fopen(tempFn, "w")) == NULL) { | ||
| 85 | perror_msg(NULL); | ||
| 86 | return -2; | ||
| 87 | } | ||
| 88 | } | ||
| 89 | |||
| 90 | while ((c = fgetc(in)) != EOF) { | ||
| 91 | if (c == '\r') { | ||
| 92 | if ((ConvType == CT_UNIX2DOS) && (fn != NULL)) { | ||
| 93 | // file is alredy in DOS format so it is not necessery to touch it | ||
| 94 | if (fclose(in) < 0 || fclose(out) < 0 || remove(tempFn) < 0) { | ||
| 95 | perror_msg(NULL); | ||
| 96 | return -2; | ||
| 97 | } | ||
| 98 | return 0; | ||
| 99 | } | ||
| 100 | if (!ConvType) | ||
| 101 | ConvType = CT_DOS2UNIX; | ||
| 102 | break; | ||
| 103 | } | ||
| 104 | if (c == '\n') { | ||
| 105 | if ((ConvType == CT_DOS2UNIX) && (fn != NULL)) { | ||
| 106 | // file is alredy in UNIX format so it is not necessery to touch it | ||
| 107 | if (fclose(in) < 0 || fclose(out) < 0 || remove(tempFn) < 0) { | ||
| 108 | perror_msg(NULL); | ||
| 109 | return -2; | ||
| 110 | } | ||
| 111 | return 0; | ||
| 112 | } | ||
| 113 | if (!ConvType) | ||
| 114 | ConvType = CT_UNIX2DOS; | ||
| 115 | if (ConvType == CT_UNIX2DOS) | ||
| 116 | fputc('\r', out); | ||
| 117 | fputc('\n', out); | ||
| 118 | break; | ||
| 119 | } | ||
| 120 | fputc(c, out); | ||
| 36 | } | 121 | } |
| 37 | c = getchar(); | 122 | if (c != EOF) |
| 38 | while (c != EOF) { | 123 | while ((c = fgetc(in)) != EOF) { |
| 39 | /* Eat any \r's... they shouldn't be here */ | 124 | if (c == '\r') |
| 40 | while (c == '\r') c = getchar(); | 125 | continue; |
| 41 | if (c == EOF) break; | 126 | if (c == '\n') { |
| 42 | putchar(c); | 127 | if (ConvType == CT_UNIX2DOS) |
| 43 | c = getchar(); | 128 | fputc('\r', out); |
| 44 | } | 129 | fputc('\n', out); |
| 45 | return EXIT_SUCCESS; | 130 | continue; |
| 131 | } | ||
| 132 | fputc(c, out); | ||
| 133 | } | ||
| 134 | |||
| 135 | if (fn != NULL) { | ||
| 136 | if (fclose(in) < 0 || fclose(out) < 0 || | ||
| 137 | (in = fopen(tempFn, "r")) == NULL || (out = fopen(fn, "w")) == NULL) { | ||
| 138 | perror_msg(NULL); | ||
| 139 | return -2; | ||
| 140 | } | ||
| 141 | |||
| 142 | while ((c = fgetc(in)) != EOF) | ||
| 143 | fputc(c, out); | ||
| 144 | |||
| 145 | if (fclose(in) < 0 || fclose(out) < 0 || remove(tempFn) < 0) { | ||
| 146 | perror_msg(NULL); | ||
| 147 | return -2; | ||
| 148 | } | ||
| 149 | } | ||
| 150 | |||
| 151 | return 0; | ||
| 46 | } | 152 | } |
diff --git a/dos2unix.c b/dos2unix.c index 222c8f6a4..7f1c5617d 100644 --- a/dos2unix.c +++ b/dos2unix.c | |||
| @@ -1,46 +1,152 @@ | |||
| 1 | /* | 1 | /* |
| 2 | Mini dos2unix implementation for busybox | 2 | * dos2unix for BusyBox |
| 3 | 3 | * | |
| 4 | Copyright 1994,1995 Patrick Volkerding, Moorhead, Minnesota USA | 4 | * dos2unix '\n' convertor 0.5.0 |
| 5 | All rights reserved. | 5 | * based on Unix2Dos 0.9.0 by Peter Hanecak (made 19.2.1997) |
| 6 | 6 | * Copyright 1997,.. by Peter Hanecak <hanecak@megaloman.sk>. | |
| 7 | Redistribution and use of this source code, with or without modification, is | 7 | * All rights reserved. |
| 8 | permitted provided that the following condition is met: | 8 | * |
| 9 | 9 | * dos2unix filters reading input from stdin and writing output to stdout. | |
| 10 | 1. Redistributions of this source code must retain the above copyright | 10 | * Without arguments it reverts the format (e.i. if source is in UNIX format, |
| 11 | notice, this condition, and the following disclaimer. | 11 | * output is in DOS format and vice versa). |
| 12 | 12 | * | |
| 13 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED | 13 | * This program is free software; you can redistribute it and/or |
| 14 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | 14 | * modify it under the terms of the GNU General Public License |
| 15 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | 15 | * as published by the Free Software Foundation; either version 2 |
| 16 | EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 16 | * of the License, or (at your option) any later version. |
| 17 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 17 | * |
| 18 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | 18 | * This program is distributed in the hope that it will be useful, |
| 19 | OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | 21 | * GNU General Public License for more details. |
| 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 | * |
| 23 | */ | 23 | * You should have received a copy of the GNU General Public License |
| 24 | * along with this program; if not, write to the Free Software | ||
| 25 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
| 26 | * | ||
| 27 | * See the COPYING file for license information. | ||
| 28 | */ | ||
| 24 | 29 | ||
| 25 | #include <stdio.h> | 30 | #include <stdio.h> |
| 26 | #include <stdlib.h> | 31 | #include <stdlib.h> |
| 32 | #include <string.h> | ||
| 33 | #include <errno.h> | ||
| 34 | #include <getopt.h> | ||
| 27 | #include "busybox.h" | 35 | #include "busybox.h" |
| 28 | 36 | ||
| 29 | int dos2unix_main( int argc, char **argv ) { | 37 | #define CT_AUTO 0 |
| 30 | int c; | 38 | #define CT_UNIX2DOS 1 |
| 31 | if (argc > 1) { | 39 | #define CT_DOS2UNIX 2 |
| 32 | c = *argv[1]; | 40 | |
| 33 | if (c == '-') { | 41 | int convert(char *fn, int ConvType); |
| 34 | show_usage(); | 42 | |
| 35 | } | 43 | int dos2unix_main(int argc, char *argv[]) { |
| 44 | int ConvType = CT_AUTO; | ||
| 45 | int o; | ||
| 46 | |||
| 47 | // process parameters | ||
| 48 | while ((o = getopt(argc, argv, "du")) != EOF) { | ||
| 49 | switch (o) { | ||
| 50 | case 'd': | ||
| 51 | ConvType = CT_UNIX2DOS; | ||
| 52 | break; | ||
| 53 | case 'u': | ||
| 54 | ConvType = CT_DOS2UNIX; | ||
| 55 | break; | ||
| 56 | default: | ||
| 57 | show_usage(); | ||
| 58 | } | ||
| 59 | } | ||
| 60 | |||
| 61 | if (optind < argc) { | ||
| 62 | while(optind < argc) | ||
| 63 | if ((o = convert(argv[optind++], ConvType)) < 0) | ||
| 64 | break; | ||
| 65 | } | ||
| 66 | else | ||
| 67 | o = convert(NULL, ConvType); | ||
| 68 | |||
| 69 | return o; | ||
| 70 | } | ||
| 71 | |||
| 72 | // if fn is NULL then input is stdin and output is stdout | ||
| 73 | int convert(char *fn, int ConvType) { | ||
| 74 | char c; | ||
| 75 | char *tempFn = NULL; | ||
| 76 | FILE *in = stdin, *out = stdout; | ||
| 77 | |||
| 78 | if (fn != NULL) { | ||
| 79 | if ((in = fopen(fn, "r")) == NULL) { | ||
| 80 | perror_msg(fn); | ||
| 81 | return -1; | ||
| 82 | } | ||
| 83 | tempFn = tmpnam(NULL); | ||
| 84 | if (tempFn == NULL || (out = fopen(tempFn, "w")) == NULL) { | ||
| 85 | perror_msg(NULL); | ||
| 86 | return -2; | ||
| 87 | } | ||
| 88 | } | ||
| 89 | |||
| 90 | while ((c = fgetc(in)) != EOF) { | ||
| 91 | if (c == '\r') { | ||
| 92 | if ((ConvType == CT_UNIX2DOS) && (fn != NULL)) { | ||
| 93 | // file is alredy in DOS format so it is not necessery to touch it | ||
| 94 | if (fclose(in) < 0 || fclose(out) < 0 || remove(tempFn) < 0) { | ||
| 95 | perror_msg(NULL); | ||
| 96 | return -2; | ||
| 97 | } | ||
| 98 | return 0; | ||
| 99 | } | ||
| 100 | if (!ConvType) | ||
| 101 | ConvType = CT_DOS2UNIX; | ||
| 102 | break; | ||
| 103 | } | ||
| 104 | if (c == '\n') { | ||
| 105 | if ((ConvType == CT_DOS2UNIX) && (fn != NULL)) { | ||
| 106 | // file is alredy in UNIX format so it is not necessery to touch it | ||
| 107 | if (fclose(in) < 0 || fclose(out) < 0 || remove(tempFn) < 0) { | ||
| 108 | perror_msg(NULL); | ||
| 109 | return -2; | ||
| 110 | } | ||
| 111 | return 0; | ||
| 112 | } | ||
| 113 | if (!ConvType) | ||
| 114 | ConvType = CT_UNIX2DOS; | ||
| 115 | if (ConvType == CT_UNIX2DOS) | ||
| 116 | fputc('\r', out); | ||
| 117 | fputc('\n', out); | ||
| 118 | break; | ||
| 119 | } | ||
| 120 | fputc(c, out); | ||
| 36 | } | 121 | } |
| 37 | c = getchar(); | 122 | if (c != EOF) |
| 38 | while (c != EOF) { | 123 | while ((c = fgetc(in)) != EOF) { |
| 39 | /* Eat any \r's... they shouldn't be here */ | 124 | if (c == '\r') |
| 40 | while (c == '\r') c = getchar(); | 125 | continue; |
| 41 | if (c == EOF) break; | 126 | if (c == '\n') { |
| 42 | putchar(c); | 127 | if (ConvType == CT_UNIX2DOS) |
| 43 | c = getchar(); | 128 | fputc('\r', out); |
| 44 | } | 129 | fputc('\n', out); |
| 45 | return EXIT_SUCCESS; | 130 | continue; |
| 131 | } | ||
| 132 | fputc(c, out); | ||
| 133 | } | ||
| 134 | |||
| 135 | if (fn != NULL) { | ||
| 136 | if (fclose(in) < 0 || fclose(out) < 0 || | ||
| 137 | (in = fopen(tempFn, "r")) == NULL || (out = fopen(fn, "w")) == NULL) { | ||
| 138 | perror_msg(NULL); | ||
| 139 | return -2; | ||
| 140 | } | ||
| 141 | |||
| 142 | while ((c = fgetc(in)) != EOF) | ||
| 143 | fputc(c, out); | ||
| 144 | |||
| 145 | if (fclose(in) < 0 || fclose(out) < 0 || remove(tempFn) < 0) { | ||
| 146 | perror_msg(NULL); | ||
| 147 | return -2; | ||
| 148 | } | ||
| 149 | } | ||
| 150 | |||
| 151 | return 0; | ||
| 46 | } | 152 | } |
diff --git a/include/applets.h b/include/applets.h index 446906cad..eaa818df7 100644 --- a/include/applets.h +++ b/include/applets.h | |||
| @@ -374,7 +374,7 @@ | |||
| 374 | APPLET(uniq, uniq_main, _BB_DIR_USR_BIN) | 374 | APPLET(uniq, uniq_main, _BB_DIR_USR_BIN) |
| 375 | #endif | 375 | #endif |
| 376 | #ifdef BB_UNIX2DOS | 376 | #ifdef BB_UNIX2DOS |
| 377 | APPLET(unix2dos, unix2dos_main, _BB_DIR_USR_BIN) | 377 | APPLET(unix2dos, dos2unix_main, _BB_DIR_USR_BIN) |
| 378 | #endif | 378 | #endif |
| 379 | #ifdef BB_UPDATE | 379 | #ifdef BB_UPDATE |
| 380 | APPLET(update, update_main, _BB_DIR_SBIN) | 380 | APPLET(update, update_main, _BB_DIR_SBIN) |
| @@ -93,9 +93,8 @@ static const int RB_AUTOBOOT = 0x01234567; | |||
| 93 | #endif | 93 | #endif |
| 94 | #endif | 94 | #endif |
| 95 | 95 | ||
| 96 | #ifndef _PATH_STDPATH | 96 | #undef _PATH_STDPATH |
| 97 | #define _PATH_STDPATH "/usr/bin:/bin:/usr/sbin:/sbin" | 97 | #define _PATH_STDPATH "/usr/bin:/bin:/usr/sbin:/sbin" |
| 98 | #endif | ||
| 99 | 98 | ||
| 100 | 99 | ||
| 101 | #if defined BB_FEATURE_INIT_COREDUMPS | 100 | #if defined BB_FEATURE_INIT_COREDUMPS |
diff --git a/init/init.c b/init/init.c index 2657ec628..4284600c4 100644 --- a/init/init.c +++ b/init/init.c | |||
| @@ -93,9 +93,8 @@ static const int RB_AUTOBOOT = 0x01234567; | |||
| 93 | #endif | 93 | #endif |
| 94 | #endif | 94 | #endif |
| 95 | 95 | ||
| 96 | #ifndef _PATH_STDPATH | 96 | #undef _PATH_STDPATH |
| 97 | #define _PATH_STDPATH "/usr/bin:/bin:/usr/sbin:/sbin" | 97 | #define _PATH_STDPATH "/usr/bin:/bin:/usr/sbin:/sbin" |
| 98 | #endif | ||
| 99 | 98 | ||
| 100 | 99 | ||
| 101 | #if defined BB_FEATURE_INIT_COREDUMPS | 100 | #if defined BB_FEATURE_INIT_COREDUMPS |
