getht-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Getht-commit] arch commit: getht--mainline--0.1--patch-31


From: Nick
Subject: [Getht-commit] arch commit: getht--mainline--0.1--patch-31
Date: Wed, 2 Apr 2008 23:21:58 +0100
User-agent: Mutt/1.5.16 (2007-06-09)

Revision: getht--mainline--0.1--patch-31
Archive: address@hidden
Creator: Nick White <address@hidden>
Date: Wed Apr  2 23:20:24 BST 2008
Standard-date: 2008-04-02 22:20:24 GMT
Modified-files: BUGS src/config.c src/download.c src/getht.h
    src/issuemem.c src/mediarev.c src/mediaxml.c
New-patches: address@hidden/getht--mainline--0.1--patch-31
Summary: Fix for media xml crash bugs
Keywords: 

Formatting
Check for empty item titles
Created function to check if any part of a string contains a phrase
Added some basic error checking to getquote
Note this does not completely fix all problems
M  src/issuemem.c
M  BUGS
M  src/config.c
M  src/download.c
M  src/getht.h
M  src/mediarev.c
M  src/mediaxml.c

* modified files

--- orig/BUGS
+++ mod/BUGS
@@ -17,17 +17,65 @@
                        realloc the pointer array,
                        and -1 to no_of_media
 
-       read media xml:
-               should not segfault if it finds an empty item
-               prob needs to check that string is not blank before trying to 
copy info
 
 further progress:
 -      main obstacle is that "on mouseUp" no longer necessarily follows a 
newline - file now less organised still
-       therefore we'll have to scan each line (except when already in useful 
clause (check this) char by char for the occurance
-       best way to do this would be to scan char by char, and if one 
worthwhile is found to copy from the start to a new string for parsing
+       therefore we'll have to scan each line (except when already in useful 
clause (check this)) char by char for the occurance
+       best way to do this would be to scan char by char, and if one 
worthwhile is found to copy from this point to a new string for parsing
        worth spending a few minutes checking if there's a library function out 
there to do this, if not create a simple generic one, using pointers, roughly 
of the form:
                int containstring(char * toparse, char * match), returning 1 if 
found and 0 otherwise
 -      change of scanning routine has been done, but is untested
        consider changing for an improved getquote which can take the nth quote
                this is due to it being best not to rely on end of lines at end 
of bit we're interested in
 -      2nd clause of above (if no url is found) is very important now, as 
majority are unuseful
+
+
+currently (16/08/2007):
+
+the strcontains does not appear to be working correctly; appears to accept any 
line as a match
+this then creates a bunch of structures, which eventually become confused
+       this may point to some niggling bug in the memory management, but for 
the moment focus on correct basic rev parsing
+
+currently (28/11/2007):
+
+strcontains works mostly - check the TODO
+the sscanf for extracting uri isn't working - best to just have a slightly 
more sophisticated getquote function
+next actions:
+       /no_of_media strangely changes where it's pointing to to be "out of 
bounds" half way through
+       /       always gets stuck on 'Geometry'
+       /       must have an overflow, prob in strcontains (only happens when 
it's used lots)
+       /       rewrite strcontains using array arithmetic - easier to maintain
+       /ensure whole lines are always parsed (not just first parts thereof) 
[should now be done]
+       /       to test search output for 1st reference to Publisher, and see 
if a few lines above is a successful on mouseUp recognition
+       /       get rid of ugly & unnecessary extra checks, which are put there 
just to ensure nothing bad happens in the delicate phase
+
+currently (09/12/2007)
+
+strcontains has been rewritten to use friendly arrays; appears to work fine 
(though not heavily tested)
+getting a str has been rewritten into a function: gzgetstr ; appears to work 
fine thouth also not well tested
+
+note - arch changes they've made:
+only one regular media item (in form of earlier)
+now a new "songs" section, with neat urls following "SongsURLs" (when not in 
on mouseUp section)
+       song titles follow, again on separate neat lines, but without any easy 
delimiter to hook on to
+there is also a video section in a "on menupick pItem" clause
+       different syntax to traditional
+       has to work out url using quality choices from pItem (high, med, low; 
given below)
+       won't be too hard, just be somewhat tricky to get the different options 
(start with them hardcoded, i.e. on "put tSize & '.mov' after tURL" just make 3 
items with high, med, & low qualities
+there is also an interviews section, which looks very similar to Songs 
(InterviewsURLs)
+       note that interview names are encased in html
+there are also thumbnail jpgs, but they needn't be handled for a while
+
+next actions:
+       improve getquote to point where sscanf line is replaced [e.g. allow to 
only return quote n (and ignore prev)]
+       only include stack if it has a uri attached (otherwise throw away)
+
+18/12/07
+
+getquote has been rewritten to extract an arbitrary quote n
+empty uri strings are ignored
+
+TODO w/bugs
+generally:
+
+we should be able to read rev.gz / xml from hd, to save time & server hitting 
with testing


--- orig/src/config.c
+++ mod/src/config.c
@@ -72,7 +72,7 @@
                                proxy_type = SOCKS5;
                        else
                                fprintf(stderr,
-                                       "Proxy type %s not known, please use 
either http, socks4 or socks5",
+                                       "Proxy type %s not known, please use 
either http, socks4 or socks5\n",
                                        parameter);
                }
                else if(!strcmp(option, "proxy_address"))


--- orig/src/download.c
+++ mod/src/download.c
@@ -134,7 +134,10 @@
 /*     Print status information */
 {
        double frac;
-       frac = 100 * dlnow / dltotal;
+       if(dlnow > 0)
+               frac = 100 * dlnow / dltotal;
+       else
+               frac = 0;
        printf("\rDownload progress: %3.0lf%% ", frac);
        fflush(stdout);
 


--- orig/src/getht.h
+++ mod/src/getht.h
@@ -26,7 +26,7 @@
 #define ISS_XML_FILE   "htde_toc.xml"
 #define MED_REVGZ_FILE "htde_media-player.rev.gz"
 
-#define STR_MAX                512
+#define STR_MAX                1024
 
 #define MAX_ISS                10
 


--- orig/src/issuemem.c
+++ mod/src/issuemem.c
@@ -125,7 +125,7 @@
        (*no_of_media)++;                                         
 
        /* make new array item a pointer to issue */
-       if( (tmp[*no_of_media] = malloc(sizeof(med))) == NULL )
+       if( ( tmp[*no_of_media] = malloc(sizeof(med)) ) == NULL )
                nogo_mem();
 
        return tmp;


--- orig/src/mediarev.c
+++ mod/src/mediarev.c
@@ -26,17 +26,20 @@
 #include "getht.h"
 #include "issue.h"
 
-int smilurl(char * smilurl, med * cur_media);
-void getquote(char * input, char * label);
-void removeleadingspace(char * cur_line);
+int gzgetstr(char * newstr, gzFile * gzfile);
+int getquote(char * input, char * quote, int number);
+int strcontains(char * source, char * comparison);
 
 med ** parsemediagz(char * media_path, int * no_of_media)
 /*     Parses gzipped adobe pagemaker files for media urls and metadata,
  *     filling media with the information. */
 {
+       char c;
        char cur_line[STR_MAX];
        gzFile mediagz;
 
+       *no_of_media = -1;
+
        med ** media = NULL;
 
        strcpy(cur_line,""); /* reset cur_line */
@@ -47,13 +50,10 @@
 
        while(gzeof(mediagz)==0)
        {
-               gzgets(mediagz, cur_line, STR_MAX);
-               cur_line[strlen(cur_line)-1] = '\0'; /* get rid of trailing 
newline */
+               gzgetstr(cur_line, mediagz);
 
-               if(!strcmp(cur_line,"on mouseUp"))
+               if(strcontains(cur_line,"on mouseUp") == 0)
                {
-                       strcpy(cur_line,""); /* reset cur_line */
-
                        /* assign memory for the new media */
                        media = assignnew_med(media, no_of_media);
 
@@ -67,30 +67,22 @@
                        cur_media->size = 0;
 
                        /* process rev file */
-                       while(strcmp(cur_line,"end mouseUp") && 
gzeof(mediagz)==0)
+                       while(strcontains(cur_line,"end mouseUp") && 
gzeof(mediagz)==0)
                        {
                                strcpy(cur_line,""); /* reset cur_line */
-                               gzgets(mediagz, cur_line, STR_MAX);
-                               cur_line[strlen(cur_line)-1] = '\0'; /* remove 
trailing newline */
-
-                               removeleadingspace(cur_line);
+                               gzgetstr(cur_line, mediagz);
 
-                               if(!strncmp(cur_line,"set the filename of 
player \"", 28))
-                               {
-                                       /* todo: check if smil, if so follow to 
find uri */
-                                       //sscanf(cur_line,"set the filename of 
player \"player1\" to \"%s\"",cur_media->uri);
-                                       sscanf(cur_line,"set the filename of 
player \"%[^\"] to \"%s\"",NULL,cur_media->uri);
-                                       
cur_media->uri[strlen(cur_media->uri)-1] = '\0'; /* workaround extra character 
*/
-                               }
-                               else if(!strncmp(cur_line,"set the label of 
this stack to \"",32))
-                               {
-                                       getquote(cur_line,cur_media->title);
-                               }
-                               else if(!strncmp(cur_line,"statusMsg \(\"",12))
-                               {
-                                       getquote(cur_line,cur_media->comment);
-                               }
+                               if(!strcontains(cur_line,"set the filename of 
player \"") && strcontains(cur_line,"empty"))
+                                       getquote(cur_line, cur_media->uri, 2);
+                               else if(!strcontains(cur_line,"set the label of 
this stack to"))
+                                       getquote(cur_line, cur_media->title, 1);
+                               else if(!strcontains(cur_line,"statusMsg\(\"") 
|| !strcontains(cur_line,"StatusMsg \(\""))
+                                       getquote(cur_line, cur_media->comment, 
1);
                        }
+
+                       /* if it turns out that there was nothing useful there, 
remove the new media */
+                       if(cur_media->uri[0] == '\0')
+                               (*no_of_media)--;
                }
                strcpy(cur_line,""); /* reset cur_line */
        }
@@ -98,19 +90,20 @@
        return media;
 }
 
-int smilurl(char * smilurl, med * cur_media)
-/*     Extracts url and other data from remote smil file, storing
- *     the info in the cur_media structure. */
+int getquote(char * input, char * quote, int number)
+/*     assigns quote string from a line of the format:
+ *     'something "quote" something' */
 {
-       return 0;
-}
+       int curnum;
 
-void getquote(char * input, char * quote)
-/*     sets quote from a line of the format:
- *     `something "quote" something' */
-{
-       char * cur_pos;
-       cur_pos = quote;
+       /* advance past earlier quotes */
+       for(curnum=0; curnum < ((number*2)-2); curnum++)
+       {
+               /* advance until " character is reached */
+               while(*input != '"' && *input)  
+                       input++;
+               input++;
+       }
 
        /* advance until " character is reached */
        while(*input != '"' && *input)  
@@ -119,33 +112,67 @@
        input++;
 
        /* copy characters in until next '"' */
-       while(*input != '"' && *input)
+       while(*input != '"')
        {
-               *cur_pos = *input;
-               cur_pos++;
+               /* if end is found without closing bracket,
+                * exit with error */
+               if(! *input)
+                       return 1;
+               *quote = *input;
+               quote++;
                input++;
        }
 
-       *cur_pos = '\0';
+       *quote = '\0';
+
+       return 0;
 }
 
-void removeleadingspace(char * cur_line)
+int strcontains(char * source, char * comparison)
 {
-       int tmp, newpos;
+       int srcpos = 0; /* position in source string */
+       int compos = 0; /* position in comparison string */
+
+       while(srcpos < strlen(source) && srcpos < STR_MAX)
+       {
+               /* if the chars match, move to the next in comparison,
+                * otherwise only advance the source */
+               if(source[srcpos] == comparison[compos])
+                       compos++;
+               else
+                       compos = 0;
+
+               /* if we got to the end of comparison, there's a match */
+               if(compos == strlen(comparison))
+                       return 0;
+
+               srcpos++;
+       }
 
-       char temp_str[STR_MAX];
+       /* if we got all the way through the source, there's no match */
+       return 1;
+}
 
-       /* advance past whitespace */
-       tmp = 0;
-       while (cur_line[tmp] == ' ' || cur_line[tmp] == '\t')
-               tmp++;
+int gzgetstr(char * newstr, gzFile * gzfile)
+/*     a reimplementation of gzgetstr, which doesn't choke at odd characters
+ */
+{
+       strcpy(newstr,""); /* reset cur_line */
+       char c;
 
-       /* copy from there to temp_str */
-       for(newpos = 0; cur_line[tmp]; tmp++, newpos++)
-               temp_str[newpos] = cur_line[tmp];
+       while((c = gzgetc(gzfile)) != -1)
+       {
+               if(c == '\n')
+                       break;
 
-       temp_str[newpos] = '\0';
+               /* append the char if there's room in the str */
+               if(strlen(newstr)+1 < STR_MAX)
+                       strncat(newstr,&c,1);
+               /* if the line is too long just break to pick up the 2nd half 
on next pass,
+                * not perfect (will miss strs cut into 2 sections), but good 
enough for now */
+               else
+                       break;
+       }
 
-       /* copy temp_str to cur_line */
-       strncpy(cur_line, temp_str, sizeof(temp_str));
+       return 0;
 }


--- orig/src/mediaxml.c
+++ mod/src/mediaxml.c
@@ -228,7 +228,10 @@
                                        if(xmlGetProp(itnode, "preview"))
                                                strncpy(cur_media->preview_uri, 
(char *) xmlGetProp(itnode, "preview_uri"), STR_MAX);
 
-                                       strncpy(cur_media->title, (char *) 
xmlNodeListGetString(media_file, itnode->xmlChildrenNode, 1), STR_MAX);
+                                       if((char *) 
xmlNodeListGetString(media_file, itnode->xmlChildrenNode, 1))
+                                               strncpy(cur_media->title, (char 
*) xmlNodeListGetString(media_file, itnode->xmlChildrenNode, 1), STR_MAX);
+                                       else
+                                               strncpy(cur_media->title, 
"untitled", STR_MAX);
                                }
                                
                                itnode = itnode->next;



Attachment: pgpMZEPQcwZfd.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]