home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QBasic & Borland Pascal & C
/
Delphi5.iso
/
C
/
Samples
/
CSAPE32.ARJ
/
SOURCE
/
CSSRC
/
SDSRCH.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-10-17
|
4KB
|
139 lines
/*
sdsrch.c 10/28/86
% sed_SearchMerge
int sed_SearchMerge(sed, c)
Goes to the next field in the sed that starts with character c.
Case and leading spaces are ignored.
Returns fieldno if a match is found.
Else returns (-1).
C-scape 3.2
Copyright (c) 1986, 1987, by Oakland Group, Inc.
ALL RIGHTS RESERVED.
Revision History:
-----------------
11/11/86 jmd added register variables
11/15/86 jmd added protected fields
12/16/86 jmd skips over writable fields
12/28/86 jmd just searchs for alphanumerics.
11/04/89 jdc changed toupper & tolower to otoupper & otolower
12/11/89 jmd added highlighted character search
3/28/90 jmd ansi-fied
8/02/90 pmcm modified to allow search of fields with writeables
10/03/90 pmcm added support (case-insensitive) for extended ascii
10/17/90 pmcm fixed trashy no-merge case
*/
#include "sed.h"
#include <ctype.h>
int sed_SearchMerge(sed_type sed, char c)
/*
Find the next field whose merge begins with the given character.
Leading Spaces are ignored. Case is ignored, except for extended
ASCII values. Protected fields are ignored.
If the field has a highlighted character, it is used for the search.
If the field has no highlighted character, the first alpha-numeric
(or extended ASCII) non-writeable character is used for the search.
Return the field number if a field is found
Return (-1) if no field starts with the character.
*/
{
register int i;
register int fld;
int reclen;
int merlen;
int r2mi;
int lastr2m;
int curr2m;
boolean found;
int delta;
char *merp;
menu_type menu;
menu = sed_GetMenu(sed);
for (i = 0; i < menu_GetFieldCount(menu); i++) {
fld = (i + sed_GetFieldNo(sed) + 1) % menu_GetFieldCount(menu);
/* ignore protected fields and fields with no record AND no merge */
merlen = menu_GetMergeLen(menu, fld);
reclen = menu_GetRecordLen(menu, fld);
if (menu_IsProtected(menu, fld) || (reclen == 0 && merlen == 0)) {
continue;
}
/* get merge (or record if no merge) */
merp = menu_GetFieldMerge(menu, fld);
if (menu_IsHiCharOn(menu, fld)) {
/* if field highlighting is on, use highlight char for search */
merp += menu_GetHiChar(menu, fld);
}
else if (merlen <= reclen) {
/* ignore fields with no merge and no highlighting */
merp = NULL;
}
else {
/* search for 1st alphanumeric non-writeable */
lastr2m = -1;
for (found = FALSE, r2mi = 0; r2mi < reclen && !found; r2mi++) {
/* use record-to-merge map to find runs of
non-writeables in merge
*/
curr2m = menu_GetR2M(menu, fld, r2mi);
if ((delta = curr2m - lastr2m) > 1) {
/* jump in map values indicates a run of
non-writeables through which to search
*/
merp += (lastr2m + 1);
lastr2m = curr2m;
while (delta > 0) {
if ((*merp != '\0') &&
(isalnum(*merp) || *merp > 127)) {
found = TRUE;
delta = 0;
}
else {
delta--;
merp++;
}
}
}
} /* end of r2m for loop */
if (!found) {
/* search rest of merge */
while (!(isalnum(*merp) || *merp > 127) && (*merp != '\0')) {
merp++;
}
}
}
/* compare the character with the merge character */
if (merp != NULL && *merp != '\0') {
if (*merp > 127 && *merp == c) {
return(fld);
}
else if (otoupper(*merp) == otoupper(c)) {
return(fld);
}
}
} /* end of for loop */
return(-1);
}