Source/CommonStuff.c

//¥ ------------------------------------------------------------------------------------------  ¥
//¥
//¥ Copyright © 1996 Apple Computer, Inc., All Rights Reserved
//¥
//¥
//¥     You may incorporate this sample code into your applications without
//¥     restriction, though the sample code has been provided "AS IS" and the
//¥     responsibility for its operation is 100% yours.  However, what you are
//¥     not permitted to do is to redistribute the source as "DSC Sample Code"
//¥     after having made changes. If you're going to re-distribute the source,
//¥     we require that you make it clear in the source that the code was
//¥     descended from Apple Sample Code, but that you've made changes.
//¥
//¥ ------------------------------------------------------------------------------------------  ¥
 
#include <Memory.h>
#include <Quickdraw.h>
 
#include "CommonStuff.h"
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
 
void DebugPrint(char *message, long error)
{
    char string[256];
    size_t  len;
    
    error;
    
    len = strlen(message);
    strcpy(string, message);
    if (len < 252)
        strcat(string, ":%ld");
    else
    {
        string[256] = '\0';
        string[255] = 'd';
        string[254] = 'l';
        string[253] = '%';
        string[252] = ':';
    }
}
 
void dprintf(char *format, ...)
{
    int numChars = 0;
    va_list     args;
    char        s[256];
    
    va_start(args, format);
    numChars = vsprintf(s, format, args);
    s[255] = 0;
    debugstr(s);
    va_end(args);
 
}
 
int Game_Random(int x)
{
    int val;
    
    val = ((Random() & 0x7ffff) % (x));
    
    return val;
}
 
StringPtr
CopyPStr(
    ConstStr255Param    inSourceStr,
    StringPtr           outDestStr)
{
    SInt16  dataLen = inSourceStr[0] + 1;
    
    BlockMoveData(inSourceStr, outDestStr, dataLen);
    outDestStr[0] = dataLen - 1;
    return outDestStr;
}