Skip to content

Commit

Permalink
处理参数带双引号的情况
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-soft committed Dec 23, 2024
1 parent 4e8e7b8 commit 5260830
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
int main(int argc, char *argv[])
{
#ifndef DEBUG
char *bin_path = malloc(sizeof(char) * (strlen(argv[0]) + 1));
strtrim(bin_path, argv[0], "\"");
char *bin_path = path_from(argv[0]);
char *dirname = path_dirname(bin_path);
chdir(dirname);
free(bin_path);
Expand All @@ -23,8 +22,10 @@ int main(int argc, char *argv[])
lcui_app_init();
if (argc > 1) {
ui_widget_t *view = ui_create_image_view();
char *file_path = path_from(argv[1]);
ui_widget_append(ui_root(), view);
image_view_load_file(view, argv[1]);
image_view_load_file(view, file_path);
free(file_path);
} else {
ui_widget_append(ui_root(), ui_create_home());
ui_widget_set_title(ui_root(), L"kantu");
Expand Down
7 changes: 7 additions & 0 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,10 @@ int format_size(char buf[16], size_t size)
}
return snprintf(buf, 16, "%zu %s", size, units[i]);
}

char *path_from(const char *str)
{
char *path = malloc(sizeof(char) * (strlen(str) + 1));
strtrim(path, str, "\"");
return path;
}
1 change: 1 addition & 0 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const char *str_last_char(const char *str, char ch);
const char *path_last_sep(const char *path);
const char *path_basename(const char *path);
char *path_from(const char *str);
char *path_dirname(const char *path);
char *path_join(const char *dir, const char *name);
int format_size(char buf[16], size_t size);

0 comments on commit 5260830

Please sign in to comment.