aboutsummarylogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api.c16
-rw-r--r--curses_win.c15
-rw-r--r--gtk_win.c18
-rw-r--r--main.c20
-rw-r--r--portfolio.c4
-rw-r--r--rc4.c2
-rw-r--r--utils.h2
7 files changed, 40 insertions, 37 deletions
diff --git a/api.c b/api.c
index 44e6dfb7889c..0f4522c45d06 100644
--- a/api.c
+++ b/api.c
@@ -173,7 +173,7 @@ String* api_iex_get_data_string(char** symbol_array, size_t len,
if (idx == len)
break;
- if (strcmp(symbol_array[idx], "USD$") != 0)
+ if (!streq(symbol_array[idx], "USD$"))
sprintf(&symbol_list_string[i][strlen(symbol_list_string[i])], "%s,",
symbol_array[idx]);
}
@@ -187,7 +187,7 @@ String* api_iex_get_data_string(char** symbol_array, size_t len,
}
for (size_t i = 0; i < num_partitions; i++)
- if (strcmp(symbol_array[i], "USD$") != 0 &&
+ if (!streq(symbol_array[i], "USD$") &&
pthread_join(threads[i], (void**) &string_array[i]))
EXIT_MSG("Error joining thread!");
@@ -227,7 +227,7 @@ void* api_morningstar_store_info(void* vpInfo) {
if (pString == NULL)
return NULL;
- if (strcmp("null", pString->data) == 0) { // Invalid symbol
+ if (streq("null", pString->data)) { // Invalid symbol
string_destroy(&pString);
return NULL;
}
@@ -348,7 +348,7 @@ void api_store_info_array(Info_Array* pInfo_Array, Data_Level data_level) {
memset(open_threads, 0, pInfo_Array->length * sizeof(int));
for (size_t i = 0; i < pInfo_Array->length; i++) {
pInfo = pInfo_Array->array[i];
- if (pInfo->api_provider == EMPTY && strcmp(pInfo->symbol, "USD$") != 0) {
+ if (pInfo->api_provider == EMPTY && !streq(pInfo->symbol, "USD$")) {
open_threads[i] = 1;
if (strlen(pInfo->symbol) > 5 && pthread_create(&threads[i], NULL,
api_coinmarketcap_store_info, pInfo)) { // Crypto
@@ -370,7 +370,7 @@ void api_store_info_array(Info_Array* pInfo_Array, Data_Level data_level) {
}
// Crypto with 5 char or less name
- if (pInfo->api_provider == EMPTY && strcmp(pInfo->symbol, "USD$") != 0 &&
+ if (pInfo->api_provider == EMPTY && !streq(pInfo->symbol, "USD$") &&
pthread_create(&threads[i], NULL, api_coinmarketcap_store_info, pInfo))
EXIT_MSG("Error creating thread!");
}
@@ -399,7 +399,7 @@ void api_store_info(Info* pInfo, Data_Level data_level) {
}
void info_store_portfolio_data(Info* pInfo) {
- if (strcmp(pInfo->symbol, "USD$") != 0) {
+ if (!streq(pInfo->symbol, "USD$")) {
if (pInfo->amount != EMPTY) {
pInfo->current_value = pInfo->amount * pInfo->price;
pInfo->profit_total = pInfo->current_value - pInfo->total_spent;
@@ -620,7 +620,7 @@ void info_store_news_json(Info* pInfo, const Json* jnews) {
* happen if there are not enough articles supplied by API.
*/
if (i > 0 && headline != NULL &&
- strcmp(json_object_get_string(headline), pInfo->articles[i - 1]->headline) == 0) {
+ streq(json_object_get_string(headline), pInfo->articles[i - 1]->headline)) {
pInfo->num_articles = i;
break;
}
@@ -677,7 +677,7 @@ void info_store_earnings_json(Info* pInfo, const Json* jearnings) {
Info* info_array_find_symbol(const Info_Array* pInfo_Array, const char* symbol) {
for (size_t i = 0; i < pInfo_Array->length; i++)
- if (strcmp(symbol, pInfo_Array->array[i]->symbol) == 0)
+ if (streq(symbol, pInfo_Array->array[i]->symbol))
return pInfo_Array->array[i];
return NULL;
diff --git a/curses_win.c b/curses_win.c
index a611da435548..6293a2935854 100644
--- a/curses_win.c
+++ b/curses_win.c
@@ -116,7 +116,7 @@ void info_array_portfolio_printw(Info_Array* portfolio_data) {
sort_option++;
portfolio_sort(portfolio_data, sort_option);
for (size_t i = 0; i < portfolio_data->length; i++)
- if (strcmp(portfolio_data->array[i]->symbol, highlight_sym) == 0)
+ if (streq(portfolio_data->array[i]->symbol, highlight_sym))
highlight_index = (int) i; // Make sure the same security stays highlighted
} else sort_option++;
@@ -127,7 +127,7 @@ void info_array_portfolio_printw(Info_Array* portfolio_data) {
sort_option--;
portfolio_sort(portfolio_data, sort_option); // Sort security array
for (size_t i = 0; i < portfolio_data->length; i++)
- if (strcmp(portfolio_data->array[i]->symbol, highlight_sym) == 0)
+ if (streq(portfolio_data->array[i]->symbol, highlight_sym))
highlight_index = (int) i; // Make sure the same security stays highlighted
} else sort_option--;
@@ -153,12 +153,13 @@ void portfolio_print_stock(const char* symbol) {
Json* jobj = json_tokener_parse(pString->data);
size_t i = 0, len = json_object_array_length(jobj);
- while (i < len && strcmp(
- json_object_get_string(json_object_object_get(json_object_array_get_idx(jobj, i), "Symbol")), symbol) != 0)
+ while (i < len && !streq(json_object_get_string(json_object_object_get
+ (json_object_array_get_idx(
+ jobj, i), "Symbol")), symbol))
i++;
if (i == len)
- GOTO_CLEAN_MSG("Your portfolio does not contain any of this security.")
+ GOTO_CLEAN_MSG("Your portfolio does not contain any of this security.")
Info* info = info_init();
strcpy(info->symbol, symbol);
@@ -260,9 +261,9 @@ void header_printw(WINDOW* window, const Info* symbol_info) {
}
void info_print(const Info* symbol_info) {
- if (strcmp(symbol_info->name, "") != 0)
+ if (streq(symbol_info->name, ""))
printf("Name: %s\n", symbol_info->name);
- if (strcmp(symbol_info->symbol, "") != 0)
+ if (streq(symbol_info->symbol, ""))
printf("Symbol: %s\n", symbol_info->symbol);
if (symbol_info->price != EMPTY)
printf("Price: $%lf\n", symbol_info->price);
diff --git a/gtk_win.c b/gtk_win.c
index 78ed4b74b3e2..821f114520ce 100644
--- a/gtk_win.c
+++ b/gtk_win.c
@@ -84,7 +84,7 @@ void on_load_button_clicked(GtkButton* button) {
if (difftime(now, app.last_reload) <= 60)
return;
- if (strcmp(gtk_button_get_label(button), "Reload") == 0) { // Reload portfolio
+ if (streq(gtk_button_get_label(button), "Reload")) { // Reload portfolio
list_store_update();
return;
}
@@ -159,7 +159,7 @@ void on_load_button_clicked(GtkButton* button) {
}
void on_lock_button_clicked(GtkButton* button) {
- if (strcmp(gtk_button_get_label(button), "Encrypt") == 0) {
+ if (streq(gtk_button_get_label(button), "Encrypt")) {
// Reset entries
gtk_entry_set_text(GTK_ENTRY(GET_OBJECT("set_password_entry1")), "");
gtk_entry_set_text(GTK_ENTRY(GET_OBJECT("set_password_entry2")), "");
@@ -192,7 +192,7 @@ void on_set_password_entry_activate(GtkEntry* entry) {
if (strlen(pass_str) < 6 || strlen(pass_str) > 30) // Too short or too long password
show_generic_message_dialog("Your password must be between 6 and 30 characters.", FALSE);
- else if (strcmp(pass_str, pass_check_str) != 0) // Passwords not matching
+ else if (!streq(pass_str, pass_check_str)) // Passwords not matching
show_generic_message_dialog("Your passwords did not match.", FALSE);
else { // If passwords match
sprintf(app.password, "%s\n", pass_str);
@@ -218,7 +218,7 @@ void on_decrypt_password_entry_activate(GtkEntry* entry) {
gchar mod_pass[strlen(pass) + 2];
sprintf(mod_pass, "%s\n", pass);
- if (strcmp(app.password, mod_pass) == 0) { // Success
+ if (streq(app.password, mod_pass)) { // Success
memset(app.password, '\0', PASS_MAX); // Overwrite password with null chars
// Change button label to Encrypt
gtk_button_set_label(GTK_BUTTON(GET_OBJECT("lock_button")), "Encrypt");
@@ -271,9 +271,9 @@ void on_modify_entry_activate(GtkEntry* entry) {
// Get text from dialog to determine whether adding, removing, or setting
const gchar* text = g_value_get_string(&gtext);
int modop;
- if (strcmp(text, "Add") == 0)
+ if (streq(text, "Add"))
modop = ADD;
- else if (strcmp(text, "Remove") == 0)
+ else if (streq(text, "Remove"))
modop = REMOVE;
else modop = SET;
@@ -292,7 +292,7 @@ void on_portfolio_modify_dialog_response(GtkDialog* dialog, gint response_id) {
void on_password_entry_activate(GtkEntry* entry) {
const gchar* password = gtk_entry_get_text(GTK_ENTRY(GET_OBJECT("password_entry")));
- if (strcmp(password, "") == 0) // Return if NULL or empty entry text
+ if (streq(password, "")) // Return if NULL or empty entry text
return;
gtk_widget_hide(GTK_WIDGET(GET_OBJECT("get_password_dialog")));
@@ -339,7 +339,7 @@ void on_check_window_destroy(void) {
void on_column_clicked(GtkTreeViewColumn* column, GtkListStore* list_store) {
Col_Index idx = SYMBOL;
for (Col_Index i = AMOUNT; i < NUM_COLS; i++) // Determine which column was clicked
- if (strcmp(gtk_tree_view_column_get_title(column), column_names[i]) == 0)
+ if (streq(gtk_tree_view_column_get_title(column), column_names[i]))
idx = i;
// Sort based on the column
@@ -472,7 +472,7 @@ void list_store_sort(GtkListStore* list_store, Col_Index idx) {
gtk_tree_model_get(model, &iter2, SYMBOL, &sym2, -1);
// Don't sort TOTALS
- if (strcmp(sym1, "TOTALS") != 0 && strcmp(sym2, "TOTALS") != 0) {
+ if (!streq(sym1, "TOTALS") && !streq(sym2, "TOTALS")) {
// Get the value from idx
gtk_tree_model_get(model, &iter1, idx, &str1, -1);
gtk_tree_model_get(model, &iter2, idx, &str2, -1);
diff --git a/main.c b/main.c
index d9deaf203edb..a7d9fdd6959d 100644
--- a/main.c
+++ b/main.c
@@ -31,7 +31,7 @@ int main(int argc, char* argv[]) {
window_main();
// News
- else if (strcmp(cmd, "news") == 0 && (argc == 3 || argc == 4)) {
+ else if (streq(cmd, "news") && (argc == 3 || argc == 4)) {
int num_articles = 3; // Default
if (argc == 4)
num_articles = (int) strtol(argv[3], NULL, 10);
@@ -39,19 +39,19 @@ int main(int argc, char* argv[]) {
}
//Encrypt/decrypt
- else if ((strcmp(cmd, "encrypt") == 0 || strcmp(cmd, "decrypt") == 0) && argc == 2)
- portfolio_write_encrypt_decrypt(strcmp(cmd, "encrypt") == 0); // 1 if encrypt, 0 if decrypt
+ else if ((streq(cmd, "encrypt") || streq(cmd, "decrypt")) && argc == 2)
+ portfolio_write_encrypt_decrypt(streq(cmd, "encrypt")); // 1 if encrypt, 0 if decrypt
// Info
- else if (strcmp(cmd, "info") == 0 && argc == 3)
+ else if (streq(cmd, "info") && argc == 3)
interface_print(sym);
// Graph
- else if (strcmp(cmd, "graph") == 0 && argc == 3)
+ else if (streq(cmd, "graph") && argc == 3)
graph_print(sym, NULL);
// Compare
- else if (strcmp(cmd, "cmp") == 0 && argc == 4) {
+ else if (streq(cmd, "cmp") && argc == 4) {
char sym2[strlen(argv[3]) + 1];
strcpy(sym2, argv[3]);
strtoupper(sym2);
@@ -59,18 +59,18 @@ int main(int argc, char* argv[]) {
}
// Check
- else if (strcmp(cmd, "check") == 0 && (argc == 2 || argc == 3)) {
+ else if (streq(cmd, "check") && (argc == 2 || argc == 3)) {
if (argc == 2)
portfolio_printw();
else portfolio_print_stock(sym);
}
// Portfolio
- else if (strcmp(cmd, "add") == 0)
+ else if (streq(cmd, "add"))
modop = ADD;
- else if (strcmp(cmd, "rm") == 0)
+ else if (streq(cmd, "rm"))
modop = REMOVE;
- else if (strcmp(cmd, "set") == 0)
+ else if (streq(cmd, "set"))
modop = SET;
else puts("Invalid arguments. Type \"man tick\" for help.");
diff --git a/portfolio.c b/portfolio.c
index 9bbc6e1944c6..b93dcf692e7d 100644
--- a/portfolio.c
+++ b/portfolio.c
@@ -81,7 +81,7 @@ int portfolio_modify_string(String* pString, const char* symbol, double quantity
GOTO_CLEAN_MSG("You don't have any of this security to remove")
}
- if (strcmp("USD$", symbol) != 0) { // Check that the symbol is valid, except if it's USD
+ if (!streq("USD$", symbol)) { // Check that the symbol is valid, except if it's USD
Info* data = info_init();
strcpy(data->symbol, symbol);
api_store_info(data, DATA_LEVEL_CHECK);
@@ -233,7 +233,7 @@ int portfolio_symbol_index(const char* symbol, const Json* jarray) {
for (size_t i = 0; i < json_object_array_length(jarray); i++) {
const char* string = json_object_get_string(
json_object_object_get(json_object_array_get_idx(jarray, (size_t) i), "Symbol"));
- if (strcmp(string, symbol) == 0)
+ if (streq(string, symbol))
return (int) i;
}
diff --git a/rc4.c b/rc4.c
index 040c5d7f18c2..9ac5352febcb 100644
--- a/rc4.c
+++ b/rc4.c
@@ -102,7 +102,7 @@ void portfolio_write_encrypt_decrypt(int crypt_opt) {
puts("You will be asked to enter your password again to make sure the entries match.");
sleep(2); // Sleep so user can read above message before ncurses initscr()
char* password_check = rc4_ncurses_get_password(); // Get password a second time
- if (strcmp(password, password_check) != 0) { // Make sure the two passwords are the same
+ if (!streq(password, password_check)) { // Make sure the two passwords are the same
free(password_check);
GOTO_CLEAN_MSG("Passwords do not match!")
}
diff --git a/utils.h b/utils.h
index 60ad747ba5e4..9671b1a87ae9 100644
--- a/utils.h
+++ b/utils.h
@@ -1,6 +1,8 @@
#ifndef TICK_UTILS_H
#define TICK_UTILS_H
+#define streq(a,b) (strcmp(a,b) == 0)
+
#define RET_MSG(msg) {\
puts(msg);\
return;\