Logo Search packages:      
Sourcecode: mah-jong version File versions

pmsg_size.c

static int pmsg_size[] = {
0,
-sizeof(PMsgSaveStateMsg),
-sizeof(PMsgLoadStateMsg),
0,
0,
0,
0,
0,
0,
0,
-sizeof(PMsgConnectMsg),
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
sizeof(PMsgDeclareSpecialMsg),
0,
0,
-sizeof(PMsgRequestPauseMsg),
sizeof(PMsgReadyMsg),
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
sizeof(PMsgDiscardMsg),
sizeof(PMsgNoClaimMsg),
0,
0,
0,
0,
0,
0,
0,
0,
sizeof(PMsgPungMsg),
0,
sizeof(PMsgFormClosedPungMsg),
0,
0,
0,
0,
0,
0,
0,
sizeof(PMsgKongMsg),
0,
0,
0,
0,
0,
0,
0,
0,
0,
sizeof(PMsgDeclareClosedKongMsg),
sizeof(PMsgAddToPungMsg),
0,
0,
0,
0,
0,
sizeof(PMsgQueryMahJongMsg),
0,
0,
sizeof(PMsgChowMsg),
0,
sizeof(PMsgFormClosedChowMsg),
0,
0,
0,
0,
0,
0,
sizeof(PMsgDeclareWashOutMsg),
sizeof(PMsgMahJongMsg),
0,
sizeof(PMsgPairMsg),
sizeof(PMsgFormClosedPairMsg),
0,
sizeof(PMsgShowTilesMsg),
sizeof(PMsgSpecialSetMsg),
sizeof(PMsgFormClosedSpecialSetMsg),
0,
0,
-sizeof(PMsgSetPlayerOptionMsg),
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
sizeof(PMsgSwapTileMsg),
};

int pmsg_size_of(PlayerMsgType t) { return pmsg_size[t]; }

PMsgMsg *pmsg_deepcopy(PMsgMsg *m) {
  PMsgMsg *n;
  int size;
  char *mc,*nc;

  size = pmsg_size_of(m->type);
  if ( size < 0 ) size *= -1;
  n = (PMsgMsg *)malloc(size);
  if ( ! n ) return n;

  memcpy((void *)n,(const void *)m,size);
  switch ( m->type ) {
  case PMsgSendMessage:
    mc = ((PMsgSendMessageMsg *)m)->text;
    if ( mc ) {
      nc = (char *)malloc(strlen(mc)+1);
      if ( ! nc ) return NULL;
      strcpy(nc,mc);
    } else {
      nc = NULL;
    }
    ((PMsgSendMessageMsg *)n)->text = nc;
    break;
  case PMsgSaveState:
    mc = ((PMsgSaveStateMsg *)m)->filename;
    if ( mc ) {
      nc = (char *)malloc(strlen(mc)+1);
      if ( ! nc ) return NULL;
      strcpy(nc,mc);
    } else {
      nc = NULL;
    }
    ((PMsgSaveStateMsg *)n)->filename = nc;
    break;
  case PMsgSetPlayerOption:
    mc = ((PMsgSetPlayerOptionMsg *)m)->text;
    if ( mc ) {
      nc = (char *)malloc(strlen(mc)+1);
      if ( ! nc ) return NULL;
      strcpy(nc,mc);
    } else {
      nc = NULL;
    }
    ((PMsgSetPlayerOptionMsg *)n)->text = nc;
    break;
  case PMsgSetGameOption:
    mc = ((PMsgSetGameOptionMsg *)m)->optvalue;
    if ( mc ) {
      nc = (char *)malloc(strlen(mc)+1);
      if ( ! nc ) return NULL;
      strcpy(nc,mc);
    } else {
      nc = NULL;
    }
    ((PMsgSetGameOptionMsg *)n)->optvalue = nc;
    break;
  case PMsgConnect:
    mc = ((PMsgConnectMsg *)m)->name;
    if ( mc ) {
      nc = (char *)malloc(strlen(mc)+1);
      if ( ! nc ) return NULL;
      strcpy(nc,mc);
    } else {
      nc = NULL;
    }
    ((PMsgConnectMsg *)n)->name = nc;
    break;
  case PMsgLoadState:
    mc = ((PMsgLoadStateMsg *)m)->filename;
    if ( mc ) {
      nc = (char *)malloc(strlen(mc)+1);
      if ( ! nc ) return NULL;
      strcpy(nc,mc);
    } else {
      nc = NULL;
    }
    ((PMsgLoadStateMsg *)n)->filename = nc;
    break;
  case PMsgRequestPause:
    mc = ((PMsgRequestPauseMsg *)m)->reason;
    if ( mc ) {
      nc = (char *)malloc(strlen(mc)+1);
      if ( ! nc ) return NULL;
      strcpy(nc,mc);
    } else {
      nc = NULL;
    }
    ((PMsgRequestPauseMsg *)n)->reason = nc;
    break;
  default:
      ;
  }
  return n;
}

void pmsg_deepfree(PMsgMsg *m) {
  switch ( m->type ) {
  case PMsgSendMessage:
    if ( ((PMsgSendMessageMsg *)m)->text )
      free((void *)((PMsgSendMessageMsg *)m)->text);
    break;
  case PMsgSaveState:
    if ( ((PMsgSaveStateMsg *)m)->filename )
      free((void *)((PMsgSaveStateMsg *)m)->filename);
    break;
  case PMsgSetPlayerOption:
    if ( ((PMsgSetPlayerOptionMsg *)m)->text )
      free((void *)((PMsgSetPlayerOptionMsg *)m)->text);
    break;
  case PMsgSetGameOption:
    if ( ((PMsgSetGameOptionMsg *)m)->optvalue )
      free((void *)((PMsgSetGameOptionMsg *)m)->optvalue);
    break;
  case PMsgConnect:
    if ( ((PMsgConnectMsg *)m)->name )
      free((void *)((PMsgConnectMsg *)m)->name);
    break;
  case PMsgLoadState:
    if ( ((PMsgLoadStateMsg *)m)->filename )
      free((void *)((PMsgLoadStateMsg *)m)->filename);
    break;
  case PMsgRequestPause:
    if ( ((PMsgRequestPauseMsg *)m)->reason )
      free((void *)((PMsgRequestPauseMsg *)m)->reason);
    break;
  default:
      ;
  }
  free((void *)m);
}


Generated by  Doxygen 1.6.0   Back to index