Ejemplo n.º 1
0
/************************************************************************************
 * Function: PackAccount
 * Description: Utility function that takes an unpacked account, optionally encrypts
 * it and packs it into a buffer, strings are seperated by null characters. puts the 
 * content in retbuffer
 * *********************************************************************************/ 
void PackAccount (MemPtr retbuff, Account acct, md_hash * pass,
			 Boolean encrypt) {
	UInt16 offset = 0;
	MemPtr pacct;
	if ((pacct = MemPtrNew (MemPtrSize (retbuff)))) {	
		/*	pack the fields of the account buffer together */
		MemMove (pacct + offset, &acct.SystemID, sizeof (acct.SystemID));
		offset += sizeof (acct.SystemID);
		MemMove (pacct + offset, &acct.AccountID, sizeof (acct.AccountID));
		offset += sizeof (acct.AccountID);
		MemMove (pacct + offset, acct.hash, sizeof (md_hash));
		offset += sizeof (md_hash);
		MemMove (pacct + offset, &acct.series, sizeof (acct.series));
		offset += sizeof (acct.series);
		MemMove (pacct + offset, &acct.hash_type, sizeof (acct.hash_type));
		offset += sizeof (acct.hash_type);
		MemMove (pacct + offset, &acct.system_type, sizeof (acct.system_type));
		offset += sizeof (acct.system_type);
		MemMove (pacct + offset, &acct.service_type, sizeof (acct.service_type));
		offset += sizeof (acct.service_type);
		MemMove (pacct + offset, &acct.username_type, sizeof (acct.username_type));
		offset += sizeof (acct.username_type);
		MemMove (pacct + offset, &acct.password_type, sizeof (acct.password_type));
		offset += sizeof (acct.password_type);

		MemMove (pacct + offset, &acct.account_mod_date, sizeof (acct.account_mod_date));
		offset += sizeof (acct.account_mod_date);
		MemMove (pacct + offset, &acct.password_mod_date, sizeof (acct.password_mod_date));
		offset += sizeof (acct.password_mod_date);
		MemMove (pacct + offset, &acct.binary_data_length, sizeof (acct.binary_data_length));
		offset += sizeof (acct.binary_data_length);

		MemMove (pacct + offset, acct.system, StrLen (acct.system) + 1);
		offset += StrLen (acct.system) + 1;
		MemMove (pacct + offset, acct.service, StrLen (acct.service) + 1);
		offset += StrLen (acct.service) + 1;
		MemMove (pacct + offset, acct.username, StrLen (acct.username) + 1);
		offset += StrLen (acct.username) + 1;
		MemMove (pacct + offset, acct.password, StrLen (acct.password) + 1);
		offset += StrLen (acct.password) + 1;
		MemMove (pacct + offset, acct.comment, StrLen (acct.comment) + 1);
		offset += StrLen (acct.comment) + 1;
		MemMove (pacct + offset, acct.key, StrLen (acct.key) + 1);
		offset += StrLen (acct.key) + 1;

		MemMove (pacct + offset, &acct.binary_data, acct.binary_data_length);
		offset += acct.binary_data_length;

		/*	optionally encrypt */
		if (encrypt) {
			MemMove (retbuff, pacct, ACCT_HEADER);
			stripCrypt (*pass, (pacct+ACCT_HEADER), (retbuff+ACCT_HEADER), 
				(getAccountSize (&acct, true) - ACCT_HEADER), 1);  				 
		} else MemMove (retbuff, pacct, getAccountSize (&acct, false));

		MemSet (pacct, MemPtrSize (pacct), 0);
		MemPtrFree (pacct);
	}
}
Ejemplo n.º 2
0
/**
 * Changes size of preallocated space for memory object "pObject"
 * to the new size specified by "constSize".
 *
 * If the new size is larger than the old size, the old contents
 * is not changed. Additionally space is added at the the end of
 * "pObject". The new allocated space is not initialized
 * to any special value.
 * If the new size is smaller than the old size, the unused space
 * is discarded.
 *
 * If "pObject" is a NULL pointer, this function behaves just like
 * smlLibMalloc().
 * If "pObject" does not point to a previously allocated memory area,
 * the behavior is undefined.
 * If "constSize" is 0, a NULL pointer is returned and the space
 * which "pObject" points to is freed up.
 *
 * Returns a pointer to the first byte of the resized object.
 * If no new memory could be allocated, a NULL Pointer is returned
 * without changing the memory object "pObject" (Nothing happens to the content).
 *
 * @param pObject (IN/OUT)
 *        memory object, which size should be changed
 * @param constSize (IN)
 *        new size the memory object shall use
 * @return void pointer to memory object, which size has been be changed\n
 *         NULL, if not successfull or if constSize==0
 */
SML_API void *smlLibRealloc(void *pObject, MemSize_t constSize)
{
#ifdef __PALM_OS__
  VoidPtr_t _new_object;
  MemSize_t   _old_size;

    // It's a malloc!
    if (pObject == NULL)
        return smlLibMalloc(constSize);

    _old_size = MemPtrSize(pObject);
    if (constSize <= _old_size) {
        // make it smaller
        MemPtrResize(pObject, constSize);
        _new_object = pObject;
    } else {
        // maker it larger (we need to allocate new memory somewhere else)
        _new_object = smlLibMalloc(constSize);
        if (_new_object != NULL) {
            smlLibMemmove(_new_object, pObject, _old_size);
            smlLibFree(pObject);
        }
    }

  return _new_object;
#else
  // %%% luz 2002-10-02
  #ifdef MEMORY_PROFILING
  return sysync_realloc(pObject, constSize);
  #else
  return realloc(pObject, constSize);
  #endif
#endif
}
Ejemplo n.º 3
0
void* PrvRealloc(void* p, UInt32 newSize)
{
    if (0 == newSize)
    {
        if (NULL != p)
            MemPtrFree(p);
        return NULL;
    }
    newSize = PrvBlockSize(newSize);
    if (NULL == p)
        return MemGluePtrNew(newSize);

    UInt32 size = MemPtrSize(p);
    if (newSize <= size)
        return p;

    Err err = MemPtrResize(p, newSize);
    if (errNone == err)
        return p;

    void* np = MemGluePtrNew(newSize);
    if (NULL != np)
        MemMove(np, p, size);

    MemPtrFree(p);
    return np;
}
Ejemplo n.º 4
0
XPTEXP1 void * XPTAPI XPTEXP2 xppRealloc(void *ptr, size_t size) {
   Err rc;
   UInt32 currentSize;
   void *newMem;

   /* If original pointer is null, act like a normal malloc                */
   if (!ptr) return MemPtrNew(size);

   /* Try resizing original area.  This will always work if the new area   */
   /* is smaller.  It may or may not work if growing the area.             */
   rc = MemPtrResize(ptr, size);
   if (!rc) return ptr;             /* It worked.  Return same pointer.    */

   /* Resizing didn't work.  Allocate a new, larger, area, and copy the    */
   /* previous data from the old area.                                     */
   newMem = MemPtrNew(size);
   if (!newMem) return newMem;      /* Pass error to caller                */

   /* The original size must be smaller than the new size                  */
   currentSize = MemPtrSize(ptr);
   MemMove(newMem, ptr, currentSize);

   /* Release the old area.                                                */
   MemPtrFree(ptr);

   return newMem;
}
Ejemplo n.º 5
0
/**
 * FUNCTION: smlLibRealloc
 *
 * Changes size of preallocated space for memory object "pObject"
 * to the new size specified by "constSize".
 *
 * If the new size is larger than the old size, the old contents 
 * is not changed. Additionally space is added at the the end of 
 * "pObject". The new allocated space is not initialized 
 * to any special value.
 * If the new size is smaller than the old size, the unused space
 * is discarded.
 *
 * If "pObject" is a NULL pointer, this function behaves just like 
 * smlLibMalloc().
 * If "pObject" does not point to a previously allocated memory area, 
 * the behavior is undefined.
 * If "constSize" is 0, a NULL pointer is returned and the space 
 * which "pObject" points to is freed up.
 *
 * Returns a pointer to the first byte of the resized object.
 * If no new memory could be allocated, a NULL Pointer is returned 
 * without changing the memory object "pObject" (Nothing happens to the content).
 *
 * IN/OUT           void *pObject,      memory object, which size should be changed
 * IN:              MemSize_t constSize new size the memory object shall use
 * RETURN:          void*               Pointer to memory object, which size has been
 *                                      be changed
 *                                      NULL, if not successfull or
 *                                            if constSize==0
 */
SML_API void *smlLibRealloc(void *pObject, MemSize_t constSize)
{
#ifdef __PALM_OS__
	VoidPtr_t	_new_object;
	MemSize_t 	_old_size;    
  
  	// It's a malloc!
  	if (pObject == NULL)
    		return smlLibMalloc(constSize);
    
  	_old_size = MemPtrSize(pObject); 
  	if (constSize <= _old_size) {
     		// make it smaller
     		MemPtrResize(pObject, constSize);
     		_new_object = pObject;
  	} else {
     		// maker it larger (we need to allocate new memory somewhere else)
     		_new_object = smlLibMalloc(constSize);
     		if (_new_object != NULL) {
        		smlLibMemmove(_new_object, pObject, _old_size);
        		smlLibFree(pObject);
     		}
  	}           

	return _new_object;
#else
  return DmReallocMem(pObject, (UINT32)constSize);
	
#endif
}
Ejemplo n.º 6
0
//***********************************************************
// Procedure: realloc
//
// Parameter: ptr     Pointer to current memory
//            size    Size of new memory block
//
// Returnval: Pointer to memory or NULL on error
//
// Description: Allocate memory and init with 0.
//***********************************************************
void *realloc(void *ptr, size_t size)
{
	void *mem;
  size_t oldsize = 0;
  
  //---------------------------------------------
  // Get size of current mem
  //---------------------------------------------
  if(ptr)
  {
    oldsize = MemPtrSize(ptr);
  }
  
  //---------------------------------------------
  // Get new memory
  //---------------------------------------------
  mem = malloc(size);
  if(mem && ptr)
  {
    //---------------------------------------------
    // Copy old content to new memory
    //---------------------------------------------
    if(size < oldsize)
      oldsize = size;
    memmove(mem, ptr, oldsize);

    //---------------------------------------------
    // Free old mem when we have new
    //---------------------------------------------
    free(ptr);
  }
  
  return mem;
}
Ejemplo n.º 7
0
static void
CourseNameCacheLoad(CacheID id, UInt16 *ids, Char **values, UInt16 numItems)
{
  MemHandle m; 
  UInt16 index=0, i=0;
  
  while ((i < numItems) && ((m = DmQueryNextInCategory(DatabaseGetRef(), &index, DatabaseGetCat())) != NULL)) {
    Char *s=(Char *)MemHandleLock(m);
    if (s[0] == TYPE_COURSE) {
      CourseDBRecord c;
      Char *tempString;

      UnpackCourse(&c, s);
      
      tempString=(Char *)MemPtrNew(StrLen(c.name)+1);
      MemSet(tempString, MemPtrSize(tempString), 0);
      StrCopy(tempString, c.name);

      ids[i] = c.id;
      values[i] = tempString;
      i += 1;
    }
    MemHandleUnlock(m);
    index += 1;
  }
}
Ejemplo n.º 8
0
/************************************************************************************
 * Function: PackRegistration
 * Description: Utility function that takes an unpacked Registration, optionally encrypts
 * it and packs it into a buffer, strings are seperated by null characters. puts the 
 * content in retbuffer
 * *********************************************************************************/ 
void PackRegistration (MemPtr retbuff, Registration reg) {
	UInt16 offset = 0;
	MemPtr preg;
	if ((preg = MemPtrNew (MemPtrSize (retbuff)))) {
		/*	move the data into the buffer. */
		MemMove (preg + offset, &reg.first_use, sizeof (reg.first_use));
		offset += sizeof (reg.first_use);
		MemMove (preg + offset, reg.email, StrLen (reg.email) + 1);
		offset += StrLen (reg.email) + 1;
		MemMove (preg + offset, reg.code, StrLen (reg.code) + 1);
		offset += StrLen (reg.code) + 1;

		MemMove (retbuff, preg, MemPtrSize(preg));
		MemSet (preg, MemPtrSize (preg), 0);
		MemPtrFree (preg);
	}
}
Ejemplo n.º 9
0
/************************************************************************
 * Function: freeHandle
 * Description: free the given handle
 * **********************************************************************/
MemHandle freeHandle (MemHandle handle) {
	if (handle) {
		MemPtr p = MemHandleLock (handle);
		MemSet (p, MemPtrSize (p), 0);
		MemHandleUnlock (handle);
		MemHandleFree (handle);
	}
	return(handle=NULL);
}
Ejemplo n.º 10
0
/***********************************************************************************
 * Function: PackPassword
 * Description: pack a password and encrypt it using spass
 * *********************************************************************************/ 
void PackPassword (MemPtr retbuff,  md_hash * spass) {
	MemPtr ppass;
	if ((ppass = MemPtrNew (getSCSize(sizeof(md_hash))))) {
		MemMove (ppass, spass, sizeof (md_hash));
		stripCrypt (*spass, ppass, retbuff, getSCSize(sizeof(md_hash)), ENCRYPT);
		MemSet (ppass, MemPtrSize (ppass), 0);
		MemPtrFree (ppass);
	}
}
Ejemplo n.º 11
0
/************************************************************************************
 * Function: PackSystem
 * Description: Utility function that takes an unpacked system, optionally encrypts
 * it and packs it into a buffer, strings are seperated by null characters. puts the 
 * content in retbuffer
 * *********************************************************************************/ 
void PackSystem (MemPtr retbuff, System sys, md_hash * pass, Boolean encrypt) {
	UInt16 offset = 0;
	MemPtr psys;
	if ((psys = MemPtrNew (MemPtrSize (retbuff)))) {
		/*	move the data into the buffer. */
		MemMove (psys + offset, &sys.SystemID, sizeof (sys.SystemID));
		offset += sizeof (sys.SystemID);
		MemMove (psys + offset, sys.name, StrLen (sys.name) + 1);
		offset += StrLen (sys.name) + 1;
		
		if (encrypt) {
			MemMove(retbuff, psys, SYST_HEADER);
			stripCrypt (*pass, psys+SYST_HEADER, retbuff+SYST_HEADER, getSystemSize(&sys, true)-SYST_HEADER, ENCRYPT);
		} else MemMove (retbuff, psys, getSystemSize (&sys, true));

		MemSet (psys, MemPtrSize (psys), 0);
		MemPtrFree (psys);
	}
}
Ejemplo n.º 12
0
/*************************************************************************
 * Function: replaceAccountHash
 * Description: regernate the hash on a single account based on account
 * index
 * ***********************************************************************/ 
void replaceAccountHash(UInt16 index, DmOpenRef db, md_hash * SysPass) {
	Account ac;
	MemHandle rH;
	MemPtr pac = NULL, scratch = NULL, scratch2=NULL;
	if ((rH = DmGetRecord (db, index))) {
		pac = MemHandleLock (rH);
		if ((scratch = MemPtrNew (MemPtrSize (pac)))) {
			UnpackAccount (&ac, pac, scratch, SysPass, 
				MemHandleSize (rH), true, true);
			if ((scratch2 = MemPtrNew (MemPtrSize (pac)))) {
				MemMove(ac.hash, 
					generateAccountHash(&ac), 
					sizeof(md_hash)); 
				PackAccount (scratch2, ac, SysPass, true);
				writeRecord(scratch2, rH);
			}
		}
		MemPtrFree(scratch);
		MemPtrFree(scratch2);
		MemHandleUnlock (rH);
		DmReleaseRecord (db, index, true);
	}
}
Ejemplo n.º 13
0
/********************************************************************
 * Function: addRecord
 * Description:  function responsible for writing a packed System record
 * to the database. 
 * ******************************************************************/ 
void writeRecord (MemPtr record, MemHandle recordDBrec) {
	UInt16 length = 0, offset = 0;
	Char *ch;
	
	/* get length of the system buffer */
	length = MemPtrSize (record);
	
	/* re-size and write. */
	if (MemHandleResize (recordDBrec, length) == 0) {
		ch = MemHandleLock (recordDBrec);
		DmWrite (ch, offset, record, length);
		MemHandleUnlock (recordDBrec);
	}
}
Ejemplo n.º 14
0
/*****************************************************************************
* Function: GadgetDrawWeekdays
*
* Description: Draws the weekdays, extra function since called in
*              GadgetDrawTimeline
*****************************************************************************/
void
GadgetDrawWeekdays(void)
{
  UInt8 i;
  MemHandle mh;
  Char *text;
  RGBColorType color, prevColor;
  DateTimeType now;
  Int16 dow;
  RectangleType bounds, rect;
  UInt16 gadgetIndex;

  // Get info about Gadget
  gadgetIndex = FrmGetObjectIndex(gForm, gGadgetID);
  FrmGetObjectBounds(gForm, gadgetIndex, &bounds);

  // Initialize time constants
  TimSecondsToDateTime(TimGetSeconds(), &now);
  dow = DayOfWeek(now.month, now.day, now.year);
  
  RctSetRectangle(&rect, bounds.topLeft.x+GADGET_BASELEFT+GADGET_LEFT, bounds.topLeft.y,
                         130, FntLineHeight()+2);

  // Erase background
  WinEraseRectangle(&rect, 0);

  for (i=0; i < gGadgetDaysNum; ++i) {
    Int16 leftoff;
    mh = DmGetResource(strRsc, GADGET_STRINGS_WDAYSTART+i);
    text = MemHandleLock(mh);
    leftoff = (gGadgetDaysWidth+2 - FntLineWidth(text, MemPtrSize(text))) / 2;
    if (TNisColored() && (dow == i+1)) {
      color.r = 0xFF;  color.g = 0x00;  color.b = 0x00;
      TNSetTextColorRGB(&color, &prevColor);
    }
    WinDrawChars(text, StrLen(text), bounds.topLeft.x+GADGET_BASELEFT+GADGET_LEFT+i*gGadgetDaysWidth+i+leftoff+2, bounds.topLeft.y);
    if (dow == i+1) {
      if (TNisColored()) {
        TNSetTextColorRGB(&prevColor, NULL);
      } else {
        // Draw some kind of underline to determine current day
        Int16 lineWidth=FntLineWidth(text, StrLen(text));
        WinDrawLine(rect.topLeft.x+i*gGadgetDaysWidth+i+leftoff+1, rect.topLeft.y+FntLineHeight(),
                    rect.topLeft.x+i*gGadgetDaysWidth+i+leftoff+1+lineWidth, rect.topLeft.y+FntLineHeight());
      }
    }
    MemHandleUnlock(mh);
  }
}
Ejemplo n.º 15
0
/**************************************************************************
 * Function: getSystemFromIndex
 * Description: based upon a system database index, this will locate the
 * system for that index, unpack and decrypt it and initialize s
 * ************************************************************************/ 
void getSystemFromIndex (DmOpenRef SystemDB, md_hash * SysPass, UInt16 index, MemHandle tmp, System * s) {
	MemHandle rec = DmQueryRecord (SystemDB, index);
	if (rec) {
		MemPtr scratch, buff = MemHandleLock (rec);
		
			/*	resize the buffer */
		if (MemHandleResize (tmp, MemPtrSize (buff)) == 0) {
			scratch = MemHandleLock (tmp);
			
			/*	unpack and decrypt the account */
			UnpackSystem (s, buff, scratch, SysPass, MemHandleSize (rec), true); 
		}
		MemHandleUnlock (rec);
	}
}
Ejemplo n.º 16
0
MemPtr realloc(MemPtr oldP, UInt32 size) {
    MemPtr newP;

    if (oldP != NULL)
        if (MemPtrResize(oldP, size) == 0)
            return oldP;

    newP = malloc(size);	// was MemPtrNew

    if (oldP!=NULL) {
        MemMove(newP,oldP,MemPtrSize(oldP));
        MemPtrFree(oldP);
    }

    return newP;
}
Ejemplo n.º 17
0
/**************************************************************************
 * Function: getAccountFromIndex
 * Description: based upon an account index, this will locate the
 * account for that index, unpack and decrypt it and initialize acc
 * ************************************************************************/ 
void getAccountFromIndex (DmOpenRef AccountDB, md_hash * SysPass, UInt16 index, MemHandle tmp, Account * acc) {
	/*	query the record from the database */
	MemHandle rec = DmQueryRecord (AccountDB, index);
	
	if (rec){
		MemPtr scratch, buff = MemHandleLock (rec);
		
		/*	resize buffer */
		if (MemHandleResize (tmp, MemPtrSize (buff)) == 0) {
			scratch = MemHandleLock (tmp);
			
			/*	unpack the account */
			UnpackAccount (acc, buff, scratch, SysPass, MemHandleSize (rec), true, true);
		}
		MemHandleUnlock (rec);
	}
}
Ejemplo n.º 18
0
}static int
inflate_into_chunk(struct mem_chunk m)
{unsigned cont_size,decompressed;const char*cont;z_stream str;int err;
  unsigned orig_size;MemSet(&str,sizeof str,0);decompressed=0;
  orig_size=*((const unsigned*)*indices);cont=*indices+sizeof(orig_size);
  cont_size=MemPtrSize(*indices)-2;decompressed=0;
  str.next_in=(char*)cont;str.avail_in=cont_size;
  err=inflateInit(&str);
  if(err){zlib_error_alert(err,"inflateInit");return err;}
  while(decompressed<orig_size)
  {unsigned n;str.next_out=zlib_buf;str.avail_out=zlib_buf_size;
   err=inflate(&str,0);
   if(err&&err!=Z_STREAM_END)
   {zlib_error_alert(err,"inflate");inflateEnd(&str);return err;}
   n=zlib_buf_size-str.avail_out;
   write_chunk(m,decompressed,zlib_buf,n);decompressed+=n;
  }while(err!=Z_STREAM_END);
  err=inflateEnd(&str);if(err)zlib_error_alert(err,"inflateEnd");return err;
}static const char*saved_uncompressed;
Ejemplo n.º 19
0
static Boolean SearchRecord
         (
         MemHandle  handle,   /* handle of record to search */
         Char*      pattern,  /* pattern to search for */
         Boolean    onlyOne   /* are we looking only for a single match? */
         )
{
    Boolean     multiple;
    Boolean     done;
    MemHandle   uncompressHandle;
    Header*     record;
    UInt16      uniqueID;
    Char*       text;
    Int16       size;
    Boolean     match;

    multiple = Prefs()->searchFlags & SEARCH_MULTIPLE;
    if ( multiple ) {
        ParseSearchString( pattern );
        if ( ! numSearchTerms )
            return false;
    }

    done                = false;
    record              = MemHandleLock( handle );
    uniqueID            = record->uid;
    lastSearchedRecordId = uniqueID;
    uncompressHandle    = NULL;
    if ( record->type == DATATYPE_PHTML_COMPRESSED ) {
        ErrTry {
            uncompressHandle    = Uncompress( record );
            text                = MemHandleLock( uncompressHandle );
            size                = MemPtrSize( text );
            ResetLastUncompressedPHTML();
        }
        ErrCatch( UNUSED_PARAM( err ) ) {
            MemHandleUnlock( handle );
            return false;
        } ErrEndCatch
    }
Ejemplo n.º 20
0
void* realloc__(void* p, size_t size, const char* file, int line)
{
    if (NULL != p && 0 == size)
    {
        free__(p);
        return NULL;
    }
    if (NULL == p)
        return malloc__(size, file, line);

#ifdef _PALM_OS

    if (errNone == MemPtrResize(p, size))
        return p;

    void* np = malloc__(size, file, line);
    if (NULL == np)
        return NULL;

    MemMove(np, p, MemPtrSize(p));
    free__(p);

#elif defined(_WIN32_WCE)

    void* np = realloc(p, size);
#ifndef NDEBUG    
    if (np != p)
    {
        logAllocation(p, 0, true, __FILE__, __LINE__);
        if (NULL != np)
            logAllocation(np, size, false, __FILE__, __LINE__);
    }
#endif    

#endif

    return np;
}
Ejemplo n.º 21
0
unsigned long memMgrChunkSize(void *ptr)
{
    return MemPtrSize(ptr);
}
Ejemplo n.º 22
0
/***********************************************************************
 *
 * FUNCTION:    FntDefineFont
 *
 * DESCRIPTION: Define a font.  Only an app font may be defined.  The
 * application is responsible for freeing or releasing the font when
 * the application quits.
 *
 * PARAMETERS:  fontID - id of the font to define.  Should be a app defined
 * 							 font only.
 *					 fontP - Pointer to font to use.
 *
 * RETURNED:    memErrNotEnoughSpace - if it isn't able to allocate
 *						space for the new font in the font table.
 *					 0 - if no error
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			roger	 9/26/97	Initial Revision
 *			SCL	12/10/97	Rewrote to support new (separate) app font table
 *			roger	11/ 9/98	Fixed MemMove reading past end of source.
 *			gavin	11/18/98	set UINumAppFonts to count, not index
 *			SCL	11/25/98	Fixed MemMove to copy exact size of old table
 *			vivek 06/07/00 Added support for hierarchical application fonts
 *
 ***********************************************************************/
Err FntDefineFont (FontID fontID, FontPtr fontP)
{
	UInt32			reqSize;
	FontTablePtr	tableP;
	FontTablePtr	newTableP;
	Err				err;
	Int16				appFontIndex;
	Int16				fontIndex;
	Int16				numAppFonts;
	Boolean			isSubFont;

	ErrNonFatalDisplayIf (!FntIsAppDefined(fontID), "App defined fonts only");
	// KEY POINT:  "...Index" is a zero-based array index, whereas
	// "...Num...Fonts" is a one-based number of fonts.
	// Thus, appFontIndex is the array index into which fontP will be installed.
	// The font table must be large enough to support this new font index.
	
	isSubFont = (fontP->fontType & fntAppSubFontMask) ? true : false;
	
	if (isSubFont)
		{
			numAppFonts = MemPtrSize(GAppSubFontListPtr) / sizeof(FontPtr);		
			tableP = GAppSubFontListPtr;
		}
	else
		{
			tableP = UIAppFontTablePtr;
			numAppFonts = UINumAppFonts;
		}
	
	appFontIndex = (FontID) (fontID - fntAppFontCustomBase);
	
		
	// See if there's room in the app font table for this font
	if (appFontIndex >= numAppFonts) 
		{
		// if not, try to resize the table (new size is appFontIndex+1 entries)
		reqSize = (appFontIndex+1) * sizeof(FontPtr);
		err = MemPtrResize(tableP, reqSize);
		
		// If we couldn't resize it, try and reallocate it
		if (err) 
			{
			newTableP = MemPtrNew(reqSize);
			if (!newTableP) return memErrNotEnoughSpace;
			
			// Copy old table (numFonts entries) into new table
			MemMove(newTableP, tableP, numAppFonts * sizeof(FontPtr));
			MemPtrSetOwner(newTableP, 0);

			// Change global to point to new table, and free the old one
			if (isSubFont)
				GAppSubFontListPtr = newTableP;
			else
				UIAppFontTablePtr = newTableP;
			
			MemPtrFree(tableP);
			tableP = newTableP;
			}

		// Zero out (only) the newly added slots in the table
		for (fontIndex = numAppFonts; fontIndex <= appFontIndex; fontIndex++) 
			{
			tableP[fontIndex] = NULL;
			}
		
		// Save the new table size
		if (!isSubFont)
			UINumAppFonts = appFontIndex+1;
		}

	tableP[appFontIndex] = fontP;
		
	return 0;
}
Ejemplo n.º 23
0
static void
ExamDetailsFormInit(FormType *frm)
{
  UInt16 selectedCourse=0;
  ListType *course;
  ControlType *course_tr, *date_tr, *time_tr;

  course = GetObjectPtr(LIST_exd_course);
  course_tr = GetObjectPtr(LIST_exd_course_trigger);
  date_tr = GetObjectPtr(SELECTOR_exd_date);
  time_tr = GetObjectPtr(SELECTOR_exd_time);

  gExamDetailsNumCourses = CountCourses();

  gExamDetailsItemList = (Char **) MemPtrNew(gExamDetailsNumCourses * sizeof(Char *));
  gExamDetailsItemIDs = (UInt16 *) MemPtrNew(gExamDetailsNumCourses * sizeof(UInt16));
  gExamDetailsItemInd = (UInt16 *) MemPtrNew(gExamDetailsNumCourses * sizeof(UInt16));

  if (gExamsLastSelRowUID == 0) {
    // ADD
    DateTimeType dt;

    selectedCourse = CourseListGen(gExamDetailsItemList, gExamDetailsItemIDs, gExamDetailsItemInd, gExamDetailsNumCourses, 0, CLIST_SEARCH_INDEX);

    TimSecondsToDateTime(TimGetSeconds(), &dt);
    gExamDetailsDate.year=dt.year-MAC_SHIT_YEAR_CONSTANT;

    gExamDetailsDate.month=dt.month;
    gExamDetailsDate.day=dt.day;

    gExamDetailsBegin.hours=14;
    gExamDetailsBegin.minutes=0;

    gExamDetailsEnd.hours=15;
    gExamDetailsEnd.minutes=30;

  } else {
    MemHandle mex, mRoom, old;
    ExamDBRecord *ex;
    UInt16 index=0;
    Char *buffer;
    FieldType *fldRoom;

    fldRoom=GetObjectPtr(FIELD_exd_room);

    DmFindRecordByID(DatabaseGetRefN(DB_MAIN), gExamsLastSelRowUID, &index);

    mex = DmQueryRecord(DatabaseGetRefN(DB_MAIN), index);
    ex = (ExamDBRecord *)MemHandleLock(mex);

    selectedCourse = CourseListGen(gExamDetailsItemList, gExamDetailsItemIDs, gExamDetailsItemInd, gExamDetailsNumCourses, ex->course, CLIST_SEARCH_ID);

    gExamDetailsDate.year=ex->date.year;
    gExamDetailsDate.month=ex->date.month;
    gExamDetailsDate.day=ex->date.day;

    gExamDetailsBegin.hours=ex->begin.hours;
    gExamDetailsBegin.minutes=ex->begin.minutes;

    gExamDetailsEnd.hours=ex->end.hours;
    gExamDetailsEnd.minutes=ex->end.minutes;

    // Copy contents to the memory handle
    mRoom=MemHandleNew(StrLen(ex->room)+1);
    buffer=(Char *)MemHandleLock(mRoom);
    MemSet(buffer, MemPtrSize(buffer), 0);
    StrNCopy(buffer, ex->room, StrLen(ex->room));
    MemHandleUnlock(mRoom);

    // Load fields
    old = FldGetTextHandle(fldRoom);
    FldSetTextHandle(fldRoom, mRoom);
    if (old != NULL)    MemHandleFree(old); 

    MemHandleUnlock(mex);
  }


  LstSetListChoices(course, gExamDetailsItemList, gExamDetailsNumCourses);
  if (gExamDetailsNumCourses < 5)  LstSetHeight(course, gExamDetailsNumCourses);
  else                 LstSetHeight(course, 5);
  LstSetSelection(course, selectedCourse);
  CtlSetLabel(course_tr, LstGetSelectionText(course, selectedCourse));

  ExamDetailsSetTriggers(date_tr, time_tr);
  EditTimeSetSelectorText(time_tr, &gExamDetailsBegin, &gExamDetailsEnd, gExamDetailsTimeTrigger);

}
Ejemplo n.º 24
0
size_t
__sys_pointer_size(void* ptr)
{
    return (size_t) MemPtrSize(ptr);
}
Ejemplo n.º 25
0
/***********************************************************************
 *
 * FUNCTION:    RepeatDrawDescription
 *
 * DESCRIPTION: This routine draws the text description of the current
 *              repeat type and frequency.
 *
 *              The description is created from a template string.  The
 *              repeat type and frequency determines which template is
 *              used.  The template may contain one or more of the
 *              following token:
 *                   ^d - day name (ex: Monday)
 *							^f - frequency
 *                   ^x - day of the month ordinal number (ex: 1st - 31th)
 *                   ^m - month name (ex: July)
 *                   ^w - week ordinal number (1st, 2nd, 3rd, 4th, or last)
 *
 * PARAMETERS:  frm - pointer to the repeat dialog box
 *
 * RETURNED:    nothing
 *
 ***********************************************************************/
void RepeatDrawDescription(FormType* frm) {
  UInt8 repeatOn;
  UInt16 i;
  UInt16 len;
  UInt16 freq;
  UInt16 dayOfWeek;
  UInt16 templateId = repeatNoneString;
  UInt16 repeatOnCount = 0;
  Char* descP = NULL;
  Char* resP = NULL;
  Char* saveResP = NULL;
  MemHandle descH = NULL;
  MemHandle resH = NULL;
  RepeatInfoType repeat;
  FieldType* fld = GetObjectPointer(frm, RepeatDescField);

  FldEraseField (fld);

  /* Get the current setting of the repeat ui gadgets. */
  RepeatGetUIValues(frm, &repeat);
  
  /*
  ** Determine which template string to use.  The template string is
  ** used to format the description string. Note that we could add
  ** a soft constant which tells us whether we need to use different
  ** strings for freq == 1 case (depends on language), thus saving space.
  */
  freq = repeat.repeatFrequency;
  switch (repeat.repeatType) {
  case repeatNone:
    templateId = repeatNoneString;
    break;
    
  case repeatHourly:
    if (freq == 1)
      /* "Every hour" */
      templateId = everyHourRepeatString;
    else
      /* "Every [other | 2nd | 3rd...] hour" */
      templateId = hourlyRepeatString;
    break;
    
  case repeatDaily:
    if (freq == 1)
      /* "Every day" */
      templateId = everyDayRepeatString;
    else
      /* "Every [other | 2nd | 3rd...] day" */
      templateId = dailyRepeatString;
    break;
    
  case repeatWeekly:
    if (freq == 1)
      /* "Every week on [days of week]" */
      templateId = everyWeekRepeat1DayString;
    else
      templateId = weeklyRepeat1DayString;
    
    /*
    ** Generate offset to appropriate string id,
    ** based on # of days that we need to append.
    */
    for (i = 0; i < daysInWeek; i++) {
      if (repeat.repeatOn & (1 << i) ) 
	repeatOnCount++;
    }
    templateId += repeatOnCount - 1;
    break;

  case repeatMonthlyByDate:
    if (freq == 1)
      /* "The ^w ^d of every month" */
      templateId = everyMonthByDateRepeatString;
    else
      templateId = monthlyByDateRepeatString;
    break;
    
  case repeatMonthlyByDay:
    if (freq == 1)
      templateId = everyMonthByDayRepeatString;
    else
      templateId = monthlyByDayRepeatString;
    break;
    
  case repeatYearly:
    if (freq == 1)
      templateId = everyYearRepeatString;
    else
      templateId = yearlyRepeatString;
    break;
    
  default:
    ErrNonFatalDisplay("Unknown repeat type");
    break;
  }

  /*
  ** Allocate a block to hold the description and copy the template
  ** string into it.
  */
  resH = DmGetResource(strRsc, templateId);
  resP = MemHandleLock(resH);
  descH = MemHandleNew(MemPtrSize(resP));
  ASSERT(descH);
  descP = MemHandleLock(descH);
  StrCopy(descP, resP);
  MemHandleUnlock(resH);
  
  /* Substitute the month name string for the month name token. */
  resH = DmGetResource(strRsc, repeatMonthNamesString);
  resP = MemHandleLock(resH);
  for (i = 1; i < d.frm_date.month; i++)
    resP = StrChr(resP, spaceChr) + 1;
  len = StrChr(resP, spaceChr) - resP;
  descP = SubstituteStr(descP, monthNameToken, resP, len);
  MemHandleUnlock(resH);

  /* Substitute the day name string for the day name token. */
  if ((repeatOnCount == 1) || (repeat.repeatType == repeatMonthlyByDay))
    templateId = repeatFullDOWNamesString;
  else
    templateId = repeatShortDOWNamesString;
  
  resH = DmGetResource(strRsc, templateId);
  resP = MemHandleLock(resH);
  if (repeat.repeatType == repeatWeekly) {
    dayOfWeek = repeat.repeatStartOfWeek;
    repeatOn = repeat.repeatOn;
    saveResP = resP;
    while (StrStr (descP, dayNameToken)) {
      for (i = 0; i < daysInWeek; i++) {
	if (repeatOn & (1 << dayOfWeek)) {
	  repeatOn &= ~(1 << dayOfWeek);
	  break;
	}
	dayOfWeek = (dayOfWeek + 1 + daysInWeek) % daysInWeek;
      }
      resP = saveResP;
      for (i = 0; i < dayOfWeek; i++)
	resP = StrChr(resP, spaceChr) + 1;
      
      len = StrChr(resP, spaceChr) - resP;
      descP = SubstituteStr(descP, dayNameToken, resP, len);
    }
  } else {
    dayOfWeek = DayOfWeek (d.frm_date.month, d.frm_date.day,
			   d.frm_date.year/* + firstYear*/);
    for (i = 0; i < dayOfWeek; i++)
      resP = StrChr(resP, spaceChr) + 1;
    len = StrChr(resP, spaceChr) - resP;
    descP = SubstituteStr(descP, dayNameToken, resP, len);
  }
  MemHandleUnlock (resH);

  /*
  ** Substitute the repeat frequency string for the frequency token. Note that
  ** we do something special for 2nd (other), since the gender of 'other' changes
  ** for some languages, depending on whether the next word is day, month, week,
  ** or year.
  */
  if (freq == 2) {
    Char otherFreqName[16];
    const UInt16 index = repeat.repeatType - repeatNone;
    SysStringByIndex(freqOrdinal2ndStrlID, index, otherFreqName, sizeof(otherFreqName));
    descP = SubstituteStr(descP, frequenceToken, otherFreqName, StrLen(otherFreqName));
  } else {
    resH = DmGetResource(strRsc, freqOrdinalsString);
    resP = MemHandleLock(resH);
    for (i = 1; i < freq; i++)
      resP = StrChr(resP, spaceChr) + 1;
    len = StrChr(resP, spaceChr) - resP;
    descP = SubstituteStr(descP, frequenceToken, resP, len);
    MemHandleUnlock(resH);
  }

  /*
  ** Substitute the repeat week string (1st, 2nd, 3rd, 4th, or last)
  ** for the week ordinal token.
  */
  if (repeat.repeatType == repeatMonthlyByDay) {
    resH = DmGetResource(strRsc, weekOrdinalsString);
    resP = MemHandleLock(resH);
    for (i = 0; i < repeat.repeatOn / daysInWeek; i++)
      resP = StrChr (resP, spaceChr) + 1;
    len = StrChr(resP, spaceChr) - resP;
    descP = SubstituteStr(descP, weekOrdinalToken, resP, len);
    MemHandleUnlock(resH);
  } else {
    /* make sure the week ordinal token really doesn't appear */
    ErrNonFatalDisplayIf(StrStr(descP, weekOrdinalToken) != NULL, "week ordinal not substituted");
  }

  /*
  ** Substitute the repeat date string (1st, 2nd, ..., 31th) for the
  ** day ordinal token.
  */
  resH = DmGetResource(strRsc, dayOrdinalsString);
  resP = MemHandleLock(resH);
  for (i = 1; i < d.frm_date.day; i++)
    resP = StrChr(resP, spaceChr) + 1;
  len = StrChr(resP, spaceChr) - resP;
  descP = SubstituteStr(descP, dayOrdinalToken, resP, len);
  MemHandleUnlock(resH);

  /* Draw the description. */
  MemHandleUnlock(descH);
  FldFreeMemory(fld);
  FldSetTextHandle(fld, descH);
  FldDrawField(fld);
}
Ejemplo n.º 26
0
/***************************************************************************
 * Function: cryptSwitch
 * Description: handles changing the system password based upon the 
 * password change screen. Basically checks that current password is correct,
 * checks that the new password was entered correctly, then re-encrypts the
 * databases based upon the new password.
 * ************************************************************************/ 
static void 
cryptSwitch (int v) 
{
	
		// total number of records to re-write
	UInt16 totalAItems = DmNumRecordsInCategory (AccountDB, dmAllCategories);
	UInt16 totalSItems = DmNumRecordsInCategory (SystemDB, dmAllCategories);
	MemPtr pac = NULL, scratch = NULL, scratch2 = NULL;
	UInt16 i = 0, senc = 0, aenc = 0;
	MemHandle rH;
	char s[5], a[5];
	StripPrefType prefs;	
	UInt16 prefsSize, prefsVersion;

	FormType *preF = FrmGetActiveForm ();
	FormType *f = FrmInitForm (pleaseWait);
	FrmDrawForm (f);
	
		// re-encrypt the password 
	if ((rH = DmGetRecord (PasswordDB, 0)))	
	{
		if ((scratch = MemPtrNew (getSCSize(sizeof(md_hash)))))			
		{
			PackPassword (scratch, &NewSysPass);			
			writeRecord (scratch, rH);
			MemPtrFree (scratch);
		}
		DmReleaseRecord (PasswordDB, 0, true);
	}
	
		// loop through the systems and re-encrypt
	for (i = 0; i < totalSItems; i++)
	{
		System_old sys;
		if ((rH = DmGetRecord (SystemDB, i)))	
		{
			pac = MemHandleLock (rH);
			if ((scratch = MemPtrNew (MemPtrSize (pac))))	
			{	
					// decrypt the system with old password
				switch (v)	
				{
					case 0:
						UnpackSystem_old (&sys, pac, scratch, SysPass,
										MemHandleSize (rH), true, 1);
										
						scratch2 = MemPtrNew (getSystemSize((System *)&sys, true));
						break;
					case 1:
						UnpackSystem_old (&sys, pac, scratch, SysPass,
										MemHandleSize (rH), true, 2);
						scratch2 = MemPtrNew (getSystemSize ((System *)&sys,true) );
						break;
					case 2:
						UnpackSystem_old (&sys, pac, scratch, SysPass,
										MemHandleSize (rH), true, 0);
						scratch2 = MemPtrNew (getSystemSize ((System *)&sys, true ));
						break;
				}
				if (scratch2)				
				{			
					PackSystem(scratch2, *((System *) &sys), &NewSysPass, true);
					MemHandleUnlock (rH);
					writeRecord (scratch2, rH);
					senc++;
					MemPtrFree (scratch2);
				}
				MemPtrFree (scratch);
			}
			DmReleaseRecord (SystemDB, i, true);
		}
	}
	
		// loop through the accounts and re-encrypt
	for (i = 0; i < totalAItems; i++)	
	{
		Account_old ac;
		Account ac_new;
		if ((rH = DmGetRecord (AccountDB, i)))
			
		{
			pac = MemHandleLock (rH);
			if ((scratch = MemPtrNew (MemPtrSize (pac))))
				
			{
				
					// decrypt the system with old password
				switch (v)	
				{
					case 0:
						UnpackAccount_old(&ac, pac, scratch, SysPass,
										 MemHandleSize (rH), true, true, 1);
						ChangeAccountFormat(i, &ac, &ac_new);
						scratch2 = MemPtrNew (getAccountSize(&ac_new, true));
						break; 
					case 1:
						UnpackAccount_old (&ac, pac, scratch, SysPass,
										 MemHandleSize (rH), true, true, 2);
						ChangeAccountFormat(i, &ac, &ac_new);
						scratch2 = MemPtrNew (getAccountSize(&ac_new, true));
						break; 
					case 2:
						UnpackAccount_old(&ac, pac, scratch, SysPass,
										 MemHandleSize (rH), true, true, 0);
						ChangeAccountFormat(i, &ac, &ac_new);
						scratch2 = MemPtrNew (getAccountSize(&ac_new,true));
						break; 
				}

				if (scratch2)
				{
					PackAccount(scratch2, ac_new, &NewSysPass, true);
					MemHandleUnlock (rH);
					writeRecord (scratch2, rH);
					aenc++;
					MemPtrFree (scratch2);
				}
				MemPtrFree (scratch);
			}
			DmReleaseRecord (AccountDB, i, true);
		}
	}
	FrmEraseForm (f);
	FrmDeleteForm (f);
	FrmSetActiveForm (preF);
		// close databases.
	DmCloseDatabase (SystemDB);
	DmCloseDatabase (AccountDB);
	DmCloseDatabase (PasswordDB);

	{
		UInt16 cardNo;
		UInt32 type;
		LocalID dbID;
		DmSearchStateType search;

		type = systemDBType;
		DmGetNextDatabaseByTypeCreator(true, &search, systemDBTypeOld, 
			StripCreator, true, &cardNo, &dbID);
		DmSetDatabaseInfo(cardNo, dbID, NULL, NULL, NULL, NULL, NULL,
			NULL, NULL, NULL, NULL, &type, NULL);
	
		type = accountDBType;
		DmGetNextDatabaseByTypeCreator(true, &search, accountDBTypeOld, 
			StripCreator, true, &cardNo, &dbID);
		DmSetDatabaseInfo(cardNo, dbID, NULL, NULL, NULL, NULL, NULL,
			NULL, NULL, NULL, NULL, &type, NULL);

		type = passwordDBType;
		DmGetNextDatabaseByTypeCreator(true, &search, passwordDBTypeOld, 
			StripCreator, true, &cardNo, &dbID);
		DmSetDatabaseInfo(cardNo, dbID, NULL, NULL, NULL, NULL, NULL,
			NULL, NULL, NULL, NULL,  &type, NULL);

	}

	prefsSize = sizeof (StripPrefType);
	prefsVersion = PrefGetAppPreferences (StripCreator, StripPrefID, &prefs, &prefsSize, true);
    if  (prefsVersion != StripVersionNumber) {
        prefs.smart_beaming = false;
        PrefSetAppPreferences (StripCreator, StripPrefID, StripVersionNumber,
            &prefs, sizeof (StripPrefType), true);
        prefsVersion = PrefGetAppPreferences (StripCreator, StripPrefID,
            &prefs, &prefsSize, true);
	} 

	StrIToA (s, senc);
	StrIToA (a, aenc);
	FrmCustomAlert (infoDialog, s, a, NULL);

	StopApplication ();
	SysReset ();
}
Ejemplo n.º 27
0
/*****************************************************************************
* Function: GadgetDrawHintCurrent
*
* Description: Draw hint for current gTimeIndex if needed (may be forced NOT
*              to draw with GadgetSetNeedsRedraw(false));
*****************************************************************************/
void
GadgetDrawHintCurrent(void)
{
  Char *tmp, *bot, begin[timeStringLength], end[timeStringLength], *day;
  MemHandle mc, mt, mh, type;
  CourseDBRecord c;
  TimeDBRecord *tc;
  RectangleType rect, bounds;
  UInt16 gadgetIndex = FrmGetObjectIndex(gForm, gGadgetID);
  RGBColorType color, prevColor;
  UInt16 attr;

  // Need to check that due to damn f*** DmRecordInfo which will show a
  // fatal alert when called on non-existing record (this happens for example
  // right after creating the new database...
  if ((gTimeIndex >= DmNumRecords(DatabaseGetRef())) ||
      (gCourseIndex >= DmNumRecords(DatabaseGetRef())) )  return;

  if (gHintDrawn) {
    // Delete border around previous entry
    if ( (gTimeDrawnIndex < DmNumRecords(DatabaseGetRef())) &&
       (DmRecordInfo(DatabaseGetRef(), gTimeDrawnIndex, &attr, NULL, NULL) == errNone) ) {
      attr &= dmRecAttrCategoryMask;
      if (attr == DatabaseGetCat()) {
    
        mt = DmQueryRecord(DatabaseGetRef(), gTimeDrawnIndex);
        if (mt) {
          // mt may be null, for example if next is drawn after delete!
          tc = (TimeDBRecord *)MemHandleLock(mt);
          if ((tc->type == TYPE_TIME) && GadgetEventIsVisible(tc) ) {

	    TNlist *tmpl = gGadgetTimeList;
	    GadgetTimeListType *gtl = NULL;
	    while (tmpl != NULL) {
	      gtl = tmpl->data;
	      if (gtl->index == gTimeDrawnIndex) {
		break;
	      }
	      tmpl = tmpl->next;
	    }
 
            color.r=tc->color[0];
            color.g=tc->color[1];
            color.b=tc->color[2];
            if (gPrefs.showTimeline)  GadgetDrawTimeline(gtErase);

	    if (gtl != NULL) {
	      GadgetDrawTime(tc->begin, tc->end, tc->day, &color, tc->course, gtl->num, gtl->pos);
	    }
            if (gPrefs.showTimeline)  GadgetDrawTimeline(gtDraw);
          }
          MemHandleUnlock(mt);
        }
      }
    }
  }

  gTimeDrawnIndex=gTimeIndex;
  gHintDrawn=true;

  if (DmRecordInfo(DatabaseGetRef(), gCourseIndex, &attr, NULL, NULL) == errNone) {
    attr &= dmRecAttrCategoryMask;
    if (attr == DatabaseGetCat()) {
      // Record is in currently displayed category

      mc = DmQueryRecord(DatabaseGetRef(), gCourseIndex);
      if (! mc)  return;

      mt = DmQueryRecord(DatabaseGetRef(), gTimeIndex);
      if (! mt) return;

      UnpackCourse(&c, MemHandleLock(mc));
      tc = (TimeDBRecord *)MemHandleLock(mt);

      if ( GadgetEventIsVisible(tc) ) {

	TNlist *tmpl = gGadgetTimeList;
	GadgetTimeListType *gtl = NULL;
	while (tmpl != NULL) {
	  gtl = tmpl->data;
	  if (gtl->index == gTimeDrawnIndex) {
	    break;
	  }
	  tmpl = tmpl->next;
	}

        mh = DmGetResource(strRsc, GADGET_STRINGS_WDAYSTART+tc->day);
        day = (Char *)MemHandleLock(mh);

        // Lecture Name (Teacher) [Typ]
        tmp=(Char *)MemPtrNew(StrLen(c.name)+StrLen(c.teacherName)+4+3+CTYPE_SHORT_MAXLENGTH);
        MemSet(tmp, MemPtrSize(tmp), 0);
        type = MemHandleNew(1);
        CourseTypeGetShort(&type, c.ctype);
        StrPrintF(tmp, "%s (%s) [%s]", c.name, c.teacherName, (Char *)MemHandleLock(type));
        MemHandleUnlock(type);
        MemHandleFree(type);


        // Fr 08:00 - 09:30 (Room)          <-- Example
        // 3    5   3   5   3+StrLen(room)  <-- Num Chars for MemPtrNew
        bot=(Char *)MemPtrNew(20+sizeof(tc->room)+MemPtrSize(day));
        MemSet(bot, MemPtrSize(bot), 0);

        TimeToAscii(tc->begin.hours, tc->begin.minutes, GadgetGetTimeFormat(), begin);
        TimeToAscii(tc->end.hours, tc->end.minutes, GadgetGetTimeFormat(), end);

        mh = DmGetResource(strRsc, GADGET_STRINGS_WDAYSTART+tc->day);

        StrPrintF(bot, "%s %s - %s (%s)", day, begin, end, tc->room);

        FrmGetObjectBounds(gForm, gadgetIndex, &bounds);

	if (gtl != NULL) {
	  GadgetTimeSetRect(&rect, tc->begin, tc->end, tc->day, gtl->num, gtl->pos);
	  RctSetRectangle(&rect,
			  //             + inset (two boxes, one black, one white)
			  rect.topLeft.x + 2,
			  rect.topLeft.y + 2,
			  // width      - 2 * inset
			  rect.extent.x - 4,
			  // height     - 2 * inset
			  rect.extent.y - 4
			  );

	  /* Invert color, looks not so nice aka bad
	     color.r=255- tc->color[0];
	     color.g=255- tc->color[1];
	     color.b=255- tc->color[2];
	  */
	  color.r=255;
	  color.g=255;
	  color.b=255;
	  TNSetForeColorRGB(&color, &prevColor);
	  WinDrawRectangleFrame(simpleFrame, &rect);
	  color.r=0;
	  color.g=0;
	  color.b=0;
	  RctSetRectangle(&rect, rect.topLeft.x-1, rect.topLeft.y-1, rect.extent.x+2, rect.extent.y+2);
	  TNSetForeColorRGB(&color, NULL);
	  WinDrawRectangleFrame(simpleFrame, &rect);
	  TNSetForeColorRGB(&prevColor, NULL);
	}

       // WinInvertRectangleFrame(simpleFrame, &rect);
        GadgetDrawHint(tmp, bot, tc->note);

        MemPtrFree((MemPtr) tmp);
        MemPtrFree((MemPtr) bot);
        MemHandleUnlock(mh);
      } else {
        MemHandleUnlock(mc);
        MemHandleUnlock(mt);
        GadgetDrawHintNext();
        return;
      }
      MemHandleUnlock(mc);
      MemHandleUnlock(mt);
    } // End attr == current category
  }
}