Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ SMAUG ➜ SMAUG coding ➜ Mudprog linked lists

Mudprog linked lists

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Samson   USA  (683 posts)  Bio
Date Tue 15 Mar 2005 03:34 AM (UTC)

Amended on Tue 15 Mar 2005 03:35 AM (UTC) by Samson

Message
Can someone tell me why the following code does not work?


void add_prog( MPROG_DATA *list, MPROG_DATA *prog )
{
   MPROG_DATA *tmp, *tmp2;

   if( !list )
   {
      list = prog;
      log_string( "Returning empty" );
      return;
   }

   for( tmp = list; tmp; tmp = tmp->next )
      if( tmp == prog )
      {
         log_string( "Already linked?!?!?!" );
         return;
      }

   tmp2 = list;

   while( tmp2->next != NULL )
      tmp2 = tmp2->next;
   tmp2->next = prog;

   log_string( "At bottom" );
}

void mobprog_file_read( MOB_INDEX_DATA *mob, char *f )
{
   MPROG_DATA *mprg = NULL;
   char MUDProgfile[256];
   FILE *progfile;
   char letter;

   snprintf( MUDProgfile, 256, "%s%s", PROG_DIR, f );

   if( !( progfile = fopen( MUDProgfile, "r" ) ) )
   {
      bug( "%s: couldn't open mudprog file", __FUNCTION__ );
      return;
   }

   for( ; ; )
   {
      letter = fread_letter( progfile );

      if( letter == '|' )
         break;

      if( letter != '>' )
      {
         bug( "%s: MUDPROG char", __FUNCTION__ );
         break;
      }

      CREATE( mprg, MPROG_DATA, 1 );
      mprg->type = mprog_name_to_type( fread_word( progfile ) );
      switch( mprg->type )
      {
         case ERROR_PROG:
            bug( "%s: mudprog file type error", __FUNCTION__ );
            DISPOSE( mprg );
            continue;

         case IN_FILE_PROG:
            bug( "%s: Nested file programs are not allowed.", __FUNCTION__ );
            DISPOSE( mprg );
            continue;

         default:
            mprg->arglist = fread_string( progfile );
            mprg->comlist = fread_string( progfile );
            mprg->fileprog = TRUE;
            xSET_BIT( mob->progtypes, mprg->type );
            add_prog( mob->mudprogs, mprg );
            break;
      }
   }
   FCLOSE( progfile );
   return;
}

void mprog_read_programs( FILE *fp, MOB_INDEX_DATA *mob )
{
   MPROG_DATA *mprg;
   char letter;
   char *word;

   for( ; ; )
   {
      letter = fread_letter( fp );

      if( letter == '|' )
         return;

      if( letter != '>' )
      {
         bug( "%s: vnum %d MUDPROG char", __FUNCTION__, mob->vnum );
         exit( 1 );
      }
      CREATE( mprg, MPROG_DATA, 1 );
      add_prog( mob->mudprogs, mprg );

      word = fread_word( fp );
      mprg->type = mprog_name_to_type( word );

      switch( mprg->type )
      {
         case ERROR_PROG:
            bug( "%s: vnum %d MUDPROG type.", __FUNCTION__, mob->vnum );
            exit( 1 );

         case IN_FILE_PROG:
            mprg->arglist = fread_string( fp );
            mprg->fileprog = FALSE;
            mobprog_file_read( mob, mprg->arglist );
            break;

         default:
            xSET_BIT( mob->progtypes, mprg->type );
            mprg->fileprog = FALSE;
            mprg->arglist = fread_string( fp );
            mprg->comlist = fread_string( fp );
            break;
      }
   }
   return;
}


No matter how I've tried to go about this, it won't load the programs properly. The above sample fails to load any programs on any mobs, regardless of what kind they are. I really really hate single linked lists, but for this purpose I'm stuck with using them since I don't want to have to have a bugfix turn into a ginormous rewriting of the mudprog lists on mobs/objs/rooms.

The real problem obviously lies with add_prog, it's returning only the "empty" message, it never hits the other possible log messages.
Top

Posted by Samson   USA  (683 posts)  Bio
Date Reply #1 on Thu 17 Mar 2005 01:17 AM (UTC)
Message
Nobody has any ideas? :)
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #2 on Thu 07 Apr 2005 01:35 AM (UTC)
Message
Are you aware that 'list' is not passed by reference?


if( !list )
   {
      list = prog;  // does nothing useful
      log_string( "Returning empty" );
      return;
   }


You need to pass a pointer to a pointer, or go about it a different way.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Samson   USA  (683 posts)  Bio
Date Reply #3 on Thu 07 Apr 2005 01:46 AM (UTC)
Message
I did actually. Fixed the issue awhile back, just forgot to mention it. Thing is though, I was following the lead from another part of the code where the act_list was being handled in a similar manner and seems to work just fine with the same call method.
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


11,036 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.