AW: [mythtv] Programming help.

Jochen Kühner jochen.kuehner at gmx.de
Mon May 23 10:53:22 UTC 2005


Thanks. That's agood Idea!  
I think I do it like you suggest!

-----Ursprüngliche Nachricht-----
Von: mythtv-dev-bounces at mythtv.org [mailto:mythtv-dev-bounces at mythtv.org] Im
Auftrag von Jeff
Gesendet: Montag, 23. Mai 2005 12:44
An: Development of mythtv
Betreff: Re: [mythtv] Programming help.

On 5/21/05, Jochen Kühner <jochen.kuehner at gmx.de> wrote:
>  
>  
> 
> I Think that all gets to complicated! 
> 
> What If I use on regex wich extracts my from a Filename the gamename
without
> the number 
> 
> Like: Giana 01.adf Giana02.adf Giana3.adf this function always returns
> Giana. 
> 
>   
> 
> Then I Check how long this Function Retirns the same Filename and so long
it
> adds the files to a field in the database with a increasing field numer
> like: fd0 = "giana 01.af" fd1="gina02.adf"… 
> 
> Because I need the names of all the disk images! 
> 
>   
> 
> The Problem for me is only the regex and how I implement a RegEx in C 

You don't need to write a full regex unless the sample filenames
you've shown aren't representitive of what you're dealing with.

Write a 'getGameName' function which takes a string and returns the
length of the game name. This scans the string from the end looking
for the 1st non-whitespace/non-numeric character preceeding the file
type.
int getGameName(char *str) {
          int i, len;
          char ch;

          len = strlen(str);
          len -= 4;  // skip back over file type
          for (i=len; i > 0; i--) {
              ch = str[i];
              if (ch < '0' && ch > '9' && ch '= ' ') {
                 ++i;   //zero based array index -> string length
                 break;
              }
          }
          return i;   /* length of base game name */
}


A simple 'isSameGame(gameNameLen,str1,str2) function would suffice.

This compares gameNameLen characters in str1 to str2 to make sure they
are the same. memcmp() will do this for you. If that passes then the
next character in str2 must be whitespace or numeric (or the '.'?) for
it to be the same game.



More information about the mythtv-dev mailing list