1 /* $Header: /cvsroot/lesstif/lesstif/test/Xm/filesb/test14.c,v 1.4 2001/06/15 09:17:36 amai Exp $ */
2 
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <unistd.h>
6 #include <sys/types.h>
7 #include <pwd.h>
8 
9 #include <Xm/XmosP.h>
10 
11 
12 static int ExitStatus = 0;
13 
14 static void
DoTest(String dir,String filter,String e_dir,String e_filter)15 DoTest(String dir, String filter, String e_dir, String e_filter)
16 {
17     String pd, pf;
18 
19     _XmOSQualifyFileSpec(dir, filter, &pd, &pf);
20     if (strcmp(pd, e_dir) != 0 || strcmp(pf, e_filter) != 0)
21     {
22     	ExitStatus = 1;
23     }
24     printf("%s %s %s %s %s %s %s\n",
25     	pd, strcmp(pd, e_dir) == 0 ? "==" : "!=", e_dir,
26     	pf, strcmp(pf, e_filter) == 0 ? "==" : "!=", e_filter,
27     	strcmp(pd, e_dir) == 0 && strcmp(pf, e_filter) == 0 ? "okay" : "fail");
28     XtFree(pd);
29     XtFree(pf);
30 }
31 
32 
33 int
main(int argc,char * argv[])34 main(int argc, char *argv[])
35 {
36       String d, f;
37       String pd, pf;
38       String cwd;
39       struct passwd *root_pw, *user_pw;
40       String root_dir, root_dir1, user_dir, user_name;
41 
42 	cwd = getcwd(NULL, 2048);
43 	cwd = XtRealloc(cwd, strlen(cwd) + 2);
44 	strcat(cwd, "/");
45 
46 	root_pw = getpwnam("root");
47 	root_dir = XtMalloc(strlen(root_pw->pw_dir) + 2);
48 	strcpy(root_dir, root_pw->pw_dir);
49 	strcat(root_dir, "/");
50 	root_dir1 = XtMalloc(strlen(root_pw->pw_dir) + 6);
51 	strcpy(root_dir1, root_pw->pw_dir);
52 	strcat(root_dir1, "/tmp/");
53 
54 	user_pw = getpwuid(getuid());
55 	user_dir = XtMalloc(strlen(user_pw->pw_dir) + 2);
56 	strcpy(user_dir, user_pw->pw_dir);
57 	strcat(user_dir, "/");
58 	user_name = XtMalloc(strlen(user_pw->pw_name) + 2);
59 	strcpy(user_name, "~");
60 	strcat(user_name, user_pw->pw_name);
61 
62 	DoTest(NULL, NULL, cwd, "*");
63 	DoTest("", "", cwd, "*");
64 	DoTest("~", "*", user_dir, "*");
65 	DoTest(user_name, "*", user_dir, "*");
66 	DoTest("~root", "*", root_dir, "*");
67 	DoTest("~unknown_user", "*", "/", "*");
68 	DoTest("/", "*", "/", "*");
69 	DoTest("~root/tmp", "*", root_dir1, "*");
70 	exit(ExitStatus);
71 }
72