ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/crossedit/Cnv/CnvFiles.c
Revision: 1.1.1.1 (vendor branch)
Committed: Fri Feb 3 07:11:45 2006 UTC (18 years, 5 months ago) by root
Content type: text/plain
Branch: UPSTREAM
CVS Tags: UPSTREAM_2006_03_15, LAST_C_VERSION, UPSTREAM_2006_02_22, difficulty_fix_merge_060810_2300, UPSTREAM_2006_02_03
Branch point for: difficulty_fix
Changes since 1.1: +0 -0 lines
Log Message:
initial import

File Contents

# User Rev Content
1 root 1.1 #include <Cnv.h>
2     #include <Posix.h>
3    
4     /**********************************************************************
5     * private
6     **********************************************************************/
7    
8     static void entryCb(Widget w,XtPointer client,XtPointer call)
9     {
10     CnvFiles self = (CnvFiles)client;
11     char path[PATH_MAX+1];
12    
13     /* entry = XawSimpleMenuGetActiveEntry(w); */
14     sprintf(path,"%s/%s",self->directory,XtName(w));
15     (*self->proc)(self->client,path);
16     }
17    
18     static void Malfunction(CnvFiles self,String msg)
19     {
20     char buf[BUFSIZ];
21    
22     sprintf(buf,"%s %s",msg,self->directory);
23     CnvWarn(self->shell,buf);
24     XtVaCreateManagedWidget
25     ("No Data",smeBSBObjectClass,self->shell,
26     NULL);
27     }
28    
29     /**********************************************************************
30     * public
31     **********************************************************************/
32    
33     /*
34     * member :
35     * name : resource-name
36     * app : application level shell-widget
37     * directory: directory to read menu from
38     * proc : callback to be called
39     * client :
40     * return : gives created menu
41     */
42     CnvFiles CnvFilesCreate(String name,
43     Widget parent,
44     CnvFilesProc proc,
45     XtPointer client,
46     String directory)
47     {
48     CnvFiles self;
49    
50     self = (CnvFiles)XtMalloc(sizeof(struct CnvFiles));
51     self->shell = NULL;
52     self->name = XtNewString(name);
53     self->proc = proc;
54     self->client = client;
55     CnvFilesRescan(self,name,parent,directory);
56     return self;
57     }
58    
59     /*
60     * member: remove CnvFiles packege
61     * return: status
62     */
63     void CnvFilesDestroy(CnvFiles self)
64     {
65     XtDestroyWidget(self->shell);
66     XtFree(self->name);
67     self->shell = NULL;
68     }
69    
70     /*
71     * member : make menu from directory
72     * directory: absolute directoryname to scan
73     * return : gives created menu
74     */
75     Widget CnvFilesRescan(CnvFiles self,String name,Widget parent,
76     String directory)
77     {
78     char buf[BUFSIZ];
79     char path[PATH_MAX+1];
80     DIR *dir;
81     #ifdef NeXT
82     struct direct *dirent;
83     #else
84     struct dirent *dirent;
85     #endif
86     struct stat statbuf;
87     Widget entry;
88     int cnt = 0;
89    
90     /*** create shell ***/
91     if(self->shell != NULL) XtDestroyWidget(self->shell);
92     self->shell = XtVaCreatePopupShell
93     (name,simpleMenuWidgetClass,parent,
94     NULL);
95    
96     /*** can read directory ? ***/
97     pathcpy(self->directory,directory);
98     if(access(self->directory,R_OK | X_OK) == -1) {
99     Malfunction(self,"has no access");
100     return NULL;
101     }
102    
103     /*** open dir ***/
104     if((dir = opendir(self->directory)) == NULL) {
105     Malfunction(self,"cannot open");
106     return NULL;
107     }
108    
109     /*** make menu ***/
110     while((dirent = readdir(dir)) != NULL) {
111     if(!strcmp(dirent->d_name,".") || !strcmp(dirent->d_name,".."))
112     continue;
113     sprintf(path,"%s/%s",directory,dirent->d_name);
114     if(stat((char*)path,&statbuf) == -1) {
115     sprintf(buf,"%s cannot stat",path);
116     CnvWarn(self->shell,buf);
117     return NULL;
118     }
119     if( S_ISREG(statbuf.st_mode) && !access(path, R_OK) ) {
120     /*** create menu selection ***/
121     entry = XtVaCreateManagedWidget
122     (dirent->d_name,smeBSBObjectClass,self->shell,
123     NULL);
124     XtAddCallback(entry,XtNcallback,entryCb,(XtPointer)self);
125     cnt++;
126     }
127     }
128     closedir(dir);
129     if(!cnt) {
130     Malfunction(self,"empty");
131     return NULL;
132     }
133     return self->shell;
134     }
135    
136     /*** end of CnvFiles.c ***/
137    
138    
139    
140    
141