home *** CD-ROM | disk | FTP | other *** search
/ Mega Top 1 / os2_top1.zip / os2_top1 / APPS / TEKST / FUNNEL_S / SOURCES / SECTION.C < prev    next >
C/C++ Source or Header  |  1992-05-27  |  4KB  |  149 lines

  1. /*##############################################################################
  2.  
  3. FUNNNELWEB COPYRIGHT
  4. ====================
  5. FunnelWeb is a literate-programming macro preprocessor.
  6.  
  7. Copyright (C) 1992 Ross N. Williams.
  8.  
  9.    Ross N. Williams
  10.    ross@spam.adelaide.edu.au
  11.    16 Lerwick Avenue, Hazelwood Park 5066, Australia.
  12.  
  13. This program is free software; you can redistribute it and/or modify
  14. it under the terms of Version 2 of the GNU General Public License as
  15. published by the Free Software Foundation.
  16.  
  17. This program is distributed WITHOUT ANY WARRANTY; without even the implied
  18. warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  19. See Version 2 of the GNU General Public License for more details.
  20.  
  21. You should have received a copy of Version 2 of the GNU General Public
  22. License along with this program. If not, you can FTP the license from
  23. prep.ai.mit.edu/pub/gnu/COPYING-2 or write to the Free Software
  24. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  25.  
  26. Section 2a of the license requires that all changes to this file be
  27. recorded prominently in this file. Please record all changes here.
  28.  
  29. Programmers:
  30.    RNW  Ross N. Williams  ross@spam.adelaide.edu.au
  31.  
  32. Changes:
  33.    07-May-1992  RNW  Program prepared for release under GNU GPL V2.
  34.  
  35. ##############################################################################*/
  36.  
  37.  
  38. /******************************************************************************/
  39. /*                                   SECTION.C                                */
  40. /******************************************************************************/
  41.  
  42. #include "style.h"
  43.  
  44. #include "as.h"
  45. #include "section.h"
  46.  
  47. /******************************************************************************/
  48.  
  49. #define MAGIC  (89201129L) /* Magic number detects uninitialized sections.    */
  50. #define SECMAX    (30000L) /* Maximum value of a single level's section num.  */
  51.  
  52. /******************************************************************************/
  53.  
  54. LOCAL void sn_chk P_((p_sn_t));
  55. LOCAL void sn_chk(p_sn)
  56. /* Checks that the given section object has a legal internal state.           */
  57. p_sn_t p_sn;
  58. {
  59.  ubyte i;
  60.  
  61.  as_cold(p_sn->sn_magic==MAGIC,"sn_chk: Section has bad magic number.");
  62.  as_cold(p_sn->sn_lev<=SECLEV_MAX,
  63.          "sn_chk: Section has bad level number.");
  64.  for (i=1;i<=p_sn->sn_lev;i++)
  65.     as_cold(p_sn->sn_num[i]>0,
  66.             "sn_chk: Section has zero hierarchical number.");
  67. }
  68.  
  69. /******************************************************************************/
  70.  
  71. EXPORT void sn_ini(p_sn)
  72. p_sn_t p_sn;
  73. {
  74.  p_sn->sn_magic = MAGIC;
  75.  p_sn->sn_lev   = 0;
  76. }
  77.  
  78. /******************************************************************************/
  79.  
  80. EXPORT void sn_set(p_sn,level)
  81. p_sn_t p_sn;
  82. ubyte  level;
  83. {
  84.  ubyte i;
  85.  sn_chk(p_sn);
  86.  as_cold(level>0 && level<=SECLEV_MAX,
  87.          "sn_set: Specified level is too high.");
  88.  p_sn->sn_lev=level;
  89.  for(i=1;i<=level;i++)
  90.     p_sn->sn_num[i]=1;
  91. }
  92.  
  93. /******************************************************************************/
  94.  
  95. EXPORT void sn_inc (p_sn,lev)
  96. p_sn_t p_sn;
  97. ubyte  lev;
  98. {
  99.  sn_chk(p_sn);
  100.  
  101.  /* Check the parameter level. */
  102.  as_cold(1<=lev && lev<=SECLEV_MAX,"sn_inc: Bad level number specified.");
  103.  
  104.  /* Check that we are not skipping a hierarchical level. */
  105.  as_cold(lev<=p_sn->sn_lev+1,"sn_inc: Discountinuous level increment.");
  106.  
  107.  /* Actually increment the section. */
  108.  if (lev==p_sn->sn_lev+1) p_sn->sn_num[lev]=0;
  109.  p_sn->sn_lev=lev;
  110.  p_sn->sn_num[lev]++;
  111.  
  112.  /* Check that the section number hasn't got too big. */
  113.  as_cold(p_sn->sn_num[lev]<=SECMAX,"sn_inc: Section number is too large.");
  114. }
  115.  
  116. /******************************************************************************/
  117.  
  118. EXPORT ubyte sn_lev(p_sn)
  119. p_sn_t p_sn;
  120. {
  121.  sn_chk(p_sn);
  122.  return p_sn->sn_lev;
  123. }
  124.  
  125. /******************************************************************************/
  126.  
  127. EXPORT void sn_str(p_sn,s)
  128. p_sn_t p_sn;
  129. char   *s;
  130. {
  131.  char   t[20];
  132.  ubyte  i;
  133.  
  134.  sn_chk(p_sn);
  135.  
  136.  s[0]=EOS;
  137.  for (i=1;i<=p_sn->sn_lev;i++)
  138.     {
  139.      if (i>1) strcat(s,".");
  140.      sprintf(t,"%u",(unsigned) p_sn->sn_num[i]);
  141.      strcat(s,t);
  142.     }
  143. }
  144.  
  145. /******************************************************************************/
  146. /*                               End of SECTION.C                             */
  147. /******************************************************************************/
  148.  
  149.