* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
static char sccsid
[] = "@(#)subr.c 5.1 (Berkeley) %G%";
* Arrayify a list of rules
arrayify(e_length
, e_array
, header
)
for (errorp
= header
, listlength
= 0;
errorp
; errorp
= errorp
->error_next
, listlength
++)
array
= (Eptr
*)Calloc(listlength
+1, sizeof (Eptr
));
for(listindex
= 0, errorp
= header
;
listindex
++, errorp
= errorp
->error_next
){
array
[listindex
] = errorp
;
errorp
->error_position
= listindex
;
array
[listindex
] = (Eptr
)0;
fprintf(stderr
, "Error: ");
fprintf(stderr
, msg
, a1
, a2
, a3
);
char *Calloc(nelements
, size
)
if ( (back
= (char *)calloc(nelements
, size
)) == (char *)NULL
){
error("Ran out of memory.\n");
(void)strcpy(outstring
= (char *)Calloc(1, strlen(instring
) + 1),
* find the position of a given character in a string
for (i
=1; *string
; string
++, i
++){
* clobber the first occurance of ch in string by the new character
char *substitute(string
, chold
, chnew
)
if (string
== 0) return('\0');
return(string
[length
-1]);
char next_lastchar(string
)
if (string
== 0) return('\0');
return(string
[length
- 2]);
clob_last(string
, newstuff
)
string
[length
- 1] = newstuff
;
* parse a string that is the result of a format %s(%d)
* return TRUE if this is of the proper format
boolean
persperdexplode(string
, r_perd
, r_pers
)
&& (string
[length
- 1] == ')' ) ){
for (cp
= &string
[length
- 2];
(isdigit(*cp
)) && (*cp
!= '(');
string
[length
- 1] = '\0'; /* clobber the ) */
string
[length
- 1] = ')';
*cp
= '\0'; /* clobber the ( */
*r_pers
= strsave(string
);
* parse a quoted string that is the result of a format \"%s\"(%d)
* return TRUE if this is of the proper format
boolean
qpersperdexplode(string
, r_perd
, r_pers
)
&& (string
[length
- 1] == ')' ) ){
for (cp
= &string
[length
- 2];
(isdigit(*cp
)) && (*cp
!= '(');
if (*cp
== '(' && *(cp
- 1) == '"'){
string
[length
- 1] = '\0';
string
[length
- 1] = ')';
*(cp
- 1) = '\0'; /* clobber the " */
*r_pers
= strsave(string
+ 1);
static char cincomment
[] = CINCOMMENT
;
static char coutcomment
[] = COUTCOMMENT
;
static char fincomment
[] = FINCOMMENT
;
static char foutcomment
[] = FOUTCOMMENT
;
static char newline
[] = NEWLINE
;
static char piincomment
[] = PIINCOMMENT
;
static char pioutcomment
[] = PIOUTCOMMENT
;
static char lispincomment
[] = LISPINCOMMENT
;
static char riincomment
[] = RIINCOMMENT
;
static char rioutcomment
[] = RIOUTCOMMENT
;
static char troffincomment
[] = TROFFINCOMMENT
;
static char troffoutcomment
[] = TROFFOUTCOMMENT
;
static char mod2incomment
[] = MOD2INCOMMENT
;
static char mod2outcomment
[] = MOD2OUTCOMMENT
;
struct lang_desc lang_table
[] = {
/*INUNKNOWN 0*/ "unknown", cincomment
, coutcomment
,
/*INCPP 1*/ "cpp", cincomment
, coutcomment
,
/*INCC 2*/ "cc", cincomment
, coutcomment
,
/*INAS 3*/ "as", ASINCOMMENT
, newline
,
/*INLD 4*/ "ld", cincomment
, coutcomment
,
/*INLINT 5*/ "lint", cincomment
, coutcomment
,
/*INF77 6*/ "f77", fincomment
, foutcomment
,
/*INPI 7*/ "pi", piincomment
, pioutcomment
,
/*INPC 8*/ "pc", piincomment
, pioutcomment
,
/*INFRANZ 9*/ "franz",lispincomment
, newline
,
/*INLISP 10*/ "lisp", lispincomment
, newline
,
/*INVAXIMA 11*/ "vaxima",lispincomment
,newline
,
/*INRATFOR 12*/ "ratfor",fincomment
, foutcomment
,
/*INLEX 13*/ "lex", cincomment
, coutcomment
,
/*INYACC 14*/ "yacc", cincomment
, coutcomment
,
/*INAPL 15*/ "apl", ".lm", newline
,
/*INMAKE 16*/ "make", ASINCOMMENT
, newline
,
/*INRI 17*/ "ri", riincomment
, rioutcomment
,
/*INTROFF 18*/ "troff",troffincomment
,troffoutcomment
,
/*INMOD2 19*/ "mod2", mod2incomment
, mod2outcomment
,
printerrors(look_at_subclass
, errorc
, errorv
)
boolean look_at_subclass
;
for (errorp
= errorv
[i
= 0]; i
< errorc
; errorp
= errorv
[++i
]){
if (errorp
->error_e_class
== C_IGNORE
)
if (look_at_subclass
&& errorp
->error_s_class
== C_DUPL
)
printf("Error %d, (%s error) [%s], text = \"",
class_table
[errorp
->error_e_class
],
lang_table
[errorp
->error_language
].lang_name
);
wordvprint(stdout
,errorp
->error_lgtext
,errorp
->error_text
);
wordvprint(fyle
, wordc
, wordv
)
for(i
= 0; i
< wordc
; i
++)
fprintf(fyle
, "%s%s",sep
,wordv
[i
]);
* Given a string, parse it into a number of words, and build
* a wordc wordv combination pointing into it.
wordvbuild(string
, r_wordc
, r_wordv
)
saltedbuffer
= strsave(string
);
for (wordcount
= 0, cp
= saltedbuffer
; *cp
; wordcount
++){
while (*cp
&& isspace(*cp
))
wordv
= (char **)Calloc(wordcount
+ 1, sizeof (char *));
for (cp
=saltedbuffer
,wordindex
=0; wordcount
; wordindex
++,--wordcount
){
while (*cp
&& isspace(*cp
))
error("Initial miscount of the number of words in a line\n");
wordv
[wordindex
] = (char *)0;
for (wordcount
= 0; wordcount
< wordindex
; wordcount
++)
printf("Word %d = \"%s\"\n", wordcount
, wordv
[wordcount
]);
* Compare two 0 based wordvectors
int wordvcmp(wordv1
, wordc
, wordv2
)
for (i
= 0; i
< wordc
; i
++){
if (wordv1
[i
] == 0 || wordv2
[i
] == 0)
if (back
= strcmp(wordv1
[i
], wordv2
[i
])){
return(0); /* they are equal */
* splice a 0 basedword vector onto the tail of a
* new wordv, allowing the first emptyhead slots to be empty
char **wordvsplice(emptyhead
, wordc
, wordv
)
int nwordc
= emptyhead
+ wordc
;
nwordv
= (char **)Calloc(nwordc
, sizeof (char *));
for (i
= 0; i
< emptyhead
; i
++)
for(i
= emptyhead
; i
< nwordc
; i
++){
nwordv
[i
] = wordv
[i
-emptyhead
];
* plural'ize and verb forms