home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / emerald / emrldsys.lha / Kernel / Em / ecutils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-17  |  2.5 KB  |  97 lines

  1. /*
  2.  *       Definition of the run-time routines for emerald types.
  3.  *       Origin:  Norm Hutchinson, 1986-05-15.
  4.  *
  5.  * C O P Y R I G H T   N O T I C E :
  6.  * Copyright 1986 Eric Jul and Norm Hutchinson.  May not be used for any
  7.  * purpose without written permission from the authors.
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include <sys/time.h>
  12. #include <sys/types.h>
  13. #include "Kernel/h/system.h"
  14. #include "Kernel/h/emTypes.h"
  15. #include "Kernel/h/emeraldTypes.h"
  16. #include "Kernel/h/assert.h"
  17. #include "Kernel/h/timeops.h"
  18. #include "Kernel/h/consts.h"
  19.  
  20. extern CodePtr              stringCodePtr;
  21. extern LODataPtr            MagicLocalCreate();
  22.  
  23. StringPtr BuildString(format, arg)
  24. char *format;
  25. int arg;
  26. {
  27.   char buffer[200];
  28.   register int length;
  29.   register StringPtr result;
  30.  
  31.   if ( IsNIL(arg) ) {
  32.     (void) strcpy(buffer, "NIL");
  33.   } else (void) sprintf(buffer, format, arg);
  34.   length = strlen(buffer);
  35.   result = (StringPtr) MagicLocalCreate(stringCodePtr, length+String_data);
  36.   result->sizeInBytes = length;
  37.   bcopy(buffer, (char *)&result->data[0], length);
  38.   return(result);
  39. }
  40.  
  41. StringPtr BuildRealString(arg)
  42. int arg;
  43. {
  44.   char buffer[200];
  45.   register int length;
  46.   register StringPtr result;
  47.  
  48.   if ( IsNIL(arg) ) {
  49.     (void) strcpy(buffer, "NIL REAL");
  50.   } else (void) sprintf(buffer, "%g", *(float *)&arg);
  51.   length = strlen(buffer);
  52.   result = (StringPtr) MagicLocalCreate(stringCodePtr, length+String_data);
  53.   result->sizeInBytes = length;
  54.   bcopy(buffer, (char *)&result->data[0], length);
  55.   return(result);
  56. }
  57.  
  58. StringPtr BuildTimeString(arg)
  59. EmTimePtr arg;
  60. {
  61.   char buffer[200];
  62.   register int length;
  63.   register StringPtr result;
  64.  
  65.   if ( IsNIL(arg) ) {
  66.     (void) strcpy(buffer, "INVALID TIME");
  67.   } else if (arg->t.tv_sec < 0 && arg->t.tv_usec > 0) { 
  68.     (void) sprintf(buffer, "%d.%06d", arg->t.tv_sec + 1, 1000000 - arg->t.tv_usec);
  69.   } else {
  70.     (void) sprintf(buffer, "%d.%06d", arg->t.tv_sec, arg->t.tv_usec);
  71.   }
  72.   length = strlen(buffer);
  73.   result = (StringPtr) MagicLocalCreate(stringCodePtr, length+String_data);
  74.   result->sizeInBytes = length;
  75.   bcopy(buffer, (char *)&result->data[0], length);
  76.   return(result);
  77. }
  78.  
  79. StringPtr BuildTimeDate(arg)
  80. EmTimePtr arg;
  81. {
  82.   char *buffer;
  83.   register int length;
  84.   register StringPtr result;
  85.  
  86.   if ( NonNIL(arg) ) {
  87.     buffer = ctime((time_t *) &arg->t.tv_sec);
  88.   } else buffer = "NIL";
  89.  
  90.   length = strlen(buffer) - 1;
  91.   result = (StringPtr) MagicLocalCreate(stringCodePtr, length+String_data);
  92.   result->sizeInBytes = length;
  93.   bcopy(buffer, (char *)&result->data[0], length);
  94.   return(result);
  95. }
  96.  
  97.