Fossil SCM
For the "fossil:" output from the "fossil info" command, on unix, provide the full pathname of the fossil executable.
Commit
01fcc6a8de6eedbe0fb5dc44af119f5666c2bdab3769a135694d174992723c3f
Parent
c0f7c8318b8c24c…
2 files changed
+59
+1
-2
+59
| --- src/file.c | ||
| +++ src/file.c | ||
| @@ -1139,10 +1139,69 @@ | ||
| 1139 | 1139 | } |
| 1140 | 1140 | #endif |
| 1141 | 1141 | blob_resize(pOut, file_simplify_name(blob_buffer(pOut), |
| 1142 | 1142 | blob_size(pOut), slash)); |
| 1143 | 1143 | } |
| 1144 | + | |
| 1145 | +/* | |
| 1146 | +** The input is the name of an executable, such as one might | |
| 1147 | +** type on a command-line. This routine resolves that name into | |
| 1148 | +** a full pathname. The result is obtained from fossil_malloc() | |
| 1149 | +** and should be freed by the caller. | |
| 1150 | +** | |
| 1151 | +** This routine only works on unix. On Windows, simply return | |
| 1152 | +** a copy of the input. | |
| 1153 | +*/ | |
| 1154 | +char *file_fullexename(const char *zCmd){ | |
| 1155 | +#ifdef _WIN32 | |
| 1156 | + return fossil_strdup(zCmd); | |
| 1157 | +#else | |
| 1158 | + char *zPath; | |
| 1159 | + char *z; | |
| 1160 | + if( zCmd[0]=='/' ){ | |
| 1161 | + return fossil_strdup(zCmd); | |
| 1162 | + } | |
| 1163 | + if( strchr(zCmd,'/')!=0 ){ | |
| 1164 | + Blob out = BLOB_INITIALIZER; | |
| 1165 | + file_canonical_name(zCmd, &out, 0); | |
| 1166 | + z = fossil_strdup(blob_str(&out)); | |
| 1167 | + blob_reset(&out); | |
| 1168 | + return z; | |
| 1169 | + } | |
| 1170 | + zPath = fossil_getenv("PATH"); | |
| 1171 | + while( zPath && zPath[0] ){ | |
| 1172 | + int n; | |
| 1173 | + char *zColon; | |
| 1174 | + zColon = strchr(zPath, ':'); | |
| 1175 | + n = zColon ? (int)(zColon-zPath) : (int)strlen(zPath); | |
| 1176 | + z = mprintf("%.*s/%s", n, zPath, zCmd); | |
| 1177 | + if( file_isexe(z, ExtFILE) ){ | |
| 1178 | + return z; | |
| 1179 | + } | |
| 1180 | + fossil_free(z); | |
| 1181 | + if( zColon==0 ) break; | |
| 1182 | + zPath = zColon+1; | |
| 1183 | + } | |
| 1184 | + return fossil_strdup(zCmd); | |
| 1185 | +#endif | |
| 1186 | +} | |
| 1187 | + | |
| 1188 | +/* | |
| 1189 | +** COMMAND: test-which | |
| 1190 | +** | |
| 1191 | +** Usage: %fossil test-which ARGS... | |
| 1192 | +** | |
| 1193 | +** For each argument, search the PATH for the executable with the name | |
| 1194 | +** and print its full pathname. | |
| 1195 | +*/ | |
| 1196 | +void test_which_cmd(void){ | |
| 1197 | + int i; | |
| 1198 | + for(i=2; i<g.argc; i++){ | |
| 1199 | + char *z = file_fullexename(g.argv[i]); | |
| 1200 | + fossil_print("%z\n", z); | |
| 1201 | + } | |
| 1202 | +} | |
| 1144 | 1203 | |
| 1145 | 1204 | /* |
| 1146 | 1205 | ** Emits the effective or raw stat() information for the specified |
| 1147 | 1206 | ** file or directory, optionally preserving the trailing slash and |
| 1148 | 1207 | ** resetting the cached stat() information. |
| 1149 | 1208 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -1139,10 +1139,69 @@ | |
| 1139 | } |
| 1140 | #endif |
| 1141 | blob_resize(pOut, file_simplify_name(blob_buffer(pOut), |
| 1142 | blob_size(pOut), slash)); |
| 1143 | } |
| 1144 | |
| 1145 | /* |
| 1146 | ** Emits the effective or raw stat() information for the specified |
| 1147 | ** file or directory, optionally preserving the trailing slash and |
| 1148 | ** resetting the cached stat() information. |
| 1149 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -1139,10 +1139,69 @@ | |
| 1139 | } |
| 1140 | #endif |
| 1141 | blob_resize(pOut, file_simplify_name(blob_buffer(pOut), |
| 1142 | blob_size(pOut), slash)); |
| 1143 | } |
| 1144 | |
| 1145 | /* |
| 1146 | ** The input is the name of an executable, such as one might |
| 1147 | ** type on a command-line. This routine resolves that name into |
| 1148 | ** a full pathname. The result is obtained from fossil_malloc() |
| 1149 | ** and should be freed by the caller. |
| 1150 | ** |
| 1151 | ** This routine only works on unix. On Windows, simply return |
| 1152 | ** a copy of the input. |
| 1153 | */ |
| 1154 | char *file_fullexename(const char *zCmd){ |
| 1155 | #ifdef _WIN32 |
| 1156 | return fossil_strdup(zCmd); |
| 1157 | #else |
| 1158 | char *zPath; |
| 1159 | char *z; |
| 1160 | if( zCmd[0]=='/' ){ |
| 1161 | return fossil_strdup(zCmd); |
| 1162 | } |
| 1163 | if( strchr(zCmd,'/')!=0 ){ |
| 1164 | Blob out = BLOB_INITIALIZER; |
| 1165 | file_canonical_name(zCmd, &out, 0); |
| 1166 | z = fossil_strdup(blob_str(&out)); |
| 1167 | blob_reset(&out); |
| 1168 | return z; |
| 1169 | } |
| 1170 | zPath = fossil_getenv("PATH"); |
| 1171 | while( zPath && zPath[0] ){ |
| 1172 | int n; |
| 1173 | char *zColon; |
| 1174 | zColon = strchr(zPath, ':'); |
| 1175 | n = zColon ? (int)(zColon-zPath) : (int)strlen(zPath); |
| 1176 | z = mprintf("%.*s/%s", n, zPath, zCmd); |
| 1177 | if( file_isexe(z, ExtFILE) ){ |
| 1178 | return z; |
| 1179 | } |
| 1180 | fossil_free(z); |
| 1181 | if( zColon==0 ) break; |
| 1182 | zPath = zColon+1; |
| 1183 | } |
| 1184 | return fossil_strdup(zCmd); |
| 1185 | #endif |
| 1186 | } |
| 1187 | |
| 1188 | /* |
| 1189 | ** COMMAND: test-which |
| 1190 | ** |
| 1191 | ** Usage: %fossil test-which ARGS... |
| 1192 | ** |
| 1193 | ** For each argument, search the PATH for the executable with the name |
| 1194 | ** and print its full pathname. |
| 1195 | */ |
| 1196 | void test_which_cmd(void){ |
| 1197 | int i; |
| 1198 | for(i=2; i<g.argc; i++){ |
| 1199 | char *z = file_fullexename(g.argv[i]); |
| 1200 | fossil_print("%z\n", z); |
| 1201 | } |
| 1202 | } |
| 1203 | |
| 1204 | /* |
| 1205 | ** Emits the effective or raw stat() information for the specified |
| 1206 | ** file or directory, optionally preserving the trailing slash and |
| 1207 | ** resetting the cached stat() information. |
| 1208 |
+1
-2
| --- src/info.c | ||
| +++ src/info.c | ||
| @@ -167,11 +167,10 @@ | ||
| 167 | 167 | fossil_print("derived-from: %s %s\n", zParentCode, |
| 168 | 168 | db_get("parent-project-name","")); |
| 169 | 169 | } |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - | |
| 173 | 172 | /* |
| 174 | 173 | ** COMMAND: info |
| 175 | 174 | ** |
| 176 | 175 | ** Usage: %fossil info ?VERSION | REPOSITORY_FILENAME? ?OPTIONS? |
| 177 | 176 | ** |
| @@ -255,11 +254,11 @@ | ||
| 255 | 254 | if( z ){ |
| 256 | 255 | z += 8; |
| 257 | 256 | }else{ |
| 258 | 257 | z = blob_str(&vx); |
| 259 | 258 | } |
| 260 | - fossil_print("fossil: %s\n", g.nameOfExe); | |
| 259 | + fossil_print("fossil: %z\n", file_fullexename(g.nameOfExe)); | |
| 261 | 260 | fossil_print("version: %s", z); |
| 262 | 261 | blob_reset(&vx); |
| 263 | 262 | } |
| 264 | 263 | }else{ |
| 265 | 264 | int rid; |
| 266 | 265 |
| --- src/info.c | |
| +++ src/info.c | |
| @@ -167,11 +167,10 @@ | |
| 167 | fossil_print("derived-from: %s %s\n", zParentCode, |
| 168 | db_get("parent-project-name","")); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | |
| 173 | /* |
| 174 | ** COMMAND: info |
| 175 | ** |
| 176 | ** Usage: %fossil info ?VERSION | REPOSITORY_FILENAME? ?OPTIONS? |
| 177 | ** |
| @@ -255,11 +254,11 @@ | |
| 255 | if( z ){ |
| 256 | z += 8; |
| 257 | }else{ |
| 258 | z = blob_str(&vx); |
| 259 | } |
| 260 | fossil_print("fossil: %s\n", g.nameOfExe); |
| 261 | fossil_print("version: %s", z); |
| 262 | blob_reset(&vx); |
| 263 | } |
| 264 | }else{ |
| 265 | int rid; |
| 266 |
| --- src/info.c | |
| +++ src/info.c | |
| @@ -167,11 +167,10 @@ | |
| 167 | fossil_print("derived-from: %s %s\n", zParentCode, |
| 168 | db_get("parent-project-name","")); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | /* |
| 173 | ** COMMAND: info |
| 174 | ** |
| 175 | ** Usage: %fossil info ?VERSION | REPOSITORY_FILENAME? ?OPTIONS? |
| 176 | ** |
| @@ -255,11 +254,11 @@ | |
| 254 | if( z ){ |
| 255 | z += 8; |
| 256 | }else{ |
| 257 | z = blob_str(&vx); |
| 258 | } |
| 259 | fossil_print("fossil: %z\n", file_fullexename(g.nameOfExe)); |
| 260 | fossil_print("version: %s", z); |
| 261 | blob_reset(&vx); |
| 262 | } |
| 263 | }else{ |
| 264 | int rid; |
| 265 |