Skip to Main Content
Volume 7A: XView Programming Manual
book

Volume 7A: XView Programming Manual

by Dan Heller
October 1994
Intermediate to advanced content levelIntermediate to advanced
770 pages
22h 58m
English
O'Reilly Media, Inc.
Content preview from Volume 7A: XView Programming Manual
Example 11-5. The menu_dir.c program (continued)
* recursive, a new menu is created for each subdirectory under the
* original path.
*/
Menu_item
add_path_to_menu(path)
char *path;
{
DIR *dirp;
struct direct *dp;
struct stat s_buf;
Menu_item mi;
Menu next_menu;
char buf[MAXPATHLEN];
/* don’t add a folder to the list if user can’t read it */
if (stat(path, &s_buf) == -1 || !(s_buf.st_mode & S_IREAD))
return NULL;
if (s_buf.st_mode & S_IFDIR) {
int cnt = 0;
if (!(dirp = opendir(path)))
/* don’t bother adding to list if we can’t scan it */
return NULL;
next_menu = (Menu)xv_create(XV_NULL, MENU, NULL);
while (dp = readdir(dirp))
if (strcmp(dp->d_name, ".") && strcmp(dp->d_name, "..")) {
(void) sprintf(buf, "%s/%s", path, dp–>d_name);
if (!(mi = add_path_to_menu(buf)))
/* unreadable file or dir - deactivate item */
mi = xv_create(XV_NULL, MENUITEM,
MENU_STRING, getfilename(dp->d_name),
MENU_RELEASE,
MENU_RELEASE_IMAGE,
MENU_INACTIVE, TRUE,
NULL);
xv_set(next_menu, MENU_APPEND_ITEM, mi, NULL);
cnt++;
}
closedir(dirp);
mi = xv_create(XV_NULL, MENUITEM,
MENU_STRING, getfilename(path),
MENU_RELEASE,
MENU_RELEASE_IMAGE,
MENU_NOTIFY_PROC, my_action_proc,
NULL);
if (!cnt) {
xv_destroy(next_menu);
/* An empty or unsearchable directory - deactivate item */
xv_set(mi, MENU_INACTIVE, TRUE, NULL);
} else {
xv_set(next_menu, MENU_TITLE_ITEM, getfilename(path), NULL);
xv_set(mi, MENU_PULLRIGHT, next_menu, NULL);
}
return mi;
}
return (Menu_item)x
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Volume 6A: Motif Programming Manual

Volume 6A: Motif Programming Manual

David Brennan, Dan Heller, Paula Ferguson
Java™ Media APIs: Cross-Platform Imaging, Media, and Visualization

Java™ Media APIs: Cross-Platform Imaging, Media, and Visualization

Alejandro Terrazas, John Ostuni, Michael Barlow

Publisher Resources

ISBN: 9780937175873