mirror of
https://github.com/dvorka/hstr.git
synced 2024-11-10 17:18:35 +08:00
Making source C99 compliant
This commit is contained in:
parent
7e91f2bcd3
commit
eef3a67183
5 changed files with 22 additions and 5 deletions
|
@ -2,7 +2,6 @@
|
|||
|
||||
rm -vf *.*~
|
||||
|
||||
# copy hstr/ source code to a work directory and run this script to create DEB package
|
||||
cd ..
|
||||
bzr commit -m "Sync."
|
||||
bzr builddeb -- -us -uc
|
||||
|
|
|
@ -59,7 +59,8 @@ int hashset_put(HashSet * hs, const char *key, void *value) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
newNode->key = strdup( key );
|
||||
newNode->key = malloc(strlen(key)+1);
|
||||
strcpy(newNode->key, key);
|
||||
newNode->value = value;
|
||||
newNode->next = hs->lists[ listNum ];
|
||||
hs->lists[ listNum ] = newNode;
|
||||
|
|
|
@ -63,11 +63,10 @@ static bool terminalHasColors=FALSE;
|
|||
static char screenLine[1000];
|
||||
|
||||
int print_prompt(WINDOW *win) {
|
||||
char hostname[128];
|
||||
char *hostname = get_hostname();
|
||||
char *user = getenv(ENV_VAR_USER);
|
||||
int xoffset = 1;
|
||||
|
||||
gethostname(hostname, sizeof hostname);
|
||||
mvwprintw(win, xoffset, Y_OFFSET_PROMPT, "%s@%s$ ", user, hostname);
|
||||
refresh();
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
#include "include/hstr_utils.h"
|
||||
|
||||
#define DEFAULT_COMMAND "pwd"
|
||||
#define HOSTNAME_BUFFER 100
|
||||
#define PROC_HOSTNAME "/proc/sys/kernel/hostname"
|
||||
|
||||
void tiocsti() {
|
||||
char buf[] = DEFAULT_COMMAND;
|
||||
|
@ -43,5 +45,19 @@ void reverse_char_pointer_array(char **array, unsigned length) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
char *get_hostname()
|
||||
{
|
||||
char *b=malloc(HOSTNAME_BUFFER);
|
||||
if(access( PROC_HOSTNAME, F_OK ) != -1) {
|
||||
FILE *f = fopen(PROC_HOSTNAME, "r");
|
||||
b=fgets(b, HOSTNAME_BUFFER, f);
|
||||
fclose(f);
|
||||
if(b) {
|
||||
b[strlen(b)-1]=0;
|
||||
return b;
|
||||
}
|
||||
}
|
||||
strcpy(b,"localhost");
|
||||
return b;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define MIN(a,b) (((a)<(b))?(a):(b))
|
||||
#define MAX(a,b) (((a)>(b))?(a):(b))
|
||||
|
@ -22,5 +23,6 @@
|
|||
void tiocsti();
|
||||
void fill_terminal_input(char* cmd, bool padding);
|
||||
void reverse_char_pointer_array(char **array, unsigned length);
|
||||
char *get_hostname();
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue