IRC client
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

chat.c 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* Copyright (C) 2018 Curtis McEnroe <june@causal.agency>
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU Affero General Public License as published by
  5. * the Free Software Foundation, either version 3 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU Affero General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Affero General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #define _WITH_GETLINE
  17. #include <err.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <sysexits.h>
  22. #include <unistd.h>
  23. #include "chat.h"
  24. static char *dupe(const char *str) {
  25. char *dup = strdup(str);
  26. if (!dup) err(EX_OSERR, "strdup");
  27. return dup;
  28. }
  29. static char *prompt(const char *prompt) {
  30. char *line = NULL;
  31. size_t cap;
  32. for (;;) {
  33. printf("%s", prompt);
  34. fflush(stdout);
  35. ssize_t len = getline(&line, &cap, stdin);
  36. if (ferror(stdin)) err(EX_IOERR, "getline");
  37. if (feof(stdin)) exit(EX_OK);
  38. if (len < 2) continue;
  39. line[len - 1] = '\0';
  40. return line;
  41. }
  42. }
  43. int main(int argc, char *argv[]) {
  44. int opt;
  45. while (0 < (opt = getopt(argc, argv, "NW:a:h:j:l:n:p:r:u:vw:"))) {
  46. switch (opt) {
  47. break; case 'N': self.notify = true;
  48. break; case 'W': self.webp = dupe(optarg);
  49. break; case 'a': self.auth = dupe(optarg);
  50. break; case 'h': self.host = dupe(optarg);
  51. break; case 'j': self.join = dupe(optarg);
  52. break; case 'l': logOpen(optarg);
  53. break; case 'n': self.nick = dupe(optarg);
  54. break; case 'p': self.port = dupe(optarg);
  55. break; case 'r': self.real = dupe(optarg);
  56. break; case 'u': self.user = dupe(optarg);
  57. break; case 'v': self.raw = true;
  58. break; case 'w': self.pass = dupe(optarg);
  59. break; default: return EX_USAGE;
  60. }
  61. }
  62. if (!self.host) self.host = prompt("Host: ");
  63. if (!self.port) self.port = dupe("6697");
  64. if (!self.nick) self.nick = prompt("Name: ");
  65. if (!self.user) self.user = dupe(self.nick);
  66. if (!self.real) self.real = dupe(self.nick);
  67. inputTab();
  68. uiInit();
  69. eventLoop();
  70. }