home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / PRINTING / DVIPS54.ZIP / DVIPS / HEADER.C < prev    next >
C/C++ Source or Header  |  1990-11-25  |  2KB  |  96 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 char *newstring() ;
  21. extern void error() ;
  22. extern void copyfile() ;
  23. #ifdef DEBUG
  24. extern integer debug_flag ;
  25. #endif
  26. /*
  27.  *   This more general routine adds a name to a list of unique
  28.  *   names.
  29.  */
  30. int
  31. add_name(s, what)
  32.    char *s ;
  33.    struct header_list **what ;
  34. {
  35.    struct header_list *p, *q ;
  36.  
  37.    for (p = *what ; p != NULL; p = p->next)
  38.       if (strcmp(p->name, s)==0)
  39.          return 0 ;
  40.    q = (struct header_list *)malloc((unsigned)sizeof(struct header_list)) ;
  41.    if (q==NULL)
  42.       error("! out of memory") ;
  43.    q->next = NULL ;
  44.    q->name = newstring(s) ;
  45.    if (*what == NULL)
  46.       *what = q ;
  47.    else {
  48.       for (p = *what; p->next != NULL; p = p->next) ;
  49.       p->next = q ;
  50.    }
  51.    return 1 ;
  52. }
  53. /*
  54.  *   This routine is responsible for adding a header file.
  55.  */
  56. int
  57. add_header(s)
  58. char *s ;
  59. {
  60. #ifdef DEBUG
  61.    if (dd(D_HEADER))
  62.       (void)fprintf(stderr, "Adding header file \"%s\"\n", s) ;
  63. #endif
  64.    return add_name(s, &header_head) ;
  65. }
  66. /*
  67.  *   This routine runs down a list, returning each in order.
  68.  */
  69. char *
  70. get_name(what)
  71.    struct header_list **what ;
  72. {
  73.    if (what && *what) {
  74.       char *p = (*what)->name ;
  75.       *what =  (*what)->next ;
  76.       return p ;
  77.    } else
  78.       return 0 ;
  79. }
  80. /*
  81.  *   This routine actually sends the headers.
  82.  */
  83. void
  84. send_headers() {
  85.    struct header_list *p = header_head ;
  86.    char *q ;
  87.  
  88.    while (q=get_name(&p)) {
  89. #ifdef DEBUG
  90.       if (dd(D_HEADER))
  91.          (void)fprintf(stderr, "Sending header file \"%s\"\n", q) ;
  92. #endif
  93.       copyfile(q) ;
  94.    }
  95. }
  96.