Beispiel #1
0
static void start_mp3_playback(char *filename)
{
	FILE *file;
	int ret;

	ret = dsp_open(&dspz, DSP_LINEOUT);
	if (ret < 0) {
		pz_perror("/dev/dsp");
		pz_close_window(mp3_wid);
		return;
	}

	do {
		pz_draw_header(_("Buffering..."));
		total_time = remaining_time = next_song_time;
		mp3_do_draw(0);

		file = fopen(filename, "r");
		if (file == 0) {
			pz_close_window(mp3_wid);
			pz_perror(filename);
			dsp_close(&dspz);
			return;
		}

		fseek(file, 0, SEEK_END);
		audiobuf_len = ftell(file);
		audiobufpos = 0;
		audiobuf = malloc(audiobuf_len);
		if (audiobuf == 0) {
			pz_close_window(mp3_wid);
			dsp_close(&dspz);
			fclose(file);

			new_message_window(_("malloc failed"));
			return;
		}

		fseek(file, 0, SEEK_SET);
		fread(audiobuf, audiobuf_len, 1, file);
		fclose(file);

		pz_draw_header(_("MP3 Playback"));

		decode_mp3();

		free(audiobuf);

		filename = next_song;
	}
	while (next_song_queued);

	dsp_close(&dspz);
	pz_close_window(mp3_wid);
}
Beispiel #2
0
TWindow *pz_new_textview_window(char *filename)
{
	TWindow *ret;
	char *buf = NULL;
	char tmp[4096];
	FILE *fp;
	long len, cs;

	if ((fp = fopen(filename, "r")) == NULL) {
		pz_perror(filename);
		return TTK_MENU_DONOTHING;
	}
	fseek(fp, 0L, SEEK_END);
	len = ftell(fp);
	rewind(fp);
	if (len == 0) {
		cs = 0;
		while (fgets(tmp, 4096, fp) != NULL) {
			len = buf ? strlen(buf) : 0;
			if (len + (long)strlen(tmp) > cs) {
				cs += 8192;
				if ((buf = realloc(buf, cs)) == NULL) {
					pz_error(_("Memory allocation failed"));
					fclose(fp);
					return TTK_MENU_DONOTHING;
				}
			}
			strncpy(buf + len, tmp, cs - len);
		}
		if (buf == NULL) {
			pz_message(_("Empty file"));
			fclose(fp);
			return TTK_MENU_DONOTHING;
		}
	}
	else {
		cs = len;
		if ((buf = malloc(len + 1)) == NULL) {
			pz_error(_("Memory allocation failed"));
			fclose(fp);
			return TTK_MENU_DONOTHING;
		}
		while (cs > 0) cs -= fread(buf + (len - cs), 1, cs, fp);
		*(buf + len) = '\0'; 
	}
	fclose(fp);

	ret = ttk_new_window();
	ret->data = 0x12345678;
	ttk_add_widget(ret, ttk_new_textarea_widget(ret->w, ret->h, buf,
				ttk_textfont, ttk_text_height(ttk_textfont)+2));
	ttk_window_title(ret, strrchr(filename, '/')?
			strrchr(filename, '/') + 1:filename);
	free(buf); /* strdup'd in textarea */
	return ret;
}
static void browser_rename_callback()
{
	if (text_get_buffer()[0] != 0) {
		if ( rename(browser_rename_oldname, text_get_buffer()) == -1 ) {
			pz_perror(current_file);
		} else {
			browser_mscandir("./");
		}
	}
}
Beispiel #4
0
static TWindow *browser_bg_exec (ttk_menu_item *item)
{
	setup_sigchld_handler();
	switch (vfork()) {
	case 0:
		execl("/bin/sh", "sh", "-c", (char *)item->data, NULL);
		pz_perror("execl");
		_exit(0);
	default: break;
	}
	return TTK_MENU_UPONE;
}
Beispiel #5
0
static TWindow *browser_do_delete (ttk_menu_item *item) 
{
#define PATHSIZ 512
	struct stat st;
	const char *filename = item->data;
	if (stat (filename, &st) < 0) {
		pz_perror (filename);
		return TTK_MENU_UPONE;
	}
	if (S_ISDIR (st.st_mode)) {
		/* we change the current directory here in order to find the
		 * absolute path of the specified directory with getcwd. this
		 * removes the need to check for references to the parent
		 * directory or follow along a path until we find the end
		 * result. in addition, opening the current directory and using
		 * its file descriptor to return to it is faster than storing
		 * its path */
		if (filename[0]) {
			int fd;
			char full_path[PATHSIZ];
			if ((fd = open(".", O_RDONLY)) == -1)
				return TTK_MENU_UPONE;
			chdir(filename);
			getcwd(full_path, PATHSIZ);
			fchdir(fd);
			close(fd);
			if (full_path[0] && full_path[1] &&
					strchr(full_path + 2, '/'))
				rm_rf (filename); // not "" or "/" or a root dir
			else
				pz_error (_("Dangerous rm -rf aborted.\n"));
		}
	} else {
		unlink (filename);
	}
	
	/* hide the top two windows */
	if (ttk_hide_window (ttk_windows->w) != -1 &&
			ttk_hide_window (ttk_windows->w) != -1) {
		/* -ttk_windows->w->widgets->v- is the top window's menu */
		ttk_menu_remove_by_ptr(ttk_windows->w->widgets->v,
			ttk_menu_get_selected_item(ttk_windows->w->widgets->v));
	} else {
		pz_error("Unable to close windows");
	}
	return TTK_MENU_DONOTHING; /* we are now back at the directory */
}
static void browser_delete_file()
{
	struct stat stat_result;

	browser_menu_overlay = browser_menu;
	stat(current_file, &stat_result);
	if(S_ISDIR(stat_result.st_mode)) {
		browser_rmdir(current_file);
	}
	else if(unlink(current_file) == -1) {
		pz_perror(current_file);
		return;
	}
	
	while(browser_menu_overlay->parent != NULL)
		browser_menu_overlay = menu_destroy(browser_menu_overlay);
	menu_delete_item(browser_menu_overlay, browser_menu_overlay->sel);
}
Beispiel #7
0
static TWindow *browser_pipe_exec (ttk_menu_item *item)
{
	int len;
	char *buf = '\0';
	char *execline = item->data;
	char st_buf[512];
	FILE *fp;
	
	if((fp = popen(execline, "r")) == NULL) {
		pz_perror(execline);
		return TTK_MENU_UPONE;
	}
	len = 0;
	while(fgets(st_buf, 512, fp) != NULL) {
		buf = (char *)realloc(buf, ((buf == '\0' ? 0 : strlen(buf)) +
				512) * sizeof(char));
		if(buf == NULL) {
			pz_error(_("malloc failed"));
			return TTK_MENU_UPONE;
		}
		if(len == 0) {
			strncpy(buf, st_buf, 512);
			len = 1;
		}
		else 
			strncat(buf, st_buf, 512);
	}
	pclose(fp);
	TWindow *ret;
	if(buf=='\0') {
		pz_message (_("No output."));
		ret = TTK_MENU_DONOTHING;
	} else {
		ttk_show_window (pz_create_stringview(buf, _("Pipe Output")));
		ret = TTK_MENU_REPLACE;
	}
	free(buf);
	return ret;
}
static void browser_pipe_exec()
{
	int len;
	char *buf = '\0';
	char *execline;
	char st_buf[512];
	FILE *fp;
	
	len = strlen(current_dir) + strlen(current_file) + 2;
	execline = (char *)malloc(len * sizeof(char));
	snprintf(execline, len, "%s/%s", current_dir, current_file);

	if((fp = popen(execline, "r")) == NULL) {
		pz_perror(execline);
		return;
	}
	len = 0;
	while(fgets(st_buf, 512, fp) != NULL) {
		buf = (char *)realloc(buf, ((buf == '\0' ? 0 : strlen(buf)) +
				512) * sizeof(char));
		if(buf == NULL) {
			pz_error(_("malloc failed"));
			return;
		}
		if(len == 0) {
			strncpy(buf, st_buf, 512);
			len = 1;
		}
		else 
			strncat(buf, st_buf, 512);
	}
	pclose(fp);
	if(buf=='\0')
		new_message_window("No Output");
	else
		new_stringview_window(buf, _("Pipe Output"));
	free(execline);
	free(buf);
}
Beispiel #9
0
/* the entry point for the menu system */
void new_dialer_window()
{
    int ret = 0;

#ifdef __linux__
    ret = dsp_open(&dspz, DSP_LINEOUT);
#endif
    if (ret < 0) {
        pz_perror("/dev/dsp");
        return;
    }
#ifdef __linux__
    ret = dsp_setup(&dspz, 1, 44100);
#endif

    dialer_gc = pz_get_gc(1);
    GrSetGCUseBackground(dialer_gc, GR_FALSE);
    GrSetGCForeground(dialer_gc, GR_RGB(0,0,0));

    if (screen_info.cols < 160) { //mini
        cxgap = 3;
        cygap = 2;
        cbw = 22;
        cbh = 15;
    }

    dialer_wid = pz_new_window(0, HEADER_TOPLINE + 1,
                               screen_info.cols,
                               screen_info.rows - (HEADER_TOPLINE + 1),
                               dialer_do_draw, dialer_do_keystroke);

    GrSelectEvents(dialer_wid, GR_EVENT_MASK_EXPOSURE |
                   GR_EVENT_MASK_KEY_UP | GR_EVENT_MASK_KEY_DOWN);

    GrMapWindow(dialer_wid);
}
Beispiel #10
0
void pz_execv(const char *path, char *const argv[])
{
#ifdef IPOD
	static const char *const vcs[] = {"/dev/vc/%d", "/dev/tty%d", 0};
	int i, tty0_fd, ttyfd, curvt, fd, status, oldvt = 0;
	struct vt_stat vtstate;
	pid_t pid;

	ttyfd = -1;
	/* open our VT */
	if ((tty0_fd = open("/dev/tty0", O_WRONLY, 0)) < 0)
		if ((tty0_fd = open("/dev/vc/0", O_WRONLY, 0)) < 0)
			tty0_fd = dup(0); /* STDIN is a VT? */

	/* find available VT */
	ioctl(tty0_fd, VT_OPENQRY, &curvt);
	if (curvt <= 0) {
		pz_error("No available VTs.");
		goto err;
	}

	for (i = 0; vcs[i] && (ttyfd < 0); ++i) {
		char vtpath[12];

		sprintf(vtpath, vcs[i], curvt);
		ttyfd = open(vtpath, O_RDWR);
	}
	if (ttyfd < 0) {
		pz_error("No available TTYs.");
		goto err;
	}

	/* switch to the correct vt */
	if (ioctl(ttyfd, VT_GETSTATE, &vtstate) == 0)
		oldvt = vtstate.v_active;
	/* trick SDL and the kernel both at the same time! */
	if (ioctl(tty0_fd, KDSETMODE, KD_TEXT) < 0) {
		pz_error("Can't set graphics.");
		goto err;
	}
	if (ioctl(ttyfd, VT_ACTIVATE, curvt)) {
		pz_perror("child VT_ACTIVATE");
		goto err;
	}
	if (ioctl(ttyfd, VT_WAITACTIVE, curvt)) {
		pz_perror("child VT_WAITACTIVE");
		goto err;
	}
        
        /* Kill MPD music player */
        if (mpd_available())
              kill_mpd();

	switch(pid = vfork()) {
	case -1: /* error */
		perror("vfork");
		goto err;
	case 0: /* child */
		close(tty0_fd);
		close(ttyfd);
		if(setsid() < 0) {
			perror("setsid");
			_exit(1);
		}
		close(0);
		if((fd = open("/dev/console", O_RDWR)) == -1) {
			perror("/dev/console");
			_exit(1);
		}
		if(dup(fd) == -1) {
			perror("stdin dup");
			_exit(1);
		}
		close(1);
		if(dup(fd) == -1) {
			perror("stdout dup");
			_exit(1);
		}
		close(2);
		if(dup(fd) == -1) {
			perror("stderr dup");
			_exit(1);
		}

		execv(path, argv);
		fprintf(stderr, _("Exec failed! (Check Permissions)\n"));
		_exit(1);
		break;
	default: /* parent */
		waitpid(pid, &status, 0);
		sleep(5);
		
		if (oldvt > 0) {
        		if (ioctl(ttyfd, VT_ACTIVATE, oldvt)) {
				perror("parent VT_ACTIVATE");
				goto err;
			}
        		if(ioctl(ttyfd, VT_WAITACTIVE, oldvt)) {
				perror("parent VT_WAITACTIVE");
				goto err;
			}
		}

		close(ttyfd);
		ttyfd = -1;

		if (ioctl(tty0_fd, KDSETMODE, KD_GRAPHICS) < 0)
			pz_error("Can't reset graphics.");

		if (ioctl(tty0_fd, VT_DISALLOCATE, curvt)) {
			perror("VT_DISALLOCATE"); // happens sometimes, no biggy
			goto err;
		}
		break;
	}

        /* init MPD music player */
        if (mpd_available())
              init_mpd();

err:
	close(tty0_fd);
	if (ttyfd >= 0)
		close(ttyfd);
#else
	pz_message(argv[0]);
#endif /* IPOD */
}
Beispiel #11
0
static void find_modules (const char *dir)
{
    char buf[256];
    char *podpath = 0;
    struct dirent *d;
    struct stat st;
    PzModule *cur;
    DIR *dp;
    
    dp = opendir (dir);
    if (!dp) {
	pz_perror (dir);
	return;
    }

    while ((d = readdir (dp)) != NULL) {
        if (d->d_name[0] == '.') continue;

        podpath = malloc (strlen (dir) + strlen (d->d_name) + 2);
        sprintf (podpath, "%s/%s", dir, d->d_name);

        if (stat (podpath, &st) < 0) {
            pz_perror (podpath);
            free (podpath);
            continue;
        }

        if (S_ISDIR (st.st_mode)) {
            // Either a category dir (to search recursively)
            // or a module dir. Check for the `Module' file.
            sprintf (buf, "%s/" MODULE_INF_FILE, podpath);
            if (stat (buf, &st) < 0) {
                find_modules (podpath);
                free (podpath);
                continue;
            }
            // Module dir - fall through
        } else if (strcasecmp (d->d_name + strlen (d->d_name) - 4, ".pod") != 0) {
            // Non-pod file - ignore it
            free (podpath);
            continue;
        }
        
	if (module_head == 0) {
	    cur = module_head = calloc (1, sizeof(PzModule));
	} else {
	    cur = module_head;
	    while (cur->next) cur = cur->next;
	    cur->next = calloc (1, sizeof(PzModule));
	    cur = cur->next;
	}
	cur->podpath = podpath;
        if ((stat (podpath, &st) >= 0) && S_ISDIR (st.st_mode))
            cur->extracted = 1;
	cur->to_load = 1;
        cur->ordered = 0;
        cur->next = 0;
    }

    closedir (dp);
}
Beispiel #12
0
static void load_modinf (PzModule *mod) 
{
    char *buf = malloc (512);
#ifdef IPOD
    char *confdir = "/sandbox";
    char *moddir = "/sandbox/packs";
#else
    char *confdir = malloc( MAXPATHLEN + 10 );
    char *moddir = malloc( MAXPATHLEN + 20 );
#endif
    FILE *fp;

    if (!mod->podpath) { // static mod, no POD
	// mod->name already set
	mod->longname = strdup (mod->name);
	mod->author = strdup ("podzilla Team");
	free (buf);
	return;
    }

    sprintf (buf, "%s/" MODULE_INF_FILE, mod->mountpt);
    fp = fopen (buf, "r");
    if (!fp) {
	pz_perror (buf);
    } else {
        while (fgets (buf, 511, fp)) {
            char *key, *value;
            
            if (buf[strlen (buf) - 1] == '\n')
                buf[strlen (buf) - 1] = 0;
            if (strchr (buf, '#'))
                *strchr (buf, '#') = 0;
            if (strlen (buf) < 1)
                continue;
            if (!strchr (buf, ':')) {
                pz_error (_("Line without colon in Module file for %s, ignored"), strrchr (mod->podpath, '/'));
                continue;
            }
            
            key = buf;
            value = strchr (buf, ':') + 1;
            while (isspace (*value)) value++;
            while (isspace (*(value + strlen (value) - 1))) value[strlen (value) - 1] = 0;
            *strchr (key, ':') = 0;
            
            if (strcmp (key, "Module") == 0) {
                mod->name = malloc (strlen (value) + 1);
                strcpy (mod->name, value);
            } else if (strcmp (key, "Display-name") == 0) {
                mod->longname = malloc (strlen (value) + 1);
                strcpy (mod->longname, value);
            } else if (strcmp (key, "Author") == 0) {
                mod->author = malloc (strlen (value) + 1);
                strcpy (mod->author, value);
            } else if (strcmp (key, "Dependencies") == 0) {
                mod->depsstr = malloc (strlen (value) + 1);
                strcpy (mod->depsstr, value);
	    } else if (strcmp (key, "Soft-Dependencies") == 0) {
                mod->sdepsstr = malloc (strlen (value) + 1);
                strcpy (mod->sdepsstr, value);
            } else if (strcmp (key, "Provides") == 0) {
                mod->providesstr = malloc (strlen (value) + 1);
                strcpy (mod->providesstr, value);
            } else if (strcmp (key, "Contact") == 0) {
                // nothing
            } else if (strcmp (key, "Category") == 0) {
                // nothing
/*
		if( mod->group == NULL ) {
		    if( strrchr( value, '/' ) ) { 
			// copy the last bit over ie "Games/Arcade" -> "Arcade"
			mod->group = malloc (strlen (strrchr(value,'/')) + 1);
			strcpy (mod->group, strrchr( value,'/')+1 );
		    } else {
			// copy the entire string over
			mod->group = malloc (strlen (value) + 1);
			strcpy (mod->group, value);
		    }
		}
            } else if (strcmp (key, "Group") == 0) {
		if( mod->group ) free( mod->group );
		mod->group = malloc (strlen (value) + 1);
		strcpy (mod->group, value);
*/

            } else if (strcmp (key, "Description") == 0) {
                // nothing
            } else if (strcmp (key, "License") == 0) {
                // nothing
            } else if (strcmp (key, "Unstable") == 0) {
                // You can override "beta" with Advanced > Beta Testing but you can't
                // override other things, e.g. "alpha" or "does not work".
                if (strcmp (value, "beta") == 0 && !pz_get_int_setting (pz_global_config, MODULE_TESTING))
                    pz_warning (_("Module %s is in beta. Use at your own risk."), mod->name);
                else
                    pz_warning (_("Module %s is unstable: %s. Use at your own risk."), mod->name, value);
            } else {
                pz_error (_("Unrecognized key <%s> in Module file for %s, ignored"), key,
                          mod->name? mod->name : strrchr (mod->podpath, '/'));
            }
        }
    }

    if (!mod->name) {
	pz_error (_("Module %s's module file provides no name! Using podfile name without the extension."), 
		  strrchr (mod->podpath, '/'));
	mod->name = malloc (strlen (strrchr (mod->podpath, '/') + 1) + 1);
	strcpy (mod->name, strrchr (mod->podpath, '/') + 1);
	if (strchr (mod->name, '.'))
	    *strchr (mod->name, '.') = 0;
    }
    if (!mod->longname) {
	mod->longname = malloc (strlen (mod->name) + 1);
	strcpy (mod->longname, mod->name);
    }
    if (!mod->author) {
	mod->author = malloc (strlen (_("Anonymous")) + 1);
	strcpy (mod->author, _("Anonymous"));
    }

    // Get the config path, now that we know the name.
#ifndef IPOD
    mod->cfgpath = malloc( MAXPATHLEN + 8 );
    confdir = getcwd( mod->cfgpath, MAXPATHLEN );
    confdir = strcat( confdir, "/config" );
    sprintf( moddir, "%s/modules", confdir );
#else
    mod->cfgpath = malloc( strlen( moddir ) + strlen( mod->name ) + 1);
#endif

    sprintf (mod->cfgpath, "%s/%s", moddir, mod->name);

    mkdir( confdir, 0755 ); /* make the main directory */
    mkdir( moddir, 0755 );  /* make the modules directory */
    if (mkdir (mod->cfgpath, 0755) < 0 && errno != EEXIST) { /* make the module subdir */
	pz_warning (_("Unable to create %s's config dir %s: %s"), mod->name, mod->cfgpath,
		    strerror (errno));
    }

#ifndef IPOD
    free( moddir );
#endif

    free (buf);
}