File: cabber.c

package info (click to toggle)
cabber 0.4.0-test5-2.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 172 kB
  • ctags: 100
  • sloc: ansic: 1,421; makefile: 82
file content (131 lines) | stat: -rw-r--r-- 2,636 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include <ncurses.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "list.h"
#include "socket.h"
#include "parsecfg.h"
#include "server.h"
#include "keyb.h"
#include "screen.h"
#include "version.h"

extern int sock;
extern List roster;
extern int numbuddies;

void
exitcabber (void)
{
  DeleteList (roster);
  clear ();
  endwin ();
  exit (EXIT_SUCCESS);
}

int
main (void)
{
  char *response;
  char *inputline = malloc (MAXINPUT);
  char *idsession;
  char *filename = malloc (4096);
  int offset = 0;
  int selected = 0;
  int x;
  int curx, cury;
  int i;

  atexit (exitcabber);

  memset (inputline, 0, MAXINPUT);

  fprintf (stderr, "\n\r%s\n\r %s\n\r\n\r", VERSION, EMAIL);

  strncpy (filename, getenv ("HOME"), 1024);
  strcat (filename, "/.cabberrc");
  ReadCFGFile (filename);
  free (filename);
  fprintf (stderr, "\n\rConfig file parsed...\n\rInitializing NCurses...");

  InitCurses ();


  fprintf (stderr, "\n\rNcurses ok. Connecting...");

  ConnectToServer ();
  idsession = LogInServer ();
  free (idsession);
  DoScreen ();
  RequestRoster ();
  SetPresence ("Online!");
  DrawRoster (roster, offset, selected);

  mvprintw (LINES - 3, 1, "");
  for (i = 2; i < COLS - 2; i++)
    addch (' ');
  mvprintw (LINES - 3, 1, "<%s>: %s",
	    FindSelectedJidInList (selected, roster), inputline);

  refresh ();

  getyx (stdscr, cury, curx);


  while (1)			//Our main loop!
    {
      x = check_io (sock, 0);
      if ((x & 1) == 1)
	{
	  getyx (stdscr, cury, curx);
	  response = receivedata ();
	  checkdatafromserver (response, offset, selected);
	  free (response);
	  move (cury, curx);
	  refresh ();
	}
      if ((x & 2) == 2)
	{
	  switch (processinput (inputline, getch ()))
	    {
	    case KEY_DOWN:
	      selected++;
	      if (selected == numbuddies)
		selected = numbuddies - 1;
	      else if (selected - offset > LINES - 10)
		offset++;
	      DrawRoster (roster, offset, selected - offset);
	      break;

	    case KEY_UP:
	      selected--;
	      if (selected < 0)
		selected = 0;
	      if (selected - offset == -1)
		offset--;
	      DrawRoster (roster, offset, selected - offset);
	      break;

	    case ERETURN:
	      SendInputLine (inputline, offset, selected);
	      memset (inputline, 0, MAXINPUT);
	      break;

	    case EEXIT:
	      clear ();
	      refresh ();
	      endwin ();
	      exit (1);
	      break;
	    }
	  mvprintw (LINES - 3, 1, "");
	  for (i = 2; i < COLS - 2; i++)
	    addch (' ');
	  mvprintw (LINES - 3, 1, "<%s>: %s",
		    FindSelectedJidInList (selected, roster), inputline);
	  refresh ();
	}
    }
  return 1;
}