Ejemplo n.º 1
0
/*
* RscAddCallback:  Called for each new resource that's loaded from a file.
*   Add given resource to table.
*/
bool RscAddCallback(char *fname, int res, char *string)
{
	resource_type entry, r;
	
	entry = (resource_type) SafeMalloc(sizeof(resource_struct));
	
	entry->idnum = res;
	entry->data = (char *) SafeMalloc(strlen(string) + 1);
	strcpy(entry->data, string);
	
	if (table_insert(t, entry, ResourceHash, ResourceCompare) != 0)
	{
		if (!ignore_duplicates)
		{
			ClientError(hInst, hMain, IDS_DUPRESOURCE, res, fname);
			FreeRsc(entry);
		}
		else
		{
			// Free existing resource
			r = (resource_type) table_lookup(t, &res, IdHash, IdResourceCompare);
			if (r != NULL)
			{
				table_delete_item(t, r, ResourceHash, ResourceCompare);
				FreeRsc(r);
				table_insert(t, entry, ResourceHash, ResourceCompare);
			}
		}
	}
	
	return true;
}
Ejemplo n.º 2
0
rb_red_blk_tree* RBTreeCreate( int (*CompFunc) (const void*,const void*),
		void (*DestFunc) (void*),
		void (*InfoDestFunc) (void*),
		void (*PrintFunc) (const void*),
		void (*PrintInfo)(void*)) {
	rb_red_blk_tree* newTree;
	rb_red_blk_node* temp;

	newTree=(rb_red_blk_tree*) SafeMalloc(sizeof(rb_red_blk_tree));
	newTree->Compare=  CompFunc;
	newTree->DestroyKey= DestFunc;
	newTree->PrintKey= PrintFunc;
	newTree->PrintInfo= PrintInfo;
	newTree->DestroyInfo= InfoDestFunc;

	/*  see the comment in the rb_red_blk_tree structure in red_black_tree.h */
	/*  for information on nil and root */
	temp=newTree->nil= (rb_red_blk_node*) SafeMalloc(sizeof(rb_red_blk_node));
	temp->parent=temp->left=temp->right=temp;
	temp->red=0;
	temp->key=0;
	temp=newTree->root= (rb_red_blk_node*) SafeMalloc(sizeof(rb_red_blk_node));
	temp->parent=temp->left=temp->right=newTree->nil;
	temp->key=0;
	temp->red=0;
	return(newTree);
}
Ejemplo n.º 3
0
/* Return False on error, True on success */
int load_add_class(char *class_name, int class_id, int superclass_id, char *superclass_name)
{
   /* Build up a class data structure for the new class. */
   id_type id = (id_type) SafeMalloc(sizeof(id_struct));
   id_type temp_id = (id_type) SafeMalloc(sizeof(id_struct));
   class_type c = (class_type) SafeMalloc(sizeof(class_struct));

   id->name = strdup(class_name);
   id->idnum = class_id;
   id->type = I_CLASS;
   id->source = DBASE;

   c->class_id = id;
   c->properties = c->messages = c->resources = c->classvars = NULL;
   c->is_new = False;  /* Don't generate code for this class */
   /* Store superclass id # in pointer for now.  Id # will be converted to pointer
    * when build_superclasses below is called. */
   c->superclass = (class_type)(intptr_t) superclass_id;

   /* Add to list of classes that have been read in */
   st.classes = list_add_item(st.classes, (void *) c);

   current_class = c;
   st.curclass = class_id;
   current_message = NULL;

   /* Call table_insert instead of add_identifier so that our id # from
    * the database file is preserved. 
    */
   if (table_insert(st.globalvars, (void *) id, id_hash, id_compare) == 0)
      return True;
   else return False;
}
Ejemplo n.º 4
0
int load_add_message(char *message_name, int message_id)
{
   id_type id = (id_type) SafeMalloc(sizeof(id_struct));
   message_handler_type m = (message_handler_type) SafeMalloc(sizeof(message_handler_struct));
   message_header_type h = (message_header_type) SafeMalloc(sizeof(message_header_struct));

   id->name = strdup(message_name);
   id->idnum = message_id;
   id->type = I_MESSAGE;
   id->ownernum = st.curclass;
   id->source = DBASE;

   h->message_id = id;
   h->params = NULL;

   m->header = h;
   m->locals = NULL;
   m->body = NULL;

   /* Add message to message list of current class */
   if (current_class == NULL)
      simple_error("Message appears outside of class in database file");
   else
      current_class->messages = list_add_item(current_class->messages, (void *) m);

   current_message = h;
   st.curmessage = message_id;
   /* OK if message already in table; just ignore return value */
   table_insert(st.globalvars, (void *) id, id_hash, id_compare);
   return True;
}
Ejemplo n.º 5
0
/*------------------------------------------------------------------------
Procedure:     SendLastEditBuffer ID:1
Author:		   Chris Watford [email protected]
Purpose:       Sends an edit buffer to the pipe
Input:
Output:
Errors:
--------------------------------------------------------------------------
Edit History:
     7 Aug  2004 - Chris Watford [email protected]
		- Fixed error where SendLastEditBuffer sent waaaay too many
		newlines which completely broke the underlying connection to the
		ocaml.exe pipe
	15 Sept 2003 - Chris Watford [email protected]
		- Sends line to the pipe and adds newline to the end
------------------------------------------------------------------------*/
void SendLastEditBuffer(HWND hwndChild)
{
	char* line = editbuffer_getasbuffer(CurrentEditBuffer);
	int l = strlen(line) - 1;
	char* linebuffer = (char*)SafeMalloc(l+2);

	// save current edit buffer to history and create a new blank edit buffer
	CurrentEditBuffer->isCorrect = TRUE;
	AddToHistory(CurrentEditBuffer);
	CurrentEditBuffer = (EditBuffer*)SafeMalloc(sizeof(EditBuffer));
	CurrentEditBuffer->LineCount = 0;
	CurrentEditBuffer->Lines = NULL;

	// trim and add the newline to the end
	strncpy(linebuffer, line, l+1);
	while((linebuffer[l] == '\n' || linebuffer[l] == '\r') && (l >= 0))
	{
		linebuffer[l--] = '\0';
	}

	linebuffer[l+1] = '\n';
	linebuffer[l+2] = '\0';

	// save line to the pipe
	WriteToPipe(linebuffer);
}
Ejemplo n.º 6
0
int	SetVars(char *name)
{
    if (!GetScriptInfo(name))
        return(false);

    if (!CheckVars())
        return(false);

    destsize = out.w * out.h;

    out.cw = out.w / xcharsize;
    out.ch = out.h / ycharsize;

    if ((usagemap = (long *)SafeMalloc(destsize * 4, "")) == NULL)
        return(false);
    if ((outpixels = (long *)SafeMalloc(destsize * 4, "")) == NULL)
        return(false);
    if ((bmptemp = (void *)SafeMalloc(destsize * 4, "")) == NULL)
        return(false);
    if ((map = (byte *)SafeMalloc(destsize / (xcharsize * ycharsize), "")) == NULL)
        return(false);

    if (GetFileDimensions() == false)
        return(false);

    if (dosort)
        SortInNames();

    return(true);
}
NODE *BuildTree(NODE *pNode, char *str, BIN *activeBin)
{
   if (pNode == NULL)                               /* string not found */
   {
      size_t length = strlen(str) + 1;              /* length of string */

      pNode = (NODE *)SafeMalloc(sizeof(NODE));     /* allocate a node */
      pNode->strng = (char *)SafeMalloc(length);
      memcpy(pNode->strng, str, length);            /* copy string */
      pNode->count = 1;                             /* 1st occurrence */
      pNode->left = pNode->right = NULL;            /* no subtrees */
      activeBin->nodes++;
   }
   else
   {
      int result = strcmp(str, pNode->strng);    
      /* compare strings */
      if (result == 0)                           
         /* new string == current */
         ++pNode->count;                         
      /* increment occurrence */
      else if (result < 0)                       
         /* new string < current */
         pNode->left = BuildTree(pNode->left, str, activeBin);     
      /* traverse left */
      else                                       
         /* new string > current */
         pNode->right = BuildTree(pNode->right, str, activeBin);   
      /* traverse right */
   }
   return(pNode);
}
Ejemplo n.º 8
0
LinkN* makeLink(Point **e, Primitive *p, bool s){
	LinkN *newLink = SafeMalloc(sizeof(LinkN));
	EdgeListEntry *newEdge = SafeMalloc(sizeof(EdgeListEntry));
	newLink->data = newEdge;
	INIT_ELN(*newEdge, e, p, s);
	return newLink;
}
Ejemplo n.º 9
0
int load_add_resource(char *resource_name, int resource_id)
{
   id_type id = (id_type) SafeMalloc(sizeof(id_struct));
   resource_type r = (resource_type) SafeMalloc(sizeof(resource_struct));
   
   id->name = strdup(resource_name);
   id->idnum = resource_id;
   id->type = I_RESOURCE;
   id->ownernum = st.curclass;
   id->source = DBASE;

   r->lhs = id;
   // Have to load in resources from *rsc files
   for (int i = 0; i < sizeof(r->resource) / sizeof(r->resource[i]); i++)
   {
      r->resource[i] = NULL;
   }

   /* Add resource to resource list of current class */
   if (current_class == NULL)
      database_error("Resource appears outside of class in database file");
   current_class->resources = list_add_item(current_class->resources, (void *) r);

   /* OK if parameter already in table; just ignore return value */
   table_insert(st.globalvars, (void *) id, id_hash, id_compare);
   return True;
}
Ejemplo n.º 10
0
/*
* RscAddCallback:  Called for each new resource that's loaded from a file.
*   Add given resource to table.
*/
bool RscAddCallback(char *fname, int res, int lang_id, char *string)
{
   resource_type r;

   // Check for existing resource first, since we might want to add
   // another language string to it.
   r = (resource_type) table_lookup(t, &res, IdHash, IdResourceCompare);
   if (r == NULL)
   {
      r = (resource_type) SafeMalloc(sizeof(resource_struct));
      r->idnum = res;

      for (int i = 0; i < MAX_LANGUAGE_ID; i++)
         r->resource[i] = NULL;
   }
   else
      table_delete_item(t, r, ResourceHash, ResourceCompare);

   // Shouldn't be able to compile blakod with multiple strings
   // of the same language type.
   if (r->resource[lang_id])
      SafeFree(r->resource[lang_id]);
   r->resource[lang_id] = (char *) SafeMalloc(strlen(string) + 1);
   strcpy(r->resource[lang_id], string);

   available_languages[lang_id] = True;

   // Replace the existing resource if we used it.
   table_insert(t, r, ResourceHash, ResourceCompare);

   return true;
}
Ejemplo n.º 11
0
expr_type make_expr_from_id(id_type id)
{
   expr_type e = (expr_type) SafeMalloc(sizeof(expr_struct));
   
   /* Id must be a parameter, local, property, constant, or resource */
   lookup_id(id);		
   switch(id->type)
   {
   case I_LOCAL:
   case I_PROPERTY:
   case I_CLASSVAR:
      e->type = E_IDENTIFIER;
      e->value.idval = id;
      break;

   case I_RESOURCE:
   {
      const_type c = (const_type) SafeMalloc(sizeof(const_struct));

      /* Turn resource id reference into the resource # itself */
      c->type = C_RESOURCE;
      c->value.numval = id->idnum; 

      e->type = E_CONSTANT;
      e->value.constval = c;
      return e;
   }

   case I_CONSTANT:
   {
      const_type c = (const_type) SafeMalloc(sizeof(const_struct));
      id_type temp;

      /* Turn constant id reference into the constant itself */
      c->type = C_NUMBER;

      temp = (id_type) list_find_item(st.constants, id, id_compare);
      c->value.numval = temp->source; /* Value is stored in source field */

      e->type = E_CONSTANT;
      e->value.constval = c;
      break;
   }
   case I_UNDEFINED:
   case I_MISSING:
      action_error("Unknown identifier %s", id->name);
      /* Put in something so that compilation can continue */
      e = make_expr_from_constant(make_nil_constant());
      break;

   default:
      action_error("Identifier %s in expression has wrong type", id->name);
      /* Put in something so that compilation can continue */
      e = make_expr_from_constant(make_nil_constant());
      break;
   }
   e->lineno = lineno;
   return e;
}
Ejemplo n.º 12
0
/*
====================
=
= SetMessage
=
====================
*/
void SetMessage
   (
   int   num,
   char *text,
   int   flags
   )

   {
   int i;
   int msg;
   int length;
   boolean found;


   length = StringLength( text );

   Messages[ num ].active = 1;
   Messages[ num ].flags  = flags;

   if ( PERMANENT_MSG( flags ) )
      {
      int l;

      l = COM_MAXTEXTSTRINGLENGTH + 1;
      Messages[ num ].text = SafeMalloc( l );
      memset( Messages[ num ].text, 0, l );

      // Hack so that we can place menu in certain order
      Messages[ num ].tictime = -100 + MsgPos;
      }
   else
      {
      Messages[ num ].text = SafeMalloc( length );

      memset( Messages[ num ].text, 0, length );
      Messages[ num ].tictime = MESSAGETIME;
      }

   memcpy( Messages[ num ].text, text, length );

   GetMessageOrder();
   found = false;
   for( i = 0; i < TotalMessages; i++ )
      {
      msg = MessageOrder[ i ];
      if ( msg == num )
         {
         found = true;
         }
      else if ( found )
         {
         UpdateMessageBackground -= EraseMessage[ i - 1 ];
         UpdateMessageBackground += 3;
         EraseMessage[ i - 1 ] = 3;
         }
      }
   }
Ejemplo n.º 13
0
arg_type make_arg_from_setting(id_type id, expr_type expr)
{
   setting_type s = (setting_type) SafeMalloc(sizeof(setting_struct));
   arg_type arg = (arg_type) SafeMalloc(sizeof(arg_struct));

   s->id = id;
   s->expr = expr;
   
   arg->type = ARG_SETTING;
   arg->value.setting_val = s;
   return arg;
}
Ejemplo n.º 14
0
/*
 * LoadSidedefs:  Load sidedefs, and set global sidedefs variable to array of sidedefs.
 *   Return True on success.
 */
Bool LoadSidedefs(file_node *f, room_type *room, int num_sidedefs)
{
   int i, size, period;
   BYTE speed;

   size = num_sidedefs * sizeof(Sidedef);
   room->sidedefs = (Sidedef *) SafeMalloc(size);
   memset(room->sidedefs, 0, size);

   for (i=0; i < num_sidedefs; i++)
   {
      Sidedef *s = &room->sidedefs[i];
      
      if (CliMappedFileRead(f, &s->server_id, 2) != 2) return False;
      security += s->server_id;
      
      // Get wall bitmaps
      if (CliMappedFileRead(f, &s->normal_type, 2) != 2) return False;
      s->normal_bmap = GetGridPdib(s->normal_type);
      if (CliMappedFileRead(f, &s->above_type, 2) != 2) return False;
      s->above_bmap  = GetGridPdib(s->above_type);
      if (CliMappedFileRead(f, &s->below_type, 2) != 2) return False;
      s->below_bmap  = GetGridPdib(s->below_type);
      security += s->above_type + s->below_type + s->normal_type;

      if (CliMappedFileRead(f, &s->flags, 4) != 4) return False;
      security += s->flags;
      if (CliMappedFileRead(f, &speed, 1) != 1) return False;

      // Set up animation, if any
      if (speed != 0)
      {
	 s->animate = (RoomAnimate *) SafeMalloc(sizeof(RoomAnimate));
	 RoomSetupCycleAnimation(s->animate, speed);
      }
      else if (WallScrollSpeed(s->flags) != SCROLL_NONE)
      {
	 // Slow down wall scrolling speed; this is because we notice subjectively
	 // that walls are scrolling too fast.
	 speed = WallScrollSpeed(s->flags);
	 switch (speed)
	 {
	 case SCROLL_SLOW:   period = SCROLL_WALL_SLOW_PERIOD;     break;
	 case SCROLL_MEDIUM: period = SCROLL_WALL_MEDIUM_PERIOD;   break;
	 case SCROLL_FAST:   period = SCROLL_WALL_FAST_PERIOD;     break;
	 }
	 s->animate = (RoomAnimate *) SafeMalloc(sizeof(RoomAnimate));
	 RoomSetupScrollAnimation(s->animate, period, WallScrollDirection(s->flags));
      }
      else s->animate = NULL;
   }
   return True;
}
Ejemplo n.º 15
0
stmt_type make_while_stmt(expr_type condition, list_type stmts)
{
   stmt_type stmt = (stmt_type) SafeMalloc(sizeof(stmt_struct));
   while_stmt_type s = (while_stmt_type) SafeMalloc(sizeof(while_stmt_struct));

   s->condition = condition;
   s->body = stmts;

   stmt->type = S_WHILE;
   stmt->value.while_stmt_val = s;
   return stmt;
}
Ejemplo n.º 16
0
stmt_type make_if_stmt(expr_type condition, list_type then_stmts, list_type else_stmts)
{
   stmt_type stmt = (stmt_type) SafeMalloc(sizeof(stmt_struct));
   if_stmt_type s = (if_stmt_type) SafeMalloc(sizeof(if_stmt_struct));

   s->condition = condition;
   s->then_clause = then_stmts;
   s->else_clause = else_stmts;

   stmt->type = S_IF;
   stmt->value.if_stmt_val = s;
   return stmt;
}
Ejemplo n.º 17
0
void D3DParticleEmitterInit(particle_system *pParticleSystem, float posX, float posY, float posZ,
                           float velX, float velY, float velZ, unsigned char b, unsigned char g,
                           unsigned char r, unsigned char a, int energy, int timerBase,
                           float rotX, float rotY, float rotZ, int randomPos, int randomRot,
                           int maxParticles, int emitterFlags)
{
   emitter	*pEmitter = NULL;

   if (pParticleSystem == NULL)
      return;

   pEmitter = (emitter *)SafeMalloc(sizeof(emitter));

   if (pEmitter == NULL)
      return;
   // User can choose how many particles to display.
   pEmitter->maxParticles = (maxParticles * config.particles) / 100;
   if (pEmitter->maxParticles <= 0)
      return;

   // Allocate particle mem and set to 0.
   pEmitter->particles = (particle *)SafeMalloc(pEmitter->maxParticles * sizeof(particle));
   memset(pEmitter->particles, 0, pEmitter->maxParticles * sizeof(particle));

   pEmitter->numParticles = 0;
   pEmitter->numAlive = 0;
   pEmitter->emitterFlags = emitterFlags;
   pEmitter->pos.x = posX;
   pEmitter->pos.y = posY;
   pEmitter->pos.z = posZ;
   pEmitter->rotation.x = rotX;
   pEmitter->rotation.y = rotY;
   pEmitter->rotation.z = rotZ;
   pEmitter->velocity.x = velX;
   pEmitter->velocity.y = velY;
   pEmitter->velocity.z = velZ;
   pEmitter->energy = energy;
   pEmitter->timer = timerBase;
   pEmitter->timerBase = timerBase;
   pEmitter->bgra.b = b;
   pEmitter->bgra.g = g;
   pEmitter->bgra.r = r;
   pEmitter->bgra.a = a;
   pEmitter->randomPos = randomPos;
   pEmitter->randomRot = randomRot;

   if (!pParticleSystem->emitterList)
      pParticleSystem->emitterList = list_create(pEmitter);
   else
      list_add_item(pParticleSystem->emitterList, pEmitter);
}
Ejemplo n.º 18
0
/* Return False on error, True on success */
int load_add_class(char *class_name, int class_id, int superclass_id, char *superclass_name)
{
   /* Build up a class data structure for the new class. */
   id_type id = (id_type)SafeMalloc(sizeof(id_struct));
   id_type temp_id = (id_type)SafeMalloc(sizeof(id_struct));
   class_type c = (class_type)SafeMalloc(sizeof(class_struct));

   // Adding new built-in object types will render existing kodbase.txt files
   // incompatible. This isn't a problem as a pre-existing kodbase.txt is only
   // required for reloading a live server, so a new one can be made. Check
   // for built-in class name/ID mismatches here and instruct the user to
   // delete kodbase.txt if this check fails.

   extern id_struct BuiltinIds[];
   if ((strcmp(BuiltinIds[SETTINGS_CLASS].name, class_name) == 0
         && class_id != SETTINGS_CLASS)
      || (strcmp(BuiltinIds[REALTIME_CLASS].name, class_name) == 0
         && class_id != REALTIME_CLASS)
      || (strcmp(BuiltinIds[EVENTENGINE_CLASS].name, class_name) == 0
         && class_id != EVENTENGINE_CLASS))
   {
      database_error("Incompatible kodbase.txt. Delete the file and recompile.");
      return False;
   }

   id->name = strdup(class_name);
   id->idnum = class_id;
   id->type = I_CLASS;
   id->source = DBASE;

   c->class_id = id;
   c->properties = c->messages = c->resources = c->classvars = NULL;
   c->is_new = False;  /* Don't generate code for this class */
   /* Store superclass id # in pointer for now.  Id # will be converted to pointer
    * when build_superclasses below is called. */
   c->superclass = (class_type) superclass_id;

   /* Add to list of classes that have been read in */
   st.classes = list_add_item(st.classes, (void *) c);

   current_class = c;
   st.curclass = class_id;
   current_message = NULL;

   /* Call table_insert instead of add_identifier so that our id # from
    * the database file is preserved. 
    */
   if (table_insert(st.globalvars, (void *) id, id_hash, id_compare) == 0)
      return True;
   else return False;
}
Ejemplo n.º 19
0
Archivo: parser.c Proyecto: ihh/gertie
Parser* parserNew (int symbols, int rules) {
  Parser* parser;
  parser = SafeMalloc (sizeof (Parser));
  parser->symbols = symbols;
  parser->rules = rules;
  parser->len = 0;
  parser->alloc = 1;
  parser->debug = 0;
  parser->rule = SafeMalloc (rules * sizeof (Rule));
  parser->p_empty = SafeCalloc (symbols, sizeof (double));
  parser->cell = SafeMalloc (sizeof (Cell*));
  parser->tokseq = NULL;
  parser->cell[0] = NULL;
  return parser;
}
Ejemplo n.º 20
0
/* Make a call to the LIST function from a list of expressions */
stmt_type make_list_call(list_type l)
{
   stmt_type stmt = (stmt_type) SafeMalloc(sizeof(stmt_struct));
   call_stmt_type s = (call_stmt_type) SafeMalloc(sizeof(call_stmt_struct));
   
   s->function = LIST;
   s->args = NULL;
   
   for ( ; l != NULL; l = l->next)
      s->args = list_add_item(s->args, make_arg_from_expr((expr_type) l->data));

   stmt->type = S_CALL;
   stmt->value.call_stmt_val = s;
   return stmt;
}
Ejemplo n.º 21
0
void CmdAliasInit(void)
{
	// Command Aliases
    char* pVerb;
    char* pCommand;
    int nAllocated = 1024;
    char* pSection = (char *) SafeMalloc(nAllocated);
    
    while (pSection)
    {
       int nReturned;
       
       // Fills buffer with "verb=command\0verb=command\0\0".
       nReturned = GetPrivateProfileSection(
          command_section,
          pSection, nAllocated,
          cinfo->ini_file);
       
       // Indicates buffer was big enough.
       if (nReturned && nReturned < nAllocated-2)
          break;
       
       SafeFree(pSection);
       pSection = NULL;
       
       // Buffer needs to grow.
       if (nReturned)
       {
          nAllocated = nAllocated * 4 / 3;
          pSection = (char *) SafeMalloc(nAllocated);
       }
    }
    
    pVerb = pSection;
    if (!pSection || !pSection[0])
       pVerb = _szDefaultVerbAliases;
    
    while (*pVerb)
    {
       pCommand = strtok(pVerb, "=");
       pCommand = strtok(NULL, "");
       AddVerbAlias(pVerb, pCommand);
       pVerb = pCommand+strlen(pCommand)+1;
    }
    
    if (pSection)
       SafeFree(pSection);
}
Ejemplo n.º 22
0
/*
 * EachRscCallback:  Called for each resource that's loaded.
 */
bool EachRscCallback(char *filename, int rsc, int lang_id, char *string)
{
    Resource *r;

    // See if we've added this resource already.
    for (r = resources; r != NULL; r = r->next)
    {
        if (r->number == rsc)
        {
            r->string[lang_id] = strdup(string);

            return true;
        }
    }

    r = (Resource *) SafeMalloc(sizeof(Resource));
    r->number = rsc;

    for (int i = 0; i < MAX_LANGUAGE_ID; i++)
        if (i == lang_id)
            r->string[i] = strdup(string);
        else
            r->string[i] = NULL;

    r->next = resources;
    resources = r;

    return true;
}
Ejemplo n.º 23
0
/*------------------------------------------------------------------------
 Procedure:     SaveText ID:1
 Purpose:       Saves the contents of the session transcript. It will
                loop for each line and write it to the specified file
 Input:         The name of the file where the session will be saved
 Output:        The session is saved
 Errors:        If it can't open the file for writing it will show an
                error box
--------------------------------------------------------------------------
 Edit History:
    06 Oct  2003 - Chris Watford [email protected]
        - Corrected wsprintf error
------------------------------------------------------------------------*/
static void SaveText(char *fname)
{
        int i,len;
        HWND hEdit = (HWND)GetWindowLongPtr(hwndSession,DWLP_USER);
        int linesCount = SendMessage(hEdit,EM_GETLINECOUNT,0,0);
        FILE *f;
        char *buf = SafeMalloc(8192);

        f = fopen(fname,"wb");
        if (f == NULL)
        {
            // corrected error using wsprintf
            wsprintf(buf, "Impossible to open %s for writing", fname);

            ShowDbgMsg(buf);
            return;
        }

        for (i = 0; i < linesCount; i++)
        {
                *(unsigned short *)buf = 8100;
                len = SendMessage(hEdit, EM_GETLINE, i, (LPARAM)buf);
                buf[len] = '\0';
                fprintf(f, "%s\r\n", buf+1);
                //fwrite(buf,1,len+2,f);
        }

        fclose(f);
        free(buf);
}
Ejemplo n.º 24
0
miptex_t *CreateBook8(byte *buffer, int w, int h, byte *palette, int *FinalSize)
{
	miptex_t	*mp;
	int			i, j;
	byte		*pos;
	int			size;

	size = sizeof(*mp) + (w * h);
	mp = (miptex_t *)SafeMalloc(size, "CreateBook8");
	memset(mp, 0, size);

	mp->version = MIP_VERSION;

	for(i=j=0;i<256;i++,j+=3)
	{
		mp->palette[i].r = palette[j];
		mp->palette[i].g = palette[j+1];
		mp->palette[i].b = palette[j+2];
	}
	pos = (byte *)(mp + 1);

	mp->width[0] = w;
	mp->height[0] = h;
	mp->offsets[0] = sizeof(*mp);
	memcpy(pos, buffer, w * h);

	*FinalSize = size;
	return(mp);
}
Ejemplo n.º 25
0
void SetupTierStuff() {
	// kSupportsTierGamesman
	kSupportsTierGamesman = TRUE;
	// function pointers
	gTierChildrenFunPtr = &TierChildren;
	gNumberOfTierPositionsFunPtr = &NumberOfTierPositions;
	gTierToStringFunPtr = &TierToString;
	// hashes
	// Tier-Specific Hashes
	int piecesArray[10] = { BLACK, 0, 0, WHITE, 0, 0, SPACE, 0, 0, -1 };
	int blackPiecesOnBoard, whitePiecesOnBoard, tier;
	for (tier = 0; tier <= boardsize; tier++) {
		blackPiecesOnBoard = (boardsize - tier + 1) / 2;
		whitePiecesOnBoard = (boardsize - tier) / 2;
		// Reds AND Blues = from 0 to piecesOnBoard
		piecesArray[1] = blackPiecesOnBoard;
		piecesArray[2] = blackPiecesOnBoard;
		piecesArray[4] = whitePiecesOnBoard;
		piecesArray[5] = whitePiecesOnBoard;
		// Blanks = tier
		piecesArray[7] = piecesArray[8] = tier;
		// make the hashes
		generic_hash_init(boardsize, piecesArray, NULL, 0);
	}
	// Initial
	int i;
	char* initial = (char *) SafeMalloc(boardsize * sizeof(char));
	for(i = 0; i < boardsize; i++)
		initial[i] = SPACE;
	gInitialTier = boardsize;
	generic_hash_context_switch(gInitialTier);
	gInitialTierPosition = hash(initial, 1);
}
Ejemplo n.º 26
0
STRING MoveToString (MOVE move){
	STRING moveStr = (STRING) SafeMalloc(sizeof(char)*3);
	moveStr[0] = (move/100)+'a'-1;
	moveStr[1] = (move % 100) + '0';
	moveStr[2] = '\0';
	return moveStr;
}
Ejemplo n.º 27
0
/* if it grows down, the InitialCount will be ignored. Otherwise, TheFirstAddress will be ignored. */
int Array_Init(__in Array *a, __in int DataLength, __in int InitialCount, __in BOOL GrowsDown, __in void *TheFirstAddress /* The first means the biggest address*/)
{
	if( InitialCount < 0)
		return 1;

	a -> DataLength = DataLength;
	a -> Used = 0;

	if( GrowsDown == FALSE )
	{
		if( InitialCount > 0 )
		{
			a -> Data = SafeMalloc(DataLength * InitialCount);
			if( a -> Data == NULL )
				return 2;

			memset(a -> Data, 0, DataLength * InitialCount);
		} else {
			a -> Data = NULL;
		}

		a -> Allocated = InitialCount;
	} else {
		a -> Allocated = -1;
		a -> Data = TheFirstAddress;
	}

	return 0;
}
Ejemplo n.º 28
0
stk_stack * StackCreate() {
  stk_stack * newStack;
  
  newStack=(stk_stack *) SafeMalloc(sizeof(stk_stack));
  newStack->top=newStack->tail=NULL;
  return(newStack);
}
Ejemplo n.º 29
0
/*
** function code
*/
void db_create() {

	/*if there is an old database table, get rid of it*/
	db_destroy();

	/* get a new table */
	db_functions = (DB_Table *) SafeMalloc(sizeof(DB_Table));

	/*set all function pointers to NULL, and each database can choose*/
	/*whatever ones they wanna implement and associate them*/

	db_functions->get_value = db_get_value;
	db_functions->put_value = db_put_value;
	db_functions->get_remoteness = db_get_remoteness;
	db_functions->put_remoteness = db_put_remoteness;
	db_functions->check_visited = db_check_visited;
	db_functions->mark_visited = db_mark_visited;
	db_functions->unmark_visited = db_unmark_visited;
	db_functions->get_mex = db_get_mex;
	db_functions->put_mex = db_put_mex;
	db_functions->get_winby = db_get_winby;
	db_functions->put_winby = db_put_winby;
	db_functions->save_database = db_save_database;
	db_functions->load_database = db_load_database;
	db_functions->free_db = db_free;
	db_functions->get_bulk = db_get_bulk;
}
Ejemplo n.º 30
0
boolean SD_StartRecordingSound ( void )
{
   int status;

   if (SD_Started==false)
      return false;
   if (remoteridicule == false)
      return false;
   if ( ( Recording==true ) || ( Playback==true ) || (Feeder==true))
      {
      return false;
      }
   Recording=true;
   RecordingBuffer = SafeMalloc (RECORDINGBUFFERSIZE);
   Feeder = false;
   FeederPointer = -1;
   RecordingPointer = 0;

   status=FX_StartRecording( RECORDINGSAMPLERATE, SD_UpdateRecordingSound);

   if (status!=FX_Ok)
      {
      Recording=false;
      SafeFree(RecordingBuffer);
      return false;
      }

   return true;
}