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

no-reply_wiki at metalforge.org no-reply_wiki at metalforge.org
Wed Jan 17 11:43:56 CST 2007


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

Date        : 2007/01/17 11:43
User        : mhoram
Edit Summary: 

@@ -21,8 +21,9 @@
  
  Thanks for all your help!
  
  ===== Notes & Comments =====
+ 
  
  
  ===== Code =====
  <code c>
@@ -279,52 +280,31 @@
   * Second value
   *
   */
  static int sortbyname(const void *a, const void *b){
-     char aa[MAX_SIZE];
-     char bb[MAX_SIZE];
-     int i;
+ /*
+     const char* aa  = (const char *)a;
+     const char* bb  = (const char *)b;
+ 
+     return( strcasecmp(aa, bb));
+ */
+     return strcasecmp( *(char **)a, *(char **)b );
      
-     strcpy(aa,a);
-     strcpy(bb,b);
-     
-     for(i=0; i<sizeof(aa) && i < sizeof(bb); i++){
-         aa[i] = tolower(aa[i]);
-         bb[i] = tolower(bb[i]);
-         if(aa[i] != bb[i]){
-             return(aa[i]-bb[i]);
-         }
-     }
-     return 0;
  }
  
  /**
-  * Appends a string to another separated by a comma and space.
+  * Add a string to a String_Array struct
   *
-  * Appends the second argument to the first argument
-  * 
-  * @param old
-  * Old string
+  * Adds the new string to the struct's 'item' array, and updates the 'count' and
+  * 'longest' values.  (THIS ROUTINE IS NOT RIGHT YET.)
   *
-  * @param new
-  * New string to append to old
+  * @param array
+  * The array to be appended
+  *
+  * @param string
+  * The new string to append
   *
   */
- static const char* append_with_comma(const char* old, const char* new){
- 
-     LOG(llevError, "%s + %s\n", old, new);
-     
-     if( old == NULL ){
-         old = calloc(1, strlen(new)+1 );
-     } else {
-         old = realloc( old, strlen(old)+ strlen(new)+strlen(", ")+1 );
-         old = strncat( old, ", ", 2 );
-     }
-     old = strncat( old, new, strlen(new));
- 
-     return(old);
- }
- 
  void push(String_Array* array, const char* string){
      sint16 i = array->count;
  
      array->item[i] = calloc(1, strlen(string)+1);
@@ -352,9 +332,9 @@
  
      fprintf(stderr, "JOIN: %d %d %s\n", array->count, array->longest, array->item[0]);
      
      newtext = calloc(1,1);
-     qsort(&array->item, array->count, array->longest, sortbyname);
+     qsort(array->item, array->count, array->longest, sortbyname);
      for(i=0;i<array->count;i++ ){
          if(i){
              newtext = realloc( newtext, strlen(newtext) + strlen(", ") +1 );
              newtext = strncat( newtext, ", ", 2 );
@@ -794,7 +774,5 @@
  
  int execute_global_event(int eventcode, ...){
      return 0;
  }
- 
  </code>
- 


IP-Address  : 206.71.197.56
Old Revision: http://wiki.metalforge.net/doku.php/user:mhoram:code:bwp?rev=1169052388
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