File: section.c

package info (click to toggle)
funnelweb 3.2-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,692 kB
  • ctags: 1,071
  • sloc: ansic: 9,156; makefile: 45
file content (147 lines) | stat: -rw-r--r-- 4,336 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*##############################################################################

FUNNNELWEB COPYRIGHT
====================
FunnelWeb is a literate-programming macro preprocessor.
The FunnelWeb web is at http://www.ross.net/funnelweb/

Copyright (c) Ross N. Williams 1992. All rights reserved.

This program is free software; you can redistribute it and/or modify
it under the terms of Version 2 of the GNU General Public License as
published by the Free Software Foundation (http://www.gnu.org/).

This program is distributed WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See Version 2 of the GNU General Public License for more details.

You should have received a copy of Version 2 of the GNU General Public
License along with this program. If not, you can obtain a copy as follows:
   ftp://prep.ai.mit.edu/pub/gnu/COPYING-2.0
or write to:
    Free Software Foundation, Inc.,
    59 Temple Place - Suite 330, Boston, MA  02111-1307, USA

Section 2a of the license requires that all changes to this file be
recorded prominently in this file. Please record all changes here.

Programmers:
   RNW  Ross N. Williams (ross@ross.net)

Changes:
   07-May-1992  RNW  Program prepared for release under GNU GPL V2.

##############################################################################*/


/******************************************************************************/
/*                                   SECTION.C                                */
/******************************************************************************/

#include "style.h"

#include "as.h"
#include "section.h"

/******************************************************************************/

#define MAGIC  (89201129L) /* Magic number detects uninitialized sections.    */
#define SECMAX    (30000L) /* Maximum value of a single level's section num.  */

/******************************************************************************/

LOCAL void sn_chk P_((p_sn_t));
LOCAL void sn_chk(p_sn)
/* Checks that the given section object has a legal internal state.           */
p_sn_t p_sn;
{
 ubyte i;

 as_cold(p_sn->sn_magic==MAGIC,"sn_chk: Section has bad magic number.");
 as_cold(p_sn->sn_lev<=SECLEV_MAX,
         "sn_chk: Section has bad level number.");
 for (i=1;i<=p_sn->sn_lev;i++)
    as_cold(p_sn->sn_num[i]>0,
            "sn_chk: Section has zero hierarchical number.");
}

/******************************************************************************/

EXPORT void sn_ini(p_sn)
p_sn_t p_sn;
{
 p_sn->sn_magic = MAGIC;
 p_sn->sn_lev   = 0;
}

/******************************************************************************/

EXPORT void sn_set(p_sn,level)
p_sn_t p_sn;
ubyte  level;
{
 ubyte i;
 sn_chk(p_sn);
 as_cold(level>0 && level<=SECLEV_MAX,
         "sn_set: Specified level is too high.");
 p_sn->sn_lev=level;
 for(i=1;i<=level;i++)
    p_sn->sn_num[i]=1;
}

/******************************************************************************/

EXPORT void sn_inc (p_sn,lev)
p_sn_t p_sn;
ubyte  lev;
{
 sn_chk(p_sn);

 /* Check the parameter level. */
 as_cold(1<=lev && lev<=SECLEV_MAX,"sn_inc: Bad level number specified.");

 /* Check that we are not skipping a hierarchical level. */
 as_cold(lev<=p_sn->sn_lev+1,"sn_inc: Discountinuous level increment.");

 /* Actually increment the section. */
 if (lev==p_sn->sn_lev+1) p_sn->sn_num[lev]=0;
 p_sn->sn_lev=lev;
 p_sn->sn_num[lev]++;

 /* Check that the section number hasn't got too big. */
 as_cold(p_sn->sn_num[lev]<=SECMAX,"sn_inc: Section number is too large.");
}

/******************************************************************************/

EXPORT ubyte sn_lev(p_sn)
p_sn_t p_sn;
{
 sn_chk(p_sn);
 return p_sn->sn_lev;
}

/******************************************************************************/

EXPORT void sn_str(p_sn,s)
p_sn_t p_sn;
char   *s;
{
 char   t[20];
 ubyte  i;

 sn_chk(p_sn);

 s[0]=EOS;
 for (i=1;i<=p_sn->sn_lev;i++)
    {
     if (i>1) strcat(s,".");
     sprintf(t,"%u",(unsigned) p_sn->sn_num[i]);
     strcat(s,t);
    }
}

/******************************************************************************/
/*                               End of SECTION.C                             */
/******************************************************************************/