- Timestamp:
- Aug 15, 2025, 2:51:28 AM (4 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/kmkbuiltin/redirect.c
r3564 r3685 119 119 "Usage: %s [-[rwa+tb]<fd> <file>] [-d<fd>=<src-fd>] [-c<fd>] [--stdin-pipe]\n" 120 120 " [-Z] [-E <var=val>] [-A <var=val>] [-P <var=val>] [-D <var>]\n" 121 " [-X <from-exitcode>[=<to>]\n" 121 122 " [-C <dir>] [--wcc-brain-damage] [-v] -- <program> [args]\n" 122 123 " or: %s --help\n" … … 153 154 /* 0 1 2 3 4 5 6 7 8 */ 154 155 /* 012345678901234567890123456789012345678901234567890123456789012345678901234567890 */ 156 "-X <from-exitcode>[=<to>], --translate-exitcode <from-exitcode>[=<to>]\n" 157 " Translates exit codes. The '<to>' value defaults to zero.\n" 155 158 "-C <dir>, --chdir <dir>\n" 156 159 " The -C switch is for changing the current directory. Please specify an\n" … … 164 167 "\n" 165 168 "On OS/2 the kernel variables BEGINLIBPATH, ENDLIBPATH and LIBPATHSTRICT can be\n" 166 "accessed as-if they were regular envi ornment variables.\n"169 "accessed as-if they were regular environment variables.\n" 167 170 "\n" 168 171 "This command was originally just a quick hack to avoid invoking the shell\n" … … 1377 1380 REDIRECTORDERS aOrders[32]; 1378 1381 1382 unsigned cExitCodeTranslations = 0; 1383 struct 1384 { 1385 int rcExitFrom, rcExitTo; 1386 } aExitCodeTranslations[8]; 1387 1379 1388 int iArg; 1380 1389 const char *pszExecutable = NULL; … … 1408 1417 return err(pCtx, 9, "getcwd failed"); 1409 1418 1410 /* We start out with a read-only envi ornment from kmk or the crt, and will1419 /* We start out with a read-only environment from kmk or the crt, and will 1411 1420 duplicate it if we make changes to it. */ 1412 1421 cAllocatedEnvVars = 0; … … 1502 1511 else if (strcmp(pszArg, "stdin-pipe") == 0) 1503 1512 chOpt = 'I'; 1513 else if (strcmp(pszArg, "translate-exitcode") == 0) 1514 chOpt = 'X'; 1504 1515 else 1505 1516 { … … 1537 1548 || chOpt == 'c' 1538 1549 || chOpt == 'd' 1539 || chOpt == 'e') 1550 || chOpt == 'e' 1551 || chOpt == 'X') 1540 1552 { 1541 1553 if (*pszArg != '\0') … … 1697 1709 1698 1710 /* 1711 * Exit code translation: from[=to] 1712 */ 1713 if (chOpt == 'X') 1714 { 1715 int rcExitTo = 0; 1716 char *pszEqual; 1717 int rcExitFrom = (int)strtol(pszValue, &pszEqual, 0); 1718 if (pszEqual == pszValue) 1719 rcExit = errx(pCtx, 2, "error: failed to convert 1st part of '--translate-exitcode %s' to a number", 1720 pszValue); 1721 else if (!pszEqual || !*pszEqual) 1722 rcExitTo = 0; 1723 else if (*pszEqual != '=') 1724 rcExit = errx(pCtx, 2, "syntax error: expected '=' to separate the two values in: '--translate-exitcode %s'", 1725 pszValue); 1726 else 1727 { 1728 char *pszEnd = 0; 1729 rcExitTo = (int)strtol(++pszEqual, &pszEnd, 0); 1730 if (pszEnd == pszEqual) 1731 rcExit = errx(pCtx, 2, "error: failed to convert 2nd half of '--translate-exitcode %s' to a number", 1732 pszValue); 1733 else if (pszEnd && *pszEnd != '\0') 1734 rcExit = errx(pCtx, 2, "error: unexpected trailing chars in: '--translate-exitcode %s'", pszValue); 1735 } 1736 if (cExitCodeTranslations >= K_ELEMENTS(aExitCodeTranslations)) 1737 rcExit = errx(pCtx, 2, "error: too many exit code translations"); 1738 else if (rcExit == 0) 1739 { 1740 aExitCodeTranslations[cExitCodeTranslations].rcExitFrom = rcExitFrom; 1741 aExitCodeTranslations[cExitCodeTranslations].rcExitTo = rcExitTo; 1742 cExitCodeTranslations++; 1743 } 1744 continue; 1745 } 1746 1747 /* 1699 1748 * Okay, it is some file descriptor operation. Make sure we've got room for it. 1700 1749 */ … … 2021 2070 #endif 2022 2071 &fChildExitCode); 2072 2073 /* Do exit code translations if rcExit is a child exit code. */ 2074 if (fChildExitCode) 2075 while (cExitCodeTranslations-- > 0) 2076 if (aExitCodeTranslations[cExitCodeTranslations].rcExitFrom == rcExit) 2077 { 2078 if (cVerbosity > 0) 2079 warnx(pCtx, "info: translating exit code %d to %d", 2080 rcExit, aExitCodeTranslations[cExitCodeTranslations].rcExitTo); 2081 rcExit = aExitCodeTranslations[cExitCodeTranslations].rcExitTo; 2082 break; 2083 } 2023 2084 } 2024 2085 else if (rcExit == 0)
Note:
See TracChangeset
for help on using the changeset viewer.