|
|
1.1 ! root 1: .TH RE 3 ! 2: .SH NAME ! 3: recomp, reexec, resub, refree, reerror \(mi regular expression library ! 4: .SH SYNOPSIS ! 5: .B #include <re.h> ! 6: .PP ! 7: .L reprogram* recomp(char* pattern, int flags) ! 8: .PP ! 9: .L int reexec(reprogram* re, char* source) ! 10: .PP ! 11: .L void resub(reprogram* re, char* old, char* new, char* destination, int flags) ! 12: .PP ! 13: .L void reerror(char* message) ! 14: .PP ! 15: .L void refree(reprogram* re) ! 16: .SH DESCRIPTION ! 17: .I recomp ! 18: compiles a regular expression in ! 19: .B pattern ! 20: and returns a pointer to a compiled regular expression. ! 21: The space is allocated by ! 22: .IR malloc (3) ! 23: and may be released by ! 24: .IR refree . ! 25: Regular expressions are as in ! 26: .I egrep ! 27: (see ! 28: .IR grep (1)) ! 29: except that newlines are treated as ordinary ! 30: characters and ! 31: .B $ ! 32: matches the end of a null-terminated string. ! 33: .B flags ! 34: may be ! 35: .B RE_EDSTYLE ! 36: which specifies ! 37: .IR ed (1) ! 38: style special characters, ! 39: .BR \e( , ! 40: .BR \e) , ! 41: .BR \e? , ! 42: .B \e+ ! 43: and ! 44: .B \e| ! 45: for the ! 46: .IR egrep (1) ! 47: .BR ( , ! 48: .BR ) , ! 49: .BR ? , ! 50: .B + ! 51: and ! 52: .BR | , ! 53: respectively. ! 54: .PP ! 55: .I reexec ! 56: matches the null-terminated ! 57: .B source ! 58: string against the compiled regular expression ! 59: .I re ! 60: from a previous call to ! 61: .IR recomp . ! 62: If it matches, ! 63: .I reexec ! 64: returns a non-zero value. ! 65: If ! 66: .B flags ! 67: is ! 68: .B RE_MATCH ! 69: then the array ! 70: .B re\->match ! 71: is filled with character pointers to the substrings of ! 72: .B source ! 73: that correspond to the ! 74: parenthesized subexpressions of ! 75: .BR pattern : ! 76: .B re\->match[i].sp ! 77: points to the beginning and ! 78: .B re\->match[i].ep ! 79: points just beyond ! 80: the end of substring ! 81: .BR i . ! 82: (Subexpression ! 83: .B i ! 84: begins at the ! 85: .BR i th ! 86: matched left parenthesis, counting from 1.) ! 87: Pointers in ! 88: .B re\->match[0] ! 89: pick out the substring that corresponds to ! 90: the entire regular expression. ! 91: Unused elements of ! 92: .B re\->match ! 93: are filled with zeros. ! 94: Matches involving ! 95: .BR * , ! 96: .BR + , ! 97: and ! 98: .B ? ! 99: are extended as far as possible. ! 100: A maximum of 9 subexpressions will be matched. ! 101: The structure of elements of ! 102: .B re\->match ! 103: is: ! 104: .nf ! 105: .ta 8n ! 106: typedef struct ! 107: { ! 108: char* sp; ! 109: char* ep; ! 110: } rematch; ! 111: .fi ! 112: .LP ! 113: .I resub ! 114: places in ! 115: .I destination ! 116: a substitution instance of ! 117: .B old ! 118: to ! 119: .B new ! 120: in ! 121: .B source ! 122: in the context of the last ! 123: .I reexec ! 124: performed on ! 125: .IR re\->match . ! 126: Each instance of ! 127: .BI \e n , ! 128: where ! 129: .I n ! 130: is a digit, is replaced by the ! 131: string delimited by ! 132: .BI re\->match[ n ].sp ! 133: and ! 134: .BI re\->match[ n ].ep . ! 135: Each instance of ! 136: .B & ! 137: is replaced by the string delimited by ! 138: .B re\->match[0].sp ! 139: and ! 140: .BR re\->match[0].ep . ! 141: If ! 142: .B RE_ALL ! 143: is set in ! 144: .B flags ! 145: then all occurrences of ! 146: .B old ! 147: are replaced by ! 148: .IR new . ! 149: If ! 150: .B RE_LOWER ! 151: .RB [ RE_UPPER ] ! 152: is set in ! 153: .B flags ! 154: then ! 155: .B old ! 156: is converted to lower [upper] case. ! 157: .LP ! 158: .I reerror, ! 159: called whenever an error is detected in ! 160: .I recomp, ! 161: .I reexec, ! 162: or ! 163: .I resub, ! 164: writes the string ! 165: .B msg ! 166: on the standard error file and exits. ! 167: .I reerror ! 168: may be replaced to perform ! 169: special error processing. ! 170: .SH DIAGNOSTICS ! 171: .I recomp ! 172: returns 0 for an invalid expression or other failure. ! 173: .I reexec ! 174: returns 1 if ! 175: .B source ! 176: is accepted, 0 otherwise. ! 177: .SH "SEE ALSO" ! 178: ed(1), grep(1), expr(1)
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.