2 * --- T2-COPYRIGHT-NOTE-BEGIN ---
3 * This copyright note is auto-generated by ./scripts/Create-CopyPatch.
5 * T2 SDE: misc/tools-source/fl_wrparse.c
6 * Copyright (C) 2004 - 2005 The T2 SDE Project
7 * Copyright (C) 1998 - 2003 ROCK Linux Project
9 * More information can be found in the files COPYING and README.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2 of the License. A copy of the
14 * GNU General Public License can be found in the file COPYING.
15 * --- T2-COPYRIGHT-NOTE-END ---
26 char * get_realname(char * origname
) {
27 static char buf
[FILENAME_MAX
];
28 char *file
, odir
[FILENAME_MAX
];
30 if (! strcmp(origname
, "/")) return "/";
33 if ( (file
=strrchr(buf
,'/')) == NULL
) {
38 file
= origname
+ (file
-buf
);
41 getcwd(odir
, FILENAME_MAX
); chdir(buf
);
42 getcwd(buf
, FILENAME_MAX
); chdir(odir
);
44 if (strcmp(buf
, "/")) strcat(buf
,"/");
50 int dir_empty(char * nam
) {
51 struct dirent
**namelist
; int n
;
52 n
= scandir(nam
, &namelist
, 0, alphasort
);
53 if (n
< 0) perror("scandir");
55 if ( strcmp(namelist
[n
]->d_name
,".") &&
56 strcmp(namelist
[n
]->d_name
,"..") ) return 0;
60 int main(int argc
, char ** argv
) {
61 char *fn
, buf
[FILENAME_MAX
], *n
;
62 char realrootdir
[FILENAME_MAX
];
66 int opt
, nodircheck
= 0;
70 while ( (opt
= getopt(argc
, argv
, "dDr:sp:")) != -1 ) {
89 strcpy(realrootdir
, get_realname(optarg
));
90 rootdir
= realrootdir
;
94 fprintf(stderr
, "Usage: %s [-D] [-r rootdir] [-s] "
95 "[-p pkg]\n", argv
[0]);
100 if ( rootdir
!= NULL
) chdir(rootdir
);
102 while ( fgets(buf
, FILENAME_MAX
, stdin
) != NULL
) {
105 fn
= strpbrk(buf
, "\t ");
106 if ( fn
++ == NULL
) continue;
108 if ( (n
= strchr(fn
, '\n')) != NULL
) *n
= '\0';
109 if ( *fn
== 0 ) continue;
111 if ( lstat(fn
,&st
) ) {
112 if (debug
) fprintf(stderr
, "DEBUG: Can't stat file: %s.\n", fn
);
116 if ( S_ISDIR(st
.st_mode
) ) {
117 if (!nodircheck
&& dir_empty(fn
) ) {
118 if (debug
) fprintf(stderr
, "DEBUG: Non-empty dir: %s.\n", fn
);
123 fn
= get_realname(fn
);
125 if (! strncmp(rootdir
, fn
, strlen(rootdir
))) {
126 fn
+= strlen(rootdir
);
128 if (debug
) fprintf(stderr
, "DEBUG: Outside "
135 if (! package
) printf("%s\n", fn
);
136 else printf("%s: %s\n", package
, fn
);