⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xtools.c

📁 -一个LINUX下的使用方&#63845 的CD-ROM刻录软件,开放源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* is valid wav-file and in cd-quality? *//* return 1 if, 0 if not */gint check_wav_file(gchar *wavname) {guchar waveHdr[44];gint fd;	fd = open (wavname, O_RDONLY, 0);	if (fd == -1) {		return 0;	}	read(fd, &waveHdr, sizeof(waveHdr));	if (!is_std_wav_file(waveHdr)) {		/* no wav at all */		close(fd);		return 0;	}	/* is it in cd-quality? */	if (!is_in_cd_quality(waveHdr)) {		close(fd);		return 0;	}	/* passed all tests */	close(fd);	return 1;}/* small thing for iso-check */gint empty(gchar c) {	return (c == 0 || c == ' ');}/* check if valid iso9660-image *//* return number of sectors if, 0 if not *//* if isoname set to NULL then query drive directly */gint check_iso_file(gint devnr, gchar *isoname, gchar *volid, gint startsec) {gchar buf[DATASECTORSIZE];gchar tmp[MAXLINE];gchar c;gint i,j,k,count;gint volsize; 	if (isoname != NULL) {		/* read from file */		if (read_info_sector_from_file(isoname,buf,sizeof(buf)) == 0) {			return 0;		}	} else {		/* read from device */		if (read_info_sector_from_dev(devnr,buf,sizeof(buf), startsec) == 0) {			return 0;		}	}	/* search iso9660-signature */	if (strncmp(buf, "\001CD001\001", 8) != 0) {		return 0;	}	/* ok, we got an iso9660-image. 	   As a bonus extract volumne-name if requested */	if (volid != NULL) {		count = 0;		for(i = 40; i < 72; i++) {			if (empty(buf[i]))				continue;			for (j = i+1; j < 72; j++) {				if (!buf[j] || (j < 72-1				&& empty(buf[j]) && empty(buf[j+1])))					break;			}			for (k = i; k < j; k++) {				c = buf[k];				if (isprint((gint)c) || isspace((gint)c)) {					tmp[count++] = c;							}			}			i = j;		}		tmp[count] = '\0';		strcpy(volid,tmp);	}	/* now also extract the size of the image */	volsize = ((buf[80] & 0xff) | 		  ((buf[81] & 0xff) << 8) | 		  ((buf[82] & 0xff) << 16) | 		  ((buf[83] & 0xff) << 24)); 		   	return volsize;}/* get cd toc and do read the iso9660-volid if possible */void get_cd_toc_and_volid(gint devnr) {gint i;gchar tmp[MAXLINE];	get_cd_toc(devnr);	/* no cd loaded? */	if (cdinfo.nr_tracks <= 0) {		return;	}	strcpy(tmp,"");	/* scan every data track */#ifdef SCANEVERYTRACK 	for (i = 0; i < cdinfo.nr_tracks; i++) {#else	for (i = 0; i < 1; i++) {#endif			if (trackinfo[i]->type == 0) {			/* get iso-header for current track */			strcpy(tmp,"");			check_iso_file(devnr, NULL, tmp, 				trackinfo[i]->start_sec); 				if (strcmp(tmp,"") != 0) {				g_free(trackinfo[i]->volname);				trackinfo[i]->volname = g_strdup(tmp);			}		}	}	/* now set disk-title to iso9660-volname because thats all we	   got at the moment */	/* last label still in buffer? */	if (strcmp(tmp,"") != 0) {		/* now check we have currently another title */		if (cdinfo.cddb_dtitle == NULL) { 			/* no? then use iso-header as title */			cdinfo.cddb_dtitle = g_strdup(tmp);		}	}	}/* do output debug messages */void dodebug(gint debuglevel, gchar *fmt, ...) {va_list ap;gchar tmp[MAXLINE*10];gchar *p;	/* output message when debuglevel is high enough */	if (debuglevel <= debug) {		/* put together the variable argument list */		va_start(ap,fmt);		vsprintf(tmp, fmt, ap);		va_end(ap);	                /* remove first linefeed if any */		p = index(tmp,'\r');		if (p != NULL)                         *p = ' ';		fprintf(stderr,"DGB%d: %s",debuglevel,tmp);	}}/* do write to logfile */void dolog(gint loglevel, gchar *fmt, ...) {va_list ap;gchar tmp[MAXLINE*10];char timestr[MAXLINE];time_t acttime;FILE *lfile;	/* output message when loglevel is high enough */	if (loglevel <= setupdata.loglevel && strcmp(setupdata.logfile,"")) {		/* put together the variable argument list */		va_start(ap,fmt);		vsprintf(tmp, fmt, ap);		va_end(ap);				acttime = time((time_t *) 0);		strcpy(timestr,ctime(&acttime));		/* remove last \n from timestr */		timestr[strlen(timestr)-1] = 0;		lfile = fopen(setupdata.logfile,"a");		if (lfile == NULL) {			g_warning("Can't open logfile %s for writing\n", 				setupdata.logfile);			return;		}		if (!fprintf(lfile,"%s XCDR %s: %s", timestr,			XCDROAST_VERSION, tmp)) {			g_warning("Error appending to logfile\n");		}		fclose(lfile);	}}/* notify-beep function *//* type: 1 = completed task, 2 = warnings */void dobeep(gint type) {gint doit;	doit = 0;	switch (setupdata.notify_at) {	case 0: 		/* we want no beep */		return;	case 1:		/* always */		doit = 1;		break;	case 2:		/* on completion */		if (type == 1) 			doit = 1;		break;	case 3:		/* warnings only */		if (type == 2)			doit = 1;		break;	default:		return;	}	/* ok..we have to play a sound */	if (doit == 1) {		if (setupdata.notify_via == 0) {			/* dspdevice */			if (strcmp(setupdata.dsp_device,"") != 0) {				test_dspdevice_play();				}		} else {			/* internal speaker */			gdk_beep();		}	}}/* does check if the loaded devices are matching the current hardware *//* returns 0 if ok, 1 if writer/read not match */gint verify_loaded_config() {gint i;gint found1, found2, found3;	/* found any scsidevices at all? */	if (scsidevices[0] == NULL) {		/* now look if this is the condition we got in the config */		if (setupdata.writer_devnr == -1 &&		    setupdata.readdev1_devnr == -1 &&			    setupdata.readdev2_devnr == -1) {			/* ok..now devices, its ok */			return 0;		}	}	i = 0;	found1 = 0;	found2 = 0;	found3 = 0;	while(scsidevices[i] != NULL) {		/* check cdwriter */		if (setupdata.writer_devnr == scsidevices[i]->devnr) {			if ((strcmp(setupdata.writer_vendor, 				   scsidevices[i]->vendor) != 0) || 			    (strcmp(setupdata.writer_model,				   scsidevices[i]->model) != 0)) {				/* devices do not match */				return 1;			} 			found1 = 1;		}		/* check readdev1 */		if (setupdata.readdev1_devnr == scsidevices[i]->devnr) {			if ((strcmp(setupdata.readdev1_vendor, 				   scsidevices[i]->vendor) != 0) || 			    (strcmp(setupdata.readdev1_model,				   scsidevices[i]->model) != 0)) {				/* devices do not match */				return 1;			} 			found2 = 1;		}		/* check readdev2 */		if (setupdata.readdev2_devnr == scsidevices[i]->devnr) {			if ((strcmp(setupdata.readdev2_vendor, 				   scsidevices[i]->vendor) != 0) || 			    (strcmp(setupdata.readdev2_model,				   scsidevices[i]->model) != 0)) {				/* devices do not match */				return 1;			} 			found3 = 1;		}		i++;	}	if (found1 == 0 || found2 == 0 || found3 == 0) {		/* devnr did not even match -> missing devices */		return 1;	}	return 0;}/* check if the image-dirs fit to our partitions *//* return 0 if ok, 1 when there were errors (and we edited the list) */gint verify_loaded_config2 () {GList *loop, *loop2;GList *fslist;gchar dir[MAXLINE];gchar fs[MAXLINE];gint free;gint fsuse;gint dirsok;	/* now check if all the loaded image-dir exists and are each on	   a own partition */	fslist = NULL;	dirsok = 0;	loop = g_list_first(setupdata.image_dirs);	while (loop) {		strcpy(dir,(gchar *)loop->data);		/* get filesystem for this dir */		free = get_free_space(dir,fs);		if (free == -1) {			/* no such directory */			/* mark to remove this entry from the list...*/			g_free(loop->data); 			loop->data = NULL;			dirsok = 1;		} else {			/* check if this dir is already in use */			/* if not, add to fs-list */			fsuse = 0;			loop2 = g_list_first(fslist);			while (loop2) {				if (strcmp(fs, (gchar *)loop2->data) == 0) {					fsuse = 1;				}				loop2 = loop2->next;			}				if (fsuse == 0) {				/* not already used */				fslist = g_list_append(fslist, g_strdup(fs));			} else {				/* remove this entry from list */				g_free(loop->data); 				loop->data = NULL;				dirsok = 1;			}		}		loop = loop->next;	}	/* free our temporary list */	free_glist(&fslist);	/* now really remove the marked dirs from list */	loop = g_list_first(setupdata.image_dirs);	while (loop) {		loop2 = loop->next;		if (loop->data == NULL) {			setupdata.image_dirs = 				g_list_remove_link(setupdata.image_dirs, loop);		}		loop = loop2;	}	return dirsok;}/* check if this track match the inserted cd (verify tracks) *//* return 0 if all ok, 1 on some error, 2 if file does not match to cd   and 3 if we dont want verify audio (checking for readable not necessary    because unreadable tracks are not displayed in verify menu */gint check_vrfy_track(gchar *fname) {gchar tmp[MAXLINE];        /* get the discid */        if (get_discid_from_imagelist(fname,tmp) != 0) {                /* no discid found in info-file? */                return 1;        }        /* compare with current cd */        if (strcmp(tmp, cdinfo.cddb_discid) != 0) {                return 2;        }	/* check if its an audio track and we want to verify them */	if (curset.noaudioverify == 1 && 		get_type_from_imagelist(fname) == 1) {		return 3;	}        /* all ok */        return 0;}/* build a trackname for image-lists */void assign_trackname(gchar *titlestr, image_files_t *entry) {                /* see if there is cd text for this track */                if (entry->title && entry->artist &&                    strcmp(entry->title,"") && strcmp(entry->artist,"")) {                        g_snprintf(titlestr,MAXLINE,"%s / %s",                                entry->title, entry->artist);                } else                if (entry->title && strcmp(entry->title,"")) {                        strcpy(titlestr, entry->title);                } else                if (entry->cddb_ttitle && strcmp(entry->cddb_ttitle,"")) {                        strcpy(titlestr, entry->cddb_ttitle);                } else                if (entry->volname && strcmp(entry->volname,"")) {                        g_snprintf(titlestr,MAXLINE,"%s / ISO9660",                                entry->volname);                }}/* check if a filename is on the writelist */gint is_on_writelist(gchar *file) {GList *loop;gchar *track;        loop = g_list_first(writelist);        while (loop) {                track = loop->data;		if (track && strcmp(track, file) == 0) {			return 1;		}		loop = loop->next;	}	return 0;}/* free trackreadset */void clear_trackreadset() {GList *loop;track_read_param_t *trackparam;        loop = g_list_first(trackreadset.trackparams);        while (loop) {                trackparam = loop->data;                g_free(trackparam->trackfile);                g_free(trackparam);                loop = loop->next;        }	if (trackreadset.trackparams)        	g_list_free(trackreadset.trackparams);        trackreadset.trackparams = NULL;	g_free(trackreadset.tocfile);	trackreadset.tocfile = g_strdup("");	g_free(trackreadset.cdtitle);	trackreadset.cdtitle = g_strdup("");        trackreadset.nrtracks = 0;        trackreadset.cdsize = 0;}/* transform coordinates when bigfonts are used */gint tbf(gint koord) {        if (bigfonts == 1) {                return (koord * XCDR_TOPLEVEL_X1)/XCDR_TOPLEVEL_X0;        } else {                return koord;        }}/* sort a glist */void sort_glist(GList *filelist) {GList *first, *last, *list1, *list2;gchar *str1, *str2, *str3;        first = g_list_first(filelist);        last = g_list_last(filelist);        for (list1 = first; list1 != last; list1 = list1->next) {                for (list2 = last; list2 != list1; list2 = list2->prev) {                        str1 = (gchar *) list1->data;                        str2 = (gchar *) list2->data;                        if (strcmp (str1, str2) > 0) {                                str3 = str1;                                list1->data = list2->data;                                list2->data = str3;                        }                }        }}/* determine path for helper apps */void get_spawn_path(gchar *app, gchar *ret) {	/* when path is with a leading slash (absolute), do nothing */	if (app[0] == '/') {		strcpy(ret,app);		return;	}	/* otherwise its relative - add sharedir */	g_snprintf(ret,MAXLINE,"%s/%s", sharedir, app);	return;}/* find a path with enough space to save a mkisofs-image *//* return 0 if found, 1 on error/disk-full *//* size is given in kbyte *//* return via call by reference the size (in kbytes) that will be   free due overwriting old files. Also return the freed size on   the directory with the most space available */gint allocate_master_filename(gint size, gint nr, gchar **return_fname, 	gint *overwrite, gint *overwritebiggest) {gchar tmp[MAXLINE];gchar biggestpath[MAXLINE];gchar path[MAXLINE];GList *freedirs;struct stat buf;GList *loop, *loop2;image_dir_free_t *freedir;gint free,maxfree,tmpkbyte;gint overwritefree, overwritefreebiggest;gint ret;        overwritefree = 0;        overwritefreebiggest = 0;        ret = 0;	freedirs = NULL;	maxfree = 0;	strcpy(biggestpath,"");        /* build image-path/free structure */        if (curset.image_index == -1) {                /* automatic setting */                loop = g_list_first(setupdata.image_dirs);                while(loop) {                        strcpy(path,(gchar *)loop->data);                        free = get_free_space(path,NULL);                        freedir = g_new(image_dir_free_t,1);                        freedir->path = g_strdup(path);                        freedir->free = free;                        freedirs = g_list_append(freedirs,freedir);                        /* path with biggest available block? */                        if (free > maxfree) {                                maxfree = free;                                strcpy(biggestpath,path);                        }                               loop = loop->next;                }        } else {                /* single path */                strncpy(path,(gchar *)g_list_nth_data(setupdata.image_dirs,                        curset.image_index), MAXLINE);                free = get_free_space(path,NULL);                freedir = g_new(image_dir_free_t,1);                freedir->path = g_strdup(path);                freedir->free = free;                freedirs = g_list_append(freedirs,freedir);                maxfree = free;                strcpy(biggestpath,path);        }        /* now we have a structure with all path we are allowed to            save data in and how much space is available there */	strcpy(path,"");	/* look in which path we have space */	loop2 = g_list_first(freedirs);	while (loop2) {		freedir = loop2->data;		/* build temporary filename */		g_snprintf(tmp,MAXLINE, "%s/%s-%02d.%s", freedir->path,			curset.file_prefix, nr, "img");		/* already a file with this name on hd? */		if (stat(tmp,&buf) == 0) {			/* file exists */			tmpkbyte = buf.st_size/1024;			overwritefree += tmpkbyte;			/* file in directory with most space? */			if (strcmp(freedir->path,biggestpath) == 0) {				overwritefreebiggest += tmpkbyte;			}		} else {			tmpkbyte = 0;		}		/* enough free? consider space that is freed		   when we overwrite a file (tmpkbyte) */		if (size < (freedir->free + tmpkbyte)) {			/* found freespace */			strcpy(path,freedir->path);			freedir->free-=size - tmpkbyte;			break;		}		loop2 = loop2->next;	}	/* no free space found? */	if (strcmp(path,"") == 0) {		ret = 1;		dodebug(1,"allocate_master_filename: no free space\n");	} else {		/* found a file */		if (return_fname != NULL) {			g_free(*return_fname);			*return_fname = g_strdup(tmp);		}		dodebug(1,"allocate_master_filename: got %s\n", tmp);	}        /* free image-path/free structure */        loop2 = g_list_first(freedirs);        while (loop2) {                freedir = loop2->data;                g_free(freedir->path);                g_free(freedir);                loop2 = loop2->next;        }        g_list_free(freedirs);        *overwrite = overwritefree;        *overwritebiggest = overwritefreebiggest;	return ret;}/* checks if the current writer does support SANYO burnproof */gint does_support_burnproof() {gint count;	if (drv_options == NULL) return 0;	count = 0;	while(drv_options[count] != NULL) {		if (strcmp(drv_options[count]->driver,"burnproof") == 0) {			return 1;		}		count++;	}	return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -