2 Copyright (C) 2006 by Jonas Kramer
3 Published under the terms of the GNU General Public License (GPL).
14 #include "completion.h"
16 #include "interface.h"
20 static char ** users
= NULL
;
21 static int usercomplete(char *, const unsigned, int);
23 void recommend(struct hash track
) {
24 char key
, * message
= NULL
, * recipient
= NULL
;
27 struct prompt setup
= {
28 .prompt
= "Recipient: ",
31 .callback
= usercomplete
,
34 struct prompt comment
= {
35 .prompt
= "Comment: ",
44 fputs("Recommend (a)rtist, a(l)bum, (t)rack or (c)ancel?\n", stderr
);
46 while(!strchr("altc", (key
= fetchkey(2))));
51 users
= neighbors(value(& rc
, "username"));
52 users
= merge(users
, friends(value(& rc
, "username")), 0);
54 recipient
= readline(& setup
);
59 message
= readline(& comment
);
64 "recommendArtist", "ssss",
65 value(& track
, "creator"),
66 recipient
, message
, "en"
72 "recommendAlbum", "sssss",
73 value(& track
, "creator"),
74 value(& track
, "album"),
75 recipient
, message
, "en"
81 "recommendTrack", "sssss",
82 value(& track
, "creator"),
83 value(& track
, "title"),
84 recipient
, message
, "en"
89 puts(result
? "Recommended." : "Sorry, failed.");
93 static int usercomplete(char * line
, const unsigned max
, int changed
) {
94 unsigned length
, nres
= 0;
96 const char * match
= NULL
;
99 length
= strlen(line
);
101 /* Remove spaces at the beginning of the string. */
102 while(isspace(line
[0])) {
104 memmove(line
, line
+ 1, strlen(line
+ 1));
108 /* Remove spaces at the end of the string. */
109 while((length
= strlen(line
)) > 0 && isspace(line
[length
- 1])) {
114 if(!users
|| !users
[0])
117 if((match
= nextmatch(users
, changed
? line
: NULL
, & nres
)) != NULL
) {
118 snprintf(line
, max
, "%s", match
);