home *** CD-ROM | disk | FTP | other *** search
- /*
- * Definition of the run-time routines for emerald types.
- * Origin: Norm Hutchinson, 1986-05-15.
- *
- * C O P Y R I G H T N O T I C E :
- * Copyright 1986 Eric Jul and Norm Hutchinson. May not be used for any
- * purpose without written permission from the authors.
- */
-
- #include <stdio.h>
- #include <sys/time.h>
- #include <sys/types.h>
- #include "Kernel/h/system.h"
- #include "Kernel/h/emTypes.h"
- #include "Kernel/h/emeraldTypes.h"
- #include "Kernel/h/assert.h"
- #include "Kernel/h/timeops.h"
- #include "Kernel/h/consts.h"
-
- extern CodePtr stringCodePtr;
- extern LODataPtr MagicLocalCreate();
-
- StringPtr BuildString(format, arg)
- char *format;
- int arg;
- {
- char buffer[200];
- register int length;
- register StringPtr result;
-
- if ( IsNIL(arg) ) {
- (void) strcpy(buffer, "NIL");
- } else (void) sprintf(buffer, format, arg);
- length = strlen(buffer);
- result = (StringPtr) MagicLocalCreate(stringCodePtr, length+String_data);
- result->sizeInBytes = length;
- bcopy(buffer, (char *)&result->data[0], length);
- return(result);
- }
-
- StringPtr BuildRealString(arg)
- int arg;
- {
- char buffer[200];
- register int length;
- register StringPtr result;
-
- if ( IsNIL(arg) ) {
- (void) strcpy(buffer, "NIL REAL");
- } else (void) sprintf(buffer, "%g", *(float *)&arg);
- length = strlen(buffer);
- result = (StringPtr) MagicLocalCreate(stringCodePtr, length+String_data);
- result->sizeInBytes = length;
- bcopy(buffer, (char *)&result->data[0], length);
- return(result);
- }
-
- StringPtr BuildTimeString(arg)
- EmTimePtr arg;
- {
- char buffer[200];
- register int length;
- register StringPtr result;
-
- if ( IsNIL(arg) ) {
- (void) strcpy(buffer, "INVALID TIME");
- } else if (arg->t.tv_sec < 0 && arg->t.tv_usec > 0) {
- (void) sprintf(buffer, "%d.%06d", arg->t.tv_sec + 1, 1000000 - arg->t.tv_usec);
- } else {
- (void) sprintf(buffer, "%d.%06d", arg->t.tv_sec, arg->t.tv_usec);
- }
- length = strlen(buffer);
- result = (StringPtr) MagicLocalCreate(stringCodePtr, length+String_data);
- result->sizeInBytes = length;
- bcopy(buffer, (char *)&result->data[0], length);
- return(result);
- }
-
- StringPtr BuildTimeDate(arg)
- EmTimePtr arg;
- {
- char *buffer;
- register int length;
- register StringPtr result;
-
- if ( NonNIL(arg) ) {
- buffer = ctime((time_t *) &arg->t.tv_sec);
- } else buffer = "NIL";
-
- length = strlen(buffer) - 1;
- result = (StringPtr) MagicLocalCreate(stringCodePtr, length+String_data);
- result->sizeInBytes = length;
- bcopy(buffer, (char *)&result->data[0], length);
- return(result);
- }
-
-