Esempio n. 1
0
int _pz_mod_check_version (int otherver) 
{
    int myver = PZ_API_VERSION;
    PzModule *module = current_module;

    /* version completely equal - OK */
    if (myver == otherver)
        return 1;

    /* version less - some stuff may be missing, won't work */
    if (myver < otherver) {
        pz_error ("Module %s compiled for a newer version of podzilla. Please upgrade.",
                  module->name);
        goto remove;
    }
    /* minor version more - only stuff added, OK */
    if (((myver & ~0xff) == (otherver & ~0xff)) && ((myver & 0xff) >= (otherver & 0xff))) {
        pz_warning ("Module %s compiled for a slightly older version of podzilla. "
                    "It will still probably work, but you should upgrade the module soon.",
                    module->name);
        return 1;
    }
    /* major version more - won't work */
    pz_error ("Module %s compiled for a significantly older version of podzilla; "
              "it will not work. Please upgrade the module.", module->name);
 remove:
    module->to_free = 1;
    return 0;
}
Esempio n. 2
0
/*  0 - connected
 *  1 - was error, connection restored
 * -1 - unable to connect to MPD
 */ 
int mpdc_tickle()
{
	char err = 0;

	if (mpdz == NULL) {
		mpdc_init();
	} else if (mpdz->error) {
		pz_error(mpdz->errorStr);
		mpd_clearError(mpdz);
		err = 1;
	}

	if (mpdc_status(mpdz) == -1) {
		mpdc_destroy();
		mpdc_init();
		if (mpdc_status(mpdz) < 0) {
			if (!err) { /* already have an error */
				pz_error(_("Unable to determine MPD status."));
			}
                        mpd_active = 0;
			return -1;
		}
                mpd_active = 1;
		return 1;
	}

	return (mpdz == NULL) ? -1 : err;
}
Esempio n. 3
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;
}
Esempio n. 4
0
/* assumes cur_file is already pointing to proper file */
static void start_next_file() {
	printf("Starting next file: %s\n", cur_file->src_filename);
	
	struct stat s;
	if (stat(cur_file->src_filename, &s) != 0) {
	  pz_error("Cannot stat %s\n", cur_file->src_filename);
	  return;
	}
	

	/* If track is being transferred, get a new destination filename */
	if (cur_file->src_track) {
		if (cur_file->dst_filename) {
		  pz_error("Track shouldn't already have dst_filename\n");
		  abort_transfer();
		  return;
		}
		
		cur_file->dst_filename = (char *)malloc(256);
		char *dst_base = ((ipod_p)(trans_list_dst_ipod))->basePath;
	    char *extension, *p;
		extension = (char*)ipod_extension_of(cur_file->src_filename,".mp3");
		cur_file->dst_location = ipod_unique_track_location_wrapper(trans_list_dst_ipod, extension);
    	strcpy(cur_file->dst_filename, dst_base);
		strcat(cur_file->dst_filename, cur_file->dst_location);
		while((p=strpbrk(cur_file->dst_filename,":"))!=NULL) *p='/'; /* convert ':'s to '/' */
	}
	
	if (!cur_file->dst_filename) {
	  pz_error("No destination filename given!\n");
	  abort_transfer();
	  return;
	}

	srcFile = fopen(cur_file->src_filename, "r");
	if (!srcFile) {
	  pz_error("Could not open %s for reading\n", cur_file->src_filename);
	  abort_transfer();
	  return;
	}
	
	dstFile = fopen(cur_file->dst_filename, "w");
	if (!dstFile) {
	  pz_error("Could not open %s for writing\n", cur_file->dst_filename);
	  fclose(srcFile);
	  srcFile = NULL;
	  abort_transfer();
	  return;
	}
}
Esempio n. 5
0
static TWindow *transfer_tracks (ttk_menu_item *item) {
	printf("Transferring tracks:\n");
	track_list *tracks = (track_list *)item->data;
	ipod_t src_ipod = tracks->ipod;
	ipod_t dst_ipod;
	if (src_ipod == local_ipod)
		dst_ipod = remote_ipod;
	else if (src_ipod == remote_ipod)
		dst_ipod = local_ipod;
	else {
		pz_error("src_ipod not set in tracklist\n");
		return TTK_MENU_DONOTHING;
	}
	
	transfer_list_reset(src_ipod, dst_ipod);
	
	uint32_t track_id;
	while ((track_id = track_list_pop(tracks)))
	   transfer_list_add_track(track_id);
	
	/* This is ugly, but it is the only easy way I can get
	 * the first window to close */
	ttk_show_window(new_transfer_window());
	return TTK_MENU_UPONE;
}
Esempio n. 6
0
void transfer_list_add_track(uint32_t track_id) {

	ipod_track_t track = ipod_track_get_by_track_id(trans_list_src_ipod, track_id);	
	if (track == NULL) {
	    pz_error("Unable to find source track (ID=%i)\n", track_id);
		return;
	}
	
	/* create new track-specific transfer_item */
	transfer_item *nitem = (transfer_item *)malloc( sizeof( transfer_item ));
	nitem->src_track = track;
	nitem->src_filename = ipod_string_new();
	nitem->src_filename = ipod_track_get_text(track,IPOD_FULL_PATH,nitem->src_filename);
	nitem->filesize = ipod_track_get_attribute(track, IPOD_TRACK_SIZE);
	/* don't determine a destination filename until right before transfer */
	nitem->dst_filename = NULL;
	nitem->dst_location = NULL;

	total_files++;
    total_bytes += nitem->filesize;	

    nitem->next = NULL;
	
	if (trans_list_head == NULL) {
      trans_list_head = nitem;
	  trans_list_tail = nitem;
	  return;
	}

    /* add the item at the end of the list */	
	trans_list_tail->next = nitem;
	trans_list_tail = nitem;
}
Esempio n. 7
0
/* an entry point for an address book or the like */
void dialer_dial( char * number )
{
    int x = 0;
    int ret;
    dsp_st dspz;

    if( !number ) return;

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

    while ( number[x] != '\0' )
    {
        dtmf_play( &dspz, number[x++] );
    }

#ifdef __linux__
    dsp_close(&dspz);
#endif
}
Esempio n. 8
0
/* Polls to check if RiP is mounted.
 * Returns 0/1 for mounted/unmounted.
 * -1 is for error.
 * 2 is for mounted at incorrect location
 */
int poll_mount(const char *expected_device, const char *expected_mountpoint) {
#ifdef ALWAYS_MOUNTED
	return 1;
#endif	

    char buf[256];
    FILE *fp = fopen ("/proc/mounts", "r");
    if (!fp) 
	  return -1;
    
	int ret = 0;
	
    while (ret==0 && fgets (buf, 256, fp)) {
        if (!strchr (buf, ' ')) continue;

        char *mountpt = strchr (buf, ' ') + 1;
        //char *fstype = strchr (mountpt, ' ') + 1;

        *strchr (buf, ' ') = 0;
        *strchr (mountpt, ' ') = 0;
//        *strchr (fstype, ' ') = 0;
        if (strcmp (buf, expected_device)==0) {
           if (strcmp (mountpt, expected_mountpoint)==0)
	         ret = 1;
		   else {
			 pz_error("Warning: Remote ipod mounted at %s, expecting %s\n", mountpt, expected_mountpoint);
		     ret = 2;
		   }
	    }
    }
    fclose (fp);
	return ret;
}
Esempio n. 9
0
static int piezomaker_load(char *filename)
{
    int i = 0, p = 0, d = 0;
    char buffer[80];
    FILE *fp;

    fp = fopen(filename, "r");
    if(!fp) {
        pz_error(_("Could not open file for reading."));
        return 1;
    }
    while(fgets(buffer, 80, fp) != NULL) {
        if(buffer[0] == '#') {
            continue;
        }
        else if(i == 0) {
            size     = atoi(buffer);
            period   = realloc(period,   sizeof(int) * size);
            duration = realloc(duration, sizeof(int) * size);
        }
        else if(i % 2 == 1) {
            *(period + p)   = atoi(buffer);
            p++;
        }
        else if(i % 2 == 0) {
            *(duration + d) = atoi(buffer);
            d++;
        }
        i++;
    }
    fclose(fp);

    return 0;
}
Esempio n. 10
0
void new_video_window(char *filename)
{
#ifndef IPOD
	pz_error("No video support on the desktop.");
#else /* IPOD */

	if (full_hw_version==0)
	{
		full_hw_version = ipod_get_hw_version();
	}
	outl(1, VAR_VIDEO_ON);
	outl(0, VAR_VIDEO_MODE);
	cop_wakeup();
	init_variables();
	video_status = VIDEO_CONTROL_MODE_STARTING; 
	video_curPosition = 0;
	video_gc = pz_get_gc(1);
	GrSetGCUseBackground(video_gc, GR_FALSE);
	GrSetGCForeground(video_gc, GR_RGB(0,0,0));
//nes_window("Create win");
	video_wid = pz_new_window(0, 0, screen_info.cols, screen_info.rows, video_do_draw, video_do_keystroke);

	GrSelectEvents(video_wid, 
			GR_EVENT_MASK_KEY_DOWN| GR_EVENT_MASK_KEY_UP);
	GrMapWindow(video_wid);

	GrClearWindow(video_wid, GR_FALSE);
//nes_window("Load");
	video_status_message("Loading video...");
//nes_window("Play");	
playVideo(filename);
	outl(0, VAR_VIDEO_ON);
#endif
}
Esempio n. 11
0
// sets mod->mountpt = 0 on failure, returns -1. 0 = success.
static int mount_pod (PzModule *mod) 
{
#ifdef MountPods
    char mountline[256];
    static int nextmount = 0;

#ifdef IPOD
#define PODDIR "/tmp/modules/"
#else
#define PODDIR "mpods/"
#endif
    mkdir (PODDIR, 0777);
    mod->mountpt = malloc (strlen (PODDIR) + 10);
    sprintf (mod->mountpt, PODDIR "%d/", nextmount);
    mkdir (mod->mountpt, 0777);

    sprintf (mountline, "mount -t podfs -o loop %s %s", mod->podpath, mod->mountpt);
    mod->mountnr = nextmount++;

    // mount it
    if (system (mountline) != 0) {
    	strcat (mountline, " 2>mountpod.err >mountpod.err");
    	system (mountline);
    	pz_error ("Module %s (#%d): mount: exit %d - some sort of error, check mountpod.err",
                  strrchr (mod->podpath, '/') + 1, mod->mountnr);
    	free (mod->mountpt);
    	mod->mountpt = 0;
    	return -1;
    }
#else
    struct stat st;

    mod->mountpt = strdup (mod->podpath);
    if (strrchr (mod->mountpt, '.'))
        *strrchr (mod->mountpt, '.') = 0;
    
    if (stat (mod->mountpt, &st) < 0 || !S_ISDIR (st.st_mode)) {
	if (stat (mod->mountpt, &st) >= 0)
	    errno = ENOTDIR;
	pz_error ("Couldn't access xpod dir for %s: %s", mod->mountpt, strerror (errno));
	free (mod->mountpt);
	mod->mountpt = 0;
	return -1;
    }
#endif
    return 0;
}
Esempio n. 12
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 */
}
Esempio n. 13
0
static void do_copy() {
    unsigned long bytesRead,bytesWritten;
    bytesRead = fread(transfer_buffer,1,BUFFER_SIZE,srcFile);
    if (bytesRead==0) {
	  pz_error("Zero bytes read!\n");
	  abort_transfer();
	  return;
	}
    
	bytesWritten = fwrite(transfer_buffer,1,bytesRead,dstFile);
    if (bytesRead != bytesWritten) {
	  pz_error("bytesRead != bytesWritten!\n");
	  abort_transfer();
	  return;
	}
    file_bytes_transferred += bytesWritten;
	total_bytes_transferred += bytesWritten;
	
    return;
}
Esempio n. 14
0
int mpdc_init()
{
	static int warned_once = 0;
	if ((mpdz = mpd_init_connection()) == NULL) {
		if (!warned_once) {
			pz_error(_("Unable to connect to MPD"));
			warned_once = 1;
		}
		return -1;
	}
	return 0;
}
Esempio n. 15
0
PzModule *pz_register_module (const char *name, void (*cleanup)()) 
{
    PzModule *cur = module_head;
    while (cur) {
	if (!strcmp (cur->name, name))
	    break;
	cur = cur->next;
    }
    if (!cur) {
	pz_error ("Module registered with invalid name <%s>.", name);
	return 0;
    }
    cur->cleanup = cleanup;
    return cur;
}
Esempio n. 16
0
int podwrite_save_callback(TWidget * wid, char * fn)
{
	FILE * f;
	pz_close_window(wid->win);
	if (fn[0]) {
		f = fopen(fn, "wb");
		if (!f) {
			pz_error(_("Could not open file for saving."));
			return 0;
		}
		fwrite(podwrite_buf->text, 1, podwrite_buf->usize, f);
		fclose(f);
	}
	podwrite_mode = 0;
	pz_close_window(podwrite_menu->win);
	ti_widget_start(podwrite_wid);
	return 0;
}
Esempio n. 17
0
// Resets the game.
static void reset()
{
	if (running == 1)
		GrDestroyTimer( timer_id );
	reset_chasm_queue(&head, &middle, &tail);
	if(new_chasm_queue((wi.width - chasmWidth) / 2, wi.height / 2, &head, &middle, &tail) == -1)
	{
		pz_error("Error making queue.");
		pz_close_window (tunnel_wid);
		return;
	}
	score = 0;
	running = 0;
	ball.radius = ballRadius;
	ball.x = wi.width / 2;
	timer_id = GrCreateTimer(tunnel_wid, timerSpeed); 
	advance_and_check();
}
Esempio n. 18
0
static void start_copy() {
	int filesize;
	int len;
	struct stat st;
	
	transfer_buffer = (char *)malloc(BUFFER_SIZE);
	if (!transfer_buffer) {
		pz_error("Unable to alloc transfer buffer!\n");
		return;
	}

	dst_ipod_dirty = 0;
	total_files_transferred = 0;
	total_bytes_transferred = 0;
	file_bytes_transferred = 0;
	cur_file = trans_list_head;
	
	rip_status = STATUS_TRANSFERRING;
}
Esempio n. 19
0
void make_lookup_table()
{
	int i, fd, version;
	double minOmega ;
	char buf[16];
	int len;
	char filename[64];

	strcpy(filename, SINE_TABLE_DIR);
	strcat(filename, SINE_TABLE_FILE);
	lookup_table = (short *) malloc(MAX_LOOKUP_SAMPLES*sizeof(short));
	if(lookup_table == NULL) {
		pz_error("Out of memory!");
		generator_destruct();
	}
	fd = open(filename, O_RDONLY);
	if (fd>=0) {	//if file exists, read it
		if (read(fd, &version, sizeof(int)) == sizeof(int)) {
			if (version == SINE_TABLE_VERSION) {
				len = read(fd, lookup_table, MAX_LOOKUP_SAMPLES*sizeof(short));
				close(fd);
				if(len == MAX_LOOKUP_SAMPLES*sizeof(short))
					return; 
			}
		}
       }
	mkdir(SINE_TABLE_DIR, 0777);
	fd = open(filename, O_RDWR |O_CREAT | O_TRUNC);
	for (i = 0; i < MAX_LOOKUP_SAMPLES; i++) {
		minOmega = (M_PI_2* i)/MAX_LOOKUP_SAMPLES; 
		lookup_table[i] = ((1.0+sin(minOmega))*ZERO_SAMPLE_VALUE);
		if((i%64)==0)	{
			sprintf(buf, "sin:%d", i);
			generator_draw_text(buf);
		}
	}
	if (fd != -1) {
		version = SINE_TABLE_VERSION;
		write(fd, &version, sizeof(int));
		write(fd, lookup_table, sizeof(short)* MAX_LOOKUP_SAMPLES);
		close(fd); 
	}
}
Esempio n. 20
0
static TWindow *browser_transfer (ttk_menu_item *item) {
   if (item->data == NULL)
     return TTK_MENU_DONOTHING;

   /* This is sketchy, the browser module actually does a change directory */
   char full_path[PATHSIZ];
   getcwd(full_path, PATHSIZ);
   if (full_path[strlen(full_path)-1] != '/')
	 strcat(full_path, "/");
   strcat(full_path, item->data);
   printf("full_path: %s\n", full_path);
   
   int remote_src = 0;
   if (strcmp(full_path, RIP_MOUNTPOINT) && rip_status == STATUS_MOUNTED)
     remote_src = 1;
   
   pz_error("File transferring not yet enabled");
   //ttk_show_window(transfer_alt_menu(NULL, remote_src ? remote_ipod : local_ipod, NULL, NULL));
   
   return TTK_MENU_DONOTHING;
}
Esempio n. 21
0
static void browser_delete_confirm()
{
	struct stat stat_result;
	static item_st delete_confirm_menu[] = {
		{N_("Whoops. No thanks."), NULL, SUB_MENU_PREV},
		{N_("Yes, Delete it."), browser_delete_file, ACTION_MENU},
		{0}
	};

	browser_menu = menu_init(browser_wid, _("Are You Sure?"), 0, 0,
			screen_info.cols, screen_info.rows -
			(HEADER_TOPLINE + 1), browser_menu,
			delete_confirm_menu, ASCII);
	browser_menu_overlay = browser_menu;

	stat(current_file, &stat_result);
	if(S_ISDIR(stat_result.st_mode)) {
		pz_error(_("Warning: this will delete everything under %s"),
				current_file);
	}
}
Esempio n. 22
0
PzWindow *new_mymodule_window()
{
    static int calledyet = 0;
    PzWindow *ret;
    FILE *fp;
    
    if (!calledyet) {
	calledyet++;
	pz_message ("Select again to see the fun stuff.");
	return TTK_MENU_DONOTHING;
    }

    image = ttk_load_image (pz_module_get_datapath (module, "image.png"));
    if (!image) {
	pz_error ("Could not load %s: %s", pz_module_get_datapath (module, "image.png"),
		  strerror (errno));
	return TTK_MENU_DONOTHING;
    }
    ttk_surface_get_dimen (image, &imgw, &imgh);

    fp = fopen (pz_module_get_datapath (module, "message.txt"), "r");
    if (!fp) {
	pz_warning ("Could not read from %s: %s.", pz_module_get_datapath (module, "message.txt"),
		    strerror (errno));
	text = (char *)strdup ("Hi! I forgot to supply a message!");
    } else {
	long len;
	fseek (fp, 0, SEEK_END);
	len = ftell (fp);
	fseek (fp, 0, SEEK_SET);
	text = malloc (len + 1);
	fread (text, 1, len, fp);
	text[len] = 0;
    }

    ret = pz_new_window ("MyModule", PZ_WINDOW_NORMAL);
    pz_add_widget (ret, draw_mymodule, event_mymodule);
    return pz_finish_window (ret);
}
Esempio n. 23
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;
}
Esempio n. 24
0
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);
}
Esempio n. 25
0
int pz_menuconf_runfile(char * fn)
{
	FILE * fp = fopen(fn, "r");
	int ret = -1;
	if (fp) {
		char * buf;
		int len;
		fseek(fp, 0, SEEK_END);
		len = ftell(fp);
		fseek(fp, 0, SEEK_SET);
		buf = malloc(len+1);
		if (!buf) {
			pz_error("Ran out of memory to run the script %s.", fn);
		} else {
			fread(buf, 1, len, fp);
			buf[len] = 0;
			ret = pz_menuconf_runstr(buf);
			free(buf);
		}
		fclose(fp);
	}
	return ret;
}
Esempio n. 26
0
static int piezomaker_save_callback(TWidget *swid, char *filename)
{
    int i;
    FILE *fp;

    pz_close_window(swid->win);

    fp = fopen(filename, "w");
    if(!fp) {
        pz_error(_("Could not save file."));
        return 0;
    }
    fprintf(fp, "#PZM\n#%.2f seconds\n#generated by piezomaker/podzilla\n", piezomaker_seconds());
    fprintf(fp, "%d\n", size);
    for(i=0; i<size; i++) {
        fprintf(fp, "%d\n%d\n", *(period+i), *(duration+i));
    }
    fclose(fp);

    free(period);
    free(duration);

    return 0;
}
Esempio n. 27
0
static void do_load (PzModule *mod) 
{
    char *fname;
#ifndef IPOD
    struct stat st;
#endif
    
    fname = malloc (strlen (mod->mountpt) + strlen (mod->name) + 8);
#ifdef IPOD
    sprintf (fname, "%s/%s.zl", mod->mountpt, mod->name);
    mod->handle = uCdl_open (fname);
    free (fname);
    if (!mod->handle) {
	pz_error ("Could not load module %s: %s", mod->name, uCdl_error());
        mod->to_load = 0;
    }
#else
    sprintf (fname, "%s/%s.so", mod->mountpt, mod->name);
    if (stat (fname, &st) < 0) {
        free (fname);
        mod->handle = 0;
        mod->to_load = 0;
        return;
    }
    mod->handle = dlopen (fname, RTLD_NOW | RTLD_GLOBAL);
    free (fname);
    if (!mod->handle) {
/*
        pz_error ("Could not load module %s: %s", mod->name, dlerror());
*/
	fprintf( stderr, "Error: Could not load module %s: %s\n",
			mod->name, dlerror());
        mod->to_load = 0;
    }
#endif
}
Esempio n. 28
0
static void credits_die(char *msg)
{
	pz_error(msg);
	credits_exit();
}
Esempio n. 29
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 */
}
Esempio n. 30
0
/* the directory to scan */
static void browser_mscandir(char *dira)
{
	DIR *dir = opendir(dira);
	int i, size, op;
	struct stat stat_result;
	struct dirent *subdir;

	if(browser_menu != NULL) {
		menu_destroy(browser_menu);
	}
	browser_menu = menu_init(browser_wid, _("File Browser"), 0, 0,
			screen_info.cols, screen_info.rows -
			(HEADER_TOPLINE + 1), NULL, NULL, ASCII);

	/* not very good for fragmentation... */
	for (i = 0; i < browser_nbEntries; i++) {
		free(browser_entries[i].full_name);
	}
	browser_nbEntries = 0;

	while ((subdir = readdir(dir))) {
		if(strncmp(subdir->d_name, ".", strlen(subdir->d_name)) == 0) {
			continue;
		}
		if(strncmp(subdir->d_name, "..", strlen(subdir->d_name)) == 0) {
			strcpy(browser_entries[browser_nbEntries].name,
				_(".. [Parent Directory]"));
			browser_entries[browser_nbEntries].full_name =
				strdup(browser_entries[browser_nbEntries].name);
			browser_entries[browser_nbEntries].type =
				FILE_TYPE_DIRECTORY;
			browser_entries[browser_nbEntries].op = STUB_MENU;
			browser_nbEntries++;
			continue;
		}
		if(!ipod_get_setting(BROWSER_HIDDEN)) {
			if (subdir->d_name[0] == '.') {
				continue;
			}
		}
		if(browser_nbEntries >= MAX_ENTRIES) {
			pz_error(_("Directory contains too many files."));
			break;
		}
		
		size = strlen(subdir->d_name);
		size = (size > 62 ? 62 : size);
		browser_entries[browser_nbEntries].full_name =
			strdup(subdir->d_name);

		strncpy(browser_entries[browser_nbEntries].name,
				subdir->d_name, size);
		browser_entries[browser_nbEntries].name[size] = '\0';

		stat(subdir->d_name, &stat_result);
		if(S_ISDIR(stat_result.st_mode)) {
			browser_entries[browser_nbEntries].type =
			    FILE_TYPE_DIRECTORY;
			op = ARROW_MENU;
		}
		else if(stat_result.st_mode & S_IXUSR) {
			browser_entries[browser_nbEntries].type =
			    FILE_TYPE_PROGRAM;
			op = EXECUTE_MENU;
		}
		else {
			browser_entries[browser_nbEntries].type =
				FILE_TYPE_OTHER;
			op = STUB_MENU;
		}
		browser_entries[browser_nbEntries].op = op;

		browser_nbEntries++;
	}
	closedir(dir);

	qsort(browser_entries, browser_nbEntries, sizeof(Directory), dir_cmp);
	for (i = 0; i < browser_nbEntries; i++)
		menu_add_item(browser_menu, browser_entries[i].name,
				NULL, 0, browser_entries[i].op);
}