Tag
External Text File Source - Versions 2.0.40b2 - b3
NB: You can now view the updated (as of 2.0.40b4) code.
The code below is that used to add the -f switch functionality, which allows users to pass the path to a text file, the contents of which are read as the tag value.
I would be very interested to hear about improvements to this code. Email address is on the homepage.
NB: The carriage return bit is used to insert a carriage return (13) in before any line feeds (10) that are found (without a preceding carriage return). I don't understand the ins and outs, but before I added this foobar was listing the value all nasty. I don't understand why there are no carriage returns when I read the file - maybe someone can explain.
Obviously the variable new_argv[i] contains the parameter, e.g.: "cuesheet=C:\CDImage.ape.cue"
char *t; size_t itemlen; FILE* stream; int ch; char filearg[10240]; int j; int cr; // other stuff here (removed) // get filename and length of tag name t = strchr ( new_argv[i], '=' ) + 1; // get length of tag name itemlen = t - new_argv[i] - 1; // check file exists if ( (stream = fopen ( t, "rt" ) ) == NULL ) { fprintf ( stderr, "%s: failed to open file for for reading.\n", t ); return 1; } //set filearg to "<tag>=" strncpy(filearg, new_argv[i], itemlen + 1); // start filling char array after "=" j = (int) itemlen + 1; // read text from file (up to 10240 chars) while ( ((ch = fgetc (stream)) != EOF ) && ( j < 10238 ) ) { //if character is line feed and last character wasn't a carriage return if ( ch == 10 && !cr ) { // add carriage return before line feed filearg[j] = (char)13; j++; // if character is carriage return set cr flag } else if ( ch == 13 ) { cr = 1; // otherwise reset flag } else { cr = 0; } // add character to array filearg[j] = (char)ch; j++; } // terminate will null char filearg[j] = '\0'; // close stream fclose (stream); // append to collection of tags (removed) // release array free ( filearg );
Created using C++2HTML
This document has been printed from http://www.synthetic-soul.co.uk/
