projects
/
selector.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Added the "%s" format when simply writing a string.
[selector.git]
/
selector.c
diff --git
a/selector.c
b/selector.c
index
d4ddb27
..
daf2c26
100644
(file)
--- a/
selector.c
+++ b/
selector.c
@@
-214,6
+214,8
@@
void usage(FILE *out) {
/* A quick and dirty hash table */
/* A quick and dirty hash table */
+#define MAGIC_HASH_MULTIPLIER 387433
+
/* The table itself stores indexes of the strings taken in a char**
table. When a string is added, if it was already in the table, the
new index replaces the previous one. */
/* The table itself stores indexes of the strings taken in a char**
table. When a string is added, if it was already in the table, the
new index replaces the previous one. */
@@
-256,11
+258,11
@@
int add_and_get_previous_index(struct hash_table_t *hash_table,
int k;
/* This is my recipe. I checked, it seems to work (as long as
int k;
/* This is my recipe. I checked, it seems to work (as long as
- hash_table->size is not a multiple of
387433 that should be
- okay) */
+ hash_table->size is not a multiple of
MAGIC_HASH_MULTIPLIER that
+
should be
okay) */
for(k = 0; new_string[k]; k++) {
for(k = 0; new_string[k]; k++) {
- code = code *
387433
+ (unsigned int) (new_string[k]);
+ code = code *
MAGIC_HASH_MULTIPLIER
+ (unsigned int) (new_string[k]);
}
code = code % hash_table->size;
}
code = code % hash_table->size;
@@
-794,7
+796,7
@@
void read_file(struct hash_table_t *hash_table,
raw_line[BUFFER_SIZE - 1] = '\0';
fprintf(stderr, "selector: Line too long (max is %d characters):\n",
BUFFER_SIZE);
raw_line[BUFFER_SIZE - 1] = '\0';
fprintf(stderr, "selector: Line too long (max is %d characters):\n",
BUFFER_SIZE);
- fprintf(stderr, raw_line);
+ fprintf(stderr,
"%s",
raw_line);
fprintf(stderr, "\n");
exit(EXIT_FAILURE);
}
fprintf(stderr, "\n");
exit(EXIT_FAILURE);
}
@@
-851,7
+853,7
@@
int main(int argc, char **argv) {
char pattern[BUFFER_SIZE];
int c, k, l, n;
int cursor_position;
char pattern[BUFFER_SIZE];
int c, k, l, n;
int cursor_position;
- int error = 0, show_help = 0;
+ int error = 0, show_help = 0
, done = 0
;
int rest_are_files = 0;
int key;
int current_focus_line, displayed_focus_line;
int rest_are_files = 0;
int key;
int current_focus_line, displayed_focus_line;
@@
-1204,14
+1206,23
@@
int main(int argc, char **argv) {
clear();
}
clear();
}
+ else if(key == '\007' || /* ^G */
+ key == '\033' || /* ^[ (escape) */
+ key == '\n' ||
+ key == KEY_ENTER) {
+ done = 1;
+ }
+
+ else {
+ /* Unknown key */
+ error_feedback();
+ }
+
update_screen(¤t_focus_line, &displayed_focus_line,
motion,
nb_lines, labels, cursor_position, pattern);
update_screen(¤t_focus_line, &displayed_focus_line,
motion,
nb_lines, labels, cursor_position, pattern);
- } while(key != '\007' && /* ^G */
- key != '\033' && /* ^[ (escape) */
- key != '\n' &&
- key != KEY_ENTER);
+ } while(!done);
echo();
endwin();
echo();
endwin();
@@
-1240,7
+1251,7
@@
int main(int argc, char **argv) {
FILE *out = fopen(output_filename, "w");
if(out) {
if(t) {
FILE *out = fopen(output_filename, "w");
if(out) {
if(t) {
- fprintf(out, t);
+ fprintf(out,
"%s",
t);
}
fprintf(out, "\n");
} else {
}
fprintf(out, "\n");
} else {