xaizek / hstr (License: Apachev2) (since 2018-12-07)
Bash and Zsh shell history suggest box - easily view, navigate, search and manage your command history.
Commit 37f684216a1dedb47781957571fd038a5047a417

Clean solution to strdup() not being in ISO C.
Author: Martin Dvorak
Author date (UTC): 2014-04-13 13:42
Committer name: Martin Dvorak
Committer date (UTC): 2014-04-13 13:42
Parent(s): 0ac76a6554d40ee948c9d2334d514145ba1471f7
Signing key:
Tree: 16905f22b913e1ce5e389ab76b68ab944100ebbd
File Lines added Lines deleted
dist/ubuntu-env.sh 3 3
src/hstr_favorites.c 5 5
src/hstr_utils.c 10 0
src/include/hstr_utils.h 1 0
tests/src/test_hashset.c 2 1
File dist/ubuntu-env.sh changed (mode: 100755) (index 837c68a..170222b)
1 1 #!/bin/bash #!/bin/bash
2 2
3 export HHVERSION="1.9.1"
3 export HHVERSION="1.9.10"
4 4 export HHFULLVERSION=${HHVERSION}-0ubuntu1 export HHFULLVERSION=${HHVERSION}-0ubuntu1
5 5 export HH=hh_${HHVERSION} export HH=hh_${HHVERSION}
6 6 export HHRELEASE=hh_${HHFULLVERSION} export HHRELEASE=hh_${HHFULLVERSION}
 
... ... export NOW=`date +%Y-%m-%d--%H-%M-%S`
9 9 export HHBUILD=hstr-${NOW} export HHBUILD=hstr-${NOW}
10 10
11 11 ## https://wiki.ubuntu.com/Releases ## https://wiki.ubuntu.com/Releases
12 export UBUNTUVERSION=precise
12 #export UBUNTUVERSION=precise
13 13 #export UBUNTUVERSION=quantal #export UBUNTUVERSION=quantal
14 14 #export UBUNTUVERSION=saucy #export UBUNTUVERSION=saucy
15 #export UBUNTUVERSION=trusty
15 export UBUNTUVERSION=trusty
16 16
17 17 export HHBZRMSG="Favorites - favorite commands can be bookmarked and shown in a new view!" export HHBZRMSG="Favorites - favorite commands can be bookmarked and shown in a new view!"
18 18
File src/hstr_favorites.c changed (mode: 100644) (index 0a0fc4e..39a39b6)
11 11 #include <stdio.h> #include <stdio.h>
12 12 #include <string.h> #include <string.h>
13 13 #include <unistd.h> #include <unistd.h>
14
14 15 #include "include/hstr_favorites.h" #include "include/hstr_favorites.h"
16 #include "include/hstr_utils.h"
15 17
16 18 #define FAVORITE_SEGMENT_SIZE 10 #define FAVORITE_SEGMENT_SIZE 10
17 19
18 extern char *strdup(const char *s);
19
20 20 void favorites_init(FavoriteItems *favorites) void favorites_init(FavoriteItems *favorites)
21 21 { {
22 22 favorites->items=NULL; favorites->items=NULL;
 
... ... void favorites_get(FavoriteItems *favorites)
68 68 while(pe!=NULL) { while(pe!=NULL) {
69 69 favorites->items[i]=pb; favorites->items[i]=pb;
70 70 *pe=0; *pe=0;
71 favorites->items[i]=(char *)strdup(pb);
71 favorites->items[i]=hstr_strdup(pb);
72 72 pb=pe+1; pb=pe+1;
73 73 pe=strchr(pb, '\n'); pe=strchr(pb, '\n');
74 74 i++; i++;
 
... ... void favorites_add(FavoriteItems *favorites, char *newFavorite)
115 115 { {
116 116 if(favorites->count) { if(favorites->count) {
117 117 favorites->items=realloc(favorites->items, sizeof(char *) * ++favorites->count); favorites->items=realloc(favorites->items, sizeof(char *) * ++favorites->count);
118 favorites->items[favorites->count-1]=strdup(newFavorite);
118 favorites->items[favorites->count-1]=hstr_strdup(newFavorite);
119 119 favorites_choose(favorites, newFavorite); favorites_choose(favorites, newFavorite);
120 120 } else { } else {
121 121 favorites->items=malloc(sizeof(char*)); favorites->items=malloc(sizeof(char*));
122 favorites->items[0]=strdup(newFavorite);
122 favorites->items[0]=hstr_strdup(newFavorite);
123 123 favorites->count=1; favorites->count=1;
124 124 } }
125 125
File src/hstr_utils.c changed (mode: 100644) (index 7346be8..0589f74)
8 8 */ */
9 9
10 10 #include "include/hstr_utils.h" #include "include/hstr_utils.h"
11
11 12 #include <ctype.h> #include <ctype.h>
12 13
13 14 #define DEFAULT_COMMAND "pwd" #define DEFAULT_COMMAND "pwd"
14 15 #define PROC_HOSTNAME "/proc/sys/kernel/hostname" #define PROC_HOSTNAME "/proc/sys/kernel/hostname"
15 16
17 // strdup() not in ISO C
18 char *hstr_strdup(const char * s)
19 {
20 size_t len = 1+strlen(s);
21 char *p = malloc(len);
22
23 return p ? memcpy(p, s, len) : NULL;
24 }
25
16 26 void tiocsti() void tiocsti()
17 27 { {
18 28 char buf[] = DEFAULT_COMMAND; char buf[] = DEFAULT_COMMAND;
File src/include/hstr_utils.h changed (mode: 100644) (index a4c7d48..2fd7a94)
20 20 #define MIN(a,b) (((a)<(b))?(a):(b)) #define MIN(a,b) (((a)<(b))?(a):(b))
21 21 #define MAX(a,b) (((a)>(b))?(a):(b)) #define MAX(a,b) (((a)>(b))?(a):(b))
22 22
23 char *hstr_strdup(const char * s);
23 24 void tiocsti(); void tiocsti();
24 25 void fill_terminal_input(char* cmd, bool padding); void fill_terminal_input(char* cmd, bool padding);
25 26 void reverse_char_pointer_array(char **array, unsigned length); void reverse_char_pointer_array(char **array, unsigned length);
File tests/src/test_hashset.c changed (mode: 100644) (index 6676938..4e6f70a)
8 8 */ */
9 9
10 10 #include "../src/include/hashset.h" #include "../src/include/hashset.h"
11 #include "../src/include/hstr_utils.h"
11 12
12 13 void testBlacklist() { void testBlacklist() {
13 14 const char* commandBlacklist[] = { }; const char* commandBlacklist[] = { };
 
... ... void testBlacklist() {
19 20 } }
20 21 for (i = 0; i < 5; i++) { for (i = 0; i < 5; i++) {
21 22 printf("match %d\n", printf("match %d\n",
22 hashset_contains(&blacklist, strdup(commandBlacklist[i])));
23 hashset_contains(&blacklist, hstr_strdup(commandBlacklist[i])));
23 24 } }
24 25 } }
25 26
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/hstr

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/hstr

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master