📄 io.c
字号:
gint match,count;FILE *fpin;gchar *p; if (write_devnr == -1) return; /* free structure first */ if (drv_options != NULL) { count = 0; while (drv_options[count] != NULL) { g_free(drv_options[count]->driver); g_free(drv_options[count]->desc); g_free(drv_options[count]); count++; } g_free(drv_options); drv_options = NULL; drvoptcount = 0; } /* get bus,id,lun string */ if (convert_devnr2busid(write_devnr,tmp) != 0) { g_error("non existing cdrom?"); } get_spawn_path(CDRECORD,tmp2); g_snprintf(line, MAXLINE, "%s dev=%s driveropts=help -checkdrive 2>&1 >/dev/null", tmp2, tmp); dodebug(1, "calling: %s\n", line); if ((fpin = popen(line,"r")) == NULL) { g_error("popen error\n"); } match = 0; for (;;) { if (fgets(line,MAXLINE,fpin) == NULL) break; dodebug(10, "driveroptions: %s",line); if (strncmp(line,"Driver options:", 15) == 0) { match = 1; continue; } if (match) { p = strtok(line," \t"); if (p) { strcpy(tmp,p); p = strtok(NULL,""); if (p) { strcpy(tmp2,p); add_drv_option(tmp,tmp2); } } } } if (pclose(fpin) == -1) { g_error("pclose error\n"); } if (debug) print_drv_options();}gint parse_freespace(gchar *line, gchar *fs) {gchar tmp[MAXLINE];gchar *p1; /* skip first line */ if (strncmp(line,"Filesystem",10) != 0) { /* skip the first 4 fields in output to come to "available" */ strcpy(tmp,line); /* are we handling the first line of two?*/ p1=strtok(tmp," "); if (dfrun == 0) { if (fs != NULL) { /* get the filesystem */ strcpy(fs,p1); } p1=strtok(NULL," "); if (p1 == NULL) { /* ok..output splitted on two lines */ dfrun = 1; return -1; } } p1=strtok(NULL," "); if (p1 == NULL) { g_error("df -k output syntax error\n"); } p1=strtok(NULL," "); if (p1 == NULL) { g_error("df -k output syntax error\n"); } return (atoi(p1)); } return -1;}/* get free diskspace. return in 1024byte blocks or -1 if not valid *//* return filesystem if not set to NULL *//* will handle if output is in two lines...like when the filesystem output is longer that 20 chars - e.g. on nfs-links *//* will handle df-output like:(Solaris)Filesystem kbytes used avail capacity Mounted onfileserv:/export/home 17502608 11609120 5718464 67% /export/homeOR(Linux)Filesystem 1024-blocks Used Available Capacity Mounted on/dev/sda3 2494898 1606489 759428 68% /*/gint get_free_space(gchar *path, gchar *filesystem) {gchar line[MAXLINE];FILE *fpin;gint space; space = -1; dfrun = 0; if (is_directory(path) != 1) { return -1; } strcpy(line,DF); strcat(line," "); strcat(line,path); 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,"df: %s",line); space = parse_freespace(line,filesystem); } if (pclose(fpin) == -1) { g_error("pclose error\n"); } if (filesystem != NULL) { dodebug(2, "filesystem lookup for %s = %d blocks, fs = %s\n", path, space, filesystem); } else { dodebug(2, "filesystem lookup for %s = %d blocks, fs = %s\n", path, space, "(NULL)"); } return space;}/* get a list of all audio-devices found on a system. This has to be done platform dependent */GList *get_dsp_devices() {GList *dsp;GList *loop;struct stat buf;#ifdef sungchar *audiodev;#endif dsp = NULL;#ifdef linux /* for linux check if /dev/dsp or /dev/dsp1 exist */ if (stat("/dev/dsp",&buf) == 0) { dsp = g_list_append(dsp,"/dev/dsp"); } if (stat("/dev/dsp1",&buf) == 0) { dsp = g_list_append(dsp,"/dev/dsp1"); }#endif#ifdef sun /* check if the user has any special audio-hardware running, which set the AUDIODEV-environment-variable */ audiodev = getenv("AUDIODEV"); if (audiodev != NULL) { if (stat(audiodev,&buf) == 0) { dsp = g_list_append(dsp,g_strdup(audiodev)); } } else { audiodev = ""; } if (strcmp(audiodev,"/dev/audio") != 0) { if (stat("/dev/audio",&buf) == 0) { dsp = g_list_append(dsp,"/dev/audio"); } }#endif#ifdef hpux /* for HP-UX check if /dev/audio exists - I've never seen */ /* other audio devices under HP-UX */ if (stat("/dev/audio",&buf) == 0) { dsp = g_list_append(dsp,"/dev/audio"); }#endif /* do some debug output */ if (debug) { loop = g_list_first(dsp); while(loop) { if (loop->data != NULL) dodebug(10, "dspscan: %s\n", (gchar *) loop->data); loop = loop->next; } } return g_list_first(dsp);}/* take a dsp-device and find the fitting mixer-device */gchar *gen_mix_from_dspdev(gchar *dsp, gchar *ret) {gchar tmp[MAXLINE];struct stat buf;#ifdef linuxgchar tmp2[MAXLINE];#endif strcpy(ret,"");#ifdef linux if (strncmp(dsp,"/dev/dsp",8) == 0) { strcpy(tmp,dsp+8); g_snprintf(tmp2,MAXLINE,"/dev/mixer%s",tmp); /* does device exist? */ if (stat(tmp2,&buf) == 0) { strcpy(ret,tmp2); } } #endif#ifdef sun g_snprintf(tmp,MAXLINE,"%s%s",dsp,"ctl"); /* does device exist? */ if (stat(tmp,&buf) == 0) { strcpy(ret,tmp); }#endif#ifdef hpux g_snprintf(tmp,MAXLINE,"%s%s",dsp,"Ctl"); /* does device exist? */ if (stat(tmp,&buf) == 0) { strcpy(ret,tmp); }#endif dodebug(10, "mixer: %s\n", ret); return ret;}/* call uname -a to get a nice system-id-string */gchar *get_uname_info(gchar *str) {FILE *fpin; dodebug(1, "calling: %s\n", UNAME); if ((fpin = popen(UNAME,"r")) == NULL) { g_error("popen error\n"); } strcpy(str,""); fgets(str,MAXLINE,fpin); if (pclose(fpin) == -1) { g_error("pclose error\n"); } dodebug(10, "uname: %s\n", str); return str;}/* Save the setup-configuration to a file - all strings are converted in a printable form first: return 0 if ok, or 1 on error */gint save_setup_config(gchar *confdir, gchar *fname) {FILE *fd;gchar tmp[MAXLINE];gchar tmp2[MAXLINE];GList *loop; /* now check if the confdir exists */ if (!is_directory(confdir)) { /* try to create directory */ mkdir(confdir, 0700); dodebug(2, "trying to mkdir %s\n", confdir); } g_snprintf(tmp,MAXLINE,"%s/%s", confdir, fname); dodebug(1, "Opening %s for writing\n", tmp); dolog(3, "Saving config file %s\n", tmp); fd = fopen(tmp,"w"); if (fd == NULL) { /* error opening file */ return 1; } /* write the config-file header */ fputs("#\n",fd); g_snprintf(tmp,MAXLINE,"# X-CD-Roast V%s Configuration-File\n",XCDROAST_VERSION); fputs(tmp,fd); fputs("#\n",fd); fputs("# Automatically created by the X-CD-Roast-Setup\n",fd); fputs("# Don't edit! (Unless you REALLY know what you are doing)\n",fd); fputs("#\n\n",fd); /* write data */ g_snprintf(tmp,MAXLINE,"VERSION = \"%s\"\n",XCDROAST_VERSION); fputs(tmp,fd); g_snprintf(tmp,MAXLINE,"PLATFORM = \"%s\"\n",system_platform); fputs(tmp,fd); g_snprintf(tmp,MAXLINE,"WRITER_DEVNR = %d\n",setupdata.writer_devnr); fputs(tmp,fd); strcpy(tmp2,setupdata.writer_vendor); g_snprintf(tmp,MAXLINE,"WRITER_VENDOR = \"%s\"\n",convert_escape(tmp2)); fputs(tmp,fd); strcpy(tmp2,setupdata.writer_model); g_snprintf(tmp,MAXLINE,"WRITER_MODEL = \"%s\"\n",convert_escape(tmp2)); fputs(tmp,fd); g_snprintf(tmp,MAXLINE,"WRITER_MODE = %d\n",setupdata.writer_mode); fputs(tmp,fd); g_snprintf(tmp,MAXLINE,"WRITER_SPEED = %d\n",setupdata.writer_speed); fputs(tmp,fd); g_snprintf(tmp,MAXLINE,"WRITER_FIFO = %d\n",setupdata.writer_fifo); fputs(tmp,fd); g_snprintf(tmp,MAXLINE,"READDEV1_DEVNR = %d\n",setupdata.readdev1_devnr); fputs(tmp,fd); strcpy(tmp2,setupdata.readdev1_vendor); g_snprintf(tmp,MAXLINE,"READDEV1_VENDOR = \"%s\"\n",convert_escape(tmp2)); fputs(tmp,fd); strcpy(tmp2,setupdata.readdev1_model); g_snprintf(tmp,MAXLINE,"READDEV1_MODEL = \"%s\"\n",convert_escape(tmp2)); fputs(tmp,fd); g_snprintf(tmp,MAXLINE,"READDEV2_DEVNR = %d\n",setupdata.readdev2_devnr); fputs(tmp,fd); strcpy(tmp2,setupdata.readdev2_vendor); g_snprintf(tmp,MAXLINE,"READDEV2_VENDOR = \"%s\"\n",convert_escape(tmp2)); fputs(tmp,fd); strcpy(tmp2,setupdata.readdev2_model); g_snprintf(tmp,MAXLINE,"READDEV2_MODEL = \"%s\"\n",convert_escape(tmp2)); fputs(tmp,fd); g_snprintf(tmp,MAXLINE,"AUDIOREAD_INTERFACE = %d\n",setupdata.audioread_interface); fputs(tmp,fd); g_snprintf(tmp,MAXLINE,"AUDIOREAD_SPEED = %d\n",setupdata.audioread_speed); fputs(tmp,fd); g_snprintf(tmp,MAXLINE,"AUDIOREAD_OVERLAP = %d\n",setupdata.audioread_overlap); fputs(tmp,fd); g_snprintf(tmp,MAXLINE,"AUDIOREAD_SECTORBURST = %d\n",setupdata.audioread_sectorburst); fputs(tmp,fd); loop = g_list_first(setupdata.image_dirs); while(loop) { strcpy(tmp2,(gchar *)loop->data); g_snprintf(tmp,MAXLINE,"IMAGE_DIRS = \"%s\"\n",convert_escape(tmp2)); fputs(tmp,fd); loop = loop->next; } strcpy(tmp2,setupdata.dsp_device); g_snprintf(tmp,MAXLINE,"DSP_DEVICE = \"%s\"\n",convert_escape(tmp2)); fputs(tmp,fd); strcpy(tmp2,setupdata.mix_device); g_snprintf(tmp,MAXLINE,"MIX_DEVICE = \"%s\"\n",convert_escape(tmp2)); fputs(tmp,fd); g_snprintf(tmp,MAXLINE,"NOTIFY_VIA = %d\n",setupdata.notify_via); fputs(tmp,fd); g_snprintf(tmp,MAXLINE,"NOTIFY_AT = %d\n",setupdata.notify_at); fputs(tmp,fd); strcpy(tmp2,setupdata.cddb_host); g_snprintf(tmp,MAXLINE,"CDDB_HOST = \"%s\"\n",convert_escape(tmp2)); fputs(tmp,fd); g_snprintf(tmp,MAXLINE,"CDDB_PORT = %d\n",setupdata.cddb_port); fputs(tmp,fd); strcpy(tmp2,setupdata.logfile); g_snprintf(tmp,MAXLINE,"LOGFILE = \"%s\"\n",convert_escape(tmp2)); fputs(tmp,fd); g_snprintf(tmp,MAXLINE,"LOGLEVEL = %d\n",setupdata.loglevel); fputs(tmp,fd); g_snprintf(tmp,MAXLINE,"LANGUAGE = %d\n",setupdata.language); fputs(tmp,fd); g_snprintf(tmp,MAXLINE,"OPTION_TOOLTIPS = %d\n",setupdata.option_tooltips); fputs(tmp,fd); g_snprintf(tmp,MAXLINE,"OPTION_AUTORAISE = %d\n",setupdata.option_autoraise); fputs(tmp,fd); g_snprintf(tmp,MAXLINE,"OPTION_SAVEPOS = %d\n",setupdata.option_savepos); fputs(tmp,fd); g_snprintf(tmp,MAXLINE,"OPTION_PERSONIMAGE = %d\n",setupdata.option_personimage); fputs(tmp,fd); g_snprintf(tmp,MAXLINE,"OPTION_OVERWRITEWARN = %d\n",setupdata.option_overwritewarn); fputs(tmp,fd); g_snprintf(tmp,MAXLINE,"OPTION_AUTODELETE = %d\n",setupdata.option_autodelete); fputs(tmp,fd); g_snprintf(tmp,MAXLINE,"OPTION_TITLEPROGRESS = %d\n",setupdata.option_titleprogress); fputs(tmp,fd); g_snprintf(tmp,MAXLINE,"OPTION_DISPLAYCDTEXT = %d\n",setupdata.option_displaycdtext); fputs(tmp,fd); g_snprintf(tmp,MAXLINE,"OPTION_SELECTIONMODE = %d\n",setupdata.option_selectionmode); fputs(tmp,fd); if (fclose(fd) != 0) { /* error closing file */ return 1; } return 0;}/* Load the setup-configuration return 0 if ok, or 1 on error */gint load_setup_config(gchar *fname) {FILE *fd;gchar line[MAXLINE];gchar id[MAXLINE];gchar value[MAXLINE]; /* prepare some data */ free_glist(&setupdata.image_dirs); dodebug(1, "Opening config file %s for reading\n", fname); dolog(3, "Loading config file %s\n", fname); if ((fd = fopen(fname,"r")) == NULL) { /* error opening file */ return 1; } for (;;) { if (fgets(line,MAXLINE,fd) == NULL) break; dodebug(10,"config: %s", line), /* skip empty or hashed lines */ strip_string(line); if (*line == '#' || *line == '\0') continue; /* parse lines */ if (parse_config_line(line,id,value)) { g_error("syntax error in config-file\n"); } if (strcmp("VERSION",id) == 0) { strcpy(xcdroast_version_loaded,value); } if (strcmp("PLATFORM",id) == 0) { ; } if (strcmp("WRITER_DEVNR",id) == 0) { setupdata.writer_devnr = atoi(value); } if (strcmp("WRITER_VENDOR",id) == 0) { strncpy(setupdata.writer_vendor,value,9); setupdata.writer_vendor[8] = '\0'; } if (strcmp("WRITER_MODEL",id) == 0) { strncpy(setupdata.writer_model,value,17); setupdata.writer_model[16] = '\0'; } if (strcmp("WRITER_MODE",id) == 0) { setupdata.writer_mode = atoi(value); } if (strcmp("WRITER_SPEED",id) == 0) { setupdata.writer_speed = atoi(value); } if (strcmp("WRITER_FIFO",id) == 0) { setupdata.writer_fifo = atoi(value); } if (strcmp("READDEV1_DEVNR",id) == 0) { setupdata.readdev1_devnr = atoi(value); } if (strcmp("READDEV1_VENDOR",id) == 0) { strncpy(setupdata.readdev1_vendor,value,9); setupdata.readdev1_vendor[8] = '\0'; } if (strcmp("READDEV1_MODEL",id) == 0) { strncpy(setupdata.readdev1_model,value,17); setupdata.readdev1_model[16] = '\0'; } if (strcmp("READDEV2_DEVNR",id) == 0) { setupdata.readdev2_devnr = atoi(value); } if (strcmp("READDEV2_VENDOR",id) == 0) { strncpy(setupdata.readdev2_vendor,value,9); setupdata.readdev2_vendor[8] = '\0'; } if (strcmp("READDEV2_MODEL",id) == 0) { strncpy(setupdata.readdev2_model,value,17); setupdata.readdev2_model[16] = '\0'; } if (strcmp("AUDIOREAD_INTERFACE",id) == 0) { setupdata.audioread_interface = atoi(value); } if (strcmp("AUDIOREAD_SPEED",id) == 0) { setupdata.audioread_speed = atoi(value); } if (strcmp("AUDIOREAD_OVERLAP",id) == 0) { setupdata.audioread_overlap = atoi(value); } if (strcmp("AUDIOREAD_SECTORBURST",id) == 0) { setupdata.audioread_sectorburst = atoi(value); } if (strcmp("IMAGE_DIRS",id) == 0) { setupdata.image_dirs = g_list_append(setupdata.image_dirs, g_strdup(value)); } if (strcmp("DSP_DEVICE",id) == 0) { g_free(setupdata.dsp_device); setupdata.dsp_device = g_strdup(value); } if (strcmp("MIX_DEVICE",id) == 0) { g_free(setupdata.mix_device); setupdata.mix_device = g_strdup(value); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -