home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume26 / uuhost-2.1 / uusplit.c < prev   
Encoding:
C/C++ Source or Header  |  1992-04-18  |  2.1 KB  |  95 lines

  1. /*
  2.  * UUHOST, Copyright 1992,   Jan-Piet Mens [Logix GmbH, Wiesbaden, Germany]
  3.  * License to freely use and distribute this software is hereby granted 
  4.  * by the author, subject to the condition that this copyright notice 
  5.  * remains intact.  The author retains the exclusive right to publish 
  6.  * derivative works based on this work, including, but not limited
  7.  * to, revised versions of this work.
  8.  *
  9.  * $Id: uusplit.c,v 2.2 1992/01/16 09:40:58 jpm Exp $
  10.  *
  11.  * $Log: uusplit.c,v $
  12.  * Revision 2.2  1992/01/16  09:40:58  jpm
  13.  * Cleanup
  14.  *
  15.  * Revision 2.1  1991/10/19  14:27:49  jpm
  16.  * *** empty log message ***
  17.  *
  18.  *
  19.  */
  20. #include <stdio.h>
  21. #define MAXBUF        1024
  22.  
  23. #if defined(__STDC__) || defined(__cplusplus)
  24. # define P_(s) s
  25. #else
  26. # define P_(s) ()
  27. #endif
  28.  
  29. int main P_((int argc, char **argv));
  30. void split P_((char *bp, char *fname));
  31. void exit();
  32. int strlen();
  33. int atoi();
  34.  
  35. #undef P_
  36.  
  37. #ifndef lint
  38. static char rcs_id[] = "@(#)$Id: uusplit.c,v 2.2 1992/01/16 09:40:58 jpm Exp $";
  39. #endif
  40.  
  41. int main(argc, argv)
  42. int argc;
  43. char **argv;
  44. {
  45.     char buf[MAXBUF];
  46.     char *fname = argv[1];
  47.     int n = strlen(fname) - 1;
  48.  
  49.     if (argc != 2)
  50.         exit(fprintf(stderr,"Usage: %0 filename\n", *argv));
  51.  
  52.     /*
  53.      * If filenames end in .Z, chop it off. We don't need that.
  54.      * Just wastes space ...
  55.      */
  56.  
  57.     if (fname[n] == 'Z' && fname[n - 1] == '.')
  58.         fname[n - 1] = '\0';
  59.  
  60.     while (fgets(buf, MAXBUF, stdin) != (char *)0)
  61.         split(buf, argv[1]);
  62.     return (0);
  63. }
  64.  
  65. /*
  66.  * `fname' is a relative path to a map: u.deu.2.
  67.  * `bp' contains an `#N' line from the map which has a line-number
  68.  *  prepended to it by `grep' , as in
  69.  *
  70.  *     1245:#N        logixwi, .logix.de,  logix.de
  71.  *
  72.  * Split that line up into lines containing the host name, a filename, and
  73.  * the line number.
  74.  *
  75.  *    logixwi    u.deu.2 1245
  76.  *    .logix.de       u.deu.2 1245
  77.  *    logix.de    u.deu.2 1245
  78.  */
  79.  
  80. void split(bp, fname)
  81. char *bp, *fname;
  82. {
  83.     char *ptr, *strtok();
  84.     int line;
  85.  
  86.     if ((ptr = strtok(bp, ":")) == (char *)0)
  87.         (void)fprintf(stderr, "ERROR: no line number\n");
  88.     line = atoi(ptr);
  89.  
  90.     ptr = strtok(NULL, " \t,;\n");
  91.  
  92.     while ((ptr = strtok(NULL, " \t,;\n")) != (char *)0)
  93.         (void)printf("%s\t%s\t%d\n", ptr, fname, line);
  94. }
  95.