First CVS upload.

v2.8-utf8proc
Sebastien Helleu 2003-09-27 10:01:11 +00:00
commit 109101faeb
108 changed files with 22604 additions and 0 deletions

29
AUTHORS Normal file
View File

@ -0,0 +1,29 @@
WeeChat - Wee Enhanced Environment for Chat
===========================================
Developers:
----------
All developers are connected to IRC:
server: irc.freenode.net, channel: #weechat
FlashCode <flashcode@flashtux.org>
Web : http://www.flashtux.org
IRC : nick is "FlashCode"
Jabber: flashcode@jabber.org
ICQ : 160677660
AIM : FlashCode AIM
Yahoo : FlashCode_Y
Bounga <bounga@altern.org>
Web : http://bounga.ath.cx
IRC : nick is "Bounga"
Jabber: Bounga@jabber.org
ICQ : 178297842
Xahlexx <xahlexx@tuxisland.org>
Web : http://www.tuxisland.org
IRC : nick is "xahlexx"
See README file for licence detail.

17
BUGS Normal file
View File

@ -0,0 +1,17 @@
WeeChat - Wee Enhanced Environment for Chat
===========================================
WeeChat known bugs, 2003-09-27
- too much nicks in the channel (> height of window) => display bug
- some IRC commands are marked as 'unknown' when received
(irc protocol is under dev!)
- bug in nicklist resize (sometimes resize doesn't work and there is display
problem)
- alias/unalias commands doesn't work
- config is not saved (to ~/.weechat/weechatrc)
- intercept Ctrl-C (do not quit immediately if Ctrl-C pressed!)
- program is stopped when bad option in config file (it should not, only display
warning)
- too much opened channel => display bug
- when kicked, channel is not prefixed by '(' and sufixed by ')'

340
COPYING Normal file
View File

@ -0,0 +1,340 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.

88
ChangeLog Normal file
View File

@ -0,0 +1,88 @@
WeeChat - Wee Enhanced Environment for Chat
===========================================
ChangeLog - 2003-09-27
* 2003-09-27:
- WeeChat 0.0.1 released!
* 2003-09-26:
- added completor prefix (in config: look_nick_completor)
- fixef log_printf command (bug with year & month)
- added "/kill" command
- fixed /version and /ctcp commands (missing ":" before message)
* 2003-09-25:
- added "/kick" command
- added IRC errors 402 to 407
- added "/invite" command
* 2003-09-24:
- "ctcp version" received is now correctly displayed
- "/version" command is ok
* 2003-09-23:
- log file (~/.weechat/weechat.log)
- renamed config file (~/.weechat/weechatrc to ~/.weechat/weechat.rc)
* 2003-09-21:
- "demi-highlight": 2 types of windows highlight: lightred for windows with
unread messages (from other users), lightmagenta for windows with other
unread data (join, part, quit, away, ...)
- "320" IRC message management
- "/clear" command
* 2003-09-19:
- préparation des sources pour l'internationalisation avec gettext
- "301" IRC command (away message)
- functions renamed in rc-commands.c, irc-server.c,
command.c and config.c (all functions are beginning with a prefix:
irc_cmd_recv_xxx, irc_cmd_send_xxx, server_xxx, weechat_cmd_xxx and
config_xxx). Moreover, all commands (sent and received) return a value
(success or not)
- "/quote" command
- "/whois" command (and colored display of /whois result in server window)
* 2003-09-18:
- use of alternate nickname (and 2nd alternate) if nick is already used
on server (changed/added in config file: options "nick1", "nick2", "nick3"
for a server, all are mandatory)
- "433" IRC error management (nickname already in use)
- "mode" command received correctly for "channel flags" and
op/deop/voice/devoice actions for a nick
- "401" IRC error management (no such nick/channel)
- private windows management (when received and opened, with /privmsg),
"/privmsg" completed consequently
* 2003-09-17:
- nickmode display ((half)op/voice) before nicks (as option, look at config
options beginning with "look_nickmode")
- windows history is now ok (pgup/pgdn on any window type)
- "/me" command (and OK when received)
- display nicks count when joining channel or with "/names" command
(total, ops, halfops, voices et normaux)
* 2003-09-16:
- added and normalized chat window colors
(new colors in config file)
- "/topic" command
- nicklist can be moved on top, bottom, left or right of window
* 2003-09-15:
- auto-resize of nicklist, according to nick max length
- IRC multi-servers is OK
* 2003-09-14:
- no hangup if "/part" command is executed on server window
- continue if no server is declared in config file
(empty window will be opened for executing WeeChat commands)
- string array for strings in config file
example: cfg_look_nicklist_position can take values "left", "right",
"top", "bottom", which are converted to int (from 0 for "left" to 3 for
"bottom")
- messages are aligned under time (server window) or under time + nick
(channel window)
* 2003-09-13:
- sources exploded in many directories: ./irc, ./gui/curses, ./gui/gtk,
./gui/qt and ./gui/text

6
FAQ Normal file
View File

@ -0,0 +1,6 @@
WeeChat - Wee Enhanced Environment for Chat
===========================================
WeeChat FAQ, 2003-09-19
<<< TO DO ! >>>

10
INSTALL Normal file
View File

@ -0,0 +1,10 @@
WeeChat - Installation instructions
===================================
1) Run 'make'
2) As root, run 'make install'
3) Enjoy ! :-)
See AUTHORS for any support, feel free to contact us for any problem ;)

31
Makefile Normal file
View File

@ -0,0 +1,31 @@
# Copyright (c) 2003 FlashCode <flashcode@flashtux.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
OUTPUT=weechat
all:
cd src && make
install:
@mkdir -v -p $(DESTDIR)/usr/$(LOCALRPM)/bin
@cp -v src/$(OUTPUT) $(DESTDIR)/usr/$(LOCALRPM)/bin/
@mkdir -v -p $(DESTDIR)/usr/share/man/man1
@cp -v weechat.1 $(DESTDIR)/usr/share/man/man1/
@echo -e "\n=== WeeChat installed!\n"
clean:
cd src && make clean

6
NEWS Normal file
View File

@ -0,0 +1,6 @@
WeeChat - Wee Enhanced Environment for Chat
===========================================
FlashCode, 2003-09-27
WeeChat 0.0.1 released.

50
README Normal file
View File

@ -0,0 +1,50 @@
WeeChat - Wee Enhanced Environment for Chat
===========================================
WeeChat (Wee Enhanced Environment for Chat) is a fast and light chat
environment for many operating systems. Everything can be done with a keyboard.
It is customizable and extensible with scripts.
Features
--------
* IRC chat client with multi-server connection
* many GUI (curses, text, Gtk, QT) (1)
* small, fast and very light
* customizable and extensible with scripts (Perl, Python, Ruby) (2)
* compliant with RFC 1459,2810,2811,2812,2813
* multi-platform (GNU/Linux, *BSD, Windows & other) (3)
* 100% GPL & free
Copyright
---------
WeeChat (c) Copyright 2003
by: FlashCode <flashcode@flashtux.org>
Xahlexx <xahlex@tuxisland.org>
Bounga <bounga@altern.org>
(see AUTHORS file if you want to contact authors)
WeeChat is distributed under GPL licence (see COPYING file for complete license):
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
---
(1) only curses & text interfaces are available today
(2) plugin interfaces are not yet developed
(3) only GNU/Linux version is available today

130
TODO Normal file
View File

@ -0,0 +1,130 @@
WeeChat - Wee Enhanced Environment for Chat
===========================================
TODO - 2003-09-27
Legend:
# done
+ currently in development
- pending
? is this really necessary?
v0.0.1:
* IRC protocol:
# "/quote" command: send a raw string to the server without parsing it
# "/me" command (for user actions description)
# "/away" command (to toggle the away status)
# "/op", "/deop", "/voice", "/devoice" commands
# "/invite" command
# "/kick", "/ban", "/unban" commands
# "/kill" command
# "/list" command: list of channels
# "/names" command: view who is on a given channel without being
on it (for example /names #weechat gives all the nicks present on
#weechat, except those who have the +i flag (server side))
# "/oper" command: become operator on the irc network
# "/topic" command: change the topic of a channel
# "/version" command: give the irc client version (CTCP VERSION)
of a given nick/channel (without parameter: gives WeeChat version)
# "/whois" command
* WeeChat commands:
# "/clear": to clear window content
* Interface:
# "demi-highlight" when joins/quits etc
# log messages/warning/errors to ~/.weechat/log file
# improve editing zone (left arrow <> backspace)
# sort nick list
# choose nick list position (top, left, right (default), bottom)
# auto-resize nicklist (when nick too long)
# do pretty cutting of long lines (align on the nick or after hour for server)
# keep history of commands and call them again with up/down arrow
# text GUI
# ncurses GUI:
# one window for each channel
# color display
# private windows
# redraw window when term size is modified
# chat history (pgup/pgdn for displaying history)
# switch to other channel window
* TCP/IP communication:
# IPv4 protocol implementation
* Configuration:
# write default config file
Future versions:
* IRC protocol:
- implement RFC 2812
+ "/mode" command: change the user/channels modes
- "/dcc" command (for chat and sending/receiving files)
- manage "halfop" status
- complete "/list" command: add regexp search, display only channels that
match regexp
- "/connect" and "/disconnect" commands (for multiservers use)
- "/ignore" and "/unignore" commands: hide all that is write by a given
nick/host
- when we're away, WeeChat should log all the lines begenning by our nick.
When we come back from our away it should print it to the current window
- "/rehash" command: tell the server to reload its config file
- "/restart" command: tell the server to restart itself
- "/notify" and "/unnotify" command to be warn by WeeChat when a given
nick/host connect to the given irc network
- "/wallops" command: write the same string to all the
persons with the flag +w enable
* WeeChat commands:
- "/completion" command: do shortcuts (for example when we type "u"
in the text bar it send it to the server as "you")
- "/exec" command: execute a command as if we was in shell
and show us the output on the current window. An option to exec
like -o could send the output to the server, on the current
channel/private
- "/reload" command: reload the WeeChat's config file
- "/set" command: allow the user to set the WeeChat variables
under WeeChat without editing the config file (colours, time
format, etc)
- "/highlight" command: highlight a given word when it appears on
channels/privates
* Interface:
- display current channel modes (example : #weechat(+nt))
- interpret ^B in messages (this means bold text)
- internationalization (traduce WeeChat in many languages)
- many channel windows in one window/term (window split)
- add lag indicator
- log chats to file
- forget some old lines that were displayed long time ago (now all is saved,
if WeeChat is running for long time, a lot of memory is used!)
- improve completion (for example complete command parameters when possible)
- understand incomplete commands if unambigous (for example: /he for /help is ok)
- add clock (in status bar?)
- Gtk GUI
? Qt GUI
* TCP/IP communication:
- IPv6 protocol implementation
* Configuration:
- add key bindings to config file
- add missing options for config file
- write config file
- add an option for each server in order to run commands on join
(example: /msg nickserv identify password)
- channel list for auto-join (for each server)
- do not stop program if problem with options in config file
- load config file after GUI (so init values by default (colors, ...) before
loading config)
* Plugins:
- add Perl plugin
- add Python plugin
- add Ruby plugin
- "/load" and "/unload" commands to (un)load extension scripts
(perl, python, ruby, ...)

5
debian/changelog vendored Normal file
View File

@ -0,0 +1,5 @@
weechat (0.0.1-1) unstable; urgency=low
* First version.
-- FlashCode <flashcode@flashtux.org> Sat, 27 Jun 2003 12:00:00 +0200

1
debian/compat vendored Normal file
View File

@ -0,0 +1 @@
4

14
debian/control vendored Normal file
View File

@ -0,0 +1,14 @@
Source: weechat
Section: net
Priority: optional
Maintainer: FlashCode <flashcode@flashtux.org>
Build-Depends: debhelper (>> 4.0.0)
Standards-Version: 3.5.8
Package: weechat
Architecture: any
Depends: ${shlibs:Depends}
Description: Fast, light and extensible IRC client
WeeChat (Wee Enhanced Environment for Chat) is a fast and light IRC client
for many operating systems. Everything can be done with a keyboard.
It is customizable and extensible with scripts.

17
debian/copyright vendored Normal file
View File

@ -0,0 +1,17 @@
This package was debianized by FlashCode <flashcode@flashtux.org> on
Sat, 27 Sep 2003 10:00:00 +0200.
It was downloaded from http://weechat.flashtux.org/download
Upstream Author(s): FlashCode <flashcode@flashtux.org>
Copyright:
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.
On Debian systems, the complete text of the GNU General Public
License, Version 2 can be found in the file
/usr/share/common-licenses/GPL

1
debian/dirs vendored Normal file
View File

@ -0,0 +1 @@
usr/bin

9
debian/docs vendored Normal file
View File

@ -0,0 +1,9 @@
AUTHORS
BUGS
ChangeLog
COPYING
FAQ
INSTALL
NEWS
README
TODO

1
debian/files vendored Normal file
View File

@ -0,0 +1 @@
weechat_0.0.1-1_i386.deb net optional

97
debian/rules vendored Executable file
View File

@ -0,0 +1,97 @@
#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
CFLAGS = -Wall -g
ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
CFLAGS += -O0
else
CFLAGS += -O2
endif
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
INSTALL_PROGRAM += -s
endif
configure: configure-stamp
configure-stamp:
dh_testdir
# Add here commands to configure the package.
touch configure-stamp
build: build-stamp
build-stamp: configure-stamp
dh_testdir
# Add here commands to compile the package.
$(MAKE)
#/usr/bin/docbook-to-man debian/weechat.sgml > weechat.1
touch build-stamp
clean:
dh_testdir
dh_testroot
rm -f build-stamp configure-stamp
# Add here commands to clean up after the build process.
-$(MAKE) clean
dh_clean
install: build
dh_testdir
dh_testroot
dh_clean -k
dh_installdirs
# Add here commands to install the package into debian/weechat.
$(MAKE) install DESTDIR=$(CURDIR)/debian/weechat
# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.
# Build architecture-dependent files here.
binary-arch: build install
dh_testdir
dh_testroot
dh_installchangelogs
dh_installdocs
dh_installexamples
# dh_install
# dh_installmenu
# dh_installdebconf
# dh_installlogrotate
# dh_installemacsen
# dh_installpam
# dh_installmime
# dh_installinit
# dh_installcron
# dh_installinfo
dh_installman weechat.1
dh_link
dh_strip
dh_compress
dh_fixperms
# dh_perl
# dh_python
# dh_makeshlibs
dh_installdeb
dh_shlibdeps
dh_gencontrol
dh_md5sums
dh_builddeb
binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install configure

1
debian/weechat.substvars vendored Normal file
View File

@ -0,0 +1 @@
shlibs:Depends=libc6 (>= 2.3.2-1), libncurses5 (>= 5.3.20030510-1)

91
src/Makefile Normal file
View File

@ -0,0 +1,91 @@
# Copyright (c) 2003 FlashCode <flashcode@flashtux.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
CC=gcc
OPTIONS=-Wall -W -pipe -O2
OUTPUT=weechat
OBJS=weechat.o config.o command.o completion.o history.o
OBJS_IRC=irc/irc.a
OBJS_GUI=gui/gui.a
# WeeChat with Curses interface
ifeq ($(GUI), curses)
LIBS_CURSES=-lcurses
DEFINES=WEE_CURSES
curses: $(OBJS) $(OBJS_IRC) $(OBJS_GUI)
$(CC) $(OPTIONS) $(OBJS) $(OBJS_IRC) $(OBJS_GUI) -o $(OUTPUT) $(LIBS_CURSES)
endif
# WeeChat with Gtk+ interface
ifeq ($(GUI), gtk)
OBJS_GTK=gui-gtk.o
LIBS_GTK=
DEFINES=WEE_GTK
gtk: $(OBJS) $(OBJS_IRC) $(OBJS_GUI)
$(CC) $(OPTIONS) $(OBJS) $(OBJS_IRC) $(OBJS_GUI) -o $(OUTPUT) $(LIBS_GTK)
endif
# WeeChat with Qt interface
ifeq ($(GUI), qt)
OBJS_QT=gui-qt.o
LIBS_QT=
DEFINES=WEE_QT
qt: $(OBJS) $(OBJS_IRC) $(OBJS_GUI)
$(CC) $(OPTIONS) $(OBJS) $(OBJS_IRC) $(OBJS_GUI) -o $(OUTPUT) $(LIBS_QT)
endif
# WeeChat with Text interface
ifeq ($(GUI), text)
OBJS_TEXT=gui-text.o
LIBS_TEXT=
DEFINES=WEE_TEXT
text: $(OBJS) $(OBJS_IRC) $(OBJS_GUI)
$(CC) $(OPTIONS) $(OBJS) $(OBJS_IRC) $(OBJS_GUI) -o $(OUTPUT) $(LIBS_TEXT)
endif
all:
make curses GUI=curses
$(OBJS):
$(CC) $(OPTIONS) -o $@ -c $< $(INCLUDES) -D$(DEFINES)
irc/irc.a:
cd irc && make
gui/gui.a:
cd gui && make $(GUI) GUI=$(GUI)
clean:
rm -f *.o *.a *~ core $(OUTPUT)
cd irc && make clean
cd gui && make clean
command.o: command.c weechat.h command.h irc/irc.h gui/gui.h completion.h \
history.h config.h
completion.o: completion.c weechat.h completion.h irc/irc.h gui/gui.h \
history.h command.h
config.o: config.c weechat.h config.h irc/irc.h gui/gui.h completion.h \
history.h
history.o: history.c weechat.h history.h gui/gui.h completion.h
weechat.o: weechat.c weechat.h config.h command.h irc/irc.h gui/gui.h \
completion.h history.h

670
src/command.c Normal file
View File

@ -0,0 +1,670 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* command.c: WeeChat internal commands */
#include <stdlib.h>
#include <string.h>
#include "weechat.h"
#include "command.h"
#include "irc/irc.h"
#include "config.h"
#include "gui/gui.h"
/* WeeChat internal commands */
t_weechat_command weechat_commands[] =
{ { "alias", N_("create an alias for a command"),
N_("[alias_name [command [arguments]]"),
N_("alias_name: name of alias\ncommand: command name (" WEECHAT_NAME
" or IRC command)\n" "arguments: arguments for command"),
0, MAX_ARGS, weechat_cmd_alias, NULL },
{ "clear", N_("clear window(s)"),
N_("[-all]"),
N_("-all: clear all windows"),
0, 1, weechat_cmd_clear, NULL },
{ "help", N_("display help about commands"),
N_("[command]"), N_("command: name of a " WEECHAT_NAME " or IRC command"),
0, 1, weechat_cmd_help, NULL },
{ "set", N_("set config parameters"),
N_("[option [value]]"), N_("option: name of an option\nvalue: value for option"),
0, 2, weechat_cmd_set, NULL },
{ "unalias", N_("remove an alias"),
N_("alias_name"), N_("alias_name: name of alias to remove"),
1, 1, weechat_cmd_unalias, NULL },
{ NULL, NULL, NULL, NULL, 0, 0, NULL, NULL }
};
t_index_command *index_commands;
t_index_command *last_index_command;
/*
* index_find_pos: find position for a command index (for sorting index)
*/
t_index_command *
index_command_find_pos (char *command)
{
t_index_command *ptr_index;
for (ptr_index = index_commands; ptr_index; ptr_index = ptr_index->next_index)
{
if (strcasecmp (command, ptr_index->command_name) < 0)
return ptr_index;
}
return NULL;
}
/*
* index_command_insert_sorted: insert index into sorted list
*/
void
index_command_insert_sorted (t_index_command *index)
{
t_index_command *pos_index;
pos_index = index_command_find_pos (index->command_name);
if (index_commands)
{
if (pos_index)
{
/* insert index into the list (before index found) */
index->prev_index = pos_index->prev_index;
index->next_index = pos_index;
if (pos_index->prev_index)
pos_index->prev_index->next_index = index;
else
index_commands = index;
pos_index->prev_index = index;
}
else
{
/* add index to the end */
index->prev_index = last_index_command;
index->next_index = NULL;
last_index_command->next_index = index;
last_index_command = index;
}
}
else
{
index->prev_index = NULL;
index->next_index = NULL;
index_commands = index;
last_index_command = index;
}
return;
}
/*
* index_command_build: build an index of commands (internal, irc and alias)
* This list will be sorted, and used for completion
*/
void
index_command_build ()
{
int i;
t_index_command *new_index;
index_commands = NULL;
last_index_command = NULL;
i = 0;
while (weechat_commands[i].command_name)
{
if ((new_index = ((t_index_command *) malloc (sizeof (t_index_command)))))
{
new_index->command_name = strdup (weechat_commands[i].command_name);
index_command_insert_sorted (new_index);
}
i++;
}
i = 0;
while (irc_commands[i].command_name)
{
if (irc_commands[i].cmd_function_args || irc_commands[i].cmd_function_1arg)
{
if ((new_index = ((t_index_command *) malloc (sizeof (t_index_command)))))
{
new_index->command_name = strdup (irc_commands[i].command_name);
index_command_insert_sorted (new_index);
}
}
i++;
}
}
/*
* explode_string: explode a string according to separators
*/
char **
explode_string (char *string, char *separators, int num_items_max,
int *num_items)
{
int i, n_items;
char **array;
char *ptr, *ptr1, *ptr2;
if (num_items != NULL)
*num_items = 0;
n_items = num_items_max;
if (string == NULL)
return NULL;
if (num_items_max == 0)
{
/* calculate number of items */
ptr = string;
i = 1;
while ((ptr = strpbrk (ptr, separators)))
{
while (strchr (separators, ptr[0]) != NULL)
ptr++;
i++;
}
n_items = i;
}
array =
(char **) malloc ((num_items_max ? n_items : n_items + 1) *
sizeof (char *));
ptr1 = string;
ptr2 = string;
for (i = 0; i < n_items; i++)
{
while (strchr (separators, ptr1[0]) != NULL)
ptr1++;
if (i == (n_items - 1) || (ptr2 = strpbrk (ptr1, separators)) == NULL)
if ((ptr2 = strchr (ptr1, '\r')) == NULL)
if ((ptr2 = strchr (ptr1, '\n')) == NULL)
ptr2 = strchr (ptr1, '\0');
if ((ptr1 == NULL) || (ptr2 == NULL))
{
array[i] = NULL;
}
else
{
if (ptr2 - ptr1 > 0)
{
array[i] =
(char *) malloc ((ptr2 - ptr1 + 1) * sizeof (char));
array[i] = strncpy (array[i], ptr1, ptr2 - ptr1);
array[i][ptr2 - ptr1] = '\0';
ptr1 = ++ptr2;
}
else
{
array[i] = NULL;
}
}
}
if (num_items_max == 0)
{
array[i] = NULL;
if (num_items != NULL)
*num_items = i;
}
else
{
if (num_items != NULL)
*num_items = num_items_max;
}
return array;
}
/*
* exec_weechat_command: executes a command (WeeChat internal or IRC)
* returns: 1 if command was executed succesfully
* 0 if error (command not executed)
*/
int
exec_weechat_command (t_irc_server *server, char *string)
{
int i, j, argc, return_code;
char *pos, *ptr_args, **argv;
if ((!string[0]) || (string[0] != '/'))
return 0;
/* look for end of command */
ptr_args = NULL;
pos = strchr (string, ' ');
if (pos)
{
pos[0] = '\0';
pos++;
while (pos[0] == ' ')
pos++;
ptr_args = pos;
if (!ptr_args[0])
ptr_args = NULL;
}
argv = explode_string (ptr_args, " ", 0, &argc);
for (i = 0; weechat_commands[i].command_name; i++)
{
if (strcasecmp (weechat_commands[i].command_name, string + 1) == 0)
{
if ((argc < weechat_commands[i].min_arg)
|| (argc > weechat_commands[i].max_arg))
{
if (weechat_commands[i].min_arg ==
weechat_commands[i].max_arg)
gui_printf (NULL,
_("%s wrong argument count for "
WEECHAT_NAME " command '%s' "
"(expected: %d arg%s)\n"),
WEECHAT_ERROR,
string + 1,
weechat_commands[i].max_arg,
(weechat_commands[i].max_arg >
1) ? "s" : "");
else
gui_printf (NULL,
_("%s wrong argument count for "
WEECHAT_NAME " command '%s' "
"(expected: between %d and %d arg%s)\n"),
WEECHAT_ERROR,
string + 1,
weechat_commands[i].min_arg,
weechat_commands[i].max_arg,
(weechat_commands[i].max_arg >
1) ? "s" : "");
}
else
{
if (weechat_commands[i].cmd_function_args != NULL)
return_code = (int) (weechat_commands[i].cmd_function_args)
(argc, argv);
else
return_code = (int) (weechat_commands[i].cmd_function_1arg)
(ptr_args);
if (return_code < 0)
gui_printf (NULL,
_("%s " WEECHAT_NAME " command \"%s\" failed\n"),
WEECHAT_ERROR, string + 1);
}
if (argv)
{
for (j = 0; argv[j]; j++)
free (argv[j]);
free (argv);
}
return 1;
}
}
for (i = 0; irc_commands[i].command_name; i++)
{
if (strcasecmp (irc_commands[i].command_name, string + 1) == 0)
{
if ((argc < irc_commands[i].min_arg)
|| (argc > irc_commands[i].max_arg))
{
if (irc_commands[i].min_arg == irc_commands[i].max_arg)
gui_printf
(NULL,
_("%s wrong argument count for IRC command '%s' "
"(expected: %d arg%s)\n"),
WEECHAT_ERROR,
string + 1,
irc_commands[i].max_arg,
(irc_commands[i].max_arg > 1) ? "s" : "");
else
gui_printf
(NULL,
_("%s wrong argument count for IRC command '%s' "
"(expected: between %d and %d arg%s)\n"),
WEECHAT_ERROR,
string + 1,
irc_commands[i].min_arg, irc_commands[i].max_arg,
(irc_commands[i].max_arg > 1) ? "s" : "");
}
else
{
if ((irc_commands[i].need_connection) &&
((!server) || (!server->is_connected)))
{
gui_printf (NULL,
_("%s command '%s' needs a server connection!\n"),
WEECHAT_ERROR, irc_commands[i].command_name);
return 0;
}
if (irc_commands[i].cmd_function_args != NULL)
return_code = (int) (irc_commands[i].cmd_function_args)
(server, argc, argv);
else
return_code = (int) (irc_commands[i].cmd_function_1arg)
(server, ptr_args);
if (return_code < 0)
gui_printf (NULL,
_("%s IRC command \"%s\" failed\n"),
WEECHAT_ERROR, string + 1);
}
if (argv)
{
for (j = 0; argv[j]; j++)
free (argv[j]);
free (argv);
}
return 1;
}
}
gui_printf (server->window,
_("%s unknown command '%s' (type /help for help)\n"),
WEECHAT_ERROR,
string + 1);
if (argv)
{
for (j = 0; argv[j]; j++)
free (argv[j]);
free (argv);
}
return 0;
}
/*
* user_command: interprets user command (if beginning with '/')
* any other text is sent to the server, if connected
*/
void
user_command (t_irc_server *server, char *command)
{
t_irc_nick *ptr_nick;
if ((!command) || (command[0] == '\r') || (command[0] == '\n'))
return;
if ((command[0] == '/') && (command[1] != '/'))
{
/* WeeChat internal command (or IRC command) */
exec_weechat_command (server, command);
}
else
{
if ((command[0] == '/') && (command[1] == '/'))
command++;
if (!WIN_IS_SERVER(gui_current_window))
{
server_sendf (server, "PRIVMSG %s :%s\r\n",
CHANNEL(gui_current_window)->name,
command);
if (WIN_IS_PRIVATE(gui_current_window))
{
gui_printf_color_type (CHANNEL(gui_current_window)->window,
MSG_TYPE_NICK,
COLOR_WIN_CHAT_DARK, "<");
gui_printf_color_type (CHANNEL(gui_current_window)->window,
MSG_TYPE_NICK,
COLOR_WIN_NICK_SELF,
"%s", server->nick);
gui_printf_color_type (CHANNEL(gui_current_window)->window,
MSG_TYPE_NICK,
COLOR_WIN_CHAT_DARK, "> ");
gui_printf_color_type (CHANNEL(gui_current_window)->window,
MSG_TYPE_MSG,
COLOR_WIN_CHAT, "%s\n", command);
}
else
{
ptr_nick = nick_search (CHANNEL(gui_current_window), server->nick);
if (ptr_nick)
{
irc_display_nick (CHANNEL(gui_current_window)->window, ptr_nick,
MSG_TYPE_NICK, 1, 1, 0);
gui_printf_color (CHANNEL(gui_current_window)->window,
COLOR_WIN_CHAT, "%s\n", command);
}
else
gui_printf (server->window,
_("%s cannot find nick for sending message\n"),
WEECHAT_ERROR);
}
}
else
gui_printf (server->window, _("This window is not a channel!\n"));
}
}
/*
* weechat_cmd_alias: display or create alias
*/
int
weechat_cmd_alias (int argc, char **argv)
{
if (argc == 0)
{
/* List all aliases */
}
argv = NULL;
gui_printf (NULL, _("(TODO) \"/alias\" command not developed!\n"));
return 0;
}
/*
* weechat_cmd_clear: display or create alias
*/
int
weechat_cmd_clear (int argc, char **argv)
{
if (argc == 1)
{
if (strcmp (argv[0], "-all") == 0)
gui_window_clear_all ();
else
{
gui_printf (NULL,
_("unknown parameter \"%s\" for /clear command\n"),
argv[0]);
return -1;
}
}
else
gui_window_clear (gui_current_window);
return 0;
}
/*
* weechat_cmd_help: display help
*/
int
weechat_cmd_help (int argc, char **argv)
{
int i;
if (argc == 0)
{
gui_printf (NULL,
_("> List of " WEECHAT_NAME " internal commands:\n"));
for (i = 0; weechat_commands[i].command_name; i++)
gui_printf (NULL, " %s - %s\n",
weechat_commands[i].command_name,
weechat_commands[i].command_description);
gui_printf (NULL, _("> List of IRC commands:\n"));
for (i = 0; irc_commands[i].command_name; i++)
if (irc_commands[i].cmd_function_args || irc_commands[i].cmd_function_1arg)
gui_printf (NULL, " %s - %s\n",
irc_commands[i].command_name,
irc_commands[i].command_description);
}
if (argc == 1)
{
for (i = 0; weechat_commands[i].command_name; i++)
{
if (strcasecmp (weechat_commands[i].command_name, argv[0]) == 0)
{
gui_printf
(NULL,
_("> Help on " WEECHAT_NAME " internal command '%s':\n"),
weechat_commands[i].command_name);
gui_printf (NULL,
_("Syntax: /%s %s\n"),
weechat_commands[i].command_name,
(weechat_commands[i].
arguments) ? weechat_commands[i].
arguments : "");
if (weechat_commands[i].arguments_description)
{
gui_printf (NULL, "%s\n",
weechat_commands[i].
arguments_description);
}
return 0;
}
}
for (i = 0; irc_commands[i].command_name; i++)
{
if (strcasecmp (irc_commands[i].command_name, argv[0]) == 0)
{
gui_printf (NULL,
_("> Help on IRC command '%s':\n"),
irc_commands[i].command_name);
gui_printf (NULL, _("Syntax: /%s %s\n"),
irc_commands[i].command_name,
(irc_commands[i].arguments) ?
irc_commands[i].arguments : "");
if (irc_commands[i].arguments_description)
{
gui_printf (NULL, "%s\n",
irc_commands[i].
arguments_description);
}
return 0;
}
}
gui_printf (NULL,
_("No help available, \"%s\" is an unknown command\n"),
argv[0]);
}
return 0;
}
/*
* weechat_cmd_set: set options
*/
int
weechat_cmd_set (int argc, char **argv)
{
int i, j, section_displayed;
char *color_name;
/* TODO: complete /set command */
for (i = 0; i < CONFIG_NUMBER_SECTIONS; i++)
{
section_displayed = 0;
if (i != CONFIG_SECTION_SERVER)
{
for (j = 0; weechat_options[i][j].option_name; j++)
{
if ((argc == 0) ||
((argc > 0)
&& (strstr (weechat_options[i][j].option_name, argv[0])
!= NULL)))
{
if (!section_displayed)
{
gui_printf (NULL, "[%s]\n",
config_sections[i].section_name);
section_displayed = 1;
}
switch (weechat_options[i][j].option_type)
{
case OPTION_TYPE_BOOLEAN:
gui_printf (NULL, " %s = %s\n",
weechat_options[i][j].option_name,
(*weechat_options[i][j].ptr_int) ?
"ON" : "OFF");
break;
case OPTION_TYPE_INT:
gui_printf (NULL,
" %s = %d\n",
weechat_options[i][j].option_name,
*weechat_options[i][j].ptr_int);
break;
case OPTION_TYPE_INT_WITH_STRING:
gui_printf (NULL,
" %s = %s\n",
weechat_options[i][j].option_name,
weechat_options[i][j].array_values[*weechat_options[i][j].ptr_int]);
break;
case OPTION_TYPE_COLOR:
color_name = gui_get_color_by_value (*weechat_options[i][j].ptr_int);
gui_printf (NULL,
" %s = %s\n",
weechat_options[i][j].option_name,
(color_name) ? color_name : _("(unknown)"));
break;
case OPTION_TYPE_STRING:
gui_printf (NULL, " %s = %s\n",
weechat_options[i][j].
option_name,
(*weechat_options[i][j].
ptr_string) ?
*weechat_options[i][j].
ptr_string : "");
break;
}
}
}
}
}
gui_printf (NULL, _("(TODO) \"/set\" command not developed!\n"));
return 0;
}
/*
* cmd_unalias: remove an alias
*/
int
weechat_cmd_unalias (int argc, char **argv)
{
if (argc != 1)
{
gui_printf
(NULL,
_("Wrong argument count for unalias function (expexted: 1 arg)\n"));
return -1;
}
argv = NULL;
gui_printf (NULL, _("(TODO) \"/unalias\" not developed!\n"));
return 0;
}

63
src/command.h Normal file
View File

@ -0,0 +1,63 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WEECHAT_COMMAND_H
#define __WEECHAT_COMMAND_H 1
#include "irc/irc.h"
#define MAX_ARGS 8192
typedef struct t_weechat_command t_weechat_command;
struct t_weechat_command
{
char *command_name;
char *command_description;
char *arguments;
char *arguments_description;
int min_arg, max_arg;
int (*cmd_function_args)(int, char **);
int (*cmd_function_1arg)(char *);
};
typedef struct t_index_command t_index_command;
struct t_index_command
{
char *command_name;
t_index_command *prev_index;
t_index_command *next_index;
};
extern t_index_command *index_commands;
extern void index_command_build ();
extern int exec_weechat_command (t_irc_server *, char *);
extern void user_command (t_irc_server *, char *);
extern int weechat_cmd_alias(int, char **);
extern int weechat_cmd_clear(int, char **);
extern int weechat_cmd_help (int, char **);
extern int weechat_cmd_set (int, char **);
extern int weechat_cmd_unalias (int, char **);
#endif /* command.h */

199
src/completion.c Normal file
View File

@ -0,0 +1,199 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* completion.c: completes words according to context (cmd/nick) */
#include <stdlib.h>
#include <string.h>
#include "weechat.h"
#include "completion.h"
#include "irc/irc.h"
#include "command.h"
/*
* completion_init: init completion
*/
void
completion_init (t_completion *completion)
{
completion->position = -1;
completion->base_word = NULL;
}
/*
* completion_command: complete a command
*/
void
completion_command (t_completion *completion)
{
int length, word_found_seen;
t_index_command *ptr_index;
length = strlen (completion->base_word) - 1;
word_found_seen = 0;
for (ptr_index = index_commands; ptr_index; ptr_index = ptr_index->next_index)
{
if (strncasecmp (ptr_index->command_name, completion->base_word + 1, length) == 0)
{
if ((!completion->word_found) || word_found_seen)
{
completion->word_found = ptr_index->command_name;
return;
}
}
if (completion->word_found &&
(strcasecmp (ptr_index->command_name, completion->word_found) == 0))
word_found_seen = 1;
}
if (completion->word_found)
{
completion->word_found = NULL;
completion_command (completion);
}
}
/*
* completion_nick: complete a nick
*/
void
completion_nick (t_completion *completion, t_irc_channel *channel)
{
int length, word_found_seen;
t_irc_nick *ptr_nick;
length = strlen (completion->base_word);
word_found_seen = 0;
for (ptr_nick = channel->nicks; ptr_nick; ptr_nick = ptr_nick->next_nick)
{
if (strncasecmp (ptr_nick->nick, completion->base_word, length) == 0)
{
if ((!completion->word_found) || word_found_seen)
{
completion->word_found = ptr_nick->nick;
return;
}
}
if (completion->word_found &&
(strcasecmp (ptr_nick->nick, completion->word_found) == 0))
word_found_seen = 1;
}
if (completion->word_found)
{
completion->word_found = NULL;
completion_nick (completion, channel);
}
}
/*
* completion_search: complete word according to context
*/
void
completion_search (t_completion *completion, void *channel,
char *buffer, int size, int pos)
{
int i, pos_start, pos_end;
char *old_word_found;
/* TODO: complete when no word is there with command according to context */
if (size == 0)
{
completion->word_found = NULL;
return;
}
/* if new complation => look for base word */
if (pos != completion->position)
{
completion->word_found = NULL;
if ((pos == size) || (buffer[pos-1] != ' '))
pos--;
if ((pos > 0) && (buffer[pos] == ' '))
return;
i = pos;
while ((i >= 0) && (buffer[i] != ' '))
i--;
pos_start = i + 1;
i = pos;
while ((i < size) && (buffer[i] != ' '))
i++;
pos_end = i - 1;
if (pos_start > pos_end)
return;
completion->base_word_pos = pos_start;
if (completion->base_word)
free (completion->base_word);
completion->base_word = (char *) malloc (pos_end - pos_start + 2);
for (i = pos_start; i <= pos_end; i++)
completion->base_word[i - pos_start] = buffer[i];
completion->base_word[pos_end - pos_start + 1] = '\0';
if (completion->base_word[0] == '/')
completion->position_replace = pos_start + 1;
else
completion->position_replace = pos_start;
}
/* completion */
old_word_found = completion->word_found;
if (completion->base_word[0] == '/')
{
completion_command (completion);
if (completion->word_found)
{
if (old_word_found)
completion->diff_size = strlen (completion->word_found) -
strlen (old_word_found);
else
completion->diff_size = strlen (completion->word_found) -
strlen (completion->base_word) + 1;
}
}
else
{
if (channel)
{
completion_nick (completion, (t_irc_channel *)channel);
if (completion->word_found)
{
if (old_word_found)
completion->diff_size = strlen (completion->word_found) -
strlen (old_word_found);
else
completion->diff_size = strlen (completion->word_found) -
strlen (completion->base_word);
}
}
}
}

41
src/completion.h Normal file
View File

@ -0,0 +1,41 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WEECHAT_COMPLETION_H
#define __WEECHAT_COMPLETION_H 1
typedef struct t_completion t_completion;
struct t_completion
{
char *base_word; /* word to complete (when Tab was pressed) */
int base_word_pos; /* beggining of base word */
int position; /* position where we shoud complete */
char *word_found; /* word found (to replace base word) */
int position_replace; /* position where word should be replaced */
int diff_size; /* size difference (< 0 = char(s) deleted) */
};
extern void completion_init (t_completion *);
extern void completion_search (t_completion *, void *, char *, int, int);
#endif /* completion.h */

1021
src/config.c Normal file

File diff suppressed because it is too large Load Diff

155
src/config.h Normal file
View File

@ -0,0 +1,155 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WEECHAT_CONFIG_H
#define __WEECHAT_CONFIG_H 1
#define WEECHAT_CONFIG_NAME "weechat.rc"
#define CONFIG_SECTION_NONE -1
#define CONFIG_SECTION_LOOK 0
#define CONFIG_SECTION_COLORS 1
#define CONFIG_SECTION_HISTORY 2
#define CONFIG_SECTION_LOG 3
#define CONFIG_SECTION_DCC 4
#define CONFIG_SECTION_PROXY 5
#define CONFIG_SECTION_SERVER 6
#define CONFIG_NUMBER_SECTIONS 7
#define OPTION_TYPE_BOOLEAN 1 /* values: on/off */
#define OPTION_TYPE_INT 2 /* values: from min to max */
#define OPTION_TYPE_INT_WITH_STRING 3 /* values: one from **array_values */
#define OPTION_TYPE_COLOR 4 /* values: a color name */
#define OPTION_TYPE_STRING 5 /* values: any string, may be empty */
#define BOOL_FALSE 0
#define BOOL_TRUE 1
#define CFG_LOOK_NICKLIST_LEFT 0
#define CFG_LOOK_NICKLIST_RIGHT 1
#define CFG_LOOK_NICKLIST_TOP 2
#define CFG_LOOK_NICKLIST_BOTTOM 3
typedef struct t_config_section t_config_section;
struct t_config_section
{
int section_number;
char *section_name;
};
typedef struct t_config_option t_config_option;
struct t_config_option
{
char *option_name;
char *short_description;
char *long_description;
int option_type;
int min, max;
int default_int;
char *default_string;
char **array_values;
int *ptr_int;
char **ptr_string;
int (*handler_change)(int *, char **);
};
extern int cfg_look_startup_logo;
extern int cfg_look_startup_version;
extern char *cfg_look_weechat_slogan;
extern int cfg_look_color_nicks;
extern int cfg_look_color_actions;
extern int cfg_look_remove_colors_from_msgs;
extern int cfg_look_nicklist;
extern int cfg_look_nicklist_position;
extern int cfg_look_nicklist_min_size;
extern int cfg_look_nicklist_max_size;
extern int cfg_look_nickmode;
extern int cfg_look_nickmode_empty;
extern char *cfg_look_no_nickname;
extern char *cfg_look_completor;
extern int cfg_col_title;
extern int cfg_col_title_bg;
extern int cfg_col_chat;
extern int cfg_col_chat_time;
extern int cfg_col_chat_time_sep;
extern int cfg_col_chat_prefix1;
extern int cfg_col_chat_prefix2;
extern int cfg_col_chat_nick;
extern int cfg_col_chat_host;
extern int cfg_col_chat_channel;
extern int cfg_col_chat_dark;
extern int cfg_col_chat_bg;
extern int cfg_col_status;
extern int cfg_col_status_active;
extern int cfg_col_status_data_msg;
extern int cfg_col_status_data_other;
extern int cfg_col_status_more;
extern int cfg_col_status_bg;
extern int cfg_col_input;
extern int cfg_col_input_channel;
extern int cfg_col_input_nick;
extern int cfg_col_input_bg;
extern int cfg_col_nick;
extern int cfg_col_nick_op;
extern int cfg_col_nick_halfop;
extern int cfg_col_nick_voice;
extern int cfg_col_nick_sep;
extern int cfg_col_nick_self;
extern int cfg_col_nick_private;
extern int cfg_col_nick_bg;
extern int cfg_history_max_lines;
extern int cfg_history_max_commands;
extern int cfg_log_auto_channels;
extern int cfg_log_auto_private;
extern char *cfg_log_path;
extern char *cfg_log_name;
extern char *cfg_log_timestamp;
extern char *cfg_log_start_string;
extern char *cfg_log_end_string;
extern int cfg_dcc_auto_accept_files;
extern int cfg_dcc_auto_accept_max_size;
extern int cfg_dcc_auto_accept_chats;
extern int cfg_dcc_timeout;
extern char *cfg_dcc_download_path;
extern char *cfg_dcc_upload_path;
extern int cfg_dcc_auto_rename;
extern int cfg_dcc_auto_resume;
extern int cfg_proxy_use;
extern char *cfg_proxy_address;
extern int cfg_proxy_port;
extern char *cfg_proxy_password;
extern t_config_section config_sections [CONFIG_NUMBER_SECTIONS];
extern t_config_option * weechat_options [CONFIG_NUMBER_SECTIONS];
extern int config_read ();
extern int config_create_default ();
extern void config_write ();
#endif /* config.h */

55
src/gui/Makefile Normal file
View File

@ -0,0 +1,55 @@
# Copyright (c) 2003 FlashCode <flashcode@flashtux.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# WeeChat with Curses interface
ifeq ($(GUI), curses)
curses: curses/gui.a
curses/gui.a:
cd curses && make
endif
# WeeChat with Gtk+ interface
ifeq ($(GUI), gtk)
gtk: gtk/gui.a
gtk/gui.a:
cd gtk && make
endif
# WeeChat with Qt interface
ifeq ($(GUI), qt)
qt: qt/gui.a
qt/gui.a:
cd qt && make
endif
# WeeChat with Text interface
ifeq ($(GUI), text)
text: text/gui.a
text/gui.a:
cd text && make
endif
all:
make curses GUI=curses
clean:
rm -f *.o *.a *~ core
cd curses && make clean
cd gtk && make clean
cd qt && make clean
cd text && make clean

38
src/gui/curses/Makefile Normal file
View File

@ -0,0 +1,38 @@
# Copyright (c) 2003 FlashCode <flashcode@flashtux.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
CC=gcc
OPTIONS=-Wall -W -pipe -O2
OUTPUT=../gui.a
OBJS=gui-display.o gui-input.o
DEFINES=WEE_CURSES
all: $(OBJS)
ar r $(OUTPUT) $(OBJS)
$(OBJS):
$(CC) $(OPTIONS) -o $@ -c $< $(INCLUDES) -D$(DEFINES)
clean:
rm -f *.o *.a *~ core
gui-display.o: gui-display.c ../../weechat.h ../gui.h ../../completion.h \
../../history.h ../../config.h ../../irc/irc.h ../../gui/gui.h
gui-input.o: gui-input.c ../../weechat.h ../gui.h ../../completion.h \
../../history.h ../../command.h ../../irc/irc.h ../../gui/gui.h

1730
src/gui/curses/gui-display.c Normal file

File diff suppressed because it is too large Load Diff

541
src/gui/curses/gui-input.c Normal file
View File

@ -0,0 +1,541 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* gui-input: user input functions for Curses GUI */
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include <time.h>
#include <sys/socket.h>
#include <curses.h>
#include "../../weechat.h"
#include "../gui.h"
#include "../../config.h"
#include "../../command.h"
#include "../../irc/irc.h"
/*
* gui_optimize_input_buffer_size: optimize input buffer size by adding
* or deleting data block (predefined size)
*/
void
gui_optimize_input_buffer_size (t_gui_window *window)
{
int optimal_size;
optimal_size = ((window->input_buffer_size / INPUT_BUFFER_BLOCK_SIZE) *
INPUT_BUFFER_BLOCK_SIZE) + INPUT_BUFFER_BLOCK_SIZE;
if (window->input_buffer_alloc != optimal_size)
{
window->input_buffer_alloc = optimal_size;
window->input_buffer = realloc (window->input_buffer, optimal_size);
}
}
/*
* gui_delete_previous_word: delete previous word
*/
void
gui_delete_previous_word ()
{
int i, j, num_char_deleted, num_char_end;
if (gui_current_window->input_buffer_pos > 0)
{
i = gui_current_window->input_buffer_pos - 1;
while ((i >= 0) &&
(gui_current_window->input_buffer[i] == ' '))
i--;
if (i >= 0)
{
while ((i >= 0) &&
(gui_current_window->input_buffer[i] != ' '))
i--;
if (i >= 0)
{
while ((i >= 0) &&
(gui_current_window->input_buffer[i] == ' '))
i--;
}
}
if (i >= 0)
i++;
i++;
num_char_deleted = gui_current_window->input_buffer_pos - i;
num_char_end = gui_current_window->input_buffer_size -
gui_current_window->input_buffer_pos;
for (j = 0; j < num_char_end; j++)
gui_current_window->input_buffer[i + j] =
gui_current_window->input_buffer[gui_current_window->input_buffer_pos + j];
gui_current_window->input_buffer_size -= num_char_deleted;
gui_current_window->input_buffer[gui_current_window->input_buffer_size] = '\0';
gui_current_window->input_buffer_pos = i;
gui_draw_window_input (gui_current_window);
gui_optimize_input_buffer_size (gui_current_window);
gui_current_window->completion.position = -1;
}
}
/*
* gui_move_previous_word: move to beginning of previous word
*/
void
gui_move_previous_word ()
{
int i;
if (gui_current_window->input_buffer_pos > 0)
{
i = gui_current_window->input_buffer_pos - 1;
while ((i >= 0) &&
(gui_current_window->input_buffer[i] == ' '))
i--;
if (i < 0)
gui_current_window->input_buffer_pos = 0;
else
{
while ((i >= 0) &&
(gui_current_window->input_buffer[i] != ' '))
i--;
gui_current_window->input_buffer_pos = i + 1;
}
gui_draw_window_input (gui_current_window);
}
}
/*
* gui_move_next_word: move to the end of next
*/
void
gui_move_next_word ()
{
int i;
if (gui_current_window->input_buffer_pos <
gui_current_window->input_buffer_size + 1)
{
i = gui_current_window->input_buffer_pos;
while ((i <= gui_current_window->input_buffer_size) &&
(gui_current_window->input_buffer[i] == ' '))
i++;
if (i > gui_current_window->input_buffer_size)
gui_current_window->input_buffer_pos = i - 1;
else
{
while ((i <= gui_current_window->input_buffer_size) &&
(gui_current_window->input_buffer[i] != ' '))
i++;
if (i > gui_current_window->input_buffer_size)
gui_current_window->input_buffer_pos =
gui_current_window->input_buffer_size;
else
gui_current_window->input_buffer_pos = i;
}
gui_draw_window_input (gui_current_window);
}
}
/*
* gui_buffer_insert_string: insert a string into the input buffer
*/
void
gui_buffer_insert_string (char *string, int pos)
{
int i, start, end, length;
length = strlen (string);
/* increase buffer size */
gui_current_window->input_buffer_size += length;
gui_optimize_input_buffer_size (gui_current_window);
gui_current_window->input_buffer[gui_current_window->input_buffer_size] = '\0';
/* move end of string to the right */
start = pos + length;
end = gui_current_window->input_buffer_size - 1;
for (i = end; i >= start; i--)
gui_current_window->input_buffer[i] =
gui_current_window->input_buffer[i - length];
/* insert new string */
strncpy (gui_current_window->input_buffer + pos, string, length);
}
/*
* gui_read_keyb: read keyboard line
*/
void
gui_read_keyb ()
{
int key, i;
t_gui_window *ptr_window;
char new_char[2];
key = getch ();
if (key != ERR)
{
switch (key)
{
/* resize event: do nothing */
case KEY_RESIZE:
gui_redraw_window (gui_current_window);
break;
case KEY_F(6):
gui_switch_to_previous_window ();
break;
/* next window */
case KEY_F(7):
gui_switch_to_next_window ();
break;
/* cursor up */
case KEY_UP:
if (gui_current_window->ptr_history)
{
gui_current_window->ptr_history =
gui_current_window->ptr_history->next_history;
if (!gui_current_window->ptr_history)
gui_current_window->ptr_history =
gui_current_window->history;
}
else
gui_current_window->ptr_history =
gui_current_window->history;
if (gui_current_window->ptr_history)
{
gui_current_window->input_buffer_size =
strlen (gui_current_window->ptr_history->text);
gui_optimize_input_buffer_size (gui_current_window);
gui_current_window->input_buffer_pos =
gui_current_window->input_buffer_size;
strcpy (gui_current_window->input_buffer,
gui_current_window->ptr_history->text);
gui_draw_window_input (gui_current_window);
}
break;
/* cursor down */
case KEY_DOWN:
if (gui_current_window->ptr_history)
{
gui_current_window->ptr_history =
gui_current_window->ptr_history->prev_history;
if (gui_current_window->ptr_history)
gui_current_window->input_buffer_size =
strlen (gui_current_window->ptr_history->text);
else
gui_current_window->input_buffer_size = 0;
gui_optimize_input_buffer_size (gui_current_window);
gui_current_window->input_buffer_pos =
gui_current_window->input_buffer_size;
if (gui_current_window->ptr_history)
strcpy (gui_current_window->input_buffer,
gui_current_window->ptr_history->text);
gui_draw_window_input (gui_current_window);
}
break;
/* cursor left */
case KEY_LEFT:
if (gui_current_window->input_buffer_pos > 0)
{
gui_current_window->input_buffer_pos--;
gui_draw_window_input (gui_current_window);
}
break;
/* cursor right */
case KEY_RIGHT:
if (gui_current_window->input_buffer_pos <
gui_current_window->input_buffer_size)
{
gui_current_window->input_buffer_pos++;
gui_draw_window_input (gui_current_window);
}
break;
/* home key */
case KEY_HOME:
if (gui_current_window->input_buffer_pos > 0)
{
gui_current_window->input_buffer_pos = 0;
gui_draw_window_input (gui_current_window);
}
break;
/* end key */
case KEY_END:
if (gui_current_window->input_buffer_pos <
gui_current_window->input_buffer_size)
{
gui_current_window->input_buffer_pos =
gui_current_window->input_buffer_size;
gui_draw_window_input (gui_current_window);
}
break;
/* page up */
case KEY_PPAGE:
gui_move_page_up ();
break;
/* page down */
case KEY_NPAGE:
gui_move_page_down ();
break;
/* erase before cursor and move cursor to the left */
case 127:
case KEY_BACKSPACE:
if (gui_current_window->input_buffer_pos > 0)
{
i = gui_current_window->input_buffer_pos-1;
while (gui_current_window->input_buffer[i])
{
gui_current_window->input_buffer[i] =
gui_current_window->input_buffer[i+1];
i++;
}
gui_current_window->input_buffer_size--;
gui_current_window->input_buffer_pos--;
gui_current_window->input_buffer[gui_current_window->input_buffer_size] = '\0';
gui_draw_window_input (gui_current_window);
gui_optimize_input_buffer_size (gui_current_window);
gui_current_window->completion.position = -1;
}
break;
/* Control + Backspace */
case 0x08:
gui_delete_previous_word ();
break;
/* erase char under cursor */
case KEY_DC:
if (gui_current_window->input_buffer_pos <
gui_current_window->input_buffer_size)
{
i = gui_current_window->input_buffer_pos;
while (gui_current_window->input_buffer[i])
{
gui_current_window->input_buffer[i] =
gui_current_window->input_buffer[i+1];
i++;
}
gui_current_window->input_buffer_size--;
gui_current_window->input_buffer[gui_current_window->input_buffer_size] = '\0';
gui_draw_window_input (gui_current_window);
gui_optimize_input_buffer_size (gui_current_window);
gui_current_window->completion.position = -1;
}
break;
/* Tab : completion */
case '\t':
completion_search (&(gui_current_window->completion),
CHANNEL(gui_current_window),
gui_current_window->input_buffer,
gui_current_window->input_buffer_size,
gui_current_window->input_buffer_pos);
if (gui_current_window->completion.word_found)
{
// replace word with new completed word into input buffer
gui_current_window->input_buffer_size +=
gui_current_window->completion.diff_size;
gui_optimize_input_buffer_size (gui_current_window);
gui_current_window->input_buffer[gui_current_window->input_buffer_size] = '\0';
if (gui_current_window->completion.diff_size > 0)
{
for (i = gui_current_window->input_buffer_size - 1;
i >= gui_current_window->completion.position_replace +
(int)strlen (gui_current_window->completion.word_found); i--)
gui_current_window->input_buffer[i] =
gui_current_window->input_buffer[i -
gui_current_window->completion.diff_size];
}
else
{
for (i = gui_current_window->completion.position_replace +
strlen (gui_current_window->completion.word_found);
i < gui_current_window->input_buffer_size; i++)
gui_current_window->input_buffer[i] =
gui_current_window->input_buffer[i -
gui_current_window->completion.diff_size];
}
strncpy (gui_current_window->input_buffer + gui_current_window->completion.position_replace,
gui_current_window->completion.word_found,
strlen (gui_current_window->completion.word_found));
gui_current_window->input_buffer_pos =
gui_current_window->completion.position_replace +
strlen (gui_current_window->completion.word_found);
gui_current_window->completion.position =
gui_current_window->input_buffer_pos;
/* add space or completor to the end of completion, if needed */
if (gui_current_window->completion.base_word[0] == '/')
{
if (gui_current_window->input_buffer[gui_current_window->input_buffer_pos] != ' ')
gui_buffer_insert_string (" ",
gui_current_window->input_buffer_pos);
gui_current_window->completion.position++;
gui_current_window->input_buffer_pos++;
}
else
{
if (gui_current_window->completion.base_word_pos == 0)
{
if (strncmp (gui_current_window->input_buffer + gui_current_window->input_buffer_pos,
cfg_look_completor, strlen (cfg_look_completor)) != 0)
gui_buffer_insert_string (cfg_look_completor,
gui_current_window->input_buffer_pos);
gui_current_window->completion.position += strlen (cfg_look_completor);
gui_current_window->input_buffer_pos += strlen (cfg_look_completor);
if (gui_current_window->input_buffer[gui_current_window->input_buffer_pos] != ' ')
gui_buffer_insert_string (" ",
gui_current_window->input_buffer_pos);
gui_current_window->completion.position++;
gui_current_window->input_buffer_pos++;
}
}
gui_draw_window_input (gui_current_window);
}
break;
/* escape code (for control-key) */
case KEY_ESCAPE:
if ((key = getch()) != ERR)
{
switch (key)
{
case KEY_LEFT:
gui_switch_to_previous_window ();
break;
case KEY_RIGHT:
gui_switch_to_next_window ();
break;
case 79:
/* TODO: replace 79 by constant name! */
if (key == 79)
{
if ((key = getch()) != ERR)
{
switch (key)
{
/* Control + Right */
case 99:
gui_move_next_word ();
break;
/* Control + Left */
case 100:
gui_move_previous_word ();
break;
}
}
}
break;
}
}
break;
/* send command/message */
case '\n':
if (gui_current_window->input_buffer_size > 0)
{
gui_current_window->input_buffer[gui_current_window->input_buffer_size] = '\0';
history_add (gui_current_window, gui_current_window->input_buffer);
gui_current_window->input_buffer_size = 0;
gui_current_window->input_buffer_pos = 0;
gui_current_window->input_buffer_1st_display = 0;
gui_current_window->completion.position = -1;
gui_current_window->ptr_history = NULL;
ptr_window = gui_current_window;
user_command (SERVER(gui_current_window),
gui_current_window->input_buffer);
if (ptr_window == gui_current_window)
gui_draw_window_input (ptr_window);
if (ptr_window)
ptr_window->input_buffer[0] = '\0';
}
break;
/* other key => add to input buffer */
default:
/*gui_printf (gui_current_window,
"[Debug] key pressed = %d, as octal: %o\n", key, key);*/
new_char[0] = key;
new_char[1] = '\0';
gui_buffer_insert_string (new_char,
gui_current_window->input_buffer_pos);
gui_current_window->input_buffer_pos++;
gui_draw_window_input (gui_current_window);
gui_current_window->completion.position = -1;
break;
}
}
}
/*
* gui_main_loop: main loop for WeeChat with ncurses GUI
*/
void
gui_main_loop ()
{
fd_set read_fd;
static struct timeval timeout;
t_irc_server *ptr_server;
quit_weechat = 0;
while (!quit_weechat)
{
timeout.tv_sec = 0;
timeout.tv_usec = 10000;
FD_ZERO (&read_fd);
FD_SET (STDIN_FILENO, &read_fd);
for (ptr_server = irc_servers; ptr_server;
ptr_server = ptr_server->next_server)
{
if (ptr_server->sock4 >= 0)
FD_SET (ptr_server->sock4, &read_fd);
}
if (select (FD_SETSIZE, &read_fd, NULL, NULL, &timeout))
{
if (FD_ISSET (STDIN_FILENO, &read_fd))
{
gui_read_keyb ();
}
else
{
for (ptr_server = irc_servers; ptr_server;
ptr_server = ptr_server->next_server)
{
if ((ptr_server->sock4 >= 0) &&
(FD_ISSET (ptr_server->sock4, &read_fd)))
server_recv (ptr_server);
}
}
}
}
}

37
src/gui/gtk/Makefile Normal file
View File

@ -0,0 +1,37 @@
# Copyright (c) 2003 FlashCode <flashcode@flashtux.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
CC=gcc
OPTIONS=-Wall -W -pipe -O2
OUTPUT=../gui.a
OBJS=gui-display.o gui-input.o
DEFINES=WEE_GTK
all: $(OBJS)
ar r $(OUTPUT) $(OBJS)
$(OBJS):
$(CC) $(OPTIONS) -o $@ -c $< $(INCLUDES) -D$(DEFINES)
clean:
rm -f *.o *.a *~ core
gui-display.o: gui-display.c ../../weechat.h ../gui.h ../../config.h \
../../irc/irc.h ../../gui/gui.h
gui-input.o: gui-input.c ../../weechat.h ../gui.h

26
src/gui/gtk/gui-gtk.c Normal file
View File

@ -0,0 +1,26 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* gui-gtk.c: Gtk+ GUI for WeeChat */
/* ***** Gtk+ GUI for WeeChat, NOT developed! ***** */

26
src/gui/gtk/gui-gtk.h Normal file
View File

@ -0,0 +1,26 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WEECHAT_GUI_GTK_H
#define __WEECHAT_GUI_GTK_H 1
#endif /* gui-gtk.h */

229
src/gui/gui.h Normal file
View File

@ -0,0 +1,229 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WEECHAT_GUI_H
#define __WEECHAT_GUI_H 1
#ifdef WEE_CURSES
#include <curses.h>
#endif
#include "../completion.h"
#include "../history.h"
#ifdef WEE_CURSES
#define KEY_ESCAPE 27
#endif
#define INPUT_BUFFER_BLOCK_SIZE 256
#define NUM_COLORS 35
#define COLOR_WIN_TITLE 1
#define COLOR_WIN_CHAT 2
#define COLOR_WIN_CHAT_TIME 3
#define COLOR_WIN_CHAT_TIME_SEP 4
#define COLOR_WIN_CHAT_PREFIX1 5
#define COLOR_WIN_CHAT_PREFIX2 6
#define COLOR_WIN_CHAT_NICK 7
#define COLOR_WIN_CHAT_HOST 8
#define COLOR_WIN_CHAT_CHANNEL 9
#define COLOR_WIN_CHAT_DARK 10
#define COLOR_WIN_STATUS 11
#define COLOR_WIN_STATUS_ACTIVE 12
#define COLOR_WIN_STATUS_DATA_MSG 13
#define COLOR_WIN_STATUS_DATA_OTHER 14
#define COLOR_WIN_STATUS_MORE 15
#define COLOR_WIN_INPUT 16
#define COLOR_WIN_INPUT_CHANNEL 17
#define COLOR_WIN_INPUT_NICK 18
#define COLOR_WIN_NICK 19
#define COLOR_WIN_NICK_OP 20
#define COLOR_WIN_NICK_HALFOP 21
#define COLOR_WIN_NICK_VOICE 22
#define COLOR_WIN_NICK_SEP 23
#define COLOR_WIN_NICK_SELF 24
#define COLOR_WIN_NICK_PRIVATE 25
#define COLOR_WIN_NICK_FIRST 26
#define COLOR_WIN_NICK_LAST 35
#define COLOR_WIN_NICK_NUMBER (COLOR_WIN_NICK_LAST - COLOR_WIN_NICK_FIRST + 1)
#define SERVER(window) ((t_irc_server *)(window->server))
#define CHANNEL(window) ((t_irc_channel *)(window->channel))
#define WIN_IS_SERVER(window) (SERVER(window) && !CHANNEL(window))
#define WIN_IS_CHANNEL(window) (CHANNEL(window) && (CHANNEL(window)->type == CHAT_CHANNEL))
#define WIN_IS_PRIVATE(window) (CHANNEL(window) && (CHANNEL(window)->type == CHAT_PRIVATE))
#define MSG_TYPE_TIME 0
#define MSG_TYPE_NICK 1
#define MSG_TYPE_INFO 2
#define MSG_TYPE_MSG 3
#define gui_printf_color(window, color, fmt, argz...) \
gui_printf_color_type(window, MSG_TYPE_INFO, color, fmt, ##argz)
#define gui_printf(window, fmt, argz...) \
gui_printf_color_type(window, MSG_TYPE_INFO, -1, fmt, ##argz)
typedef struct t_gui_message t_gui_message;
struct t_gui_message
{
int type; /* type of message (time, nick, other) */
int color; /* color of message */
char *message; /* message content */
t_gui_message *prev_message; /* link to previous message for line */
t_gui_message *next_message; /* link to next message for line */
};
typedef struct t_gui_line t_gui_line;
struct t_gui_line
{
int length; /* length of the line (in char) */
int length_align; /* alignment length (time or time/nick) */
int line_with_message; /* line contains a message from a user? */
t_gui_message *messages; /* messages for the line */
t_gui_message *last_message; /* last message of the line */
t_gui_line *prev_line; /* link to previous line */
t_gui_line *next_line; /* link to next line */
};
typedef struct t_gui_color t_gui_color;
struct t_gui_color
{
char *name;
int color;
};
typedef struct t_gui_window t_gui_window;
struct t_gui_window
{
/* server/channel */
void *server; /* window's server */
void *channel; /* window's channel */
/* global position & size */
int win_x, win_y; /* position of window */
int win_width, win_height; /* window geometry */
/* chat window settings */
int win_chat_x, win_chat_y; /* chat window position */
int win_chat_width; /* width of chat window */
int win_chat_height; /* height of chat window */
int win_chat_cursor_x; /* position of cursor in chat window */
int win_chat_cursor_y; /* position of cursor in chat window */
/* nicklist window settings */
int win_nick_x, win_nick_y; /* chat window position */
int win_nick_width; /* width of chat window */
int win_nick_height; /* height of chat window */
/* windows */
#ifdef WEE_CURSES
WINDOW *win_title; /* title window */
WINDOW *win_chat; /* chat window (exemple: channel) */
WINDOW *win_nick; /* nick window */
WINDOW *win_status; /* status window */
WINDOW *win_input; /* input window */
#endif
#ifdef WEE_GTK
/* TODO: declare Gtk+ window */
#endif
#ifdef WEE_QT
/* TODO: declare Qt window */
#endif
/* chat content (lines, line is composed by many messages) */
t_gui_line *lines; /* lines of chat window */
t_gui_line *last_line; /* last line of chat window */
int first_line_displayed; /* = 1 if first line is displayed */
int sub_lines; /* if > 0 then do not display until end */
int line_complete; /* current line complete ? (\n ending) */
int unread_data; /* highlight windows with unread data */
/* inupt buffer */
char *input_buffer; /* input buffer */
int input_buffer_alloc; /* input buffer: allocated size in mem */
int input_buffer_size; /* buffer size (user input length) */
int input_buffer_pos; /* position into buffer */
int input_buffer_1st_display; /* first char displayed on screen */
/* completion */
t_completion completion; /* for cmds/nicks completion */
/* history */
t_history *history; /* commands history */
t_history *ptr_history; /* current command in history */
/* link to next window */
t_gui_window *prev_window; /* link to previous window */
t_gui_window *next_window; /* link to next window */
};
/* variables */
extern int gui_ready;
extern t_gui_window *gui_windows;
extern t_gui_window *gui_current_window;
/* prototypes */
extern int gui_assign_color (int *, char *);
extern int gui_get_color_by_name (char *);
extern char *gui_get_color_by_value (int);
extern void gui_draw_window_title (t_gui_window *);
extern void gui_redraw_window_title (t_gui_window *);
extern void gui_draw_window_chat (t_gui_window *);
extern void gui_redraw_window_chat (t_gui_window *);
extern void gui_draw_window_nick (t_gui_window *);
extern void gui_redraw_window_nick (t_gui_window *);
extern void gui_draw_window_status (t_gui_window *);
extern void gui_redraw_window_status (t_gui_window *);
extern void gui_draw_window_input (t_gui_window *);
extern void gui_redraw_window_input (t_gui_window *);
extern void gui_redraw_window (t_gui_window *);
extern void gui_window_clear (t_gui_window *);
extern void gui_window_clear_all ();
extern void gui_switch_to_window (t_gui_window *);
extern void gui_switch_to_previous_window ();
extern void gui_switch_to_next_window ();
extern void gui_move_page_up ();
extern void gui_move_page_down ();
extern void gui_init ();
/* TODO: add coordinates and size */
extern t_gui_window *gui_window_new (void *, void * /*int, int, int, int*/);
extern void gui_window_free (t_gui_window *);
extern void gui_end ();
extern void gui_printf_color_type (t_gui_window *, int, int, char *, ...);
extern void gui_display_nick (t_gui_window *, void *, int, int, int, int);
extern void gui_main_loop ();
#endif /* gui.h */

37
src/gui/qt/Makefile Normal file
View File

@ -0,0 +1,37 @@
# Copyright (c) 2003 FlashCode <flashcode@flashtux.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
CC=gcc
OPTIONS=-Wall -W -pipe -O2
OUTPUT=../gui.a
OBJS=gui-display.o gui-input.o
DEFINES=WEE_QT
all: $(OBJS)
ar r $(OUTPUT) $(OBJS)
$(OBJS):
$(CC) $(OPTIONS) -o $@ -c $< $(INCLUDES) -D$(DEFINES)
clean:
rm -f *.o *.a *~ core
gui-display.o: gui-display.c ../../weechat.h ../gui.h ../../config.h \
../../irc/irc.h ../../gui/gui.h
gui-input.o: gui-input.c ../../weechat.h ../gui.h

26
src/gui/qt/gui-qt.c Normal file
View File

@ -0,0 +1,26 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* gui-qt.c: Qt GUI for WeeChat */
/* ***** Qt GUI for WeeChat, NOT developed! ***** */

26
src/gui/qt/gui-qt.h Normal file
View File

@ -0,0 +1,26 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WEECHAT_GUI_QT_H
#define __WEECHAT_GUI_QT_H 1
#endif /* gui-qt.h */

37
src/gui/text/Makefile Normal file
View File

@ -0,0 +1,37 @@
# Copyright (c) 2003 FlashCode <flashcode@flashtux.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
CC=gcc
OPTIONS=-Wall -W -pipe -O2
OUTPUT=../gui.a
OBJS=gui-display.o gui-input.o
DEFINES=WEE_TEXT
all: $(OBJS)
ar r $(OUTPUT) $(OBJS)
$(OBJS):
$(CC) $(OPTIONS) -o $@ -c $< $(INCLUDES) -D$(DEFINES)
clean:
rm -f *.o *.a *~ core
gui-display.o: gui-display.c ../../weechat.h ../gui.h ../../config.h \
../../irc/irc.h ../../gui/gui.h
gui-input.o: gui-input.c ../../weechat.h ../gui.h

164
src/gui/text/gui-text.c Normal file
View File

@ -0,0 +1,164 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* gui-text.c: text GUI - display functions */
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/socket.h>
#include "weechat.h"
#include "gui-text.h"
#include "command.h"
#include "irc.h"
/*
* gui_init: init GUI
*/
void
gui_init ()
{
}
/*
* gui_init_irc_window: allocates a window for a channel or server
*/
void
gui_init_irc_window (t_irc_window * window)
{
/* no window in text GUI */
window->text = NULL;
window->window = NULL;
}
/*
* gui_free_irc_window: free a GUI window
*/
void
gui_free_irc_window (t_irc_window * window)
{
/* no window in text GUI */
}
/*
* gui_end: GUI end
*/
void
gui_end ()
{
}
/*
* read_keyb: read keyboard line
*/
void
read_keyb ()
{
int num_read;
static char buffer[4096];
static int pos_buffer = 0;
char buffer_tmp[1024];
int pos_buffer_tmp;
num_read = read (STDIN_FILENO, buffer_tmp, sizeof (buffer_tmp) - 1);
pos_buffer_tmp = 0;
while (pos_buffer_tmp < num_read)
{
switch (buffer_tmp[pos_buffer_tmp])
{
case '\r':
break;
case '\n':
buffer[pos_buffer] = '\0';
pos_buffer = 0;
user_command (buffer);
break;
default:
buffer[pos_buffer] = buffer_tmp[pos_buffer_tmp];
if (pos_buffer < (int) (sizeof (buffer) - 2))
pos_buffer++;
}
pos_buffer_tmp++;
}
}
/*
* gui_main_loop: main loop for WeeChat with text GUI
*/
void
gui_main_loop ()
{
struct timeval timeout;
fd_set read_fd;
t_irc_server *ptr_server;
quit_weechat = 0;
while (!quit_weechat)
{
timeout.tv_sec = 0;
timeout.tv_usec = 10000;
FD_ZERO (&read_fd);
FD_SET (STDIN_FILENO, &read_fd);
for (ptr_server = irc_servers; ptr_server;
ptr_server = ptr_server->next_server)
{
FD_SET (ptr_server->sock4, &read_fd);
}
select (FD_SETSIZE, &read_fd, NULL, NULL, &timeout);
if (FD_ISSET (STDIN_FILENO, &read_fd))
{
read_keyb ();
}
for (ptr_server = irc_servers; ptr_server;
ptr_server = ptr_server->next_server)
{
if (FD_ISSET (ptr_server->sock4, &read_fd))
recv_from_server (ptr_server);
}
}
}
/*
* gui_display_message: display a message on the screen
*/
void
gui_display_message (char *message)
{
printf ("%s\n", message);
}

26
src/gui/text/gui-text.h Normal file
View File

@ -0,0 +1,26 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WEECHAT_GUI_TEXT_H
#define __WEECHAT_GUI_TEXT_H 1
#endif /* gui-text.h */

66
src/history.c Normal file
View File

@ -0,0 +1,66 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* history.c: memorize and call again commands or text */
#include <stdlib.h>
#include <string.h>
#include "weechat.h"
#include "history.h"
#include "gui/gui.h"
t_history *history_general = NULL;
t_history *history_general_ptr = NULL;
/*
* history_add: add a text/command to history
*/
void
history_add (void *window, char *string)
{
t_history *new_history;
new_history = (t_history *)malloc (sizeof (t_history));
if (new_history)
{
new_history->text = strdup (string);
/* add history to general history */
if (history_general)
history_general->prev_history = new_history;
new_history->next_history = history_general;
new_history->prev_history = NULL;
history_general = new_history;
/* add history to local history */
if (((t_gui_window *)(window))->history)
((t_gui_window *)(window))->history->prev_history = new_history;
new_history->next_history = ((t_gui_window *)(window))->history;
new_history->prev_history = NULL;
((t_gui_window *)window)->history = new_history;
}
}

37
src/history.h Normal file
View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WEECHAT_HISTORY_H
#define __WEECHAT_HISTORY_H 1
typedef struct t_history t_history;
struct t_history
{
char *text; /* text or command (as entered by user) */
t_history *next_history; /* link to next text/command */
t_history *prev_history; /* link to previous text/command */
};
extern void history_add (void *, char *);
#endif /* history.h */

44
src/irc/Makefile Normal file
View File

@ -0,0 +1,44 @@
# Copyright (c) 2003 FlashCode <flashcode@flashtux.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
CC=gcc
OPTIONS=-Wall -W -pipe -O2
OUTPUT=irc.a
OBJS=irc-commands.o irc-display.o irc-server.o irc-channel.o irc-nick.o
DEFINES=WEE_CURSES
all: $(OBJS)
ar r $(OUTPUT) $(OBJS)
$(OBJS):
$(CC) $(OPTIONS) -o $@ -c $< $(INCLUDES) -D$(DEFINES)
clean:
rm -f *.o *.a *~ core
irc-channel.o: irc-channel.c ../weechat.h irc.h ../gui/gui.h \
../completion.h ../history.h
irc-commands.o: irc-commands.c ../weechat.h irc.h ../gui/gui.h \
../completion.h ../history.h ../command.h ../irc/irc.h ../config.h
irc-display.o: irc-display.c ../weechat.h irc.h ../gui/gui.h \
../completion.h ../history.h
irc-nick.o: irc-nick.c ../weechat.h irc.h ../gui/gui.h ../completion.h \
../history.h
irc-server.o: irc-server.c ../weechat.h irc.h ../gui/gui.h \
../completion.h ../history.h

153
src/irc/irc-channel.c Normal file
View File

@ -0,0 +1,153 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* irc-channel.c: manages a chat (channel or private chat) */
#include <stdlib.h>
#include <string.h>
#include "../weechat.h"
#include "irc.h"
t_irc_channel *current_channel = NULL;
/*
* channel_new: allocate a new channel for a server and add it to the server queue
*/
t_irc_channel *
channel_new (t_irc_server *server, int channel_type, char *channel_name)
{
t_irc_channel *new_channel;
#if DEBUG >= 1
log_printf ("joining channel %s\n", channel_name);
#endif
/* alloc memory for new channel */
if ((new_channel = (t_irc_channel *) malloc (sizeof (t_irc_channel))) == NULL)
{
fprintf (stderr, _("%s cannot allocate new channel"), WEECHAT_ERROR);
return NULL;
}
/* initialize new channel */
new_channel->type = channel_type;
new_channel->name = strdup (channel_name);
new_channel->topic = NULL;
new_channel->nicks = NULL;
new_channel->last_nick = NULL;
/* add new channel to queue */
new_channel->prev_channel = server->last_channel;
new_channel->next_channel = NULL;
if (server->channels)
server->last_channel->next_channel = new_channel;
else
server->channels = new_channel;
server->last_channel = new_channel;
gui_window_new (server, new_channel);
/* all is ok, return address of new channel */
return new_channel;
}
/*
* channel_free: free a channel and remove it from channels queue
*/
void
channel_free (t_irc_server *server, t_irc_channel *channel)
{
t_irc_channel *new_channels;
/* remove channel from queue */
if (server->last_channel == channel)
server->last_channel = channel->prev_channel;
if (channel->prev_channel)
{
(channel->prev_channel)->next_channel = channel->next_channel;
new_channels = server->channels;
}
else
new_channels = channel->next_channel;
if (channel->next_channel)
(channel->next_channel)->prev_channel = channel->prev_channel;
/* free data */
if (channel->name)
free (channel->name);
if (channel->topic)
free (channel->topic);
nick_free_all (channel);
free (channel);
server->channels = new_channels;
}
/*
* channel_free_all: free all allocated channels
*/
void
channel_free_all (t_irc_server *server)
{
/* remove all channels for the server */
while (server->channels)
channel_free (server, server->channels);
}
/*
* channel_search: returns pointer on a channel with name
*/
t_irc_channel *
channel_search (t_irc_server *server, char *channel_name)
{
t_irc_channel *ptr_channel;
for (ptr_channel = server->channels; ptr_channel;
ptr_channel = ptr_channel->next_channel)
{
if (strcasecmp (ptr_channel->name, channel_name) == 0)
return ptr_channel;
}
return NULL;
}
/*
* string_is_channel: returns 1 if string is channel
*/
int
string_is_channel (char *string)
{
char first_char[2];
first_char[0] = string[0];
first_char[1] = '\0';
return (strpbrk (first_char, CHANNEL_PREFIX)) ? 1 : 0;
}

3064
src/irc/irc-commands.c Normal file

File diff suppressed because it is too large Load Diff

127
src/irc/irc-display.c Normal file
View File

@ -0,0 +1,127 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* irc-display.c: display functions for IRC */
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include "../weechat.h"
#include "irc.h"
#include "../config.h"
#include "../gui/gui.h"
/*
* irc_display_prefix: display prefix for action or info message
* prefix must be 3 chars length
*/
void
irc_display_prefix (t_gui_window *window, char *prefix)
{
if (prefix[0] == prefix[2])
{
gui_printf_color (window, COLOR_WIN_CHAT_PREFIX1, "%c", prefix[0]);
gui_printf_color (window, COLOR_WIN_CHAT_PREFIX2, "%c", prefix[1]);
gui_printf_color (window, COLOR_WIN_CHAT_PREFIX1, "%c ", prefix[2]);
}
else
gui_printf_color (window, COLOR_WIN_CHAT_PREFIX1, "%s ", prefix);
}
/*
* irc_display_nick: display nick in chat window
*/
void
irc_display_nick (t_gui_window *window, t_irc_nick *nick, int message_type,
int display_around, int color_nick, int no_nickmode)
{
if (display_around)
gui_printf_color_type (window,
message_type, COLOR_WIN_CHAT_DARK, "<");
if (cfg_look_nickmode)
{
if (nick->is_op)
gui_printf_color_type (window,
message_type,
COLOR_WIN_NICK_OP, "@");
else
{
if (nick->is_halfop)
gui_printf_color_type (window,
message_type,
COLOR_WIN_NICK_HALFOP, "%%");
else
{
if (nick->has_voice)
gui_printf_color_type (window,
message_type,
COLOR_WIN_NICK_VOICE, "+");
else
if (cfg_look_nickmode_empty && !no_nickmode)
gui_printf_color_type (window,
message_type,
COLOR_WIN_CHAT, " ");
}
}
}
gui_printf_color_type (window,
message_type,
(color_nick) ?
((cfg_look_color_nicks) ?
nick->color : COLOR_WIN_CHAT) :
COLOR_WIN_CHAT,
"%s", nick->nick);
if (display_around)
gui_printf_color_type (window,
message_type, COLOR_WIN_CHAT_DARK, "> ");
}
/*
* irc_display_mode: display IRC message for mode change
*/
void
irc_display_mode (t_gui_window *window, char *channel_name, char set_flag,
char *symbol, char *nick_host, char *message, char *param)
{
irc_display_prefix (window, PREFIX_INFO);
gui_printf_color (window, COLOR_WIN_CHAT_DARK, "[");
gui_printf_color (window, COLOR_WIN_CHAT_CHANNEL, "%s", channel_name);
gui_printf_color (window, COLOR_WIN_CHAT, "/");
gui_printf_color (window, COLOR_WIN_CHAT_CHANNEL, "%c%s", set_flag, symbol);
gui_printf_color (window, COLOR_WIN_CHAT_DARK, "] ");
gui_printf_color (window, COLOR_WIN_CHAT_NICK, "%s", nick_host);
if (param)
{
gui_printf_color (window, COLOR_WIN_CHAT, " %s ", message);
gui_printf_color (window, COLOR_WIN_CHAT_NICK, "%s\n", param);
}
else
gui_printf_color (window, COLOR_WIN_CHAT, " %s\n", message);
}

357
src/irc/irc-nick.c Normal file
View File

@ -0,0 +1,357 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* irc-nick.c: manages nick list for channels */
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include "../weechat.h"
#include "irc.h"
/*
* nick_find_color: find a color for a nick (less used will be better!)
*/
int
nick_find_color (t_irc_channel *channel)
{
int i, color_less_used, min_used;
int count_used[COLOR_WIN_NICK_NUMBER];
t_irc_nick *ptr_nick;
/* initialize array for counting usage of color */
for (i = 0; i < COLOR_WIN_NICK_NUMBER; i++)
count_used[i] = 0;
/* summarize each color usage */
for (ptr_nick = channel->nicks; ptr_nick; ptr_nick = ptr_nick->next_nick)
count_used[ptr_nick->color - COLOR_WIN_NICK_FIRST]++;
/* look for color less used on channel */
color_less_used = -1;
min_used = INT_MAX;
for (i = 0; i < COLOR_WIN_NICK_NUMBER; i++)
{
if (count_used[i] < min_used)
{
color_less_used = i;
min_used = count_used[i];
}
}
return (color_less_used < 0) ?
COLOR_WIN_NICK_FIRST : COLOR_WIN_NICK_FIRST + color_less_used;
}
/*
* nick_compare: compare two nicks
* return: -1 is nick1 < nick2
* 0 if nick1 = nick2
* +1 if nick1 > nick2
* status sort: operator > voice > normal nick
*/
int
nick_compare (t_irc_nick *nick1, t_irc_nick *nick2)
{
int score1, score2, comp;
score1 = - ( (nick1->is_op * 3) + (nick1->is_halfop * 2) + nick1->has_voice );
score2 = - ( (nick2->is_op * 3) + (nick2->is_halfop * 2) + nick2->has_voice );
comp = strcasecmp(nick1->nick, nick2->nick);
if (comp > 0)
score1++;
else
if (comp < 0)
score2++;
/* nick1 > nick2 */
if (score1 > score2)
return 1;
/* nick1 < nick2 */
if (score1 < score2)
return -1;
/* nick1 == nick2 */
return 0;
}
/*
* nick_find_pos: find position for a nick (for sorting nick list)
*/
t_irc_nick *
nick_find_pos (t_irc_channel *channel, t_irc_nick *nick)
{
t_irc_nick *ptr_nick;
for (ptr_nick = channel->nicks; ptr_nick; ptr_nick = ptr_nick->next_nick)
{
if (nick_compare (nick, ptr_nick) < 0)
return ptr_nick;
}
return NULL;
}
/*
* nick_insert_sorted: insert nick into sorted list
*/
void
nick_insert_sorted (t_irc_channel *channel, t_irc_nick *nick)
{
t_irc_nick *pos_nick;
if (channel->nicks)
{
pos_nick = nick_find_pos (channel, nick);
if (pos_nick)
{
/* insert nick into the list (before nick found) */
nick->prev_nick = pos_nick->prev_nick;
nick->next_nick = pos_nick;
if (pos_nick->prev_nick)
pos_nick->prev_nick->next_nick = nick;
else
channel->nicks = nick;
pos_nick->prev_nick = nick;
}
else
{
/* add nick to the end */
nick->prev_nick = channel->last_nick;
nick->next_nick = NULL;
channel->last_nick->next_nick = nick;
channel->last_nick = nick;
}
}
else
{
nick->prev_nick = NULL;
nick->next_nick = NULL;
channel->nicks = nick;
channel->last_nick = nick;
}
}
/*
* nick_new: allocate a new nick for a channel and add it to the nick list
*/
t_irc_nick *
nick_new (t_irc_channel *channel, char *nick_name,
int is_op, int is_halfop, int has_voice)
{
t_irc_nick *new_nick;
/* nick already exists on this channel? */
if ((new_nick = nick_search (channel, nick_name)))
{
/* update nick */
new_nick->is_op = is_op;
new_nick->is_halfop = is_halfop;
new_nick->has_voice = has_voice;
return new_nick;
}
/* alloc memory for new nick */
if ((new_nick = (t_irc_nick *) malloc (sizeof (t_irc_nick))) == NULL)
{
gui_printf (channel->window,
_("%s cannot allocate new nick\n"), WEECHAT_ERROR);
return NULL;
}
/* initialize new nick */
new_nick->nick = strdup (nick_name);
new_nick->is_op = is_op;
new_nick->is_halfop = is_halfop;
new_nick->has_voice = has_voice;
if (strcasecmp (new_nick->nick, SERVER(channel->window)->nick) == 0)
new_nick->color = COLOR_WIN_NICK_SELF;
else
new_nick->color = nick_find_color (channel);
nick_insert_sorted (channel, new_nick);
/* all is ok, return address of new nick */
return new_nick;
}
/*
* nick_resort: resort nick in the list
*/
void
nick_resort (t_irc_channel *channel, t_irc_nick *nick)
{
/* temporarly remove nick from list */
if (nick == channel->nicks)
channel->nicks = nick->next_nick;
else
nick->prev_nick->next_nick = nick->next_nick;
if (nick->next_nick)
nick->next_nick->prev_nick = nick->prev_nick;
if (nick == channel->last_nick)
channel->last_nick = nick->prev_nick;
/* insert again nick into sorted list */
nick_insert_sorted (channel, nick);
}
/*
* nick_change: change nickname and move it if necessary (list is sorted)
*/
void
nick_change (t_irc_channel *channel, t_irc_nick *nick, char *new_nick)
{
/* change nickname */
if (nick->nick)
free (nick->nick);
nick->nick = strdup (new_nick);
/* insert again nick into sorted list */
nick_resort (channel, nick);
}
/*
* nick_free: free a nick and remove it from nicks queue
*/
void
nick_free (t_irc_channel *channel, t_irc_nick *nick)
{
t_irc_nick *new_nicks;
/* remove nick from queue */
if (channel->last_nick == nick)
channel->last_nick = nick->prev_nick;
if (nick->prev_nick)
{
(nick->prev_nick)->next_nick = nick->next_nick;
new_nicks = channel->nicks;
}
else
new_nicks = nick->next_nick;
if (nick->next_nick)
(nick->next_nick)->prev_nick = nick->prev_nick;
/* free data */
if (nick->nick)
free (nick->nick);
free (nick);
channel->nicks = new_nicks;
}
/*
* nick_free_all: free all allocated nicks for a channel
*/
void
nick_free_all (t_irc_channel *channel)
{
/* remove all nicks for the channel */
while (channel->nicks)
nick_free (channel, channel->nicks);
}
/*
* nick_search: returns pointer on a nick
*/
t_irc_nick *
nick_search (t_irc_channel *channel, char *nickname)
{
t_irc_nick *ptr_nick;
for (ptr_nick = channel->nicks; ptr_nick;
ptr_nick = ptr_nick->next_nick)
{
if (strcasecmp (ptr_nick->nick, nickname) == 0)
return ptr_nick;
}
return NULL;
}
/*
* nick_count: returns number of nicks (total, op, halfop, voice) on a channel
*/
void
nick_count (t_irc_channel *channel, int *total, int *count_op,
int *count_halfop, int *count_voice, int *count_normal)
{
t_irc_nick *ptr_nick;
(*total) = 0;
(*count_op) = 0;
(*count_halfop) = 0;
(*count_voice) = 0;
(*count_normal) = 0;
for (ptr_nick = channel->nicks; ptr_nick;
ptr_nick = ptr_nick->next_nick)
{
(*total)++;
if (ptr_nick->is_op)
(*count_op)++;
else
{
if (ptr_nick->is_halfop)
(*count_halfop)++;
else
{
if (ptr_nick->has_voice)
(*count_voice)++;
else
(*count_normal)++;
}
}
}
}
/*
* nick_get_max_length: returns longer nickname on a channel
*/
int
nick_get_max_length (t_irc_channel *channel)
{
int length, max_length;
t_irc_nick *ptr_nick;
max_length = 0;
for (ptr_nick = channel->nicks; ptr_nick;
ptr_nick = ptr_nick->next_nick)
{
length = strlen (ptr_nick->nick);
if (length > max_length)
max_length = length;
}
return max_length;
}

615
src/irc/irc-server.c Normal file
View File

@ -0,0 +1,615 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* irc-server.c: (dis)connection and communication with irc server */
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include "../weechat.h"
#include "irc.h"
#include "../gui/gui.h"
t_irc_server *irc_servers = NULL;
t_irc_server *last_irc_server = NULL;
t_irc_server *current_irc_server = NULL;
t_irc_message *recv_msgq, *msgq_last_msg;
/* buffer containing beginning of message if not ending with \r\n */
char *unterminated_message = NULL;
/*
* server_alloc: allocate a new server and add it to the servers queue
*/
t_irc_server *
server_alloc ()
{
t_irc_server *new_server;
#if DEBUG >= 1
log_printf ("allocating new server\n");
#endif
/* alloc memory for new server */
if ((new_server = (t_irc_server *) malloc (sizeof (t_irc_server))) == NULL)
{
fprintf (stderr, _("%s cannot allocate new server"), WEECHAT_ERROR);
return NULL;
}
/* initialize new server */
new_server->name = NULL;
new_server->address = NULL;
new_server->password = NULL;
new_server->nick1 = NULL;
new_server->nick2 = NULL;
new_server->nick3 = NULL;
new_server->username = NULL;
new_server->realname = NULL;
new_server->nick = NULL;
new_server->is_connected = 0;
new_server->sock4 = -1;
new_server->is_away = 0;
new_server->server_read = -1;
new_server->server_write = -1;
new_server->window = NULL;
new_server->channels = NULL;
new_server->last_channel = NULL;
/* add new server to queue */
new_server->prev_server = last_irc_server;
new_server->next_server = NULL;
if (irc_servers)
last_irc_server->next_server = new_server;
else
irc_servers = new_server;
last_irc_server = new_server;
/* all is ok, return address of new server */
return new_server;
}
/*
* server_create_window: create windows for a server
*/
void
server_create_window (t_irc_server *server)
{
if (!SERVER(gui_windows))
{
server->window = gui_windows;
SERVER(gui_windows) = server;
}
else
gui_window_new (server, NULL);
}
/*
* server_free: free a server and remove it from servers queue
*/
void
server_free (t_irc_server *server)
{
t_irc_server *new_irc_servers;
/* remove server from queue */
if (server->prev_server)
{
(server->prev_server)->next_server = server->next_server;
new_irc_servers = irc_servers;
}
else
new_irc_servers = server->next_server;
if (server->next_server)
(server->next_server)->prev_server = server->prev_server;
/* free data */
if (server->name)
free (server->name);
if (server->address)
free (server->address);
if (server->password)
free (server->password);
if (server->nick1)
free (server->nick1);
if (server->nick2)
free (server->nick2);
if (server->nick3)
free (server->nick3);
if (server->username)
free (server->username);
if (server->realname)
free (server->realname);
if (server->nick)
free (server->nick);
if (server->channels)
channel_free_all (server);
/* TODO: free weechat window (???) */
/* (...) */
free (server);
irc_servers = new_irc_servers;
}
/*
* server_free_all: free all allocated servers
*/
void
server_free_all ()
{
/* for each server in memory, remove it */
while (irc_servers)
server_free (irc_servers);
}
/*
* server_new: creates a new server, and initialize it
*/
t_irc_server *
server_new (char *name, char *address, int port, char *password,
char *nick1, char *nick2, char *nick3,
char *username, char *realname)
{
t_irc_server *new_server;
if (!name || !address || (port < 0) || !nick1 || !nick2 || !nick3
|| !username || !realname)
return NULL;
#if DEBUG >= 1
log_printf ("creating new server (name:%s, address:%s, port:%d, pwd:%s, "
"nick1:%s, nick2:%s, nick3:%s, username:%s, realname:%s)\n",
name, address, port, password, nick1, nick2, nick3,
username, realname);
#endif
if ((new_server = server_alloc ()))
{
new_server->name = strdup (name);
new_server->address = strdup (address);
new_server->port = port;
new_server->password = (password) ? strdup (password) : strdup ("");
new_server->nick1 = (nick1) ? strdup (nick1) : strdup ("weechat_user");
new_server->nick2 = (nick2) ? strdup (nick2) : strdup ("weechat2");
new_server->nick3 = (nick3) ? strdup (nick3) : strdup ("weechat3");
new_server->username =
(username) ? strdup (username) : strdup ("weechat");
new_server->realname =
(realname) ? strdup (realname) : strdup ("realname");
new_server->nick = strdup (new_server->nick1);
}
else
return NULL;
return new_server;
}
/*
* server_send: send data to irc server
*/
int
server_send (t_irc_server * server, char *buffer, int size_buf)
{
if (!server)
return -1;
return send (server->sock4, buffer, size_buf, 0);
}
/*
* server_sendf: send formatted data to irc server
*/
int
server_sendf (t_irc_server * server, char *fmt, ...)
{
va_list args;
static char buffer[1024];
int size_buf;
if (!server)
return -1;
va_start (args, fmt);
size_buf = vsnprintf (buffer, sizeof (buffer) - 1, fmt, args);
va_end (args);
if ((size_buf == 0) || (strcmp (buffer, "\r\n") == 0))
return 0;
buffer[sizeof (buffer) - 1] = '\0';
if ((size_buf < 0) || (size_buf > (int) (sizeof (buffer) - 1)))
size_buf = strlen (buffer);
buffer[size_buf - 2] = '\0';
#if DEBUG >= 2
gui_printf (server->window, "[DEBUG] Sending to server >>> %s\n", buffer);
#endif
buffer[size_buf - 2] = '\r';
return server_send (server, buffer, size_buf);
}
/*
* server_msgq_add_msg: add a message to received messages queue (at the end)
*/
void
server_msgq_add_msg (t_irc_server * server, char *msg)
{
t_irc_message *message;
message = (t_irc_message *) malloc (sizeof (t_irc_message));
message->server = server;
if (unterminated_message)
{
message->data = (char *) malloc (strlen (unterminated_message) +
strlen (msg) + 1);
strcpy (message->data, unterminated_message);
strcat (message->data, msg);
free (unterminated_message);
unterminated_message = NULL;
}
else
message->data = strdup (msg);
message->next_message = NULL;
if (msgq_last_msg)
{
msgq_last_msg->next_message = message;
msgq_last_msg = message;
}
else
{
recv_msgq = message;
msgq_last_msg = message;
}
}
/*
* server_msgq_add_buffer: explode received buffer, creating queued messages
*/
void
server_msgq_add_buffer (t_irc_server * server, char *buffer)
{
char *pos;
while (buffer[0])
{
pos = strstr (buffer, "\r\n");
if (pos)
{
pos[0] = '\0';
server_msgq_add_msg (server, buffer);
buffer = pos + 2;
}
else
{
pos = strchr (buffer, '\0');
if (pos)
{
unterminated_message =
(char *) realloc (unterminated_message,
strlen (buffer) + 1);
strcpy (unterminated_message, buffer);
return;
}
gui_printf (server->window,
_("%s unable to explode received buffer\n"),
WEECHAT_ERROR);
}
}
}
/*
* server_msgq_flush: flush message queue
*/
void
server_msgq_flush ()
{
t_irc_message *next;
/*char **argv;
int argc;*/
char *ptr_data, *pos, *pos2;
char *host, *command, *args;
/* TODO: optimize this function, parse only a few messages (for low CPU time!) */
while (recv_msgq)
{
#if DEBUG >= 2
gui_printf (gui_current_window, "[DEBUG] %s\n", recv_msgq->data);
#endif
ptr_data = recv_msgq->data;
while (ptr_data[0] == ' ')
ptr_data++;
if (ptr_data)
{
#if DEBUG >= 2
gui_printf (NULL, "[DEBUG] data received from server: %s\n", ptr_data);
#endif
host = NULL;
command = NULL;
args = ptr_data;
if (ptr_data[0] == ':')
{
pos = strchr(ptr_data, ' ');
pos[0] = '\0';
host = ptr_data+1;
pos++;
}
else
pos = ptr_data;
if (pos != NULL)
{
while (pos[0] == ' ')
pos++;
pos2 = strchr(pos, ' ');
if (pos2 != NULL)
{
pos2[0] = '\0';
command = strdup(pos);
pos2++;
while (pos2[0] == ' ')
pos2++;
args = (pos2[0] == ':') ? pos2+1 : pos2;
}
}
switch (irc_recv_command (recv_msgq->server, host, command, args))
{
case -1:
gui_printf (recv_msgq->server->window,
_("Command '%s' failed!\n"), command);
break;
case -2:
gui_printf (recv_msgq->server->window,
_("No command to execute!\n"));
break;
case -3:
gui_printf (recv_msgq->server->window,
_("Unknown command: cmd=%s, args=%s\n"),
command, args);
break;
}
}
free (recv_msgq->data);
next = recv_msgq->next_message;
free (recv_msgq);
recv_msgq = next;
if (recv_msgq == NULL)
msgq_last_msg = NULL;
}
}
/*
* server_recv: receive data from an irc server
*/
void
server_recv (t_irc_server *server)
{
static char buffer[4096 + 2];
int num_read;
num_read = recv (server->sock4, buffer, sizeof (buffer) - 2, 0);
if (num_read > 0)
{
buffer[num_read] = '\0';
server_msgq_add_buffer (server, buffer);
server_msgq_flush ();
}
}
/*
* server_connect: connect to an irc server
*/
int
server_connect (t_irc_server *server)
{
int set;
struct hostent *ip4_hostent;
struct sockaddr_in addr;
char *ip_address;
int error;
int server_pipe[2];
gui_printf (server->window,
_(WEECHAT_NAME ": connecting to %s:%d...\n"),
server->address, server->port);
log_printf ("connecting to server %s:%d...\n",
server->address, server->port);
server->is_connected = 0;
/* create pipe */
if (pipe (server_pipe) < 0)
{
gui_printf (server->window,
_("%s cannot create pipe\n"), WEECHAT_ERROR);
server_free (server);
return 0;
}
server->server_read = server_pipe[0];
server->server_write = server_pipe[1];
/* create socket and set options */
server->sock4 = socket (AF_INET, SOCK_STREAM, 0);
set = 1;
if (setsockopt
(server->sock4, SOL_SOCKET, SO_REUSEADDR, (char *) &set,
sizeof (set)) == -1)
gui_printf (server->window,
_("%s cannot set socket option 'SO_REUSEADDR'\n"),
WEECHAT_ERROR);
set = 1;
if (setsockopt
(server->sock4, SOL_SOCKET, SO_KEEPALIVE, (char *) &set,
sizeof (set)) == -1)
gui_printf (server->window,
_("%s cannot set socket option \"SO_KEEPALIVE\"\n"),
WEECHAT_ERROR);
/* bind to hostname */
ip4_hostent = gethostbyname (server->address);
if (!ip4_hostent)
{
gui_printf (server->window,
_("%s address \"%s\" not found\n"),
WEECHAT_ERROR, server->address);
close (server->server_read);
close (server->server_write);
close (server->sock4);
server->sock4 = -1;
return 0;
}
memset (&addr, 0, sizeof (addr));
memcpy (&addr.sin_addr, ip4_hostent->h_addr, ip4_hostent->h_length);
addr.sin_port = htons (server->port);
addr.sin_family = AF_INET;
/*error = bind(server->sock4, (struct sockaddr *)(&addr), sizeof(addr));
if (error != 0)
{
gui_printf (server->window,
WEECHAT_ERORR "server_connect: can't bind to hostname\n");
return 0;
} */
ip_address = inet_ntoa (addr.sin_addr);
if (!ip_address)
{
gui_printf (server->window,
_("%s IP address not found\n"), WEECHAT_ERROR);
close (server->server_read);
close (server->server_write);
close (server->sock4);
server->sock4 = -1;
return 0;
}
/* connection to server */
gui_printf (server->window,
_(WEECHAT_NAME ": server IP is: %s\n"), ip_address);
error = connect (server->sock4, (struct sockaddr *) &addr, sizeof (addr));
if (error != 0)
{
gui_printf (server->window,
_("%s cannot connect to irc server\n"), WEECHAT_ERROR);
close (server->server_read);
close (server->server_write);
close (server->sock4);
server->sock4 = -1;
return 0;
}
current_irc_server = server;
return 1;
}
/*
* server_disconnect: disconnect from an irc server
*/
void
server_disconnect (t_irc_server *server)
{
if (server->is_connected)
{
close (server->server_read);
close (server->server_write);
close (server->sock4);
server->is_connected = 0;
}
}
/*
* server_disconnect_all: disconnect from all irc servers
*/
void
server_disconnect_all ()
{
t_irc_server *ptr_server;
for (ptr_server = irc_servers; ptr_server; ptr_server = ptr_server->next_server)
server_disconnect (ptr_server);
}
/*
* server_get_number_connected: returns number of connected server
*/
int
server_get_number_connected ()
{
t_irc_server *ptr_server;
int number;
number = 0;
for (ptr_server = irc_servers; ptr_server; ptr_server = ptr_server->next_server)
{
if (ptr_server->is_connected)
number++;
}
return number;
}
/*
* server_name_already_exists: return 1 if server name already exists
* otherwise return 0
*/
int
server_name_already_exists (char *name)
{
t_irc_server *ptr_server;
for (ptr_server = irc_servers; ptr_server; ptr_server = ptr_server->next_server)
{
if (strcmp (ptr_server->name, name) == 0)
return 1;
}
return 0;
}

247
src/irc/irc.h Normal file
View File

@ -0,0 +1,247 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WEECHAT_IRC_H
#define __WEECHAT_IRC_H 1
#include "../gui/gui.h"
#define PREFIX_SERVER "-@-"
#define PREFIX_INFO "-=-"
#define PREFIX_ACTION_ME "-*-"
#define PREFIX_JOIN "-->"
#define PREFIX_PART "<--"
#define PREFIX_QUIT "<--"
#define PREFIX_ERROR "=!="
#define CHANNEL_PREFIX "#&+!"
/* nick types */
typedef struct t_irc_nick t_irc_nick;
struct t_irc_nick
{
char *nick; /* nickname */
int is_op; /* operator privileges? */
int is_halfop; /* half operaor privileges? */
int has_voice; /* nick has voice? */
int color; /* color for nickname */
t_irc_nick *prev_nick; /* link to previous nick on the channel */
t_irc_nick *next_nick; /* link to next nick on the channel */
};
/* channel types */
typedef struct t_irc_channel t_irc_channel;
#define CHAT_UNKNOWN -1
#define CHAT_CHANNEL 0
#define CHAT_PRIVATE 1
struct t_irc_channel
{
int type; /* channel type */
char *name; /* name of channel (exemple: "#abc") */
char *topic; /* topic of channel (host for private) */
t_irc_nick *nicks; /* nicks on the channel */
t_irc_nick *last_nick; /* last nick on the channel */
t_gui_window *window; /* GUI window allocated for channel */
t_irc_channel *prev_channel; /* link to previous channel */
t_irc_channel *next_channel; /* link to next channel */
};
/* server types */
typedef struct t_irc_server t_irc_server;
struct t_irc_server
{
/* user choices */
char *name; /* name of server (only for display) */
char *address; /* address of server (IP or name) */
int port; /* port for server (6667 by default) */
char *password; /* password for server */
char *nick1; /* first nickname for the server */
char *nick2; /* alternate nickname */
char *nick3; /* 2nd alternate nickname */
char *username; /* user name */
char *realname; /* real name */
/* internal vars */
char *nick; /* current nickname */
int is_connected; /* 1 if WeeChat is connected to server */
int sock4; /* socket for server */
int is_away; /* 1 is user is marker as away */
int server_read; /* pipe for reading server data */
int server_write; /* pipe for sending data to server */
t_gui_window *window; /* GUI window allocated for server */
t_irc_channel *channels; /* opened channels on server */
t_irc_channel *last_channel; /* last opened channal on server */
t_irc_server *prev_server; /* link to previous server */
t_irc_server *next_server; /* link to next server */
};
/* irc commands */
typedef struct t_irc_command t_irc_command;
struct t_irc_command
{
char *command_name; /* command name (internal or IRC cmd) */
char *command_description; /* command description */
char *arguments; /* command parameters */
char *arguments_description; /* parameters description */
int min_arg, max_arg; /* min & max number of parameters */
int need_connection; /* = 1 if cmd needs server connection */
int (*cmd_function_args)(t_irc_server *, int, char **);
/* function called when user enters cmd */
int (*cmd_function_1arg)(t_irc_server *, char *);
/* function called when user enters cmd */
int (*recv_function)(t_irc_server *, char *, char *);
/* function called when cmd is received */
};
typedef struct t_irc_message t_irc_message;
struct t_irc_message
{
t_irc_server *server; /* server pointer for received msg */
char *data; /* message content */
t_irc_message *next_message; /* link to next message */
};
extern t_irc_command irc_commands[];
extern t_irc_server *irc_servers, *current_irc_server;
extern t_irc_message *recv_msgq, *msgq_last_msg;
extern t_irc_channel *current_channel;
/* server functions (irc-server.c) */
extern t_irc_server *server_alloc ();
extern void server_create_window (t_irc_server *);
extern void server_free (t_irc_server *);
extern void server_free_all ();
extern t_irc_server *server_new (char *, char *, int, char *, char *, char *,
char *, char *, char *);
extern int server_send (t_irc_server *, char *, int);
extern int server_sendf (t_irc_server *, char *, ...);
extern void server_recv (t_irc_server *);
extern int server_connect ();
extern void server_disconnect (t_irc_server *);
extern void server_disconnect_all ();
extern int server_get_number_connected ();
extern int server_name_already_exists (char *);
/* channel functions (irc-channel.c) */
extern t_irc_channel *channel_new (t_irc_server *, int, char *);
extern void channel_free (t_irc_server *, t_irc_channel *);
extern void channel_free_all (t_irc_server *);
extern t_irc_channel *channel_search (t_irc_server *, char *);
extern int string_is_channel (char *);
/* nick functions (irc-nick.c) */
extern t_irc_nick *nick_new (t_irc_channel *, char *, int, int, int);
extern void nick_resort (t_irc_channel *, t_irc_nick *);
extern void nick_change (t_irc_channel *, t_irc_nick *, char *);
extern void nick_free (t_irc_channel *, t_irc_nick *);
extern void nick_free_all (t_irc_channel *);
extern t_irc_nick *nick_search (t_irc_channel *, char *);
extern void nick_count (t_irc_channel *, int *, int *, int *, int *, int *);
extern int nick_get_max_length (t_irc_channel *);
/* IRC display (irc-diplay.c) */
extern void irc_display_prefix (t_gui_window *, char *);
extern void irc_display_nick (t_gui_window *, t_irc_nick *, int, int, int, int);
extern void irc_display_mode (t_gui_window *, char *, char, char *, char *,
char *, char *);
/* IRC protocol (irc-commands.c) */
extern int irc_recv_command (t_irc_server *, char *, char *, char *);
extern void irc_login (t_irc_server *);
/* IRC commands issued by user */
extern int irc_cmd_send_away (t_irc_server *, char *);
extern int irc_cmd_send_ctcp (t_irc_server *, char *);
extern int irc_cmd_send_deop (t_irc_server *, int, char **);
extern int irc_cmd_send_devoice (t_irc_server *, int, char **);
extern int irc_cmd_send_invite (t_irc_server *, char *);
extern int irc_cmd_send_join (t_irc_server *, char *);
extern int irc_cmd_send_kick (t_irc_server *, char *);
extern int irc_cmd_send_kill (t_irc_server *, char *);
extern int irc_cmd_send_list (t_irc_server *, char *);
extern int irc_cmd_send_me (t_irc_server *, char *);
extern int irc_cmd_send_mode (t_irc_server *, char *);
extern int irc_cmd_send_msg (t_irc_server *, char *);
extern int irc_cmd_send_names (t_irc_server *, char *);
extern int irc_cmd_send_nick (t_irc_server *, int, char **);
extern int irc_cmd_send_notice (t_irc_server *, char *);
extern int irc_cmd_send_op (t_irc_server *, int, char **);
extern int irc_cmd_send_oper (t_irc_server *, int, char **);
extern int irc_cmd_send_part (t_irc_server *, char *);
extern int irc_cmd_send_ping (t_irc_server *, int, char **);
extern int irc_cmd_send_pong (t_irc_server *, int, char **);
extern int irc_cmd_send_quit (t_irc_server *, char *);
extern int irc_cmd_send_quote (t_irc_server *, char *);
extern int irc_cmd_send_topic (t_irc_server *, char *);
extern int irc_cmd_send_version (t_irc_server *, char *);
extern int irc_cmd_send_voice (t_irc_server *, int, char **);
extern int irc_cmd_send_whois (t_irc_server *, char *);
/* IRC commands executed when received from server */
extern int irc_cmd_recv_error (t_irc_server *, char *, char *);
extern int irc_cmd_recv_join (t_irc_server *, char *, char *);
extern int irc_cmd_recv_kick (t_irc_server *, char *, char *);
extern int irc_cmd_recv_mode (t_irc_server *, char *, char *);
extern int irc_cmd_recv_nick (t_irc_server *, char *, char *);
extern int irc_cmd_recv_notice (t_irc_server *, char *, char *);
extern int irc_cmd_recv_part (t_irc_server *, char *, char *);
extern int irc_cmd_recv_ping (t_irc_server *, char *, char *);
extern int irc_cmd_recv_privmsg (t_irc_server *, char *, char *);
extern int irc_cmd_recv_quit (t_irc_server *, char *, char *);
extern int irc_cmd_recv_server_msg (t_irc_server *, char *, char *);
extern int irc_cmd_recv_server_reply (t_irc_server *, char *, char *);
extern int irc_cmd_recv_topic (t_irc_server *, char *, char *);
extern int irc_cmd_recv_001 (t_irc_server *, char *, char *);
extern int irc_cmd_recv_004 (t_irc_server *, char *, char *);
extern int irc_cmd_recv_301 (t_irc_server *, char *, char *);
extern int irc_cmd_recv_311 (t_irc_server *, char *, char *);
extern int irc_cmd_recv_312 (t_irc_server *, char *, char *);
extern int irc_cmd_recv_313 (t_irc_server *, char *, char *);
extern int irc_cmd_recv_317 (t_irc_server *, char *, char *);
extern int irc_cmd_recv_318 (t_irc_server *, char *, char *);
extern int irc_cmd_recv_319 (t_irc_server *, char *, char *);
extern int irc_cmd_recv_320 (t_irc_server *, char *, char *);
extern int irc_cmd_recv_321 (t_irc_server *, char *, char *);
extern int irc_cmd_recv_322 (t_irc_server *, char *, char *);
extern int irc_cmd_recv_323 (t_irc_server *, char *, char *);
extern int irc_cmd_recv_331 (t_irc_server *, char *, char *);
extern int irc_cmd_recv_332 (t_irc_server *, char *, char *);
extern int irc_cmd_recv_333 (t_irc_server *, char *, char *);
extern int irc_cmd_recv_351 (t_irc_server *, char *, char *);
extern int irc_cmd_recv_353 (t_irc_server *, char *, char *);
extern int irc_cmd_recv_366 (t_irc_server *, char *, char *);
extern int irc_cmd_recv_433 (t_irc_server *, char *, char *);
#endif /* irc.h */

9
src/plugins/README Normal file
View File

@ -0,0 +1,9 @@
WeeChat - Wee Enhanced Environment for Chat
===========================================
This is plugins directory for WeeChat.
In the future, you'll find there interfaces with many famous languages for
writing extensions to WeeChat:
- Perl interface,
- Python interface,
- Ruby interface.

311
src/weechat.c Normal file
View File

@ -0,0 +1,311 @@
/* ############################################################################
* ### ___ __ ______________ _____ ###
* ### __ | / /___________ ____/__ /_______ __ /_ ###
* ### __ | /| / /_ _ \ _ \ / __ __ \ __ `/ __/ ###
* ### __ |/ |/ / / __/ __/ /___ _ / / / /_/ // /_ ###
* ### ____/|__/ \___/\___/\____/ /_/ /_/\__,_/ \__/ ###
* ### ###
* ### WeeChat - Wee Enhanced Environment for Chat ###
* ### Fast & light environment for Chat ###
* ### ###
* ### By: FlashCode <flashcode@flashtux.org> ###
* ### Bounga <bounga@altern.org> ###
* ### Xahlexx <xahlexx@tuxisland.org> ###
* ### ###
* ### http://weechat.flashtux.org ###
* ### ###
* ############################################################################
*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* weechat.c: core functions for WeeChat */
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <sys/stat.h>
#include <time.h>
#include "weechat.h"
#include "config.h"
#include "command.h"
#include "irc/irc.h"
#include "gui/gui.h"
/* char *display_name; */
int quit_weechat; /* = 1 if quit request from user... why ? :'( */
FILE *log_file; /* WeeChat log file (~/.weechat/weechat.log */
/*
* log_printf: displays a message in WeeChat log (~/.weechat/weechat.log)
*/
void
log_printf (char *message, ...)
{
static char buffer[4096];
va_list argptr;
static time_t seconds;
struct tm *date_tmp;
if (!log_file)
return;
va_start (argptr, message);
vsnprintf (buffer, sizeof (buffer) - 1, message, argptr);
va_end (argptr);
seconds = time (NULL);
date_tmp = localtime (&seconds);
fprintf (log_file, "[%04d-%02d-%02d %02d:%02d:%02d] %s",
date_tmp->tm_year + 1900, date_tmp->tm_mon + 1, date_tmp->tm_mday,
date_tmp->tm_hour, date_tmp->tm_min, date_tmp->tm_sec,
buffer);
fflush (log_file);
}
/*
* wee_parse_args: parse command line args
*/
void
wee_parse_args (int argc, char *argv[])
{
int i;
for (i = 1; i < argc; i++)
{
if ((strcmp (argv[i], "-h") == 0)
|| (strcmp (argv[i], "--help") == 0))
{
printf ("\n%s%s", WEE_USAGE);
exit (0);
}
else if ((strcmp (argv[i], "-l") == 0)
|| (strcmp (argv[i], "--license") == 0))
{
printf ("\n%s%s", WEE_LICENSE);
exit (0);
}
/*else if ((strcmp (argv[i], "-d") == 0)
|| (strcmp (argv[i], "--display") == 0))
{
if (i == (argc - 1))
fprintf (stderr,
_("%s no display specified (parameter '%s'), ignored\n"),
WEECHAT_WARNING, argv[i]);
else
{
display_name = argv[i + 1];
i++;
}
}*/
else if ((strcmp (argv[i], "-v") == 0)
|| (strcmp (argv[i], "--version") == 0))
{
printf (WEECHAT_VERSION "\n");
exit (0);
}
else
{
fprintf (stderr,
_("%s unknown parameter '%s', ignored\n"),
WEECHAT_WARNING, argv[i]);
}
}
}
/*
* wee_create_home_dir: create weechat home directory (if not found)
*/
void
wee_create_home_dir ()
{
char *weechat_home_dir;
int return_code;
weechat_home_dir =
(char *) malloc ((strlen (getenv ("HOME")) + 64) * sizeof (char));
sprintf (weechat_home_dir, "%s/.weechat", getenv ("HOME"));
return_code = mkdir (weechat_home_dir, 0755);
if (return_code < 0)
{
if (errno != EEXIST)
{
fprintf (stderr, _("%s cannot create directory \"%s\"\n"),
WEECHAT_ERROR, weechat_home_dir);
free (weechat_home_dir);
exit (1);
}
}
free (weechat_home_dir);
}
/*
* wee_init_vars: initialize some variables
*/
void
wee_init_vars ()
{
/* GUI not yet initialized */
gui_ready = 0;
/* init received messages queue */
recv_msgq = NULL;
msgq_last_msg = NULL;
}
/*
* wee_init_log: initialize log file
*/
void
wee_init_log ()
{
char *filename;
filename =
(char *) malloc ((strlen (getenv ("HOME")) + 64) * sizeof (char));
sprintf (filename, "%s/.weechat/" WEECHAT_LOG_NAME, getenv ("HOME"));
if ((log_file = fopen (filename, "wt")) == NULL)
{
free (filename);
fprintf (stderr,
_("%s unable to create/append to log file (~/.weechat/"
WEECHAT_LOG_NAME), WEECHAT_ERROR);
}
free (filename);
}
/*
* wee_shutdown: shutdown WeeChat
*/
void
wee_shutdown ()
{
gui_end ();
server_free_all ();
if (log_file)
fclose (log_file);
exit (0);
}
/*
* main: WeeChat startup
*/
int
main (int argc, char *argv[])
{
t_irc_server *ptr_server;
/* initialize variables */
wee_init_vars ();
/* parse command line args */
wee_parse_args (argc, argv);
/* create weechat home directory */
wee_create_home_dir ();
/* init log file */
wee_init_log ();
/* read configuration */
switch (config_read ())
{
case 0: /* success */
break;
case -1: /* config file not found */
config_create_default ();
config_read ();
break;
default: /* other error (fatal) */
server_free_all ();
return 1;
}
/* init gui */
gui_init ();
/* build commands index (sorted), for completion */
index_command_build ();
/* Welcome message - yeah! */
if (cfg_look_startup_logo)
{
gui_printf_color (NULL, COLOR_WIN_CHAT_PREFIX1,
" ___ __ ______________ _____ \n"
" __ | / /___________ ____/__ /_______ __ /_\n"
" __ | /| / /_ _ \\ _ \\ / __ __ \\ __ `/ __/\n"
" __ |/ |/ / / __/ __/ /___ _ / / / /_/ // /_ \n"
" ____/|__/ \\___/\\___/\\____/ /_/ /_/\\__,_/ \\__/ \n");
}
if (cfg_look_weechat_slogan && cfg_look_weechat_slogan[0])
{
gui_printf_color (NULL, COLOR_WIN_CHAT, _("%sWelcome to "),
(cfg_look_startup_logo) ? " " : "");
gui_printf_color (NULL, COLOR_WIN_CHAT_PREFIX2, WEECHAT_NAME);
gui_printf_color (NULL, COLOR_WIN_CHAT,
", %s\n", cfg_look_weechat_slogan);
}
if (cfg_look_startup_version)
{
gui_printf_color (NULL, COLOR_WIN_CHAT_PREFIX2,
"%s" WEECHAT_NAME_AND_VERSION,
(cfg_look_startup_logo) ? " " : "");
gui_printf_color (NULL, COLOR_WIN_CHAT,
", %s %s %s\n",
_("compiled on"), __DATE__, __TIME__);
}
if (cfg_look_startup_logo ||
(cfg_look_weechat_slogan && cfg_look_weechat_slogan[0]) ||
cfg_look_startup_version)
gui_printf_color (NULL, COLOR_WIN_CHAT_PREFIX1,
"-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
/* connect to all servers */
for (ptr_server = irc_servers; ptr_server;
ptr_server = ptr_server->next_server)
{
server_create_window (ptr_server);
if (server_connect (ptr_server))
irc_login (ptr_server);
}
gui_main_loop ();
server_disconnect_all ();
/* program ending */
wee_shutdown ();
/* make gcc happy (statement never executed) */
return 0;
}

96
src/weechat.h Normal file
View File

@ -0,0 +1,96 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WEECHAT_H
#define __WEECHAT_H 1
#include <stdio.h>
#include <libintl.h>
#define _(string) gettext(string)
#define N_(string) (string)
#define WEECHAT_NAME "WeeChat"
#define WEECHAT_VERSION "0.0.1"
#define WEECHAT_NAME_AND_VERSION WEECHAT_NAME " " WEECHAT_VERSION
#define WEECHAT_COPYRIGHT WEECHAT_NAME " (c) 2003 by Wee Team"
#define WEECHAT_WEBSITE "http://weechat.flashtux.org"
#define WEECHAT_ERROR _(WEECHAT_NAME " Error:")
#define WEECHAT_WARNING _(WEECHAT_NAME " Warning:")
/* debug mode, 0=normal use, 1=some debug msg, 2=full debug (developers only) */
#define DEBUG 0
/* log file */
#define WEECHAT_LOG_NAME "weechat.log"
/* license */
#define WEE_LICENSE \
WEECHAT_NAME_AND_VERSION " (c) Copyright 2003, compiled on " __DATE__ __TIME__ \
"Developed by FlashCode <flashcode@flashtux.org>\n" \
" Bounga <bounga@altern.org>\n" \
" Xahlexx <xahlexx@tuxisland.org>\n\n" \
"This program is free software; you can redistribute it and/or modify\n" \
"it under the terms of the GNU General Public License as published by\n" \
"the Free Software Foundation; either version 2 of the License, or\n" \
"(at your option) any later version.\n" \
"\n", \
\
"This program is distributed in the hope that it will be useful,\n" \
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n" \
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" \
"GNU General Public License for more details.\n" \
"\n" \
"You should have received a copy of the GNU General Public License\n" \
"along with this program; if not, write to the Free Software\n" \
"Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n\n"
#define WEE_USAGE \
WEECHAT_NAME_AND_VERSION " (c) Copyright 2003, compiled on " __DATE__ __TIME__ \
"Developed by FlashCode <flashcode@flashtux.org>\n" \
" Bounga <bounga@altern.org>\n" \
" Xahlexx <xahlexx@tuxisland.org>\n\n" \
" Bounga <bounga@altern.org>\n" \
" Xahlexx <xahlexx@tuxisland.org>\n\n" \
" -h, --help this help screen\n", \
" -l, --license display WeeChat license\n" \
" -v, --version display WeeChat version\n\n"
/* " -d, --display choose X display\n" \*/
/*#define DEFAULT_DISPLAY ":0" */
/*extern char *display_name; */
int quit_weechat;
extern int quit_weechat;
extern void log_printf (char *, ...);
extern void wee_shutdown ();
#endif /* weechat.h */

44
weechat.1 Normal file
View File

@ -0,0 +1,44 @@
.TH WEECHAT 1 "September 2003" "FlashCode"
.SH NAME
weechat \- wee enhanced environment for chat
.SH SYNOPSIS
.B weechat
.RI [ options ]
.br
.SH DESCRIPTION
Fast, light and extensible IRC client for many operating systems. Everything can be
done with a keyboard. It is customizable and extensible with scripts.
.SH OPTIONS
.TP
.B \-h, \-\-help
.br
display summary of options
.TP
.B \-l, \-\-license
.br
display program license
.TP
.B \-v, \-\-version
.br
display WeeChat version
.SH FILES
.TP
.B $HOME/.weechat/weechat.rc
configuration file for WeeChat
.SH AUTHOR
WeeChat is written by:
.br
- FlashCode <flashcode@flashtux.org>
- Bounga <bounga@altern.org>
- Xahlexx <xahlexx@tuxisland.org>
.br
WeeChat on the web:
.UR
http://weechat.flashtux.org
.UE

41
weechat.spec Normal file
View File

@ -0,0 +1,41 @@
%define name weechat
%define version 0.0.1
%define release 1
Name: %{name}
Summary: portable, fast, light and extensible IRC client
Version: %{version}
Release: %{release}
Source: http://weechat.flashtux.org/download/%{name}-%{version}.tar.gz
URL: http://weechat.flashtux.org
Group: Networking/IRC
BuildRoot: %{_tmppath}/%{name}-buildroot
License: GPL
%description
WeeChat (Wee Enhanced Environment for Chat) is a portable, fast, light and
extensible IRC client. Everything can be done with a keyboard.
It is customizable and extensible with scripts.
%prep
rm -rf $RPM_BUILD_ROOT
%setup
%build
make DESTDIR="$RPM_BUILD_ROOT" LOCALRPM="local"
%install
make DESTDIR="$RPM_BUILD_ROOT" LOCALRPM="local" install
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root,0755)
%doc AUTHORS BUGS ChangeLog COPYING FAQ INSTALL NEWS README TODO
/usr/share/man/man1/weechat.1*
/usr/local/bin/weechat
%changelog
* Thu Sep 27 2003 FlashCode <flashcode@flashtux.org> 0.0.1-1
- Released version 0.0.1

29
weechat/AUTHORS Normal file
View File

@ -0,0 +1,29 @@
WeeChat - Wee Enhanced Environment for Chat
===========================================
Developers:
----------
All developers are connected to IRC:
server: irc.freenode.net, channel: #weechat
FlashCode <flashcode@flashtux.org>
Web : http://www.flashtux.org
IRC : nick is "FlashCode"
Jabber: flashcode@jabber.org
ICQ : 160677660
AIM : FlashCode AIM
Yahoo : FlashCode_Y
Bounga <bounga@altern.org>
Web : http://bounga.ath.cx
IRC : nick is "Bounga"
Jabber: Bounga@jabber.org
ICQ : 178297842
Xahlexx <xahlexx@tuxisland.org>
Web : http://www.tuxisland.org
IRC : nick is "xahlexx"
See README file for licence detail.

17
weechat/BUGS Normal file
View File

@ -0,0 +1,17 @@
WeeChat - Wee Enhanced Environment for Chat
===========================================
WeeChat known bugs, 2003-09-27
- too much nicks in the channel (> height of window) => display bug
- some IRC commands are marked as 'unknown' when received
(irc protocol is under dev!)
- bug in nicklist resize (sometimes resize doesn't work and there is display
problem)
- alias/unalias commands doesn't work
- config is not saved (to ~/.weechat/weechatrc)
- intercept Ctrl-C (do not quit immediately if Ctrl-C pressed!)
- program is stopped when bad option in config file (it should not, only display
warning)
- too much opened channel => display bug
- when kicked, channel is not prefixed by '(' and sufixed by ')'

340
weechat/COPYING Normal file
View File

@ -0,0 +1,340 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.

88
weechat/ChangeLog Normal file
View File

@ -0,0 +1,88 @@
WeeChat - Wee Enhanced Environment for Chat
===========================================
ChangeLog - 2003-09-27
* 2003-09-27:
- WeeChat 0.0.1 released!
* 2003-09-26:
- added completor prefix (in config: look_nick_completor)
- fixef log_printf command (bug with year & month)
- added "/kill" command
- fixed /version and /ctcp commands (missing ":" before message)
* 2003-09-25:
- added "/kick" command
- added IRC errors 402 to 407
- added "/invite" command
* 2003-09-24:
- "ctcp version" received is now correctly displayed
- "/version" command is ok
* 2003-09-23:
- log file (~/.weechat/weechat.log)
- renamed config file (~/.weechat/weechatrc to ~/.weechat/weechat.rc)
* 2003-09-21:
- "demi-highlight": 2 types of windows highlight: lightred for windows with
unread messages (from other users), lightmagenta for windows with other
unread data (join, part, quit, away, ...)
- "320" IRC message management
- "/clear" command
* 2003-09-19:
- préparation des sources pour l'internationalisation avec gettext
- "301" IRC command (away message)
- functions renamed in rc-commands.c, irc-server.c,
command.c and config.c (all functions are beginning with a prefix:
irc_cmd_recv_xxx, irc_cmd_send_xxx, server_xxx, weechat_cmd_xxx and
config_xxx). Moreover, all commands (sent and received) return a value
(success or not)
- "/quote" command
- "/whois" command (and colored display of /whois result in server window)
* 2003-09-18:
- use of alternate nickname (and 2nd alternate) if nick is already used
on server (changed/added in config file: options "nick1", "nick2", "nick3"
for a server, all are mandatory)
- "433" IRC error management (nickname already in use)
- "mode" command received correctly for "channel flags" and
op/deop/voice/devoice actions for a nick
- "401" IRC error management (no such nick/channel)
- private windows management (when received and opened, with /privmsg),
"/privmsg" completed consequently
* 2003-09-17:
- nickmode display ((half)op/voice) before nicks (as option, look at config
options beginning with "look_nickmode")
- windows history is now ok (pgup/pgdn on any window type)
- "/me" command (and OK when received)
- display nicks count when joining channel or with "/names" command
(total, ops, halfops, voices et normaux)
* 2003-09-16:
- added and normalized chat window colors
(new colors in config file)
- "/topic" command
- nicklist can be moved on top, bottom, left or right of window
* 2003-09-15:
- auto-resize of nicklist, according to nick max length
- IRC multi-servers is OK
* 2003-09-14:
- no hangup if "/part" command is executed on server window
- continue if no server is declared in config file
(empty window will be opened for executing WeeChat commands)
- string array for strings in config file
example: cfg_look_nicklist_position can take values "left", "right",
"top", "bottom", which are converted to int (from 0 for "left" to 3 for
"bottom")
- messages are aligned under time (server window) or under time + nick
(channel window)
* 2003-09-13:
- sources exploded in many directories: ./irc, ./gui/curses, ./gui/gtk,
./gui/qt and ./gui/text

6
weechat/FAQ Normal file
View File

@ -0,0 +1,6 @@
WeeChat - Wee Enhanced Environment for Chat
===========================================
WeeChat FAQ, 2003-09-19
<<< TO DO ! >>>

10
weechat/INSTALL Normal file
View File

@ -0,0 +1,10 @@
WeeChat - Installation instructions
===================================
1) Run 'make'
2) As root, run 'make install'
3) Enjoy ! :-)
See AUTHORS for any support, feel free to contact us for any problem ;)

31
weechat/Makefile Normal file
View File

@ -0,0 +1,31 @@
# Copyright (c) 2003 FlashCode <flashcode@flashtux.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
OUTPUT=weechat
all:
cd src && make
install:
@mkdir -v -p $(DESTDIR)/usr/$(LOCALRPM)/bin
@cp -v src/$(OUTPUT) $(DESTDIR)/usr/$(LOCALRPM)/bin/
@mkdir -v -p $(DESTDIR)/usr/share/man/man1
@cp -v weechat.1 $(DESTDIR)/usr/share/man/man1/
@echo -e "\n=== WeeChat installed!\n"
clean:
cd src && make clean

6
weechat/NEWS Normal file
View File

@ -0,0 +1,6 @@
WeeChat - Wee Enhanced Environment for Chat
===========================================
FlashCode, 2003-09-27
WeeChat 0.0.1 released.

50
weechat/README Normal file
View File

@ -0,0 +1,50 @@
WeeChat - Wee Enhanced Environment for Chat
===========================================
WeeChat (Wee Enhanced Environment for Chat) is a fast and light chat
environment for many operating systems. Everything can be done with a keyboard.
It is customizable and extensible with scripts.
Features
--------
* IRC chat client with multi-server connection
* many GUI (curses, text, Gtk, QT) (1)
* small, fast and very light
* customizable and extensible with scripts (Perl, Python, Ruby) (2)
* compliant with RFC 1459,2810,2811,2812,2813
* multi-platform (GNU/Linux, *BSD, Windows & other) (3)
* 100% GPL & free
Copyright
---------
WeeChat (c) Copyright 2003
by: FlashCode <flashcode@flashtux.org>
Xahlexx <xahlex@tuxisland.org>
Bounga <bounga@altern.org>
(see AUTHORS file if you want to contact authors)
WeeChat is distributed under GPL licence (see COPYING file for complete license):
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
---
(1) only curses & text interfaces are available today
(2) plugin interfaces are not yet developed
(3) only GNU/Linux version is available today

130
weechat/TODO Normal file
View File

@ -0,0 +1,130 @@
WeeChat - Wee Enhanced Environment for Chat
===========================================
TODO - 2003-09-27
Legend:
# done
+ currently in development
- pending
? is this really necessary?
v0.0.1:
* IRC protocol:
# "/quote" command: send a raw string to the server without parsing it
# "/me" command (for user actions description)
# "/away" command (to toggle the away status)
# "/op", "/deop", "/voice", "/devoice" commands
# "/invite" command
# "/kick", "/ban", "/unban" commands
# "/kill" command
# "/list" command: list of channels
# "/names" command: view who is on a given channel without being
on it (for example /names #weechat gives all the nicks present on
#weechat, except those who have the +i flag (server side))
# "/oper" command: become operator on the irc network
# "/topic" command: change the topic of a channel
# "/version" command: give the irc client version (CTCP VERSION)
of a given nick/channel (without parameter: gives WeeChat version)
# "/whois" command
* WeeChat commands:
# "/clear": to clear window content
* Interface:
# "demi-highlight" when joins/quits etc
# log messages/warning/errors to ~/.weechat/log file
# improve editing zone (left arrow <> backspace)
# sort nick list
# choose nick list position (top, left, right (default), bottom)
# auto-resize nicklist (when nick too long)
# do pretty cutting of long lines (align on the nick or after hour for server)
# keep history of commands and call them again with up/down arrow
# text GUI
# ncurses GUI:
# one window for each channel
# color display
# private windows
# redraw window when term size is modified
# chat history (pgup/pgdn for displaying history)
# switch to other channel window
* TCP/IP communication:
# IPv4 protocol implementation
* Configuration:
# write default config file
Future versions:
* IRC protocol:
- implement RFC 2812
+ "/mode" command: change the user/channels modes
- "/dcc" command (for chat and sending/receiving files)
- manage "halfop" status
- complete "/list" command: add regexp search, display only channels that
match regexp
- "/connect" and "/disconnect" commands (for multiservers use)
- "/ignore" and "/unignore" commands: hide all that is write by a given
nick/host
- when we're away, WeeChat should log all the lines begenning by our nick.
When we come back from our away it should print it to the current window
- "/rehash" command: tell the server to reload its config file
- "/restart" command: tell the server to restart itself
- "/notify" and "/unnotify" command to be warn by WeeChat when a given
nick/host connect to the given irc network
- "/wallops" command: write the same string to all the
persons with the flag +w enable
* WeeChat commands:
- "/completion" command: do shortcuts (for example when we type "u"
in the text bar it send it to the server as "you")
- "/exec" command: execute a command as if we was in shell
and show us the output on the current window. An option to exec
like -o could send the output to the server, on the current
channel/private
- "/reload" command: reload the WeeChat's config file
- "/set" command: allow the user to set the WeeChat variables
under WeeChat without editing the config file (colours, time
format, etc)
- "/highlight" command: highlight a given word when it appears on
channels/privates
* Interface:
- display current channel modes (example : #weechat(+nt))
- interpret ^B in messages (this means bold text)
- internationalization (traduce WeeChat in many languages)
- many channel windows in one window/term (window split)
- add lag indicator
- log chats to file
- forget some old lines that were displayed long time ago (now all is saved,
if WeeChat is running for long time, a lot of memory is used!)
- improve completion (for example complete command parameters when possible)
- understand incomplete commands if unambigous (for example: /he for /help is ok)
- add clock (in status bar?)
- Gtk GUI
? Qt GUI
* TCP/IP communication:
- IPv6 protocol implementation
* Configuration:
- add key bindings to config file
- add missing options for config file
- write config file
- add an option for each server in order to run commands on join
(example: /msg nickserv identify password)
- channel list for auto-join (for each server)
- do not stop program if problem with options in config file
- load config file after GUI (so init values by default (colors, ...) before
loading config)
* Plugins:
- add Perl plugin
- add Python plugin
- add Ruby plugin
- "/load" and "/unload" commands to (un)load extension scripts
(perl, python, ruby, ...)

5
weechat/debian/changelog Normal file
View File

@ -0,0 +1,5 @@
weechat (0.0.1-1) unstable; urgency=low
* First version.
-- FlashCode <flashcode@flashtux.org> Sat, 27 Jun 2003 12:00:00 +0200

1
weechat/debian/compat Normal file
View File

@ -0,0 +1 @@
4

14
weechat/debian/control Normal file
View File

@ -0,0 +1,14 @@
Source: weechat
Section: net
Priority: optional
Maintainer: FlashCode <flashcode@flashtux.org>
Build-Depends: debhelper (>> 4.0.0)
Standards-Version: 3.5.8
Package: weechat
Architecture: any
Depends: ${shlibs:Depends}
Description: Fast, light and extensible IRC client
WeeChat (Wee Enhanced Environment for Chat) is a fast and light IRC client
for many operating systems. Everything can be done with a keyboard.
It is customizable and extensible with scripts.

17
weechat/debian/copyright Normal file
View File

@ -0,0 +1,17 @@
This package was debianized by FlashCode <flashcode@flashtux.org> on
Sat, 27 Sep 2003 10:00:00 +0200.
It was downloaded from http://weechat.flashtux.org/download
Upstream Author(s): FlashCode <flashcode@flashtux.org>
Copyright:
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.
On Debian systems, the complete text of the GNU General Public
License, Version 2 can be found in the file
/usr/share/common-licenses/GPL

1
weechat/debian/dirs Normal file
View File

@ -0,0 +1 @@
usr/bin

9
weechat/debian/docs Normal file
View File

@ -0,0 +1,9 @@
AUTHORS
BUGS
ChangeLog
COPYING
FAQ
INSTALL
NEWS
README
TODO

1
weechat/debian/files Normal file
View File

@ -0,0 +1 @@
weechat_0.0.1-1_i386.deb net optional

97
weechat/debian/rules Executable file
View File

@ -0,0 +1,97 @@
#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
CFLAGS = -Wall -g
ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
CFLAGS += -O0
else
CFLAGS += -O2
endif
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
INSTALL_PROGRAM += -s
endif
configure: configure-stamp
configure-stamp:
dh_testdir
# Add here commands to configure the package.
touch configure-stamp
build: build-stamp
build-stamp: configure-stamp
dh_testdir
# Add here commands to compile the package.
$(MAKE)
#/usr/bin/docbook-to-man debian/weechat.sgml > weechat.1
touch build-stamp
clean:
dh_testdir
dh_testroot
rm -f build-stamp configure-stamp
# Add here commands to clean up after the build process.
-$(MAKE) clean
dh_clean
install: build
dh_testdir
dh_testroot
dh_clean -k
dh_installdirs
# Add here commands to install the package into debian/weechat.
$(MAKE) install DESTDIR=$(CURDIR)/debian/weechat
# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.
# Build architecture-dependent files here.
binary-arch: build install
dh_testdir
dh_testroot
dh_installchangelogs
dh_installdocs
dh_installexamples
# dh_install
# dh_installmenu
# dh_installdebconf
# dh_installlogrotate
# dh_installemacsen
# dh_installpam
# dh_installmime
# dh_installinit
# dh_installcron
# dh_installinfo
dh_installman weechat.1
dh_link
dh_strip
dh_compress
dh_fixperms
# dh_perl
# dh_python
# dh_makeshlibs
dh_installdeb
dh_shlibdeps
dh_gencontrol
dh_md5sums
dh_builddeb
binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install configure

View File

@ -0,0 +1 @@
shlibs:Depends=libc6 (>= 2.3.2-1), libncurses5 (>= 5.3.20030510-1)

91
weechat/src/Makefile Normal file
View File

@ -0,0 +1,91 @@
# Copyright (c) 2003 FlashCode <flashcode@flashtux.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
CC=gcc
OPTIONS=-Wall -W -pipe -O2
OUTPUT=weechat
OBJS=weechat.o config.o command.o completion.o history.o
OBJS_IRC=irc/irc.a
OBJS_GUI=gui/gui.a
# WeeChat with Curses interface
ifeq ($(GUI), curses)
LIBS_CURSES=-lcurses
DEFINES=WEE_CURSES
curses: $(OBJS) $(OBJS_IRC) $(OBJS_GUI)
$(CC) $(OPTIONS) $(OBJS) $(OBJS_IRC) $(OBJS_GUI) -o $(OUTPUT) $(LIBS_CURSES)
endif
# WeeChat with Gtk+ interface
ifeq ($(GUI), gtk)
OBJS_GTK=gui-gtk.o
LIBS_GTK=
DEFINES=WEE_GTK
gtk: $(OBJS) $(OBJS_IRC) $(OBJS_GUI)
$(CC) $(OPTIONS) $(OBJS) $(OBJS_IRC) $(OBJS_GUI) -o $(OUTPUT) $(LIBS_GTK)
endif
# WeeChat with Qt interface
ifeq ($(GUI), qt)
OBJS_QT=gui-qt.o
LIBS_QT=
DEFINES=WEE_QT
qt: $(OBJS) $(OBJS_IRC) $(OBJS_GUI)
$(CC) $(OPTIONS) $(OBJS) $(OBJS_IRC) $(OBJS_GUI) -o $(OUTPUT) $(LIBS_QT)
endif
# WeeChat with Text interface
ifeq ($(GUI), text)
OBJS_TEXT=gui-text.o
LIBS_TEXT=
DEFINES=WEE_TEXT
text: $(OBJS) $(OBJS_IRC) $(OBJS_GUI)
$(CC) $(OPTIONS) $(OBJS) $(OBJS_IRC) $(OBJS_GUI) -o $(OUTPUT) $(LIBS_TEXT)
endif
all:
make curses GUI=curses
$(OBJS):
$(CC) $(OPTIONS) -o $@ -c $< $(INCLUDES) -D$(DEFINES)
irc/irc.a:
cd irc && make
gui/gui.a:
cd gui && make $(GUI) GUI=$(GUI)
clean:
rm -f *.o *.a *~ core $(OUTPUT)
cd irc && make clean
cd gui && make clean
command.o: command.c weechat.h command.h irc/irc.h gui/gui.h completion.h \
history.h config.h
completion.o: completion.c weechat.h completion.h irc/irc.h gui/gui.h \
history.h command.h
config.o: config.c weechat.h config.h irc/irc.h gui/gui.h completion.h \
history.h
history.o: history.c weechat.h history.h gui/gui.h completion.h
weechat.o: weechat.c weechat.h config.h command.h irc/irc.h gui/gui.h \
completion.h history.h

670
weechat/src/command.c Normal file
View File

@ -0,0 +1,670 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* command.c: WeeChat internal commands */
#include <stdlib.h>
#include <string.h>
#include "weechat.h"
#include "command.h"
#include "irc/irc.h"
#include "config.h"
#include "gui/gui.h"
/* WeeChat internal commands */
t_weechat_command weechat_commands[] =
{ { "alias", N_("create an alias for a command"),
N_("[alias_name [command [arguments]]"),
N_("alias_name: name of alias\ncommand: command name (" WEECHAT_NAME
" or IRC command)\n" "arguments: arguments for command"),
0, MAX_ARGS, weechat_cmd_alias, NULL },
{ "clear", N_("clear window(s)"),
N_("[-all]"),
N_("-all: clear all windows"),
0, 1, weechat_cmd_clear, NULL },
{ "help", N_("display help about commands"),
N_("[command]"), N_("command: name of a " WEECHAT_NAME " or IRC command"),
0, 1, weechat_cmd_help, NULL },
{ "set", N_("set config parameters"),
N_("[option [value]]"), N_("option: name of an option\nvalue: value for option"),
0, 2, weechat_cmd_set, NULL },
{ "unalias", N_("remove an alias"),
N_("alias_name"), N_("alias_name: name of alias to remove"),
1, 1, weechat_cmd_unalias, NULL },
{ NULL, NULL, NULL, NULL, 0, 0, NULL, NULL }
};
t_index_command *index_commands;
t_index_command *last_index_command;
/*
* index_find_pos: find position for a command index (for sorting index)
*/
t_index_command *
index_command_find_pos (char *command)
{
t_index_command *ptr_index;
for (ptr_index = index_commands; ptr_index; ptr_index = ptr_index->next_index)
{
if (strcasecmp (command, ptr_index->command_name) < 0)
return ptr_index;
}
return NULL;
}
/*
* index_command_insert_sorted: insert index into sorted list
*/
void
index_command_insert_sorted (t_index_command *index)
{
t_index_command *pos_index;
pos_index = index_command_find_pos (index->command_name);
if (index_commands)
{
if (pos_index)
{
/* insert index into the list (before index found) */
index->prev_index = pos_index->prev_index;
index->next_index = pos_index;
if (pos_index->prev_index)
pos_index->prev_index->next_index = index;
else
index_commands = index;
pos_index->prev_index = index;
}
else
{
/* add index to the end */
index->prev_index = last_index_command;
index->next_index = NULL;
last_index_command->next_index = index;
last_index_command = index;
}
}
else
{
index->prev_index = NULL;
index->next_index = NULL;
index_commands = index;
last_index_command = index;
}
return;
}
/*
* index_command_build: build an index of commands (internal, irc and alias)
* This list will be sorted, and used for completion
*/
void
index_command_build ()
{
int i;
t_index_command *new_index;
index_commands = NULL;
last_index_command = NULL;
i = 0;
while (weechat_commands[i].command_name)
{
if ((new_index = ((t_index_command *) malloc (sizeof (t_index_command)))))
{
new_index->command_name = strdup (weechat_commands[i].command_name);
index_command_insert_sorted (new_index);
}
i++;
}
i = 0;
while (irc_commands[i].command_name)
{
if (irc_commands[i].cmd_function_args || irc_commands[i].cmd_function_1arg)
{
if ((new_index = ((t_index_command *) malloc (sizeof (t_index_command)))))
{
new_index->command_name = strdup (irc_commands[i].command_name);
index_command_insert_sorted (new_index);
}
}
i++;
}
}
/*
* explode_string: explode a string according to separators
*/
char **
explode_string (char *string, char *separators, int num_items_max,
int *num_items)
{
int i, n_items;
char **array;
char *ptr, *ptr1, *ptr2;
if (num_items != NULL)
*num_items = 0;
n_items = num_items_max;
if (string == NULL)
return NULL;
if (num_items_max == 0)
{
/* calculate number of items */
ptr = string;
i = 1;
while ((ptr = strpbrk (ptr, separators)))
{
while (strchr (separators, ptr[0]) != NULL)
ptr++;
i++;
}
n_items = i;
}
array =
(char **) malloc ((num_items_max ? n_items : n_items + 1) *
sizeof (char *));
ptr1 = string;
ptr2 = string;
for (i = 0; i < n_items; i++)
{
while (strchr (separators, ptr1[0]) != NULL)
ptr1++;
if (i == (n_items - 1) || (ptr2 = strpbrk (ptr1, separators)) == NULL)
if ((ptr2 = strchr (ptr1, '\r')) == NULL)
if ((ptr2 = strchr (ptr1, '\n')) == NULL)
ptr2 = strchr (ptr1, '\0');
if ((ptr1 == NULL) || (ptr2 == NULL))
{
array[i] = NULL;
}
else
{
if (ptr2 - ptr1 > 0)
{
array[i] =
(char *) malloc ((ptr2 - ptr1 + 1) * sizeof (char));
array[i] = strncpy (array[i], ptr1, ptr2 - ptr1);
array[i][ptr2 - ptr1] = '\0';
ptr1 = ++ptr2;
}
else
{
array[i] = NULL;
}
}
}
if (num_items_max == 0)
{
array[i] = NULL;
if (num_items != NULL)
*num_items = i;
}
else
{
if (num_items != NULL)
*num_items = num_items_max;
}
return array;
}
/*
* exec_weechat_command: executes a command (WeeChat internal or IRC)
* returns: 1 if command was executed succesfully
* 0 if error (command not executed)
*/
int
exec_weechat_command (t_irc_server *server, char *string)
{
int i, j, argc, return_code;
char *pos, *ptr_args, **argv;
if ((!string[0]) || (string[0] != '/'))
return 0;
/* look for end of command */
ptr_args = NULL;
pos = strchr (string, ' ');
if (pos)
{
pos[0] = '\0';
pos++;
while (pos[0] == ' ')
pos++;
ptr_args = pos;
if (!ptr_args[0])
ptr_args = NULL;
}
argv = explode_string (ptr_args, " ", 0, &argc);
for (i = 0; weechat_commands[i].command_name; i++)
{
if (strcasecmp (weechat_commands[i].command_name, string + 1) == 0)
{
if ((argc < weechat_commands[i].min_arg)
|| (argc > weechat_commands[i].max_arg))
{
if (weechat_commands[i].min_arg ==
weechat_commands[i].max_arg)
gui_printf (NULL,
_("%s wrong argument count for "
WEECHAT_NAME " command '%s' "
"(expected: %d arg%s)\n"),
WEECHAT_ERROR,
string + 1,
weechat_commands[i].max_arg,
(weechat_commands[i].max_arg >
1) ? "s" : "");
else
gui_printf (NULL,
_("%s wrong argument count for "
WEECHAT_NAME " command '%s' "
"(expected: between %d and %d arg%s)\n"),
WEECHAT_ERROR,
string + 1,
weechat_commands[i].min_arg,
weechat_commands[i].max_arg,
(weechat_commands[i].max_arg >
1) ? "s" : "");
}
else
{
if (weechat_commands[i].cmd_function_args != NULL)
return_code = (int) (weechat_commands[i].cmd_function_args)
(argc, argv);
else
return_code = (int) (weechat_commands[i].cmd_function_1arg)
(ptr_args);
if (return_code < 0)
gui_printf (NULL,
_("%s " WEECHAT_NAME " command \"%s\" failed\n"),
WEECHAT_ERROR, string + 1);
}
if (argv)
{
for (j = 0; argv[j]; j++)
free (argv[j]);
free (argv);
}
return 1;
}
}
for (i = 0; irc_commands[i].command_name; i++)
{
if (strcasecmp (irc_commands[i].command_name, string + 1) == 0)
{
if ((argc < irc_commands[i].min_arg)
|| (argc > irc_commands[i].max_arg))
{
if (irc_commands[i].min_arg == irc_commands[i].max_arg)
gui_printf
(NULL,
_("%s wrong argument count for IRC command '%s' "
"(expected: %d arg%s)\n"),
WEECHAT_ERROR,
string + 1,
irc_commands[i].max_arg,
(irc_commands[i].max_arg > 1) ? "s" : "");
else
gui_printf
(NULL,
_("%s wrong argument count for IRC command '%s' "
"(expected: between %d and %d arg%s)\n"),
WEECHAT_ERROR,
string + 1,
irc_commands[i].min_arg, irc_commands[i].max_arg,
(irc_commands[i].max_arg > 1) ? "s" : "");
}
else
{
if ((irc_commands[i].need_connection) &&
((!server) || (!server->is_connected)))
{
gui_printf (NULL,
_("%s command '%s' needs a server connection!\n"),
WEECHAT_ERROR, irc_commands[i].command_name);
return 0;
}
if (irc_commands[i].cmd_function_args != NULL)
return_code = (int) (irc_commands[i].cmd_function_args)
(server, argc, argv);
else
return_code = (int) (irc_commands[i].cmd_function_1arg)
(server, ptr_args);
if (return_code < 0)
gui_printf (NULL,
_("%s IRC command \"%s\" failed\n"),
WEECHAT_ERROR, string + 1);
}
if (argv)
{
for (j = 0; argv[j]; j++)
free (argv[j]);
free (argv);
}
return 1;
}
}
gui_printf (server->window,
_("%s unknown command '%s' (type /help for help)\n"),
WEECHAT_ERROR,
string + 1);
if (argv)
{
for (j = 0; argv[j]; j++)
free (argv[j]);
free (argv);
}
return 0;
}
/*
* user_command: interprets user command (if beginning with '/')
* any other text is sent to the server, if connected
*/
void
user_command (t_irc_server *server, char *command)
{
t_irc_nick *ptr_nick;
if ((!command) || (command[0] == '\r') || (command[0] == '\n'))
return;
if ((command[0] == '/') && (command[1] != '/'))
{
/* WeeChat internal command (or IRC command) */
exec_weechat_command (server, command);
}
else
{
if ((command[0] == '/') && (command[1] == '/'))
command++;
if (!WIN_IS_SERVER(gui_current_window))
{
server_sendf (server, "PRIVMSG %s :%s\r\n",
CHANNEL(gui_current_window)->name,
command);
if (WIN_IS_PRIVATE(gui_current_window))
{
gui_printf_color_type (CHANNEL(gui_current_window)->window,
MSG_TYPE_NICK,
COLOR_WIN_CHAT_DARK, "<");
gui_printf_color_type (CHANNEL(gui_current_window)->window,
MSG_TYPE_NICK,
COLOR_WIN_NICK_SELF,
"%s", server->nick);
gui_printf_color_type (CHANNEL(gui_current_window)->window,
MSG_TYPE_NICK,
COLOR_WIN_CHAT_DARK, "> ");
gui_printf_color_type (CHANNEL(gui_current_window)->window,
MSG_TYPE_MSG,
COLOR_WIN_CHAT, "%s\n", command);
}
else
{
ptr_nick = nick_search (CHANNEL(gui_current_window), server->nick);
if (ptr_nick)
{
irc_display_nick (CHANNEL(gui_current_window)->window, ptr_nick,
MSG_TYPE_NICK, 1, 1, 0);
gui_printf_color (CHANNEL(gui_current_window)->window,
COLOR_WIN_CHAT, "%s\n", command);
}
else
gui_printf (server->window,
_("%s cannot find nick for sending message\n"),
WEECHAT_ERROR);
}
}
else
gui_printf (server->window, _("This window is not a channel!\n"));
}
}
/*
* weechat_cmd_alias: display or create alias
*/
int
weechat_cmd_alias (int argc, char **argv)
{
if (argc == 0)
{
/* List all aliases */
}
argv = NULL;
gui_printf (NULL, _("(TODO) \"/alias\" command not developed!\n"));
return 0;
}
/*
* weechat_cmd_clear: display or create alias
*/
int
weechat_cmd_clear (int argc, char **argv)
{
if (argc == 1)
{
if (strcmp (argv[0], "-all") == 0)
gui_window_clear_all ();
else
{
gui_printf (NULL,
_("unknown parameter \"%s\" for /clear command\n"),
argv[0]);
return -1;
}
}
else
gui_window_clear (gui_current_window);
return 0;
}
/*
* weechat_cmd_help: display help
*/
int
weechat_cmd_help (int argc, char **argv)
{
int i;
if (argc == 0)
{
gui_printf (NULL,
_("> List of " WEECHAT_NAME " internal commands:\n"));
for (i = 0; weechat_commands[i].command_name; i++)
gui_printf (NULL, " %s - %s\n",
weechat_commands[i].command_name,
weechat_commands[i].command_description);
gui_printf (NULL, _("> List of IRC commands:\n"));
for (i = 0; irc_commands[i].command_name; i++)
if (irc_commands[i].cmd_function_args || irc_commands[i].cmd_function_1arg)
gui_printf (NULL, " %s - %s\n",
irc_commands[i].command_name,
irc_commands[i].command_description);
}
if (argc == 1)
{
for (i = 0; weechat_commands[i].command_name; i++)
{
if (strcasecmp (weechat_commands[i].command_name, argv[0]) == 0)
{
gui_printf
(NULL,
_("> Help on " WEECHAT_NAME " internal command '%s':\n"),
weechat_commands[i].command_name);
gui_printf (NULL,
_("Syntax: /%s %s\n"),
weechat_commands[i].command_name,
(weechat_commands[i].
arguments) ? weechat_commands[i].
arguments : "");
if (weechat_commands[i].arguments_description)
{
gui_printf (NULL, "%s\n",
weechat_commands[i].
arguments_description);
}
return 0;
}
}
for (i = 0; irc_commands[i].command_name; i++)
{
if (strcasecmp (irc_commands[i].command_name, argv[0]) == 0)
{
gui_printf (NULL,
_("> Help on IRC command '%s':\n"),
irc_commands[i].command_name);
gui_printf (NULL, _("Syntax: /%s %s\n"),
irc_commands[i].command_name,
(irc_commands[i].arguments) ?
irc_commands[i].arguments : "");
if (irc_commands[i].arguments_description)
{
gui_printf (NULL, "%s\n",
irc_commands[i].
arguments_description);
}
return 0;
}
}
gui_printf (NULL,
_("No help available, \"%s\" is an unknown command\n"),
argv[0]);
}
return 0;
}
/*
* weechat_cmd_set: set options
*/
int
weechat_cmd_set (int argc, char **argv)
{
int i, j, section_displayed;
char *color_name;
/* TODO: complete /set command */
for (i = 0; i < CONFIG_NUMBER_SECTIONS; i++)
{
section_displayed = 0;
if (i != CONFIG_SECTION_SERVER)
{
for (j = 0; weechat_options[i][j].option_name; j++)
{
if ((argc == 0) ||
((argc > 0)
&& (strstr (weechat_options[i][j].option_name, argv[0])
!= NULL)))
{
if (!section_displayed)
{
gui_printf (NULL, "[%s]\n",
config_sections[i].section_name);
section_displayed = 1;
}
switch (weechat_options[i][j].option_type)
{
case OPTION_TYPE_BOOLEAN:
gui_printf (NULL, " %s = %s\n",
weechat_options[i][j].option_name,
(*weechat_options[i][j].ptr_int) ?
"ON" : "OFF");
break;
case OPTION_TYPE_INT:
gui_printf (NULL,
" %s = %d\n",
weechat_options[i][j].option_name,
*weechat_options[i][j].ptr_int);
break;
case OPTION_TYPE_INT_WITH_STRING:
gui_printf (NULL,
" %s = %s\n",
weechat_options[i][j].option_name,
weechat_options[i][j].array_values[*weechat_options[i][j].ptr_int]);
break;
case OPTION_TYPE_COLOR:
color_name = gui_get_color_by_value (*weechat_options[i][j].ptr_int);
gui_printf (NULL,
" %s = %s\n",
weechat_options[i][j].option_name,
(color_name) ? color_name : _("(unknown)"));
break;
case OPTION_TYPE_STRING:
gui_printf (NULL, " %s = %s\n",
weechat_options[i][j].
option_name,
(*weechat_options[i][j].
ptr_string) ?
*weechat_options[i][j].
ptr_string : "");
break;
}
}
}
}
}
gui_printf (NULL, _("(TODO) \"/set\" command not developed!\n"));
return 0;
}
/*
* cmd_unalias: remove an alias
*/
int
weechat_cmd_unalias (int argc, char **argv)
{
if (argc != 1)
{
gui_printf
(NULL,
_("Wrong argument count for unalias function (expexted: 1 arg)\n"));
return -1;
}
argv = NULL;
gui_printf (NULL, _("(TODO) \"/unalias\" not developed!\n"));
return 0;
}

63
weechat/src/command.h Normal file
View File

@ -0,0 +1,63 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WEECHAT_COMMAND_H
#define __WEECHAT_COMMAND_H 1
#include "irc/irc.h"
#define MAX_ARGS 8192
typedef struct t_weechat_command t_weechat_command;
struct t_weechat_command
{
char *command_name;
char *command_description;
char *arguments;
char *arguments_description;
int min_arg, max_arg;
int (*cmd_function_args)(int, char **);
int (*cmd_function_1arg)(char *);
};
typedef struct t_index_command t_index_command;
struct t_index_command
{
char *command_name;
t_index_command *prev_index;
t_index_command *next_index;
};
extern t_index_command *index_commands;
extern void index_command_build ();
extern int exec_weechat_command (t_irc_server *, char *);
extern void user_command (t_irc_server *, char *);
extern int weechat_cmd_alias(int, char **);
extern int weechat_cmd_clear(int, char **);
extern int weechat_cmd_help (int, char **);
extern int weechat_cmd_set (int, char **);
extern int weechat_cmd_unalias (int, char **);
#endif /* command.h */

199
weechat/src/completion.c Normal file
View File

@ -0,0 +1,199 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* completion.c: completes words according to context (cmd/nick) */
#include <stdlib.h>
#include <string.h>
#include "weechat.h"
#include "completion.h"
#include "irc/irc.h"
#include "command.h"
/*
* completion_init: init completion
*/
void
completion_init (t_completion *completion)
{
completion->position = -1;
completion->base_word = NULL;
}
/*
* completion_command: complete a command
*/
void
completion_command (t_completion *completion)
{
int length, word_found_seen;
t_index_command *ptr_index;
length = strlen (completion->base_word) - 1;
word_found_seen = 0;
for (ptr_index = index_commands; ptr_index; ptr_index = ptr_index->next_index)
{
if (strncasecmp (ptr_index->command_name, completion->base_word + 1, length) == 0)
{
if ((!completion->word_found) || word_found_seen)
{
completion->word_found = ptr_index->command_name;
return;
}
}
if (completion->word_found &&
(strcasecmp (ptr_index->command_name, completion->word_found) == 0))
word_found_seen = 1;
}
if (completion->word_found)
{
completion->word_found = NULL;
completion_command (completion);
}
}
/*
* completion_nick: complete a nick
*/
void
completion_nick (t_completion *completion, t_irc_channel *channel)
{
int length, word_found_seen;
t_irc_nick *ptr_nick;
length = strlen (completion->base_word);
word_found_seen = 0;
for (ptr_nick = channel->nicks; ptr_nick; ptr_nick = ptr_nick->next_nick)
{
if (strncasecmp (ptr_nick->nick, completion->base_word, length) == 0)
{
if ((!completion->word_found) || word_found_seen)
{
completion->word_found = ptr_nick->nick;
return;
}
}
if (completion->word_found &&
(strcasecmp (ptr_nick->nick, completion->word_found) == 0))
word_found_seen = 1;
}
if (completion->word_found)
{
completion->word_found = NULL;
completion_nick (completion, channel);
}
}
/*
* completion_search: complete word according to context
*/
void
completion_search (t_completion *completion, void *channel,
char *buffer, int size, int pos)
{
int i, pos_start, pos_end;
char *old_word_found;
/* TODO: complete when no word is there with command according to context */
if (size == 0)
{
completion->word_found = NULL;
return;
}
/* if new complation => look for base word */
if (pos != completion->position)
{
completion->word_found = NULL;
if ((pos == size) || (buffer[pos-1] != ' '))
pos--;
if ((pos > 0) && (buffer[pos] == ' '))
return;
i = pos;
while ((i >= 0) && (buffer[i] != ' '))
i--;
pos_start = i + 1;
i = pos;
while ((i < size) && (buffer[i] != ' '))
i++;
pos_end = i - 1;
if (pos_start > pos_end)
return;
completion->base_word_pos = pos_start;
if (completion->base_word)
free (completion->base_word);
completion->base_word = (char *) malloc (pos_end - pos_start + 2);
for (i = pos_start; i <= pos_end; i++)
completion->base_word[i - pos_start] = buffer[i];
completion->base_word[pos_end - pos_start + 1] = '\0';
if (completion->base_word[0] == '/')
completion->position_replace = pos_start + 1;
else
completion->position_replace = pos_start;
}
/* completion */
old_word_found = completion->word_found;
if (completion->base_word[0] == '/')
{
completion_command (completion);
if (completion->word_found)
{
if (old_word_found)
completion->diff_size = strlen (completion->word_found) -
strlen (old_word_found);
else
completion->diff_size = strlen (completion->word_found) -
strlen (completion->base_word) + 1;
}
}
else
{
if (channel)
{
completion_nick (completion, (t_irc_channel *)channel);
if (completion->word_found)
{
if (old_word_found)
completion->diff_size = strlen (completion->word_found) -
strlen (old_word_found);
else
completion->diff_size = strlen (completion->word_found) -
strlen (completion->base_word);
}
}
}
}

41
weechat/src/completion.h Normal file
View File

@ -0,0 +1,41 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WEECHAT_COMPLETION_H
#define __WEECHAT_COMPLETION_H 1
typedef struct t_completion t_completion;
struct t_completion
{
char *base_word; /* word to complete (when Tab was pressed) */
int base_word_pos; /* beggining of base word */
int position; /* position where we shoud complete */
char *word_found; /* word found (to replace base word) */
int position_replace; /* position where word should be replaced */
int diff_size; /* size difference (< 0 = char(s) deleted) */
};
extern void completion_init (t_completion *);
extern void completion_search (t_completion *, void *, char *, int, int);
#endif /* completion.h */

1021
weechat/src/config.c Normal file

File diff suppressed because it is too large Load Diff

155
weechat/src/config.h Normal file
View File

@ -0,0 +1,155 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WEECHAT_CONFIG_H
#define __WEECHAT_CONFIG_H 1
#define WEECHAT_CONFIG_NAME "weechat.rc"
#define CONFIG_SECTION_NONE -1
#define CONFIG_SECTION_LOOK 0
#define CONFIG_SECTION_COLORS 1
#define CONFIG_SECTION_HISTORY 2
#define CONFIG_SECTION_LOG 3
#define CONFIG_SECTION_DCC 4
#define CONFIG_SECTION_PROXY 5
#define CONFIG_SECTION_SERVER 6
#define CONFIG_NUMBER_SECTIONS 7
#define OPTION_TYPE_BOOLEAN 1 /* values: on/off */
#define OPTION_TYPE_INT 2 /* values: from min to max */
#define OPTION_TYPE_INT_WITH_STRING 3 /* values: one from **array_values */
#define OPTION_TYPE_COLOR 4 /* values: a color name */
#define OPTION_TYPE_STRING 5 /* values: any string, may be empty */
#define BOOL_FALSE 0
#define BOOL_TRUE 1
#define CFG_LOOK_NICKLIST_LEFT 0
#define CFG_LOOK_NICKLIST_RIGHT 1
#define CFG_LOOK_NICKLIST_TOP 2
#define CFG_LOOK_NICKLIST_BOTTOM 3
typedef struct t_config_section t_config_section;
struct t_config_section
{
int section_number;
char *section_name;
};
typedef struct t_config_option t_config_option;
struct t_config_option
{
char *option_name;
char *short_description;
char *long_description;
int option_type;
int min, max;
int default_int;
char *default_string;
char **array_values;
int *ptr_int;
char **ptr_string;
int (*handler_change)(int *, char **);
};
extern int cfg_look_startup_logo;
extern int cfg_look_startup_version;
extern char *cfg_look_weechat_slogan;
extern int cfg_look_color_nicks;
extern int cfg_look_color_actions;
extern int cfg_look_remove_colors_from_msgs;
extern int cfg_look_nicklist;
extern int cfg_look_nicklist_position;
extern int cfg_look_nicklist_min_size;
extern int cfg_look_nicklist_max_size;
extern int cfg_look_nickmode;
extern int cfg_look_nickmode_empty;
extern char *cfg_look_no_nickname;
extern char *cfg_look_completor;
extern int cfg_col_title;
extern int cfg_col_title_bg;
extern int cfg_col_chat;
extern int cfg_col_chat_time;
extern int cfg_col_chat_time_sep;
extern int cfg_col_chat_prefix1;
extern int cfg_col_chat_prefix2;
extern int cfg_col_chat_nick;
extern int cfg_col_chat_host;
extern int cfg_col_chat_channel;
extern int cfg_col_chat_dark;
extern int cfg_col_chat_bg;
extern int cfg_col_status;
extern int cfg_col_status_active;
extern int cfg_col_status_data_msg;
extern int cfg_col_status_data_other;
extern int cfg_col_status_more;
extern int cfg_col_status_bg;
extern int cfg_col_input;
extern int cfg_col_input_channel;
extern int cfg_col_input_nick;
extern int cfg_col_input_bg;
extern int cfg_col_nick;
extern int cfg_col_nick_op;
extern int cfg_col_nick_halfop;
extern int cfg_col_nick_voice;
extern int cfg_col_nick_sep;
extern int cfg_col_nick_self;
extern int cfg_col_nick_private;
extern int cfg_col_nick_bg;
extern int cfg_history_max_lines;
extern int cfg_history_max_commands;
extern int cfg_log_auto_channels;
extern int cfg_log_auto_private;
extern char *cfg_log_path;
extern char *cfg_log_name;
extern char *cfg_log_timestamp;
extern char *cfg_log_start_string;
extern char *cfg_log_end_string;
extern int cfg_dcc_auto_accept_files;
extern int cfg_dcc_auto_accept_max_size;
extern int cfg_dcc_auto_accept_chats;
extern int cfg_dcc_timeout;
extern char *cfg_dcc_download_path;
extern char *cfg_dcc_upload_path;
extern int cfg_dcc_auto_rename;
extern int cfg_dcc_auto_resume;
extern int cfg_proxy_use;
extern char *cfg_proxy_address;
extern int cfg_proxy_port;
extern char *cfg_proxy_password;
extern t_config_section config_sections [CONFIG_NUMBER_SECTIONS];
extern t_config_option * weechat_options [CONFIG_NUMBER_SECTIONS];
extern int config_read ();
extern int config_create_default ();
extern void config_write ();
#endif /* config.h */

55
weechat/src/gui/Makefile Normal file
View File

@ -0,0 +1,55 @@
# Copyright (c) 2003 FlashCode <flashcode@flashtux.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# WeeChat with Curses interface
ifeq ($(GUI), curses)
curses: curses/gui.a
curses/gui.a:
cd curses && make
endif
# WeeChat with Gtk+ interface
ifeq ($(GUI), gtk)
gtk: gtk/gui.a
gtk/gui.a:
cd gtk && make
endif
# WeeChat with Qt interface
ifeq ($(GUI), qt)
qt: qt/gui.a
qt/gui.a:
cd qt && make
endif
# WeeChat with Text interface
ifeq ($(GUI), text)
text: text/gui.a
text/gui.a:
cd text && make
endif
all:
make curses GUI=curses
clean:
rm -f *.o *.a *~ core
cd curses && make clean
cd gtk && make clean
cd qt && make clean
cd text && make clean

View File

@ -0,0 +1,38 @@
# Copyright (c) 2003 FlashCode <flashcode@flashtux.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
CC=gcc
OPTIONS=-Wall -W -pipe -O2
OUTPUT=../gui.a
OBJS=gui-display.o gui-input.o
DEFINES=WEE_CURSES
all: $(OBJS)
ar r $(OUTPUT) $(OBJS)
$(OBJS):
$(CC) $(OPTIONS) -o $@ -c $< $(INCLUDES) -D$(DEFINES)
clean:
rm -f *.o *.a *~ core
gui-display.o: gui-display.c ../../weechat.h ../gui.h ../../completion.h \
../../history.h ../../config.h ../../irc/irc.h ../../gui/gui.h
gui-input.o: gui-input.c ../../weechat.h ../gui.h ../../completion.h \
../../history.h ../../command.h ../../irc/irc.h ../../gui/gui.h

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,541 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* gui-input: user input functions for Curses GUI */
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include <time.h>
#include <sys/socket.h>
#include <curses.h>
#include "../../weechat.h"
#include "../gui.h"
#include "../../config.h"
#include "../../command.h"
#include "../../irc/irc.h"
/*
* gui_optimize_input_buffer_size: optimize input buffer size by adding
* or deleting data block (predefined size)
*/
void
gui_optimize_input_buffer_size (t_gui_window *window)
{
int optimal_size;
optimal_size = ((window->input_buffer_size / INPUT_BUFFER_BLOCK_SIZE) *
INPUT_BUFFER_BLOCK_SIZE) + INPUT_BUFFER_BLOCK_SIZE;
if (window->input_buffer_alloc != optimal_size)
{
window->input_buffer_alloc = optimal_size;
window->input_buffer = realloc (window->input_buffer, optimal_size);
}
}
/*
* gui_delete_previous_word: delete previous word
*/
void
gui_delete_previous_word ()
{
int i, j, num_char_deleted, num_char_end;
if (gui_current_window->input_buffer_pos > 0)
{
i = gui_current_window->input_buffer_pos - 1;
while ((i >= 0) &&
(gui_current_window->input_buffer[i] == ' '))
i--;
if (i >= 0)
{
while ((i >= 0) &&
(gui_current_window->input_buffer[i] != ' '))
i--;
if (i >= 0)
{
while ((i >= 0) &&
(gui_current_window->input_buffer[i] == ' '))
i--;
}
}
if (i >= 0)
i++;
i++;
num_char_deleted = gui_current_window->input_buffer_pos - i;
num_char_end = gui_current_window->input_buffer_size -
gui_current_window->input_buffer_pos;
for (j = 0; j < num_char_end; j++)
gui_current_window->input_buffer[i + j] =
gui_current_window->input_buffer[gui_current_window->input_buffer_pos + j];
gui_current_window->input_buffer_size -= num_char_deleted;
gui_current_window->input_buffer[gui_current_window->input_buffer_size] = '\0';
gui_current_window->input_buffer_pos = i;
gui_draw_window_input (gui_current_window);
gui_optimize_input_buffer_size (gui_current_window);
gui_current_window->completion.position = -1;
}
}
/*
* gui_move_previous_word: move to beginning of previous word
*/
void
gui_move_previous_word ()
{
int i;
if (gui_current_window->input_buffer_pos > 0)
{
i = gui_current_window->input_buffer_pos - 1;
while ((i >= 0) &&
(gui_current_window->input_buffer[i] == ' '))
i--;
if (i < 0)
gui_current_window->input_buffer_pos = 0;
else
{
while ((i >= 0) &&
(gui_current_window->input_buffer[i] != ' '))
i--;
gui_current_window->input_buffer_pos = i + 1;
}
gui_draw_window_input (gui_current_window);
}
}
/*
* gui_move_next_word: move to the end of next
*/
void
gui_move_next_word ()
{
int i;
if (gui_current_window->input_buffer_pos <
gui_current_window->input_buffer_size + 1)
{
i = gui_current_window->input_buffer_pos;
while ((i <= gui_current_window->input_buffer_size) &&
(gui_current_window->input_buffer[i] == ' '))
i++;
if (i > gui_current_window->input_buffer_size)
gui_current_window->input_buffer_pos = i - 1;
else
{
while ((i <= gui_current_window->input_buffer_size) &&
(gui_current_window->input_buffer[i] != ' '))
i++;
if (i > gui_current_window->input_buffer_size)
gui_current_window->input_buffer_pos =
gui_current_window->input_buffer_size;
else
gui_current_window->input_buffer_pos = i;
}
gui_draw_window_input (gui_current_window);
}
}
/*
* gui_buffer_insert_string: insert a string into the input buffer
*/
void
gui_buffer_insert_string (char *string, int pos)
{
int i, start, end, length;
length = strlen (string);
/* increase buffer size */
gui_current_window->input_buffer_size += length;
gui_optimize_input_buffer_size (gui_current_window);
gui_current_window->input_buffer[gui_current_window->input_buffer_size] = '\0';
/* move end of string to the right */
start = pos + length;
end = gui_current_window->input_buffer_size - 1;
for (i = end; i >= start; i--)
gui_current_window->input_buffer[i] =
gui_current_window->input_buffer[i - length];
/* insert new string */
strncpy (gui_current_window->input_buffer + pos, string, length);
}
/*
* gui_read_keyb: read keyboard line
*/
void
gui_read_keyb ()
{
int key, i;
t_gui_window *ptr_window;
char new_char[2];
key = getch ();
if (key != ERR)
{
switch (key)
{
/* resize event: do nothing */
case KEY_RESIZE:
gui_redraw_window (gui_current_window);
break;
case KEY_F(6):
gui_switch_to_previous_window ();
break;
/* next window */
case KEY_F(7):
gui_switch_to_next_window ();
break;
/* cursor up */
case KEY_UP:
if (gui_current_window->ptr_history)
{
gui_current_window->ptr_history =
gui_current_window->ptr_history->next_history;
if (!gui_current_window->ptr_history)
gui_current_window->ptr_history =
gui_current_window->history;
}
else
gui_current_window->ptr_history =
gui_current_window->history;
if (gui_current_window->ptr_history)
{
gui_current_window->input_buffer_size =
strlen (gui_current_window->ptr_history->text);
gui_optimize_input_buffer_size (gui_current_window);
gui_current_window->input_buffer_pos =
gui_current_window->input_buffer_size;
strcpy (gui_current_window->input_buffer,
gui_current_window->ptr_history->text);
gui_draw_window_input (gui_current_window);
}
break;
/* cursor down */
case KEY_DOWN:
if (gui_current_window->ptr_history)
{
gui_current_window->ptr_history =
gui_current_window->ptr_history->prev_history;
if (gui_current_window->ptr_history)
gui_current_window->input_buffer_size =
strlen (gui_current_window->ptr_history->text);
else
gui_current_window->input_buffer_size = 0;
gui_optimize_input_buffer_size (gui_current_window);
gui_current_window->input_buffer_pos =
gui_current_window->input_buffer_size;
if (gui_current_window->ptr_history)
strcpy (gui_current_window->input_buffer,
gui_current_window->ptr_history->text);
gui_draw_window_input (gui_current_window);
}
break;
/* cursor left */
case KEY_LEFT:
if (gui_current_window->input_buffer_pos > 0)
{
gui_current_window->input_buffer_pos--;
gui_draw_window_input (gui_current_window);
}
break;
/* cursor right */
case KEY_RIGHT:
if (gui_current_window->input_buffer_pos <
gui_current_window->input_buffer_size)
{
gui_current_window->input_buffer_pos++;
gui_draw_window_input (gui_current_window);
}
break;
/* home key */
case KEY_HOME:
if (gui_current_window->input_buffer_pos > 0)
{
gui_current_window->input_buffer_pos = 0;
gui_draw_window_input (gui_current_window);
}
break;
/* end key */
case KEY_END:
if (gui_current_window->input_buffer_pos <
gui_current_window->input_buffer_size)
{
gui_current_window->input_buffer_pos =
gui_current_window->input_buffer_size;
gui_draw_window_input (gui_current_window);
}
break;
/* page up */
case KEY_PPAGE:
gui_move_page_up ();
break;
/* page down */
case KEY_NPAGE:
gui_move_page_down ();
break;
/* erase before cursor and move cursor to the left */
case 127:
case KEY_BACKSPACE:
if (gui_current_window->input_buffer_pos > 0)
{
i = gui_current_window->input_buffer_pos-1;
while (gui_current_window->input_buffer[i])
{
gui_current_window->input_buffer[i] =
gui_current_window->input_buffer[i+1];
i++;
}
gui_current_window->input_buffer_size--;
gui_current_window->input_buffer_pos--;
gui_current_window->input_buffer[gui_current_window->input_buffer_size] = '\0';
gui_draw_window_input (gui_current_window);
gui_optimize_input_buffer_size (gui_current_window);
gui_current_window->completion.position = -1;
}
break;
/* Control + Backspace */
case 0x08:
gui_delete_previous_word ();
break;
/* erase char under cursor */
case KEY_DC:
if (gui_current_window->input_buffer_pos <
gui_current_window->input_buffer_size)
{
i = gui_current_window->input_buffer_pos;
while (gui_current_window->input_buffer[i])
{
gui_current_window->input_buffer[i] =
gui_current_window->input_buffer[i+1];
i++;
}
gui_current_window->input_buffer_size--;
gui_current_window->input_buffer[gui_current_window->input_buffer_size] = '\0';
gui_draw_window_input (gui_current_window);
gui_optimize_input_buffer_size (gui_current_window);
gui_current_window->completion.position = -1;
}
break;
/* Tab : completion */
case '\t':
completion_search (&(gui_current_window->completion),
CHANNEL(gui_current_window),
gui_current_window->input_buffer,
gui_current_window->input_buffer_size,
gui_current_window->input_buffer_pos);
if (gui_current_window->completion.word_found)
{
// replace word with new completed word into input buffer
gui_current_window->input_buffer_size +=
gui_current_window->completion.diff_size;
gui_optimize_input_buffer_size (gui_current_window);
gui_current_window->input_buffer[gui_current_window->input_buffer_size] = '\0';
if (gui_current_window->completion.diff_size > 0)
{
for (i = gui_current_window->input_buffer_size - 1;
i >= gui_current_window->completion.position_replace +
(int)strlen (gui_current_window->completion.word_found); i--)
gui_current_window->input_buffer[i] =
gui_current_window->input_buffer[i -
gui_current_window->completion.diff_size];
}
else
{
for (i = gui_current_window->completion.position_replace +
strlen (gui_current_window->completion.word_found);
i < gui_current_window->input_buffer_size; i++)
gui_current_window->input_buffer[i] =
gui_current_window->input_buffer[i -
gui_current_window->completion.diff_size];
}
strncpy (gui_current_window->input_buffer + gui_current_window->completion.position_replace,
gui_current_window->completion.word_found,
strlen (gui_current_window->completion.word_found));
gui_current_window->input_buffer_pos =
gui_current_window->completion.position_replace +
strlen (gui_current_window->completion.word_found);
gui_current_window->completion.position =
gui_current_window->input_buffer_pos;
/* add space or completor to the end of completion, if needed */
if (gui_current_window->completion.base_word[0] == '/')
{
if (gui_current_window->input_buffer[gui_current_window->input_buffer_pos] != ' ')
gui_buffer_insert_string (" ",
gui_current_window->input_buffer_pos);
gui_current_window->completion.position++;
gui_current_window->input_buffer_pos++;
}
else
{
if (gui_current_window->completion.base_word_pos == 0)
{
if (strncmp (gui_current_window->input_buffer + gui_current_window->input_buffer_pos,
cfg_look_completor, strlen (cfg_look_completor)) != 0)
gui_buffer_insert_string (cfg_look_completor,
gui_current_window->input_buffer_pos);
gui_current_window->completion.position += strlen (cfg_look_completor);
gui_current_window->input_buffer_pos += strlen (cfg_look_completor);
if (gui_current_window->input_buffer[gui_current_window->input_buffer_pos] != ' ')
gui_buffer_insert_string (" ",
gui_current_window->input_buffer_pos);
gui_current_window->completion.position++;
gui_current_window->input_buffer_pos++;
}
}
gui_draw_window_input (gui_current_window);
}
break;
/* escape code (for control-key) */
case KEY_ESCAPE:
if ((key = getch()) != ERR)
{
switch (key)
{
case KEY_LEFT:
gui_switch_to_previous_window ();
break;
case KEY_RIGHT:
gui_switch_to_next_window ();
break;
case 79:
/* TODO: replace 79 by constant name! */
if (key == 79)
{
if ((key = getch()) != ERR)
{
switch (key)
{
/* Control + Right */
case 99:
gui_move_next_word ();
break;
/* Control + Left */
case 100:
gui_move_previous_word ();
break;
}
}
}
break;
}
}
break;
/* send command/message */
case '\n':
if (gui_current_window->input_buffer_size > 0)
{
gui_current_window->input_buffer[gui_current_window->input_buffer_size] = '\0';
history_add (gui_current_window, gui_current_window->input_buffer);
gui_current_window->input_buffer_size = 0;
gui_current_window->input_buffer_pos = 0;
gui_current_window->input_buffer_1st_display = 0;
gui_current_window->completion.position = -1;
gui_current_window->ptr_history = NULL;
ptr_window = gui_current_window;
user_command (SERVER(gui_current_window),
gui_current_window->input_buffer);
if (ptr_window == gui_current_window)
gui_draw_window_input (ptr_window);
if (ptr_window)
ptr_window->input_buffer[0] = '\0';
}
break;
/* other key => add to input buffer */
default:
/*gui_printf (gui_current_window,
"[Debug] key pressed = %d, as octal: %o\n", key, key);*/
new_char[0] = key;
new_char[1] = '\0';
gui_buffer_insert_string (new_char,
gui_current_window->input_buffer_pos);
gui_current_window->input_buffer_pos++;
gui_draw_window_input (gui_current_window);
gui_current_window->completion.position = -1;
break;
}
}
}
/*
* gui_main_loop: main loop for WeeChat with ncurses GUI
*/
void
gui_main_loop ()
{
fd_set read_fd;
static struct timeval timeout;
t_irc_server *ptr_server;
quit_weechat = 0;
while (!quit_weechat)
{
timeout.tv_sec = 0;
timeout.tv_usec = 10000;
FD_ZERO (&read_fd);
FD_SET (STDIN_FILENO, &read_fd);
for (ptr_server = irc_servers; ptr_server;
ptr_server = ptr_server->next_server)
{
if (ptr_server->sock4 >= 0)
FD_SET (ptr_server->sock4, &read_fd);
}
if (select (FD_SETSIZE, &read_fd, NULL, NULL, &timeout))
{
if (FD_ISSET (STDIN_FILENO, &read_fd))
{
gui_read_keyb ();
}
else
{
for (ptr_server = irc_servers; ptr_server;
ptr_server = ptr_server->next_server)
{
if ((ptr_server->sock4 >= 0) &&
(FD_ISSET (ptr_server->sock4, &read_fd)))
server_recv (ptr_server);
}
}
}
}
}

View File

@ -0,0 +1,37 @@
# Copyright (c) 2003 FlashCode <flashcode@flashtux.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
CC=gcc
OPTIONS=-Wall -W -pipe -O2
OUTPUT=../gui.a
OBJS=gui-display.o gui-input.o
DEFINES=WEE_GTK
all: $(OBJS)
ar r $(OUTPUT) $(OBJS)
$(OBJS):
$(CC) $(OPTIONS) -o $@ -c $< $(INCLUDES) -D$(DEFINES)
clean:
rm -f *.o *.a *~ core
gui-display.o: gui-display.c ../../weechat.h ../gui.h ../../config.h \
../../irc/irc.h ../../gui/gui.h
gui-input.o: gui-input.c ../../weechat.h ../gui.h

View File

@ -0,0 +1,26 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* gui-gtk.c: Gtk+ GUI for WeeChat */
/* ***** Gtk+ GUI for WeeChat, NOT developed! ***** */

View File

@ -0,0 +1,26 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WEECHAT_GUI_GTK_H
#define __WEECHAT_GUI_GTK_H 1
#endif /* gui-gtk.h */

229
weechat/src/gui/gui.h Normal file
View File

@ -0,0 +1,229 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WEECHAT_GUI_H
#define __WEECHAT_GUI_H 1
#ifdef WEE_CURSES
#include <curses.h>
#endif
#include "../completion.h"
#include "../history.h"
#ifdef WEE_CURSES
#define KEY_ESCAPE 27
#endif
#define INPUT_BUFFER_BLOCK_SIZE 256
#define NUM_COLORS 35
#define COLOR_WIN_TITLE 1
#define COLOR_WIN_CHAT 2
#define COLOR_WIN_CHAT_TIME 3
#define COLOR_WIN_CHAT_TIME_SEP 4
#define COLOR_WIN_CHAT_PREFIX1 5
#define COLOR_WIN_CHAT_PREFIX2 6
#define COLOR_WIN_CHAT_NICK 7
#define COLOR_WIN_CHAT_HOST 8
#define COLOR_WIN_CHAT_CHANNEL 9
#define COLOR_WIN_CHAT_DARK 10
#define COLOR_WIN_STATUS 11
#define COLOR_WIN_STATUS_ACTIVE 12
#define COLOR_WIN_STATUS_DATA_MSG 13
#define COLOR_WIN_STATUS_DATA_OTHER 14
#define COLOR_WIN_STATUS_MORE 15
#define COLOR_WIN_INPUT 16
#define COLOR_WIN_INPUT_CHANNEL 17
#define COLOR_WIN_INPUT_NICK 18
#define COLOR_WIN_NICK 19
#define COLOR_WIN_NICK_OP 20
#define COLOR_WIN_NICK_HALFOP 21
#define COLOR_WIN_NICK_VOICE 22
#define COLOR_WIN_NICK_SEP 23
#define COLOR_WIN_NICK_SELF 24
#define COLOR_WIN_NICK_PRIVATE 25
#define COLOR_WIN_NICK_FIRST 26
#define COLOR_WIN_NICK_LAST 35
#define COLOR_WIN_NICK_NUMBER (COLOR_WIN_NICK_LAST - COLOR_WIN_NICK_FIRST + 1)
#define SERVER(window) ((t_irc_server *)(window->server))
#define CHANNEL(window) ((t_irc_channel *)(window->channel))
#define WIN_IS_SERVER(window) (SERVER(window) && !CHANNEL(window))
#define WIN_IS_CHANNEL(window) (CHANNEL(window) && (CHANNEL(window)->type == CHAT_CHANNEL))
#define WIN_IS_PRIVATE(window) (CHANNEL(window) && (CHANNEL(window)->type == CHAT_PRIVATE))
#define MSG_TYPE_TIME 0
#define MSG_TYPE_NICK 1
#define MSG_TYPE_INFO 2
#define MSG_TYPE_MSG 3
#define gui_printf_color(window, color, fmt, argz...) \
gui_printf_color_type(window, MSG_TYPE_INFO, color, fmt, ##argz)
#define gui_printf(window, fmt, argz...) \
gui_printf_color_type(window, MSG_TYPE_INFO, -1, fmt, ##argz)
typedef struct t_gui_message t_gui_message;
struct t_gui_message
{
int type; /* type of message (time, nick, other) */
int color; /* color of message */
char *message; /* message content */
t_gui_message *prev_message; /* link to previous message for line */
t_gui_message *next_message; /* link to next message for line */
};
typedef struct t_gui_line t_gui_line;
struct t_gui_line
{
int length; /* length of the line (in char) */
int length_align; /* alignment length (time or time/nick) */
int line_with_message; /* line contains a message from a user? */
t_gui_message *messages; /* messages for the line */
t_gui_message *last_message; /* last message of the line */
t_gui_line *prev_line; /* link to previous line */
t_gui_line *next_line; /* link to next line */
};
typedef struct t_gui_color t_gui_color;
struct t_gui_color
{
char *name;
int color;
};
typedef struct t_gui_window t_gui_window;
struct t_gui_window
{
/* server/channel */
void *server; /* window's server */
void *channel; /* window's channel */
/* global position & size */
int win_x, win_y; /* position of window */
int win_width, win_height; /* window geometry */
/* chat window settings */
int win_chat_x, win_chat_y; /* chat window position */
int win_chat_width; /* width of chat window */
int win_chat_height; /* height of chat window */
int win_chat_cursor_x; /* position of cursor in chat window */
int win_chat_cursor_y; /* position of cursor in chat window */
/* nicklist window settings */
int win_nick_x, win_nick_y; /* chat window position */
int win_nick_width; /* width of chat window */
int win_nick_height; /* height of chat window */
/* windows */
#ifdef WEE_CURSES
WINDOW *win_title; /* title window */
WINDOW *win_chat; /* chat window (exemple: channel) */
WINDOW *win_nick; /* nick window */
WINDOW *win_status; /* status window */
WINDOW *win_input; /* input window */
#endif
#ifdef WEE_GTK
/* TODO: declare Gtk+ window */
#endif
#ifdef WEE_QT
/* TODO: declare Qt window */
#endif
/* chat content (lines, line is composed by many messages) */
t_gui_line *lines; /* lines of chat window */
t_gui_line *last_line; /* last line of chat window */
int first_line_displayed; /* = 1 if first line is displayed */
int sub_lines; /* if > 0 then do not display until end */
int line_complete; /* current line complete ? (\n ending) */
int unread_data; /* highlight windows with unread data */
/* inupt buffer */
char *input_buffer; /* input buffer */
int input_buffer_alloc; /* input buffer: allocated size in mem */
int input_buffer_size; /* buffer size (user input length) */
int input_buffer_pos; /* position into buffer */
int input_buffer_1st_display; /* first char displayed on screen */
/* completion */
t_completion completion; /* for cmds/nicks completion */
/* history */
t_history *history; /* commands history */
t_history *ptr_history; /* current command in history */
/* link to next window */
t_gui_window *prev_window; /* link to previous window */
t_gui_window *next_window; /* link to next window */
};
/* variables */
extern int gui_ready;
extern t_gui_window *gui_windows;
extern t_gui_window *gui_current_window;
/* prototypes */
extern int gui_assign_color (int *, char *);
extern int gui_get_color_by_name (char *);
extern char *gui_get_color_by_value (int);
extern void gui_draw_window_title (t_gui_window *);
extern void gui_redraw_window_title (t_gui_window *);
extern void gui_draw_window_chat (t_gui_window *);
extern void gui_redraw_window_chat (t_gui_window *);
extern void gui_draw_window_nick (t_gui_window *);
extern void gui_redraw_window_nick (t_gui_window *);
extern void gui_draw_window_status (t_gui_window *);
extern void gui_redraw_window_status (t_gui_window *);
extern void gui_draw_window_input (t_gui_window *);
extern void gui_redraw_window_input (t_gui_window *);
extern void gui_redraw_window (t_gui_window *);
extern void gui_window_clear (t_gui_window *);
extern void gui_window_clear_all ();
extern void gui_switch_to_window (t_gui_window *);
extern void gui_switch_to_previous_window ();
extern void gui_switch_to_next_window ();
extern void gui_move_page_up ();
extern void gui_move_page_down ();
extern void gui_init ();
/* TODO: add coordinates and size */
extern t_gui_window *gui_window_new (void *, void * /*int, int, int, int*/);
extern void gui_window_free (t_gui_window *);
extern void gui_end ();
extern void gui_printf_color_type (t_gui_window *, int, int, char *, ...);
extern void gui_display_nick (t_gui_window *, void *, int, int, int, int);
extern void gui_main_loop ();
#endif /* gui.h */

View File

@ -0,0 +1,37 @@
# Copyright (c) 2003 FlashCode <flashcode@flashtux.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
CC=gcc
OPTIONS=-Wall -W -pipe -O2
OUTPUT=../gui.a
OBJS=gui-display.o gui-input.o
DEFINES=WEE_QT
all: $(OBJS)
ar r $(OUTPUT) $(OBJS)
$(OBJS):
$(CC) $(OPTIONS) -o $@ -c $< $(INCLUDES) -D$(DEFINES)
clean:
rm -f *.o *.a *~ core
gui-display.o: gui-display.c ../../weechat.h ../gui.h ../../config.h \
../../irc/irc.h ../../gui/gui.h
gui-input.o: gui-input.c ../../weechat.h ../gui.h

View File

@ -0,0 +1,26 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* gui-qt.c: Qt GUI for WeeChat */
/* ***** Qt GUI for WeeChat, NOT developed! ***** */

View File

@ -0,0 +1,26 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WEECHAT_GUI_QT_H
#define __WEECHAT_GUI_QT_H 1
#endif /* gui-qt.h */

View File

@ -0,0 +1,37 @@
# Copyright (c) 2003 FlashCode <flashcode@flashtux.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
CC=gcc
OPTIONS=-Wall -W -pipe -O2
OUTPUT=../gui.a
OBJS=gui-display.o gui-input.o
DEFINES=WEE_TEXT
all: $(OBJS)
ar r $(OUTPUT) $(OBJS)
$(OBJS):
$(CC) $(OPTIONS) -o $@ -c $< $(INCLUDES) -D$(DEFINES)
clean:
rm -f *.o *.a *~ core
gui-display.o: gui-display.c ../../weechat.h ../gui.h ../../config.h \
../../irc/irc.h ../../gui/gui.h
gui-input.o: gui-input.c ../../weechat.h ../gui.h

View File

@ -0,0 +1,164 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* gui-text.c: text GUI - display functions */
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/socket.h>
#include "weechat.h"
#include "gui-text.h"
#include "command.h"
#include "irc.h"
/*
* gui_init: init GUI
*/
void
gui_init ()
{
}
/*
* gui_init_irc_window: allocates a window for a channel or server
*/
void
gui_init_irc_window (t_irc_window * window)
{
/* no window in text GUI */
window->text = NULL;
window->window = NULL;
}
/*
* gui_free_irc_window: free a GUI window
*/
void
gui_free_irc_window (t_irc_window * window)
{
/* no window in text GUI */
}
/*
* gui_end: GUI end
*/
void
gui_end ()
{
}
/*
* read_keyb: read keyboard line
*/
void
read_keyb ()
{
int num_read;
static char buffer[4096];
static int pos_buffer = 0;
char buffer_tmp[1024];
int pos_buffer_tmp;
num_read = read (STDIN_FILENO, buffer_tmp, sizeof (buffer_tmp) - 1);
pos_buffer_tmp = 0;
while (pos_buffer_tmp < num_read)
{
switch (buffer_tmp[pos_buffer_tmp])
{
case '\r':
break;
case '\n':
buffer[pos_buffer] = '\0';
pos_buffer = 0;
user_command (buffer);
break;
default:
buffer[pos_buffer] = buffer_tmp[pos_buffer_tmp];
if (pos_buffer < (int) (sizeof (buffer) - 2))
pos_buffer++;
}
pos_buffer_tmp++;
}
}
/*
* gui_main_loop: main loop for WeeChat with text GUI
*/
void
gui_main_loop ()
{
struct timeval timeout;
fd_set read_fd;
t_irc_server *ptr_server;
quit_weechat = 0;
while (!quit_weechat)
{
timeout.tv_sec = 0;
timeout.tv_usec = 10000;
FD_ZERO (&read_fd);
FD_SET (STDIN_FILENO, &read_fd);
for (ptr_server = irc_servers; ptr_server;
ptr_server = ptr_server->next_server)
{
FD_SET (ptr_server->sock4, &read_fd);
}
select (FD_SETSIZE, &read_fd, NULL, NULL, &timeout);
if (FD_ISSET (STDIN_FILENO, &read_fd))
{
read_keyb ();
}
for (ptr_server = irc_servers; ptr_server;
ptr_server = ptr_server->next_server)
{
if (FD_ISSET (ptr_server->sock4, &read_fd))
recv_from_server (ptr_server);
}
}
}
/*
* gui_display_message: display a message on the screen
*/
void
gui_display_message (char *message)
{
printf ("%s\n", message);
}

View File

@ -0,0 +1,26 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WEECHAT_GUI_TEXT_H
#define __WEECHAT_GUI_TEXT_H 1
#endif /* gui-text.h */

66
weechat/src/history.c Normal file
View File

@ -0,0 +1,66 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* history.c: memorize and call again commands or text */
#include <stdlib.h>
#include <string.h>
#include "weechat.h"
#include "history.h"
#include "gui/gui.h"
t_history *history_general = NULL;
t_history *history_general_ptr = NULL;
/*
* history_add: add a text/command to history
*/
void
history_add (void *window, char *string)
{
t_history *new_history;
new_history = (t_history *)malloc (sizeof (t_history));
if (new_history)
{
new_history->text = strdup (string);
/* add history to general history */
if (history_general)
history_general->prev_history = new_history;
new_history->next_history = history_general;
new_history->prev_history = NULL;
history_general = new_history;
/* add history to local history */
if (((t_gui_window *)(window))->history)
((t_gui_window *)(window))->history->prev_history = new_history;
new_history->next_history = ((t_gui_window *)(window))->history;
new_history->prev_history = NULL;
((t_gui_window *)window)->history = new_history;
}
}

37
weechat/src/history.h Normal file
View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WEECHAT_HISTORY_H
#define __WEECHAT_HISTORY_H 1
typedef struct t_history t_history;
struct t_history
{
char *text; /* text or command (as entered by user) */
t_history *next_history; /* link to next text/command */
t_history *prev_history; /* link to previous text/command */
};
extern void history_add (void *, char *);
#endif /* history.h */

44
weechat/src/irc/Makefile Normal file
View File

@ -0,0 +1,44 @@
# Copyright (c) 2003 FlashCode <flashcode@flashtux.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
CC=gcc
OPTIONS=-Wall -W -pipe -O2
OUTPUT=irc.a
OBJS=irc-commands.o irc-display.o irc-server.o irc-channel.o irc-nick.o
DEFINES=WEE_CURSES
all: $(OBJS)
ar r $(OUTPUT) $(OBJS)
$(OBJS):
$(CC) $(OPTIONS) -o $@ -c $< $(INCLUDES) -D$(DEFINES)
clean:
rm -f *.o *.a *~ core
irc-channel.o: irc-channel.c ../weechat.h irc.h ../gui/gui.h \
../completion.h ../history.h
irc-commands.o: irc-commands.c ../weechat.h irc.h ../gui/gui.h \
../completion.h ../history.h ../command.h ../irc/irc.h ../config.h
irc-display.o: irc-display.c ../weechat.h irc.h ../gui/gui.h \
../completion.h ../history.h
irc-nick.o: irc-nick.c ../weechat.h irc.h ../gui/gui.h ../completion.h \
../history.h
irc-server.o: irc-server.c ../weechat.h irc.h ../gui/gui.h \
../completion.h ../history.h

View File

@ -0,0 +1,153 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* irc-channel.c: manages a chat (channel or private chat) */
#include <stdlib.h>
#include <string.h>
#include "../weechat.h"
#include "irc.h"
t_irc_channel *current_channel = NULL;
/*
* channel_new: allocate a new channel for a server and add it to the server queue
*/
t_irc_channel *
channel_new (t_irc_server *server, int channel_type, char *channel_name)
{
t_irc_channel *new_channel;
#if DEBUG >= 1
log_printf ("joining channel %s\n", channel_name);
#endif
/* alloc memory for new channel */
if ((new_channel = (t_irc_channel *) malloc (sizeof (t_irc_channel))) == NULL)
{
fprintf (stderr, _("%s cannot allocate new channel"), WEECHAT_ERROR);
return NULL;
}
/* initialize new channel */
new_channel->type = channel_type;
new_channel->name = strdup (channel_name);
new_channel->topic = NULL;
new_channel->nicks = NULL;
new_channel->last_nick = NULL;
/* add new channel to queue */
new_channel->prev_channel = server->last_channel;
new_channel->next_channel = NULL;
if (server->channels)
server->last_channel->next_channel = new_channel;
else
server->channels = new_channel;
server->last_channel = new_channel;
gui_window_new (server, new_channel);
/* all is ok, return address of new channel */
return new_channel;
}
/*
* channel_free: free a channel and remove it from channels queue
*/
void
channel_free (t_irc_server *server, t_irc_channel *channel)
{
t_irc_channel *new_channels;
/* remove channel from queue */
if (server->last_channel == channel)
server->last_channel = channel->prev_channel;
if (channel->prev_channel)
{
(channel->prev_channel)->next_channel = channel->next_channel;
new_channels = server->channels;
}
else
new_channels = channel->next_channel;
if (channel->next_channel)
(channel->next_channel)->prev_channel = channel->prev_channel;
/* free data */
if (channel->name)
free (channel->name);
if (channel->topic)
free (channel->topic);
nick_free_all (channel);
free (channel);
server->channels = new_channels;
}
/*
* channel_free_all: free all allocated channels
*/
void
channel_free_all (t_irc_server *server)
{
/* remove all channels for the server */
while (server->channels)
channel_free (server, server->channels);
}
/*
* channel_search: returns pointer on a channel with name
*/
t_irc_channel *
channel_search (t_irc_server *server, char *channel_name)
{
t_irc_channel *ptr_channel;
for (ptr_channel = server->channels; ptr_channel;
ptr_channel = ptr_channel->next_channel)
{
if (strcasecmp (ptr_channel->name, channel_name) == 0)
return ptr_channel;
}
return NULL;
}
/*
* string_is_channel: returns 1 if string is channel
*/
int
string_is_channel (char *string)
{
char first_char[2];
first_char[0] = string[0];
first_char[1] = '\0';
return (strpbrk (first_char, CHANNEL_PREFIX)) ? 1 : 0;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,127 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* irc-display.c: display functions for IRC */
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include "../weechat.h"
#include "irc.h"
#include "../config.h"
#include "../gui/gui.h"
/*
* irc_display_prefix: display prefix for action or info message
* prefix must be 3 chars length
*/
void
irc_display_prefix (t_gui_window *window, char *prefix)
{
if (prefix[0] == prefix[2])
{
gui_printf_color (window, COLOR_WIN_CHAT_PREFIX1, "%c", prefix[0]);
gui_printf_color (window, COLOR_WIN_CHAT_PREFIX2, "%c", prefix[1]);
gui_printf_color (window, COLOR_WIN_CHAT_PREFIX1, "%c ", prefix[2]);
}
else
gui_printf_color (window, COLOR_WIN_CHAT_PREFIX1, "%s ", prefix);
}
/*
* irc_display_nick: display nick in chat window
*/
void
irc_display_nick (t_gui_window *window, t_irc_nick *nick, int message_type,
int display_around, int color_nick, int no_nickmode)
{
if (display_around)
gui_printf_color_type (window,
message_type, COLOR_WIN_CHAT_DARK, "<");
if (cfg_look_nickmode)
{
if (nick->is_op)
gui_printf_color_type (window,
message_type,
COLOR_WIN_NICK_OP, "@");
else
{
if (nick->is_halfop)
gui_printf_color_type (window,
message_type,
COLOR_WIN_NICK_HALFOP, "%%");
else
{
if (nick->has_voice)
gui_printf_color_type (window,
message_type,
COLOR_WIN_NICK_VOICE, "+");
else
if (cfg_look_nickmode_empty && !no_nickmode)
gui_printf_color_type (window,
message_type,
COLOR_WIN_CHAT, " ");
}
}
}
gui_printf_color_type (window,
message_type,
(color_nick) ?
((cfg_look_color_nicks) ?
nick->color : COLOR_WIN_CHAT) :
COLOR_WIN_CHAT,
"%s", nick->nick);
if (display_around)
gui_printf_color_type (window,
message_type, COLOR_WIN_CHAT_DARK, "> ");
}
/*
* irc_display_mode: display IRC message for mode change
*/
void
irc_display_mode (t_gui_window *window, char *channel_name, char set_flag,
char *symbol, char *nick_host, char *message, char *param)
{
irc_display_prefix (window, PREFIX_INFO);
gui_printf_color (window, COLOR_WIN_CHAT_DARK, "[");
gui_printf_color (window, COLOR_WIN_CHAT_CHANNEL, "%s", channel_name);
gui_printf_color (window, COLOR_WIN_CHAT, "/");
gui_printf_color (window, COLOR_WIN_CHAT_CHANNEL, "%c%s", set_flag, symbol);
gui_printf_color (window, COLOR_WIN_CHAT_DARK, "] ");
gui_printf_color (window, COLOR_WIN_CHAT_NICK, "%s", nick_host);
if (param)
{
gui_printf_color (window, COLOR_WIN_CHAT, " %s ", message);
gui_printf_color (window, COLOR_WIN_CHAT_NICK, "%s\n", param);
}
else
gui_printf_color (window, COLOR_WIN_CHAT, " %s\n", message);
}

Some files were not shown because too many files have changed in this diff Show More