Functions for working with the idealized calendar of Planet Xhilr
Rev. | c9ca731a29c3838146d1e7e85626e1273ae7ca7f |
---|---|
크기 | 1,124 bytes |
Time | 2017-06-17 10:35:04 |
Author | Joel Matthew Rees |
Log Message | UD/MOD double integer division in M6800 assembler within figForth.
|
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
typedef struct string_header_s
{ short length;
char string[ 1 ];
} string_header_t;
char bigblock[ 100000 ];
char * here = bigblock;
string_header_t * string_allocate( long length )
{ char * place = here;;
if ( ( place = here + length + sizeof (string_header_t) ) >= bigblock + 100000 )
{ return NULL;
}
here = place;
( (string_header_t *) place )->length = length;
return (string_header_t *) place;
}
string_header_t * string_save( char string[] )
{ long length = strlen( string );
string_header_t * headerp = string_allocate( length );
memcpy( headerp->string, string, length );
headerp->string[ length ] = '\0';
return headerp;
}
void print_string( string_header_t * header )
{ int i;
for ( i = 0; i < header->length; ++i )
{ putchar( header->string[ i ] );
}
}
int main ( int argc, char * argv[] )
{ string_header_t * thing;
puts( "before thing" );
thing = string_save( "hello" );
puts( "after thing" );
/* ... */
print_string( thing );
putchar( '\n' );
return EXIT_SUCCESS;
}