Skip to content

Commit

Permalink
strupr is a Microsoft C function; replaced with custom strupr to avoi…
Browse files Browse the repository at this point in the history
…d errors on Linux.
  • Loading branch information
linguini1 committed Jul 10, 2023
1 parent 4585f39 commit ac440a9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
10 changes: 5 additions & 5 deletions assembler/src/conversion/lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ Token *lexer_next_token(Lexer *lexer) {

if (is_operator(identifier)) {
ident_type = TokenOperator;
strupr(identifier);
string_to_uppercase(identifier);
} else if (is_register(identifier)) {
ident_type = TokenRegister;
strupr(identifier);
string_to_uppercase(identifier);
} else if (is_special_register(identifier)) {
ident_type = TokenSpecialRegister;
strupr(identifier);
string_to_uppercase(identifier);
}
return token_construct(identifier, ident_type, lexer->line, lexer->col);
}
Expand Down Expand Up @@ -276,7 +276,7 @@ static char *_struprcpy(char *ident) {
size_t length = strlen(ident);
char *upr_ident = malloc(length + 1);
strcpy(upr_ident, ident);
strupr(upr_ident);
string_to_uppercase(upr_ident);
return upr_ident;
}

Expand Down Expand Up @@ -318,7 +318,7 @@ static bool is_operator(char *ident) {
size_t length = strlen(ident);
char *upr_ident = malloc(length + 1);
strcpy(upr_ident, ident);
strupr(upr_ident);
string_to_uppercase(upr_ident);

if (length == 0) {
free(upr_ident);
Expand Down
12 changes: 10 additions & 2 deletions assembler/src/conversion/tokens.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "tokens.h"
#include <ctype.h>
#include <stdlib.h>
#include <string.h>

Expand Down Expand Up @@ -103,8 +104,15 @@ Token *token_list_get(TokenList *list, int index) {
return list->tokens[index];
}

/* Operator classifcation */
/* Utility functions */
void string_to_uppercase(char *string) {
while (*string) {
*string = toupper(*string);
string++;
}
}

/* Operator classification */
bool is_conditional(char *ident) {

if (ident == NULL) {
Expand All @@ -115,7 +123,7 @@ bool is_conditional(char *ident) {
size_t length = strlen(ident);
char *upr_ident = malloc(length + 1);
strcpy(upr_ident, ident);
strupr(upr_ident);
string_to_uppercase(upr_ident);

if (length == 0) {
free(upr_ident);
Expand Down
3 changes: 3 additions & 0 deletions assembler/src/conversion/tokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ void token_list_destruct(TokenList *list);
void token_list_append(TokenList *list, Token *token);
Token *token_list_get(TokenList *list, int index);

/* Utility functions */
void string_to_uppercase(char *string);

/* Operator classification */
bool is_conditional(char *ident);
unsigned int _condition_code(char *cc);
Expand Down

0 comments on commit ac440a9

Please sign in to comment.