Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move user completion to xlsh.

Signed-off-by: Michał Siejak <michal@siejak.pl>
  • Loading branch information...
commit c05ab203ac15ac3e11f49da000cf033193a31cb8 1 parent 4e8cccb
Mateusz Hromada authored committed
Showing with 55 additions and 56 deletions.
  1. +0 −6 include/libxlsh.h
  2. +5 −0 include/xlsh.h
  3. +0 −49 src/libxlsh.c
  4. +50 −1 src/xlsh.c
View
6 include/libxlsh.h
@@ -22,16 +22,10 @@
#define XLSH_OVERWRITE 0x01
#define XLSH_DETACH 0x02
-#if !defined (STREQN)
-#define STREQN(a, b, n) (((n) == 0) ? (1) \
- : ((a)[0] == (b)[0]) && (strncmp ((a), (b), (n)) == 0))
-#endif
-
void libxlsh_proc_sigmask(void);
pid_t libxlsh_proc_exec(const char* cmdline, int flags);
pid_t libxlsh_pid_read(const char* filename);
int libxlsh_pid_lock(const char* filename, pid_t pid, int flags);
int libxlsh_file_read(const char* filename, char** buffer, size_t* bufsize);
-char* libxlsh_username_completion_function(const char* text, int state);
#endif
View
5 include/xlsh.h
@@ -7,6 +7,11 @@
#ifndef __XLSH_H
#define __XLSH_H
+#if !defined (STREQN)
+#define STREQN(a, b, n) (((n) == 0) ? (1) \
+ : ((a)[0] == (b)[0]) && (strncmp ((a), (b), (n)) == 0))
+#endif
+
typedef enum xlsh_config_id_e {
XLSH_ID_EXEC = 0,
XLSH_ID_REBOOT,
View
49 src/libxlsh.c
@@ -109,52 +109,3 @@ int libxlsh_file_read(const char* filename, char** buffer, size_t* bufsize)
return XLSH_EOK;
}
-
-/* A completion function for usernames. */
-char* libxlsh_username_completion_function(const char* text, int state)
-{
- static char* username = (char*) NULL;
- static struct passwd* entry;
- static int namelen;
- char* value;
-
- if(state == 0)
- {
- if(username)
- free(username);
- namelen = strlen(text);
- username = malloc(namelen + 1);
- strcpy(username, text);
- setpwent();
- }
-
- while((entry = getpwent()))
- {
-#if XLSHD_COMPLETION_SHOWROOT == 1
- if(entry->pw_uid != 0
- && (entry->pw_uid < XLSHD_COMPLETION_MINUID
- || entry->pw_uid >= XLSHD_COMPLETION_MAXUID))
-#else
- if(entry->pw_uid == 0
- || entry->pw_uid < XLSHD_COMPLETION_MINUID
- || entry->pw_uid >= XLSHD_COMPLETION_MAXUID)
-#endif
- continue;
- /* Null usernames should result in all users as possible completions. */
- if(namelen == 0 || (STREQN(username, entry->pw_name, namelen)))
- break;
- }
-
- if(entry == 0)
- {
- endpwent();
- return ((char*) NULL);
- }
- else
- {
- value = malloc(2 + strlen(entry->pw_name));
- *value = *text;
- strcpy(value, entry->pw_name);
- return (value);
- }
-}
View
51 src/xlsh.c
@@ -515,13 +515,62 @@ static char* xlsh_cmd_match(const char* text, int state)
return NULL;
}
+/* A completion function for usernames. */
+char* xlsh_username_match(const char* text, int state)
+{
+ static char* username = (char*) NULL;
+ static struct passwd* entry;
+ static int namelen;
+ char* value;
+
+ if(state == 0)
+ {
+ if(username)
+ free(username);
+ namelen = strlen(text);
+ username = malloc(namelen + 1);
+ strcpy(username, text);
+ setpwent();
+ }
+
+ while((entry = getpwent()))
+ {
+#if XLSHD_COMPLETION_SHOWROOT == 1
+ if(entry->pw_uid != 0
+ && (entry->pw_uid < XLSHD_COMPLETION_MINUID
+ || entry->pw_uid >= XLSHD_COMPLETION_MAXUID))
+#else
+ if(entry->pw_uid == 0
+ || entry->pw_uid < XLSHD_COMPLETION_MINUID
+ || entry->pw_uid >= XLSHD_COMPLETION_MAXUID)
+#endif
+ continue;
+ /* Null usernames should result in all users as possible completions. */
+ if(namelen == 0 || (STREQN(username, entry->pw_name, namelen)))
+ break;
+ }
+
+ if(entry == 0)
+ {
+ endpwent();
+ return ((char*) NULL);
+ }
+ else
+ {
+ value = malloc(2 + strlen(entry->pw_name));
+ *value = *text;
+ strcpy(value, entry->pw_name);
+ return (value);
+ }
+}
+
static char** xlsh_cmd_complete(const char* text, int start, int end)
{
if(start == 0)
return rl_completion_matches((char*)text, xlsh_cmd_match);
else
return rl_completion_matches((char*)text,
- libxlsh_username_completion_function);
+ xlsh_username_match);
}
int xlsh_cmd_loop(void)
Please sign in to comment.
Something went wrong with that request. Please try again.