-void silc_print_to_window(WINDOW *win, char *message)
-{
- int str_len, len;
-
- str_len = strlen(message);
-
- if (str_len > COLS - 1) {
- /* Split overlapping words to next line */
- /* XXX In principal this is wrong as this modifies the original
- string as it replaces the last ' ' with '\n'. This could be done
- with little more work so that it would not replace anything. */
- len = COLS - 1;
- while (1) {
-
- while (len && message[len] != ' ')
- len--;
-
- if (!len)
- break;
-
- message[len] = '\n';
- len += COLS - 1;
- if (len > str_len)
- break;
- }
- }
-
- wprintw(win, "%s", message);
- wrefresh(win);
-}
-
-/* Prints message to the screen. This is used to print the messages
- user is typed and message that came on channels. */
-
-void silc_print(SilcClient client, char *msg, ...)
-{
- va_list vp;
- char message[2048];
- SilcClientInternal app = client->application;
-
- memset(message, 0, sizeof(message));
- strncat(message, "\n ", 2);
-
- va_start(vp, msg);
- vsprintf(message + 1, msg, vp);
- va_end(vp);
-
- /* Print the message */
- silc_print_to_window(app->screen->output_win[0], message);
-}
-
-/* Returns user's mail path */
-
-char *silc_get_mail_path()
-{
- char pathbuf[MAXPATHLEN];
- char *path;
-
-#ifndef _PATH_MAILDIR
-#define _PATH_MAILDIR "/var/mail"
-#endif
-
- path = getenv("MAIL");
- if (path) {
- strncpy(pathbuf, path, strlen(path));
- } else {
- strcpy(pathbuf, _PATH_MAILDIR);
- strcat(pathbuf, "/");
- strcat(pathbuf, silc_get_username());
- }
-
- return strdup(pathbuf);
-}
-
-/* gets the number of the user's mails, if possible */
-
-int silc_get_number_of_emails()
-{
- FILE *tl;
- int num = 0;
- char *filename;
- char data[1024];
-
- filename = silc_get_mail_path();
-
- tl = fopen(filename, "r");
- if (!tl) {
- fprintf(stderr, "Couldn't open mail file (%s).\n", filename);
- } else {
- while((fscanf(tl, "%s", data)) != EOF) {
- if(!strcmp(data, "From:"))
- num++;
- }
-
- fclose(tl);
- }
-
- return num;
-}
-
-/* Returns time til next minute changes. Used to update the clock when
- needed. */
-
-int silc_client_time_til_next_min()
-{
- time_t curtime;
- struct tm *min;
-
- curtime = time(0);
- min = localtime(&curtime);
-
- return 60 - min->tm_sec;
-}
-
-/* Asks yes/no from user on the input line. Returns TRUE on "yes" and
- FALSE on "no". */
-
-int silc_client_ask_yes_no(SilcClient client, char *prompt)
-{
- SilcClientInternal app = (SilcClientInternal)client->application;
- char answer[4];
- int ret;
-
- again:
- silc_screen_input_reset(app->screen);
-
- /* Print prompt */
- wattroff(app->screen->input_win, A_INVIS);
- silc_screen_input_print_prompt(app->screen, prompt);
-
- /* Get string */
- memset(answer, 0, sizeof(answer));
- echo();
- wgetnstr(app->screen->input_win, answer, sizeof(answer));
- if (!strncasecmp(answer, "yes", strlen(answer)) ||
- !strncasecmp(answer, "y", strlen(answer))) {
- ret = TRUE;
- } else if (!strncasecmp(answer, "no", strlen(answer)) ||
- !strncasecmp(answer, "n", strlen(answer))) {
- ret = FALSE;
- } else {
- silc_say(client, app->conn, "Type yes or no");
- goto again;
- }
- noecho();