Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F152797971
D37926.id114698.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
5 KB
Referenced Files
None
Subscribers
None
D37926.id114698.diff
View Options
Index: bin/sh/parser.c
===================================================================
--- bin/sh/parser.c
+++ bin/sh/parser.c
@@ -2056,135 +2056,139 @@
/*
* Format prompt string.
*/
- for (i = 0; (i < PROMPTLEN - 1) && (*fmt != '\0'); i++, fmt++)
- if (*fmt == '\\')
- switch (*++fmt) {
+ for (i = 0; (i < PROMPTLEN - 1) && (*fmt != '\0'); i++, fmt++) {
+ if (*fmt != '\\') {
+ ps[i] = *fmt;
+ continue;
+ }
- /*
- * Non-printing sequence begin and end.
- */
- case '[':
- case ']':
- ps[i] = '\001';
- break;
+ switch (*++fmt) {
- /*
- * Literal \ and some ASCII characters:
- * \a BEL
- * \e ESC
- * \r CR
- */
- case '\\':
- case 'a':
- case 'e':
- case 'r':
- if (*fmt == 'a')
- ps[i] = '\007';
- else if (*fmt == 'e')
- ps[i] = '\033';
- else if (*fmt == 'r')
- ps[i] = '\r';
- else
- ps[i] = '\\';
- break;
+ /*
+ * Non-printing sequence begin and end.
+ */
+ case '[':
+ case ']':
+ ps[i] = '\001';
+ break;
- /*
- * CRLF sequence
- */
- case 'n':
- if (i < PROMPTLEN - 3) {
- ps[i++] = '\r';
- ps[i] = '\n';
- }
- break;
+ /*
+ * Literal \ and some ASCII characters:
+ * \a BEL
+ * \e ESC
+ * \r CR
+ */
+ case '\\':
+ case 'a':
+ case 'e':
+ case 'r':
+ if (*fmt == 'a')
+ ps[i] = '\007';
+ else if (*fmt == 'e')
+ ps[i] = '\033';
+ else if (*fmt == 'r')
+ ps[i] = '\r';
+ else
+ ps[i] = '\\';
+ break;
- /*
- * Hostname.
- *
- * \h specifies just the local hostname,
- * \H specifies fully-qualified hostname.
- */
- case 'h':
- case 'H':
- ps[i] = '\0';
- gethostname(&ps[i], PROMPTLEN - i - 1);
- ps[PROMPTLEN - 1] = '\0';
- /* Skip to end of hostname. */
- trim = (*fmt == 'h') ? '.' : '\0';
- while ((ps[i] != '\0') && (ps[i] != trim))
- i++;
- --i;
- break;
+ /*
+ * CRLF sequence
+ */
+ case 'n':
+ if (i < PROMPTLEN - 3) {
+ ps[i++] = '\r';
+ ps[i] = '\n';
+ }
+ break;
- /*
- * User name.
- */
- case 'u':
- ps[i] = '\0';
- getusername(&ps[i], PROMPTLEN - i);
- /* Skip to end of username. */
- while (ps[i + 1] != '\0')
- i++;
- break;
+ /*
+ * Hostname.
+ *
+ * \h specifies just the local hostname,
+ * \H specifies fully-qualified hostname.
+ */
+ case 'h':
+ case 'H':
+ ps[i] = '\0';
+ gethostname(&ps[i], PROMPTLEN - i - 1);
+ ps[PROMPTLEN - 1] = '\0';
+ /* Skip to end of hostname. */
+ trim = (*fmt == 'h') ? '.' : '\0';
+ while ((ps[i] != '\0') && (ps[i] != trim))
+ i++;
+ --i;
+ break;
- /*
- * Working directory.
- *
- * \W specifies just the final component,
- * \w specifies the entire path.
- */
- case 'W':
- case 'w':
- pwd = lookupvar("PWD");
- if (pwd == NULL || *pwd == '\0')
- pwd = "?";
- if (*fmt == 'W' &&
- *pwd == '/' && pwd[1] != '\0')
- strlcpy(&ps[i], strrchr(pwd, '/') + 1,
+ /*
+ * User name.
+ */
+ case 'u':
+ ps[i] = '\0';
+ getusername(&ps[i], PROMPTLEN - i);
+ /* Skip to end of username. */
+ while (ps[i + 1] != '\0')
+ i++;
+ break;
+
+ /*
+ * Working directory.
+ *
+ * \W specifies just the final component,
+ * \w specifies the entire path.
+ */
+ case 'W':
+ case 'w':
+ pwd = lookupvar("PWD");
+ if (pwd == NULL || *pwd == '\0')
+ pwd = "?";
+ if (*fmt == 'W' &&
+ *pwd == '/' && pwd[1] != '\0')
+ strlcpy(&ps[i], strrchr(pwd, '/') + 1,
+ PROMPTLEN - i);
+ else {
+ home = lookupvar("HOME");
+ if (home != NULL)
+ homelen = strlen(home);
+ if (home != NULL &&
+ strcmp(home, "/") != 0 &&
+ strncmp(pwd, home, homelen) == 0 &&
+ (pwd[homelen] == '/' ||
+ pwd[homelen] == '\0')) {
+ strlcpy(&ps[i], "~",
PROMPTLEN - i);
- else {
- home = lookupvar("HOME");
- if (home != NULL)
- homelen = strlen(home);
- if (home != NULL &&
- strcmp(home, "/") != 0 &&
- strncmp(pwd, home, homelen) == 0 &&
- (pwd[homelen] == '/' ||
- pwd[homelen] == '\0')) {
- strlcpy(&ps[i], "~",
- PROMPTLEN - i);
- strlcpy(&ps[i + 1],
- pwd + homelen,
- PROMPTLEN - i - 1);
- } else {
- strlcpy(&ps[i], pwd, PROMPTLEN - i);
- }
+ strlcpy(&ps[i + 1],
+ pwd + homelen,
+ PROMPTLEN - i - 1);
+ } else {
+ strlcpy(&ps[i], pwd, PROMPTLEN - i);
}
- /* Skip to end of path. */
- while (ps[i + 1] != '\0')
- i++;
- break;
+ }
+ /* Skip to end of path. */
+ while (ps[i + 1] != '\0')
+ i++;
+ break;
- /*
- * Superuser status.
- *
- * '$' for normal users, '#' for root.
- */
- case '$':
- ps[i] = (geteuid() != 0) ? '$' : '#';
- break;
+ /*
+ * Superuser status.
+ *
+ * '$' for normal users, '#' for root.
+ */
+ case '$':
+ ps[i] = (geteuid() != 0) ? '$' : '#';
+ break;
- /*
- * Emit unrecognized formats verbatim.
- */
- default:
- ps[i] = '\\';
- if (i < PROMPTLEN - 2)
- ps[++i] = *fmt;
- break;
- }
- else
- ps[i] = *fmt;
+ /*
+ * Emit unrecognized formats verbatim.
+ */
+ default:
+ ps[i] = '\\';
+ if (i < PROMPTLEN - 2)
+ ps[++i] = *fmt;
+ break;
+ }
+
+ }
ps[i] = '\0';
return (ps);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Apr 18, 4:38 AM (29 m, 31 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31698371
Default Alt Text
D37926.id114698.diff (5 KB)
Attached To
Mode
D37926: sh: reindent a for loop in parser.c
Attached
Detach File
Event Timeline
Log In to Comment