std::string get_field_text<edit_text_t>(const edit_text_t& widget) { if (!widget.control_m) return std::string(); if (widget.scroll_control_m) { ::Handle text_handle(0); ::ADOBE_REQUIRE_STATUS(::TXNGetDataEncoded(::HITextViewGetTXNObject(widget.control_m), kTXNStartOffset, kTXNEndOffset, &text_handle, kTXNUnicodeTextData)); auto_resource< ::Handle > auto_handle(text_handle); ::UniChar* buffer(reinterpret_cast< ::UniChar* >(*text_handle)); std::size_t size(::GetHandleSize(text_handle) / sizeof(::UniChar)); return implementation::convert_utf(buffer, size); } else { ::CFStringRef cfstring(0); implementation::get_widget_data(widget.control_m, kControlEntireControl, kControlEditTextCFStringTag, cfstring); auto_cfstring_t auto_cfstring(cfstring); return explicit_cast<std::string>(auto_cfstring); } }
int main(int argc, char **argv) { int c, i; int status; struct pollfd fd[3]; char msg[BUFLEN]; char *home; char *p; if(argc <= 1) usage(); opterr = 0; while((c = getopt(argc, argv, "c:e:f:F:m:n:p:P:rs:v")) != -1) { switch(c) { case 'c': channel = optarg; break; case 'e': program = optarg; break; case 'f': fifo = optarg; break; case 'F': fullname = optarg; break; case 'm': fifo_perms = strtoul(optarg, NULL, 8); break; case 'n': nickname = optarg; break; case 'p': port = atoi(optarg); break; case 'P': nspasswd = optarg; break; case 'r': reconnect = 1; break; case 's': server = optarg; break; case 'v': verbose++; break; default: usage(); break; } } /* keep passwords out of process lists */ if(nspasswd && strlen(nspasswd) > 1) { p = nspasswd; nspasswd = strdup(nspasswd); p[0] = '?'; for(i = 1; p[i]; i++) p[i] = '\0'; } if(optind != argc) usage(); if(!fifo) { if(!(home = getenv("HOME"))) home = "/tmp"; fifo = malloc(strlen(home) + strlen("/irc-pipe") + 1); sprintf(fifo, "%s/irc-pipe", home); } if(strlen(channel) > 200) { fprintf(stderr, "fifoirc: %s: channels must be at most 200 characters\n", channel); return 1; } if(!nickname) { fprintf(stderr, "fifoirc: no nickname specified\n"); return 1; } if(!fullname) fullname = nickname; if(make_fifo() == -1) return 1; if(verbose > INFO) printf(" -- fifo at %s\n", fifo); atexit(unlink_fifo); if(program && start_program() == -1) return 1; if(verbose > INFO) printf(" -- started '%s'\n", program); irc_connect(); signal(SIGINT, quit); signal(SIGTERM, quit); signal(SIGHUP, quit); while(1) { i = 0; fd[i].fd = fifo_fd; fd[i].events = POLLIN; i++; fd[i].fd = irc_fd; fd[i].events = POLLIN; i++; if(program) { fd[i].fd = program_fd; fd[i].events = POLLIN; i++; } c = poll(fd, i, 600000); /* restart the child if it died */ if(program && waitpid(childpid, &status, WNOHANG)) if(start_program() == -1) break; if(c == -1) { perror("fifoirc: poll"); break; } else if(c == 0) {/* timeout */ if(time(NULL) > recv_time + 600) { fprintf(stderr, "fifoirc: ping timeout: %d seconds\n", (int)(time(NULL) - recv_time)); irc_disconnect(); } snprintf(msg, BUFLEN, "PING :%s", server); irc_write(irc_fd, msg); } else { if(fd[0].revents & POLLIN) text_handle(fifo_fd); if(fd[0].revents & POLLHUP) if(make_fifo() == -1) break; if(fd[1].revents & POLLIN) irc_handle(); if(fd[1].revents & POLLHUP) irc_disconnect(); if(program) { if(fd[2].revents & POLLIN) text_handle(program_fd); if(fd[2].revents & POLLHUP) if(start_program() == -1) break; } } } quit(0); return 0; }