home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / fingercl.zip / text-finger.c < prev    next >
Text File  |  1997-08-29  |  2KB  |  71 lines

  1. /* text-finger.c -- How to do textual GNU fingering. */
  2.  
  3. /* Copyright (C) 1988, 1990, 1992  Free Software Foundation, Inc.
  4.  
  5.    This file is part of GNU Finger.
  6.  
  7.    This program is free software; you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License as published by
  9.    the Free Software Foundation; either version 2, or (at your option)
  10.    any later version.
  11.  
  12.    This program is distributed in the hope that it will be useful,
  13.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.    GNU General Public License for more details.
  16.  
  17.    You should have received a copy of the GNU General Public License
  18.    along with this program; if not, write to the Free Software
  19.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. #include <stdio.h>
  22. #include <config.h>
  23. #include <pwd.h>
  24. /* #include <general.h> */
  25.  
  26. /* Tell CONNECTION to send us the info on USER, and then print that
  27.    info out. */
  28. void
  29. text_finger (user, connection)
  30.   char *user;
  31.   int connection;
  32. {
  33.   int out_fd, in_fd;
  34.   FILE *out_stream, *in_stream;
  35.  
  36.   /* This buffer is used only to fragment the data; it is not a limit. */
  37.   char line[256];
  38.   out_fd = dup (connection);
  39.   in_fd = dup (connection);
  40.  
  41.   if (!(in_stream = fdopen (in_fd, "r"))
  42.       || !(out_stream = fdopen (out_fd, "w")))
  43.     return;
  44.  
  45.   fprintf (out_stream, "%s\r\n", user);
  46.   fflush (out_stream);
  47.  
  48.   while (fgets (line, sizeof(line), in_stream))
  49.     {
  50.       int n = strlen (line);
  51.  
  52.       if (n > 1 && line[n - 2] == '\r')
  53.         {
  54.           line[n - 2] = 0;
  55.  
  56.           fputs (line, stdout);
  57.           putc ('\n', stdout);
  58.         }
  59.       else
  60.         fputs (line, stdout);
  61.     }
  62.   fflush (stdout);
  63.   close (in_fd);
  64.   close (out_fd);
  65.   fclose (in_stream);
  66.   fclose (out_stream);
  67. }
  68.  
  69.  
  70.  
  71.