home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / PRINTING / DVIPS386.ZIP / HEADER.C < prev    next >
C/C++ Source or Header  |  1991-11-03  |  2KB  |  97 lines

  1. /*
  2.  *   This routine handles the PostScript prologs that might
  3.  *   be included through:
  4.  *
  5.  *      - Default
  6.  *      - Use of PostScript fonts
  7.  *      - Specific inclusion through specials, etc.
  8.  *      - Use of graphic specials that require them.
  9.  *
  10.  *   Things are real simple.  We build a linked list of headers to
  11.  *   include.  Then, when the time comes, we simply copy those
  12.  *   headers down.
  13.  */
  14. #include "structures.h" /* The copyright notice in that file is included too! */
  15. struct header_list *header_head ;
  16. /*
  17.  *   The external routines we use.
  18.  */
  19. /* extern char *malloc() ; */
  20. extern void* malloc(unsigned) ;
  21. extern char *newstring() ;
  22. extern void error() ;
  23. extern void copyfile() ;
  24. #ifdef DEBUG
  25. extern integer debug_flag ;
  26. #endif
  27. /*
  28.  *   This more general routine adds a name to a list of unique
  29.  *   names.
  30.  */
  31. int
  32. add_name(s, what)
  33.    char *s ;
  34.    struct header_list **what ;
  35. {
  36.    struct header_list *p, *q ;
  37.  
  38.    for (p = *what ; p != NULL; p = p->next)
  39.       if (strcmp(p->name, s)==0)
  40.          return 0 ;
  41.    q = (struct header_list *)malloc((unsigned)sizeof(struct header_list)) ;
  42.    if (q==NULL)
  43.       error("! out of memory") ;
  44.    q->next = NULL ;
  45.    q->name = newstring(s) ;
  46.    if (*what == NULL)
  47.       *what = q ;
  48.    else {
  49.       for (p = *what; p->next != NULL; p = p->next) ;
  50.       p->next = q ;
  51.    }
  52.    return 1 ;
  53. }
  54. /*
  55.  *   This routine is responsible for adding a header file.
  56.  */
  57. int
  58. add_header(s)
  59. char *s ;
  60. {
  61. #ifdef DEBUG
  62.    if (dd(D_HEADER))
  63.       (void)fprintf(stderr, "Adding header file \"%s\"\n", s) ;
  64. #endif
  65.    return add_name(s, &header_head) ;
  66. }
  67. /*
  68.  *   This routine runs down a list, returning each in order.
  69.  */
  70. char *
  71. get_name(what)
  72.    struct header_list **what ;
  73. {
  74.    if (what && *what) {
  75.       char *p = (*what)->name ;
  76.       *what =  (*what)->next ;
  77.       return p ;
  78.    } else
  79.       return 0 ;
  80. }
  81. /*
  82.  *   This routine actually sends the headers.
  83.  */
  84. void
  85. send_headers() {
  86.    struct header_list *p = header_head ;
  87.    char *q ;
  88.  
  89.    while (q=get_name(&p)) {
  90. #ifdef DEBUG
  91.       if (dd(D_HEADER))
  92.          (void)fprintf(stderr, "Sending header file \"%s\"\n", q) ;
  93. #endif
  94.       copyfile(q) ;
  95.    }
  96. }
  97.