Fix exit/return behavior in the id3 info screen.Fixes returning immediately on touchs...
[maemo-rb.git] / apps / filetree.c
blob59e7343600dd8c85c670471e8412eb1b7598598d
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 by Björn Stenberg
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include <stdlib.h>
22 #include <file.h>
23 #include <dir.h>
24 #include <string.h>
25 #include <kernel.h>
26 #include <lcd.h>
27 #include <debug.h>
28 #include <font.h>
29 #include <limits.h>
30 #include "bookmark.h"
31 #include "tree.h"
32 #include "core_alloc.h"
33 #include "settings.h"
34 #include "filetypes.h"
35 #include "talk.h"
36 #include "playlist.h"
37 #include "lang.h"
38 #include "language.h"
39 #include "screens.h"
40 #include "plugin.h"
41 #include "rolo.h"
42 #include "splash.h"
43 #include "cuesheet.h"
44 #include "filetree.h"
45 #include "misc.h"
46 #include "strnatcmp.h"
47 #include "playlist_viewer.h"
48 #ifdef HAVE_LCD_BITMAP
49 #include "keyboard.h"
50 #endif
52 #if CONFIG_TUNER
53 #include "radio.h"
54 #endif
55 #include "wps.h"
57 static int compare_sort_dir; /* qsort key for sorting directories */
59 int ft_build_playlist(struct tree_context* c, int start_index)
61 int i;
62 int start=start_index;
64 tree_lock_cache(c);
65 struct entry *entries = tree_get_entries(c);
67 for(i = 0;i < c->filesindir;i++)
69 if((entries[i].attr & FILE_ATTR_MASK) == FILE_ATTR_AUDIO)
71 if (playlist_add(entries[i].name) < 0)
72 break;
74 else
76 /* Adjust the start index when se skip non-MP3 entries */
77 if(i < start)
78 start_index--;
82 tree_unlock_cache(c);
84 return start_index;
87 /* Start playback of a playlist, checking for bookmark autoload, modified
88 * playlists, etc., as required. Returns false if playback wasn't started,
89 * or started via bookmark autoload, true otherwise.
91 * Pointers to both the full pathname and the separated parts needed to
92 * avoid allocating yet another path buffer on the stack (and save some
93 * code; the caller typically needs to create the full pathname anyway)...
95 bool ft_play_playlist(char* pathname, char* dirname, char* filename)
97 if (global_settings.party_mode && audio_status())
99 splash(HZ, ID2P(LANG_PARTY_MODE));
100 return false;
103 if (bookmark_autoload(pathname))
105 return false;
108 splash(0, ID2P(LANG_WAIT));
110 /* about to create a new current playlist...
111 allow user to cancel the operation */
112 if (!warn_on_pl_erase())
113 return false;
115 if (playlist_create(dirname, filename) != -1)
117 if (global_settings.playlist_shuffle)
119 playlist_shuffle(current_tick, -1);
122 playlist_start(0, 0);
123 return true;
126 return false;
129 /* walk a directory and check all entries if a .talk file exists */
130 static void check_file_thumbnails(struct tree_context* c)
132 int i;
133 struct dirent *entry;
134 struct entry* entries;
135 DIR *dir;
137 dir = opendir(c->currdir);
138 if(!dir)
139 return;
140 /* mark all files as non talking, except the .talk ones */
141 entries = tree_get_entries(c);
142 tree_lock_cache(c);
143 for (i=0; i < c->filesindir; i++)
145 if (entries[i].attr & ATTR_DIRECTORY)
146 continue; /* we're not touching directories */
148 if (strcasecmp(file_thumbnail_ext,
149 &entries[i].name[strlen(entries[i].name)
150 - strlen(file_thumbnail_ext)]))
151 { /* no .talk file */
152 entries[i].attr &= ~FILE_ATTR_THUMBNAIL; /* clear */
154 else
155 { /* .talk file, we later let them speak themselves */
156 entries[i].attr |= FILE_ATTR_THUMBNAIL; /* set */
160 while((entry = readdir(dir)) != 0) /* walk directory */
162 int ext_pos;
163 struct dirinfo info = dir_get_info(dir, entry);
164 ext_pos = strlen((char *)entry->d_name) - strlen(file_thumbnail_ext);
165 if (ext_pos <= 0 /* too short to carry ".talk" */
166 || (info.attribute & ATTR_DIRECTORY) /* no file */
167 || strcasecmp((char *)&entry->d_name[ext_pos], file_thumbnail_ext))
168 { /* or doesn't end with ".talk", no candidate */
169 continue;
172 /* terminate the (disposable) name in dir buffer,
173 this truncates off the ".talk" without needing an extra buffer */
174 entry->d_name[ext_pos] = '\0';
176 /* search corresponding file in dir cache */
177 for (i=0; i < c->filesindir; i++)
179 if (!strcasecmp(entries[i].name, (char *)entry->d_name))
180 { /* match */
181 entries[i].attr |= FILE_ATTR_THUMBNAIL; /* set the flag */
182 break; /* exit search loop, because we found it */
186 tree_unlock_cache(c);
187 closedir(dir);
190 /* support function for qsort() */
191 static int compare(const void* p1, const void* p2)
193 struct entry* e1 = (struct entry*)p1;
194 struct entry* e2 = (struct entry*)p2;
195 int criteria;
197 if (e1->attr & ATTR_DIRECTORY && e2->attr & ATTR_DIRECTORY)
198 { /* two directories */
199 criteria = compare_sort_dir;
201 #ifdef HAVE_MULTIVOLUME
202 if (e1->attr & ATTR_VOLUME || e2->attr & ATTR_VOLUME)
203 { /* a volume identifier is involved */
204 if (e1->attr & ATTR_VOLUME && e2->attr & ATTR_VOLUME)
205 criteria = SORT_ALPHA; /* two volumes: sort alphabetically */
206 else /* only one is a volume: volume first */
207 return (e2->attr & ATTR_VOLUME) - (e1->attr & ATTR_VOLUME);
209 #endif
212 else if (!(e1->attr & ATTR_DIRECTORY) && !(e2->attr & ATTR_DIRECTORY))
213 { /* two files */
214 criteria = global_settings.sort_file;
216 else /* dir and file, dir goes first */
217 return (e2->attr & ATTR_DIRECTORY) - (e1->attr & ATTR_DIRECTORY);
219 switch(criteria)
221 case SORT_TYPE:
222 case SORT_TYPE_REVERSED:
224 int t1 = e1->attr & FILE_ATTR_MASK;
225 int t2 = e2->attr & FILE_ATTR_MASK;
227 if (!t1) /* unknown type */
228 t1 = INT_MAX; /* gets a high number, to sort after known */
229 if (!t2) /* unknown type */
230 t2 = INT_MAX; /* gets a high number, to sort after known */
232 if (t1 != t2) /* if different */
233 return (t1 - t2) * (criteria == SORT_TYPE_REVERSED ? -1 : 1);
234 /* else fall through to alphabetical sorting */
237 case SORT_DATE:
238 case SORT_DATE_REVERSED:
239 /* Ignore SORT_TYPE */
240 if (criteria == SORT_DATE || criteria == SORT_DATE_REVERSED)
242 if (e1->time_write != e2->time_write)
243 return (e1->time_write - e2->time_write)
244 * (criteria == SORT_DATE_REVERSED ? -1 : 1);
245 /* else fall through to alphabetical sorting */
248 case SORT_ALPHA:
249 case SORT_ALPHA_REVERSED:
251 if (global_settings.sort_case)
253 if (global_settings.interpret_numbers == SORT_INTERPRET_AS_NUMBER)
254 return strnatcmp(e1->name, e2->name)
255 * (criteria == SORT_ALPHA_REVERSED ? -1 : 1);
256 else
257 return strncmp(e1->name, e2->name, MAX_PATH)
258 * (criteria == SORT_ALPHA_REVERSED ? -1 : 1);
260 else
262 if (global_settings.interpret_numbers == SORT_INTERPRET_AS_NUMBER)
263 return strnatcasecmp(e1->name, e2->name)
264 * (criteria == SORT_ALPHA_REVERSED ? -1 : 1);
265 else
266 return strncasecmp(e1->name, e2->name, MAX_PATH)
267 * (criteria == SORT_ALPHA_REVERSED ? -1 : 1);
272 return 0; /* never reached */
275 /* load and sort directory into the tree's cache. returns NULL on failure. */
276 int ft_load(struct tree_context* c, const char* tempdir)
278 int files_in_dir = 0;
279 int name_buffer_used = 0;
280 struct dirent *entry;
281 bool (*callback_show_item)(char *, int, struct tree_context *) = NULL;
282 DIR *dir;
284 if (tempdir)
285 dir = opendir(tempdir);
286 else
288 dir = opendir(c->currdir);
289 callback_show_item = c->browse? c->browse->callback_show_item: NULL;
291 if(!dir)
292 return -1; /* not a directory */
294 c->dirsindir = 0;
295 c->dirfull = false;
297 tree_lock_cache(c);
298 while ((entry = readdir(dir))) {
299 int len;
300 struct dirinfo info;
301 struct entry* dptr = tree_get_entry_at(c, files_in_dir);
302 if (!entry)
303 break;
305 info = dir_get_info(dir, entry);
306 len = strlen((char *)entry->d_name);
308 /* skip directories . and .. */
309 if ((info.attribute & ATTR_DIRECTORY) &&
310 (((len == 1) && (!strncmp((char *)entry->d_name, ".", 1))) ||
311 ((len == 2) && (!strncmp((char *)entry->d_name, "..", 2))))) {
312 continue;
315 /* Skip FAT volume ID */
316 if (info.attribute & ATTR_VOLUME_ID) {
317 continue;
320 /* filter out dotfiles and hidden files */
321 if (*c->dirfilter != SHOW_ALL &&
322 ((entry->d_name[0]=='.') ||
323 (info.attribute & ATTR_HIDDEN))) {
324 continue;
327 dptr->attr = info.attribute;
329 /* check for known file types */
330 if ( !(dptr->attr & ATTR_DIRECTORY) )
331 dptr->attr |= filetype_get_attr((char *)entry->d_name);
333 /* filter out non-visible files */
334 if ((!(dptr->attr & ATTR_DIRECTORY) && (
335 (*c->dirfilter == SHOW_PLAYLIST &&
336 (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_M3U) ||
337 ((*c->dirfilter == SHOW_MUSIC &&
338 (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_AUDIO) &&
339 (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_M3U) ||
340 (*c->dirfilter == SHOW_SUPPORTED && !filetype_supported(dptr->attr)))) ||
341 (*c->dirfilter == SHOW_WPS && (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_WPS) ||
342 #ifdef HAVE_LCD_BITMAP
343 (*c->dirfilter == SHOW_FONT && (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_FONT) ||
344 (*c->dirfilter == SHOW_SBS && (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_SBS) ||
345 #if CONFIG_TUNER
346 (*c->dirfilter == SHOW_FMS && (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_FMS) ||
347 #endif
348 #endif
349 #ifdef HAVE_REMOTE_LCD
350 (*c->dirfilter == SHOW_RWPS && (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_RWPS) ||
351 (*c->dirfilter == SHOW_RSBS && (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_RSBS) ||
352 #if CONFIG_TUNER
353 (*c->dirfilter == SHOW_RFMS && (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_RFMS) ||
354 #endif
355 #endif
356 #if CONFIG_TUNER
357 (*c->dirfilter == SHOW_FMR && (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_FMR) ||
358 #endif
359 (*c->dirfilter == SHOW_M3U && (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_M3U) ||
360 (*c->dirfilter == SHOW_CFG && (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_CFG) ||
361 (*c->dirfilter == SHOW_LNG && (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_LNG) ||
362 (*c->dirfilter == SHOW_MOD && (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_MOD) ||
363 (*c->dirfilter == SHOW_PLUGINS && (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_ROCK &&
364 (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_LUA) ||
365 (callback_show_item && !callback_show_item(entry->d_name, dptr->attr, c)))
367 continue;
370 if ((len > c->cache.name_buffer_size - name_buffer_used - 1) ||
371 (files_in_dir >= c->cache.max_entries)) {
372 /* Tell the world that we ran out of buffer space */
373 c->dirfull = true;
374 break;
377 ++files_in_dir;
379 dptr->name = core_get_data(c->cache.name_buffer_handle)+name_buffer_used;
380 dptr->time_write =
381 (long)info.wrtdate<<16 |
382 (long)info.wrttime; /* in one # */
383 strcpy(dptr->name, (char *)entry->d_name);
384 name_buffer_used += len + 1;
386 if (dptr->attr & ATTR_DIRECTORY) /* count the remaining dirs */
387 c->dirsindir++;
389 c->filesindir = files_in_dir;
390 c->dirlength = files_in_dir;
391 closedir(dir);
393 compare_sort_dir = c->sort_dir;
394 qsort(tree_get_entries(c), files_in_dir, sizeof(struct entry), compare);
396 /* If thumbnail talking is enabled, make an extra run to mark files with
397 associated thumbnails, so we don't do unsuccessful spinups later. */
398 if (global_settings.talk_file_clip)
399 check_file_thumbnails(c); /* map .talk to ours */
401 tree_unlock_cache(c);
402 return 0;
404 #ifdef HAVE_LCD_BITMAP
405 static void ft_load_font(char *file)
407 int current_font_id;
408 enum screen_type screen = SCREEN_MAIN;
409 #if NB_SCREENS > 1
410 MENUITEM_STRINGLIST(menu, ID2P(LANG_CUSTOM_FONT), NULL,
411 ID2P(LANG_MAIN_SCREEN), ID2P(LANG_REMOTE_SCREEN))
412 switch (do_menu(&menu, NULL, NULL, false))
414 case 0: /* main lcd */
415 screen = SCREEN_MAIN;
416 set_file(file, (char *)global_settings.font_file, MAX_FILENAME);
417 break;
418 case 1: /* remote */
419 screen = SCREEN_REMOTE;
420 set_file(file, (char *)global_settings.remote_font_file, MAX_FILENAME);
421 break;
423 #else
424 set_file(file, (char *)global_settings.font_file, MAX_FILENAME);
425 #endif
426 splash(0, ID2P(LANG_WAIT));
427 current_font_id = global_status.font_id[screen];
428 if (current_font_id >= 0)
429 font_unload(current_font_id);
430 global_status.font_id[screen] = font_load(file);
431 viewportmanager_theme_changed(THEME_UI_VIEWPORT);
433 #endif
435 int ft_enter(struct tree_context* c)
437 int rc = GO_TO_PREVIOUS;
438 char buf[MAX_PATH];
439 struct entry* file = tree_get_entry_at(c, c->selected_item);
440 int file_attr = file->attr;
442 if (c->currdir[1])
443 snprintf(buf,sizeof(buf),"%s/%s",c->currdir, file->name);
444 else
445 snprintf(buf,sizeof(buf),"/%s",file->name);
447 if (file_attr & ATTR_DIRECTORY) {
448 memcpy(c->currdir, buf, sizeof(c->currdir));
449 if ( c->dirlevel < MAX_DIR_LEVELS )
450 c->selected_item_history[c->dirlevel] = c->selected_item;
451 c->dirlevel++;
452 c->selected_item=0;
454 else {
455 int seed = current_tick;
456 bool play = false;
457 int start_index=0;
459 switch ( file_attr & FILE_ATTR_MASK ) {
460 case FILE_ATTR_M3U:
461 if (!bookmark_autoload(buf))
462 playlist_viewer_ex(buf);
463 break;
465 case FILE_ATTR_AUDIO:
466 if (bookmark_autoload(c->currdir))
467 break;
469 splash(0, ID2P(LANG_WAIT));
471 /* about to create a new current playlist...
472 allow user to cancel the operation */
473 if (!warn_on_pl_erase())
474 break;
476 if (global_settings.party_mode && audio_status())
478 playlist_insert_track(NULL, buf,
479 PLAYLIST_INSERT_LAST, true, true);
480 splash(HZ, ID2P(LANG_QUEUE_LAST));
482 else if (playlist_create(c->currdir, NULL) != -1)
484 start_index = ft_build_playlist(c, c->selected_item);
485 if (global_settings.playlist_shuffle)
487 start_index = playlist_shuffle(seed, start_index);
489 /* when shuffling dir.: play all files
490 even if the file selected by user is
491 not the first one */
492 if (!global_settings.play_selected)
493 start_index = 0;
496 playlist_start(start_index, 0);
497 play = true;
499 break;
501 #if CONFIG_TUNER
502 /* fmr preset file */
503 case FILE_ATTR_FMR:
504 splash(0, ID2P(LANG_WAIT));
506 /* Preset inside the default folder. */
507 if(!strncasecmp(FMPRESET_PATH, buf, strlen(FMPRESET_PATH)))
509 set_file(buf, global_settings.fmr_file, MAX_FILENAME);
510 radio_load_presets(global_settings.fmr_file);
513 * Preset outside default folder, we can choose such only
514 * if we are out of the radio screen, so the check for the
515 * radio status isn't neccessary
517 else
519 radio_load_presets(buf);
521 rc = GO_TO_FM;
523 break;
524 case FILE_ATTR_FMS:
525 splash(0, ID2P(LANG_WAIT));
526 set_file(buf, (char *)global_settings.fms_file, MAX_FILENAME);
527 settings_apply_skins();
528 break;
529 #ifdef HAVE_REMOTE_LCD
530 case FILE_ATTR_RFMS:
531 splash(0, ID2P(LANG_WAIT));
532 set_file(buf, (char *)global_settings.rfms_file, MAX_FILENAME);
533 settings_apply_skins();
534 break;
535 #endif
536 #endif
538 #ifdef HAVE_LCD_BITMAP
539 case FILE_ATTR_SBS:
540 splash(0, ID2P(LANG_WAIT));
541 set_file(buf, (char *)global_settings.sbs_file, MAX_FILENAME);
542 settings_apply_skins();
543 break;
544 #endif
545 #ifdef HAVE_REMOTE_LCD
546 case FILE_ATTR_RSBS:
547 splash(0, ID2P(LANG_WAIT));
548 set_file(buf, (char *)global_settings.rsbs_file, MAX_FILENAME);
549 settings_apply_skins();
550 break;
551 #endif
552 /* wps config file */
553 case FILE_ATTR_WPS:
554 splash(0, ID2P(LANG_WAIT));
555 set_file(buf, (char *)global_settings.wps_file,
556 MAX_FILENAME);
557 settings_apply_skins();
558 break;
560 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
561 /* remote-wps config file */
562 case FILE_ATTR_RWPS:
563 splash(0, ID2P(LANG_WAIT));
564 set_file(buf, (char *)global_settings.rwps_file,
565 MAX_FILENAME);
566 settings_apply_skins();
567 break;
568 #endif
570 case FILE_ATTR_CFG:
571 splash(0, ID2P(LANG_WAIT));
572 if (!settings_load_config(buf,true))
573 break;
574 splash(HZ, ID2P(LANG_SETTINGS_LOADED));
575 break;
577 case FILE_ATTR_BMARK:
578 splash(0, ID2P(LANG_WAIT));
579 bookmark_load(buf, false);
580 rc = GO_TO_FILEBROWSER;
581 break;
583 case FILE_ATTR_LNG:
584 splash(0, ID2P(LANG_WAIT));
585 if (lang_core_load(buf))
587 splash(HZ, ID2P(LANG_FAILED));
588 break;
590 set_file(buf, (char *)global_settings.lang_file,
591 MAX_FILENAME);
592 talk_init(); /* use voice of same language */
593 viewportmanager_theme_changed(THEME_LANGUAGE);
594 settings_apply_skins();
595 splash(HZ, ID2P(LANG_LANGUAGE_LOADED));
596 break;
598 #ifdef HAVE_LCD_BITMAP
599 case FILE_ATTR_FONT:
600 ft_load_font(buf);
601 break;
603 case FILE_ATTR_KBD:
604 splash(0, ID2P(LANG_WAIT));
605 if (!load_kbd(buf))
606 splash(HZ, ID2P(LANG_KEYBOARD_LOADED));
607 set_file(buf, (char *)global_settings.kbd_file, MAX_FILENAME);
608 break;
609 #endif
611 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
612 /* firmware file */
613 case FILE_ATTR_MOD:
614 splash(0, ID2P(LANG_WAIT));
615 audio_hard_stop();
616 rolo_load(buf);
617 break;
618 #endif
620 /* plugin file */
621 case FILE_ATTR_ROCK:
622 case FILE_ATTR_LUA:
624 char *plugin = buf, *argument = NULL, lua_path[MAX_PATH];
625 int ret;
627 if ((file_attr & FILE_ATTR_MASK) == FILE_ATTR_LUA) {
628 snprintf(lua_path, sizeof(lua_path)-1, "%s/lua.rock", VIEWERS_DIR); /* Use a #define here ? */
629 plugin = lua_path;
630 argument = buf;
633 if (global_settings.party_mode && audio_status()) {
634 splash(HZ, ID2P(LANG_PARTY_MODE));
635 break;
637 ret = plugin_load(plugin, argument);
638 switch (ret)
640 case PLUGIN_GOTO_WPS:
641 play = true;
642 break;
643 case PLUGIN_USB_CONNECTED:
644 if(*c->dirfilter > NUM_FILTER_MODES)
645 /* leave sub-browsers after usb, doing
646 otherwise might be confusing to the user */
647 rc = GO_TO_ROOT;
648 else
649 rc = GO_TO_FILEBROWSER;
650 break;
652 case PLUGIN_ERROR:
653 case PLUGIN_OK:
655 default:
656 break;
658 break;
660 case FILE_ATTR_CUE:
661 display_cuesheet_content(buf);
662 break;
664 default:
666 const char* plugin;
668 if (global_settings.party_mode && audio_status()) {
669 splash(HZ, ID2P(LANG_PARTY_MODE));
670 break;
673 struct entry* file = tree_get_entry_at(c, c->selected_item);
674 plugin = filetype_get_plugin(file);
675 if (plugin)
677 switch (plugin_load(plugin,buf))
679 case PLUGIN_USB_CONNECTED:
680 rc = GO_TO_FILEBROWSER;
681 break;
682 case PLUGIN_GOTO_WPS:
683 rc = GO_TO_WPS;
684 break;
686 case PLUGIN_OK:
687 case PLUGIN_ERROR:
689 default:
690 break;
693 break;
697 if ( play ) {
698 /* the resume_index must always be the index in the
699 shuffled list in case shuffle is enabled */
700 global_status.resume_index = start_index;
701 global_status.resume_offset = 0;
702 status_save();
703 rc = GO_TO_WPS;
705 else {
706 if (*c->dirfilter > NUM_FILTER_MODES &&
707 *c->dirfilter != SHOW_CFG &&
708 *c->dirfilter != SHOW_FONT &&
709 *c->dirfilter != SHOW_PLUGINS)
711 rc = GO_TO_ROOT;
715 return rc;
718 int ft_exit(struct tree_context* c)
720 extern char lastfile[]; /* from tree.c */
721 char buf[MAX_PATH];
722 int rc = 0;
723 bool exit_func = false;
725 int i = strlen(c->currdir);
726 if (i>1) {
727 while (c->currdir[i-1]!='/')
728 i--;
729 strcpy(buf,&c->currdir[i]);
730 if (i==1)
731 c->currdir[i]=0;
732 else
733 c->currdir[i-1]=0;
735 if (*c->dirfilter > NUM_FILTER_MODES && c->dirlevel < 1)
736 exit_func = true;
738 c->dirlevel--;
739 if ( c->dirlevel < MAX_DIR_LEVELS )
740 c->selected_item=c->selected_item_history[c->dirlevel];
741 else
742 c->selected_item=0;
744 /* if undefined position */
745 if (c->selected_item == -1)
746 strcpy(lastfile, buf);
748 else
750 if (*c->dirfilter > NUM_FILTER_MODES && c->dirlevel < 1)
751 exit_func = true;
754 if (exit_func)
755 rc = 3;
757 return rc;