aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-09-22 08:56:03 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-09-22 08:56:03 +0000
commit750fc6d7bb6dc4c57399696e5e05c75c6cdd4aa5 (patch)
tree52e9ba9d455376a16a3086986e5ea60e6142f623
parent8514fc5681a640b305a79bb9d42fcec4d3b113d5 (diff)
downloadbusybox-w32-750fc6d7bb6dc4c57399696e5e05c75c6cdd4aa5.tar.gz
busybox-w32-750fc6d7bb6dc4c57399696e5e05c75c6cdd4aa5.tar.bz2
busybox-w32-750fc6d7bb6dc4c57399696e5e05c75c6cdd4aa5.zip
sed: getopt_ulflags'isation
-rw-r--r--editors/sed.c56
1 files changed, 22 insertions, 34 deletions
diff --git a/editors/sed.c b/editors/sed.c
index 98437585c..ee910d7ab 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -1086,7 +1086,9 @@ static void add_cmd_block(char *cmdstr)
1086 1086
1087int sed_main(int argc, char **argv) 1087int sed_main(int argc, char **argv)
1088{ 1088{
1089 int status = EXIT_SUCCESS, opt, getpat = 1; 1089 unsigned long opt;
1090 char *opt_e, *opt_f;
1091 int status = EXIT_SUCCESS, getpat = 1;
1090 1092
1091 bbg.sed_cmd_tail=&bbg.sed_cmd_head; 1093 bbg.sed_cmd_tail=&bbg.sed_cmd_head;
1092 1094
@@ -1100,41 +1102,27 @@ int sed_main(int argc, char **argv)
1100 } 1102 }
1101 1103
1102 /* do normal option parsing */ 1104 /* do normal option parsing */
1103 while ((opt = getopt(argc, argv, "irne:f:")) > 0) { 1105 opt = bb_getopt_ulflags(argc, argv, "irne:f:", &opt_e, &opt_f);
1104 switch (opt) { 1106 if (opt & 0x1) { // -i
1105 case 'i': 1107 bbg.in_place++;
1106 bbg.in_place++; 1108 atexit(cleanup_outname);
1107 atexit(cleanup_outname); 1109 }
1108 break; 1110 if (opt & 0x2) bbg.regex_type|=REG_EXTENDED; // -r
1109 case 'r': 1111 if (opt & 0x4) bbg.be_quiet++; // -n
1110 bbg.regex_type|=REG_EXTENDED; 1112 if (opt & 0x8) { // -e
1111 break; 1113 add_cmd_block(opt_e);
1112 case 'n': 1114 getpat=0;
1113 bbg.be_quiet++; 1115 }
1114 break; 1116 if (opt & 0x10) { // -f
1115 case 'e': 1117 FILE *cmdfile;
1116 add_cmd_block(optarg); 1118 char *line;
1119 cmdfile = xfopen(opt_f, "r");
1120 while ((line = bb_get_chomped_line_from_file(cmdfile)) != NULL) {
1121 add_cmd(line);
1117 getpat=0; 1122 getpat=0;
1118 break; 1123 free(line);
1119 case 'f':
1120 {
1121 FILE *cmdfile;
1122 char *line;
1123
1124 cmdfile = xfopen(optarg, "r");
1125
1126 while ((line = bb_get_chomped_line_from_file(cmdfile)) != NULL) {
1127 add_cmd(line);
1128 getpat=0;
1129 free(line);
1130 }
1131 xprint_and_close_file(cmdfile);
1132
1133 break;
1134 }
1135 default:
1136 bb_show_usage();
1137 } 1124 }
1125 xprint_and_close_file(cmdfile);
1138 } 1126 }
1139 1127
1140 /* if we didn't get a pattern from -e or -f, use argv[optind] */ 1128 /* if we didn't get a pattern from -e or -f, use argv[optind] */