/* (c) steve at steve dash parker dot org Released under GPL version 2 (http://www.gnu.org/copyleft/gpl.html) This program is free software; you can redistribute it and/or modify it under the terms of Version 2 of the the GNU General Public License as published by the Free Software Foundation. Any later versions of the GPL will be evaluated as they are released, and this software may or may not be re-released under those terms also. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA See the included file COPYING for more details. */ #include #include FILE *datfile; int read_num(char *prompt) { int n; char *s=(char*)malloc(sizeof(char)*5); fflush(stdin); printf("%s", prompt); fflush(stdout); //fscanf(stdin, "%d", n); fgets(s, 5, stdin); fflush(stdin); fflush(stdin); printf("s=%s\n", s); fflush(stdin); fflush(stdin); n=atoi(s); free(s); return n; } char *read_item(char *prompt, int n) { char *s; s=(char*)malloc(sizeof(char)*256); fflush(stdin); if (n>0) printf("%s%d: ", prompt, n); else printf("%s", prompt); fflush(stdout); //fscanf(stdin, "%s\n", s); fgets(s, 256, stdin); s[strlen(s)-1]='\0'; //printf("Returning: %s...\n", s); return s; } void write_entry(char *t, int n, char *e) { /* Give a negative value for n to not include it, eg: write_entry("Hello", 2, "World"); == Hello2=World write_entry("Hello!", -1, "World"); == Hello!=World */ char *s; s=(char*)malloc(sizeof(char)*256); if (n<0) sprintf(s, "%s=%s\n", t, e); else sprintf(s, "%s%d=%s\n", t, n, e); fwrite(s, sizeof(char), strlen(s), datfile); free(s); } main() { char *cd_id; char *cd_category; char *cd_title; char *track_title; char *pathname; int notracks; int i; cd_id=(char*)malloc(sizeof(char)*50); cd_title=(char*)malloc(sizeof(char)*256); track_title=(char*)malloc(sizeof(char)*256); pathname=(char*)malloc(sizeof(char)*1024); cd_category=read_item("CD Category: ", -1); cd_id=read_item("CD ID: ",-1); cd_title=read_item("CD Title: ", -1); notracks=read_num("Number of Tracks: "); sprintf(pathname, "/home/steve/.kde/share/apps/kscd/cddb/%s/%s", cd_category, cd_id); printf("Opening %s\n", pathname); datfile=fopen(pathname, "w"); write_entry("# Created By Steve's Program", -1, "cddb"); write_entry("# File Name", -1, pathname); write_entry("# DISC CATEGORY", -1, cd_category); write_entry("DISCID", -1, cd_id); write_entry("DTITLE", -1, cd_title); for (i=0; i