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

📄 io.c

📁 -一个LINUX下的使用方&#63845 的CD-ROM刻录软件,开放源码
💻 C
📖 第 1 页 / 共 5 页
字号:
		if (strcmp("NOTIFY_VIA",id) == 0) {			setupdata.notify_via = atoi(value);		}		if (strcmp("NOTIFY_AT",id) == 0) {			setupdata.notify_at = atoi(value);		}		if (strcmp("CDDB_HOST",id) == 0) {			g_free(setupdata.cddb_host);			setupdata.cddb_host = g_strdup(value);		}		if (strcmp("CDDB_PORT",id) == 0) {			setupdata.cddb_port = atoi(value);		}		if (strcmp("LOGFILE",id) == 0) {			g_free(setupdata.logfile);			setupdata.logfile = g_strdup(value);		}		if (strcmp("LOGLEVEL",id) == 0) {			setupdata.loglevel = atoi(value);		}		if (strcmp("LANGUAGE",id) == 0) {			setupdata.language = atoi(value);		}		if (strcmp("OPTION_TOOLTIPS",id) == 0) {			setupdata.option_tooltips = atoi(value);		}		if (strcmp("OPTION_AUTORAISE",id) == 0) {			setupdata.option_autoraise = atoi(value);		}		if (strcmp("OPTION_SAVEPOS",id) == 0) {			setupdata.option_savepos = atoi(value);		}		if (strcmp("OPTION_PERSONIMAGE",id) == 0) {			setupdata.option_personimage = atoi(value);		}		if (strcmp("OPTION_OVERWRITEWARN",id) == 0) {			setupdata.option_overwritewarn = atoi(value);		}		if (strcmp("OPTION_AUTODELETE",id) == 0) {			setupdata.option_autodelete = atoi(value);		}		if (strcmp("OPTION_TITLEPROGRESS",id) == 0) {			setupdata.option_titleprogress = atoi(value);		}		if (strcmp("OPTION_DISPLAYCDTEXT",id) == 0) {			setupdata.option_displaycdtext = atoi(value);		}		if (strcmp("OPTION_SELECTIONMODE",id) == 0) {			setupdata.option_selectionmode = atoi(value);		}	}	if (fclose(fd) != 0) {		/* error closing file */		return 1;	}	return 0;}/* parse a detailed toc line */void parse_toc_line(gchar *line) {gchar tmp[MAXLINE];gchar tmp2[MAXLINE];gchar tmp3[MAXLINE];gchar old_cddb_title[MAXLINE];gchar *p1;gint min,sec,frm;gint ret;	/* to much tracks? */	if (tocnr >= MAXTRACKS) {		g_error("over %d tracks in toc\n",MAXTRACKS);	}	strcpy(old_cddb_title,"");	/* allocate memory for new line (free first old memory)*/	if (trackinfo[tocnr] != NULL) {		g_free(trackinfo[tocnr]->volname);		g_free(trackinfo[tocnr]->title);		g_free(trackinfo[tocnr]->artist);		/* backup old cddb-title  */		if (trackinfo[tocnr]->cddb_ttitle != NULL) {			strcpy(old_cddb_title, trackinfo[tocnr]->cddb_ttitle);		}		g_free(trackinfo[tocnr]->cddb_ttitle);		g_free(trackinfo[tocnr]);	}	trackinfo[tocnr] = g_new0(track_info_t,1);	/* when the cd is still the same as last time, restore cddb-title */	if (cd_is_still_the_same == 1) {		/* got a backuped title? */		if (strcmp(old_cddb_title,"") != 0) {			trackinfo[tocnr]->cddb_ttitle = g_strdup(old_cddb_title); 		}	}	/* now we are prepared to fill structure */	strcpy(tmp,line+1);	p1 = strtok(tmp,":");	if (p1 == NULL) {		g_error("Unexpected output in cdda2wav toc-output\n");	}	trackinfo[tocnr]->track_nr = atoi(p1);	/* reststring into tmp2 - strip to remove leading spaces */	p1 = strtok(NULL,"");	strcpy(tmp2,p1);	strip_string(tmp2);	p1 = strtok(tmp2," ");	trackinfo[tocnr]->start_sec = atoi(p1);	p1 = strtok(NULL,"");	strcpy(tmp,p1);	strip_string(tmp);	/* now get tracklength - convert to frames */	p1 = strtok(tmp," ");	sscanf(p1,"%d:%d.%d",&min,&sec,&frm);	trackinfo[tocnr]->size = (min*60+sec)*75 + frm;	/* tracktype */	p1 = strtok(NULL," ");	if (strncmp(p1,"data",4) == 0) {		/* data-track */		trackinfo[tocnr]->type = 0;		p1 = strtok(NULL," ");		if (strncmp(p1,"uninterrupted",13) == 0) {			trackinfo[tocnr]->rec_type = 1;		} else {			trackinfo[tocnr]->rec_type = 0;		}		p1 = strtok(NULL," ");		if (strncmp(p1,"copydenied",10) == 0) {			trackinfo[tocnr]->copyperm = 0;		} else {			trackinfo[tocnr]->copyperm = 1;		}		} else {		/* audio-track */		trackinfo[tocnr]->type = 1;				p1 = strtok(NULL," ");		if (strncmp(p1,"linear",6) == 0) {			trackinfo[tocnr]->preemp = 0;		} else {			trackinfo[tocnr]->preemp = 1;		}		p1 = strtok(NULL," ");		if (strncmp(p1,"copydenied",10) == 0) {			trackinfo[tocnr]->copyperm = 0;		} else {			trackinfo[tocnr]->copyperm = 1;		}			p1 = strtok(NULL," ");		if (strncmp(p1,"stereo",6) == 0) {			trackinfo[tocnr]->stereo = 1;		} else {			trackinfo[tocnr]->stereo = 0;		}			p1 = strtok(NULL," ");		p1 = strtok(NULL,"");		strcpy(tmp2,p1);		strip_string(tmp2);		ret = decode_title_artist(tmp2,tmp,tmp3);		if (ret != 0) {			g_error("got unexpected artist/title\n");		}		trackinfo[tocnr]->title = g_strdup(tmp);		trackinfo[tocnr]->artist = g_strdup(tmp3);	}			tocnr++;}/* print memory-structure with toc-data (debug purposes) */void print_cdinfo() {gint i;gchar *p1, *p2, *p3, *p4;gchar tmp[] = "(NULL)";	dodebug(2,"------ cdinfo-structure -----\n");	dodebug(2,"nr_tracks: %d\n",cdinfo.nr_tracks);	dodebug(2,"total_size: %d\n",cdinfo.total_size);	dodebug(2,"cddb_discid: %s\n",cdinfo.cddb_discid);	dodebug(2,"have_cdtext: %d, have_cdextra: %d\n",cdinfo.have_cdtext,		 cdinfo.have_cdextra);	if (cdinfo.title != NULL && cdinfo.artist != NULL) {		dodebug(2,"title/artist: %s/%s\n",cdinfo.title,cdinfo.artist);	} else {		dodebug(2,"title/artist: (NULL)/(NULL)\n");	}	if (cdinfo.cddb_dtitle != NULL) {		dodebug(2,"cddb_dtitle: %s\n",cdinfo.cddb_dtitle);	} else {		dodebug(2,"cddb_dtitle: (NULL)\n");	}	dodebug(2,"leadout: %d\n", cdinfo.leadout);	for (i = 0; i < cdinfo.nr_tracks; i++) {		dodebug(2,"track: %d start: %d size: %d\n",trackinfo[i]->track_nr,			trackinfo[i]->start_sec, trackinfo[i]->size);		dodebug(2,"       type: %d, rec_type: %d, preemp: %d, copyperm: %d, stereo: %d\n", 			trackinfo[i]->type, trackinfo[i]->rec_type,			trackinfo[i]->preemp, trackinfo[i]->copyperm,			trackinfo[i]->stereo);		/* check if we have any null-pointers lying around */		p1 = trackinfo[i]->title;		p2 = trackinfo[i]->artist;		p3 = trackinfo[i]->cddb_ttitle;		p4 = trackinfo[i]->volname;		if (p1 == NULL) p1 = tmp;		if (p2 == NULL) p2 = tmp;		if (p3 == NULL) p3 = tmp;		if (p4 == NULL) p4 = tmp;		dodebug(2,"       title/artist: %s/%s cddb_title: %s volname: %s\n", 			p1, p2, p3, p4);	}}/* interpret line for line the output of cdda2wav */void parse_toc(gchar *line) {gchar tmp[MAXLINE];gchar tmp2[MAXLINE];gchar tmp3[MAXLINE];gchar *p1;gint min,sec,frm;gint ret;	/* initial state */	if (tocstate == 0) {		/* first look for "Tracks" line */		if (strncmp(line,"Tracks:",7) == 0) {			strcpy(tmp,line+7);			p1 = strtok(tmp," ");			strcpy(tmp2,p1);			cdinfo.nr_tracks = atoi(tmp2);			p1 = strtok(NULL,"");			strcpy(tmp2,p1);			sscanf(tmp2,"%d:%d.%d",&min,&sec,&frm);						cdinfo.total_size = (min*60+sec)*75 + frm;		}		if (strncmp(line,"CDINDEX",7) == 0) {			/* we dont support cdindex right now */			;		}		if (strncmp(line,"CDDB",4) == 0) {			strcpy(tmp,line+15);			strip_string(tmp);			strcpy(cdinfo.cddb_discid,tmp);			/* check if the cd we have in the drive is the same			   as the last cd we got */			if (strcmp(cdinfo_cddb_title_bak, cdinfo.cddb_discid) == 0) {				cd_is_still_the_same = 1;			}				/* finished with state 0 */			tocstate = 1;		}		/* get next line from output */		return;	}	/* cd-text state */	if (tocstate == 1) {		if (strncmp(line,"CD-Text: detected",17) == 0) {			cdinfo.have_cdtext = 1;		}		if (strncmp(line,"CD-Text: not detected",21) == 0) {			cdinfo.have_cdtext = 0;		}		/* ignore any cd-text-output for now */		;		if (strncmp(line,"CD-Extra: ",10) == 0) {			/* see this as endmarker of cd-text section */			tocstate = 2;		}				/* dont return here because we may need the current line */	}	/* cd-extra state */	if (tocstate == 2) {		if (strncmp(line,"CD-Extra: detected",18) == 0) {			cdinfo.have_cdextra = 1;		}		if (strncmp(line,"CD-Extra: not detected",22) == 0) {			cdinfo.have_cdextra = 0;		}		/* ignore any cd-extra-output for now */		;				if (strncmp(line,"Album title:",12) == 0) {			/* see this as endmarker of cd-extra section */			tocstate = 3;		}		/* dont return here because we may need the current line */	}		/* toc-listing mode */	if (tocstate == 3) {		if (strncmp(line,"Album title:",12) == 0) {			strcpy(tmp,line+13);			strip_string(tmp);			ret = decode_title_artist(tmp,tmp2,tmp3);			if (ret != 0) {				g_error("got unexpected artist/title\n");			}				g_free(cdinfo.title);			cdinfo.title = g_strdup(tmp2);			g_free(cdinfo.artist);			cdinfo.artist = g_strdup(tmp3);		}		/* now the most complex part: the toc-list itself */		if (line[0] == 'T' && line[1] != 'h') {			parse_toc_line(line);		}			if (strncmp(line,"Leadout:",8) == 0) {			strcpy(tmp,line+8);			strip_string(tmp);			cdinfo.leadout = atoi(tmp);		}	}}/* call cdda2wav -J to get the cd-toc */void get_cd_toc(gint devnr) {gchar line[MAXLINE];gchar tmp[MAXLINE];gchar tmp2[MAXLINE];FILE *fpin;gint ret;	/* check if cd is loaded */	if (!check_medium_loaded(devnr)) {		/* not loaded */		cdinfo.nr_tracks = -1;		return;	}	cdinfo.have_cdtext = -1;	cdinfo.have_cdextra = -1;	cdinfo.nr_tracks = -1;	tocstate = 0;	tocnr = 0;	cd_is_still_the_same = 0;	/* get bus,id,lun string */	if (convert_devnr2busid(devnr,tmp) != 0) {		g_error("non existing cdrom?");	}	/* backup cddb-value to check if the new cd is the same as	   the last we read */	strcpy(cdinfo_cddb_title_bak, cdinfo.cddb_discid);	/* build command line */	get_spawn_path(CDDA2WAV,tmp2);	g_snprintf(line,MAXLINE,"%s -D %s -J -g -Q -H -v1 2>&1",		tmp2,tmp);	dodebug(1,"calling: %s\n", line);        if ((fpin = popen(line,"r")) == NULL) {                g_error("popen error\n");        }        for (;;) {                if (fgets(line,MAXLINE,fpin) == NULL)                         break;		dodebug(10,"readtoc: %s", line);		parse_toc(line);        }	ret = pclose(fpin);        if (ret == -1) {                g_error("pclose error\n");        }	/* error while reading tracks? */	if (ret != 0 && cdinfo.nr_tracks != tocnr) {		cdinfo.nr_tracks = -2;	}	/* cd loaded but not readable = empty recordable? */	if (ret != 0 && cdinfo.nr_tracks < 1 ) {		cdinfo.nr_tracks = -2;	}	/* if cd changed, clear out cddb_dtitle */	if (cd_is_still_the_same == 0) {		g_free(cdinfo.cddb_dtitle);		cdinfo.cddb_dtitle = NULL;	}		if (debug) print_cdinfo();}/* start subprocess and reroute stdin and stdout *//* use /bin/sh to spawn subprocess */pid_t full_dpl_pipe_shell(gint *out, gint *in, gchar *cmd) {gint fd1[2], fd2[2];pid_t pid;	if (pipe(fd1) <0 || pipe(fd2) <0) {		g_error("pipe error\n");	}	if (( pid = fork()) < 0) {		g_error("fork error\n");	} else 	if (pid > 0) {		/* parent */		close(fd1[0]);		close(fd2[1]);		/* return new stdout/stdin of child */		if (in != NULL) 			*in = fd1[1];		else			close(fd1[1]);		if (out != NULL)			*out = fd2[0];		else			close(fd2[0]);	} else {		/* child */		close(fd1[1]);		close(fd2[0]);		/* reroute stdin from child */		if (fd1[0] != STDIN_FILENO) {			if (dup2(fd1[0], STDIN_FILENO) != STDIN_FILENO) {				g_error("dup2 error on stdin\n");			}			close(fd1[0]);		}		/* reroute stdout from child */		if (fd2[1] != STDOUT_FILENO) {			if (dup2(fd2[1], STDOUT_FILENO) != STDOUT_FILENO) {				g_error("dup2 error on stdout\n");			}			close(fd2[1]);		}		/* startup child */		if (execl("/bin/sh", "sh", "-c", cmd ,NULL) < 0) {			g_error("execl error\n");		} 	}	return(pid);}/* rebuild a cmdline-string into a list of arguments..handle quotes and   escaped chars nicely */void rebuild_cmdline(char **arglist, gchar *cmd, gchar *callpath) {gchar tmp[MAXLINE];gchar *p;gint n, count, start, in_quotes;gchar oldc, c;	n = 0;	count = 0;	start = 0;	in_quotes = 0;	oldc = '\0';	for (n = 0; n <= strlen(cmd); n++) {		c = cmd[n];		/* quotes found? search for closing quote */		/* ignore escaped quotes */		if (c == '\"' && oldc != '\\') {			if (in_quotes == 0) {				in_quotes = 1;			} else {				/* end-quote found */				in_quotes = 0;			}		}		oldc = c;		/* space is delimitor between args */		if (in_quotes == 0 && (c == ' ' || c == '\0')) {			strncpy(tmp,cmd+start,n-start);			tmp[n-start] = '\0';			/* skip empty args */			if (n-start == 0) {				continue;			}			strip_string(tmp);			/* tmp does contain now our substr -			   remove surrounding quotes if any and			   remove any escaped-chars */			if (tmp[0] == '\"') {				p = tmp + 1;			} else {				p = tmp;			} 			if (tmp[strlen(tmp)-1] == '\"') {				tmp[strlen(tmp)-1] = '\0';			}			escape_parse(p); 			/* empty unquoted string? skip */			if (p == tmp && strcmp(p,"") == 0) {				continue;			}				arglist[count] = g_strdup(p);			count++;			start = n+1;		}			if (count >= MAXPIPEARGS) {			g_error("Error: More than %d cmd arguments given\n",MAXPIPEARGS);		}

⌨️ 快捷键说明

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