Files
c-prime/source/tools.c
2025-11-17 10:28:09 +01:00

89 lines
1.2 KiB
C

#include "tools.h"
char * tools_findDatatype( struct array * variableDeclarationParts ) {
int partsCount = array_length( variableDeclarationParts );
char * datatype = malloc( 100 );
for (int i = 0; i < partsCount; ++i)
{
char * variablePart = text_removeWhiteSpaces( array_get( variableDeclarationParts, i ) );
if( strcmp( variablePart, "extern") == 0 ) {
continue;
}
if( strcmp( variablePart, "struct") == 0 ) {
continue;
}
datatype = variablePart;
break;
}
return datatype;
}
int tools_findArgumentCloseIndexReverse( char * body, int fromKey ) {
int depth = 0;
int hasStarted = -1;
for (int i = fromKey; i >= 0; --i)
{
// ')'
if ( (int)body[i] == 41 ) {
depth++;
hasStarted = 1;
}
if( hasStarted == 1 && depth == 0 ) {
return i + 1;
}
// '('
if ( (int)body[i] == 40 ) {
depth--;
}
}
return -1;
}
char * tools_removePointerSymbolFromDatatype( char * returnType, int * leftSideIsPointer ) {
struct array * returnTypeParts = text_split( text_copy( returnType ), " " );
*leftSideIsPointer = variable_isPointer( returnTypeParts );
//printf(" removePointerSymbolFromDatatype: %i \n\n\n", *leftSideIsPointer);
return array_get( returnTypeParts, 0 );
}