mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-24 13:49:50 +00:00
Implement ls -q and lsq commands to list files in quiet mode (one file per line)
This commit is contained in:
parent
54f171e8f9
commit
8bcd28c386
@ -72,7 +72,9 @@ static char *showfile(char *res, const int nth, const char *fpath, const char *n
|
||||
u_rwx = strdup ("-");
|
||||
fch = isdir? 'd': '-';
|
||||
#endif
|
||||
if (printfmt == FMT_RAW) {
|
||||
if (printfmt == 'q') {
|
||||
res = r_str_appendf (res, "%s\n", nn);
|
||||
} else if (printfmt == FMT_RAW) {
|
||||
res = r_str_appendf (res, "%c%s%s%s 1 %4d:%-4d %-10d %s\n",
|
||||
isdir?'d': fch,
|
||||
u_rwx? u_rwx: "-",
|
||||
@ -85,7 +87,7 @@ static char *showfile(char *res, const int nth, const char *fpath, const char *n
|
||||
}
|
||||
res = r_str_appendf (res, "{\"name\":\"%s\",\"size\":%d,\"uid\":%d,"
|
||||
"\"gid\":%d,\"perm\":%d,\"isdir\":%s}",
|
||||
name, sz, uid, gid, perm, isdir?"true":"false");
|
||||
name, sz, uid, gid, perm, isdir? "true": "false");
|
||||
}
|
||||
free (nn);
|
||||
free (u_rwx);
|
||||
@ -110,6 +112,10 @@ R_API char *r_syscmd_ls(const char *input) {
|
||||
input = "";
|
||||
path = ".";
|
||||
}
|
||||
if (*input == 'q') {
|
||||
printfmt = 'q';
|
||||
input++;
|
||||
}
|
||||
if (r_sandbox_enable (0)) {
|
||||
eprintf ("Sandbox forbids listing directories\n");
|
||||
return NULL;
|
||||
@ -118,7 +124,15 @@ R_API char *r_syscmd_ls(const char *input) {
|
||||
input++;
|
||||
}
|
||||
if (*input) {
|
||||
if ((!strncmp (input, "-l", 2)) || (!strncmp (input, "-j", 2))) {
|
||||
if ((!strncmp (input, "-h", 2))) {
|
||||
eprintf ("Usage: ls ([-l,-j,-q]) ([path]) # long, json, quiet\n");
|
||||
} else if ((!strncmp (input, "-q", 2))) {
|
||||
printfmt = 'q';
|
||||
path ++;
|
||||
while (*path == ' ') {
|
||||
path++;
|
||||
}
|
||||
} else if ((!strncmp (input, "-l", 2)) || (!strncmp (input, "-j", 2))) {
|
||||
// mode = 'l';
|
||||
if (input[2]) {
|
||||
printfmt = (input[2] == 'j') ? FMT_JSON : FMT_RAW;
|
||||
@ -144,8 +158,8 @@ R_API char *r_syscmd_ls(const char *input) {
|
||||
path = (const char *)homepath;
|
||||
}
|
||||
} else if (*path == '$') {
|
||||
if (!strncmp (path + 1, "home", 4) || !strncmp (path + 1, "HOME", 4)){
|
||||
homepath = r_str_home ((strlen (path)>5)? path + 6: NULL);
|
||||
if (!strncmp (path + 1, "home", 4) || !strncmp (path + 1, "HOME", 4)) {
|
||||
homepath = r_str_home ((strlen (path) > 5)? path + 6: NULL);
|
||||
if (homepath) {
|
||||
path = (const char *)homepath;
|
||||
}
|
||||
@ -153,7 +167,7 @@ R_API char *r_syscmd_ls(const char *input) {
|
||||
}
|
||||
if (!r_file_is_directory (path)) {
|
||||
p = strrchr (path, '/');
|
||||
if (p){
|
||||
if (p) {
|
||||
off = p - path;
|
||||
d = (char *) calloc (1, off + 1);
|
||||
if (!d) {
|
||||
|
Loading…
Reference in New Issue
Block a user