Initial import of the CDE 2.1.30 sources from the Open Group.

This commit is contained in:
Peter Howkins
2012-03-10 18:21:40 +00:00
commit 83b6996daa
18978 changed files with 3945623 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
XCOMM $XConsortium: Imakefile /main/3 1995/11/08 11:01:32 rswiston $
/* Util Imakefile */
INCLUDES = -I.
LIBSRCS = \
allwhite.c inctest.c letter.c triedump.c triepdmp.c \
trieplk.c trierset.c upcmp8.c upstrcmp.c wchar.c
CTXSRCS = \
conutil.c error.c exit.c itoa.c lower.c malloc.c openchk.c \
trie.c triecnt.c upper.c whitesp.c
OTHERSRCS = \
context.c emptyfil.c fclndir.c
SRCS = $(LIBSRCS) $(CTXSRCS) $(OTHERSRCS)
LIBOBJS = \
allwhite.o inctest.o letter.o triedump.o triepdmp.o \
trieplk.o trierset.o upcmp8.o upstrcmp.o wchar.o
CTXOBJS = \
conutil.o error.o exit.o itoa.o lower.o malloc.o openchk.o \
trie.o triecnt.o upper.o whitesp.o
OTHEROBJS = \
context.o fclndir.o emptyfil.o
LOCAL_LIBRARIES = libutil.a
/* Don't use shared libs for hp */
#ifdef HPArchitecture
#if OSMajorVersion > 7
EXTRA_LOAD_FLAGS = -Wl,-a archive
#endif
#endif
all::
NormalLibraryObjectRule()
NormalLibraryTarget(util,$(LIBOBJS) $(CTXOBJS))
all:: context fclndir
NormalProgramTarget(context,context.o,$(LOCAL_LIBRARIES),$(LOCAL_LIBRARIES),)
NormalProgramTarget(fclndir,fclndir.o,$(LOCAL_LIBRARIES),$(LOCAL_LIBRARIES),)
DependTarget()
depend:: $(SRCS)

View File

@@ -0,0 +1,32 @@
/* $XConsortium: allwhite.c /main/3 1995/11/08 11:01:49 rswiston $ */
/*
Copyright 1987, 1988, 1989 Hewlett-Packard Co.
*/
#include "basic.h"
LOGICAL m_allwhite(
#if defined(M_PROTO)
const M_WCHAR *string
#endif
) ;
LOGICAL m_whitespace(
#if defined(M_PROTO)
M_WCHAR c
#endif
) ;
/* Test if a string contains only white space characters */
#if defined(M_PROTO)
LOGICAL m_allwhite(const M_WCHAR *string )
#else
LOGICAL m_allwhite(string)
M_WCHAR *string ;
#endif /* M_PROTO */
{
const M_WCHAR *p ;
for (p = string; *p ; p++)
if (! m_whitespace(*p)) return(FALSE) ;
return(TRUE) ;
}

View File

@@ -0,0 +1,92 @@
/* $XConsortium: basic.h /main/3 1995/11/08 11:02:02 rswiston $ */
/* Copyright (c) 1986, 1987, 1988, 1989 Hewlett-Packard Co. */
/* Basic.h has a few very primitive #define's used by all MARKUP programs */
#include <stdlib.h>
/* hpux protects stdio.h from multiple includes thru stdlib.h . */
#include <stdio.h>
#define TRUE 1
#define FALSE 0
typedef unsigned char LOGICAL;
/* End of String marker */
#define M_EOS '\0'
/* Integer null value marker */
#define M_NULLVAL 0
/* 8-bit data characters */
typedef unsigned char M_CHAR8;
/* wide characters */
typedef wchar_t M_WCHAR;
/* For function prototypes */
typedef char * M_POINTER;
#if defined(hpux) || defined(__aix) || defined(sun) || defined(USL) || defined(__uxp__)
/* Old unix stuff
*#define void int
*#define M_NOPAR
*/
/* New Ansi style */
#define M_PROTO
#define M_NOPAR void
#else
#define M_PROTO
#define M_NOPAR void
#endif
char *MakeMByteString(
#if defined(M_PROTO)
const M_WCHAR *from
#endif
);
M_WCHAR *MakeWideCharString(
#if defined(M_PROTO)
const char *from
#endif
);
int w_strcmp(
#if defined(M_PROTO)
const M_WCHAR *string1, const M_WCHAR *string2
#endif
);
int w_strncmp(
#if defined(M_PROTO)
const M_WCHAR *string1, const M_WCHAR *string2, int max
#endif
);
M_WCHAR *w_strcpy(
#if defined(M_PROTO)
M_WCHAR *string1, const M_WCHAR *string2
#endif
);
M_WCHAR *w_strncpy(
#if defined(M_PROTO)
M_WCHAR *string1, const M_WCHAR *string2, int max
#endif
);
int w_strlen(
#if defined(M_PROTO)
const M_WCHAR *string
#endif
);
M_WCHAR *w_strchr(
#if defined(M_PROTO)
M_WCHAR *string, const M_WCHAR chr
#endif
);
M_WCHAR *w_strstr(
#if defined(M_PROTO)
M_WCHAR *string1, M_WCHAR *string2
#endif
);

View File

@@ -0,0 +1,268 @@
/* $XConsortium: chartype.h /main/3 1995/11/08 11:02:16 rswiston $ */
/* Copyright (c) 1988, 1989 Hewlett-Packard Co. */
/* This table defines the subset of the HP Roman8 character set
supported by HP Tag. Characters defined in Roman8 but not supported
by HP Tag are marked "(invalid)". */
M_CHARTYPE m_ctarray[M_CHARSETLEN]
= {
/* Char Name Type, Upper, Lower */
/* 0: ^@ NUL */ M_NONNAME, 0, 0,
/* 1: ^A SOH */ M_NONNAME, 1, 1,
/* 2: ^B STX */ M_NONNAME, 2, 2,
/* 3: ^C ETX */ M_NONNAME, 3, 3,
/* 4: ^D EOT */ M_NONNAME, 4, 4,
/* 5: ^E ENQ */ M_NONNAME, 5, 5,
/* 6: ^F ACK */ M_NONNAME, 6, 6,
/* 7: ^G BEL */ M_NONNAME, 7, 7,
/* 8: ^H BS */ M_NONNAME, 8, 8,
/* 9: ^I HT */ M_NONNAME, 9, 9,
/* 10: ^J LF */ M_NONNAME, 10, 10,
/* 11: ^K VT */ M_NONNAME, 11, 11,
/* 12: ^L FF */ M_NONNAME, 12, 12,
/* 13: ^M CR */ M_NONNAME, 13, 13,
/* 14: ^N SO */ M_NONNAME, 14, 14,
/* 15: ^O SI */ M_NONNAME, 15, 15,
/* 16: ^P DLE */ M_NONNAME, 16, 16,
/* 17: ^Q DC1 */ M_NONNAME, 17, 17,
/* 18: ^R DC2 */ M_NONNAME, 18, 18,
/* 19: ^S DC3 */ M_NONNAME, 19, 19,
/* 20: ^T DC4 */ M_NONNAME, 20, 20,
/* 21: ^U NAK */ M_NONNAME, 21, 21,
/* 22: ^V SYN */ M_NONNAME, 22, 22,
/* 23: ^W ETB */ M_NONNAME, 23, 23,
/* 24: ^X CAN */ M_NONNAME, 24, 24,
/* 25: ^Y EM */ M_NONNAME, 25, 25,
/* 26: ^Z SUB */ M_NONNAME, 26, 26,
/* 27: ^[ ESC */ M_NONNAME, 27, 27,
/* 28: ^\ FS */ M_NONNAME, 28, 28,
/* 29: ^] GS */ M_NONNAME, 29, 29,
/* 30: ^^ RS */ M_NONNAME, 30, 30,
/* 31: ^_ US */ M_NONNAME, 31, 31,
/* 32: SP */ M_NONNAME, 32, 32,
/* 33: ! */ M_NONNAME, 33, 33,
/* 34: " */ M_NONNAME, 34, 34,
/* 35: # */ M_NONNAME, 35, 35,
/* 36: $ */ M_NONNAME, 36, 36,
/* 37: % */ M_NONNAME, 37, 37,
/* 38: & */ M_NONNAME, 38, 38,
/* 39: ' */ M_NONNAME, 39, 39,
/* 40: ( */ M_NONNAME, 40, 40,
/* 41: ) */ M_NONNAME, 41, 41,
/* 42: * */ M_NONNAME, 42, 42,
/* 43: + */ M_NAMECHAR, 43, 43,
/* 44: , */ M_NONNAME, 44, 44,
/* 45: - */ M_NAMECHAR, 45, 45,
/* 46: . */ M_NAMECHAR, 46, 46,
/* 47: / */ M_NONNAME, 47, 47,
/* 48: 0 */ M_DIGIT, 48, 48,
/* 49: 1 */ M_DIGIT, 49, 49,
/* 50: 2 */ M_DIGIT, 50, 50,
/* 51: 3 */ M_DIGIT, 51, 51,
/* 52: 4 */ M_DIGIT, 52, 52,
/* 53: 5 */ M_DIGIT, 53, 53,
/* 54: 6 */ M_DIGIT, 54, 54,
/* 55: 7 */ M_DIGIT, 55, 55,
/* 56: 8 */ M_DIGIT, 56, 56,
/* 57: 9 */ M_DIGIT, 57, 57,
/* 58: : */ M_NONNAME, 58, 58,
/* 59: ; */ M_NONNAME, 59, 59,
/* 60: < */ M_NONNAME, 60, 60,
/* 61: = */ M_NONNAME, 61, 61,
/* 62: > */ M_NONNAME, 62, 62,
/* 63: ? */ M_NONNAME, 63, 63,
/* 64: @ */ M_NONNAME, 64, 64,
/* 65: A */ M_NMSTART, 65, 97,
/* 66: B */ M_NMSTART, 66, 98,
/* 67: C */ M_NMSTART, 67, 99,
/* 68: D */ M_NMSTART, 68, 100,
/* 69: E */ M_NMSTART, 69, 101,
/* 70: F */ M_NMSTART, 70, 102,
/* 71: G */ M_NMSTART, 71, 103,
/* 72: H */ M_NMSTART, 72, 104,
/* 73: I */ M_NMSTART, 73, 105,
/* 74: J */ M_NMSTART, 74, 106,
/* 75: K */ M_NMSTART, 75, 107,
/* 76: L */ M_NMSTART, 76, 108,
/* 77: M */ M_NMSTART, 77, 109,
/* 78: N */ M_NMSTART, 78, 110,
/* 79: O */ M_NMSTART, 79, 111,
/* 80: P */ M_NMSTART, 80, 112,
/* 81: Q */ M_NMSTART, 81, 113,
/* 82: R */ M_NMSTART, 82, 114,
/* 83: S */ M_NMSTART, 83, 115,
/* 84: T */ M_NMSTART, 84, 116,
/* 85: U */ M_NMSTART, 85, 117,
/* 86: V */ M_NMSTART, 86, 118,
/* 87: W */ M_NMSTART, 87, 119,
/* 88: X */ M_NMSTART, 88, 120,
/* 89: Y */ M_NMSTART, 89, 121,
/* 90: Z */ M_NMSTART, 90, 122,
/* 91: [ */ M_NONNAME, 91, 91,
/* 92: \\ */ M_NONNAME, 92, 92,
/* 93: ] */ M_NONNAME, 93, 93,
/* 94: ^ */ M_NONNAME, 94, 94,
/* 95: _ */ M_NONNAME, 95, 95,
/* 96: ` */ M_NONNAME, 96, 96,
/* 97: a */ M_NMSTART, 65, 97,
/* 98: b */ M_NMSTART, 66, 98,
/* 99: c */ M_NMSTART, 67, 99,
/* 100: d */ M_NMSTART, 68, 100,
/* 101: e */ M_NMSTART, 69, 101,
/* 102: f */ M_NMSTART, 70, 102,
/* 103: g */ M_NMSTART, 71, 103,
/* 104: h */ M_NMSTART, 72, 104,
/* 105: i */ M_NMSTART, 73, 105,
/* 106: j */ M_NMSTART, 74, 106,
/* 107: k */ M_NMSTART, 75, 107,
/* 108: l */ M_NMSTART, 76, 108,
/* 109: m */ M_NMSTART, 77, 109,
/* 110: n */ M_NMSTART, 78, 110,
/* 111: o */ M_NMSTART, 79, 111,
/* 112: p */ M_NMSTART, 80, 112,
/* 113: q */ M_NMSTART, 81, 113,
/* 114: r */ M_NMSTART, 82, 114,
/* 115: s */ M_NMSTART, 83, 115,
/* 116: t */ M_NMSTART, 84, 116,
/* 117: u */ M_NMSTART, 85, 117,
/* 118: v */ M_NMSTART, 86, 118,
/* 119: w */ M_NMSTART, 87, 119,
/* 120: x */ M_NMSTART, 88, 120,
/* 121: y */ M_NMSTART, 89, 121,
/* 122: z */ M_NMSTART, 90, 122,
/* 123: { */ M_NONNAME, 123, 123,
/* 124: | */ M_NONNAME, 124, 124,
/* 125: } */ M_NONNAME, 125, 125,
/* 126: ~ */ M_NONNAME, 126, 126,
/* 127: DEL */ M_NONNAME, 127, 127,
/* 128: undefined */ M_NONNAME, 128, 128,
/* 129: undefined */ M_NONNAME, 129, 129,
/* 130: undefined */ M_NONNAME, 130, 130,
/* 131: undefined */ M_NONNAME, 131, 131,
/* 132: undefined */ M_NONNAME, 132, 132,
/* 133: undefined */ M_NONNAME, 133, 133,
/* 134: undefined */ M_NONNAME, 134, 134,
/* 135: undefined */ M_NONNAME, 135, 135,
/* 136: undefined */ M_NONNAME, 136, 136,
/* 137: undefined */ M_NONNAME, 137, 137,
/* 138: undefined */ M_NONNAME, 138, 138,
/* 139: undefined */ M_NONNAME, 139, 139,
/* 140: undefined */ M_NONNAME, 140, 140,
/* 141: undefined */ M_NONNAME, 141, 141,
/* 142: undefined */ M_NONNAME, 142, 142,
/* 143: undefined */ M_NONNAME, 143, 143,
/* 144: undefined */ M_NONNAME, 144, 144,
/* 145: undefined */ M_NONNAME, 145, 145,
/* 146: undefined */ M_NONNAME, 146, 146,
/* 147: undefined */ M_NONNAME, 147, 147,
/* 148: undefined */ M_NONNAME, 148, 148,
/* 149: undefined */ M_NONNAME, 149, 149,
/* 150: undefined */ M_NONNAME, 150, 150,
/* 151: undefined */ M_NONNAME, 151, 151,
/* 152: undefined */ M_NONNAME, 152, 152,
/* 153: undefined */ M_NONNAME, 153, 153,
/* 154: undefined */ M_NONNAME, 154, 154,
/* 155: undefined */ M_NONNAME, 155, 155,
/* 156: undefined */ M_NONNAME, 156, 156,
/* 157: undefined */ M_NONNAME, 157, 157,
/* 158: undefined */ M_NONNAME, 158, 158,
/* 159: undefined */ M_NONNAME, 159, 159,
/* 160: undefined */ M_NONNAME, 160, 160,
/* 161: A grave */ M_NMSTART, 161, 200,
/* 162: A circumflex */ M_NMSTART, 162, 192,
/* 163: E grave */ M_NMSTART, 163, 201,
/* 164: E circumflex */ M_NMSTART, 164, 193,
/* 165: E dieresis */ M_NMSTART, 165, 205,
/* 166: I circumflex */ M_NMSTART, 166, 209,
/* 167: I dieresis */ M_NMSTART, 167, 221,
/* 168: acute accent */ M_NONNAME, 168, 168,
/* 169: grave accent */ M_NONNAME, 169, 169,
/* 170: circumflex */ M_NONNAME, 170, 170,
/* 171: dieresis */ M_NONNAME, 171, 171,
/* 172: tilde */ M_NONNAME, 172, 172,
/* 173: U grave */ M_NMSTART, 173, 203,
/* 174: U circumflex */ M_NMSTART, 174, 195,
/* 175: Italian Lira (invalid) */ M_NONNAME, 175, 175,
/* 176: overbar (invalid) */ M_NONNAME, 176, 176,
/* 177: Y acute */ M_NMSTART, 177, 178,
/* 178: y acute */ M_NMSTART, 177, 178,
/* 179: degree (invalid) */ M_NONNAME, 179, 179,
/* 180: C cedilla */ M_NMSTART, 180, 181,
/* 181: c cedilla */ M_NMSTART, 180, 181,
/* 182: N tilde */ M_NMSTART, 182, 183,
/* 183: n tilde */ M_NMSTART, 182, 183,
/* 184: inverted exclamation mark */ M_NONNAME, 184, 184,
/* 185: inverted question mark */ M_NONNAME, 185, 185,
/* 186: currency sign (invalid) */ M_NONNAME, 186, 186,
/* 187: pound sterling (invalid) */ M_NONNAME, 187, 187,
/* 188: Yen */ M_NONNAME, 188, 188,
/* 189: Section sign (invalid) */ M_NONNAME, 189, 189,
/* 190: florin (invalid) */ M_NONNAME, 190, 190,
/* 191: Cent sign (invalid) */ M_NONNAME, 191, 191,
/* 192: a circumflex */ M_NMSTART, 162, 192,
/* 193: e circumflex */ M_NMSTART, 164, 193,
/* 194: o circumflex */ M_NMSTART, 223, 194,
/* 195: u circumflex */ M_NMSTART, 174, 195,
/* 196: a acute */ M_NMSTART, 224, 196,
/* 197: e acute */ M_NMSTART, 220, 197,
/* 198: o acute */ M_NMSTART, 231, 198,
/* 199: u acute */ M_NMSTART, 237, 199,
/* 200: a grave */ M_NMSTART, 161, 200,
/* 201: e grave */ M_NMSTART, 163, 201,
/* 202: o grave */ M_NMSTART, 232, 202,
/* 203: u grave */ M_NMSTART, 173, 203,
/* 204: a dieresis */ M_NMSTART, 216, 204,
/* 205: e dieresis */ M_NMSTART, 165, 205,
/* 206: o dieresis */ M_NMSTART, 218, 206,
/* 207: u dieresis */ M_NMSTART, 219, 207,
/* 208: A angstrom */ M_NMSTART, 208, 212,
/* 209: i circumflex */ M_NMSTART, 166, 209,
/* 210: O slash */ M_NMSTART, 210, 214,
/* 211: AE ligature */ M_NMSTART, 211, 215,
/* 212: a angstrom */ M_NMSTART, 208, 212,
/* 213: i acute */ M_NMSTART, 229, 213,
/* 214: o slash */ M_NMSTART, 210, 214,
/* 215: ae ligature */ M_NMSTART, 211, 215,
/* 216: A dieresis */ M_NMSTART, 216, 204,
/* 217: i grave */ M_NMSTART, 230, 217,
/* 218: O dieresis */ M_NMSTART, 218, 206,
/* 219: U dieresis */ M_NMSTART, 219, 207,
/* 220: E acute */ M_NMSTART, 220, 197,
/* 221: i dieresis */ M_NMSTART, 167, 221,
/* 222: SS ligature */ M_NMSTART, 222, 222,
/* 223: O circumflex */ M_NMSTART, 223, 194,
/* 224: A acute */ M_NMSTART, 224, 196,
/* 225: A tilde */ M_NMSTART, 225, 226,
/* 226: a tilde */ M_NMSTART, 225, 226,
/* 227: Eth (invalid) */ M_NMSTART, 227, 228,
/* 228: eth (invalid) */ M_NMSTART, 227, 228,
/* 229: I acute */ M_NMSTART, 229, 213,
/* 230: I grave */ M_NMSTART, 230, 217,
/* 231: O acute */ M_NMSTART, 231, 198,
/* 232: O grave */ M_NMSTART, 232, 202,
/* 233: O tilde */ M_NMSTART, 233, 234,
/* 234: o tilde */ M_NMSTART, 233, 234,
/* 235: S caron */ M_NMSTART, 235, 236,
/* 236: s caron */ M_NMSTART, 235, 236,
/* 237: U acute */ M_NMSTART, 237, 199,
/* 238: Y dieresis */ M_NMSTART, 238, 239,
/* 239: y dieresis */ M_NMSTART, 238, 239,
/* 240: Thorn (invalid) */ M_NMSTART, 240, 241,
/* 241: thorn (invalid) */ M_NMSTART, 240, 241,
/* 242: undefined */ M_NONNAME, 242, 242,
/* 243: mu (invalid) */ M_NONNAME, 243, 243,
/* 244: paragraph sign (invalid) */ M_NONNAME, 244, 244,
/* 245: fraction 3/4 (invalid) */ M_NONNAME, 245, 245,
/* 246: long dash (invalid) */ M_NONNAME, 246, 246,
/* 247: fraction 1/4 (invalid) */ M_NONNAME, 247, 247,
/* 248: fraction 1/2 (invalid) */ M_NONNAME, 248, 248,
/* 249: Female ordinal (invalid) */ M_NONNAME, 249, 249,
/* 250: Male ordinal (invalid) */ M_NONNAME, 250, 250,
/* 251: French double open quote(invalid) */ M_NONNAME, 251, 251,
/* 252: Solid square (invalid) */ M_NONNAME, 252, 252,
/* 253: French double close quote(invalid) */ M_NONNAME, 253, 253,
/* 254: Plus over minus sign(invalid)*/ M_NONNAME, 254, 254,
/* 255: undefined */ M_NONNAME, 255, 255,
} ;

View File

@@ -0,0 +1,63 @@
/* $XConsortium: common.h /main/6 1996/07/31 13:34:28 cde-hp $ */
/*
Copyright (c) 1987, 1988, 1989 Hewlett-Packard Co.
*/
/* Common.h contains definitions common to programs BUILD, ELTDEF, and PARSER.
Its purpose is to insure that limits, such as the maximum length of an SGML
name, are the same for all programs.
*/
#define M_MARKUP
/* White-space characters */
#define M_RE '\n'
#define M_SPACE ' '
#define M_TAB '\t'
/* Maximum length of a default parameter value */
#define M_LITLEN 1024
/* Maximum length of an element name */
#define M_NAMELEN 64
/* M_NONNAME, M_NMSTART, M_NAMECHAR, and M_DIGIT are used to indicate
which characters can appear within element names*/
#define M_NONNAME 0
#define M_NMSTART 1
#define M_NAMECHAR 2
#define M_DIGIT 3
/* Number of characters in the character set */
#define M_CHARSETLEN 256
/* Structure for entities */
typedef struct m_entity M_ENTITY ;
struct m_entity {
unsigned char type ;
unsigned char wheredef ;
M_WCHAR *content ;
M_WCHAR *name ;
#if defined(BUILDEXTERN) || defined(ELTEXTERN)
int index ;
M_ENTITY *next ;
#endif
#if ! defined(BUILDEXTERN)
int codeindex ;
#endif
} ;
/* Declarations for character types */
typedef struct {
LOGICAL type ;
/* Must be same type as EOF */
int upper ;
int lower ;
} M_CHARTYPE ;
#define m_ischar(x) ((int) (x) >= 0 && (int) (x) < M_CHARSETLEN)
#define m_cttype(x) (m_ischar(x) ? m_ctarray[x].type : M_NONNAME)
#define m_ctupper(x) (m_ischar(x) ? m_ctarray[x].upper : x)
#define m_ctlower(x) (m_ischar(x) ? m_ctarray[x].lower : x)
#define m_ctdigit(x) (m_ischar(x) ? m_ctarray[x].type == M_DIGIT : FALSE)

View File

@@ -0,0 +1,247 @@
/* $XConsortium: cont.h /main/3 1995/11/08 11:02:46 rswiston $ */
/*
Copyright 1986 Tandem Computers Incorporated.
This product and information is proprietary of Tandem Computers Incorporated.
Copyright (c) 1986, 1987, 1988, 1989 Hewlett-Packard Co.
*/
/* Cont.h is the primary include file for program CONTEXT. */
#if defined(CONTDEF)
#define CONTEXTERN
#define CONTINIT(a) = a
#else
#define CONTEXTERN extern
#define CONTINIT(a)
#endif
void countdown(
#if defined(M_PROTO)
M_TRIE *parent, int *count
#endif
) ;
void dumpdlmptr(
#if defined(M_PROTO)
M_NOPAR
#endif
) ;
void dumpnode(
#if defined(M_PROTO)
LOGICAL *first, FILE *file, M_TRIE *trieptr, int *count, void (*proc)
#endif
) ;
void dumptree(
#if defined(M_PROTO)
LOGICAL sparse
#endif
) ;
void enterdelim(
#if defined(M_PROTO)
int n
#endif
) ;
void m_error(
#if defined(M_PROTO)
char *text
#endif
) ;
void m_err1(
#if defined(M_PROTO)
char *text, char *arg
#endif
) ;
void getcode(
#if defined(M_PROTO)
int n
#endif
) ;
void getcolon(
#if defined(M_PROTO)
M_NOPAR
#endif
) ;
int getContext(
#if defined(M_PROTO)
M_NOPAR
#endif
) ;
LOGICAL getdname(
#if defined(M_PROTO)
M_NOPAR
#endif
) ;
void inccon(
#if defined(M_PROTO)
M_NOPAR
#endif
) ;
void incdelim(
#if defined(M_PROTO)
M_NOPAR
#endif
) ;
void loaddelim(
#if defined(M_PROTO)
M_NOPAR
#endif
) ;
int m_lower(
#if defined(M_PROTO)
int c
#endif
) ;
void main(
#if defined(M_PROTO)
int argc, char **argv
#endif
) ;
void *m_malloc(
#if defined(M_PROTO)
int size, char *msg
#endif
) ;
void nextcon(
#if defined(M_PROTO)
LOGICAL sparse
#endif
) ;
void m_openchk(
#if defined(M_PROTO)
FILE **ptr, char *name, char *mode
#endif
) ;
void printval(
#if defined(M_PROTO)
FILE *file, M_TRIE *value
#endif
) ;
void prtctxt(
#if defined(M_PROTO)
int column, int value
#endif
) ;
int readchar(
#if defined(M_PROTO)
LOGICAL cap
#endif
) ;
void skiptoend(
#if defined(M_PROTO)
M_NOPAR
#endif
) ;
void unread(
#if defined(M_PROTO)
int c
#endif
) ;
int m_upper(
#if defined(M_PROTO)
int c
#endif
) ;
void warning(
#if defined(M_PROTO)
char *text
#endif
) ;
void warning1(
#if defined(M_PROTO)
char *text, char *arg
#endif
) ;
void warning2(
#if defined(M_PROTO)
char *text, char *arg1, char *arg2
#endif
) ;
LOGICAL m_whitespace(
#if defined(M_PROTO)
M_WCHAR c
#endif
) ;
#define NOMORE -1
/* Increase by 10 percent */
#define m_plus10p(x) (x + (x > 10 ? x / 10 : 1))
CONTEXTERN int NUMCON CONTINIT(100) ;
#define CNAMELEN 12
#define DNAMELEN 12
#define DELIMLEN 25
CONTEXTERN int NUMDELIM CONTINIT(100) ;
#define contype ccount <= 255 ? "unsigned char" : "int"
CONTEXTERN LOGICAL m_heapchk CONTINIT(FALSE) ;
CONTEXTERN LOGICAL m_malftrace CONTINIT(FALSE) ;
#define ENDIFSTRING "}\n#endif\n ;\n"
CONTEXTERN char endif[sizeof(ENDIFSTRING)] CONTINIT(ENDIFSTRING) ;
CONTEXTERN LOGICAL casestarted ;
CONTEXTERN LOGICAL errexit CONTINIT(FALSE) ;
CONTEXTERN FILE *delim ;
CONTEXTERN FILE *context ;
CONTEXTERN FILE *fcase, *cdat, *ddat, *m_errfile ;
CONTEXTERN M_TRIE delimtrie ;
CONTEXTERN M_TRIE **contree ;
CONTEXTERN int *xtransit ;
#define transit(i,j) xtransit[i * NUMDELIM + j]
CONTEXTERN M_WCHAR **contexts ;
CONTEXTERN int ccount CONTINIT(0) ;
CONTEXTERN M_WCHAR dname[DNAMELEN + 1] ;
CONTEXTERN M_WCHAR dstring[DELIMLEN + 1] ;
CONTEXTERN int dcount CONTINIT(0) ;
CONTEXTERN struct dstruct {
int count ;
M_WCHAR *string ;
} *dstruct ;
CONTEXTERN LOGICAL withdelim ;
CONTEXTERN LOGICAL loading ;
CONTEXTERN int curdelim ;
CONTEXTERN char **dlmptr ;
CONTEXTERN LOGICAL first CONTINIT(TRUE) ;
CONTEXTERN int maxd CONTINIT(0) ;
CONTEXTERN int m_line CONTINIT(1) ;
CONTEXTERN int nonzero CONTINIT(0) ;

View File

@@ -0,0 +1,224 @@
/* $XConsortium: context.c /main/3 1995/11/08 11:03:02 rswiston $ */
/*
Copyright 1986 Tandem Computers Incorporated.
This product and information is proprietary of Tandem Computers Incorporated.
Copyright (c) 1986, 1987, 1988, 1989 Hewlett-Packard Co.
*/
/*
Context.c contains the main procedure for program CONTEXT.
CONTEXT builds scanning and parsing tables for a simple
state-transition recognizer. Input consists of two files, delimiter
declarations in file "delim.dat" and state tables with corresponding
actions in file "context.dat". If a parameter is present on the
command line, a sparse matrix technique is used to encode some of the
output arrays.
Data lines in "delim.dat" contain the name of the delimiter followed
by the text of the delimiter (one or more non-white space
characters). The delimiter name must begin in the first column.
Lines with white-space in the first column are considered comments.
Data in "context.dat" consists of free-form multi-line declarations.
Each declaration is terminated by a semi-colon. It begins with the
name of a token followed by any number of pairs of contexts (parser
states). The context pairs are separated by a colon and may
optionally be followed by some C code enclosed in braces. In each
pair, the first context is one in which the delimiter is recognized,
the second is the state that will result from an occurrence of the
delimiter in the first context. If code is specified, it is to be
executed by the parser when the delimiter occurs in the first context
of the pair. If successive pairs of contexts are separated by a
comma, code which follows is common to all the pairs.
The tokens specified in "context.dat" can either be delimiters defined in
"delim.dat" or other tokens (e.g., number, name, end_of_file) that will
be recognized by the user-defined scanner.
For example, suppose "delim.dat" contains the line
grpo (
and "context.dat" includes
grpo element:namegroup
content:model {openmod() ;}
excon:openex
pcon:type ;
name namegroup:namesep {eltname() ;}
model:connector,
model2:connector
{storemod(nstring) ;}
These declarations specify that the "grpo" delimiter is "(" and is
recognized in contexts "element", "content", "excon", and "pcon".
Procedure openmod() is called when "grpo" occurs in "content" and,
beyond the state change, no code is executed in other contexts when
"grpo" occurs. The "name" token is valid in contexts "namegroup",
"model", and "model2"; in the first, the context is set to "namesep"
and procedure eltname() is called, in the last two, the context is
set to "connector" and storemod(nstring) is called.
The program has several output files: case.c, delim.h, context.h, and
error. Case.c contains nested switch statements to execute the code
specified with the context transitions. Delim.h contains C
declarations related to delimiters; context.h has declarations
related to contexts. Programs that include delim.h should define
M_DELIMDEF for definition form of the declarations and not define it
for the declaration form. Programs that include context.h should
define M_CONDEF analogously.
The program numbers the delimiter names and the contexts as
encountered and outputs corresponding #define instructions with all
letters in the names forced to uppercase to delim.h and context.h.
In addition, an array named for each delimiter (with all letters
forced to lowercase) is initialized to the delimiter text. The first
declaration in the above example, for instance, would result in the
following lines written to delim.h:
#define GRPO 1
M_DELIMEXTERN char grpo[] M_DELIMINIT("(") ;
These lines would be written to context.h:
#define ELEMENT 1
#define NAMEGROUP 2
#define CONTENT 3
#define MODEL 4
#define EXCON 5
#define OPENEX 6
#define PCON 7
#define TYPE 8
#define NAMESEP 9
#define CONNECTOR 10
#define MODEL2 11
Delim.h also contains an array, m_dlmptr, which contains pointers to the
names of all the defined delimiters. In addition, delim.h contains the
declaration of a tree representation of the delimiters allowed in each
context. Internally, the program represents the delimiter strings with a
tree. The children of the root of this tree represent the set of characters
with which delimiters can start. Children of other nodes represent
characters that can follow the character of their parent. Leaf nodes
are associated with the null character, indicating the end of a
delimiter. A path from the root to a leaf thus represents a valid
delimiter.
The form in which the tree is represented within this program is not
quite the same as the output data structure. In the latter, each
element consists of a flag called 'more' indicating whether it is the last
child of its parent; a character, called 'symbol'; and an integer,
called 'index'. All sons of a node are stored in adjacent elements
ordered in increaing value of their 'symbol' fields. 'Symbol'
contains the character associated with the node (0 if the node is a
leaf node), with the sign bit turned on if the node is the last child
of its parent. 'Index' contains the array index of the first son of
the node, if the node is not a leaf. If the node is a leaf, 'index'
is the number of the represented delimiter (i.e., 1 for "grpo" in the
above example).
As the tree is constructed, it is not feasible to store brothers in adjacent
elements, so the internal data structure is different. It contains a 'next'
field which points to the first brother of a given node. Because the 'next'
field can be used to detect the last child of a parent, it is not necessary
to use the sign bit of 'symbol' to indicate this special case.
Two other arrays are written to context.h. Contree[i] points to the root
of the delimiter tree for the ith context within the array tree whose
declaration is in delim.h; nextcon[i][j] indicates the state
resulting from an occurrence of delimiter j+1 in state i+1. Finally,
a #define of MAXD to the length of the longest delimiter is written to
delim.h.
*/
#include <stdio.h>
#include <malloc.h>
#if defined(MSDOS)
#include <process.h>
#endif
#include "basic.h"
#include "trie.h"
#include "common.h"
#include "chartype.h"
#define CONTDEF 1
#include "cont.h"
/* Main procedure */
void main(argc, argv)
int argc ;
char **argv ;
{
int n ;
m_openchk(&delim, "delim.h", "w") ;
m_openchk(&context, "context.h", "w") ;
m_openchk(&fcase, "case.c", "w") ;
m_openchk(&cdat, "context.dat", "r") ;
m_openchk(&ddat, "delim.dat", "r") ;
m_openchk(&m_errfile, "error", "w") ;
fputs(" switch(m_token) {\n", fcase) ; /* keep the "}" balanced */
fputs("#if defined(M_DELIMDEF)\n", delim) ;
fputs("#define M_DELIMEXTERN\n", delim) ;
fputs("#define M_DELIMINIT(a) = a\n", delim) ;
fputs("#else\n", delim) ;
fputs("#define M_DELIMEXTERN extern\n", delim) ;
fputs("#define M_DELIMINIT(a)\n", delim) ;
fputs("#endif\n\n", delim) ;
fputs("#if defined(M_CONDEF)\n", context) ;
fputs("#define M_CONEXTERN\n", context) ;
fputs("#else\n", context) ;
fputs("#define M_CONEXTERN extern\n", context) ;
fputs("#endif\n\n", context) ;
contree = (M_TRIE **) calloc(NUMCON, sizeof(M_TRIE *)) ;
xtransit = (int *) calloc(NUMCON * NUMDELIM, sizeof(int)) ;
contexts = (M_WCHAR **) calloc(NUMCON, sizeof(char *)) ;
dlmptr = (char**) calloc(NUMDELIM, sizeof(char*)) ;
loaddelim() ;
while (getdname())
{
casestarted = FALSE ;
while ((n = getContext()) >= 0)
{
if (withdelim) enterdelim(n) ;
getcolon() ;
if (transit(n, curdelim))
{
if (! withdelim)
{
char *mb_dname, *mb_contexts;
mb_dname = MakeMByteString(dname);
mb_contexts = MakeMByteString(contexts[n]);
warning2(
"Duplicate assignment to token \"%s\" in context \"%s\"",
mb_dname,
mb_contexts) ;
m_free(mb_dname,"multi-byte string");
m_free(mb_contexts,"multi-byte string");
}
}
transit(n, curdelim) = getContext() + 1 ;
getcode(n) ;
}
if (casestarted)
{
fprintf(fcase, " default:\n break ;\n") ;
/* keep the "{" balanced */
fprintf(fcase, " }\n break ;\n") ;
}
}
/* keep the "{" balanced */
fprintf(fcase, " default:\n break ;\n }\n") ;
fprintf(context, "#define MAXD %d\n", maxd) ;
dumptree((LOGICAL) (argc > 1)) ;
fprintf(stderr, "NUMCON set to %d\n", NUMCON) ;
fprintf(stderr, "NUMDELIM set to %d\n", NUMDELIM) ;
exit(errexit) ;
}

View File

@@ -0,0 +1,652 @@
/* $XConsortium: conutil.c /main/3 1995/11/08 11:03:16 rswiston $ */
/*
Copyright 1986 Tandem Computers Incorporated.
This product and information is proprietary of Tandem Computers Incorporated.
Copyright (c) 1986, 1987, 1988, 1989 Hewlett-Packard Co.
*/
/* Conutil has utility procedures for program CONTEXT. */
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#if defined(MSDOS)
#include <process.h>
#endif
#include "basic.h"
#include "trie.h"
#include "cont.h"
/* Output declaration of dlmptr */
void dumpdlmptr(M_NOPAR)
{
int n;
fprintf(delim, "M_DELIMEXTERN M_WCHAR *m_dlmptr[%d];\n", dcount+1);
fprintf(delim, "M_DELIMEXTERN char *mb_dlmptr[%d]\n", dcount+1);
fprintf(delim, "#if defined(M_DELIMDEF)\n = {\n");
for (n = 0 ; n < dcount ; n++) {
if (n) fputs(",\n", delim);
fprintf(delim, " %s", dlmptr[n]);
}
fprintf(delim, endif);
}
/* Output the generated data structures */
#if defined(M_PROTO)
void dumptree(LOGICAL sparse)
#else
void dumptree(sparse)
LOGICAL sparse;
#endif
{
int i, count = 0;
for (i = 0 ; i < ccount ; i++)
if (contree[i])
countdown(contree[i], &count);
fprintf(delim,
"M_DELIMEXTERN M_PTRIE m_delimtrie[%d]\n#if defined(M_DELIMDEF)\n = {\n",
count);
fprintf(context,
"M_CONEXTERN int m_contree[%d]\n#if defined(M_CONDEF)\n = {\n ",
ccount);
count = 0;
for (i = 0 ; i < ccount ; i++) {
if (contree[i]) {
fprintf(context, "%d", count + 1);
dumpnode(&first, delim, contree[i], &count, (void *)printval);
}
else fprintf(context, "0");
if (i < ccount - 1) fprintf(context, ",\n ");
}
fprintf(delim, endif);
fprintf(context, endif);
nextcon(sparse);
}
/* Enter a delimiter into the delimiter tree for a particular context */
void enterdelim(n)
int n;
{
if (! contree[n])
{
contree[n] = m_gettrienode();
}
if (m_ntrtrie(dstruct->string,
contree[n],
(void *) (unsigned long) dstruct->count))
{
char *mb_dstring, *mb_contexts;
mb_dstring = MakeMByteString(dstring);
mb_contexts = MakeMByteString(contexts[n]);
dcount--;
warning2("Duplicate assignment to delimiter \"%s\" in context \"%s\"",
mb_dstring,
mb_contexts);
m_free(mb_dstring,"multi-byte string");
m_free(mb_contexts,"multi-byte string");
}
}
/* Read the code to be executed with a given state transition */
void getcode(n)
int n;
{
int c ; /* c is int instead of char for use with ungetc */
int nested = 1;
LOGICAL comment = FALSE;
char *mb_context;
M_WCHAR wlb = 0, wcm, wnl, wsl, wst;
if (!wlb)
{
mbtowc(&wlb, "{", 1); /* keep the "}" balanced */
mbtowc(&wcm, ",", 1);
mbtowc(&wnl, "\n", 1);
mbtowc(&wsl, "/", 1);
mbtowc(&wst, "*", 1);
}
while (m_whitespace((M_WCHAR) (c = readchar(FALSE))));
if (c != wlb && c != wcm)
{
unread(c);
return;
}
if (! casestarted)
{
char *mb_dname;
mb_dname = MakeMByteString(dname);
casestarted = TRUE;
fprintf(fcase, " case %s:\n", mb_dname);
fprintf(fcase, " switch (m_prevcon) {\n") ; /* balance the } */
m_free(mb_dname,"multi-byte string");
}
mb_context = MakeMByteString(contexts[n]);
fprintf(fcase, " case %s:\n", mb_context);
m_free(mb_context,"multi-byte string");
if (c == wcm) return;
fprintf(fcase, "/* line %d \"context.dat\" */\n", m_line);
while (TRUE)
{
char mb_c[32]; /* arbitrarily large */
int length;
c = readchar(FALSE);
if (c == EOF)
{
warning("Unexpected EOF");
exit(TRUE);
}
length = wctomb(mb_c, c);
mb_c[length] = 0;
if (length == 1)
{
switch (mb_c[0])
{
case '{':
if (! comment) nested++;
break;
case '}':
if (! comment)
if (! --nested)
{
fprintf(fcase,"\n break ;\n");
return;
}
break;
case '/':
if (! comment)
{
fprintf(fcase, "/");
c = readchar(FALSE);
if (c == wst) comment = TRUE;
length = wctomb(mb_c, c);
mb_c[length] = 0;
}
break;
case '*':
if (comment)
{
fprintf(fcase, "*");
c = readchar(FALSE);
if (c == wsl) comment = FALSE;
length = wctomb(mb_c, c);
mb_c[length] = 0;
}
} /* End case */
}
fprintf(fcase, "%s", mb_c);
#if 0
if (c == wnl)
fprintf(fcase, "#line %d \"context.dat\"\n", m_line);
#endif
} /* End while */
} /* End proc getcode() */
/* Read the colon separating the two states in a transition pair */
void getcolon(M_NOPAR)
{
int c ; /* c is int instead of char for use with ungetc */
M_WCHAR wcl;
char unexp[32]; /* arbitraily large */
int length;
mbtowc(&wcl, ":", 1);
while (TRUE)
{
c = readchar(FALSE);
if (! m_whitespace((M_WCHAR) c)) break;
}
if (c != wcl)
{
length = wctomb(unexp, (M_WCHAR) c);
unexp[length] = 0;
warning1("Expecting : instead of '%s'\n", unexp);
}
}
/* Read a context name from an input line */
int getContext(M_NOPAR)
{
M_WCHAR name[CNAMELEN + 1];
int c ; /* c is int instead of char for use with ungetc */
int i = 0;
M_WCHAR wsm = 0, wcl, wcm;
char *mb_name;
if (!wsm)
{
mbtowc(&wsm, ";", 1);
mbtowc(&wcl, ":", 1);
mbtowc(&wcm, ",", 1);
}
while (TRUE)
{
c = readchar(TRUE);
if (c == EOF) return(NOMORE);
*name = (M_WCHAR) c;
if (*name == wsm) return(NOMORE);
if (! m_whitespace(*name)) break;
}
while (TRUE)
{
i++;
if (i >= CNAMELEN)
{
while (! m_whitespace((M_WCHAR) (c = readchar(TRUE)))
&& c != wcl
&& c != wcm
&& c != EOF
&& c != wsm);
unread(c);
break;
}
c = readchar(TRUE);
if (m_whitespace((M_WCHAR) c) ||
c == wsm ||
c == wcl ||
c == wcm ||
c == EOF)
{
unread(c);
break;
}
name[i] = (M_WCHAR) c;
}
name[i] = M_EOS;
for (i = 0 ; i < ccount ; i++)
if (! w_strcmp(name, contexts[i])) return(i);
inccon() ;
i = w_strlen(name) + 1;
contexts[ccount - 1] = (M_WCHAR *) m_malloc(i, "context name");
memcpy(contexts[ccount - 1], name, i * sizeof(M_WCHAR));
mb_name = MakeMByteString(name);
fprintf(context, "#define %s %d\n", mb_name, ccount);
m_free(mb_name,"multi-byte string");
return(ccount - 1);
}
/* Read a delimiter name from the input line */
LOGICAL getdname(M_NOPAR)
{
int c;
M_WCHAR *p;
/* Skip leading blanks */
while (TRUE)
{
c = readchar(TRUE);
if (c == EOF) return(FALSE);
if (! m_whitespace((M_WCHAR) c)) break;
}
for (p = dname;
! m_whitespace((M_WCHAR) c) && c != EOF;
c = readchar(TRUE))
{
if (p - dname >= DNAMELEN)
{
while (! m_whitespace((M_WCHAR) c) && c != EOF) c = readchar(TRUE);
break;
}
*p++ = (M_WCHAR) c;
}
*p = M_EOS;
if (dstruct = (struct dstruct *) m_lookfortrie(dname, &delimtrie))
{
withdelim = TRUE;
curdelim = dstruct->count - 1;
}
else
{
char *mb_dname;
curdelim = dcount;
incdelim();
withdelim = FALSE;
mb_dname = MakeMByteString(dname);
fprintf(delim, "#define %s %d\n", mb_dname, dcount);
m_free(mb_dname,"multi-byte string");
}
return(TRUE);
}
/* Out of context space. Increase. */
void inccon(M_NOPAR)
{
M_TRIE **newtrie = NULL;
int *newtransit = NULL;
M_WCHAR **newcontexts = NULL;
int trysize;
int i, j;
if (ccount < NUMCON) {
ccount++;
return;
}
trysize = m_plus10p(NUMCON);
newtrie = (M_TRIE **) calloc(trysize, sizeof(M_TRIE *));
newtransit = (int *) calloc(trysize * NUMDELIM, sizeof(int));
newcontexts = (M_WCHAR **) calloc(trysize, sizeof(M_WCHAR *));
if (! newtrie || ! newtransit || ! newcontexts) {
trysize = NUMCON + 1;
if (newtrie) free((M_POINTER) newtrie);
if (newtransit) free((M_POINTER) newtransit);
if (newcontexts) free((M_POINTER) newcontexts);
newtrie = (M_TRIE **) calloc(trysize, sizeof(M_TRIE *));
newtransit = (int *) calloc(trysize * NUMDELIM, sizeof(int));
newcontexts = (M_WCHAR **) calloc(trysize, sizeof(M_WCHAR *));
}
if (! newtrie || ! newtransit || ! newcontexts) {
m_error("Out of memory for contexts");
exit(TRUE);
}
for (i = 0 ; i < ccount ; i++)
for (j = 0 ; j < dcount ; j++)
newtransit[i * NUMDELIM + j] = transit(i, j);
NUMCON = trysize;
free((M_POINTER) xtransit);
xtransit = newtransit;
memcpy((M_POINTER) newtrie, (M_POINTER) contree,
ccount * sizeof(M_TRIE **));
memcpy((M_POINTER) newcontexts, (M_POINTER) contexts,
ccount * sizeof(M_WCHAR **));
free((M_POINTER) contree);
free((M_POINTER) contexts);
contree = newtrie;
contexts = newcontexts;
ccount++;
}
/* Increase delimiter space. */
void incdelim(M_NOPAR)
{
int *newtransit = NULL;
char **newdlm = NULL;
int trysize;
int i, j;
if (dcount < NUMDELIM)
{
dcount++;
return;
}
trysize = m_plus10p(NUMDELIM);
newtransit = (int *) calloc(NUMCON * trysize, sizeof(int));
if (loading) newdlm = (char **) calloc(trysize, sizeof(M_WCHAR *));
if (! newtransit || (loading && ! newdlm))
{
trysize = NUMDELIM + 1;
newtransit = (int *) calloc(NUMCON * trysize, sizeof(int));
if (loading) newdlm = (char **) calloc(trysize, sizeof(M_WCHAR *));
}
if (! newtransit || (loading && ! newdlm))
{
m_error("Out of memory for delimiters");
exit(TRUE);
}
for (i = 0 ; i < ccount ; i++)
for (j = 0 ; j < dcount ; j++)
newtransit[i * trysize + j] = transit(i, j);
free((M_POINTER) xtransit);
if (loading)
{
memcpy((M_POINTER) newdlm, (M_POINTER) dlmptr, dcount * sizeof(M_TRIE **));
free((M_POINTER) dlmptr);
dlmptr = newdlm;
}
NUMDELIM = trysize;
xtransit = newtransit;
dcount++;
}
/* Read delimiter definitions from delim.dat */
void loaddelim(M_NOPAR)
{
int c;
M_WCHAR *p;
int i;
M_WCHAR wnl;
char *mb_dname, *mb_dstring;
mbtowc(&wnl, "\n", 1);
loading = TRUE;
while ((c = getc(ddat)) != EOF)
{
/* Skip leading white space */
if (c == wnl) continue;
if (m_whitespace((M_WCHAR) c))
{
while ((c = getc(ddat)) != wnl)
if (c == EOF) return;
continue;
}
/* Delimiter name into dname */
for (p = dname ; ! m_whitespace((M_WCHAR) c) ; c = getc(ddat))
{
if (c == EOF)
{
warning("Unexpected EOF");
exit(TRUE);
}
if (p - dname >= DNAMELEN)
{
while (! m_whitespace((M_WCHAR) c) && c != EOF) c = getc(ddat);
if (c == EOF)
{
warning("Unexpected EOF");
exit(TRUE);
}
break;
}
*p++ = m_upper(c);
}
*p = M_EOS;
/* Skip intervening white space */
while (m_whitespace((M_WCHAR) c) && c != EOF) c = getc(ddat);
if (c == EOF)
{
warning("Unexpected EOF");
exit(TRUE);
}
/* Delimiter string into dstring */
for (p = dstring;
! m_whitespace((M_WCHAR) c) && c != EOF;
c = getc(ddat))
{
if (p - dstring >= DELIMLEN)
{
m_error("Delimiter string too long");
exit(TRUE);
}
*p++ = c;
}
*p = M_EOS;
if (w_strlen(dstring) > maxd) maxd = w_strlen(dstring);
/* Write definitions to output file. Save data for later. */
incdelim();
dstruct = (struct dstruct *)
m_malloc(sizeof(struct dstruct), "delimiter structure");
dstruct->string = (M_WCHAR *) m_malloc(w_strlen(dstring) + 1, "delimiter");
w_strcpy(dstruct->string, dstring);
dstruct->count = dcount;
mb_dname = MakeMByteString(dname);
fprintf(delim, "#define %s %d\n", mb_dname, dcount);
m_free(mb_dname,"multi-byte string");
for (i = 0 ; dname[i] ; i++)
dname[i] = m_lower(dname[i]);
mb_dname = MakeMByteString(dname);
mb_dstring = MakeMByteString(dstring);
fprintf(delim,
"M_DELIMEXTERN char %s[%d] M_DELIMINIT(\"",
mb_dname,
strlen(mb_dstring) + 1);
for (p = dstring ; *p ; p++)
{
char *pc;
char mb_p[32]; /* arbitrarily large */
int length, i;
length = wctomb(mb_p, *p);
mb_p[length] = 0;
pc = mb_p;
while (*pc)
{
if (*pc == '"' || *pc == '\\') putc('\\', delim);
putc(*pc, delim);
pc++;
}
}
fputs("\") ;\n", delim);
dlmptr[dcount - 1] = MakeMByteString(dname);
if (m_ntrtrie(dname, &delimtrie, dstruct))
m_err1("Duplicate definition of %s", mb_dname);
while (c != wnl)
{
if (c == EOF) break;
c = getc(ddat);
}
m_free(mb_dname,"multi-byte string");
m_free(mb_dstring,"multi-byte string");
}
dumpdlmptr();
loading = FALSE;
}
/* Output transition matrix */
#if defined(M_PROTO)
void nextcon(LOGICAL sparse)
#else
void nextcon(sparse)
LOGICAL sparse;
#endif
{
int i, j;
int firstinrow;
if (sparse) {
for (i = 0 ; i < ccount ; i++) {
for (j = 0 ; j < dcount ; j++)
if (transit(i, j)) nonzero++;
nonzero++;
}
fprintf(delim,
"M_DELIMEXTERN struct {\n %s context ;\n %s nextcon ;\n",
contype, contype);
fprintf(delim, " } m_trnsit [%d]\n", nonzero);
nonzero = 0;
fprintf(delim, "#if defined(M_DELIMDEF)\n = {\n");
fprintf(context, "M_CONEXTERN int m_trnsptr[%d]\n", ccount);
fprintf(context, "#if defined(M_CONDEF)\n = {\n");
for (i = 0 ; i < ccount ; i++) {
firstinrow = 0;
for (j = 0 ; j < dcount ; j++) {
if (! transit(i, j)) continue;
prtctxt(j, transit(i, j));
if (! firstinrow) firstinrow = nonzero;
}
prtctxt(0, 0);
if (i > 0) fprintf(context, ",\n");
fprintf(context, " %d", firstinrow);
}
fprintf(delim, endif);
fprintf(context, endif);
}
else {
fprintf(context,
"M_CONEXTERN %s m_nextcon[%d][%d]\n#if defined(M_CONDEF)\n = {\n",
contype, ccount, dcount);
for (i = 0 ; i < ccount ; i++) {
fprintf(context, " {\n");
for (j = 0 ; j < dcount ; j++) {
fprintf(context, " %d", transit(i, j));
if (j < dcount - 1) fprintf(context, ",\n");
}
fprintf(context, "}");
if (i < ccount - 1) fprintf(context, ",");
fprintf(context, "\n");
}
fprintf(context, endif);
}
}
/* If sparse matrix output option, generate a single element of transit
array */
void prtctxt(column, value)
int column, value;
{
static LOGICAL first = TRUE;
if (! first) fprintf(delim, ",\n");
first = FALSE;
fprintf(delim, " %d, %d", column, value);
nonzero++;
}
/* Read the next input character */
#if defined(M_PROTO)
int readchar(LOGICAL cap)
#else
int readchar(cap)
LOGICAL cap;
#endif
{
int c;
M_WCHAR wnl;
mbtowc(&wnl, "\n", 1);
c = mb_getwc(cdat); /* use mb_getwc so we read multi-byte chars */
if (cap && c != EOF) c = m_upper(c);
if (c == wnl) m_line++;
return(c);
}
/* Called by utility procedure m_error() -- has content in other programs
that use m_error() */
void skiptoend(M_NOPAR)
{
}
/* Return a character to the input stream for re-reading */
void unread(c)
int c;
{
M_WCHAR wnl;
mbtowc(&wnl, "\n", 1);
ungetc(c, cdat);
if (c == wnl) m_line--;
}

View File

@@ -0,0 +1,81 @@
/* $XConsortium: dtddef.h /main/3 1995/11/08 11:03:31 rswiston $ */
/* Copyright (c) 1988, 1989 Hewlett-Packard Co. */
/* Dtddef.h contains definitions relevant to document-type
definitions */
typedef int M_ELEMENT ;
typedef int M_ARC ;
typedef int M_STATE ;
typedef int M_ANDGROUP ;
/* Possible element content types */
#define M_REGEXP 0
#define M_ANY 1
#define M_NONE 2
#define M_CDATA 3
#define M_RCDATA 4
typedef struct{
int enptr, start, content, inptr, exptr, parptr, parcount, srefptr ;
unsigned int smin : 1, emin : 1, useoradd : 1 ;
} M_ELTSTRUCT ;
typedef struct {
int paramname, type, kwlist, deftype ;
M_WCHAR *defval ;
} M_PARAMETER ;
/* Possible parameter default types */
#define M_NAMEDEF 0
#define M_CURRENT 1
#define M_REQUIRED 2
#define M_NULLDEF 3
#define M_CHANGEDCUR 4
/* Possible parameter types */
#define M_KEYWORD 0
#define M_ID 1
#define M_IDRF 2
#define M_IDRFS 3
#define M_NAMEPAR 4
#define M_NAMES 5
#define M_NMTOKEN 6
#define M_NMSTOKEN 7
#define M_NUMBER 8
#define M_NUMS 9
#define M_NUTOKEN 10
#define M_NUSTOKEN 11
#define M_CDATT 12
#define M_ENTATT 13
typedef struct {
int sref ;
int entity ;
int next ;
} M_SREF ;
typedef struct {
unsigned final : 1, datacontent : 1 ;
unsigned first : 14 ;
} M_STATESTRUCT ;
typedef struct {
M_STATE start ;
M_ANDGROUP next ;
} M_ANDSTRUCT ;
typedef struct {
M_ELEMENT element ;
int next ;
} M_EXCEPTION ;
typedef struct {
unsigned label : 15;
unsigned optional : 1;
int minim ;
M_ANDGROUP group ;
M_STATE to ;
M_ARC next ;
} M_ARCSTRUCT ;

View File

@@ -0,0 +1,46 @@
/* $XConsortium: dtdext.h /main/3 1995/11/08 11:03:45 rswiston $ */
/* Copyright (c) 1988, 1989 Hewlett-Packard Co. */
/* Dtdext.h contains the dtd-independent external forms of
declarations relevant to document-type definitions. The
definition form of these declarations is contained in files
dtd.h and arc.h generated by BUILD. */
#include "dtddef.h"
extern M_PTRIE m_entree[] ;
extern M_WCHAR m_ename[] ;
extern int m_elcount ;
extern M_ELTSTRUCT m_element[] ;
extern M_WCHAR m_keyword[] ;
extern M_WCHAR m_defval[] ;
extern struct {
int keyword, next ;
} m_ptype[] ;
extern M_PARAMETER m_parameter[] ;
extern M_WCHAR m_pname[] ;
extern M_PTRIE m_maptree[] ;
extern M_PTRIE m_sreftree[] ;
extern int m_map[] ;
extern M_SREF m_sref[] ;
extern M_STATESTRUCT m_state[] ;
extern M_ANDSTRUCT m_andgroup[] ;
extern M_EXCEPTION m_exception[] ;
extern M_ARCSTRUCT m_arc[] ;

View File

@@ -0,0 +1,27 @@
/* $XConsortium: emptyfil.c /main/3 1995/11/08 11:04:00 rswiston $ */
/* Copyright (c) 1988, 1989 Hewlett-Packard Co. */
/* Creates a file with nothing in it */
#include <stdio.h>
#if defined(MSDOS)
#include <process.h>
#endif
#include "basic.h"
void main(
#if defined(M_PROTO)
int argc, char **argv
#endif
) ;
void main(argc, argv)
int argc ;
char **argv ;
{
if (argc != 2) {
fprintf(stderr, "Usage: emptyfil filename\n") ;
exit(1) ;
}
if (! fopen(argv[1], "w"))
fprintf(stderr, "Unable to open %s\n", argv[1]) ;
return 0;
}

View File

@@ -0,0 +1,21 @@
/* $XConsortium: entdef.h /main/3 1995/11/08 11:04:14 rswiston $ */
/* Copyright (c) 1988, 1989 Hewlett-Packard Co. */
/* Entdef.h contains definitions relevant to entities */
#define M_GENERAL 0
#define M_SYSTEM 1
#define M_STARTTAG 2
#define M_ENDTAG 3
#define M_MD 4
#define M_MS 5
#define M_PI 6
#define M_CDATAENT 7
#define M_SDATA 8
#define M_CODEPI 9
#define M_CODESDATA 10
#define M_DBUILD 1
#define M_DELTDEF 2
#define M_DPARSER 3

View File

@@ -0,0 +1,22 @@
/* $XConsortium: entext.h /main/3 1995/11/08 11:04:28 rswiston $ */
/* Copyright (c) 1988, 1989 Hewlett-Packard Co. */
/* Entext.h contains the dtd- and interface-independent external
forms of declarations relevant to entity declarations that occur in a
dtd or interface. The definition form of these declarations is
contained in files entity.h generated by BUILD and entity2.h
generated by ELTDEF */
#include "entdef.h"
extern M_WCHAR m_entcon[] ;
extern M_WCHAR m_entname[] ;
extern M_ENTITY m_entities[] ;
extern M_TRIE m_enttrie[] ;
#if defined(ELTEXTERN)
extern int m_entcnt ;
extern M_ENTITY *firstent ;
extern M_ENTITY *lastent ;
#endif

View File

@@ -0,0 +1,209 @@
/* $XConsortium: entout.c /main/3 1995/11/08 11:04:43 rswiston $ */
/* Copyright (c) 1986, 1987, 1988, 1989 Hewlett-Packard Co. */
/* Entout has procedures to write generated entity TRIE */
void entptr(
#if defined(M_PROTO)
M_ENTITY *data
#endif
) ;
char *typetype(
#if defined(M_PROTO)
int n
#endif
) ;
char *typewhere(
#if defined(M_PROTO)
unsigned char n
#endif
) ;
/* Macro names written to output file */
char xdbuild[] = "M_DBUILD" ;
char xdeltdef[] = "M_DELTDEF" ;
char xgeneral[] = "M_GENERAL" ;
char xsystem[] = "M_SYSTEM" ;
char xstarttag[] = "M_STARTTAG" ;
char xendtag[] = "M_ENDTAG" ;
char xmd[] = "M_MD" ;
char xms[] = "M_MS" ;
char xpi[] = "M_PI" ;
char xcdataent[] = "M_CDATAENT" ;
char xsdata[] = "M_SDATA" ;
char xcodepi[] = "M_CODEPI" ;
char xcodesdata[] = "M_CODESDATA" ;
char xerror[] = "ERROR" ;
/* Outputs entity definitions */
#define ENTFILENAME 12
void entout(fname)
char *fname ;
{
char efilename[ENTFILENAME] ;
int count = 1 ;
M_ENTITY *ent ;
M_WCHAR *p ;
int conindex ;
int nameindex ;
LOGICAL start ;
strcpy(efilename, fname) ;
strcpy(&efilename[strlen(efilename)], ".h") ;
m_openchk(&entfile, efilename, "w") ;
fprintf(entfile, "#include \"entdef.h\"\n") ;
fprintf(entfile, "#if defined(M_ENTDEF)\n") ;
fprintf(entfile, "#define M_ENTEXTERN\n") ;
fprintf(entfile, "#define M_ENTINIT(a) = a\n") ;
fprintf(entfile, "#else\n") ;
fprintf(entfile, "#define M_ENTEXTERN extern\n") ;
fprintf(entfile, "#define M_ENTINIT(a)\n") ;
fprintf(entfile, "#endif\n\n") ;
if (m_entcnt) {
for (ent = firstent, conindex = 0, nameindex = 0 ;
ent ; ent = ent->next) {
if (ent->content) conindex += w_strlen(ent->content) + 1 ;
nameindex += w_strlen(ent->name) + 1 ;
}
fprintf(entfile, "M_ENTEXTERN M_WCHAR m_entcon[%d]\n",
conindex ? conindex : 1) ;
if (conindex) {
fputs("#if defined(M_ENTDEF)\n = {\n", entfile) ;
start = FALSE ;
for (ent = firstent ; ent ; ent = ent->next)
if (ent->content) {
if (start) fputs(",\n", entfile) ;
start = TRUE ;
for (p = ent->content ; *p ; p++)
fprintf(entfile, " %d,\n", *p) ;
fputs(" 0", entfile) ;
}
fprintf(entfile, "}\n#endif\n") ;
}
fputs(" ;\n\n", entfile) ;
fprintf(entfile, "M_ENTEXTERN M_WCHAR m_entname[%d]\n", nameindex) ;
fputs("#if defined(M_ENTDEF)\n = {\n", entfile) ;
for (ent = firstent ; ent ; ent = ent->next) {
for (p = ent->name ; *p ; p++)
fprintf(entfile, " %d,\n", *p) ;
if (ent != lastent) fputs(" 0,\n", entfile) ;
else fputs(" 0\n", entfile) ;
}
fprintf(entfile, "}\n#endif\n ;\n\n") ;
}
else {
fputs("M_ENTEXTERN M_WCHAR m_entcon[1] ;\n", entfile) ;
fputs("M_ENTEXTERN M_WCHAR m_entname[1] ;\n", entfile) ;
}
fprintf(entfile, "M_ENTEXTERN M_ENTITY m_entities[%d]\n",
m_entcnt ? m_entcnt : 1) ;
if (m_entcnt) {
fprintf(entfile, "#if defined(M_ENTDEF)\n = {\n") ;
for (ent = firstent, conindex = 0, nameindex = 0 ;
ent ; ent = ent->next) {
fprintf(entfile, " %s, %s, ",
typetype(ent->type),
typewhere(ent->wheredef)) ;
if (ent->content) {
fprintf(entfile, "&m_entcon[%d]", conindex) ;
conindex += w_strlen(ent->content) + 1 ;
}
else fputs(" NULL", entfile) ;
fprintf(entfile, ", &m_entname[%d]", nameindex) ;
nameindex += w_strlen(ent->name) + 1 ;
#if defined(BUILDEXTERN)
fprintf(entfile, ", %d", ent->index) ;
if (ent != lastent)
fprintf(entfile, ", &m_entities[%d], 0", ent->index) ;
else fputs(", NULL, 0", entfile) ;
#else
fprintf(entfile, ", %d", ent->codeindex) ;
#endif
if (ent != lastent) fprintf(entfile, ", \n") ;
else fprintf(entfile, "}\n#endif\n") ;
}
}
fprintf(entfile, " ;\n\n") ;
if (m_enttrie->data) countdown(m_enttrie, &count) ;
fprintf(entfile,
"M_ENTEXTERN M_TRIE m_enttrie[%d]\n", count) ;
if (m_enttrie->data) {
count = 0 ;
fputs("#if defined(M_ENTDEF)\n = {\n 0, NULL, &m_enttrie[1]", entfile) ;
m_dumptrie(entfile, m_enttrie->data, "m_enttrie", &count, entptr) ;
fprintf(entfile, "}\n#endif\n") ;
}
fprintf(entfile, " ;\n\n") ;
#if defined(BUILDEXTERN)
fprintf(entfile, "M_ENTEXTERN int m_entcnt M_ENTINIT(%d) ;\n", m_entcnt) ;
#endif
#if defined(BUILDEXTERN)
if (m_entcnt) {
fputs("M_ENTEXTERN M_ENTITY *firstent M_ENTINIT(&m_entities[0]) ;\n",
entfile) ;
fprintf(entfile,
"M_ENTEXTERN M_ENTITY *lastent M_ENTINIT(&m_entities[%d]) ;\n",
m_entcnt - 1) ;
}
else {
fputs("M_ENTEXTERN M_ENTITY *firstent M_ENTINIT(NULL) ;\n", entfile) ;
fputs("M_ENTEXTERN M_ENTITY *lastent M_ENTINIT(NULL) ;\n", entfile) ;
}
#endif
} /* End entout() */
/* Entptr is called by m_dumptrie to output the value stored with a
particular entity in the entity trie */
void entptr(data)
M_ENTITY *data ;
{
fprintf(entfile, "(M_TRIE *) &m_entities[%d]", data->index - 1) ;
}
/* Typetype returns a string indicating the type of the nth entity.*/
char *typetype(n)
int n ;
{
switch(n) {
case M_GENERAL: return(xgeneral) ;
case M_SYSTEM: return(xsystem) ;
case M_STARTTAG: return(xstarttag) ;
case M_ENDTAG: return(xendtag) ;
case M_MD: return(xmd) ;
case M_MS: return(xms) ;
case M_PI: return(xpi) ;
case M_CDATAENT: return(xcdataent) ;
case M_SDATA: return(xsdata) ;
case M_CODEPI: return(xcodepi) ;
case M_CODESDATA: return(xcodesdata) ;
default: return(xerror) ;
}
}
/* Typewhere returns a string indicating where the nth entity was defined.*/
#if defined(M_PROTO)
char *typewhere(unsigned char n)
#else
char *typewhere(n)
unsigned char n ;
#endif
{
switch(n) {
case M_DBUILD: return(xdbuild) ;
case M_DELTDEF: return(xdeltdef) ;
case FALSE: return("0") ;
}
}

View File

@@ -0,0 +1,417 @@
/* $XConsortium: error.c /main/3 1995/11/08 11:04:57 rswiston $ */
/* Copyright (c) 1986, 1987, 1988, 1989 Hewlett-Packard Co. */
/* Error.c contains procedures for issuing error messages and warnings in
BUILD and ELTDEF */
#include <stdio.h>
#include "basic.h"
extern FILE *m_errfile ;
extern int m_line ;
extern LOGICAL errexit ;
void eprefix(
#if defined(M_PROTO)
LOGICAL flag
#endif
) ;
void m_errline(
#if defined(M_PROTO)
char *text
#endif
) ;
void m_error(
#if defined(M_PROTO)
char *text
#endif
) ;
void m_err1(
#if defined(M_PROTO)
char *text, const M_WCHAR *arg
#endif
) ;
void m_mberr1(
#if defined(M_PROTO)
char *text, const char *arg
#endif
) ;
void m_err2(
#if defined(M_PROTO)
const char *text, const M_WCHAR *arg1, const M_WCHAR *arg2
#endif
) ;
void m_err3(
#if defined(M_PROTO)
char *text, M_WCHAR *arg1, M_WCHAR *arg2, M_WCHAR *arg3
#endif
) ;
void m_err5(
#if defined(M_PROTO)
char *text, M_WCHAR *arg1, M_WCHAR *arg2, M_WCHAR *arg3, M_WCHAR *arg4,
M_WCHAR *arg5
#endif
) ;
void esuffix(
#if defined(M_PROTO)
void
#endif
) ;
void msgline(
#if defined(M_PROTO)
char *text
#endif
) ;
void msg1line(
#if defined(M_PROTO)
char *text, char *arg1
#endif
) ;
void skiptoend(
#if defined(M_PROTO)
M_NOPAR
#endif
) ;
void m_wctrace(
#if defined(M_PROTO)
M_WCHAR *text
#endif
) ;
void m_trace(
#if defined(M_PROTO)
char *text
#endif
) ;
void warning(
#if defined(M_PROTO)
char *text
#endif
) ;
void warning1(
#if defined(M_PROTO)
char *text, M_WCHAR *arg
#endif
) ;
void warning2(
#if defined(M_PROTO)
char *text, M_WCHAR *arg1, M_WCHAR *arg2
#endif
) ;
void warning3(
#if defined(M_PROTO)
char *text, M_WCHAR *arg1, M_WCHAR *arg2, M_WCHAR *arg3
#endif
) ;
void warning4(
#if defined(M_PROTO)
char *text, M_WCHAR *arg1, M_WCHAR *arg2, M_WCHAR *arg3, M_WCHAR *arg4
#endif
) ;
/* Write error message prefix */
#if defined(M_PROTO)
void eprefix(LOGICAL flag)
#else
void eprefix(flag)
LOGICAL flag ;
#endif
{
if (flag) errexit = TRUE ;
fprintf(stderr, "\n**** ") ;
fprintf(m_errfile, "\n**** ") ;
}
/* Writes part of an error message. Called from m_malloc instead of
m_err1, since PARSER's version of m_err1 calls m_malloc and recursive
calls are possible when the heap is exhausted */
void m_errline(text)
char *text ;
{
fputs(text, stderr) ;
fputs(text, m_errfile) ;
}
/* Writes an error message to standard error and file "error" */
void m_error(text)
char *text ;
{
eprefix(TRUE) ;
fprintf(stderr,"%s", text) ;
fprintf(m_errfile,"%s", text) ;
esuffix() ;
skiptoend() ;
}
/* Writes an error message with one argument to standard error and file
"error" */
#if defined(M_PROTO)
void m_err1(char *text, const M_WCHAR *arg)
#else
void m_err1(text, arg)
char *text;
M_WCHAR *arg ;
#endif
{
char *mb_arg;
mb_arg = MakeMByteString(arg);
eprefix(TRUE) ;
fprintf(stderr, text, mb_arg) ;
fprintf(m_errfile, text, mb_arg) ;
esuffix() ;
skiptoend() ;
m_free(mb_arg,"multi-byte string");
}
#if defined(M_PROTO)
void m_mberr1(char *text, const char *arg)
#else
void m_err1(text, arg)
char *text;
char *arg ;
#endif
{
eprefix(TRUE) ;
fprintf(stderr, text, arg) ;
fprintf(m_errfile, text, arg) ;
esuffix() ;
skiptoend() ;
}
/* Writes an error message with two arguments to standard error and file
"error" */
#if defined(M_PROTO)
void m_err2( const char *text, const M_WCHAR *arg1, const M_WCHAR *arg2)
#else
void m_err2(text, arg1, arg2)
char *text;
M_WCHAR *arg1, *arg2 ;
#endif
{
char *mb_arg1, *mb_arg2;
mb_arg1 = MakeMByteString(arg1);
mb_arg2 = MakeMByteString(arg2);
eprefix(TRUE) ;
fprintf(stderr, text, mb_arg1, mb_arg2) ;
fprintf(m_errfile, text, mb_arg1, mb_arg2) ;
esuffix() ;
skiptoend() ;
m_free(mb_arg1,"multi-byte string");
m_free(mb_arg2,"multi-byte string");
}
/* Writes an error message with three arguments to standard error and file
"error" */
#if defined(M_PROTO)
void m_err3( char *text, M_WCHAR *arg1, M_WCHAR *arg2, M_WCHAR *arg3)
#else
void m_err3(text, arg1, arg2, arg3)
char *text;
M_WCHAR *arg1, *arg2, *arg3 ;
#endif
{
char *mb_arg1, *mb_arg2, *mb_arg3;
mb_arg1 = MakeMByteString(arg1);
mb_arg2 = MakeMByteString(arg2);
mb_arg3 = MakeMByteString(arg3);
eprefix(TRUE) ;
fprintf(stderr, text, mb_arg1, mb_arg2, mb_arg3) ;
fprintf(m_errfile, text, mb_arg1, mb_arg2, mb_arg3) ;
esuffix() ;
skiptoend() ;
m_free(mb_arg1,"multi-byte string");
m_free(mb_arg2,"multi-byte string");
m_free(mb_arg3,"multi-byte string");
}
/* Writes an error message with five arguments to standard error and file
"error" */
#if defined(M_PROTO)
void m_err5( char *text, M_WCHAR *arg1, M_WCHAR *arg2, M_WCHAR *arg3,
M_WCHAR *arg4, M_WCHAR *arg5)
#else
void m_err5(text, arg1, arg2, arg3, arg4, arg5)
char *text;
M_WCHAR *arg1, *arg2, *arg3, *arg4, *arg5 ;
#endif
{
char *mb_arg1, *mb_arg2, *mb_arg3, *mb_arg4, *mb_arg5;
mb_arg1 = MakeMByteString(arg1);
mb_arg2 = MakeMByteString(arg2);
mb_arg3 = MakeMByteString(arg3);
mb_arg4 = MakeMByteString(arg4);
mb_arg5 = MakeMByteString(arg5);
fprintf(stderr, text, mb_arg1, mb_arg2, mb_arg3, mb_arg4, mb_arg5) ;
fprintf(m_errfile, text, mb_arg1, mb_arg2, mb_arg3, mb_arg4, mb_arg5) ;
esuffix() ;
skiptoend() ;
m_free(mb_arg1,"multi-byte string");
m_free(mb_arg2,"multi-byte string");
m_free(mb_arg3,"multi-byte string");
m_free(mb_arg4,"multi-byte string");
m_free(mb_arg5,"multi-byte string");
}
/* Write error message suffix */
void esuffix(M_NOPAR)
{
fprintf(stderr, " (line %d) ****\n", m_line) ;
fprintf(m_errfile, " (line %d) ****\n", m_line) ;
}
/* Print something to both stderr and m_errfile */
void msgline(text)
char *text ;
{
fprintf(stderr, text) ;
fprintf(m_errfile, text) ;
}
/* Print something to both stderr and m_errfile */
void msg1line(text, arg1)
char *text, *arg1 ;
{
fprintf(stderr, text, arg1) ;
fprintf(m_errfile, text, arg1) ;
}
/* Trace used for m_malloc trace output */
void m_trace(text)
char *text ;
{
m_errline(text) ;
}
void m_wctrace(text)
M_WCHAR *text ;
{
char *mb_text;
mb_text = MakeMByteString(text);
m_trace(mb_text);
m_free(mb_text,"multi-byte string");
}
/* Writes a nonfatal error message to standard error and file "error" */
void warning(text)
char *text ;
{
eprefix(FALSE) ;
fprintf(stderr,"%s", text) ;
fprintf(m_errfile,"%s", text) ;
esuffix() ;
}
/* Writes a nonfatal error message with one argument to standard error
and file "error" */
#if defined(M_PROTO)
void warning1( char *text, M_WCHAR *arg)
#else
void warning1(text, arg)
char *text;
M_WCHAR *arg ;
#endif
{
char *mb_arg;
mb_arg = MakeMByteString(arg);
eprefix(FALSE) ;
fprintf(stderr, text, mb_arg) ;
fprintf(m_errfile, text, mb_arg) ;
esuffix() ;
m_free(mb_arg,"multi-byte string");
}
/* Writes a nonfatal error message with two arguments to standard error
and file "error" */
#if defined(M_PROTO)
void warning2(char *text, M_WCHAR *arg1, M_WCHAR *arg2)
#else
void warning2(text, arg1, arg2)
char *text;
M_WCHAR *arg1, *arg2 ;
#endif
{
char *mb_arg1, *mb_arg2;
mb_arg1 = MakeMByteString(arg1);
mb_arg2 = MakeMByteString(arg2);
eprefix(FALSE) ;
fprintf(stderr, text, mb_arg1, mb_arg2) ;
fprintf(m_errfile, text, mb_arg1, mb_arg2) ;
esuffix() ;
m_free(mb_arg1,"multi-byte string");
m_free(mb_arg2,"multi-byte string");
}
/* Writes a nonfatal error message with three arguments to standard error
and file "error" */
#if defined(M_PROTO)
void warning3(char *text, M_WCHAR *arg1, M_WCHAR *arg2, M_WCHAR *arg3)
#else
void warning3(text, arg1, arg2, arg3)
char *text;
M_WCHAR *arg1, *arg2, *arg3 ;
#endif
{
char *mb_arg1, *mb_arg2, *mb_arg3;
mb_arg1 = MakeMByteString(arg1);
mb_arg2 = MakeMByteString(arg2);
mb_arg3 = MakeMByteString(arg3);
eprefix(FALSE) ;
fprintf(stderr, text, mb_arg1, mb_arg2, mb_arg3) ;
fprintf(m_errfile, text, mb_arg1, mb_arg2, mb_arg3) ;
esuffix() ;
m_free(mb_arg1,"multi-byte string");
m_free(mb_arg2,"multi-byte string");
m_free(mb_arg3,"multi-byte string");
}
/* Writes a nonfatal error message with four arguments to standard error
and file "error" */
#if defined(M_PROTO)
void warning4(char *text, M_WCHAR *arg1, M_WCHAR *arg2, M_WCHAR *arg3,
M_WCHAR *arg4)
#else
void warning4(text, arg1, arg2, arg3, arg4)
char *text;
M_WCHAR *arg1, *arg2, *arg3, *arg4 ;
#endif
{
char *mb_arg1, *mb_arg2, *mb_arg3, *mb_arg4;
mb_arg1 = MakeMByteString(arg1);
mb_arg2 = MakeMByteString(arg2);
mb_arg3 = MakeMByteString(arg3);
mb_arg4 = MakeMByteString(arg4);
eprefix(FALSE) ;
fprintf(stderr, text, mb_arg1, mb_arg2, mb_arg3, mb_arg4) ;
fprintf(m_errfile, text, mb_arg1, mb_arg2, mb_arg3, mb_arg4) ;
esuffix() ;
m_free(mb_arg1,"multi-byte string");
m_free(mb_arg2,"multi-byte string");
m_free(mb_arg3,"multi-byte string");
m_free(mb_arg4,"multi-byte string");
}

View File

@@ -0,0 +1,24 @@
/* $XConsortium: exit.c /main/3 1995/11/08 11:05:12 rswiston $ */
/*
Copyright 1988, 1989 Hewlett-Packard Co.
*/
#if defined(MSDOS)
#include <process.h>
#endif
#include "basic.h"
void m_exit(
#if defined(M_PROTO)
int status
#endif
) ;
/* Exit function called by utilities used in PARSER and other programs in
the MARKUP system */
void m_exit(status)
int status ;
{
exit(status) ;
}

View File

@@ -0,0 +1,159 @@
/* $XConsortium: fclndir.c /main/3 1995/11/08 11:05:25 rswiston $ */
/* Copyright (c) 1987-1990 Hewlett-Packard Co.
Fclndir.c compares two files, ignoring C line directives that appear
within them as well as blank lines, and leading white space. It exits
with an error code of 0 if the files are the same, 1 if they differ, and
2 if the program was called incorrectly.
*/
/* Feb. 11, 1991, CED: Added v2 fixes to v3 version of fclndir.
Thus, both versions now copy the source file to the target if
the files differ.
*/
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#if defined(MSDOS)
#include <process.h>
#endif
#include "basic.h"
#define SAME 0
/* different defined to be 0 as of 12-1-89, because fclndir now does
the file-copy if the files are different, or if the second file
doesn't exist. (different used to be 1.) --ced */
#define DIFFERENT 0
#define ERROR 2
struct data {
int c ;
LOGICAL linestart ;
char *p ;
char *q ;
} data1, data2 ;
char linedir[] = "#line" ;
char *p = linedir, *q = linedir + 1 ;
void main(
#if defined(M_PROTO)
int argc, char **argv
#endif
) ;
void copyfile(
#if defined(m_proto)
char *pfile1, char *pfile2
#endif
) ;
int nextchar(
#if defined (M_PROTO)
FILE *file, struct data *data
#endif
) ;
void main(argc, argv)
int argc ;
char **argv ;
{
FILE *one, *two ;
int c1, c2 ;
if (argc != 3) {
fputs("Usage: fclndir file1 (=source) file2 (=target)\n", stderr) ;
exit(ERROR) ;
}
if (! (one = fopen(argv[1], "r"))) {
fprintf(stderr, "ERROR: source file unavailable: %s\n", argv[1]) ;
exit(ERROR) ;
}
if (! (two = fopen(argv[2], "r"))) {
fprintf(stderr, "No target file %s; copying source file...\n", argv[2]) ;
/* call to copyfile entered by ced, 12-29-89. */
copyfile(argv[1],argv[2]);
exit(DIFFERENT) ;
}
data1.linestart = data2.linestart = TRUE ;
data1.p = data2.p = linedir ;
data1.q = data2.q = linedir + 1 ;
c1 = nextchar(one, &data1) ;
c2 = nextchar(two, &data2) ;
while (c1 != EOF && c2 != EOF) {
if (c1 != c2) {
fprintf(stderr, "%s and %s are different; copying source...\n",
argv[1], argv[2]) ;
/* call to copyfile entered by ced, 12-1-89. */
copyfile(argv[1],argv[2]);
exit(DIFFERENT) ;
}
c1 = nextchar(one, &data1) ;
c2 = nextchar(two, &data2) ;
}
if (c1 != c2) {
fprintf(stderr, "%s and %s are different; copying source...\n",
argv[1], argv[2]) ;
/* call to copyfile entered by ced, 12-1-89. */
copyfile(argv[1],argv[2]);
exit(DIFFERENT) ;
}
fprintf(stderr, "%s and %s are the same\n", argv[1], argv[2]) ;
exit(SAME) ;
}
/* copyfile inserted by ced, 12-1-89. */
void copyfile(pfile1,pfile2)
char *pfile1, *pfile2;
{
int ret;
char *pcmd;
/* malloc space for the system command: two filenames, plus a command,
spaces, and the terminating null */
pcmd = (char *) malloc(strlen(pfile1) + strlen(pfile2) + 8);
#if defined(MSDOS)
ret = sprintf(pcmd,"copy %s %s",pfile1,pfile2);
#else
ret = sprintf(pcmd,"cp %s %s",pfile1,pfile2);
#endif
ret = system(pcmd);
ret = sprintf(pcmd,"touch %s",pfile2);
ret = system(pcmd);
}
int nextchar(file, data)
FILE *file ;
struct data *data ;
{
while (data->linestart) {
data->linestart = FALSE ;
for (data->p = linedir ; *data->p; data->p++)
if ((data->c = getc(file)) != (int) *data->p) break ;
/* Found a line directive, skip remainder of line */
if (! *data->p) {
data->c = getc(file) ;
while (data->c != '\n' && data->c != EOF)
data->c = getc(file) ;
data->linestart = TRUE ;
continue ;
}
/* Check for leading blanks */
else if (data->p == linedir) {
while (data->c == ' ' || data->c == '\t') data->c = getc(file) ;
if (data->c == '\n') {
data->linestart = TRUE ;
continue ;
}
return(data->c) ;
}
/* Line began with a prefix of #line */
data->q = linedir ;
}
if (data->q < data->p) return(*data->q++) ;
else if (data->q++ != data->p) data->c = getc(file) ;
if (data->c == '\n') data->linestart = TRUE ;
return(data->c) ;
}

View File

@@ -0,0 +1,38 @@
/* $XConsortium: inctest.c /main/3 1995/11/08 11:05:40 rswiston $ */
/*
Copyright 1986, 1987, 1988, 1989 Hewlett-Packard Co.
*/
#if defined(MSDOS)
#include <process.h>
#endif
#include "basic.h"
void m_err1(
#if defined(M_PROTO)
const char *text, const char *arg
#endif
) ;
void m_exit(
#if defined(M_PROTO)
int status
#endif
) ;
void m_inctest(
#if defined(M_PROTO)
int *count, int limit, char *message
#endif
) ;
/* Increment a count and test against a limit */
void m_inctest(count, limit, message)
int *count ;
int limit ;
char *message ;
{
if (++*count <= limit) return ;
m_err1("Internal error: %s exceeded", message) ;
m_exit(TRUE) ;
}

View File

@@ -0,0 +1,29 @@
/* $XConsortium: initct.c /main/3 1995/11/08 11:05:54 rswiston $ */
/* Copyright (c) 1987, 1988 Hewlett-Packard Co. */
/* M_initctype initializes the array used to indicate which ASCII
characters can appear within SGML names */
#include "basic.h"
#include "common.h"
extern char m_chartype[M_CHARSETLEN] ;
void m_initctype(
#if defined(M_PROTO)
M_NOPAR
#endif
) ;
void m_initctype(M_NOPAR)
{
int i ;
/* ****************************** NOTE: **********************************
If the set of name characters is ever modified, make appropriate changes
in ELTDEF's scanner for testing for valid C identifiers as parameter
names */
for (i = 0 ; i < M_CHARSETLEN ; i++) m_chartype[i] = M_NONNAME ;
for (i = 'A' ; i <= 'Z' ; i++) m_chartype[i] = M_NMSTART ;
for (i = 'a' ; i <= 'z' ; i++) m_chartype[i] = M_NMSTART ;
for (i = '0' ; i <= '9' ; i++) m_chartype[i] = M_DIGIT ;
m_chartype['.'] = m_chartype['-'] = M_NAMECHAR ;
}

View File

@@ -0,0 +1,50 @@
/* $XConsortium: itoa.c /main/3 1995/11/08 11:06:09 rswiston $ */
/* From example in Kernighan and Ritchie, The C Programming Language,
Prentice-Hall, 1978 */
#include <string.h>
#include "basic.h"
char *m_itoa(
#if defined(M_PROTO)
int n, char *s
#endif
) ;
void reverse(
#if defined(M_PROTO)
char *s
#endif
) ;
char *m_itoa(n, s) /* convert n to characters in s */
char s[];
int n;
{
int sign ;
char *p = s ;
if ( (sign = n) < 0 ) /* record sign */
n = -n;
do { /* generate digits in reverse order */
*p++ = (char) (n % 10 + '0') ;
} while (( n/= 10) > 0);
if (sign < 0)
*p++ = '-';
*p = '\0';
reverse(s);
return(s) ;
}
void reverse(s)
char s[];
{
int c, i, j;
for (i=0, j=strlen(s)-1; i < j ; i++, j--) {
c = s[i];
s[i] = s[j];
s[j] = (char) c;
}
}

View File

@@ -0,0 +1,23 @@
/* $XConsortium: letter.c /main/3 1995/11/08 11:06:23 rswiston $ */
/* Copyright 1987, 1988, 1989 Hewlett-Packard Co. */
/* Tests whether a character is a letter */
#include "basic.h"
LOGICAL m_letter(
#if defined(M_PROTO)
M_WCHAR c
#endif
) ;
#if defined(M_PROTO)
LOGICAL m_letter(M_WCHAR c)
#else
LOGICAL m_letter(c)
M_WCHAR c ;
#endif
{
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) return(TRUE) ;
return(FALSE) ;
}

View File

@@ -0,0 +1,22 @@
/* $XConsortium: lower.c /main/3 1995/11/08 11:06:37 rswiston $ */
/*
Copyright 1986, 1987, 1988, 1989 Hewlett-Packard Co.
*/
#include "basic.h"
int m_lower(
#if defined(M_PROTO)
int c
#endif
) ;
/* Force a letter to lowercase */
int m_lower(c)
int c ;
{
if (c >= 'A' && c <= 'Z') c += 'a' - 'A' ;
return(c) ;
}

View File

@@ -0,0 +1,209 @@
/* $XConsortium: malloc.c /main/3 1995/11/08 11:06:50 rswiston $ */
/* Copyright (c) 1988, 1989 Hewlett-Packard Co. */
/* Interfaces to free and malloc with optional debugging traces */
/**/
#include <malloc.h>
#include <stdio.h>
#if defined(MSDOS)
#include <process.h>
#endif
#include "basic.h"
extern LOGICAL m_heapchk ;
extern LOGICAL m_malftrace ;
void m_errline(
#if defined(M_PROTO)
char *text
#endif
) ;
void m_exit(
#if defined(M_PROTO)
int status
#endif
) ;
void m_free(
#if defined(M_PROTO)
void *block, char *msg
#endif
) ;
void m_heapdump(
#if defined(M_PROTO)
M_NOPAR
#endif
) ;
void *m_malloc(
#if defined(M_PROTO)
int size, char *msg
#endif
) ;
void *m_realloc(
#if defined(M_PROTO)
void *ptr, int size, char *msg
#endif
) ;
void *m_trace(
#if defined(M_PROTO)
char *text
#endif
) ;
void *m_wctrace(
#if defined(M_PROTO)
M_WCHAR *text
#endif
) ;
void m_free(block, msg)
void *block ;
char *msg ;
{
char buffer[32] ;
#if defined(MSDOS)
if (m_heapchk) m_heapdump() ;
#endif
free(block) ;
if (m_malftrace) {
#if defined(hpux) || defined(_AIX) || defined(sun) || defined(USL) || defined(__uxp__)
sprintf(buffer, "%5x:%5x",
(unsigned int) ((unsigned long) block >> 16),
(unsigned int) block, msg) ;
#else
sprintf(buffer, " %9p", block, msg) ;
#endif
m_trace(buffer) ;
m_trace("- Freed ") ;
m_trace(msg) ;
m_trace("\n") ;
}
#if defined(MSDOS)
if (m_heapchk) m_heapdump() ;
#endif
}
#if defined(MSDOS)
void m_heapdump(M_NOPAR)
{
struct _heapinfo hinfo ;
int heapstatus ;
heapstatus = _heapchk() ;
if (heapstatus == _HEAPOK || heapstatus == _HEAPEMPTY) return ;
printf("\nDumping heap:\n") ;
hinfo._pentry = NULL ;
while ((heapstatus = _heapwalk(&hinfo)) == _HEAPOK)
printf("%6s block at %p of size %4.4X\n",
hinfo._useflag == _USEDENTRY ? "USED" : "FREE",
hinfo._pentry, hinfo._size) ;
switch(heapstatus) {
case _HEAPEMPTY:
printf("OK - empty heap\n\n") ;
break ;
case _HEAPEND:
printf("OK - end of heap\n\n") ;
break ;
case _HEAPBADPTR:
printf("Error - bad pointer to heap\n\n") ;
break ;
case _HEAPBADBEGIN:
printf("Error - bad start of heap\n\n") ;
break ;
case _HEAPBADNODE:
printf("Error - bad node in heap\n\n") ;
break ;
}
m_exit(TRUE) ;
}
#endif
void *m_malloc(size, msg)
int size ;
char *msg ;
{
char buffer[32] ;
void *p ;
size *= sizeof(M_WCHAR);
#if defined(MSDOS)
if (m_heapchk) m_heapdump() ;
#endif
if (! size) return(NULL) ;
p = (void *) malloc(size) ;
#if defined(MSDOS)
if (m_heapchk) m_heapdump() ;
#endif
if (! p) {
m_errline("Unable to allocate space for ") ;
m_errline(msg) ;
m_errline("\n") ;
m_exit(TRUE) ;
}
if (m_malftrace) {
#if defined(hpux) || defined(_AIX) || defined(sun) || defined(USL) || defined(__uxp__)
sprintf(buffer, "%5x:%5x",
(unsigned int) ((unsigned long) p >> 16), (unsigned int) p) ;
#else
sprintf(buffer, " %9p", p) ;
#endif
m_trace(buffer) ;
m_trace("- Allocated ") ;
sprintf(buffer, "%6d", size) ;
m_trace(buffer) ;
m_trace(" bytes for ") ;
m_trace(msg) ;
m_trace("\n") ;
}
return(p) ;
}
void *m_realloc(ptr, size, msg)
void *ptr ;
int size ;
char *msg ;
{
char buffer[32] ;
void *p ;
size *= sizeof(M_WCHAR);
#if defined(MSDOS)
if (m_heapchk) m_heapdump() ;
#endif
if (! size) return(NULL) ;
p = (void *) realloc(ptr, size) ;
#if defined(MSDOS)
if (m_heapchk) m_heapdump() ;
#endif
if (! p) {
m_errline("Unable to re-allocate space for ") ;
m_errline(msg) ;
m_errline("\n") ;
m_exit(TRUE) ;
}
if (m_malftrace) {
#if defined(hpux) || defined(_AIX) || defined(sun) || defined(USL) || defined(__uxp__)
sprintf(buffer, "%5x:%5x",
(unsigned int) ((unsigned long) p >> 16), (unsigned int) p) ;
#else
sprintf(buffer, " %9p", p) ;
#endif
m_trace(buffer) ;
m_trace("- Re-allocated ") ;
sprintf(buffer, "%6d", size) ;
m_trace(buffer) ;
m_trace(" bytes for ") ;
m_trace(msg) ;
m_trace("\n") ;
}
return(p) ;
}

View File

@@ -0,0 +1,36 @@
/* $XConsortium: openchk.c /main/3 1995/11/08 11:07:01 rswiston $ */
/*
Copyright 1986, 1987, 1988, 1989 Hewlett-Packard Co.
*/
#include <stdio.h>
#if defined(MSDOS)
#include <process.h>
#endif
#include "basic.h"
extern FILE *m_errfile ;
void m_exit(
#if defined(M_PROTO)
int status
#endif
) ;
void m_openchk(
#if defined(M_PROTO)
FILE **ptr, char *name, char *mode
#endif
) ;
/* Open a file and check that the open succeeded */
void m_openchk(ptr, name, mode)
FILE **ptr ;
char *name, *mode ;
{
*ptr = fopen(name, mode) ;
if (*ptr) return ;
fprintf(stderr, "Unable to open %s\n", name) ;
if (m_errfile) fprintf(m_errfile, "Unable to open %s\n", name) ;
m_exit(TRUE) ;
}

View File

@@ -0,0 +1,125 @@
/* $XConsortium: paramu.c /main/3 1995/11/08 11:07:11 rswiston $ */
/*
Copyright 1986 Tandem Computers Incorporated.
This product and information is proprietary of Tandem Computers Incorporated.
Copyright (c) 1986, 1987, 1988, 1989 Hewlett-Packard Co.
*/
/* Paramu.c contains functions for programs ELTDEF and PARSER
relevant to checking parameter values. */
/* Check to see if string is a valid value for parameter par. If so
return a pointer to the keyword if it's a keyword parameter and otherwise
a pointer to string. If not valid, return FALSE. */
#if defined(M_PROTO)
const M_WCHAR *m_partype(const int par , const M_WCHAR *string )
#else
M_WCHAR *m_partype(par, string)
int par ;
M_WCHAR *string ;
#endif /* M_PROTO */
{
LOGICAL first = TRUE ;
int kw ;
const M_WCHAR *p = string ;
int len ;
if (m_parameter[par - 1].type == M_KEYWORD) {
for (kw = m_parameter[par - 1].kwlist ; kw ; kw = m_ptype[kw - 1].next)
if (! m_wcupstrcmp(&m_keyword[m_ptype[kw - 1].keyword], string))
return(&m_keyword[m_ptype[kw - 1].keyword]) ;
return(FALSE) ;
}
if (m_parameter[par - 1].type == M_CDATT) return(string) ;
if (! *string) return(FALSE) ;
if (m_allwhite(string)) return(FALSE) ;
len = 0 ;
for ( ; *p ; p++)
switch (m_cttype(*p)) {
case M_NONNAME:
switch (m_parameter[par - 1].type) {
case M_ID:
case M_IDRF:
case M_NAMEPAR:
case M_NMTOKEN:
case M_NUMBER:
case M_NUTOKEN:
case M_ENTATT:
return(FALSE) ;
default:
len = 0 ;
if (! m_whitespace(*p)) return(FALSE) ;
}
first = TRUE ;
break ;
case M_NMSTART:
len++ ;
if (len > M_NAMELEN) return(FALSE) ;
if (m_parameter[par - 1].type == M_NUMBER ||
m_parameter[par - 1].type == M_NUMS) return(FALSE) ;
first = FALSE ;
break ;
case M_NAMECHAR:
len++ ;
if (len > M_NAMELEN) return(FALSE) ;
switch (m_parameter[par - 1].type) {
case M_ID:
case M_IDRF:
case M_IDRFS:
case M_NAMEPAR:
case M_NAMES:
case M_ENTATT:
if (first) return(FALSE) ;
break ;
case M_NMTOKEN:
case M_NMSTOKEN:
break ;
case M_NUMBER:
case M_NUMS:
return(FALSE) ;
case M_NUTOKEN:
case M_NUSTOKEN:
if (first) return(FALSE) ;
break ;
default:
m_error("Undefined parameter type") ;
m_exit(TRUE) ;
}
break ;
case M_DIGIT:
len++ ;
if (len > M_NAMELEN) return(FALSE) ;
switch (m_parameter[par - 1].type) {
case M_ID:
case M_IDRF:
case M_IDRFS:
case M_NAMEPAR:
case M_NAMES:
case M_ENTATT:
if (first) return(FALSE) ;
break ;
case M_NUMBER:
case M_NUMS:
break ;
case M_NMTOKEN:
case M_NMSTOKEN:
case M_NUTOKEN:
case M_NUSTOKEN:
first = FALSE ;
break ;
default:
m_error("Undefined parameter type") ;
m_exit(TRUE) ;
}
break ;
default:
m_error("Undefined character type") ;
m_exit(TRUE) ;
}
if (m_parameter[par - 1].type == M_ENTATT) {
if ((M_ENTITY *) m_lookfortrie(string, m_enttrie))
return(string) ;
else return(FALSE) ;
}
return(string) ;
}

View File

@@ -0,0 +1,230 @@
/* $XConsortium: scanutil.c /main/3 1995/11/08 11:07:21 rswiston $ */
/* Copyright (c) 1986, 1987, 1988, 1989 Hewlett-Packard Co. */
/* Scanutil.c contains procedures used in the scanners of BUILD and ELTDEF */
extern FILE *ifile;
/* Getachar returns the next character from the input stream */
int getachar(M_NOPAR)
{
int c;
M_WCHAR wc,wnl;
char mbyte[32]; /* bigger than any possible multibyte char */
int length;
if (toundo) wc = (M_WCHAR) savechar[--toundo];
else
{
length = 0;
if ((c = getc(ifile)) == EOF) return(EOF);
while (1)
{
mbyte[length++] = c;
mbyte[length] = 0;
if (mblen(mbyte,length) != -1) break; /* hurray! */
if (length == MB_CUR_MAX)
{ /* reached max without a hit */
m_error("An invalid multi-byte character was found in the input");
c = ' ';
length = 1;
break;
}
if ((c = getc(ifile)) == EOF)
{ /* huh? */
m_error("End-of-file found in within a multi-byte character");
return(EOF);
}
}
mbtowc(&wc,mbyte,length);
}
mbtowc(&wnl, "\n", 1);
if (wc == wnl) m_line++;
if (wc == 65535)
return -1;
return((int) wc);
}
/* Reads the next token stored in a packed trie (as defined by context.dat) */
int gettoken(c, context)
int *c;
int context;
{
int hold[MAXD + 1];
int ucase;
int i, n = 0, current, delim[MAXD + 1];
if (! (current = m_contree[context - 1]))
{
*c = getachar();
return(M_NULLVAL);
}
current--;
while (TRUE)
{
hold[n] = getachar();
ucase = m_ctupper(hold[n]);
delim[n] = FALSE;
for (i = current;
(int) m_delimtrie[i].symbol < ucase && m_delimtrie[i].more;
i++);
if ((int) m_delimtrie[i].symbol == ucase)
{
current = m_delimtrie[i].index;
if (! m_delimtrie[current].symbol)
delim[n] = m_delimtrie[current].index;
n++;
}
else break;
}
while (n >= 0)
{
if (delim[n])
{
/* Found a delimiter. If it ends with a letter, verify
that the following character is not a letter, in order
to issue error messages in cases such as <!ENTITYrunon ... */
if (m_cttype(hold[n]) != M_NMSTART) return(delim[n]);
*c = getachar();
ungetachar(*c);
if (*c == EOF || m_cttype(*c) != M_NMSTART) return(delim[n]);
}
if (n) ungetachar(hold[n]);
n--;
}
*c = *hold;
return(M_NULLVAL);
}
/* Reads a literal (called after the opening quotation mark is read) */
LOGICAL litproc(delim)
int delim;
{
int n, i, number;
M_WCHAR *p, *pStart; /* bigger than wide versions of lit or lita */
int c;
for (i = 0 ; i < M_LITLEN ; i++)
{
n = gettoken(&c, LITCON);
switch (n)
{
case LIT:
case LITA:
if (n == delim)
{
literal[i] = M_EOS;
return(TRUE);
}
pStart = p = MakeWideCharString((n == LIT) ? lit : lita);
if (w_strlen(p) + i > M_LITLEN)
{
m_error("Literal too long");
return(FALSE);
}
while (*p) literal[i++] = *p++;
m_free(pStart,"wide character string");
i--;
break;
case CRO:
number = 0;
while (! (n = gettoken(&c, CHARENT)))
{
if (c <= '0' || c >= '9')
{
ungetachar(c);
break;
}
number = 10 * number + c - '0';
if (number >= M_CHARSETLEN)
{
m_error("Invalid character code");
return(FALSE);
}
}
literal[i] = (M_WCHAR) number;
break;
case LITRS:
case LITRSC:
#if defined(BUILDEXTERN)
if (curcon == SREF || curcon == S2REF)
literal[i] = RS;
else
#endif
i--;
break;
case LITRE:
case LITREC:
literal[i] = M_RE;
break;
case LITTAB:
case LITTABC:
literal[i] = M_TAB;
break;
case LITSPACE:
case LITCSPACE:
literal[i] = M_SPACE;
break;
default:
if (c == EOF)
{
m_error("End of File occurred within literal");
return(FALSE);
}
literal[i] = (M_WCHAR) c;
break;
} /* End switch */
} /* End for i */
n = gettoken(&c, LITCON);
if (n == delim)
{
literal[M_LITLEN] = M_EOS;
return(TRUE);
}
if (n) undodelim(m_dlmptr[n - 1]) ;
else ungetachar(c);
m_error("Literal too long");
return(FALSE);
}
/* Returns a context-dependent delimiter string to input stream so
characters can be reread one at a time in another context */
void undodelim(delim)
M_WCHAR *delim;
{
M_WCHAR *p;
for (p = delim ; *p ; p++);
p--;
while (TRUE)
{
ungetachar(*p);
if (p == delim) return;
p--;
}
}
/* Returns a character to the input stream to read again later. Unexplained
problems occurred using standard ungetc procedure; hence
explicit declaration of buffer for read-ahead characters */
void ungetachar(c)
int c;
{
M_WCHAR wnl;
if (toundo >= SAVECHAR)
{
m_error("Exceeded read-ahead buffer");
exit(TRUE);
}
savechar[toundo++] = c;
if (toundo > maxundo) maxundo = toundo;
mbtowc(&wnl, "\n", 1);
if (c == wnl) m_line--;
}

View File

@@ -0,0 +1,18 @@
/* $XConsortium: sparse.c /main/3 1995/11/08 11:07:31 rswiston $ */
/* Copyright (c) 1986, 1987, 1988, 1989 Hewlett-Packard Co. */
/* Sparse.c has a procedure used with the tables generated by program
CONTEXT when the sparse option is used */
int m_sprscon(i, j)
int i, j ;
{
int k ;
for (k = m_trnsptr[i] ; k ; k++) {
if ((int) m_trnsit[k - 1].context > j) return(0) ;
if (! m_trnsit[k - 1].context) return(0) ;
if ((int) m_trnsit[k - 1].context == j)
return(m_trnsit[k - 1].nextcon) ;
}
return(0) ;
}

View File

@@ -0,0 +1,20 @@
/* $XConsortium: sparse.h /main/3 1995/11/08 11:07:40 rswiston $ */
/* Copyright (c) 1986, 1987, 1988, 1989 Hewlett-Packard Co. */
/* Sparse.h contains definitions which allow selection of the sparse
matrix output option of CONTEXT */
#if defined(sparse)
#define m_newcon(i, j) m_sprscon(i, j)
int m_sprscon(
#if defined(M_PROTO)
int i, int j
#endif
) ;
#else
#define m_newcon(i, j) m_nextcon[i][j]
#endif

View File

@@ -0,0 +1,10 @@
/* $XConsortium: sref.h /main/3 1995/11/08 11:07:49 rswiston $ */
/* Copyright 1986, 1987, 1988, 1989 Hewlett-Packard Co. */
/* Sref.h contains declarations for short references relevant to more than
one program */
#define BLANKSEQ 'B'
#define RS 'S'
#define WSSEQ 'W'

View File

@@ -0,0 +1,18 @@
/* $XConsortium: strstr.c /main/3 1995/11/08 11:07:59 rswiston $ */
char *strstr ( s1, s2 )
char *s1, *s2 ; {
int x, y ;
y = strlen ( s2 ) ;
x = strlen ( s1 ) - y ;
if ( x < 0 ) return ( ( char * ) 0L ) ;
do {
if ( strncmp ( s1 + x, s2, y ) == 0 ) return ( s1 + x ) ;
}
while ( --x >= 0 ) ;
return ( ( char * ) 0L ) ;
}

View File

@@ -0,0 +1,137 @@
/* $XConsortium: trie.c /main/3 1995/11/08 11:08:08 rswiston $ */
/*
Copyright 1986, 1987, 1988, 1989 Hewlett-Packard Co.
*/
/* Trie.c contains procedures for maintaining the tree structure
used to store element names, delimiter strings, short reference strings,
etc. */
#include <stdio.h>
#if defined(MSDOS)
#include <stdlib.h>
#endif
#include "basic.h"
#include "common.h"
#include "trie.h"
extern int m_line ;
extern FILE *m_errfile ;
extern M_CHARTYPE m_ctarray[M_CHARSETLEN] ;
void *m_malloc(
#if defined(M_PROTO)
int size, char *msg
#endif
) ;
void m_entercharintrie(
#if defined(M_PROTO)
M_TRIE **currentnode, M_WCHAR c
#endif
) ;
/* Enters the next character of a string into a trie */
#if defined(M_PROTO)
void m_entercharintrie(M_TRIE **currentnode, M_WCHAR c)
#else
void m_entercharintrie(currentnode, c)
M_TRIE **currentnode ;
M_WCHAR c ;
#endif
{
M_TRIE *newnode ;
if (! (*currentnode)->data) {
(*currentnode)->data = m_gettrienode() ;
*currentnode = (*currentnode)->data ;
(*currentnode)->next = M_NULLVAL ;
(*currentnode)->symbol = c ;
(*currentnode)->data = M_NULLVAL ;
} /* end insert a son */
else if ((*currentnode)->data->symbol > c) {
newnode = m_gettrienode() ;
newnode->next = (*currentnode)->data ;
(*currentnode)->data = newnode ;
*currentnode = (*currentnode)->data ;
(*currentnode)->symbol = c ;
(*currentnode)->data = M_NULLVAL ;
} /* end insert before first son */
else {
for (*currentnode = (*currentnode)->data ;
(*currentnode)->next &&(*currentnode)->next->symbol <= c;
*currentnode = (*currentnode)->next ) ;
if ((*currentnode)->symbol != c) {
newnode = m_gettrienode() ;
newnode->next = (*currentnode)->next ;
(*currentnode)->next = newnode ;
*currentnode = (*currentnode)->next ;
(*currentnode)->symbol = c ;
(*currentnode)->data = M_NULLVAL ;
} /* end insert node in descendant list */
} /* end check descendant list */
} /* end entertree */
/* Gets a new node for a trie */
M_TRIE *m_gettrienode(M_NOPAR)
{
M_TRIE *new ;
new = (M_TRIE *) m_malloc(sizeof(M_TRIE), "trie") ;
new->symbol = 0 ;
new->next = new->data = NULL ;
return(new) ;
} /*end m_gettrienode */
/* M_lookfortrie(p, xtrie) looks for string p in the specified trie,
returning its data value if found and otherwise FALSE */
#if defined(M_PROTO)
void *m_lookfortrie( const M_WCHAR *p , const M_TRIE *xtrie )
#else
void *m_lookfortrie(p, xtrie)
M_WCHAR *p ;
M_TRIE *xtrie ;
#endif /* M_PROTO */
{
M_TRIE *currentnode ;
currentnode = xtrie->data ;
while (TRUE) {
if (! currentnode) return(NULL) ;
if (currentnode->symbol == m_ctupper(*p))
if (! *p) return((void *) currentnode->data) ;
else {
p++ ;
currentnode = currentnode->data ;
continue ;
}
else if (currentnode->symbol < *p) {
currentnode = currentnode->next ;
continue ;
}
else return(NULL) ;
}
}
/* Enters a string and associated data value into a trie */
void *m_ntrtrie(p, xtrie, dataval)
M_WCHAR *p ;
M_TRIE *xtrie ;
void *dataval ;
{
M_TRIE *currentnode ;
void *n ;
if (n = m_lookfortrie(p, xtrie)) return(n) ;
currentnode = xtrie ;
for ( ; *p ; p++)
m_entercharintrie(&currentnode, m_ctupper(*p)) ;
m_entercharintrie(&currentnode, M_EOS) ;
currentnode->data = (M_TRIE *) dataval ;
return(NULL) ;
}

View File

@@ -0,0 +1,54 @@
/* $XConsortium: trie.h /main/3 1995/11/08 11:08:18 rswiston $ */
/*
Copyright 1986, 1987, 1988, 1989 Hewlett-Packard Co.
*/
/* Trie.h contains definitions relating to trees used to store
element names, delimiter strings, short reference strings, etc. */
/* The data structure described here is not a true trie as described
in Knuth, Vol. 3. These functions represent entries by a tree
structure in which there is one level of subnode for each letter
in an entry. In a trie, subnodes are not needed as soon as a
unique prefix has been encountered. */
typedef struct m_trie M_TRIE ;
typedef struct m_ptrie M_PTRIE ;
struct m_trie {
M_WCHAR symbol ;
M_TRIE *next ;
M_TRIE *data ;
} ;
struct m_ptrie {
LOGICAL more ;
M_WCHAR symbol ;
int index ;
} ;
M_TRIE *m_gettrienode(
#if defined(M_PROTO)
M_NOPAR
#endif
) ;
void *m_lookfortrie(
#if defined(M_PROTO)
const M_WCHAR *p, const M_TRIE *xtrie
#endif
) ;
void *m_ntrtrie(
#if defined(M_PROTO)
M_WCHAR *p, M_TRIE *xtrie, void *dataval
#endif
) ;
void *m_resettrie(
#if defined(M_PROTO)
M_TRIE *xtrie, M_WCHAR *p, void *value
#endif
) ;

View File

@@ -0,0 +1,92 @@
/* $XConsortium: triecnt.c /main/3 1995/11/08 11:08:29 rswiston $ */
/*
Copyright 1986, 1987, 1988, 1989 Hewlett-Packard Co.
*/
/* Triecnt.c contains procedures for writing out a trie structure */
#include <stdio.h>
#include "basic.h"
#include "trie.h"
void countdown(
#if defined(M_PROTO)
M_TRIE *parent, int *count
#endif
) ;
void dumpnode(
#if defined(M_PROTO)
LOGICAL *first, FILE *file, M_TRIE *trieptr, int *count,
void (*proc)(FILE *file, void *value)
#endif
) ;
void printval(
#if defined(M_PROTO)
FILE *file, void *value
#endif
) ;
/* Count the descendants of a node in order to generate declarations for
the packed form of a trie*/
void countdown(parent, count)
M_TRIE *parent ;
int *count ;
{
M_TRIE *child ;
for (child = parent->data ; child ; child = child->next) {
(*count)++ ;
if (child->symbol) countdown(child, count) ;
}
}
/* Output descendants of a node for the declaration of a trie, in packed
or normal format*/
void dumpnode(first, file, trieptr, count, proc)
LOGICAL *first ;
FILE *file ;
M_TRIE *trieptr ;
int *count ;
void (*proc) (
#if defined (M_PROTO)
FILE *file,
void *value
#endif
) ;
{
M_TRIE *p ;
int savecount ;
for (p = trieptr->data ; p ; p = p->next) (*count)++ ;
savecount = *count ;
for (p = trieptr->data ; p ; p = p->next) {
/* generate a child */
if (*first) *first = FALSE ;
else fprintf(file, ",\n") ;
fprintf(file, " ") ;
if (p->next) fprintf(file, "TRUE, ") ;
else fprintf(file, "FALSE, ") ;
fprintf(file, "%d", p->symbol) ;
if (p->symbol) fprintf(file, ", %d", *count) ;
else (*proc)(file, p->data) ;
/* count the children of the child*/
if (p->symbol) countdown(p, count) ;
}
*count = savecount ;
for (p = trieptr->data ; p ; p = p->next)
if (p->symbol) dumpnode(first, file, p, count, proc) ;
}
/* Most common procedure passed to dumpptrie */
void printval(file, value)
FILE *file ;
void *value ;
{
fprintf(file, ", %d", (int) value) ;
}

View File

@@ -0,0 +1,56 @@
/* $XConsortium: triedump.c /main/3 1995/11/08 11:08:37 rswiston $ */
/*
Copyright 1986, 1987, 1988, 1989 Hewlett-Packard Co.
*/
#include <stdio.h>
#include "basic.h"
#include "trie.h"
void countdown(
#if defined(M_PROTO)
M_TRIE *parent, int *count
#endif
) ;
void m_dumptrie(
#if defined(M_PROTO)
FILE *file, M_TRIE *xtrie, char *extname, int *count,
void (*proc)(void *value)
#endif
) ;
/* Write the C declaration of a trie */
void m_dumptrie(file, xtrie, extname, count, proc)
FILE *file ;
M_TRIE *xtrie ;
char *extname ;
int *count ;
void (*proc)(
#if defined(M_PROTO)
void *value
#endif
) ;
{
int firstson ;
M_TRIE *p ;
firstson = *count + 1 ;
for (p = xtrie ; p ; p = p->next) firstson++ ;
for (p = xtrie ; p ; p = p->next) {
(*count)++ ;
fprintf(file, ",\n %d, ", p-> symbol) ;
if (p->next) fprintf(file, "&%s[%d], ", extname, *count + 1) ;
else fputs("NULL, ", file) ;
if (p->symbol) {
fprintf(file, "&%s[%d]", extname, firstson) ;
countdown(p, &firstson) ;
}
else (*proc) (p->data) ;
}
for (p = xtrie ; p ; p = p->next)
if (p->symbol)
m_dumptrie(file, p->data, extname, count, proc) ;
}

View File

@@ -0,0 +1,60 @@
/* $XConsortium: triepdmp.c /main/3 1995/11/08 11:08:46 rswiston $ */
/*
Copyright 1986, 1987, 1988, 1989 Hewlett-Packard Co.
*/
#include <stdio.h>
#include "basic.h"
#include "trie.h"
void countdown(
#if defined(M_PROTO)
M_TRIE *parent, int *count
#endif
) ;
void dumpnode(
#if defined(M_PROTO)
LOGICAL *first, FILE *file, M_TRIE *trieptr, int *count,
void (*proc)(FILE *file, void *value)
#endif
) ;
void dumpptrie(
#if defined(M_PROTO)
M_TRIE *intname, char *extname, FILE *file, char *externdef, char *defdef,
void (*proc)(FILE *file, void *value)
#endif
) ;
/* Write the declaration of a packed trie to the specified files */
void dumpptrie(intname, extname, file, externdef, defdef, proc)
M_TRIE *intname ;
char *extname ;
FILE *file ;
char *externdef ;
char *defdef ;
void (*proc) (
#if defined (M_PROTO)
FILE *file,
void *value
#endif
) ;
{
LOGICAL first = TRUE ;
int count = 0 ;
int treelen = 1 ;
/* Count nodes in tree */
countdown(intname, &treelen);
if (treelen > 1) {
fprintf(file, "%s M_PTRIE %s[%d]\n#if defined(%s)\n = {\n",
externdef, extname, treelen - 1, defdef) ;
dumpnode(&first, file, intname, &count, proc) ;
fprintf(file, "}\n#endif\n ;\n\n") ;
}
else {
fprintf(file, "%s M_PTRIE %s[1] ;\n\n", externdef, extname) ;
}
}

View File

@@ -0,0 +1,46 @@
/* $XConsortium: trieplk.c /main/3 1995/11/08 11:08:55 rswiston $ */
/*
Copyright 1986, 1987, 1988, 1989 Hewlett-Packard Co.
*/
/* Trie.c contains procedures for maintaining the tree structure
used to store element names, delimiter strings, short reference strings,
etc. */
#include <stdio.h>
#include "basic.h"
#include "common.h"
#include "trie.h"
extern M_CHARTYPE m_ctarray[M_CHARSETLEN] ;
int m_packedlook(
#if defined(M_PROTO)
M_PTRIE *xptrie,
M_WCHAR *name
#endif
) ;
/* Look for the string NAME in the packed trie PTRIE */
int m_packedlook(xptrie, name)
M_PTRIE *xptrie ;
M_WCHAR *name ;
{
int current = 0 ;
int i ;
int c ;
for ( ; TRUE ; name++)
{
c = m_ctupper(*name) ;
for (i = current ;
(int) ((xptrie + i)->symbol) < c && (xptrie + i)->more ;
i++) ;
if ((int) ((xptrie + i)->symbol) == c)
{
if (! c) return((xptrie + i)->index) ;
current = (xptrie + i)->index ;
}
else return(FALSE) ;
}
}

View File

@@ -0,0 +1,39 @@
/* $XConsortium: trierset.c /main/3 1995/11/08 11:09:04 rswiston $ */
/*
Copyright 1988, 1989 Hewlett-Packard Co.
*/
#include <stdio.h>
#include "basic.h"
#include "common.h"
#include "trie.h"
extern M_CHARTYPE m_ctarray[M_CHARSETLEN] ;
/* Changes the value associated with an entry in a trie. */
void *m_resettrie(xtrie, p, value)
M_TRIE *xtrie ;
M_WCHAR *p ;
void *value ;
{
M_TRIE *currentnode ;
currentnode = xtrie->data ;
while (TRUE) {
if (! currentnode) return(FALSE) ;
if ((int) currentnode->symbol == m_ctupper(*p))
if (! *p) return((void *)(currentnode->data = (M_TRIE *) value)) ;
else {
p++ ;
currentnode = currentnode->data ;
continue ;
}
else if (currentnode->symbol < *p) {
currentnode = currentnode->next ;
continue ;
}
else return(NULL) ;
}
}

View File

@@ -0,0 +1,80 @@
/* $XConsortium: upcmp8.c /main/3 1995/11/08 11:09:12 rswiston $ */
/*
Copyright 1986, 1987, 1988, 1989 Hewlett-Packard Co.
*/
/* Compare uppercase versions of two strings of eight-bit characters */
#include <stdio.h>
#include "basic.h"
#include "common.h"
extern M_CHARTYPE m_ctarray[256] ;
int m_wcupstrcmp(
#if defined(M_PROTO)
const M_WCHAR *p, const M_WCHAR *q
#endif
) ;
int m_wcmbupstrcmp(
#if defined(M_PROTO)
const M_WCHAR *p, const char *q
#endif
) ;
int m_mbmbupstrcmp(
#if defined(M_PROTO)
const char *p, const char *q
#endif
) ;
#if defined(M_PROTO)
int m_wcupstrcmp(const M_WCHAR *p, const M_WCHAR *q )
#else
int m_wcupstrcmp(p, q)
M_WCHAR *p, *q ;
#endif /* M_PROTO */
{
do {
if (m_ctupper(*p) < m_ctupper(*q)) return(-1) ;
if (m_ctupper(*p) > m_ctupper(*q)) return(1) ;
q++ ;
} while (*p++) ;
return(0) ;
}
#if defined(M_PROTO)
int m_wcmbupstrcmp(const M_WCHAR *p, const char *q)
#else
int m_wcmbupstrcmp(p, q)
M_WCHAR *p;
char *q ;
#endif
{
M_WCHAR *wc;
int retval;
wc = MakeWideCharString(q);
retval = m_wcupstrcmp(p, wc);
m_free(wc,"wide character string");
return retval;
}
#if defined(M_PROTO)
int m_mbmbupstrcmp(const char *p, const char *q)
#else
int m_mbmbupstrcmp(p, q)
char *p;
char *q ;
#endif
{
M_WCHAR *w_p, *w_q;
int retval;
w_p = MakeWideCharString(p);
w_q = MakeWideCharString(q);
retval = m_wcupstrcmp(w_p, w_q);
m_free(w_p,"wide character string");
m_free(w_q,"wide character string");
return retval;
}

View File

@@ -0,0 +1,21 @@
/* $XConsortium: upper.c /main/3 1995/11/08 11:09:21 rswiston $ */
/*
Copyright 1986, 1987, 1988, 1989 Hewlett-Packard Co.
*/
/* Force a letter to uppercase */
#include "basic.h"
int m_upper(
#if defined(M_PROTO)
int c
#endif
) ;
int m_upper(c)
int c ;
{
if (c >= 'a' && c <= 'z') c += 'A' - 'a' ;
return(c) ;
}

View File

@@ -0,0 +1,30 @@
/* $XConsortium: upstrcmp.c /main/3 1995/11/08 11:09:30 rswiston $ */
/*
Copyright 1986, 1987, 1988, 1989 Hewlett-Packard Co.
*/
/* Compare uppercase versions of two strings */
#include "basic.h"
int m_upper(
#if defined(M_PROTO)
int c
#endif
) ;
int m_upstrcmp(
#if defined(M_PROTO)
char *p, char *q
#endif
) ;
int m_upstrcmp(p, q)
char *p, *q ;
{
do {
if (m_upper((int) *p) < m_upper((int) *q)) return(-1) ;
if (m_upper((int) *p) > m_upper((int) *q++)) return(1) ;
} while (*p++) ;
return(0) ;
}

View File

@@ -0,0 +1,5 @@
/* $XConsortium: version.h /main/3 1995/11/08 11:09:39 rswiston $ */
/* Copyright (c) 1987, 1988, 1989 Hewlett-Packard Co. */
/* Version.h defines the MARKUP System Version Number */
#define M_VERSION "Version 2.4"

View File

@@ -0,0 +1,300 @@
/* $XConsortium: wchar.c /main/3 1995/11/08 11:09:48 rswiston $ */
/*
Copyright 1992 Hewlett-Packard Co.
*/
#include "basic.h"
/* compare two wide character strings */
#if defined(M_PROTO)
int w_strcmp(const M_WCHAR *string1, const M_WCHAR *string2)
#else
int w_strcmp(string1, string2)
M_WCHAR *string1;
M_WCHAR *string2;
#endif
{
M_WCHAR c1, c2, null;
if (string1 == string2) return 0;
null = (M_WCHAR) 0;
if (!string1) string1 = &null;
if (!string2) string2 = &null;
while (1)
{
c1 = *string1++;
c2 = *string2++;
if (c1 < c2) return -1;
if (c1 > c2) return 1;
if (!c1) return 0;
}
}
/* compare two wide character strings to length "n" */
#if defined(M_PROTO)
int w_strncmp(const M_WCHAR *string1, const M_WCHAR *string2, int max)
#else
int w_strcmp(string1, string2, max)
M_WCHAR *string1;
M_WCHAR *string2;
int max;
#endif
{
M_WCHAR c1, c2, null;
if (string1 == string2) return 0;
if (max <= 0) return 0;
null = (M_WCHAR) 0;
if (!string1) string1 = &null;
if (!string2) string2 = &null;
while (--max >= 0)
{
c1 = *string1++;
c2 = *string2++;
if (c1 < c2) return -1;
if (c1 > c2) return 1;
if (!c1) return 0;
}
return 0;
}
/* copy a wide character string */
#if defined(M_PROTO)
M_WCHAR *w_strcpy(M_WCHAR *string1, const M_WCHAR *string2)
#else
M_WCHAR *w_strcpy(string1, string2)
M_WCHAR *string1;
M_WCHAR *string2;
#endif
{
M_WCHAR *string1start;
string1start = string1;
while (*string1++ = *string2++);
return string1start;
}
/* copy a wide character string, stopping after "max" moves */
#if defined(M_PROTO)
M_WCHAR *w_strncpy(M_WCHAR *string1, const M_WCHAR *string2, int max)
#else
M_WCHAR *w_strncpy(string1, string2, max)
M_WCHAR *string1;
M_WCHAR *string2;
int max;
#endif
{
M_WCHAR *string1start;
string1start = string1;
while ((--max >= 0) && (*string1++ = *string2++));
return string1start;
}
/* get the length of a wide character string */
#if defined(M_PROTO)
int w_strlen(const M_WCHAR *string)
#else
int w_strlen(string)
M_WCHAR *string;
#endif
{
int length;
length = 0;
if (string)
while (*string++) length++;
return length;
}
/* find wide character "chr" in wide string "string" */
#if defined(M_PROTO)
M_WCHAR *w_strchr(M_WCHAR *string, const M_WCHAR chr)
#else
M_WCHAR *w_strchr(string, chr)
M_WCHAR *string, chr;
#endif
{
M_WCHAR *where;
where = string;
while (*where)
{
if (*where == chr) return where;
where++;
}
if (!chr)
return where;
else
return NULL;
}
/* find wide character "chr" in wide string "string" */
#if defined(M_PROTO)
M_WCHAR *w_strstr(M_WCHAR *string1, M_WCHAR *string2)
#else
M_WCHAR *w_strstr(string1, string2)
M_WCHAR *string1, *string2;
#endif
{
M_WCHAR *where1, *where2;
if (!*string2) return string1;
where1 = string1;
where2 = string2;
while (*where1)
{
if (*where1 == *where2)
{
string1 = where1;
while (*where1 && *where2 && (*where1 == *where2))
{
where1++;
where2++;
}
if (!*where2) return string1;
if (!*where1) return NULL;
where1 = string1;
where2 = string2;
}
where1++;
}
return NULL;
}
/* make a multi-byte string from a wide character string */
#if defined(M_PROTO)
char *MakeMByteString(const M_WCHAR *wc_string)
#else
char *MakeMByteString(wc_string)
M_WCHAR *wc_string;
#endif
{
char *mb_string;
int length, retVal;
M_WCHAR wc;
static M_WCHAR empty[] = {0};
if (!wc_string)
wc_string = empty;
/* Do a little work to compensate for m_malloc allocating sizeof(M_WCHAR)
* bytes for each increment in the size requested.
*/
length = (w_strlen(wc_string) * MB_CUR_MAX) + 1;
length = (length + sizeof(M_WCHAR) - 1) / sizeof(M_WCHAR);
mb_string = (char *) m_malloc(length, "multi-byte string");
length = 0;
while (wc = *wc_string++)
{
if ((retVal = wctomb(&mb_string[length], wc)) > 0)
length += retVal;
}
mb_string[length] = 0;
return mb_string;
}
/* make a wide character string from a multi-byte string */
#if defined(M_PROTO)
M_WCHAR *MakeWideCharString(const char *mb_string)
#else
M_WCHAR *MakeWideCharString(mb_string)
char *mb_string;
#endif
{
M_WCHAR *wc_string, *wc_stringStart;
int length, incr;
char c;
if (!mb_string)
mb_string = "";
length = strlen(mb_string);
wc_stringStart = wc_string =
(M_WCHAR *) m_malloc(length + 1, "wide character string");
length = 0;
while (mb_string[length])
{
if ((incr = mbtowc(wc_string, &mb_string[length], MB_CUR_MAX)) < 0)
{
char badOne[2], buffer[32];
badOne[0] = mb_string[length];
badOne[1] = 0;
sprintf(buffer, "0x%x", mb_string[length]);
m_err2("invalid multibyte character found: '%c' (%s)", badOne, buffer);
incr = 1;
}
length += incr;
wc_string++;
}
*wc_string = (M_WCHAR) 0;
return wc_stringStart;
}
/* Get-wide-char procedure */
int mb_getwc(m_ptr)
void *m_ptr;
{
int c;
M_WCHAR wc;
char badch[2];
char mbyte[32]; /* make this bigger than any possible multi-byte char */
int length;
length = 0;
if ((c = getc((FILE *) m_ptr)) == EOF) return(EOF);
while (1)
{
mbyte[length++] = c;
mbyte[length] = 0;
if (mblen(mbyte,length) != -1) break; /* hurray! */
if (length == MB_CUR_MAX)
{ /* reached max without a hit */
m_error("An invalid multi-byte character was found in the input");
c = ' ';
length = 1;
break;
}
if ((c = getc((FILE *) m_ptr)) == EOF)
{ /* huh? */
m_error("End-of-file found in within a multi-byte character");
return(EOF);
}
}
mbtowc(&wc,mbyte,length);
return((int) wc);
}

View File

@@ -0,0 +1,30 @@
/* $XConsortium: whitesp.c /main/3 1995/11/08 11:09:57 rswiston $ */
/*
Copyright 1986, 1987, 1988, 1989 Hewlett-Packard Co.
*/
#include "basic.h"
LOGICAL m_whitespace(
#if defined(M_PROTO)
M_WCHAR c
#endif
) ;
/* Test if character c is a blank, tab, or carriage return */
#if defined(M_PROTO)
LOGICAL m_whitespace(M_WCHAR c)
#else
LOGICAL m_whitespace(c)
M_WCHAR c ;
#endif
{
char mb_c[32]; /* arbitrarily large */
int length;
length = wctomb(mb_c, c);
if (length != 1) return FALSE;
if (*mb_c == ' ' || *mb_c == '\t' || *mb_c == '\n') return(TRUE) ;
else return(FALSE) ;
}