While I was waiting for a response I worked on a pair of functions that extracted and concated variables from the path to a text buffer (_path in this case), somehow the problem went away after I did that and used them so I'm guessing I didn't properly copy the path the first time, thanks for the input anyways, probably come back with some opengl problems (assuming I don't get a response on official forum).
Just in case someone was interested in those functions I spoke of, here they are:
Code:
TCS* concate_environment_value( TCS *text, tch const *name )
{
INDEX leng, used;
char *value = getenv( name );
if ( !value )
{
int err;
errno = EINVAL;
EXEC
(
err
, fprintf
(
stderr
, "Environment value '%s' does not exist!"
, name
)
, true
);
return NULL;
}
leng = strlen(value);
used = text ? tcsnlen( text->addr, text->have ) : 0;
text = alt_list( text, leng + used + 1, 1, sizeof(tch) );
if ( !text )
return NULL;
tcsncat( text->addr, value, text->have );
return text;
}
TCS* extract_environment_value( TCS *TEXT, tch *text )
{
char *name = text;
++text;
if ( *text != '(' )
{
if ( *text == '$' )
{
INDEX leng = TEXT ? tcslen( TEXT->addr ) : 0;
TCS *_temp = alt_tcs( TEXT, leng + 1, 1, 0 );
if ( !_temp )
return NULL;
text = _temp->addr;
*(text + leng) = '$';
return _temp;
}
*name = *text;
}
else
{
for ( name = text + 1; *text && *text != ')'; ++text );
if ( !text )
{
int err;
errno = EINVAL;
EXEC( err, fputs( "Expected ')'\n", stderr ), true );
return NULL;
}
}
*text = 0;
return concate_environment_value( TEXT, name );
}
TCS* get_absolute_path( TCS *TEMP, TCS *PATH, tch const *path )
{
void *addr;
INDEX leng = path ? tcslen(path) : 0, need = 0;
TCS *_path = alt_list( PATH, leng + 1, 1, sizeof(tch) );
TCS *_temp = alt_list( TEMP, leng + 1, 1, sizeof(tch) );
tch sep = get_dir_sep(), *text, *from;
tch *PFX = NULL;
if ( !_temp || !_path )
{
fail:
if ( !TEMP && _temp )
del_tcs( _temp );
if ( !PATH && _path )
return del_tcs( _path );
return NULL;
}
_temp->used = leng;
_path->used = 0;
memset( _temp->addr, 0, _temp->size );
memset( _path->addr, 0, _path->size );
tcsncpy( _temp->addr, path, _temp->have );
text = _temp->addr;
if ( *text == '~' )
{
addr = concate_environment_value
(
_path
#ifdef _WIN32
, "HOMEPATH"
#else
, "HOME"
#endif
);
if ( !addr )
goto fail;
_path = addr;
}
else if ( *text == '$' )
{
addr = extract_environment_value( _path, text );
if ( !addr )
goto fail;
_path = addr;
}
leng = tcslen( _path->addr );
while ( *text )
{
if ( *text == '$' )
{
addr = extract_environment_value( _path, text );
if ( !addr )
goto fail;
_path = addr;
leng = tcslen( _path->addr );
}
else
{
tch *chr = _path->addr, *end = chr + leng;
need = leng + 2;
if ( need >= _path->have )
{
addr = alt_tcs( _path, need + BUFSIZ, 1, 0 );
if ( !addr )
goto fail;
_path = addr;
chr = _path->addr;
end = chr + leng;
}
*end = (*text == '/' || *text == '\\') ? sep : *text;
++end;
++leng;
*end = 0;
}
++text;
}
if ( !TEMP )
del_tcs( _temp );
leng = tcslen( path );
addr = dec_tcs( _path, leng + 1 );
_path->used = leng;
return _path;
}
And because they're related:
Code:
typedef struct _LIST
{
BYTES const perN;
BYTES size;
INDEX have;
INDEX used;
void *addr;
} LIST, BUFF, STR, WCS, TCS;
typedef struct _TCF
{
uint line;
INDEX pos;
TCS temp, path;
BUFF buff;
#ifdef _WIN32
HANDLE handle;
#else
int fd;
#endif
} TCF;
struct _LIST* alt_list( struct _LIST *list, INDEX want, int only, BYTES fixed )
{
BYTES size, prev;
char *temp;
if ( !list )
{
size = fixed;
list = calloc( sizeof(LIST), 1 );
if ( !list )
return NULL;
memset( list, 0, sizeof(LIST) );
list->size = size * want;
list->addr = malloc( list->size );
if ( !(list->addr) )
{
free(list);
return NULL;
}
list->have = want;
*((BYTES*)list) = size;
return list;
}
fixed = fixed ? fixed : list->perN;
if ( !(list->addr) )
memset( list, 0, sizeof(LIST) );
if ( !(list->perN) )
*((BYTES*)list) = fixed;
prev = list->size;
size = list->perN * want;
if ( size == prev )
return list;
if ( only > 0 && size < prev )
return list;
if ( only < 0 && size > prev )
return NULL;
if ( !size )
{
if ( list->addr );
free( list->addr );
memset( list, 0, sizeof(LIST) );
if ( !fixed )
free( list );
return NULL;
}
temp = prev ? realloc( list->addr, size ) : malloc( size );
if ( !temp )
return NULL;
if ( size > prev )
memset( temp + prev, 0, size - prev );
list->size = size;
list->addr = temp;
list->have = size / list->perN;
return list;
}
Now I got some Japanese to revise then I'll have to track the cause of an infinite loop, if anyone cares to do that for me while I catch up on my studies (I'm not holding my breath on that one) then the faulty function is here:
Code:
tch* tcf_next_line( TCF *file )
{
TCS *_temp;
BUFF *_buff = alt_list( &(file->buff), BUFSIZ, 1, 1 );
INDEX max;
ssize_t done = 0;
bool eof = false;
tch *line;
if ( !_buff )
return NULL;
max = _buff->size / sizeof(tch);
_temp = alt_list( &(file->temp), max + 1, 1, sizeof(tch) );
if ( !_temp )
return NULL;
line = _temp->addr;
while ( !eof )
{
tch *chr, *end;
char *_line, *_chr, *_end;
BYTES kept, lost;
int err = 0;
if ( !_temp )
return NULL;
/* This can change per loop so cannot store outside */
line = _temp->addr;
_line = _temp->addr;
_end = _line + _temp->size;
end = (tch*)end;
chr = line;
/* First we find where the start of our line string is */
if ( !done )
{
for ( chr = line; *chr; ++chr );
_chr = (char*)chr;
for ( ; chr < end; ++chr );
if ( chr < end )
_chr = (char*)chr;
else
chr = (tch*)_chr;
/* Now we move it forward */
if ( chr != line )
{
kept = (BYTES)(_end - _chr);
lost = (BYTES)(_chr - _line);
tcsnmov( line, chr, _temp->have );
memset( _line + kept, 0, lost );
}
}
/* Now we find the new line character */
for ( chr = line; *chr && *chr != '\n' && *chr != '\r'; ++chr );
if ( *chr )
{
for ( ; *chr == '\n' || *chr == '\r'; ++chr )
return line;
}
_chr = (char*)chr;
kept = (BYTES)(_chr - _line);
lost = (BYTES)(_end - _chr);
max = _temp->have + kept;
_temp = alt_list( &(file->temp), max + 1, 1, sizeof(tch) );
#ifdef _WIN32
done = ReadFile( file->handle, _buff->size, _buff->size );
#else
done = read( file->fd, _buff->addr, _buff->size );
err = errno;
#endif
/* TODO: Implement conversion from base encoding to tch encoding */
memcpy( chr, _buff->addr, done );
eof = ( done < 0 || (BYTES)done < _buff->size );
}
return *line ? line : NULL;
}