home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Multimed / Multimed.zip / chord3_6.zip / chord / toc.c < prev    next >
C/C++ Source or Header  |  1995-04-25  |  4KB  |  185 lines

  1. static char SccsId[] = "@(#)chord.c    3.6\t Mar. 1995";
  2. static char copyright[] = "Copyright 1991-1995 by Martin Leclerc & Mario Dorion";
  3.  
  4. #include "chord.h"
  5.  
  6. struct toc_struct *so_toc = NULL;
  7. struct toc_struct *cur_toc_entry;
  8.  
  9. extern char title1;
  10. extern int v_pages;
  11. extern int pagination;
  12. extern float scale;
  13. extern int number_all;
  14. extern int song_pages;
  15. extern int text_size;
  16. extern int vpos;
  17.  
  18. struct toc_struct *toc_ptr;
  19. struct sub_title_struct **sub_ptr_handle;
  20.  
  21. /* --------------------------------------------------------------------------------*/
  22. void print_toc_entry (toc_ptr)
  23. struct toc_struct *toc_ptr;
  24. {
  25. struct sub_title_struct *sub_ptr;
  26. fprintf (stderr, "+++\n");
  27. if ( toc_ptr != NULL )
  28.     {
  29.     fprintf (stderr, "*%s\n %d\n", toc_ptr->title, toc_ptr->page_label);
  30.     sub_ptr = toc_ptr->sub_titles;
  31.  
  32.     while (sub_ptr != NULL)
  33.         {
  34.         fprintf(stderr, "%s\n", sub_ptr->sub_title);
  35.         sub_ptr = sub_ptr->next_sub;
  36.         }
  37.     }
  38. else
  39.     fprintf (stderr, "Pointer is NULL\n");
  40. fprintf (stderr, "---\n");
  41. }
  42. /* --------------------------------------------------------------------------------*/
  43. void print_toc_entries()
  44. {
  45. struct toc_struct *dummy;
  46.  
  47. dummy=so_toc;
  48. while (dummy != NULL )
  49.     {
  50.     print_toc_entry (dummy);
  51.     dummy=dummy->next;
  52.     }
  53. }
  54. /* --------------------------------------------------------------------------------*/
  55. void add_title_to_toc (title, page_label)
  56. char *title;
  57. int page_label;
  58. {
  59.        struct toc_struct **prev_ptr_handle, *new_toc_entry;
  60. static struct toc_struct dummy_toc;
  61.  
  62. debug ("start of add_title_to_toc");
  63.  
  64. new_toc_entry = (struct toc_struct *)malloc (sizeof (dummy_toc));
  65. new_toc_entry->page_label=page_label;
  66. new_toc_entry->title = malloc (strlen (title)+1);
  67. new_toc_entry->sub_titles = NULL;
  68. sub_ptr_handle = &new_toc_entry->sub_titles;
  69. strcpy (new_toc_entry->title, title);
  70.  
  71. toc_ptr = so_toc;
  72. prev_ptr_handle = &so_toc;
  73.  
  74. while (  ( toc_ptr != NULL) && (strcmp (title, toc_ptr->title) >= 0 ))
  75.     {
  76.     prev_ptr_handle = &(toc_ptr->next);
  77.     toc_ptr=toc_ptr->next;
  78.     }
  79.  
  80. new_toc_entry->next = toc_ptr;
  81. *prev_ptr_handle = new_toc_entry;
  82. cur_toc_entry = new_toc_entry;
  83.  
  84. }
  85.  
  86. /* --------------------------------------------------------------------------------*/
  87. void add_subtitle_to_toc (sub_title)
  88. char *sub_title;
  89. {
  90.  
  91. static struct sub_title_struct dummy_sub_title_struct;
  92.        struct sub_title_struct *new_sub = NULL;
  93.        char *tmp_string;
  94.  
  95. debug ("start of add_subtitle_to_toc");
  96.  
  97. new_sub = (struct sub_title_struct *)malloc (sizeof (dummy_sub_title_struct));
  98. tmp_string = (char *)malloc (strlen (sub_title) + 1);
  99. new_sub->sub_title = tmp_string;
  100. new_sub->next_sub = NULL;
  101. strcpy (new_sub->sub_title, sub_title);
  102. *sub_ptr_handle = new_sub;
  103. sub_ptr_handle = &(new_sub->next_sub);
  104. new_sub = NULL;
  105. }
  106. /* --------------------------------------------------------------------------------*/
  107. void build_ps_toc()
  108.     {
  109.     char line[MAXTOKEN];
  110.     struct toc_struct *toc_ptr;
  111.     struct sub_title_struct *sub_ptr;
  112.  
  113.     debug("Debut de build_ps_toc");
  114.     /* print_toc_entries(); */
  115.  
  116.     strcpy (&title1, "Index");
  117.  
  118.     if (v_pages % pagination)
  119.         do_end_of_page(TRUE);
  120.                 
  121.     if (pagination == 4) 
  122.         {
  123.         pagination = 1;
  124.         scale = 1.0;
  125.         }
  126.  
  127.     v_pages=0;
  128.     do_start_of_page();
  129.     number_all= FALSE;
  130.     song_pages= 0;
  131.     set_text_font (text_size+10);
  132.     use_text_font();
  133.     printf ("(");
  134.     ps_puts (&title1);
  135.     printf (") dup stringwidth pop 2 div\n");
  136.     printf ("%f 2 div exch sub %d moveto\n", WIDTH, vpos);
  137.     printf ("show\n");
  138.     advance(text_size);
  139.  
  140.     toc_ptr = so_toc;
  141.  
  142.     while (toc_ptr != NULL)
  143.         {
  144.  
  145.         /* title */
  146.         if ( vpos < BOTTOM + 3 * text_size)
  147.             {
  148.             advance (vpos);
  149.             song_pages= 0;
  150.             }
  151.         advance(text_size+8);
  152.         set_text_font(text_size + 5);
  153.         use_text_font();
  154.         printf("72 %d moveto\n", vpos);
  155.         printf("(");
  156.         debug ("Setting title\n");
  157.         ps_puts(toc_ptr->title);
  158.         printf(") show\n");
  159.         printf("500 %d moveto\n", vpos);
  160.         debug ("Setting page_label\n");
  161.         printf("(%d) show\n", toc_ptr->page_label);
  162.  
  163.         /* sub titles */
  164.         sub_ptr=toc_ptr->sub_titles;
  165.  
  166.         while (sub_ptr != NULL)
  167.             {
  168.             advance(text_size);
  169.             set_text_font(text_size);
  170.             use_text_font();
  171.             printf ("108 %d moveto\n", vpos);
  172.             printf("(");
  173.             ps_puts(sub_ptr->sub_title);
  174.             printf(") show\n");
  175.             sub_ptr = sub_ptr->next_sub;
  176.             }
  177.         toc_ptr= toc_ptr->next;
  178.         }
  179.  
  180.     vpos = vpos - text_size - 5;
  181.     set_text_font (text_size);
  182.     }
  183.  
  184. /* --------------------------------------------------------------------------------*/
  185.