Fixing all unsigned/signed warnings.

This commit is contained in:
Martin Dvorak 2018-08-10 20:03:54 +02:00
parent 80938d40d4
commit 19e9271161
8 changed files with 86 additions and 65 deletions

View file

@ -19,9 +19,7 @@ CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
QMAKE_CXX = ccache g++
# -L where to look for library, -l link the library
# -L for where to look for library, -l for linking the library
LIBS += -lm -lreadline -lncursesw
SOURCES += \
@ -44,3 +42,7 @@ HEADERS += \
src/include/hstr_regexp.h \
src/include/hstr_utils.h \
src/include/radixsort.h
# compiler and linker
QMAKE_CC = ccache gcc
QMAKE_LINK = gcc

View file

@ -427,9 +427,9 @@ void hstr_get_env_configuration(Hstr *hstr)
}
}
int print_prompt()
unsigned print_prompt()
{
int xoffset = 0, promptLength;
unsigned xoffset = 0, promptLength;
if(hstr->theme & HH_THEME_COLOR) {
color_attr_on(COLOR_PAIR(HH_COLOR_PROMPT));
@ -462,7 +462,7 @@ int print_prompt()
void add_to_selection(Hstr *hstr, char *line, unsigned int *index)
{
if (hstr->unique) {
int i;
unsigned i;
for(i = 0; i < *index; i++) {
if (strcmp(hstr->selection[i], line) == 0) {
return;
@ -558,7 +558,7 @@ void print_cmd_added_favorite_label(const char *cmd, Hstr *hstr)
void print_history_label()
{
int width=getmaxx(stdscr);
unsigned width=getmaxx(stdscr);
char screenLine[CMDLINE_LNG];
snprintf(screenLine, width, "- HISTORY - view:%s (C-7) - match:%s (C-e) - case:%s (C-t) - %d/%d/%d ",
@ -570,7 +570,7 @@ void print_history_label()
hstr->favorites->count);
width -= strlen(screenLine);
unsigned i;
for (i=0; i < width; i++) {
for(i=0; i<width; i++) {
strcat(screenLine, "-");
}
if(hstr->theme & HH_THEME_COLOR) {
@ -618,7 +618,7 @@ void hstr_realloc_selection(unsigned size, Hstr *hstr)
}
}
unsigned hstr_make_selection(char *prefix, HistoryItems *history, int maxSelectionCount, Hstr *hstr)
unsigned hstr_make_selection(char *prefix, HistoryItems *history, unsigned maxSelectionCount, Hstr *hstr)
{
hstr_realloc_selection(maxSelectionCount, hstr);
@ -824,6 +824,8 @@ void print_selection_row(char *text, int y, int width, char *pattern)
void hstr_print_highlighted_selection_row(char *text, int y, int width, Hstr *hstr)
{
UNUSED_ARG(width);
color_attr_on(A_BOLD);
if(hstr->theme & HH_THEME_COLOR) {
color_attr_on(COLOR_PAIR(HH_COLOR_HIROW));
@ -851,8 +853,8 @@ char *hstr_print_selection(unsigned maxHistoryItems, char *pattern, Hstr *hstr)
result=hstr->selection[0];
}
int height=recalculate_max_history_items();
int width=getmaxx(stdscr);
unsigned height=recalculate_max_history_items();
unsigned width=getmaxx(stdscr);
unsigned i;
int y;
@ -869,7 +871,7 @@ char *hstr_print_selection(unsigned maxHistoryItems, char *pattern, Hstr *hstr)
int start, count;
char screenLine[CMDLINE_LNG];
for (i = 0; i<height; ++i) {
for(i=0; i<height; ++i) {
if(i<hstr->selectionSize) {
// TODO make this function
if(pattern && strlen(pattern)) {
@ -952,7 +954,7 @@ void highlight_selection(int selectionCursorPosition, int previousSelectionCurso
}
}
void hstr_on_exit(Hstr *hstr)
void hstr_on_exit(void)
{
history_mgmt_flush();
free_prioritized_history();
@ -962,12 +964,12 @@ void signal_callback_handler_ctrl_c(int signum)
{
if(signum==SIGINT) {
hstr_curses_stop(false);
hstr_on_exit(hstr);
hstr_on_exit();
exit(signum);
}
}
int remove_from_history_model(char *delete, Hstr *hstr)
int remove_from_history_model(char* delete, Hstr *hstr)
{
if(hstr->historyView==HH_VIEW_FAVORITES) {
return favorites_remove(hstr->favorites, delete);
@ -994,7 +996,7 @@ void hstr_next_view(Hstr *hstr)
void stdout_history_and_return(Hstr *hstr) {
unsigned selectionCount=hstr_make_selection(hstr->cmdline, hstr->history, hstr->history->rawCount, hstr);
if (selectionCount > 0) {
int i;
unsigned i;
for(i=0; i<selectionCount; i++) {
printf("%s\n",hstr->selection[i]);
}
@ -1035,7 +1037,7 @@ void loop_to_select(Hstr *hstr)
bool done=FALSE, skip=TRUE, executeResult=FALSE, lowercase=TRUE;
bool printDefaultLabel=TRUE, fixCommand=FALSE, editCommand=FALSE;
int basex=print_prompt();
unsigned basex=print_prompt();
int x=basex, c, cc, cursorX=0, cursorY=0, maxHistoryItems, deletedOccurences;
int width=getmaxx(stdscr);
int selectionCursorPosition=SELECTION_CURSOR_IN_PROMPT;
@ -1111,12 +1113,12 @@ void loop_to_select(Hstr *hstr)
}
if(hstr->promptBottom) {
if(selectionCursorPosition <= hstr->promptYItemsEnd-hstr->selectionSize+1) {
if(selectionCursorPosition <= (int)(hstr->promptYItemsEnd-hstr->selectionSize+1)) {
selectionCursorPosition=hstr->promptYItemsEnd-hstr->selectionSize+1;
}
} else {
if(selectionCursorPosition>=hstr->selectionSize) {
selectionCursorPosition=hstr->selectionSize-1;
if(selectionCursorPosition >= (int)hstr->selectionSize) {
selectionCursorPosition = hstr->selectionSize - 1;
}
}
highlight_selection(selectionCursorPosition, SELECTION_CURSOR_IN_PROMPT, pattern, hstr);
@ -1226,7 +1228,7 @@ void loop_to_select(Hstr *hstr)
previousSelectionCursorPosition=selectionCursorPosition;
if(selectionCursorPosition>0) {
if(hstr->promptBottom) {
if(selectionCursorPosition <= hstr->promptYItemsEnd-hstr->selectionSize+1) {
if(selectionCursorPosition <= (int)(hstr->promptYItemsEnd-hstr->selectionSize+1)) {
selectionCursorPosition=hstr->promptYItemsEnd;
} else {
selectionCursorPosition--;
@ -1272,7 +1274,7 @@ void loop_to_select(Hstr *hstr)
selectionCursorPosition=hstr->promptYItemsEnd-hstr->selectionSize+1;
}
} else {
if((selectionCursorPosition+1)<hstr->selectionSize) {
if((selectionCursorPosition+1) < (int)hstr->selectionSize) {
selectionCursorPosition++;
} else {
selectionCursorPosition=0;
@ -1289,7 +1291,7 @@ void loop_to_select(Hstr *hstr)
selectionCursorPosition=previousSelectionCursorPosition=0;
} else {
previousSelectionCursorPosition=selectionCursorPosition;
if((selectionCursorPosition+PG_JUMP_SIZE)<hstr->selectionSize) {
if((selectionCursorPosition+PG_JUMP_SIZE) < (int)hstr->selectionSize) {
selectionCursorPosition = selectionCursorPosition+PG_JUMP_SIZE;
} else {
selectionCursorPosition=hstr->selectionSize-1;
@ -1430,7 +1432,7 @@ void hstr_main(Hstr *hstr)
} else {
stdout_history_and_return(hstr);
}
hstr_on_exit(hstr);
hstr_on_exit();
} else {
printf("No history - nothing to suggest...\n");
}

View file

@ -70,8 +70,10 @@ void blacklist_load(Blacklist *blacklist)
fileSize = ftell(file);
rewind(file);
fileContent = malloc((fileSize + 1) * (sizeof(char)));
if(fread(fileContent, sizeof(char), fileSize, file)==-1) {
exit(EXIT_FAILURE);
if(!fread(fileContent, sizeof(char), fileSize, file)) {
if(ferror(file)) {
exit(EXIT_FAILURE);
}
}
fclose(file);
fileContent[fileSize] = 0;
@ -135,23 +137,27 @@ void blacklist_destroy(Blacklist *blacklist)
char* fileName = blacklist_get_filename();
int size=hashset_size(blacklist->set);
if(size) {
FILE *output_file = fopen(fileName, "wb");
rewind(output_file);
FILE *outputFile = fopen(fileName, "wb");
rewind(outputFile);
int i;
char **keys=hashset_keys(blacklist->set);
for(i=0; i<size; i++) {
if(fwrite(keys[i], sizeof(char), strlen(keys[i]), output_file)==-1) {
exit(EXIT_FAILURE);
if(!fwrite(keys[i], sizeof(char), strlen(keys[i]), outputFile)) {
if(ferror(outputFile)) {
exit(EXIT_FAILURE);
}
}
if(fwrite("\n", sizeof(char), strlen("\n"), output_file)==-1) {
exit(EXIT_FAILURE);
if(!fwrite("\n", sizeof(char), strlen("\n"), outputFile)) {
if(ferror(outputFile)) {
exit(EXIT_FAILURE);
}
}
}
fclose(output_file);
fclose(outputFile);
} else {
if(access(fileName, F_OK) != -1) {
FILE *output_file = fopen(fileName, "wb");
fclose(output_file);
FILE *outputFile = fopen(fileName, "wb");
fclose(outputFile);
}
}
free(fileName);

View file

@ -38,8 +38,8 @@ void favorites_show(FavoriteItems *favorites)
{
printf("\n\nFavorites (%d):", favorites->count);
if(favorites->count) {
int i;
for(i=0;i<favorites->count;i++) {
unsigned i;
for(i=0; i<favorites->count; i++) {
printf("\n%s",favorites->items[i]);
}
}
@ -69,8 +69,10 @@ void favorites_get(FavoriteItems* favorites)
inputFileSize = ftell(inputFile);
rewind(inputFile);
fileContent = malloc((inputFileSize + 1) * (sizeof(char)));
if(fread(fileContent, sizeof(char), inputFileSize, inputFile)==-1) {
exit(EXIT_FAILURE);
if(!fread(fileContent, sizeof(char), inputFileSize, inputFile)) {
if(ferror(inputFile)) {
exit(EXIT_FAILURE);
}
}
fclose(inputFile);
fileContent[inputFileSize] = 0;
@ -112,18 +114,22 @@ void favorites_save(FavoriteItems* favorites)
char* fileName=favorites_get_filename();
if(favorites->count) {
FILE* output_file = fopen(fileName, "wb");
rewind(output_file);
int i;
FILE* outputFile = fopen(fileName, "wb");
rewind(outputFile);
unsigned i;
for(i=0; i<favorites->count; i++) {
if(fwrite(favorites->items[i], sizeof(char), strlen(favorites->items[i]), output_file)==-1) {
exit(EXIT_FAILURE);
if(!fwrite(favorites->items[i], sizeof(char), strlen(favorites->items[i]), outputFile)) {
if(ferror(outputFile)) {
exit(EXIT_FAILURE);
}
}
if(fwrite("\n", sizeof(char), strlen("\n"), output_file)==-1) {
exit(EXIT_FAILURE);
if(!fwrite("\n", sizeof(char), strlen("\n"), outputFile)) {
if(ferror(outputFile)) {
exit(EXIT_FAILURE);
}
}
}
fclose(output_file);
fclose(outputFile);
} else {
if(access(fileName, F_OK) != -1) {
FILE *output_file = fopen(fileName, "wb");
@ -152,7 +158,7 @@ void favorites_add(FavoriteItems* favorites, char* newFavorite)
void favorites_choose(FavoriteItems* favorites, char* choice)
{
if(favorites->count && choice) {
int r;
unsigned r;
char* b=NULL, *next;
for(r=0; r<favorites->count; r++) {
if(!strcmp(favorites->items[r],choice)) {
@ -197,7 +203,7 @@ void favorites_destroy(FavoriteItems* favorites)
{
if(favorites) {
// TODO hashset destroys keys - no need to destroy items!
int i;
unsigned i;
for(i=0; i<favorites->count; i++) {
free(favorites->items[i]);
}

View file

@ -64,7 +64,7 @@ char *get_history_file_name(void)
void dump_prioritized_history(HistoryItems *historyItems)
{
printf("\n\nPrioritized history:");
int i;
unsigned i;
for(i=0; i<historyItems->count; i++) {
if(historyItems->items[i]!=NULL) {
printf("\n%s",historyItems->items[i]); fflush(stdout);
@ -75,7 +75,7 @@ void dump_prioritized_history(HistoryItems *historyItems)
printf("\n"); fflush(stdout);
}
int get_item_offset(void)
unsigned get_item_offset(void)
{
if(isZshParentShell()) {
// In zsh history file, the format of item is
@ -119,13 +119,12 @@ HistoryItems *get_prioritized_history(int optionBigKeys, HashSet *blacklist)
}
HISTORY_STATE *historyState=history_get_history_state();
int itemOffset = get_item_offset();
unsigned itemOffset = get_item_offset();
if(historyState->length > 0) {
HashSet rankmap;
hashset_init(&rankmap);
int i;
RadixSorter rs;
unsigned radixMaxKeyEstimate=historyState->size*1000;
radixsort_init(&rs, (radixMaxKeyEstimate<100000?100000:radixMaxKeyEstimate));
@ -137,6 +136,7 @@ HistoryItems *get_prioritized_history(int optionBigKeys, HashSet *blacklist)
char **rawHistory=malloc(sizeof(char*) * historyState->length);
int rawOffset=historyState->length-1, rawTimestamps=0;
char *line;
int i;
for(i=0; i<historyState->length; i++, rawOffset--) {
if(is_hist_timestamp(historyList[i]->line)) {
rawHistory[rawOffset]=0;
@ -193,16 +193,17 @@ HistoryItems *get_prioritized_history(int optionBigKeys, HashSet *blacklist)
prioritizedHistory->rawCount=historyState->length-rawTimestamps;
prioritizedHistory->items=malloc(rs.size * sizeof(char*));
prioritizedHistory->rawItems=rawHistory;
for(i=0; i<rs.size; i++) {
if(prioritizedRadix[i]->data) {
char* item = ((RankedHistoryItem *)(prioritizedRadix[i]->data))->item;
unsigned u;
for(u=0; u<rs.size; u++) {
if(prioritizedRadix[u]->data) {
char* item = ((RankedHistoryItem *)(prioritizedRadix[u]->data))->item;
if(strlen(item)>itemOffset) {
item += itemOffset;
}
prioritizedHistory->items[i]=item;
prioritizedHistory->items[u]=item;
}
free(prioritizedRadix[i]->data);
free(prioritizedRadix[i]);
free(prioritizedRadix[u]->data);
free(prioritizedRadix[u]);
}
radixsort_destroy(&rs);
@ -297,9 +298,9 @@ bool history_mgmt_remove_last_history_entry(bool verbose)
}
int history_mgmt_remove_from_raw(char *cmd, HistoryItems *history) {
int occurences=history->rawCount;
unsigned occurences=history->rawCount;
if(history->rawCount) {
int i, ii;
unsigned i, ii;
for(i=0, ii=0; i<history->rawCount; i++) {
if(strcmp(cmd, history->rawItems[i])) {
history->rawItems[ii++]=history->rawItems[i];
@ -311,9 +312,9 @@ int history_mgmt_remove_from_raw(char *cmd, HistoryItems *history) {
}
int history_mgmt_remove_from_ranked(char *cmd, HistoryItems *history) {
int occurences=history->count;
unsigned occurences=history->count;
if(history->count) {
int i, ii;
unsigned i, ii;
for(i=0, ii=0; i<history->count; i++) {
if(strcmp(cmd, history->items[i])) {
history->items[ii++]=history->items[i];

View file

@ -77,8 +77,8 @@ void hstr_chop(char *s)
void tiocsti()
{
char buf[] = DEFAULT_COMMAND;
int i;
for (i = 0; i < sizeof buf - 1; i++) {
unsigned i;
for (i=0; i<sizeof buf-1; i++) {
ioctl(0, TIOCSTI, &buf[i]);
}
}

View file

@ -27,6 +27,8 @@
#include <stdbool.h>
#include <unistd.h>
#define UNUSED_ARG(expr) do { (void)(expr); } while (0)
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))

View file

@ -97,6 +97,8 @@ void radixsort_add(RadixSorter *rs, RadixItem *item)
void radix_dec_slot_descriptor_size(RadixSorter *rs, RadixSlot *descriptor, unsigned key, unsigned topIndex)
{
UNUSED_ARG(key);
descriptor->size--;
if(!descriptor->size) {
descriptor->min=rs->keyLimit;