Fossil SCM

For the "fossil:" output from the "fossil info" command, on unix, provide the full pathname of the fossil executable.

drh 2020-04-19 16:53 trunk
Commit 01fcc6a8de6eedbe0fb5dc44af119f5666c2bdab3769a135694d174992723c3f
2 files changed +59 +1 -2
+59
--- src/file.c
+++ src/file.c
@@ -1139,10 +1139,69 @@
11391139
}
11401140
#endif
11411141
blob_resize(pOut, file_simplify_name(blob_buffer(pOut),
11421142
blob_size(pOut), slash));
11431143
}
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
+}
11441203
11451204
/*
11461205
** Emits the effective or raw stat() information for the specified
11471206
** file or directory, optionally preserving the trailing slash and
11481207
** resetting the cached stat() information.
11491208
--- 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 @@
167167
fossil_print("derived-from: %s %s\n", zParentCode,
168168
db_get("parent-project-name",""));
169169
}
170170
}
171171
172
-
173172
/*
174173
** COMMAND: info
175174
**
176175
** Usage: %fossil info ?VERSION | REPOSITORY_FILENAME? ?OPTIONS?
177176
**
@@ -255,11 +254,11 @@
255254
if( z ){
256255
z += 8;
257256
}else{
258257
z = blob_str(&vx);
259258
}
260
- fossil_print("fossil: %s\n", g.nameOfExe);
259
+ fossil_print("fossil: %z\n", file_fullexename(g.nameOfExe));
261260
fossil_print("version: %s", z);
262261
blob_reset(&vx);
263262
}
264263
}else{
265264
int rid;
266265
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button