[Crossfire-wiki] [Crossfire DokuWiki] page changed: user:mhoram:code:bwp

no-reply_wiki at metalforge.org no-reply_wiki at metalforge.org
Fri Jan 19 08:32:17 CST 2007


A page in your DokuWiki was added or changed. Here are the details:

Date        : 2007/01/19 08:32
User        : mhoram
Edit Summary: Continuing to work on it

@@ -31,18 +31,32 @@
    * You need to do ''qsort(array->item, array->count, sizeof(char*), sortbyname);'', not ''qsort(array->item, array->count, array->longest, sortbyname);''. The item size is a char*, not the longest element. ''array->item'' is an array of ''char*'', that is of pointers to memory zones containing ''char'', not an array of items of size ''array->longest'' :) This can certainly explain some weird things.
      * I see what you're saying, but I was calling it that way in my ''qsort'' of ''archnames'', and that was working ok.  ''archames'' is an array of arrays, though, while ''array->item'' is a pointer to an array of pointers, so I ssupose that's the difference.  In any case, I think I have everything else working, so I've updated the code below.  ''sortbyname'' now no longer causes segfaults, but it still isn't sorting correctly either.  To be exact, it sorts ''archnames'' correctly, but not ''array->item''.  When I try <code>*(const char* *)a</code>, it segfaults, and when I inspect the variables with gdb, it says that's accessing a bad address.  At this point, I'm really stumped on this part, but I'm still looking for other examples.
  
        * can you try with ''qsort(&array->item, ...)'' and the ''const char * ''? Not sure that's the issue, but well... Also a few hints:
+           * It seems like I've tried every possible combination at this point -- passing ''array->item'' to ''qsort'' by itself and with & and * ; casting the arguments inside ''sortbyname'' in various ways.  The combination I'm doing now doesn't complain about anything and doesn't mangle any memory, but it doesn't sort it either.
+ 
          * do ''canuse.count = 0;'' before using ''push''. Count isn't initialized, so weird effects can happen
+           * I do, a few lines up.
          * ''free(NULL)'' is perfectly correct in ANSI, i don't know what your debugger/compiler is complainign about :)
+           * Not the compiler, but running the program spit out a bunch of ''"in free(): warning: junk pointer, too high to make sense"'' warnings.  I assumed that assigning "" to a ''char*'' would give it a valid pointer; obviously I was wrong.  But I didn't want to initialize those ''_row'' pointers to ''NULL'' either, because I'd be passing them as values to ''do_template'' later.  Initializing them with ''strdup_local'' did the trick.
+ 
          * instead of ''calloc(1, strlen(string)+1) / strncpy'', use ''strdup(string)'' in ''push'' (that's what this is for ^_-) - Crossfire may have a ''strdup_local'' somewhere, better use that if it exists
+           * It does; using that now.
          * doing ''char *newtext = "";'' is not required, and may be dangerous since you do ''realloc'' after (but of course you do ''calloc'', so the initialization won't do anything anyway ;p)
+           * Good point.  I think that was an attempt to fix a problem that went away.
          * for duplicated names, check if the monster isn't yet part of the array before inserting it
+           * Maybe the ideal would be to spit out a warning on duplicate names, but skip the duplicates in the actual output.  Those duplicates are actually separate archetypes; often from separate arch files; check ''monster/humanoid/Dragon/green_dragon?'' for example.  Two identical archetypes except for their faces, so perhaps one should be deleted, or turned into "fiery green dragon" or something (so as not to waste the images).
+ 
          * it may be better to use ''archt* archetypes[4000]'' instead of ''char archnames[4000][MAX_SIZE];''. It would let you sort by name, then plural name, then archetype name in case of duplicated monsters, and also enable you to check for head/more
+           * Nice idea; I should have thought of that.  Of course, I might end up having trouble sorting that too. ;-)  Should be examples of that in the code to copy, though.
          * similarly, you may want to avoid inserting archetypes which are ''more'' of another one - thus check ''more != NULL'' somewhere
+           * I don't think that's a problem.  The ''first_archetype'' list built by ''init_archetypes()'' seems to only contain whole archetypes, not parts.  Unless I'm misunderstanding your meaning; for example?
+ 
          * all in all, seems it'll work fine soon :)
-         * if you wanted to be really really flexible, you could use templates for flags themselves - instead of concatenating items with a comma, let a template (or a few, in this case) decide how to adjust stuff. This may be overkill, though, of course ^_-
+           * We'll see.  I won't make the mistake of claiming to be down to one bug again. ;-)  I'll finish making the change to use ''archt*'' and some other improvements before I bother updating the code here.
  
+         * if you wanted to be really really flexible, you could use templates for flags themselves - instead of concatenating items with a comma, let a template (or a few, in this case) decide how to adjust stuff. This may be overkill, though, of course ^_-
+           * I thought about that, but I wasn't sure how to do a template where an item could be repeated a variable number of times.  I also intend to insert wiki-style line breaks every N characters in long lines of text, like my perl version does, but that was one line of code there.  It'll take a bit more here. ;-)
  
  
  
    * Also, to compare, try ''strcasecmp'' which does case-insensitive comparison.


IP-Address  : 206.71.197.56
Old Revision: http://wiki.metalforge.net/doku.php/user:mhoram:code:bwp?rev=1169194981
New Revision: http://wiki.metalforge.net/doku.php/user:mhoram:code:bwp

-- 
This mail was generated by DokuWiki at
http://wiki.metalforge.net/




More information about the crossfire-wiki mailing list