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

📄 io.c

📁 -一个LINUX下的使用方&#63845 的CD-ROM刻录软件,开放源码
💻 C
📖 第 1 页 / 共 5 页
字号:
	}	/* now remove path from first argument */	strcpy(callpath,arglist[0]);	strcpy(tmp,arglist[0]);	p = rindex(tmp,'/');	if (p != NULL) {		g_free(arglist[0]);		arglist[0] = g_strdup(p+1);	}		/* now arglist is finished */	/* output generated argument-list */	if (debug) {		dodebug(11,"----- created argument array for execv -----\n");		count = 0;		dodebug(11,":%s:\n",callpath);		while(arglist[count]) {			dodebug(11,":%s:\n",arglist[count]);			count++;		}	}}/* start subprocess and reroute stdin, stderr and stdout *//* does NOT use the shell as spawner */pid_t full_dpl_pipe3(gint *out, gint *in, gint *err, gchar *cmd) { gint fd1[2], fd2[2], fd3[2];gchar **arglist;gchar callpath[MAXLINE];pid_t pid;gint count;	/* rebuild cmdline to array of args for execv */	arglist = g_new0(gchar *, MAXPIPEARGS);	rebuild_cmdline(arglist, cmd, callpath);	/* do the pipe-stuff */	if (pipe(fd1) <0 || pipe(fd2) <0 || pipe(fd3) <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]);		close(fd3[1]);		/* return new stdout/stdin/stderr of child */		if (in != NULL) 			*in = fd1[1];		else			close(fd1[1]);		if (out != NULL)			*out = fd2[0];		else			close(fd2[0]);		if (err != NULL)			*err = fd3[0];		else 			close(fd3[0]);	} else {		/* child */		close(fd1[1]);		close(fd2[0]);		close(fd3[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]);		}		/* reroute stderr from child */		if (fd3[1] != STDERR_FILENO) {			if (dup2(fd3[1], STDERR_FILENO) != STDERR_FILENO) {				g_error("dup2 error on stderr\n");			}			close(fd3[1]);		}		/* startup child */		if (execv(callpath,arglist) < 0) {			g_error("execv error\n");		} 	}	/* free arglist */	count = 0;	while(arglist[count]) {		g_free(arglist[count]);		count++;	}	g_free(arglist);	return(pid);}/* start two subprocesses and connect stdout of the first with stdin   of the second (proc1 | proc2) and reroute stdin and stderr of the   first and stdout and stderr of the second *//* returns pidnr1 and pidnr2 */void full_dpl_pipe4(pid_t *pidnr1, pid_t *pidnr2, gint *in1, gint *err1, 		    gchar *cmd, gint *out2, gint *err2, gchar *cmd2) {gint fd1[2], fd2[2], fd3[2], fd4[2], pipefd[2];gchar **arglist;gchar **arglist2;gchar callpath[MAXLINE];gchar callpath2[MAXLINE];pid_t pid, pid2;gint count;	/* rebuild cmdline to array of args for execv */	arglist = g_new0(gchar *, MAXPIPEARGS);	arglist2 = g_new0(gchar *, MAXPIPEARGS);	rebuild_cmdline(arglist, cmd, callpath);	rebuild_cmdline(arglist2, cmd2, callpath2);	/* do the pipe-stuff */	if (pipe(fd1) <0 || pipe(fd2) <0 || pipe(fd3) <0 || pipe(fd4) <0	   || pipe(pipefd) <0 ) {		g_error("pipe error\n");	}	/* fork for first process */	if (( pid = fork()) < 0) {		g_error("fork error\n");	} else 	if (pid > 0) {		/* parent */		close(fd1[0]);		close(fd2[1]);		close(pipefd[1]);		/* return new fds of child */		if (in1 != NULL) 			*in1 = fd1[1];		else			close(fd1[1]);		if (err1 != NULL)			*err1 = fd2[0];		else			close(fd2[0]);	} else {		/* child */		close(fd1[1]); 		close(fd2[0]);		close(pipefd[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 stderr from child */		if (fd2[1] != STDERR_FILENO) {			if (dup2(fd2[1], STDERR_FILENO) != STDERR_FILENO) {				g_error("dup2 error on stdout\n");			}			close(fd2[1]);		}		/* reroute stdout from child to second child */		if (pipefd[1] != STDOUT_FILENO) {			if (dup2(pipefd[1], STDOUT_FILENO) != STDOUT_FILENO) {				g_error("dup2 error on stdout\n");			}			close(pipefd[1]); 		} 		/* startup first child */		if (execv(callpath,arglist) < 0) {			g_error("execv error\n");		}	}	/* fork for second process */	if (( pid2 = fork()) < 0) {		g_error("fork error\n");	} else 	if (pid2 > 0) {		/* parent */		close(fd3[1]);		close(fd4[1]);		close(pipefd[0]);		/* return new fds of child */		if (out2 != NULL)			*out2 = fd3[0];		else			close(fd3[0]);		if (err2 != NULL)			*err2 = fd4[0];		else 			close(fd4[0]);	} else {		/* child */		close(fd3[0]);		close(fd4[0]);		close(pipefd[1]);		/* reroute stdin from first child */		if (pipefd[0] != STDIN_FILENO) {			if (dup2(pipefd[0], STDIN_FILENO) != STDIN_FILENO) {				g_error("dup2 error on stdin\n");			}			close(pipefd[0]); 		}		/* reroute stderr from child */		if (fd4[1] != STDERR_FILENO) {			if (dup2(fd4[1], STDERR_FILENO) != STDERR_FILENO) {				g_error("dup2 error on stdout\n");			}			close(fd4[1]);		}		/* reroute stdout from child to second child */		if (fd3[1] != STDOUT_FILENO) {			if (dup2(fd3[1], STDOUT_FILENO) != STDOUT_FILENO) {				g_error("dup2 error on stdout\n");			}			close(fd3[1]);		}		/* startup second child */		if (execv(callpath2,arglist2) < 0) {			g_error("execv error\n");		}	}	/* free arglists */	count = 0;	while(arglist[count]) {		g_free(arglist[count]);		count++;	}	g_free(arglist);	count = 0;	while(arglist2[count]) {		g_free(arglist2[count]);		count++;	}	g_free(arglist2);	/* return pids by call by reference */	*pidnr1 = pid;	*pidnr2 = pid2;}/* get the master-volume *//* return val 0..100 or -1 or error */gint query_mixer() {gint mix;#ifdef linuxgint val;#endif#ifdef sunaudio_info_t ainfo;#endif#ifdef hpuxstruct audio_gains again;#endif	if (strcmp(setupdata.mix_device,"") == 0) {		/* no mixer found - ignore */		return -1;	}#ifdef linux	dodebug(10,"quering mixer %s\n", setupdata.mix_device);	mix = open(setupdata.mix_device, O_RDWR);	if (mix < 0) {		g_warning("Can't open mixer-device %s\n", setupdata.mix_device);		return -1;	}	if (ioctl(mix,MIXER_READ(0),&val) == -1) {		g_warning("Error reading mixer\n");		return -1;	}		close(mix);	/* average val of both channels */	return ((val & 0x7f) + ((val >> 8) & 0x7f))/2;#endif#ifdef sun	dodebug(10,"quering mixer %s\n", setupdata.mix_device);	mix = open(setupdata.mix_device, O_RDONLY);	if (mix < 0) {		g_warning("Can't open mixer-device %s\n", setupdata.mix_device);		return -1;	}	if (ioctl(mix, AUDIO_GETINFO, &ainfo) == -1) {		g_warning("Error reading mixer\n");		return -1;	}	close(mix);	return ((gint) ((gfloat) ainfo.play.gain / 2.55));#endif#ifdef hpux       dodebug(10,"quering mixer %s\n", setupdata.mix_device);       mix = open(setupdata.mix_device, O_RDONLY);       if (mix < 0) {               g_warning("Can't open mixer-device %s\n", setupdata.mix_device);               return -1;       }       if (ioctl(mix, AUDIO_GET_GAINS, &again) == -1) {               g_warning("Error reading mixer\n");               return -1;       }       close(mix);       return ((gint) ((gfloat) again.transmit_gain / AUDIO_MAX_GAIN * 100));#endif	return 0;}/* set the master-volume *//* returns 0 on ok, -1 on error */gint set_mixer(gint val) {gint mix;#ifdef sunaudio_info_t ainfo;#endif#ifdef hpuxstruct audio_gains again;#endif	if (strcmp(setupdata.mix_device,"") == 0) {		/* no mixer found - ignore */		return -1;	}#ifdef linux	dodebug(10,"setting mixer %s to %d\n", setupdata.mix_device, val);	mix = open(setupdata.mix_device, O_RDWR);	if (mix < 0) {		g_warning("Can't open mixer-device\n");		return -1;	}	val |= val << 8;	if (ioctl(mix, MIXER_WRITE(0), &val) == -1) {		g_warning("Error writing mixer\n");		return -1;	}	close(mix);#endif #ifdef sun	dodebug(10,"setting mixer %s to %d\n", setupdata.mix_device, val);	mix = open(setupdata.mix_device, O_WRONLY);	if (mix < 0) {		g_warning("Can't open mixer-device %s\n", setupdata.mix_device);		return -1;	}	AUDIO_INITINFO(&ainfo);	ainfo.play.gain = (gint) (2.55 * (gfloat) val);	if (ioctl(mix, AUDIO_SETINFO, &ainfo) == -1) {		g_warning("Error writing mixer\n");		return -1;	}	close(mix);#endif#ifdef hpux       dodebug(10,"setting mixer %s to %d\n", setupdata.mix_device, val);       mix = open(setupdata.mix_device, O_WRONLY);       if (mix < 0) {               g_warning("Can't open mixer-device %s\n", setupdata.mix_device);               return -1;       }       if (ioctl(mix, AUDIO_GET_GAINS, &again) == -1) {               g_warning("Error reading mixer\n");               return -1;       }       again.transmit_gain = (gint) (AUDIO_MAX_GAIN / 100 * (gfloat) val);       if (ioctl(mix, AUDIO_SET_GAINS, &again) == -1) {               g_warning("Error writing mixer\n");               return -1;       }       close(mix);#endif	return 0;	}/* send SIGINT to a cdda2wav/readcd/cdrecord process (btw to its child)    and hope that it terminates at it own */void kill_readcdda() {	if (readcdda_pid != -1) {		dodebug(2,"sending SIGINT to %d\n", (gint) readcdda_pid);		kill(readcdda_pid, SIGINT);	}}/* in bulk mode update the info-label of read tracks */void update_bulk_readlabel() {gchar tmp[MAXLINE];gchar tmp2[MAXLINE];gint frms;	frms = writeparams.frames[read_tracknr];	convert_frames2mbminstring(frms, tmp);	g_snprintf(tmp2,MAXLINE,text(157), read_tracknr,			writeparams.nrtracks, tmp);	gtk_label_set_text(GTK_LABEL(readtrack_info_label), tmp2);}/* parse output of cdda2wav and update sliders */void read_cdda2wav_out(gpointer data, gint source, GdkInputCondition cond) {gint n;gint ret;gchar line[MAXLINE];gchar tmp[MAXLINE];gchar tmp2[MAXLINE];gchar *p;gint val, tnr, bulk;gfloat pval, pval2;	/* called for bulk or not? */	bulk = GPOINTER_TO_INT(data);	/* read output of cdda */	n = read_line(source, line, MAXLINE);	/* cdda-finished? */	if (n <= 0) {		gtk_input_remove(readcdda_callback);		/* pick up return status of child */		wait(&ret);		/* tell our caller that we are done here */		read_done = (ret >> 8);		return;	}	dodebug(10,"cdda2wav: %s\n", line);	/* scanning for indexes? */	if (strncmp(line,"index scan:", 11) == 0) {		strcpy(tmp,line+11);		p = strtok(tmp,".");		if (p != NULL) {			tnr = atoi(p);		} else {			tnr = 0;		}		g_snprintf(tmp,MAXLINE,text(317),tnr);		gtk_label_set_text(GTK_LABEL(readtrack_info_label),tmp);		}	/* found indices? */	if (strncmp(line,"track", 5) == 0) {		strcpy(tmp,line);		/* just output until first comma - looks nicer */		p = strtok(tmp,",");		if (p != NULL) {			strcpy(tmp2,p);		} else {			strcpy(tmp2,tmp);		}			strcat(tmp2,"\n");		gtk_text_insert(GTK_TEXT(readtrack_textview),			NULL,NULL,NULL, tmp2, strlen(tmp2));	}	/* scanning for MCN? */	if (strncmp(line,"scanning for MCN", 16) == 0) {		gtk_label_set_text(GTK_LABEL(readtrack_info_label),text(318));		}		/* scanning for ISRC? */	if (strncmp(line,"\rscanning for ISRCs:", 20) == 0) {		strcpy(tmp,line+21);		p = strtok(tmp,".");		if (p != NULL) {			tnr = atoi(p);		} else {			tnr = 0;		}		g_snprintf(tmp,MAXLINE,text(319),tnr);		gtk_label_set_text(GTK_LABEL(readtrack_info_label),tmp);		}		/* done with scanning? */	if (strncmp(line,"recording", 9) == 0) {		if (bulk == 0) {			/* restore original info text */			gtk_label_set_text(GTK_LABEL(readtrack_info_label),				readtrack_info_string);			} else {			update_bulk_readlabel();		}	}

⌨️ 快捷键说明

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