mirror of
https://github.com/rxrbln/t2sde.git
synced 2025-05-08 20:21:59 +08:00
* improve fl_wrparse to terminate directories with a / so they are
instantly recognizable in the flist w/o further syscall i/o git-svn-id: https://svn.exactcode.de/t2/trunk@73194 c5f82cb5-29bc-0310-9cd0-bff59a50e3bc
This commit is contained in:
parent
37cbb4c791
commit
5c9e34c2e7
@ -1,18 +1,10 @@
|
||||
/*
|
||||
* --- T2-COPYRIGHT-NOTE-BEGIN ---
|
||||
* This copyright note is auto-generated by ./scripts/Create-CopyPatch.
|
||||
*
|
||||
* T2 SDE: misc/tools-source/fl_wrparse.c
|
||||
* Copyright (C) 2004 - 2005 The T2 SDE Project
|
||||
* --- T2-COPYRIGHT-BEGIN ---
|
||||
* t2/misc/tools-source/fl_wrparse.c
|
||||
* Copyright (C) 2004 - 2025 The T2 SDE Project
|
||||
* Copyright (C) 1998 - 2003 ROCK Linux Project
|
||||
*
|
||||
* More information can be found in the files COPYING and README.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; version 2 of the License. A copy of the
|
||||
* GNU General Public License can be found in the file COPYING.
|
||||
* --- T2-COPYRIGHT-NOTE-END ---
|
||||
* SPDX-License-Identifier: GPL-2.0
|
||||
* --- T2-COPYRIGHT-END ---
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
@ -23,7 +15,7 @@
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
|
||||
char * get_realname(char * origname) {
|
||||
char * get_realname(char * origname, int is_dir) {
|
||||
static char buf[FILENAME_MAX];
|
||||
char *file, odir[FILENAME_MAX];
|
||||
|
||||
@ -34,7 +26,7 @@ char * get_realname(char * origname) {
|
||||
file = origname;
|
||||
strcpy(buf, ".");
|
||||
} else {
|
||||
*file=0; file++;
|
||||
*file = 0; file++;
|
||||
file = origname + (file-buf);
|
||||
}
|
||||
|
||||
@ -43,13 +35,14 @@ char * get_realname(char * origname) {
|
||||
|
||||
if (strcmp(buf, "/")) strcat(buf,"/");
|
||||
strcat(buf, file);
|
||||
if (is_dir) strcat(buf, "/");
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
int dir_empty(char * nam) {
|
||||
int dir_empty(char * name) {
|
||||
struct dirent **namelist; int n;
|
||||
n = scandir(nam, &namelist, 0, alphasort);
|
||||
n = scandir(name, &namelist, 0, alphasort);
|
||||
if (n < 0) perror("scandir");
|
||||
while (n--)
|
||||
if ( strcmp(namelist[n]->d_name,".") &&
|
||||
@ -86,7 +79,7 @@ int main(int argc, char ** argv) {
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
strcpy(realrootdir, get_realname(optarg));
|
||||
strcpy(realrootdir, get_realname(optarg, 0));
|
||||
rootdir = realrootdir;
|
||||
break;
|
||||
|
||||
@ -100,7 +93,7 @@ int main(int argc, char ** argv) {
|
||||
if ( rootdir != NULL ) chdir(rootdir);
|
||||
|
||||
while ( fgets(buf, FILENAME_MAX, stdin) != NULL ) {
|
||||
|
||||
int is_dir = 0;
|
||||
if (stripinfo) {
|
||||
fn = strpbrk(buf, "\t ");
|
||||
if ( fn++ == NULL ) continue;
|
||||
@ -114,19 +107,19 @@ int main(int argc, char ** argv) {
|
||||
}
|
||||
|
||||
if ( S_ISDIR(st.st_mode) ) {
|
||||
is_dir = 1;
|
||||
if (!nodircheck && dir_empty(fn) ) {
|
||||
if (debug) fprintf(stderr, "DEBUG: Non-empty dir: %s.\n", fn);
|
||||
if (debug) fprintf(stderr, "DEBUG: Empty dir: %s.\n", fn);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
fn = get_realname(fn);
|
||||
fn = get_realname(fn, is_dir);
|
||||
if (rootdir) {
|
||||
if (! strncmp(rootdir, fn, strlen(rootdir))) {
|
||||
fn += strlen(rootdir);
|
||||
} else {
|
||||
if (debug) fprintf(stderr, "DEBUG: Outside "
|
||||
"root (%s): %s.\n",
|
||||
if (debug) fprintf(stderr, "DEBUG: Outside root (%s): %s.\n",
|
||||
rootdir, fn);
|
||||
continue;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user