home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 15 / MA_Cover_15.iso / internet / aamp2htmlconvert-r / aamp2htmlconvert-r.c next >
Encoding:
C/C++ Source or Header  |  2000-04-27  |  14.2 KB  |  302 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <dos/dos.h>
  4. #include <dos/rdargs.h>
  5.  
  6. /* #define DEBUGGING */ /* uncomment this line to activate debugging mode */
  7.  
  8. #ifdef DEBUGGING
  9.     #define aFILE        0
  10.     #define aOUTPUTFILE  1
  11.     #define aPATH        2
  12.     #define aSECONDS     3
  13.     #define aNOCOLOR     4
  14.     #define aBGCOLOR     5
  15.     #define aTEXTCOLOR   6
  16.     #define aEVENCOLOR   7
  17.     #define aODDCOLOR    8
  18.     #define aDEBUG       9
  19.     #define aCOUNTER    10
  20.     #define TEMPLATE "FILE/A,OUTFILE/K,PATH/S,SECONDS/S,NOCOLOR/S,BGCOLOR/K,TEXTCOLOR/K,EVENCOLOR/K,ODDCOLOR/K,DEBUG/S"
  21. #else
  22.     #define aFILE        0
  23.     #define aOUTPUTFILE  1
  24.     #define aPATH        2
  25.     #define aSECONDS     3
  26.     #define aNOCOLOR     4
  27.     #define aBGCOLOR     5
  28.     #define aTEXTCOLOR   6
  29.     #define aEVENCOLOR   7
  30.     #define aODDCOLOR    8
  31.     #define aCOUNTER     9
  32.     #define TEMPLATE "FILE/A,OUTFILE/K,PATH/S,SECONDS/S,NOCOLOR/S,BGCOLOR/K,TEXTCOLOR/K,EVENCOLOR/K,ODDCOLOR/K"
  33. #endif
  34.  
  35. const UBYTE *vers="$VER: Aamp2HtmlConvert-r 1.1";
  36.  
  37. struct RDArgs *ReadArgs();
  38. void FreeArgs();
  39. long atol();
  40.  
  41. int main(int argc, char *argv[])
  42. {
  43.     FILE *in=0, *out=0;
  44.     struct RDArgs *rdargs=0;
  45.     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;
  46.     char check=0, check2=0, timestring[6], bgcolor[7]="FFFFFF", textcolor[7]="000000", evencolor[7]="00FFFF", oddcolor[7]="FFFFFF";
  47.     long time=0, allsongs=0;
  48. #ifdef DEBUGGING
  49.     long templatearray[aCOUNTER]={0,0,0,0,0,0,0,0,0,0};
  50. #else
  51.     long templatearray[aCOUNTER]={0,0,0,0,0,0,0,0,0};
  52. #endif
  53.     printf("|     Aamp2HtmlConvert-r  1.1    |\n|  by radiat-r aka Sascha Ploss  |\n| www.Global-Multimedia.de/amiga |\n");
  54.     if (argc == 1)
  55.     {
  56.         printf("Error, no file specified.\n1 error occured.\n");
  57.         return 1;
  58.     }
  59.     rdargs=(struct RDArgs *) ReadArgs(TEMPLATE, templatearray, NULL);
  60.     if (rdargs)
  61.     {
  62. #ifdef DEBUGGING
  63.         if (templatearray[aDEBUG])
  64.         {
  65.             DEBUG=1;
  66.         }
  67.         if (DEBUG)
  68.         {
  69.             printf("debugging: %hi \n",DEBUG);
  70.             for (idx=0;idx<aCOUNTER;idx++)
  71.             {
  72.                 printf("templatearray[%hi]: %i\n", idx, (int) templatearray[idx]);
  73.             }
  74.         }
  75. #endif
  76.         if (templatearray[aSECONDS])
  77.         {
  78.             secondsoutput=1;
  79.         }
  80.         if (templatearray[aNOCOLOR])
  81.         {
  82.             color=0;
  83.         }
  84.         if (templatearray[aBGCOLOR])
  85.         {
  86.             strncpy(bgcolor,(char *) templatearray[aBGCOLOR],6);
  87.             bgcolor[6]='\0';
  88.         }
  89.         if (templatearray[aTEXTCOLOR])
  90.         {
  91.             strncpy(textcolor,(char *) templatearray[aTEXTCOLOR],6);
  92.             textcolor[6]='\0';
  93.         }
  94.         if (templatearray[aEVENCOLOR])
  95.         {
  96.             strncpy(evencolor,(char *) templatearray[aEVENCOLOR],6);
  97.             evencolor[6]='\0';
  98.         }
  99.         if (templatearray[aODDCOLOR])
  100.         {
  101.             strncpy(oddcolor,(char *) templatearray[aODDCOLOR],6);
  102.             oddcolor[6]='\0';
  103.         }
  104.         if (templatearray[aPATH])
  105.         {
  106.             path=1;
  107.         }
  108.         in=(FILE *) fopen((char *) templatearray[aFILE], "rb");
  109.         if (in)
  110.         {
  111.             check=fgetc(in);
  112.             if (check != EOF)
  113.             {
  114.                 fseek(in,ftell(in)-1,SEEK_SET); /* move back to beginning of file */
  115.                 if (templatearray[aOUTPUTFILE])
  116.                 {
  117.                     out=(FILE *) fopen((char *) templatearray[aOUTPUTFILE], "wb");
  118.                 }
  119.                 else
  120.                 {
  121.                     out=(FILE *) fopen("playlist.html", "wb");
  122.                 }
  123.                 if (out)
  124.                 {
  125.                     fprintf(out,"<HTML><HEAD><TITLE>AmigaAMP Playlist</TITLE></HEAD>\n
  126.                                  <BODY BGCOLOR=\"#%s\" TEXT=\"#%s\">\n
  127.                                  AmigaAMP Playlist created with <A HREF=\"http://amigaamp.amiga-software.com\">AmigaAMP</A> by Thomas Wenzel,<BR>\n
  128.                                  converted to HTML with <A HREF=\"http://www.Global-Multimedia.de/amiga\">Aamp2HtmlConvert-r</A> by radiat-r aka Sascha Ploss<HR>\n
  129.                                  <TABLE>\n<TR><TD><B>Nr.</B></TD>", bgcolor, textcolor);
  130.                     if (path) fprintf(out,"<TD><B>Path</B></TD>");
  131.                     fprintf(out,"<TD><B>Artist</B></TD><TD><B>-</B></TD><TD><B>Title</B></TD><TD><B>Length</B></TD></TR>\n");
  132.                     songcounter=1;
  133.                     do  /* move through whole file */
  134.                     {
  135.                         field=0; /* Artist, Title or Length */
  136.                         check2=check;
  137.                         check=fgetc(in);
  138.                         if ((check != EOF) && (check2 != EOF))
  139.                         {
  140.                             if (color) /* colored backgrounds in list */
  141.                             {
  142.                                 if (songcounter-(songcounter/2)*2) /* check if odd or even */
  143.                                 {
  144.                                     fprintf(out,"<TR BGCOLOR=\"#%s\"><TD>%03hi</TD><TD>", oddcolor, songcounter); /* odd, init row with oddcolor and write songcounter to file */
  145.                                 }
  146.                                 else
  147.                                 {
  148.                                     fprintf(out,"<TR BGCOLOR=\"#%s\"><TD>%03hi</TD><TD>", evencolor, songcounter); /* even, init row with evencolor and write songcounter to file */
  149.                                 }
  150.                             }
  151.                             else /* no colored backgrounds in list */
  152.                             {
  153.                                 fprintf(out,"<TR><TD>%03hi</TD><TD>",songcounter); /* write songcounter to file */
  154.                             }
  155.                         }
  156.                         while ((check != 0x09) && (check != 0x0A) && (check != EOF))
  157.                         {
  158.                             if (path) fprintf(out,"%c",check);
  159.                             check=fgetc(in);
  160.                         }
  161.                         if (check == 0x09) /* search first tab, to remove path and filename */
  162.                         {
  163.                             field++; /* first field (artist) found */
  164.                             songcounter++; /* increase songcounter */                            
  165.                             if (path) fprintf(out,"</TD><TD>");
  166.                             if (DEBUG) fprintf(out,"Field %hi: ",field); /* for debugging purose, check if were really in the right field */
  167.                             check=fgetc(in);
  168.                             while ((check != 0x0A) && (check != EOF))  /* loop for single song, ends either with end of line or end of file */
  169.                             {
  170.                                 if (check == 0x09) /* found the next tab */
  171.                                 {                                    
  172.                                     field++; /* and so this must be the next field */
  173.                                     if (field == 2) /* check if were already in title field (it isnt separated with tabs, so it must be empty) */
  174.                                     {
  175.                                         fprintf(out,"</TD><TD>-</TD><TD> "); /* add separator for empty title field */
  176.                                         if (DEBUG) fprintf(out,"Field %hi: ",field); /* debugging purpose again */
  177.                                     }
  178.                                     fprintf(out,"</TD><TD>"); /* end last field and init next one */
  179.                                     if (DEBUG) fprintf(out,"Field %hi: ",field); /* debugging */
  180.                                 }
  181.                                 else if ((check == 0x20) && (field == 1))  /* blank in artist field (maybe end of artist and start of seperator) */
  182.                                 {
  183.                                     check=fgetc(in);  /* get the next two chars... */
  184.                                     check2=fgetc(in);
  185.                                     if ((check == 0x2D) && (check2 == 0x20)) /* ...to check if we have the separator: " - " */
  186.                                     {
  187.                                         field++;
  188.                                         fprintf(out,"</TD><TD>-</TD><TD>");  /* add the separator */
  189.                                         if (DEBUG) fprintf(out,"Field %hi: ",field);
  190.                                     }
  191.                                     else /* not the separator, just a normal blank */
  192.                                     {
  193.                                         fseek(in,ftell(in)-2,SEEK_SET); /* move the two preread chars back */
  194.                                         fprintf(out," "); /* write the read blank */
  195.                                     }
  196.                                 }
  197.                                 else /* neither tab nor eol/eof found, so its a normal text char */
  198.                                 {
  199.                                     if (field == 3) /* arrived in lenght field */
  200.                                     {
  201.                                         time=0;
  202.                                         idx=0;
  203.                                         do
  204.                                         {
  205.                                             if (idx<6) /* make sure were not writing outside of string */
  206.                                             {
  207.                                                 if (check == 0x20) /* must be end of time,... */
  208.                                                 {
  209.                                                     timestring[idx]='\0'; /* ...so end string */
  210.                                                 }
  211.                                                 else /* number */
  212.                                                 {
  213.                                                     timestring[idx]=check;  /* save in string */
  214.                                                 }
  215.                                             }
  216.                                             idx++; /* stringposition */
  217.                                             check=fgetc(in); /* next char */
  218.                                         } while ((check != 0x0A) && (check != EOF)); /* move till end of timefield */
  219.                                         fseek(in,ftell(in)-1,SEEK_SET); /* move back to end of line/file */
  220.                                         time=atol(timestring); /* convert time string to long */
  221.                                         if (DEBUG) printf("lenght: %li\n",time); /* say for debugging */
  222.                                         allsongs=allsongs+time; /* add length of actual song to summary */
  223.                                         if (secondsoutput)
  224.                                         {
  225.                                             fprintf(out,"%03li Seconds",time); /* write time to file */
  226.                                         }
  227.                                         else
  228.                                         {
  229.                                             minutes=time/60;
  230.                                             seconds=time-minutes*60;
  231.                                             fprintf(out,"%02hi:%02hi",minutes,seconds); /* write time to file */
  232.                                         }
  233.                                     }
  234.                                     else /* not yet in third field */
  235.                                     {
  236.                                         fprintf(out,"%c",check); /* write the char to file */
  237.                                     }
  238.                                 }
  239.                                 check=fgetc(in); /* move on and get the next char */
  240.                             }
  241.                             fprintf(out,"</TD></TR>\n"); /* end of line/file */
  242.                         } /* endif for first tab check */
  243.                     } while (check != EOF); /* loop till end of file */
  244.                     hours=allsongs/3600;
  245.                     if (hours > 24)
  246.                     {
  247.                         days=hours/24;
  248.                         hours=hours-days*24;
  249.                         minutes=(allsongs-(hours+days*24)*3600)/60;
  250.                         seconds=(allsongs-(hours+days*24)*3600)-minutes*60;
  251.                     }
  252.                     else
  253.                     {
  254.                     minutes=(allsongs-hours*3600)/60;
  255.                     seconds=(allsongs-hours*3600)-minutes*60;
  256.                     }
  257.                     if (days)
  258.                     {
  259.                         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 */
  260.                         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 */
  261.                     }
  262.                     else
  263.                     {
  264.                         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 */
  265.                         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 */
  266.                     }
  267.                     fprintf(out,"</BODY></HTML>"); /* finish the outputfile */
  268.                     if (out) fclose(out);
  269.                     out=0;
  270.                 }
  271.                 else
  272.                 {
  273.                     printf("Error, could not open outfile.\n");
  274.                     errors++;
  275.                 }
  276.             }
  277.             else
  278.             {
  279.                 printf("Error, inputfile is empty.\n");
  280.                 errors++;
  281.             }
  282.             if (in) fclose(in);
  283.             in=0;
  284.         }
  285.         else
  286.         {
  287.             printf("Error, could not open inputfile.\n");
  288.             errors++;
  289.         }
  290.         if (rdargs) FreeArgs(rdargs);
  291.         rdargs=0;
  292.     }
  293.     else
  294.     {
  295.         printf("Error, could not read args.\n");
  296.         errors++;
  297.     }
  298.     if (errors == 1) printf("1 error occured.\n");
  299.     if (errors > 1) printf("%hi errors occured.\n", errors);
  300.     return errors;
  301. }
  302.