Add resizing to remove_label_tokens
This commit is contained in:
parent
508bf04793
commit
7bc5189aef
3 changed files with 18 additions and 6 deletions
|
@ -3,10 +3,11 @@
|
|||
|
||||
#include "../header/common.h"
|
||||
#include "../header/shash/shash.h"
|
||||
#include "dyn_buf.h"
|
||||
|
||||
void build_label_table(char label_tokens[][MAX_TOKEN_SIZE], shash_hashtable_t *label_table);
|
||||
|
||||
void remove_label_definition_tokens(char label_tokens[][MAX_TOKEN_SIZE], char no_label_definition_tokens[][MAX_TOKEN_SIZE]);
|
||||
void remove_label_definition_tokens(char label_tokens[][MAX_TOKEN_SIZE], dynamic_buffer_t *no_label_definition_tokens);
|
||||
|
||||
void replace_labels_with_adresses(char no_label_definition_tokens[][MAX_TOKEN_SIZE], char tokens[][MAX_TOKEN_SIZE], shash_hashtable_t label_table, shash_hashtable_t instruction_information_table);
|
||||
#endif
|
||||
|
|
17
src/labels.c
17
src/labels.c
|
@ -27,16 +27,27 @@ void build_label_table(char label_tokens[][MAX_TOKEN_SIZE], shash_hashtable_t *l
|
|||
}
|
||||
}
|
||||
|
||||
void remove_label_definition_tokens(char label_tokens[][MAX_TOKEN_SIZE], char no_label_definition_tokens[][MAX_TOKEN_SIZE])
|
||||
void remove_label_definition_tokens(char label_tokens[][MAX_TOKEN_SIZE], dynamic_buffer_t *no_label_definition_tokens)
|
||||
{
|
||||
unsigned int new_index = 0;
|
||||
for(unsigned int i = 0; label_tokens[i][0] != EOF; i++)
|
||||
{
|
||||
if(label_tokens[i][0] == '$') continue;
|
||||
strncpy(no_label_definition_tokens[new_index], label_tokens[i], MAX_TOKEN_SIZE);
|
||||
if(no_label_definition_tokens->size <= no_label_definition_tokens->used)
|
||||
{
|
||||
resize_dynamic_buffer(no_label_definition_tokens);
|
||||
}
|
||||
strncpy(((char(*)[MAX_TOKEN_SIZE]) no_label_definition_tokens->buffer)[new_index], label_tokens[i], MAX_TOKEN_SIZE);
|
||||
new_index++;
|
||||
no_label_definition_tokens->used += MAX_TOKEN_SIZE;
|
||||
}
|
||||
no_label_definition_tokens[new_index][0] = EOF;
|
||||
|
||||
if(no_label_definition_tokens->size <= no_label_definition_tokens->used)
|
||||
{
|
||||
resize_dynamic_buffer(no_label_definition_tokens);
|
||||
}
|
||||
((char (*)[MAX_TOKEN_SIZE]) no_label_definition_tokens->buffer)[new_index][0] = EOF;
|
||||
no_label_definition_tokens->used += MAX_TOKEN_SIZE;
|
||||
}
|
||||
|
||||
void replace_labels_with_adresses(char no_label_definition_tokens[][MAX_TOKEN_SIZE], char tokens[][MAX_TOKEN_SIZE], shash_hashtable_t label_table, shash_hashtable_t instruction_information_table)
|
||||
|
|
|
@ -129,7 +129,7 @@ int main(int argc, char **argv)
|
|||
}
|
||||
|
||||
dynamic_buffer_t label_tokens;
|
||||
init_dynamic_buffer(&label_tokens, 3 * MAX_TOKEN_SIZE, TABLE_GROW_SIZE * MAX_TOKEN_SIZE);
|
||||
init_dynamic_buffer(&label_tokens, TABLE_INIT_SIZE * MAX_TOKEN_SIZE, TABLE_GROW_SIZE * MAX_TOKEN_SIZE);
|
||||
if (label_tokens.buffer == NULL)
|
||||
{
|
||||
printf("Error: Could not create the label_tokens array\n");
|
||||
|
@ -154,7 +154,7 @@ int main(int argc, char **argv)
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
remove_label_definition_tokens((char (*)[MAX_TOKEN_SIZE]) label_tokens.buffer, (char (*)[MAX_TOKEN_SIZE]) no_label_definition_tokens.buffer);
|
||||
remove_label_definition_tokens((char (*)[MAX_TOKEN_SIZE]) label_tokens.buffer, &no_label_definition_tokens);
|
||||
printf("Removed label defintions\n");
|
||||
free(label_tokens.buffer);
|
||||
|
||||
|
|
Loading…
Reference in a new issue