home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Games / SprocketInvaders / Source / CommonStuff.c < prev    next >
Encoding:
Text File  |  2000-09-28  |  1.7 KB  |  79 lines  |  [TEXT/CWIE]

  1. //•    ------------------------------------------------------------------------------------------    •
  2. //•
  3. //•    Copyright © 1996 Apple Computer, Inc., All Rights Reserved
  4. //•
  5. //•
  6. //•        You may incorporate this sample code into your applications without
  7. //•        restriction, though the sample code has been provided "AS IS" and the
  8. //•        responsibility for its operation is 100% yours.  However, what you are
  9. //•        not permitted to do is to redistribute the source as "DSC Sample Code"
  10. //•        after having made changes. If you're going to re-distribute the source,
  11. //•        we require that you make it clear in the source that the code was
  12. //•        descended from Apple Sample Code, but that you've made changes.
  13. //•
  14. //•    ------------------------------------------------------------------------------------------    •
  15.  
  16. #include <Memory.h>
  17. #include <Quickdraw.h>
  18.  
  19. #include "CommonStuff.h"
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include <stdarg.h>
  23.  
  24. void DebugPrint(char *message, long error)
  25. {
  26.     char string[256];
  27.     size_t    len;
  28.     
  29.     error;
  30.     
  31.     len = strlen(message);
  32.     strcpy(string, message);
  33.     if (len < 252)
  34.         strcat(string, ":%ld");
  35.     else
  36.     {
  37.         string[256] = '\0';
  38.         string[255] = 'd';
  39.         string[254] = 'l';
  40.         string[253] = '%';
  41.         string[252] = ':';
  42.     }
  43. }
  44.  
  45. void dprintf(char *format, ...)
  46. {
  47.     int numChars = 0;
  48.     va_list        args;
  49.     char        s[256];
  50.     
  51.     va_start(args, format);
  52.     numChars = vsprintf(s, format, args);
  53.     s[255] = 0;
  54.     debugstr(s);
  55.     va_end(args);
  56.  
  57. }
  58.  
  59. int Game_Random(int x)
  60. {
  61.     int val;
  62.     
  63.     val = ((Random() & 0x7ffff) % (x));
  64.     
  65.     return val;
  66. }
  67.  
  68. StringPtr
  69. CopyPStr(
  70.     ConstStr255Param    inSourceStr,
  71.     StringPtr            outDestStr)
  72. {
  73.     SInt16    dataLen = inSourceStr[0] + 1;
  74.     
  75.     BlockMoveData(inSourceStr, outDestStr, dataLen);
  76.     outDestStr[0] = dataLen - 1;
  77.     return outDestStr;
  78. }
  79.