$OpenBSD: patch-grip_c,v 1.1.1.1 2001/05/19 00:21:00 lebel Exp $ --- grip.c.orig Wed Oct 18 15:12:53 2000 +++ grip.c Tue Apr 10 15:00:59 2001 @@ -38,7 +38,7 @@ #if defined(__linux__) #include #endif -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || defined(__OpenBSD__) #include #include #endif @@ -125,7 +125,7 @@ void SelectRow(GtkWidget *widget,gint ro GdkEventButton *event,gpointer data); void CDDBToggle(void); void LookupDisc(gboolean manual); -void DoLookup(void); +void *DoLookup(void *); gboolean CDDBLookupDisc(CDDBServer *server); void SubmitEntryCB(void); void SubmitEntry(void); @@ -156,6 +156,9 @@ void Usage(void); void ParseArgs(int numargs,char *args[]); void ShuffleTracks(int num_tracks); void MakeStyles(void); +void setCurrentTrackIndex(int track); +void ParseRipCmd(char *instr,char *outstr,int track,int startsec,int endsec, + char *filename); /* Rip-related functions */ @@ -211,7 +214,7 @@ GtkStyle *style_dark_grey; GdkCursor *wait_cursor; -int cd_desc; +int g_cd_desc; int changer_slots; int current_disc=0; int volume=255; @@ -792,7 +795,7 @@ void PlaylistChanged(void) InitProgram(info.disc_totaltracks,play_mode); - if(CDDBWriteDiscData(cd_desc,&ddata,NULL,TRUE)<0) + if(CDDBWriteDiscData(g_cd_desc,&ddata,NULL,TRUE)<0) DisplayMsg("Error saving disc data\n"); } @@ -854,7 +857,7 @@ void SetYear(int year) void SaveDiscInfo(void) { if(have_disc) { - if(CDDBWriteDiscData(cd_desc,&ddata,NULL,TRUE)<0) + if(CDDBWriteDiscData(g_cd_desc,&ddata,NULL,TRUE)<0) DisplayMsg("Error saving disc data\n"); } else BoolDialog("No disc present","OK",NULL,NULL,NULL); @@ -974,7 +977,7 @@ void SetVolume(GtkWidget *widget,gpointe volume=vol.vol_front.left=vol.vol_front.right= vol.vol_back.left=vol.vol_back.right=GTK_ADJUSTMENT(widget)->value; - CDSetVolume(cd_desc,&vol); + CDSetVolume(g_cd_desc,&vol); } void NextTrack(void) @@ -986,7 +989,7 @@ void NextTrack(void) } #endif - CDStat(cd_desc,&info,FALSE); + CDStat(g_cd_desc,&info,FALSE); if(current_track_index<(prog_totaltracks-1)) { gtk_clist_select_row(GTK_CLIST(trackclist), @@ -1009,7 +1012,7 @@ void PrevTrack(void) } #endif - CDStat(cd_desc,&info,FALSE); + CDStat(g_cd_desc,&info,FALSE); if((info.disc_mode==CDAUDIO_PLAYING) && ((info.disc_frame - info.track[info.disc_track-1].track_start) > 100)) @@ -1120,7 +1123,7 @@ void FastFwd(void) tv.seconds=5; if((info.disc_mode==CDAUDIO_PLAYING)||(info.disc_mode==CDAUDIO_PAUSED)) { - CDAdvance(cd_desc,&info,&tv); + CDAdvance(g_cd_desc,&info,&tv); } } @@ -1146,7 +1149,7 @@ void Rewind(void) tv.seconds=-5; if((info.disc_mode==CDAUDIO_PLAYING)||(info.disc_mode==CDAUDIO_PAUSED)) { - CDAdvance(cd_desc,&info,&tv); + CDAdvance(g_cd_desc,&info,&tv); } } @@ -1161,7 +1164,7 @@ void NextDisc(void) if(changer_slots>1) { current_disc=(current_disc+1)%changer_slots; - CDChangerSelectDisc(cd_desc,current_disc); + CDChangerSelectDisc(g_cd_desc,current_disc); have_disc=FALSE; } } @@ -1172,8 +1175,8 @@ void StopPlay(void) if(ripping) return; #endif - CDStop(cd_desc); - CDStat(cd_desc,&info,FALSE); + CDStop(g_cd_desc); + CDStat(g_cd_desc,&info,FALSE); stopped=TRUE; if(stop_first) @@ -1197,8 +1200,8 @@ void EjectDisc(void) if(have_disc) { Debug("Have disc -- ejecting\n"); - CDStop(cd_desc); - CDEject(cd_desc); + CDStop(g_cd_desc); + CDEject(g_cd_desc); playing=0; have_disc=FALSE; update_required=TRUE; @@ -1207,12 +1210,12 @@ void EjectDisc(void) } else { if(faulty_eject) { - if(tray_open) CDClose(cd_desc); - else CDEject(cd_desc); + if(tray_open) CDClose(g_cd_desc); + else CDEject(g_cd_desc); } else { - if(TrayOpen(cd_desc)!=0) CDClose(cd_desc); - else CDEject(cd_desc); + if(TrayOpen(g_cd_desc)!=0) CDClose(g_cd_desc); + else CDEject(g_cd_desc); } tray_open=!tray_open; @@ -1232,7 +1235,7 @@ void PlayTrackCB(GtkWidget *widget,gpoin } #endif - CDStat(cd_desc,&info,FALSE); + CDStat(g_cd_desc,&info,FALSE); if(play_mode!=PM_NORMAL&&!((info.disc_mode==CDAUDIO_PLAYING)|| info.disc_mode==CDAUDIO_PAUSED)) { @@ -1247,11 +1250,11 @@ void PlayTrackCB(GtkWidget *widget,gpoin if(track==(info.disc_track-1)) { switch(info.disc_mode) { case CDAUDIO_PLAYING: - CDPause(cd_desc); + CDPause(g_cd_desc); return; break; case CDAUDIO_PAUSED: - CDResume(cd_desc); + CDResume(g_cd_desc); return; break; default: @@ -1267,8 +1270,8 @@ void PlayTrack(int track) Busy(); if(play_mode==PM_NORMAL) - CDPlayTrack(cd_desc,&info,track+1,info.disc_totaltracks); - else CDPlayTrack(cd_desc,&info,track+1,track+1); + CDPlayTrack(g_cd_desc,&info,track+1,info.disc_totaltracks); + else CDPlayTrack(g_cd_desc,&info,track+1,track+1); UnBusy(); @@ -1288,16 +1291,16 @@ void CheckNewDisc(void) if(!looking_up) { Debug("Checking for a new disc\n"); - if( (CDStat(cd_desc,&info,FALSE) == 0) + if( (CDStat(g_cd_desc,&info,FALSE) == 0) && info.disc_present - && (CDStat(cd_desc,&info,TRUE) == 0) ) { + && (CDStat(g_cd_desc,&info,TRUE) == 0) ) { Debug("CDStat found a disc, checking tracks\n"); if(CheckTracks()) { Debug("We have a valid disc!\n"); - new_id=CDDBDiscid(cd_desc); + new_id=CDDBDiscid(g_cd_desc); InitProgram(info.disc_totaltracks,play_mode); if(play_first) if(info.disc_mode == CDAUDIO_COMPLETED || @@ -1352,7 +1355,7 @@ void UpdateDisplay(void) if(!update_required) { if(have_disc) { - CDStat(cd_desc,&info,FALSE); + CDStat(g_cd_desc,&info,FALSE); if((info.disc_mode==CDAUDIO_PLAYING)|| (info.disc_mode==CDAUDIO_PAUSED)) { @@ -1420,7 +1423,7 @@ void UpdateDisplay(void) if(!stopped) PlayTrack(CURRENT_TRACK); } else if(stopped) { - CDStop(cd_desc); + CDStop(g_cd_desc); #ifndef GRIPCD frames=secs=mins=0; g_snprintf(buf,80,"Current sector: %6d",frames); @@ -1654,7 +1657,7 @@ void CDDBToggle(void) if(looking_up) { #ifdef SOLARIS pthread_exit(&status); -#elif defined(__FreeBSD__) +#elif defined(__FreeBSD__) || defined(__OpenBSD__) pthread_kill(cddb_thread, 0); #else pthread_kill_other_threads_np(); @@ -1682,15 +1685,15 @@ void LookupDisc(gboolean manual) ddata.data_multi_artist=FALSE; ddata.data_year=0; - present=CDDBStatDiscData(cd_desc); + present=CDDBStatDiscData(g_cd_desc); if(!manual&&present) { - CDDBReadDiscData(cd_desc,&ddata); + CDDBReadDiscData(g_cd_desc,&ddata); update_required=TRUE; } else { if(!manual) { - ddata.data_id=CDDBDiscid(cd_desc); + ddata.data_id=CDDBDiscid(g_cd_desc); ddata.data_genre=7; /* "misc" */ strcpy(ddata.data_title,"Unknown Disc"); strcpy(ddata.data_artist,""); @@ -1710,15 +1713,23 @@ void LookupDisc(gboolean manual) if(!local_mode && (manual?TRUE:automatic_cddb)) { looking_up=TRUE; - pthread_create(&cddb_thread,NULL,(void *)&DoLookup,NULL); + Debug("creating cddb lookup thread.\n"); + pthread_create(&cddb_thread,NULL, DoLookup,NULL); +#if 1 + /* XXX: */ + Debug("join cddb lookup thread.\n"); + pthread_join(cddb_thread, NULL); +#endif } } } -void DoLookup(void) +void *DoLookup(void *unused) { int cddb_found = 0; + Debug("cddb lookup thread running.\n"); + if(!CDDBLookupDisc(&dbserver)) { if(*(dbserver2.name)) { if(CDDBLookupDisc(&dbserver2)) { @@ -1737,6 +1748,7 @@ void DoLookup(void) looking_up=FALSE; pthread_exit(0); + return (NULL); } gboolean CDDBLookupDisc(CDDBServer *server) @@ -1749,15 +1761,15 @@ gboolean CDDBLookupDisc(CDDBServer *serv if(server->use_proxy) Debug("Querying %s (through %s) for disc %02x.\n",server->name, server->proxy->name, - CDDBDiscid(cd_desc)); + CDDBDiscid(g_cd_desc)); else Debug("Querying %s for disc %02x.\n",server->name, - CDDBDiscid(cd_desc)); + CDDBDiscid(g_cd_desc)); strncpy(hello.hello_program,PROGRAM,256); strncpy(hello.hello_version,VERSION,256); - if(!CDDBDoQuery(cd_desc,server,&hello,&query)) { + if(!CDDBDoQuery(g_cd_desc,server,&hello,&query)) { update_required=TRUE; } else { switch(query.query_match) { @@ -1768,12 +1780,12 @@ gboolean CDDBLookupDisc(CDDBServer *serv query.query_list[0].list_title); entry.entry_genre = query.query_list[0].list_genre; entry.entry_id = query.query_list[0].list_id; - CDDBRead(cd_desc,server,&hello,&entry,&ddata); + CDDBRead(g_cd_desc,server,&hello,&entry,&ddata); Debug("Done\n"); success=TRUE; - if(CDDBWriteDiscData(cd_desc,&ddata,NULL,TRUE)<0) + if(CDDBWriteDiscData(g_cd_desc,&ddata,NULL,TRUE)<0) printf("Error saving disc data\n"); update_required=TRUE; @@ -1860,7 +1872,7 @@ void SubmitEntry(void) fprintf(efp , "To: %s\nFrom: %s\nSubject: cddb %s %02x\n\n", \ cddb_submit_email,user_email,CDDBGenre(ddata.data_genre), \ ddata.data_id); - if(CDDBWriteDiscData(cd_desc,&ddata,efp,FALSE)<0) { + if(CDDBWriteDiscData(g_cd_desc,&ddata,efp,FALSE)<0) { DisplayMsg("Error: Unable to write disc data"); fclose(efp); } @@ -1924,7 +1936,7 @@ void UpdateTracks(void) if(have_disc) { auto_eject_countdown=0; /* Reset to make sure we don't eject twice */ - current_discid=CDDBDiscid(cd_desc); + current_discid=CDDBDiscid(g_cd_desc); SetTitle(ddata.data_title); SetArtist(ddata.data_artist); @@ -3286,7 +3298,7 @@ GtkWidget *MakeControls(void) gtk_widget_set_name(volume_control,"darkgrey"); gtk_box_pack_start(GTK_BOX(vbox),volume_control,FALSE,FALSE,0); - /* CDGetVolume(cd_desc,&vol); + /* CDGetVolume(g_cd_desc,&vol); gtk_adjustment_set_value(GTK_ADJUSTMENT(adj),(vol.vol_front.left+ vol.vol_front.right)/2);*/ @@ -3770,7 +3782,7 @@ void ParseFileFmt(char *instr,char *outs else strncpy(outstr,"NoTitle",left); break; case 'i': - g_snprintf(outstr,PATH_MAX,"%02x",CDDBDiscid(cd_desc)); + g_snprintf(outstr,PATH_MAX,"%02x",CDDBDiscid(g_cd_desc)); break; #ifndef GRIPCD case 'g': @@ -3929,7 +3941,7 @@ void ParseEncFileFmt(char *instr,char *o /* Make file1 relative to file2 */ char *MakeRelative(char *file1,char *file2) { - int pos, pos2, slashcnt, i; + int pos, pos2 = 0, slashcnt, i; char *rel=file1; char tem[PATH_MAX]=""; @@ -4464,7 +4476,7 @@ void RedirectIO(gboolean redirect_output } close(fd); - close(cd_desc); + close(g_cd_desc); } void ID3Add(char *file,EncodeTrack *enc_track) @@ -4494,7 +4506,7 @@ void FillInEncode(int track,EncodeTrack strncpy(new_track->disc_name,ddata.data_title,80); strncpy(new_track->disc_artist,ddata.data_artist,80); new_track->id3_genre=id3_genre_number; - new_track->discid=CDDBDiscid(cd_desc); + new_track->discid=CDDBDiscid(g_cd_desc); } void AddToEncode(int track) @@ -4629,7 +4641,7 @@ void DoRip(GtkWidget *widget,gpointer da return; } - CDStop(cd_desc); + CDStop(g_cd_desc); stopped=TRUE; if(ripping) return; @@ -4753,7 +4765,7 @@ gboolean RipNextTrack(void) sprintf(tmp,"Rip: Trk %d (0.0x)",rip_track+1); gtk_label_set(GTK_LABEL(rip_prog_label),tmp); - CDStop(cd_desc); + CDStop(g_cd_desc); if(rip_partial) { startsec=start_sector; @@ -4854,7 +4866,7 @@ void PlaySegmentCB(GtkWidget *widget,gpo void PlaySegment(int track) { - CDPlayFrames(cd_desc,info.track[track].track_start+start_sector, + CDPlayFrames(g_cd_desc,info.track[track].track_start+start_sector, info.track[track].track_start+end_sector); } @@ -5220,8 +5232,8 @@ int main(int argc,char *argv[]) find_cdrom(); #endif - cd_desc=CDInitDevice(cddevice); - if(cd_desc==-1) { + g_cd_desc=CDInitDevice(cddevice); + if(g_cd_desc==-1) { BoolDialog("Unable to open the cd device. Please make sure that you are\n" "using the correct device (passed to the program with \"-d\")\n" "and that you have permission to access the device. See the\n" @@ -5232,9 +5244,9 @@ int main(int argc,char *argv[]) have_working_device=TRUE; if(!no_interrupt) - CDStop(cd_desc); + CDStop(g_cd_desc); - changer_slots=CDChangerSlots(cd_desc); + changer_slots=CDChangerSlots(g_cd_desc); CheckNewDisc(); UpdateDisplay(); @@ -5245,7 +5257,7 @@ int main(int argc,char *argv[]) gtk_main(); if(!no_interrupt) - CDStop(cd_desc); + CDStop(g_cd_desc); DoSaveConfig();