Skip to content

Commit

Permalink
flag for utf8 arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattn committed Nov 7, 2011
1 parent 9bd5ae8 commit cb2442b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
19 changes: 14 additions & 5 deletions src/gntp-send.c
Expand Up @@ -96,15 +96,17 @@ main(int argc, char* argv[]) {
char* icon = NULL;
char* url = NULL;
int tcpsend = 1;
int utf8 = 0;

opterr = 0;
while ((c = getopts(argc, argv, "a:n:s:p:u")) != -1) {
while ((c = getopts(argc, argv, "a:n:s:p:u8")) != -1) {
switch (optopt) {
case 'a': appname = optarg; break;
case 'n': notify = optarg; break;
case 's': server = optarg; break;
case 'p': password = optarg; break;
case 'u': tcpsend = 0; break;
case '8': utf8 = 1; break;
case '?': break;
default: argc = 0; break;
}
Expand All @@ -116,10 +118,17 @@ main(int argc, char* argv[]) {
exit(1);
}

title = string_to_utf8_alloc(argv[optind]);
message = string_to_utf8_alloc(argv[optind + 1]);
if ((argc - optind) >= 3) icon = string_to_utf8_alloc(argv[optind + 2]);
if ((argc - optind) == 4) url = string_to_utf8_alloc(argv[optind + 3]);
if (!utf8) {
title = string_to_utf8_alloc(argv[optind]);
message = string_to_utf8_alloc(argv[optind + 1]);
if ((argc - optind) >= 3) icon = string_to_utf8_alloc(argv[optind + 2]);
if ((argc - optind) == 4) url = string_to_utf8_alloc(argv[optind + 3]);
} else {
title = strdup(argv[optind]);
message = strdup(argv[optind + 1]);
if ((argc - optind) >= 3) icon = strdup(argv[optind + 2]);
if ((argc - optind) == 4) url = strdup(argv[optind + 3]);
}

if (!server) server = "127.0.0.1";

Expand Down
8 changes: 4 additions & 4 deletions src/growl.c
Expand Up @@ -164,7 +164,7 @@ growl_tcp_register(
growl_tcp_write(sock, "Notifications-Count: %d", notifications_count);
growl_tcp_write(sock, "%s", "");

for(i = 0; i < notifications_count; i++) {
for (i = 0; i < notifications_count; i++) {
growl_tcp_write(sock, "Notification-Name: %s", notifications[i]);
growl_tcp_write(sock, "Notification-Display-Name: %s", notifications[i]);
growl_tcp_write(sock, "Notification-Enabled: True");
Expand Down Expand Up @@ -406,15 +406,15 @@ int growl_udp_register(
sprintf((char*)data + pointer, "%s", appname);
pointer += strlen(appname);

for(i = 0; i < notifications_count; i++) {
for (i = 0; i < notifications_count; i++) {
uint16_t notify_length = ntohs(strlen(notifications[i]));
memcpy(data + pointer, &notify_length, 2);
pointer +=2;
sprintf((char*)data + pointer, "%s", notifications[i]);
pointer += strlen(notifications[i]);
}

for(j = 0; j < notifications_count; j++) {
for (j = 0; j < notifications_count; j++) {
memcpy(data + pointer, &j, 1);
pointer++;
}
Expand Down Expand Up @@ -500,7 +500,7 @@ int growl_udp(
const char *const password,
const char *url) {

int rc = growl_udp_register(server, appname, (const char **const)&notify, 1, password);
int rc = growl_udp_register(server, appname, (const char **const)&notify, 1, password);
if (rc == 0) {
rc = growl_udp_notify(server, appname, notify, title, message, password);
}
Expand Down

0 comments on commit cb2442b

Please sign in to comment.