home *** CD-ROM | disk | FTP | other *** search
Wrap
#include <stdio.h> #include <string.h> #include <dos/dos.h> #include <dos/rdargs.h> /* #define DEBUGGING */ /* uncomment this line to activate debugging mode */ #ifdef DEBUGGING #define aFILE 0 #define aOUTPUTFILE 1 #define aPATH 2 #define aSECONDS 3 #define aNOCOLOR 4 #define aBGCOLOR 5 #define aTEXTCOLOR 6 #define aEVENCOLOR 7 #define aODDCOLOR 8 #define aDEBUG 9 #define aCOUNTER 10 #define TEMPLATE "FILE/A,OUTFILE/K,PATH/S,SECONDS/S,NOCOLOR/S,BGCOLOR/K,TEXTCOLOR/K,EVENCOLOR/K,ODDCOLOR/K,DEBUG/S" #else #define aFILE 0 #define aOUTPUTFILE 1 #define aPATH 2 #define aSECONDS 3 #define aNOCOLOR 4 #define aBGCOLOR 5 #define aTEXTCOLOR 6 #define aEVENCOLOR 7 #define aODDCOLOR 8 #define aCOUNTER 9 #define TEMPLATE "FILE/A,OUTFILE/K,PATH/S,SECONDS/S,NOCOLOR/S,BGCOLOR/K,TEXTCOLOR/K,EVENCOLOR/K,ODDCOLOR/K" #endif const UBYTE *vers="$VER: Aamp2HtmlConvert-r 1.1"; struct RDArgs *ReadArgs(); void FreeArgs(); long atol(); int main(int argc, char *argv[]) { FILE *in=0, *out=0; struct RDArgs *rdargs=0; short errors=0, DEBUG=0, songcounter=0, idx=0, field=0, days=0, hours=0, minutes=0, seconds=0, secondsoutput=0, path=0, color=1; char check=0, check2=0, timestring[6], bgcolor[7]="FFFFFF", textcolor[7]="000000", evencolor[7]="00FFFF", oddcolor[7]="FFFFFF"; long time=0, allsongs=0; #ifdef DEBUGGING long templatearray[aCOUNTER]={0,0,0,0,0,0,0,0,0,0}; #else long templatearray[aCOUNTER]={0,0,0,0,0,0,0,0,0}; #endif printf("| Aamp2HtmlConvert-r 1.1 |\n| by radiat-r aka Sascha Ploss |\n| www.Global-Multimedia.de/amiga |\n"); if (argc == 1) { printf("Error, no file specified.\n1 error occured.\n"); return 1; } rdargs=(struct RDArgs *) ReadArgs(TEMPLATE, templatearray, NULL); if (rdargs) { #ifdef DEBUGGING if (templatearray[aDEBUG]) { DEBUG=1; } if (DEBUG) { printf("debugging: %hi \n",DEBUG); for (idx=0;idx<aCOUNTER;idx++) { printf("templatearray[%hi]: %i\n", idx, (int) templatearray[idx]); } } #endif if (templatearray[aSECONDS]) { secondsoutput=1; } if (templatearray[aNOCOLOR]) { color=0; } if (templatearray[aBGCOLOR]) { strncpy(bgcolor,(char *) templatearray[aBGCOLOR],6); bgcolor[6]='\0'; } if (templatearray[aTEXTCOLOR]) { strncpy(textcolor,(char *) templatearray[aTEXTCOLOR],6); textcolor[6]='\0'; } if (templatearray[aEVENCOLOR]) { strncpy(evencolor,(char *) templatearray[aEVENCOLOR],6); evencolor[6]='\0'; } if (templatearray[aODDCOLOR]) { strncpy(oddcolor,(char *) templatearray[aODDCOLOR],6); oddcolor[6]='\0'; } if (templatearray[aPATH]) { path=1; } in=(FILE *) fopen((char *) templatearray[aFILE], "rb"); if (in) { check=fgetc(in); if (check != EOF) { fseek(in,ftell(in)-1,SEEK_SET); /* move back to beginning of file */ if (templatearray[aOUTPUTFILE]) { out=(FILE *) fopen((char *) templatearray[aOUTPUTFILE], "wb"); } else { out=(FILE *) fopen("playlist.html", "wb"); } if (out) { fprintf(out,"<HTML><HEAD><TITLE>AmigaAMP Playlist</TITLE></HEAD>\n <BODY BGCOLOR=\"#%s\" TEXT=\"#%s\">\n AmigaAMP Playlist created with <A HREF=\"http://amigaamp.amiga-software.com\">AmigaAMP</A> by Thomas Wenzel,<BR>\n converted to HTML with <A HREF=\"http://www.Global-Multimedia.de/amiga\">Aamp2HtmlConvert-r</A> by radiat-r aka Sascha Ploss<HR>\n <TABLE>\n<TR><TD><B>Nr.</B></TD>", bgcolor, textcolor); if (path) fprintf(out,"<TD><B>Path</B></TD>"); fprintf(out,"<TD><B>Artist</B></TD><TD><B>-</B></TD><TD><B>Title</B></TD><TD><B>Length</B></TD></TR>\n"); songcounter=1; do /* move through whole file */ { field=0; /* Artist, Title or Length */ check2=check; check=fgetc(in); if ((check != EOF) && (check2 != EOF)) { if (color) /* colored backgrounds in list */ { if (songcounter-(songcounter/2)*2) /* check if odd or even */ { fprintf(out,"<TR BGCOLOR=\"#%s\"><TD>%03hi</TD><TD>", oddcolor, songcounter); /* odd, init row with oddcolor and write songcounter to file */ } else { fprintf(out,"<TR BGCOLOR=\"#%s\"><TD>%03hi</TD><TD>", evencolor, songcounter); /* even, init row with evencolor and write songcounter to file */ } } else /* no colored backgrounds in list */ { fprintf(out,"<TR><TD>%03hi</TD><TD>",songcounter); /* write songcounter to file */ } } while ((check != 0x09) && (check != 0x0A) && (check != EOF)) { if (path) fprintf(out,"%c",check); check=fgetc(in); } if (check == 0x09) /* search first tab, to remove path and filename */ { field++; /* first field (artist) found */ songcounter++; /* increase songcounter */ if (path) fprintf(out,"</TD><TD>"); if (DEBUG) fprintf(out,"Field %hi: ",field); /* for debugging purose, check if were really in the right field */ check=fgetc(in); while ((check != 0x0A) && (check != EOF)) /* loop for single song, ends either with end of line or end of file */ { if (check == 0x09) /* found the next tab */ { field++; /* and so this must be the next field */ if (field == 2) /* check if were already in title field (it isnt separated with tabs, so it must be empty) */ { fprintf(out,"</TD><TD>-</TD><TD> "); /* add separator for empty title field */ if (DEBUG) fprintf(out,"Field %hi: ",field); /* debugging purpose again */ } fprintf(out,"</TD><TD>"); /* end last field and init next one */ if (DEBUG) fprintf(out,"Field %hi: ",field); /* debugging */ } else if ((check == 0x20) && (field == 1)) /* blank in artist field (maybe end of artist and start of seperator) */ { check=fgetc(in); /* get the next two chars... */ check2=fgetc(in); if ((check == 0x2D) && (check2 == 0x20)) /* ...to check if we have the separator: " - " */ { field++; fprintf(out,"</TD><TD>-</TD><TD>"); /* add the separator */ if (DEBUG) fprintf(out,"Field %hi: ",field); } else /* not the separator, just a normal blank */ { fseek(in,ftell(in)-2,SEEK_SET); /* move the two preread chars back */ fprintf(out," "); /* write the read blank */ } } else /* neither tab nor eol/eof found, so its a normal text char */ { if (field == 3) /* arrived in lenght field */ { time=0; idx=0; do { if (idx<6) /* make sure were not writing outside of string */ { if (check == 0x20) /* must be end of time,... */ { timestring[idx]='\0'; /* ...so end string */ } else /* number */ { timestring[idx]=check; /* save in string */ } } idx++; /* stringposition */ check=fgetc(in); /* next char */ } while ((check != 0x0A) && (check != EOF)); /* move till end of timefield */ fseek(in,ftell(in)-1,SEEK_SET); /* move back to end of line/file */ time=atol(timestring); /* convert time string to long */ if (DEBUG) printf("lenght: %li\n",time); /* say for debugging */ allsongs=allsongs+time; /* add length of actual song to summary */ if (secondsoutput) { fprintf(out,"%03li Seconds",time); /* write time to file */ } else { minutes=time/60; seconds=time-minutes*60; fprintf(out,"%02hi:%02hi",minutes,seconds); /* write time to file */ } } else /* not yet in third field */ { fprintf(out,"%c",check); /* write the char to file */ } } check=fgetc(in); /* move on and get the next char */ } fprintf(out,"</TD></TR>\n"); /* end of line/file */ } /* endif for first tab check */ } while (check != EOF); /* loop till end of file */ hours=allsongs/3600; if (hours > 24) { days=hours/24; hours=hours-days*24; minutes=(allsongs-(hours+days*24)*3600)/60; seconds=(allsongs-(hours+days*24)*3600)-minutes*60; } else { minutes=(allsongs-hours*3600)/60; seconds=(allsongs-hours*3600)-minutes*60; } if (days) { printf("%hi files in playlist with a total length of %02hi days, %02hi hours, %02hi minutes and %02hi seconds (%li seconds).\n",songcounter-1,days,hours,minutes,seconds,allsongs); /* were finished, say some results */ fprintf(out,"</TABLE><HR>\n%hi files in playlist with a total length of %02hi days, %02hi hours, %02hi minutes and %02hi seconds (%li seconds).\n",songcounter-1,days,hours,minutes,seconds,allsongs); /* save the same info to the file */ } else { printf("%hi files in playlist with a total length of %02hi hours, %02hi minutes and %02hi seconds (%li seconds).\n",songcounter-1,hours,minutes,seconds,allsongs); /* were finished, say some results */ fprintf(out,"</TABLE><HR>\n%hi files in playlist with a total length of %02hi hours, %02hi minutes and %02hi seconds (%li seconds).\n",songcounter-1,hours,minutes,seconds,allsongs); /* save the same info to the file */ } fprintf(out,"</BODY></HTML>"); /* finish the outputfile */ if (out) fclose(out); out=0; } else { printf("Error, could not open outfile.\n"); errors++; } } else { printf("Error, inputfile is empty.\n"); errors++; } if (in) fclose(in); in=0; } else { printf("Error, could not open inputfile.\n"); errors++; } if (rdargs) FreeArgs(rdargs); rdargs=0; } else { printf("Error, could not read args.\n"); errors++; } if (errors == 1) printf("1 error occured.\n"); if (errors > 1) printf("%hi errors occured.\n", errors); return errors; }