📄 io.c
字号:
/* look for a percent value */ if (line[strlen(line)-1] == '%') { /* skip leading linefeed if any */ if (line[0] == '\r') line[0] = ' '; /* look for last space */ p = rindex(line,' '); if (p != NULL) strcpy(tmp,p); else strcpy(tmp,line); tmp[strlen(tmp)-1] = '\0'; strip_string(tmp); val = atoi(tmp); pval = (gfloat)val/100; if (pval > 1.0) pval = 1.0; gtk_progress_set_percentage(GTK_PROGRESS(readtrack_pbar1), pval); /* now calculate how much percent he have at all */ if (bulk == 0) { pval2 = (pct_so_far + (pval * pct_this_track)) /100; if (pval2 > 1.0) pval2 = 1.0; } else { pval2 = (writeparams.pct_so_far_arr[read_tracknr] + (pval * writeparams.pct_this_track_arr[read_tracknr]))/100; } gtk_progress_set_percentage(GTK_PROGRESS(readtrack_pbar2), pval2); /* now update info for small view */ g_snprintf(tmp,MAXLINE,"%d%% / %d%%",(gint)(pval*100+0.5), (gint)(pval2*100+0.5)); gtk_label_set_text(GTK_LABEL(readtrack_small_info2),tmp); return; } /* track successfully recorded? */ if (strlen(line) > strlen("successfully recorded")) { strcpy(tmp, line+strlen(line)-strlen("successfully recorded")); if (strcmp(tmp, "successfully recorded") == 0) { gtk_progress_set_percentage(GTK_PROGRESS(readtrack_pbar1), 1.0); /* look for last % */ p = rindex(line,'%'); if (p != NULL) { strcpy(tmp,p+1); strip_string(tmp); } else strcpy(tmp,line); /* strips the 100% value from the string */ strip_string(tmp); strcpy(line,tmp); if (bulk == 1) { /* in bulkmode this means we switched tracks */ read_tracknr++; update_bulk_readlabel(); } } } /* get subprocess pid */ if (strncmp(line,"child pid", 9) == 0) { strcpy(tmp, line+12); readcdda_pid= (pid_t) atoi(tmp); return; } /* error-text? do display these in the next block */ if (strncmp(line,"Error",5) == 0) { read_output_ctrl = 1; } /* forward most other output to textview-window */ if (strncmp(line,"record",6) == 0 || read_output_ctrl == 1) { read_output_ctrl = 1; /* skip lines that do not interest us */ if (strncmp(line,"percent_done",12) == 0) { return; } if (strncmp(line,"overlap:min",11) == 0) { return; } strcat(line,"\n"); gtk_text_insert(GTK_TEXT(readtrack_textview), NULL,NULL,NULL, line, strlen(line)); } }/* parse dummy output of cdda2wav *//* output stdout of cdda2wav where never should any data be delivered */void read_cdda2wav_dummyout(gpointer data, gint source, GdkInputCondition cond) {gint n;gchar line[MAXLINE]; /* read output of cdda */ n = read_line(source, line, MAXLINE); /* cdda-finished? */ if (n <= 0) { gtk_input_remove(readcdda_callback2); return; } strcat(line,"\n"); gtk_text_insert(GTK_TEXT(readtrack_textview), NULL,NULL,NULL, line, strlen(line));}/* call cdda2wav to read an audio-track return 0 on success, 1 on error */gint read_audio_track(gint devnr, gint starttrack, gint endtrack, gint kbyte, gchar *fname, gint startoffset, gint endoffset, gint nrtracks, gfloat percent, gfloat percent_done, gint viewtrack) {gchar cmd[MAXLINE];gchar tmp[MAXLINE];gchar tmp2[MAXLINE];gchar tmp3[MAXLINE];gchar tmp4[MAXLINE];gchar tmp5[MAXLINE];gint read_in, read_out, read_dummy; /* if another read running, ignore */ if (read_done == 999) { return -1; } /* no filename given? */ if (fname == NULL) { return 1; } /* mark our read-process as running */ read_done = 999; read_output_ctrl = 0; readcdda_pid = -1; read_abort_mark = 0; /* set info-label */ convert_kbytes2mbminstring(kbyte, tmp); g_snprintf(tmp2,MAXLINE,text(157), viewtrack, nrtracks, tmp); gtk_label_set_text(GTK_LABEL(readtrack_info_label),tmp2); strcpy(readtrack_info_string, tmp2); g_snprintf(tmp2,MAXLINE,text(163), viewtrack, nrtracks); gtk_label_set_text(GTK_LABEL(readtrack_small_info),tmp2); /* get bus,id,lun string */ if (convert_devnr2busid(devnr,tmp) != 0) { g_error("non existing cdrom?"); } /* some stuff to have our slider moving smoothly no matter how big the tracks are */ pct_so_far = percent_done; pct_this_track = percent; /* build command line */ if (endtrack != 0) { g_snprintf(tmp2,MAXLINE,"%d+%d",starttrack,endtrack); } else { g_snprintf(tmp2,MAXLINE,"%d",starttrack); } /* set speed only when not zero */ if (curset.audioread_speed > 0) { g_snprintf(tmp3,MAXLINE,"-S %d", curset.audioread_speed); } else { strcpy(tmp3,""); } /* have to scan for indexes? */ if (curset.indexscan != 0) { strcpy(tmp4,"-i 1"); } else { strcpy(tmp4,""); } get_spawn_path(CDDA2WAV,tmp5); g_snprintf(cmd,MAXLINE, "%s -D %s -g -v2 -O wav -t %s %s %s -P %d -n %d \"%s\"", tmp5,tmp,tmp2,tmp3,tmp4, setupdata.audioread_overlap,setupdata.audioread_sectorburst, convert_escape(fname)); dodebug(1, "spawning: %s\n",cmd); dolog(2,"Read audio track %s\n", fname); dolog(3,"Executing: %s\n",cmd); /* start child and get new fds */ readcdda_pid = full_dpl_pipe3(&read_dummy,&read_in,&read_out,cmd); /* set output to nonblocking - otherwise our callback would block */ fcntl(read_out, F_SETFL, O_NONBLOCK); fcntl(read_dummy, F_SETFL, O_NONBLOCK); /* catch output of child */ readcdda_callback = gdk_input_add(read_out, GDK_INPUT_READ, (GdkInputFunction) read_cdda2wav_out, GINT_TO_POINTER(0)); readcdda_callback2 = gdk_input_add(read_dummy, GDK_INPUT_READ, (GdkInputFunction) read_cdda2wav_dummyout,NULL); /* now wait until track is read */ while (read_done == 999) { wait_and_process_events(); } close(read_out); close(read_in); close(read_dummy); gtk_text_insert(GTK_TEXT(readtrack_textview), NULL,NULL,NULL, "\n", 1); /* error while reading? */ if (read_done != 0 && read_abort_mark == 0) { g_snprintf(tmp,MAXLINE,text(159), starttrack, nrtracks); gtk_label_set_text(GTK_LABEL(readtrack_info_label),tmp); gtk_label_set_text(GTK_LABEL(readtrack_small_info),text(164)); return 1; } /* aborted? */ if (read_abort_mark == 1) { gtk_label_set_text(GTK_LABEL(readtrack_info_label),text(247)); return 1; } return 0;}/* call cdda2wav to read all audio tracks from a cd */gint start_bulk_read_action(gint devnr, gfloat percent_done, gint startnr) {GList *loop;track_read_param_t *trackparam;char tmp[MAXLINE];char tmptmp[MAXLINE];char tmp3[MAXLINE];char tmp4[MAXLINE];char tmp5[MAXLINE];char cmd[MAXLINE*10]; /* extra big buffer for very long cdrecord options */gint read_in, read_out, read_dummy;gint tracknr; /* if another read running, ignore */ if (read_done == 999) { return -1; } /* mark our read-process as running */ read_done = 999; read_output_ctrl = 0; pct_so_far = percent_done; read_tracknr = startnr; readcdda_pid = -1; read_abort_mark = 0; /* init track-label */ gtk_label_set_text(GTK_LABEL(readtrack_info_label), text(320)); strcpy(readtrack_info_string, ""); /* reset writeparams-arrays */ /* lets reuse this structure - even when we just read now */ g_free(writeparams.tracktype); g_free(writeparams.frames); g_free(writeparams.pct_so_far_arr); g_free(writeparams.pct_this_track_arr); writeparams.tracktype = g_new0(gint,MAXTRACKS); writeparams.frames = g_new0(gint,MAXTRACKS); writeparams.pct_so_far_arr = g_new0(gfloat,MAXTRACKS); writeparams.pct_this_track_arr = g_new0(gfloat,MAXTRACKS); writeparams.nrtracks = 0; writeparams.simulation = curset.writesimul; /* get bus,id,lun string */ if (convert_devnr2busid(devnr,tmp) != 0) { g_error("non existing cdrom?"); } /* set speed only when not zero */ if (curset.audioread_speed > 0) { g_snprintf(tmp3,MAXLINE,"-S %d", curset.audioread_speed); } else { strcpy(tmp3,""); } /* have to scan for indexes? */ if (curset.indexscan != 0) { strcpy(tmp4,"-v30"); } else { strcpy(tmp4,"-v2"); } get_spawn_path(CDDA2WAV,tmp5); g_snprintf(cmd,MAXLINE, "%s -D %s -g -O wav %s %s -P %d -n %d -B", tmp5,tmp,tmp3,tmp4, setupdata.audioread_overlap,setupdata.audioread_sectorburst ); tracknr = startnr; /* now add all track-filenames (only audio) */ loop = g_list_first(trackreadset.trackparams); while(loop) { trackparam = loop->data; if (trackparam->trackfile != NULL && trackparam->tracktype == 1) { strcpy(tmptmp, trackparam->trackfile); g_snprintf(tmp, MAXLINE, " \"%s\"", convert_escape(tmptmp)); strcat(cmd, tmp); /* fill up percent values for percentbar */ writeparams.tracktype[tracknr] = trackparam->tracktype; writeparams.frames[tracknr] = trackparam->frames; writeparams.pct_this_track_arr[tracknr] = trackparam->percent; writeparams.pct_so_far_arr[tracknr] = pct_so_far; pct_so_far += trackparam->percent; writeparams.nrtracks++; tracknr++; } loop = loop->next; } /* correct full nr of tracks (so we have the full count of tracks) */ writeparams.nrtracks+=startnr-1; dodebug(1, "spawning: %s\n",cmd); dolog(2,"Read all audio tracks\n"); dolog(3,"Executing: %s\n",cmd); /* start child and get new fds */ readcdda_pid = full_dpl_pipe3(&read_dummy,&read_in,&read_out,cmd); /* set output to nonblocking - otherwise our callback would block */ fcntl(read_out, F_SETFL, O_NONBLOCK); /* catch output of child */ readcdda_callback = gdk_input_add(read_out, GDK_INPUT_READ, (GdkInputFunction) read_cdda2wav_out, GINT_TO_POINTER(1)); readcdda_callback2 = gdk_input_add(read_dummy, GDK_INPUT_READ, (GdkInputFunction) read_cdda2wav_dummyout,NULL); /* now wait until track is read */ while (read_done == 999) { wait_and_process_events(); } close(read_out); close(read_in); close(read_dummy); gtk_text_insert(GTK_TEXT(readtrack_textview), NULL,NULL,NULL, "\n", 1); /* error while reading? */ if (read_done != 0 && read_abort_mark == 0) { g_snprintf(tmp,MAXLINE,text(159), read_tracknr, writeparams.nrtracks); gtk_label_set_text(GTK_LABEL(readtrack_info_label),tmp); gtk_label_set_text(GTK_LABEL(readtrack_small_info),text(164)); return 1; } /* aborted? */ if (read_abort_mark == 1) { gtk_label_set_text(GTK_LABEL(readtrack_info_label),text(247)); return 1; } return 0;}/* parse output of readcd and update sliders */void read_readcd_out(gpointer data, gint source, GdkInputCondition cond) {gint n;gint ret;gchar line[MAXLINE];gchar tmp[MAXLINE];gchar tmp2[MAXLINE];gint val;gfloat pval, pval2; /* read output of readcd */ n = read_line(source, line, MAXLINE); /* readcd-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 */ if ((ret >> 8) == 0 && read_output_ctrl == 0) { /* readcd does return status 0 when killed - override */ read_done = 1; } else { read_done = (ret >> 8); } return; } dodebug(10,"readcd: %s\n", line); /* look for end value */ if (strncmp(line,"end:",4) == 0) { strcpy(tmp,line+4); strip_string(tmp); readcd_endsector = atoi(tmp); return; } /* look for a percent value */ if (strncmp(line,"addr:",5) == 0) { /* skip leading linefeed if any */ if (line[0] == '\r') strcpy(tmp,line+6); else strcpy(tmp,line+5); strip_string(tmp); strcpy(tmp2,strtok(tmp," ")); val = atoi(tmp2) - readcd_startsector; /* if not set yet, do nothing */ if (readcd_endsector == 0) return; pval = (gfloat)val/(gfloat)(readcd_endsector - readcd_startsector); if (pval > 1.0) pval = 1.0; gtk_progress_set_percentage(GTK_PROGRESS(readtrack_pbar1), pval); /* now calculate how much percent he has at all */ pval2 = (pct_so_far + (pval * pct_this_track)) /100; if (pval2 > 1.0) pval2 = 1.0; gtk_progress_set_percentage(GTK_PROGRESS(readtrack_pbar2), pval2); /* now update info for small view */ g_snprintf(tmp,MAXLINE,"%d%% / %d%%",(gint)(pval*100+0.5), (gint)(pval2*100+0.5)); gtk_label_set_text(GTK_LABEL(readtrack_small_info2),tmp); return; } /* look if last expected line from readcd came */ if (strncmp(line,"Read",4) == 0) { /* ok...now we can expect that we were not aborted */ read_output_ctrl = 1; } /* forward most other output to textview-window */ strcat(line,"\n"); gtk_text_insert(GTK_TEXT(readtrack_textview), NULL,NULL,NULL, line, strlen(line));}/* call readcd to read a data-track return 0 on success, 1 on error */gint read_data_track(gint devnr, gint starttrack, gint kbyte, gchar *fname, gint startoffset, gint endoffset, gint nrtracks, gfloat percent, gfloat percent_done, gint viewtrack) {gchar cmd[MAXLINE];gchar tmp[MAXLINE];gchar tmptmp[MAXLINE];gchar tmp2[MAXLINE];gchar tmp3[MAXLINE];gint read_in, read_out; /* if another read running, ignore */ if (read_done == 999) { return -1; } /* no filename given? */ if (fname == NULL) { return 1; } /* mark our read-process as running */ read_done = 999; readcdda_pid = -1; read_output_ctrl = 0; readcd_startsector = startoffset; readcd_endsector = 0; read_abort_mark = 0; /* set info-label */ convert_kbytes2mbminstring(kbyte, tmp); g_snprintf(tmp2,MAXLINE,text(158), viewtrack, nrtracks, tmp); gtk_label_set_text(GTK_LABEL(readtrack_info_label),tmp2); g_snprintf(tmp2,MAXLINE,text(163), viewtrack, nrtracks); gtk_label_set_text(GTK_LABEL(readtrack_small_info),tmp2); /* get bus,id,lun string */ if (convert_devnr2busid(devnr,tmp) != 0) { g_error("non existing cdrom?"); } /* some stuff to have our slider moving smoothly no matter how big the tracks are */ pct_so_far = percent_done; pct_this_track = percent; get_spawn_path(READCD,tmp3); strcpy(tmptmp,fname); g_snprintf(cmd,MAXLINE, "%s dev=%s sectors=%d-%d -s f= \"%s\"", tmp3, tmp, startoffset, endoffset, convert_escape(tmptmp)); dodebug(1, "spawning: %s\n",cmd); dolog(2,"Read data track %s\n", fname); dolog(3,"Executing: %s\n",cmd); /* start child and get new fds */ readcdda_pid = full_dpl_pipe3(NULL,&read_in,&read_out,cmd); /* set output to nonblocking - otherwise our callback would block */ fcntl(read_out, F_SETFL, O_NONBLOCK); /* catch output of child */ readcdda_callback = gdk_input_add(read_out, GDK_INPUT_READ, (GdkInputFunction) read_readcd_out, NULL); /* now wait until track is read */ while (read_done == 999) { wait_and_process_events(); } close(read_out); close(read_in); gtk_text_insert(GTK_TEXT(readtrack_textview), NULL,NULL,NULL, "\n", 1); /* error while reading
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -