Lines Matching full:command
28 -n No default output (use the p command to output matched lines)
39 Each COMMAND may be preceded by an address which limits the command to
43 [ADDRESS[,ADDRESS]][!]COMMAND
66 of input early (using the n and N command), but other than that command
69 Each COMMAND starts with a single character. The following commands take
72 ! Run this command when the test _didn't_ match.
74 { Start a new command block, continuing until a corresponding "}".
75 Command blocks may nest. If the block has an address, commands within
78 } End command block (this command cannot have an address)
83 D Delete one line of input and restart command SCRIPT (same as "d"
150 t [label] Test, jump to :label only if an "s" command found a match in
168 2-address anywhere an address is allowed, "T" command, multiline
201 int arg1, arg2, w; // offset of two arguments per command, plus s//w filename
244 static void *get_regex(void *command, int offset) in get_regex() argument
251 return TT.lastregex = offset+(char *)command; in get_regex()
264 struct sedcmd *command; in sed_line() local
286 // otherwise N as last command would restart script in sed_line()
287 command = TT.restart ? ((struct sedcmd *)TT.restart)-1 : (void *)TT.pattern; in sed_line()
290 while (command) { in sed_line()
291 char *str, c = command->c; in sed_line()
294 if (*command->lmatch || *command->rmatch) { in sed_line()
299 if (command->hit) { in sed_line()
300 if (!(lm = command->lmatch[1])) { in sed_line()
301 if (!command->rmatch[1]) command->hit = 0; in sed_line()
303 void *rm = get_regex(command, command->rmatch[1]); in sed_line()
308 } else if (lm > 0 && lm < TT.count) command->hit = 0; in sed_line()
309 else if (lm < -1 && TT.count == command->hit+(-lm-1)) command->hit = 0; in sed_line()
313 if (!(lm = *command->lmatch)) { in sed_line()
314 void *rm = get_regex(command, *command->rmatch); in sed_line()
317 command->hit = TT.count; in sed_line()
319 command->hit = TT.count; in sed_line()
321 if (!command->lmatch[1] && !command->rmatch[1]) miss = 1; in sed_line()
325 lm = !(command->not^!!command->hit); in sed_line()
328 if (miss || command->lmatch[1] == TT.count) command->hit = 0; in sed_line()
331 // Handle skipping curly bracket command group in sed_line()
336 command = command->next; in sed_line()
337 if (command->c == '{') curly++; in sed_line()
338 if (command->c == '}') curly--; in sed_line()
341 command = command->next; in sed_line()
348 command = command->next; in sed_line()
352 // Process command in sed_line()
356 if (command->arg1) a->str = command->arg1+(char *)command; in sed_line()
364 if (!command->arg1) break; in sed_line()
365 str = command->arg1+(char *)command; in sed_line()
366 for (command = (void *)TT.pattern; command; command = command->next) in sed_line()
367 if (command->c == ':' && !strcmp(command->arg1+(char *)command, str)) in sed_line()
369 if (!command) error_exit("no :%s", str); in sed_line()
372 str = command->arg1+(char *)command; in sed_line()
373 if (!command->hit) emit(str, strlen(str), 1); in sed_line()
395 command = (void *)TT.pattern; in sed_line()
417 str = command->arg1+(char *)command; in sed_line()
445 TT.restart = command->next+1; in sed_line()
452 TT.restart = command->next+1; in sed_line()
469 if (!toys.exitval && command->arg1) in sed_line()
470 toys.exitval = atoi(command->arg1+(char *)command); in sed_line()
477 char *rline = line, *new = command->arg2 + (char *)command, *l2 = 0; in sed_line()
479 regex_t *reg = get_regex(command, command->arg1); in sed_line()
497 off = command->sflags>>3; in sed_line()
560 if (!(command->sflags & 2)) break; in sed_line()
575 if (command->sflags & 4) emit(line, len, eol); in sed_line()
578 if (command->w) goto writenow; in sed_line()
590 name = command->w + (char *)command; in sed_line()
597 perror_exit("w '%s'", command->arg1+(char *)command); in sed_line()
610 char *from, *to = (char *)command; in sed_line()
613 from = to+command->arg1; in sed_line()
614 to += command->arg2; in sed_line()
625 command = command->next; in sed_line()
658 struct sedcmd *command; in do_sed_file() local
663 for (command = (void *)TT.pattern; command; command = command->next) in do_sed_file()
664 command->hit = 0; in do_sed_file()
746 // Translate pattern strings into command structures. Each command structure
750 struct sedcmd *command = (void *)TT.pattern; in parse_pattern() local
757 // Append this line to previous multiline command? (hit indicates type.) in parse_pattern()
759 // sed_line() it means the match range attached to this command in parse_pattern()
761 if (command && command->prev->hit) { in parse_pattern()
764 command = dlist_pop(&TT.pattern); in parse_pattern()
765 c = command->c; in parse_pattern()
766 reg = (char *)command; in parse_pattern()
767 reg += command->arg1 + strlen(reg + command->arg1); in parse_pattern()
769 // Resume parsing for 'a' or 's' command. (Only two that can do this.) in parse_pattern()
772 if (command->hit < 256) goto resume_s; in parse_pattern()
778 command = 0; in parse_pattern()
780 if (command) dlist_add_nomalloc(&TT.pattern, (void *)command); in parse_pattern()
794 command = (void *)toybuf; in parse_pattern()
804 command->lmatch[i] = -2-strtol(line, &line, 0); in parse_pattern()
805 } else if (isdigit(*line)) command->lmatch[i] = strtol(line, &line, 0); in parse_pattern()
807 command->lmatch[i] = -1; in parse_pattern()
813 if (!*s) command->rmatch[i] = 0; in parse_pattern()
816 command->rmatch[i] = reg-toybuf; in parse_pattern()
827 command->not = 1; in parse_pattern()
833 c = command->c = *(line++); in parse_pattern()
838 command = xmemdup(toybuf, reg-toybuf); in parse_pattern()
839 reg = (reg-toybuf) + (char *)command; in parse_pattern()
841 // Parse arguments by command type in parse_pattern()
855 command->arg2 = reg - (char *)command; in parse_pattern()
860 command->arg1 = reg-(char *)command; in parse_pattern()
861 command->hit = delim; in parse_pattern()
866 while (*end != command->hit) { in parse_pattern()
877 reg = extend_string((void *)&command, line, reg-(char *)command,end-line); in parse_pattern()
880 if (*line == command->hit) command->hit = 0; in parse_pattern()
889 i = command->arg1; in parse_pattern()
890 command->arg1 = command->arg2; in parse_pattern()
891 command->arg2 = i; in parse_pattern()
899 if (0 <= (l = stridx("igp", *line))) command->sflags |= 1<<l; in parse_pattern()
900 else if (!(command->sflags>>3) && 0<(l = strtol(line, &line, 10))) { in parse_pattern()
901 command->sflags |= l << 3; in parse_pattern()
908 if (!*TT.remember) command->arg1 = 0; in parse_pattern()
909 else xregcomp((void *)(command->arg1 + (char *)command), TT.remember, in parse_pattern()
910 (REG_EXTENDED*!!FLAG(r))|((command->sflags&1)*REG_ICASE)); in parse_pattern()
935 command->w = reg - (char *)command; in parse_pattern()
936 command = xrealloc(command, command->w+(cc-line)+6); in parse_pattern()
937 reg = command->w + (char *)command; in parse_pattern()
953 command->arg1 = reg-(char *)command; in parse_pattern()
955 reg = extend_string((void *)&command, s, reg-(char *)command, len); in parse_pattern()
957 command->arg2 = reg-(char *)command; in parse_pattern()
960 reg = extend_string((void *)&command, s, reg-(char*)command, len); in parse_pattern()
971 command->hit = 0; in parse_pattern()
977 else if (!command->arg1) break; in parse_pattern()
991 if (!command->arg1) command->arg1 = reg - (char*)command; in parse_pattern()
992 else if (*(command->arg1+(char *)command)) *(reg++) = '\n'; in parse_pattern()
994 command->arg1 = 0; in parse_pattern()
997 reg = extend_string((void *)&command, line, reg - (char *)command, end); in parse_pattern()
1013 command->hit = 256; in parse_pattern()