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

📄 xtools.c

📁 -一个LINUX下的使用方&#63845 的CD-ROM刻录软件,开放源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/*	xtools.c	27.3.99 tn*/#include <stdio.h>#include <sys/stat.h>#include <unistd.h>#include <string.h>#include <strings.h>#include <dirent.h>#include <fcntl.h>#include <sys/types.h>#include <errno.h>#include <ctype.h>#include <gtk/gtk.h>#include <gdk/gdk.h>#include <gdk_imlib.h>#include "xcdroast.h"#include "main.h"extern gint debug;extern scsi_devices_t **scsidevices;extern setup_data_t setupdata;extern cd_info_t cdinfo;extern track_info_t **trackinfo;extern GList *imagelist;extern current_set_t curset;extern track_read_set_t trackreadset;extern GList *tocfiles;extern GList *writelist;extern gint bigfonts;extern gint oldfontcode;extern gchar sharedir[MAXLINE];extern writer_driver_t **drv_options;void define_tooltip(GtkWidget *widget, gchar *ttext) {GtkTooltips *tip;#ifndef YELLOW_TIPSGdkColor bg;GtkStyle *style;#endif	/* tooltips wanted? */	if (setupdata.option_tooltips == 0) {		return;	}	tip = gtk_tooltips_new();	gtk_tooltips_set_tip(tip,widget,ttext,NULL);	/* set tip color (yellow) */	/*	*** Commented by C.W.Huang :	*** Why set tip color by hand? It should be set by the theme.	*** Due to an unknown feature or bug of gtk_widget_set_style(),	*** GdkFont of the tip will be changed so multibyte characters	*** cannot be displayed correctly!	*/#ifndef YELLOW_TIPS		gtk_tooltips_force_window(tip);	if (!gdk_color_parse(TOOLTIPCOL,&bg)) {		g_warning("Can't parse color %s\n",TOOLTIPCOL);		return;	}        if (!gdk_color_alloc(gtk_widget_get_colormap(tip->tip_window),&bg)) {		g_warning("Cant allocate color %s\n",TOOLTIPCOL);		return;	}	style = gtk_style_copy(gtk_widget_get_style(tip->tip_window));	style->bg[GTK_STATE_NORMAL] = bg;	gtk_widget_set_style(tip->tip_window, style);#endif}/* sets the font and color for a label widget.   if color/font is NULL then don't set color/font  */void set_font_and_color(GtkWidget *widget, gchar *font, gchar *color) {GtkStyle *style;GdkColor c;gchar *p;	style=gtk_style_copy(gtk_widget_get_style(widget));	if (font != NULL) {		gdk_font_unref(style->font);		/* for unknown reasons in some locales the fonts do		   not work correcly bold or italic when using fontset */		if (oldfontcode) {			/* now use only the definition up to the first comma */			p = strtok(font,",");			if (p) {							style->font = gdk_font_load(p);			} else {				style->font = gdk_font_load(font);			}		} else {			style->font = gdk_fontset_load(font);		}        	/* check if valid font */        	if (style->font == NULL) {                	g_warning("Font %s not found\n",font);                	return;        	}	}	if (color != NULL) {		if (!gdk_color_parse(color,&c)) {			g_warning("Can't parse color %s\n",color);			return;		}        	if (!gdk_color_alloc(gtk_widget_get_colormap(widget),&c)) {			g_warning("Cant allocate color %s\n",color);			return;		}		style->fg[GTK_STATE_NORMAL] = c;	}		gtk_widget_set_style(GTK_WIDGET(widget),style);}/* sets a certain row in a clist to a font */void set_clist_row_font(GtkCList *clist, gint row, gchar *ffont) {GtkStyle *style;gchar *p;	style=gtk_style_copy(gtk_widget_get_style(GTK_WIDGET(clist)));	gdk_font_unref(style->font);	/* for unknown reasons in some locales the fonts do	   not work correcly bold or italic when using fontset */	if (oldfontcode) {		/* now use only the definition up to the first comma */		p = strtok(ffont,",");		if (p) {						style->font = gdk_font_load(p);		} else {			style->font = gdk_font_load(ffont);		}	} else {		style->font = gdk_fontset_load(ffont);	}       	/* check if valid font */       	if (style->font == NULL) {               	g_warning("Font %s not found\n",ffont);               	return;       	}	gtk_clist_set_row_style(clist,row,style);}/* colors a certain row in a clist */void set_clist_row_color(GtkCList *clist, gint row, gchar *color) {GtkStyle *style;GdkColor c;	style=gtk_style_copy(gtk_widget_get_style(GTK_WIDGET(clist)));	if (!gdk_color_parse(color,&c)) {		g_warning("Can't parse color %s\n",color);		return;	}       	if (!gdk_color_alloc(gtk_widget_get_colormap(GTK_WIDGET(clist)),&c)) {		g_warning("Cant allocate color %s\n",color);		return;	}	style->fg[GTK_STATE_NORMAL] = c;	gtk_clist_set_row_style(clist,row,style);}/* free a simple glist structure */void free_glist(GList **list) {GList *loop;gchar *dir;	loop = g_list_first(*list);	while(loop) {		dir = loop->data;		g_free(dir); 		loop = loop->next;	}	g_list_free(*list);	*list = NULL;	}/* copy a simple glist (which has only strings as elements) */void copy_glist(GList **dst, GList *src) {GList *loop;gchar *dir;	/* clear target list */	free_glist(dst); 	loop = g_list_first(src);	while(loop) {		dir = loop->data;		*dst = g_list_append(*dst,g_strdup(dir)); 		loop = loop->next;	}}/* remove a string-element from a glist */void del_glist_link(GList **list, gchar *str) {GList *loop;gchar *dir;	if (str == NULL) 		return;	loop = g_list_first(*list);	while(loop) {		dir = loop->data;		if (dir && strcmp(str,dir) == 0) {			g_free(dir); 			*list = g_list_remove_link(*list, loop);			return;		}		loop = loop->next;	}}/* check if a string-element is in a glist *//* return 1 if found, 0 if not */gint check_in_glist(GList **list, gchar *str) {GList *loop;gchar *dir;	if (str == NULL) 		return 0;	loop = g_list_first(*list);	while(loop) {		dir = loop->data;		if (dir && strcmp(str,dir) == 0) {			return 1;		}		loop = loop->next;	}	return 0;}/* check if a path is in a master-path-glist *//* return 1 if found, 0 if not */gint check_in_mstr_glist(GList **list, gchar *str) {GList *loop;mstr_redirect_t *mstr;gchar *dir;	if (str == NULL) 		return 0;	loop = g_list_first(*list);	while(loop) {		mstr = (mstr_redirect_t *) loop->data;		if (mstr) {			dir = mstr->mstr_path;		} else {			dir = NULL;		}		if (dir && strcmp(str,dir) == 0) {			return 1;		}		loop = loop->next;	}	return 0;}/* remove a string-element from a master-glist *//* if there is a redir-path, remove only this and return */void del_mstr_glist_link(GList **list, gchar *str) {GList *loop;mstr_redirect_t *mstr;gchar *dir;	if (str == NULL) 		return;	loop = g_list_first(*list);	while(loop) {		mstr = (mstr_redirect_t *) loop->data;		if (mstr) {			dir = mstr->mstr_path;		} else {			dir = NULL;		}		if (dir && strcmp(str,dir) == 0) {			/* found link */			if (mstr->redir_path) {				/* remove redir-path only */				g_free(mstr->redir_path);				mstr->redir_path = NULL;				return;			}			g_free(dir); 			g_free(mstr);			*list = g_list_remove_link(*list, loop);			return;		}		loop = loop->next;	}}/* add a redir path to the master-glist */void add_redir_mstr_glist(GList **list, gchar *str, gchar *new) {GList *loop;mstr_redirect_t *mstr;gchar *dir;	if (str == NULL) 		return;	loop = g_list_first(*list);	while(loop) {		mstr = (mstr_redirect_t *) loop->data;		if (mstr) {			dir = mstr->mstr_path;		} else {			dir = NULL;		}		if (dir && strcmp(str,dir) == 0) {			/* found link */			if (mstr->redir_path) {				/* remove redir-path first */				g_free(mstr->redir_path);			}			/* now set new value */			mstr->redir_path = g_strdup(new);			return;		}		loop = loop->next;	}}/* get a string in the form bla => foo and return only bla */void extract_mstr_path_from_clist(gchar *in, gchar *out) {gint i, found;	if (in == NULL || out == NULL) 		return;	found = -1;	for (i = 0; i < strlen(in)-1; i++) {		if ((in[i] == '=') && (in[i+1] == '>')) {			found = i;			break;		}	} 	if (found == -1) {		/* nothing found - return original string */		strcpy(out,in);	} else {		strncpy(out,in,found);		out[found] = '\0';	}	strip_string(out);}/* get the redir path from the master-glist */void get_redir_path_from_mstr_glist(GList **list, gchar *str, gchar *ret) {GList *loop;mstr_redirect_t *mstr;gchar *dir;	if (str == NULL) 		return;	loop = g_list_first(*list);	while(loop) {		mstr = (mstr_redirect_t *) loop->data;		if (mstr) {			dir = mstr->mstr_path;		} else {			dir = NULL;		}		if (dir && strcmp(str,dir) == 0) {			/* found link */			if (mstr->redir_path) {				strcpy(ret, mstr->redir_path);			} else {				strcpy(ret, "");			}			return;		}		loop = loop->next;	}	strcpy(ret, "");}/* convert the devnr to a device-string. return 1 if devnr not found */gint convert_devnr2devstring(gint devnr, gchar *str) {gint i;gchar tmp[MAXLINE];	i = 0;	while(scsidevices[i] != NULL) {		if (devnr == scsidevices[i]->devnr) {			g_snprintf(tmp,MAXLINE,"%s %s [%d,%d]",				scsidevices[i]->vendor, scsidevices[i]->model,				scsidevices[i]->bus, scsidevices[i]->id);			strcpy(str,tmp);			return 0;		}		i++;	}	strcpy(str,"");	return 1;}/* convert the devnr to a vendor-string. return 1 if devnr not found */gint convert_devnr2vendor(gint devnr, gchar *str) {gint i;	i = 0;	while(scsidevices[i] != NULL) {		if (devnr == scsidevices[i]->devnr) {			strcpy(str,scsidevices[i]->vendor);			return 0;		}		i++;	}	strcpy(str,"");	return 1;}/* convert the devnr to a model-string. return 1 if devnr not found */gint convert_devnr2model(gint devnr, gchar *str) {gint i;	i = 0;	while(scsidevices[i] != NULL) {		if (devnr == scsidevices[i]->devnr) {			strcpy(str,scsidevices[i]->model);			return 0;		}		i++;	}	strcpy(str,"");	return 1;}/* convert the devnr to a bus/id/lun-string. return 1 if devnr not found */gint convert_devnr2busid(gint devnr, gchar *str) {gint i;	i = 0;	while(scsidevices[i] != NULL) {		if (devnr == scsidevices[i]->devnr) {			g_snprintf(str,MAXLINE,"%d,%d,%d",				scsidevices[i]->bus,				scsidevices[i]->id,				0);  /* lun always zero? */				return 0;		}		i++;	}	strcpy(str,"");	return 1;}/* convert kilobytes to MB/min string *//* displays MB when using 2048b sectors. min like stored audiotracks on the   hard drive - this is not correct when displaying the minutesize of DATA   tracks. */ void convert_kbytes2mbminstring(gint kbytes, gchar *str) {gint mb;gint min;gint sec;gint frames;gint frms;	mb = kbytes/1024;		/* we have a problem here, that we hit gint overflow on	   large values - in this case round a little inexact */	if (mb < 2000) {		/* correct value */		frames = (kbytes*1024)/CDDAFRAME;	} else {		/* rounded value */		frames = (kbytes/CDDAFRAME)*1024;	}		min = frames/(60*75);	sec = (frames%(60*75))/75;	frms = (frames%75);	/* csec = (4*(frames%75)+1)/3; */	g_snprintf(str,MAXLINE,"%dMB / %d:%02d.%02d",mb,min,sec,frms);}/* convert kilobytes to MB/min string *//* displays MB when using 2048b sectors. min like the size of track after   burned. The only correct min size display when burning data tracks */ void convert_kbytes2mbcorrectminstring(gint kbytes, gchar *str) {gint mb;gint min;gint sec;gint frames;gint frms;	mb = kbytes/1024;	frames = kbytes/2;		min = frames/(60*75);	sec = (frames%(60*75))/75;	frms = (frames%75);	/* csec = (4*(frames%75)+1)/3; */	g_snprintf(str,MAXLINE,"%dMB / %d:%02d.%02d",mb,min,sec,frms);}/* convert frames to MB/min string *//* should only be used for audio or full disk info */void convert_frames2mbminstring(gint frames, gchar *str) {gint mb;gint min;gint sec;gint frms;	mb = ((frames/1024)*CDDAFRAME)/1024;	min = frames/(60*75);	sec = (frames%(60*75))/75;	frms = (frames%75);	/* csec = (4*(frames%75)+1)/3; */	g_snprintf(str,MAXLINE,"%dMB / %d:%02d.%02d",mb,min,sec,frms);}/* convert frames/sectors to MB string *//* note - this is only true for DATA-tracks */void convert_frames2mbstring(gint frames, gchar *str) {gint mb;	mb = frames*(DATASECTORSIZE/1024)/1024;	g_snprintf(str,MAXLINE,"%dMB",mb);}/* convert kbytes to MB string */void convert_kbytes2mbstring(gint kbytes, gchar *str) {gint mb;	mb = kbytes/1024;	g_snprintf(str,MAXLINE,"%dMB",mb);}/* convert frames to min string */void convert_frames2minstring(gint frames, gchar *str) {gint min;gint sec;gint frms;	min = frames/(60*75);	sec = (frames%(60*75))/75;	frms = (frames%75);	/* csec = (4*(frames%75)+1)/3; */	g_snprintf(str,MAXLINE,"%d:%02d.%02d",min,sec,frms);}/* creates a label that is right justified. Useful when   packing into a table */GtkWidget *rightjust_gtk_label_new(gchar *txt) {GtkWidget *align;GtkWidget *label;	/* create right justify alignment */	align = gtk_alignment_new(1.0,0.5,0,0);	label = gtk_label_new(txt);	gtk_container_add(GTK_CONTAINER(align),label);	gtk_widget_show(label);	return align;}/* creates a label that is left justified. Useful when   packing into a table */GtkWidget *leftjust_gtk_label_new(gchar *txt) {GtkWidget *align;GtkWidget *label;	/* create left justify alignment */	align = gtk_alignment_new(0.0,0.5,0,0);	label = gtk_label_new(txt);	gtk_container_add(GTK_CONTAINER(align),label);	gtk_widget_show(label);	return align;}/* get some info about our image-file */void analyze_imgfile(gchar *path, gchar *file, GList **retlist) {struct stat buf;image_files_t *entry;gchar tmp[MAXLINE];gchar volid[MAXLINE];glong size;gint type,readable,isosize;gint fd;	strncpy(tmp,path,MAXLINE-strlen(file)-2);	strcat(tmp,"/");	strcat(tmp,file);	stat(tmp,&buf);	/* check if regular file or link */	if (S_ISLNK(buf.st_mode) != 1 && S_ISREG(buf.st_mode) != 1) {		/* its not..so ignore */		return;	} 	/* readable for us? */	fd = open(tmp, O_RDONLY,0);	if (fd == -1) {		readable = 0;	} else {		readable = 1;		close(fd);	}			size = (glong) buf.st_size;	isosize = 0;	/* now do some tests about file-contents */	if (strncmp(file+strlen(file)-4,".toc",4) == 0) {		type = 4;	} else if (strncmp(file+strlen(file)-4,".wav",4) == 0) {		/* wav-file */		if (check_wav_file(tmp) == 0) {			/* invalid wav */			type = 2;		} else {			/* valid wav */

⌨️ 快捷键说明

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