gphoto2canonpath(): handle non-"D:" drive names, remove trailing backslash

canon2gphotopath(): handle longer drive names


git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@3660 67ed7778-7388-44ab-90cf-0a291f65f57c
This commit is contained in:
Hans Ulrich Niedermann
2002-01-02 18:40:01 +00:00
parent 4c1c082e8c
commit 2597b4dfef
2 changed files with 32 additions and 10 deletions

View File

@@ -631,20 +631,34 @@ canon_int_get_disk_name_info (Camera *camera, const char *name, int *capacity, i
* into canon style path (e.g. "D:\DCIM\116CANON\IMG_1240.JPG")
*/
char *
gphoto2canonpath (char *path)
gphoto2canonpath (Camera *camera, char *path)
{
static char tmp[2000];
char *p;
if (path[0] != '/') {
GP_DEBUG ("Non-absolute gphoto2 path cannot be converted");
return NULL;
}
strcpy (tmp, "D:"); // FIXME
strcpy (tmp + 2, path);
for (p = tmp + 2; *p != '\0'; p++) {
if (camera->pl->cached_drive == NULL)
GP_DEBUG ("NULL camera->pl->cached_drive in gphoto2canonpath");
strcpy (tmp, camera->pl->cached_drive);
strcat (tmp, path);
/* replace all slashes by backslashes */
for (p = tmp; *p != '\0'; p++) {
if (*p == '/')
*p = '\\';
}
/* remove trailing backslash */
if ((p > tmp) && (*(p-1) == '\\'))
*(p-1) = '\0';
GP_LOG (GP_LOG_DATA, "gphoto2canonpath: converted '%s' to '%s'", path, tmp);
return (tmp);
}
@@ -654,9 +668,12 @@ gphoto2canonpath (char *path)
*
* convert canon style path (e.g. "D:\DCIM\116CANON\IMG_1240.JPG")
* into gphoto2 path (e.g. "/DCIM/116CANON/IMG_1240.JPG")
*
* Assumes @path to start with drive name followed by a colon.
* It just drops the drive name.
*/
char *
canon2gphotopath (char *path)
const char *
canon2gphotopath (Camera *camera, const char *path)
{
static char tmp[2000];
char *p;
@@ -664,13 +681,18 @@ canon2gphotopath (char *path)
if (!((path[1] == ':') && (path[2] == '\\'))) {
return NULL;
}
// FIXME: just drops the drive letter
p = path + 2;
p = strchr(path, ':') + 1;
strcpy (tmp, p);
/* replace backslashes by slashes */
for (p = tmp; *p != '\0'; p++) {
if (*p == '\\')
*p = '/';
}
GP_LOG (GP_LOG_DATA, "canon2gphotopath: converted '%s' to '%s'", path, tmp);
return (tmp);
}

View File

@@ -181,8 +181,8 @@ int canon_int_identify_camera(Camera *camera);
int canon_int_set_owner_name(Camera *camera, const char *name);
/* path conversion - needs drive letter, and can therefor not be moved to util.c */
char *canon2gphotopath(char *path);
char *gphoto2canonpath(char *path);
const char *canon2gphotopath(Camera *camera, const char *path);
char *gphoto2canonpath(Camera *camera, char *path);
/* for the macros abbreviating gp_log* */
#define GP_MODULE "canon"