diff options
| author | Eric Andersen <andersen@codepoet.org> | 2003-06-20 09:01:58 +0000 |
|---|---|---|
| committer | Eric Andersen <andersen@codepoet.org> | 2003-06-20 09:01:58 +0000 |
| commit | 8876fb2f59a0b515b3121d5894933eef88ce566a (patch) | |
| tree | f67de9320202043aca8ded20fb80d668c3b0c2d8 /miscutils | |
| parent | dfce3536ace2bcd38bdd3731841998ce344d786e (diff) | |
| download | busybox-w32-8876fb2f59a0b515b3121d5894933eef88ce566a.tar.gz busybox-w32-8876fb2f59a0b515b3121d5894933eef88ce566a.tar.bz2 busybox-w32-8876fb2f59a0b515b3121d5894933eef88ce566a.zip | |
last_patch89 from vodz:
Manuel,
I rewrite bb_getopt_ulflags() function for more universal usage.
My version support now:
- options with arguments (optional arg as GNU extension also)
- complementaly and/or incomplementaly and/or incongruously and/or list
options
- long_opt (all applets may have long option, add supporting is trivial)
This realisation full compatibile from your version.
Code size grow 480 bytes, but only coreutils/* over compensate this size
after using new function. Last patch reduced over 800 bytes and not full
applied to all. "mkdir" and "mv" applets have long_opt now for demonstrate
trivial addition support long_opt with usage new bb_getopt_ulflags().
Complementaly and/or incomplementaly and/or incongruously and/or list options
logic is not trivial, but new "cut" and "grep" applets using this logic
for examples with full demostrating. New "grep" applet reduced over 300
bytes.
Mark,
Also. I removed bug from "grep" applet.
$ echo a b | busybox grep -e a b
a b
a b
But right is printing one only.
--w
vodz
Diffstat (limited to 'miscutils')
| -rw-r--r-- | miscutils/crond.c | 62 |
1 files changed, 28 insertions, 34 deletions
diff --git a/miscutils/crond.c b/miscutils/crond.c index cbb4ffc58..9d9ecc290 100644 --- a/miscutils/crond.c +++ b/miscutils/crond.c | |||
| @@ -117,46 +117,40 @@ static CronFile *FileBase; | |||
| 117 | int | 117 | int |
| 118 | crond_main(int ac, char **av) | 118 | crond_main(int ac, char **av) |
| 119 | { | 119 | { |
| 120 | int i; | 120 | unsigned long opt; |
| 121 | char *lopt, *Lopt, *copt; | ||
| 122 | #ifdef FEATURE_DEBUG_OPT | ||
| 123 | char *dopt; | ||
| 124 | bb_opt_complementaly = "f-b:b-f:S-L:L-S:d-l"; | ||
| 125 | #else | ||
| 126 | bb_opt_complementaly = "f-b:b-f:S-L:L-S"; | ||
| 127 | #endif | ||
| 121 | 128 | ||
| 122 | opterr = 0; /* disable getopt 'errors' message.*/ | 129 | opterr = 0; /* disable getopt 'errors' message.*/ |
| 123 | 130 | opt = bb_getopt_ulflags(ac, av, "l:L:fbSc:" | |
| 124 | while ((i = getopt(ac,av, | ||
| 125 | #ifdef FEATURE_DEBUG_OPT | 131 | #ifdef FEATURE_DEBUG_OPT |
| 126 | "d:" | 132 | "d:" |
| 127 | #endif | 133 | #endif |
| 128 | "l:L:fbSc:")) != EOF){ | 134 | , &lopt, &Lopt, &copt |
| 129 | |||
| 130 | switch (i){ | ||
| 131 | case 'l': | ||
| 132 | LogLevel = atoi(optarg); | ||
| 133 | break; | ||
| 134 | #ifdef FEATURE_DEBUG_OPT | 135 | #ifdef FEATURE_DEBUG_OPT |
| 135 | case 'd': | 136 | , &dopt |
| 136 | DebugOpt = atoi(optarg); | ||
| 137 | LogLevel = 0; | ||
| 138 | break; | ||
| 139 | #endif | 137 | #endif |
| 140 | case 'f': | 138 | ); |
| 141 | ForegroundOpt = 1; | 139 | if(opt & 1) |
| 142 | break; | 140 | LogLevel = atoi(lopt); |
| 143 | case 'b': | 141 | LoggerOpt = opt & 2; |
| 144 | ForegroundOpt = 0; | 142 | if(LoggerOpt) |
| 145 | break; | 143 | if (*Lopt != 0) LogFile = Lopt; |
| 146 | case 'S': /* select logging to syslog */ | 144 | ForegroundOpt = opt & 4; |
| 147 | LoggerOpt = 0; | 145 | if(opt & 32) { |
| 148 | break; | 146 | if (*copt != 0) CDir = copt; |
| 149 | case 'L': /* select internal file logger */ | ||
| 150 | LoggerOpt = 1; | ||
| 151 | if (*optarg != 0) LogFile = optarg; | ||
| 152 | break; | ||
| 153 | case 'c': | ||
| 154 | if (*optarg != 0) CDir = optarg; | ||
| 155 | break; | ||
| 156 | default: /* parse error */ | ||
| 157 | bb_show_usage(); | ||
| 158 | } | 147 | } |
| 148 | #ifdef FEATURE_DEBUG_OPT | ||
| 149 | if(opt & 64) { | ||
| 150 | DebugOpt = atoi(dopt); | ||
| 151 | LogLevel = 0; | ||
| 159 | } | 152 | } |
| 153 | #endif | ||
| 160 | 154 | ||
| 161 | /* | 155 | /* |
| 162 | * change directory | 156 | * change directory |
| @@ -165,6 +159,9 @@ crond_main(int ac, char **av) | |||
| 165 | if (chdir(CDir) != 0) | 159 | if (chdir(CDir) != 0) |
| 166 | bb_perror_msg_and_die("chdir"); | 160 | bb_perror_msg_and_die("chdir"); |
| 167 | 161 | ||
| 162 | signal(SIGHUP,SIG_IGN); /* hmm.. but, if kill -HUP original | ||
| 163 | * version - his died. ;( | ||
| 164 | */ | ||
| 168 | /* | 165 | /* |
| 169 | * close stdin and stdout, stderr. | 166 | * close stdin and stdout, stderr. |
| 170 | * close unused descriptors - don't need. | 167 | * close unused descriptors - don't need. |
| @@ -177,9 +174,6 @@ crond_main(int ac, char **av) | |||
| 177 | } | 174 | } |
| 178 | 175 | ||
| 179 | (void)startlogger(); /* need if syslog mode selected */ | 176 | (void)startlogger(); /* need if syslog mode selected */ |
| 180 | signal(SIGHUP,SIG_IGN); /* hmm.. but, if kill -HUP original | ||
| 181 | * version - his died. ;( | ||
| 182 | */ | ||
| 183 | 177 | ||
| 184 | /* | 178 | /* |
| 185 | * main loop - synchronize to 1 second after the minute, minimum sleep | 179 | * main loop - synchronize to 1 second after the minute, minimum sleep |
