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