Lines Matching +full:r +full:- +full:xp

4 /*-
14 * is granted to deal in this work without restriction, including un-
78 Xcheck_grow(XString *xsp, const char *xp, size_t more) in Xcheck_grow() argument
80 const char *old_beg = xsp->beg; in Xcheck_grow()
82 if (more < xsp->len) in Xcheck_grow()
83 more = xsp->len; in Xcheck_grow()
84 /* (xsp->len + X_EXTRA) never overflows */ in Xcheck_grow()
85 checkoktoadd(more, xsp->len + X_EXTRA); in Xcheck_grow()
86 xsp->beg = aresize(xsp->beg, (xsp->len += more) + X_EXTRA, xsp->areap); in Xcheck_grow()
87 xsp->end = xsp->beg + xsp->len; in Xcheck_grow()
88 return (xsp->beg + (xp - old_beg)); in Xcheck_grow()
106 #define OFC(i) (options[i][-2])
107 #define OFF(i) (((const unsigned char *)options[i])[-1])
116 * translate -o option into F* constant (also used for test -o option)
136 return ((size_t)-1); in option()
154 shf_snprintf(buf, buflen, "%-*s %s", in options_fmt_entry()
155 oi->opt_width, OFN(oi->opts[i]), in options_fmt_entry()
156 Flag(oi->opts[i]) ? "on" : "off"); in options_fmt_entry()
239 strndupx(cp, m, cp - m, ATEMP); in getoptions()
258 /* turning off -p */ in change_flag()
295 /* Turning on -o posix? */ in change_flag()
299 /* Turning on -o posix or -o sh? */ in change_flag()
355 if (shl_xtrace->fd != 2) in change_xtrace()
356 close(shl_xtrace->fd); in change_xtrace()
357 if (!newval || (shl_xtrace->fd = savefd(2)) == -1) in change_xtrace()
358 shl_xtrace->fd = 2; in change_xtrace()
372 * non-option arguments, -1 if there is an error.
403 while ((optc = ksh_getopt(argv, &go, opts)) != -1) { in parse_args()
409 arrayset = set ? 1 : -1; in parse_args()
418 * lone -o: print options in parse_args()
420 * Note that on the command line, -o requires in parse_args()
428 return (-1); in parse_args()
432 return (-1); in parse_args()
438 * If running 'set -o posix' or in parse_args()
439 * 'set -o sh', turn off the other; in parse_args()
440 * if running 'set -o posix -o sh' in parse_args()
447 if ((i != (size_t)-1) && (set ? 1U : 0U) == Flag(i)) in parse_args()
450 * isn't changing - makes "set -o interactive" in parse_args()
455 else if ((i != (size_t)-1) && (OFF(i) & what)) in parse_args()
462 return (-1); in parse_args()
476 return (-1); in parse_args()
494 return (-1); in parse_args()
499 /* -s: sort positional params (AT&T ksh stupidity) */ in parse_args()
517 /* lone - clears -v and -x flags */ in parse_args()
518 if (argv[go.optind][0] == '-') { in parse_args()
522 /* set skips lone - or + option */ in parse_args()
526 /* -- means set $#/$* even if there are no arguments */ in parse_args()
537 return (-1); in parse_args()
543 qsort(&argv[go.optind], i - go.optind, sizeof(void *), in parse_args()
568 case '-': in getn()
588 /* overflow for signed 32-bit int */ in getn()
592 num.u = -num.u; in getn()
599 * - @(x) -> x (not @(x|y) though)
600 * - ** -> *
612 /* foo@(b@(a)r)b@(a|a)z -> foobarb@(a|a)z */ in simplify_gmatch_pattern()
629 if (!ps || ps[-1] != /*(*/ ')') in simplify_gmatch_pattern()
633 ps -= 2; in simplify_gmatch_pattern()
670 /* -------- gmatch.c -------- */
695 size_t len = pe - p + 1; in gmatchx()
721 * - [ with no closing ]
722 * - imbalanced $(...) expression
723 * - [...] and *(...) not nested (eg, @(a[b|)c], *(a[b|c]d))
726 * - if no magic,
729 * - if magic && (no globbing || syntax error)
732 * - return ?
776 /* sub-bracket expressions */ in has_globbing()
809 --nest; in has_globbing()
828 sl = s[-1]; in do_gmatch()
848 /* zero-length match */ in do_gmatch()
849 --s; in do_gmatch()
872 --s; in do_gmatch()
880 s--; in do_gmatch()
898 s--; in do_gmatch()
900 if (ord(p[-1]) == (0x80 | ORD('*')) && in do_gmatch()
906 if (do_gmatch(s, srest, psub, pnext - 2, smin) && in do_gmatch()
909 do_gmatch(srest, se, p - 2, pe, smin)))) in do_gmatch()
925 s--; in do_gmatch()
927 if (ord(p[-1]) == (0x80 | ORD('?')) && in do_gmatch()
934 if (do_gmatch(s, srest, psub, pnext - 2, smin) && in do_gmatch()
947 s--; in do_gmatch()
954 pnext - 2, smin)) { in do_gmatch()
968 if (sc != p[-1]) in do_gmatch()
1025 /* make initial ] non-MAGIC */ in gmatch_cclass()
1031 /* non-regular character? */ in gmatch_cclass()
1041 /* sub-bracket expressions */ in gmatch_cclass()
1066 strndupx(subp, s, p - s - 3, ATEMP); in gmatch_cclass()
1067 debunk(subp, subp, p - s - 3 + 1); in gmatch_cclass()
1074 while (cls->name) in gmatch_cclass()
1075 if (!strcmp(subp, cls->name)) { in gmatch_cclass()
1078 cls->value)) in gmatch_cclass()
1110 if (!(ISMAGIC(p[0]) && ord(p[1]) == ORD('-') && in gmatch_cclass()
1128 /* non-regular character? */ in gmatch_cclass()
1133 /* sub-bracket expressions */ in gmatch_cclass()
1158 strndupx(subp, s, p - s - 3, ATEMP); in gmatch_cclass()
1159 debunk(subp, subp, p - s - 3 + 1); in gmatch_cclass()
1167 /* match hyphen-minus */ in gmatch_cclass()
1168 if (ord(sc) == ORD('-')) in gmatch_cclass()
1222 if ((*++p == /*(*/ ')' && nest-- == 0) || in pat_scan()
1241 return ((int)asciibetical(*cp1) - (int)asciibetical(*cp2)); in ascstrcmp()
1255 go->optind = 1; in ksh_getopt_reset()
1256 go->optarg = NULL; in ksh_getopt_reset()
1257 go->p = 0; in ksh_getopt_reset()
1258 go->flags = flags; in ksh_getopt_reset()
1259 go->info = 0; in ksh_getopt_reset()
1260 go->buf[1] = '\0'; in ksh_getopt_reset()
1265 * getopt() used for shell built-in commands, the getopts command, and
1268 * or ':' and set go->optarg to the offending option character.
1272 * Non-standard features:
1273 * - ';' is like ':' in options, except the argument is optional
1275 * Used for 'set -o'.
1276 * - ',' is like ':' in options, except the argument always immediately
1279 * Used for 'read -u2', 'print -u2' and fc -40.
1280 * - '#' is like ':' in options, expect that the argument is optional
1284 * Used for 'typeset -LZ4'.
1285 * - accepts +c as well as -c IF the GF_PLUSOPT flag is present. If an
1287 * in go->info.
1295 if (go->p == 0 || (c = argv[go->optind - 1][go->p]) == '\0') { in ksh_getopt()
1296 const char *arg = argv[go->optind], flag = arg ? *arg : '\0'; in ksh_getopt()
1298 go->p = 1; in ksh_getopt()
1299 if (flag == '-' && ksh_isdash(arg + 1)) { in ksh_getopt()
1300 go->optind++; in ksh_getopt()
1301 go->p = 0; in ksh_getopt()
1302 go->info |= GI_MINUSMINUS; in ksh_getopt()
1303 return (-1); in ksh_getopt()
1306 ((flag != '-' ) && in ksh_getopt()
1307 /* neither a - nor a + (if + allowed) */ in ksh_getopt()
1308 (!(go->flags & GF_PLUSOPT) || flag != '+')) || in ksh_getopt()
1310 go->p = 0; in ksh_getopt()
1311 return (-1); in ksh_getopt()
1313 go->optind++; in ksh_getopt()
1314 go->info &= ~(GI_MINUS|GI_PLUS); in ksh_getopt()
1315 go->info |= flag == '-' ? GI_MINUS : GI_PLUS; in ksh_getopt()
1317 go->p++; in ksh_getopt()
1321 go->buf[0] = c; in ksh_getopt()
1322 go->optarg = go->buf; in ksh_getopt()
1325 (go->flags & GF_NONAME) ? "" : argv[0], in ksh_getopt()
1326 (go->flags & GF_NONAME) ? "" : Tcolsp, in ksh_getopt()
1328 if (go->flags & GF_ERROR) in ksh_getopt()
1340 if (argv[go->optind - 1][go->p]) in ksh_getopt()
1341 go->optarg = argv[go->optind - 1] + go->p; in ksh_getopt()
1342 else if (argv[go->optind]) in ksh_getopt()
1343 go->optarg = argv[go->optind++]; in ksh_getopt()
1345 go->optarg = NULL; in ksh_getopt()
1348 go->buf[0] = c; in ksh_getopt()
1349 go->optarg = go->buf; in ksh_getopt()
1353 (go->flags & GF_NONAME) ? "" : argv[0], in ksh_getopt()
1354 (go->flags & GF_NONAME) ? "" : Tcolsp, in ksh_getopt()
1356 if (go->flags & GF_ERROR) in ksh_getopt()
1360 go->p = 0; in ksh_getopt()
1363 go->optarg = argv[go->optind - 1] + go->p; in ksh_getopt()
1364 go->p = 0; in ksh_getopt()
1371 if (argv[go->optind - 1][go->p]) { in ksh_getopt()
1372 if (ctype(argv[go->optind - 1][go->p], C_DIGIT)) { in ksh_getopt()
1373 go->optarg = argv[go->optind - 1] + go->p; in ksh_getopt()
1374 go->p = 0; in ksh_getopt()
1376 go->optarg = NULL; in ksh_getopt()
1378 if (argv[go->optind] && in ksh_getopt()
1379 ctype(argv[go->optind][0], C_DIGIT)) { in ksh_getopt()
1380 go->optarg = argv[go->optind++]; in ksh_getopt()
1381 go->p = 0; in ksh_getopt()
1383 go->optarg = NULL; in ksh_getopt()
1391 * (POSIX says they should be suitable for re-entry...)
1401 /* first, special-case empty strings (for re-entrancy) */ in print_value_quoted()
1408 /* non-empty; check whether any quotes are needed */ in print_value_quoted()
1451 if (n != (size_t)-1) { in print_value_quoted()
1477 case '\r': in print_value_quoted()
1478 c = 'r'; in print_value_quoted()
1522 * Print things in columns and rows - func() is called to format
1523 * the i-th element
1530 unsigned int i, r = 0, c, rows, cols, nspace, max_col; in print_columns() local
1558 * to avoid problems with terminals that have auto-wrap, in print_columns()
1566 while (r < n) { in print_columns()
1567 shf_putc(opts->linesep, opts->shf); in print_columns()
1569 (*func)(str, max_oct, r++, arg); in print_columns()
1570 shf_puts(str, opts->shf); in print_columns()
1575 rows = (n + cols - 1) / cols; in print_columns()
1576 if (opts->prefcol && cols > rows) { in print_columns()
1578 rows = (n + cols - 1) / cols; in print_columns()
1581 nspace = (x_cols - max_col * cols) / cols; in print_columns()
1584 max_col = -max_col; in print_columns()
1586 while (r < rows) { in print_columns()
1587 shf_putchar(opts->linesep, opts->shf); in print_columns()
1590 if ((i = c * rows + r) >= n) in print_columns()
1594 shf_puts(str, opts->shf); in print_columns()
1596 shf_fprintf(opts->shf, "%*s%*s", in print_columns()
1599 ++r; in print_columns()
1602 if (opts->do_last) in print_columns()
1603 shf_putchar(opts->linesep, opts->shf); in print_columns()
1607 /* strip all NUL bytes from buf; output is NUL-terminated if stripped */
1631 * Like read(2), but if read fails due to non-blocking flag,
1654 * Reset the non-blocking flag on the specified file descriptor.
1655 * Returns -1 if there was an error, 0 if non-blocking wasn't set,
1664 return (-1); in reset_nonblock()
1669 return (-1); in reset_nonblock()
1704 char *xp, *ip, *tp, *ipath, *ldest = NULL; in do_realpath() local
1725 /* upath is a drive-relative pathname */ in do_realpath()
1728 /* A:foo -> A:/cwd/foo; A: -> A:/cwd */ in do_realpath()
1739 /* ipath and upath are in memory at the same time -> unchecked */ in do_realpath()
1740 Xinit(xs, xp, strlen(ip = ipath) + 1, ATEMP); in do_realpath()
1756 len = ip - tp; in do_realpath()
1766 while (xp > Xstring(xs, xp)) in do_realpath()
1767 if (mksh_cdirsep(*--xp)) in do_realpath()
1775 pos = Xsavepos(xs, xp); in do_realpath()
1777 XcheckN(xs, xp, 1 + len + 1); in do_realpath()
1778 Xput(xs, xp, '/'); in do_realpath()
1781 memcpy(xp, tp, len); in do_realpath()
1782 xp += len; in do_realpath()
1783 *xp = '\0'; in do_realpath()
1786 if (mksh_lstat(Xstring(xs, xp), &sb)) { in do_realpath()
1807 if (!symlinks--) { in do_realpath()
1823 llen = readlink(Xstring(xs, xp), ldest, pathlen); in do_realpath()
1842 /* symlink target might be drive-relative */ in do_realpath()
1851 xp = Xrestpos(xs, xp, pos); in do_realpath()
1856 xp = Xstring(xs, xp); in do_realpath()
1859 /* assert: xp == xs.beg => start of path */ in do_realpath()
1864 Xput(xs, xp, '/'); in do_realpath()
1870 Xput(xs, xp, *ip++); in do_realpath()
1871 Xput(xs, xp, *ip++); in do_realpath()
1883 if (Xlength(xs, xp) == 0) in do_realpath()
1888 Xput(xs, xp, '/'); in do_realpath()
1889 Xput(xs, xp, '\0'); in do_realpath()
1893 * is not a non-directory existing file in do_realpath()
1895 if (ip > ipath && mksh_cdirsep(ip[-1])) { in do_realpath()
1896 if (stat(Xstring(xs, xp), &sb)) { in do_realpath()
1909 return (Xclose(xs, xp)); in do_realpath()
1916 Xfree(xs, xp); in do_realpath()
1926 * - make result NULL
1927 * - if file starts with '/', append file to result & set cdpathp to NULL
1928 * - if file starts with ./ or ../ append cwd and file to result
1930 * - if the first element of cdpathp doesnt start with a '/' xx or '.' xx
1932 * - the first element of cdpathp is appended to result
1933 * - file is appended to result
1934 * - cdpathp is set to the start of the next element in cdpathp (or NULL
1936 * The return value indicates whether a non-null element from cdpathp
1941 /* pointer to colon-separated list */ in make_path()
1950 char *xp = Xstring(*xsp, xp); in make_path() local
1976 plen = pend - plist; in make_path()
1983 XcheckN(*xsp, xp, len); in make_path()
1984 memcpy(xp, cwd, len); in make_path()
1985 xp += len; in make_path()
1986 if (!mksh_cdirsep(cwd[len - 1])) in make_path()
1987 Xput(*xsp, xp, '/'); in make_path()
1989 *phys_pathp = Xlength(*xsp, xp); in make_path()
1991 XcheckN(*xsp, xp, plen); in make_path()
1992 memcpy(xp, plist, plen); in make_path()
1993 xp += plen; in make_path()
1994 if (!mksh_cdirsep(plist[plen - 1])) in make_path()
1995 Xput(*xsp, xp, '/'); in make_path()
2001 XcheckN(*xsp, xp, len); in make_path()
2002 memcpy(xp, file, len); in make_path()
2010 /*-
2080 len = ip - tp; in simplify_path()
2098 if (mksh_cdirsep(*--dp)) in simplify_path()
2103 /* or already dotdot-slash'd */ in simplify_path()
2105 /* keep dotdot-slash if not absolute */ in simplify_path()
2128 /* empty path -> dot (or slash, when absolute) */ in simplify_path()
2167 while ((optc = ksh_getopt(wp, &builtin_opt, "eLP")) != -1) in c_cd()
2192 /* No arguments - go home */ in c_cd()
2198 /* One argument: - or dir */ in c_cd()
2211 /* Two arguments - substitute arg1 in PWD for arg2 */ in c_cd()
2229 /*- in c_cd()
2235 ilen = cp - current_wd; in c_cd()
2271 rv = chdir(tryp = Xstring(xs, xp) + phys_path); in c_cd()
2273 simplify_path(Xstring(xs, xp)); in c_cd()
2274 rv = chdir(tryp = Xstring(xs, xp)); in c_cd()
2284 Xfree(xs, xp); in c_cd()
2305 if (!mksh_abspath(Xstring(xs, xp))) { in c_cd()
2309 } else if ((pwd = allocd = do_realpath(Xstring(xs, xp))) == NULL) { in c_cd()
2313 pwd = Xstring(xs, xp); in c_cd()
2325 pwd = Xstring(xs, xp); in c_cd()
2334 Xfree(xs, xp); in c_cd()
2345 const char *dv = go->optarg; in chvt()
2350 case '-': in chvt()
2367 "can't find tty", go->optarg); in chvt()
2389 if (go->optarg[0] != '!') { in chvt()
2391 case -1: in chvt()
2399 if (setsid() == -1) in chvt()
2401 if (go->optarg[0] != '-') { in chvt()
2402 if (ioctl(fd, TIOCSCTTY, NULL) == -1) in chvt()
2445 return (b - 1); in strstr()
2471 #define INVTCK(r,t) do { \ argument
2472 r.tv_usec = ((t) % (1000000 / CLK_TCK)) * (1000000 / CLK_TCK); \
2473 r.tv_sec = (t) / CLK_TCK; \
2482 if (/* ru == NULL || */ times(&tms) == (clock_t)-1) in getrusage()
2483 return (-1); in getrusage()
2496 return (-1); in getrusage()
2498 INVTCK(ru->ru_utime, u); in getrusage()
2499 INVTCK(ru->ru_stime, s); in getrusage()
2507 * assuming the first call to *fg gets the char di-
2509 * (0..0xFF), UCS (wc + 0x100), or -1 if no known
2541 case 'r': in unbksl()
2542 wc = '\r'; in unbksl()
2570 while (i--) in unbksl()
2587 i = cstyle ? -1 : 2; in unbksl()
2597 while (n < i || i == -1) { in unbksl()
2629 return (-1); in unbksl()