home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume20 / psroff / part01 / utils.c < prev   
Encoding:
C/C++ Source or Header  |  1989-10-17  |  2.1 KB  |  96 lines

  1. /*    Copyright 1985, 1986, 1987, 1988 Chris Lewis
  2.         All Rights Reserved
  3.  
  4.     Permission to copy and further distribute is freely given provided 
  5.     this copyright notice remains intact and that this software is not 
  6.     sold for profit.
  7.  
  8.     Project:    Generic Troff drivers
  9.     Module:        utils.c
  10.     Author:     Chris Lewis
  11.     Specs:        Utility functions
  12.  */
  13.  
  14. #include "defs.h"
  15.  
  16. #ifndef    SVR3
  17. #ifndef    lint
  18. static char SCCSid[] = "@(#)utils.c: 1.7 Copyright 89/07/17 10:58:36 Chris Lewis";
  19. #endif
  20. #else
  21. #ident  "@(#)utils.c: 1.7 Copyright 89/07/17 10:58:36 Chris Lewis"
  22. #endif
  23.  
  24. #ifdef    DEBUG
  25. debugprintf(fmt, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
  26. char    *fmt;
  27. int    a1, a2, a3, a4, a5, a6, a7, a8, a9, a10; {
  28.     char buf[BUFSIZ];
  29.     sprintf(buf, fmt, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
  30.     fprintf(diagFile, buf);
  31. }
  32. #endif
  33.  
  34. char *skipblanks(p)
  35. register char *p; {
  36.     while (*p && isspace(*p)) p++;
  37.     return(p);
  38. }
  39.  
  40. char *gettok(p, bp)
  41. register char *p, *bp; {
  42.     p = skipblanks(p);
  43.     while(*p && !isspace(*p)) *bp++ = *p++;
  44.     *bp = '\0';
  45.     return(p);
  46. }
  47.  
  48. interp(buf, xlator, suffix)
  49. char *buf, *suffix; FUNC xlator; {
  50.     register char *p, *ep;
  51.     char token[512];
  52.     p = gettok(buf, token);
  53.     if (0 == strcmp(token, "include") || 0 == strcmp(token, "binclude")) {
  54.     int binary;
  55.     FILE *inc;
  56.     binary = (token[0] == 'b') ? 1: 0;
  57.     p = gettok(p, token);
  58.     strcat(token, suffix);
  59.     if (!(inc = fopen(token, "r"))) {
  60.         char nbuf[512];
  61.         if (token[0] != '/') {
  62.         sprintf(nbuf, "%s/%s", LIBDIR, token);
  63.         inc = fopen(nbuf, "r");
  64.         }
  65.     }
  66.     if (!inc) {
  67.         fprintf(stderr, "%s: cannot open file %s\n", progname, token);
  68.         exit(1);
  69.     } else {
  70.         if (binary || !xlator)
  71.         while ((binary = fread(token, 1, sizeof(token), inc)) > 0)
  72.             fwrite(token, 1, binary, stdout);
  73.         else
  74.         (*xlator)(inc);
  75.         fclose(inc);
  76.     }
  77.     }
  78.  
  79.     else {
  80.     fprintf(stderr, "%s: unknown directive: %s\n", progname, token);
  81.     exit(1);
  82.     }
  83. }
  84.  
  85. char nodename[25];
  86. getnodename() {
  87.     FILE *uuname;
  88.     int c;
  89.     if ((uuname = popen("uuname -l", "r")) == NULL)
  90.     strcpy(nodename, "<noname>");
  91.     else {
  92.     fscanf(uuname, "%s", nodename);
  93.     pclose(uuname);
  94.     }
  95. }
  96.