Added option parsing. - irc - Unnamed repository; edit this file 'description' to name the repository.
 (HTM) git clone git://vernunftzentrum.de/irc.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
       ---
 (DIR) commit a10ff13d00eb7fa816a3771b2c4ae7265627a024
 (DIR) parent 9ec61b4072285e36baeab8f1ac6d819f9445b56c
 (HTM) Author: Quentin Carbonneaux <qcarbonneaux@gmail.com>
       Date:   Sun, 25 Mar 2012 10:41:07 +0200
       
       Added option parsing.
       
       This commit allows users to customize their IRC user name, nick name,
       and server. The user name, if not specified, is taken from the
       environment variable USER. The nick name, if not specified, is taken
       from IRCNICK. The nick name cannot exceed 63 chars (which is way more
       than what is currently accepted by most IRC servers).
       
       Diffstat:
         irc.c                               |      42 ++++++++++++++++++++++++++------
       
       1 file changed, 35 insertions(+), 7 deletions(-)
       ---
 (DIR) diff --git a/irc.c b/irc.c
       @@ -25,11 +25,12 @@
        #define SCROLL 15
        #define DATEFMT "%H:%M"
        #define PFMT "%-12s < %s"
       +#define SRV "chat.freenode.org"
       +#define PORT 6667
        
        enum { ChanLen = 64, LineLen = 512, MaxChans = 16, BufSz = 2048, LogSz = 4096 };
        
        char nick[64];
       -char prefix[64];
        int quit, winchg;
        int sfd; /* Server file descriptor. */
        struct {
       @@ -536,17 +537,44 @@ treset(void)
        }
        
        int
       -main(void)
       +main(int argc, char *argv[])
        {
                const char *user = getenv("USER");
       -
       -        if (!user) user="Unknown";
       +        const char *ircnick = getenv("IRCNICK");
       +        const char *server = SRV;
       +        unsigned short port = PORT;
       +        int o;
       +
       +        while ((o=getopt(argc, argv, "hn:u:s:p:"))>=0)
       +                switch (o) {
       +                case 'h':
       +                case '?':
       +                usage:
       +                        fputs("Usage: irc [-n NICK] [-u USER] [-s SERVER] [-p PORT] [-h]\n", stderr);
       +                        exit(0);
       +                case 'n':
       +                        if (strlen(optarg)>=sizeof nick) goto usage;
       +                        strcpy(nick, optarg);
       +                        break;
       +                case 'u':
       +                        user = optarg;
       +                        break;
       +                case 's':
       +                        server = optarg;
       +                        break;
       +                case 'p':
       +                        if (!(port=strtol(optarg, 0, 0))) goto usage;
       +                        break;
       +                }
       +        if (!nick[0] && ircnick && strlen(ircnick)<sizeof nick)
       +                strcpy(nick, ircnick);
       +        if (!nick[0]) goto usage;
       +        if (!user) user = "Unknown";
                tinit();
       +        sfd = dial(server, port);
                chadd("*server*");
       -        strcpy(nick, "_mpu");
       -        sfd = dial("chat.freenode.org", 6667);
                sndf("NICK %s", nick);
       -        sndf("USER brebi 8 * :%s", user);
       +        sndf("USER %s 8 * :%s", user, user);
                sndf("MODE %s +i", nick);
                while (!quit) {
                        fd_set rfs, wfs;