예제 #1
0
static int
DoCtVW(charptr EndArg, unsigned char TmpChr)        /* do a control-V or control-W */
/* charptr EndArg;                         ptr to end of string argument */
/* unsigned char TmpChr;                 temporary character */
{
    unsigned char WVFlag = TmpChr;                /* ^W or ^V flag */
    DBGFEN(3, "DoCtVW", NULL);

    if (++CBfPtr == EndArg)                 /* move past ^W or ^V,  too far? */
    {
        ErrMsg(ERR_ISS);                /* yes, illegal search string */
        DBGFEX(2, DbgFNm, "FAILURE");
        return FAILURE;
    }

    if ((*CBfPtr == '^') && ((EdFlag & ED_CARET_OK) == 0))
    {
        if (++CBfPtr == EndArg)
        {
            ErrMsg(ERR_ISS);
            DBGFEX(2, DbgFNm, "FAILURE");
            return FAILURE;
        }
        TmpChr = To_Upper(*CBfPtr);

        if ((TmpChr < '@') || (TmpChr > '_'))
        {
            ErrChr(ERR_IUC, *CBfPtr);
            DBGFEX(2, DbgFNm, "FAILURE");
            return FAILURE;
        }
        TmpChr &= '\077';
    }
    else
        TmpChr = *CBfPtr;

    if (WVFlag == CTRL_V)
        if (TmpChr == CTRL_V)
            CaseCv = LOWER;
        else
            *BBfPtr++ = To_Lower(TmpChr);
    else
        if (TmpChr == CTRL_W)
            CaseCv = UPPER;
        else
            *BBfPtr++ = To_Upper(TmpChr);

    DBGFEX(2, DbgFNm, "SUCCESS");
    return SUCCESS;
}
예제 #2
0
int main()
{
	FILE *fp;
	int i,sc=0,wc=0;
	int lf[26]={0},alpha[26]={0};
	char a,str[255];
	fp=fopen("ks.txt","r");
	fscanf(fp, "%[^\r]",str);
	char * a1 = strtok(str,"\n");
	while(a1!=NULL)
	{
		a1=To_Lower(a1,lf);
		sc+=symb_count(a1);
		wc+=wordify(a1);
		a1=strtok(NULL,"\n");
	}
	printf("1.Letter count = %d\n",count);
	printf("2.Symbol count = %d\n",sc);
	printf("3.Word Count = %d\n",wc);
	letters_not_used(lf);
	frequent_letters(lf,alpha);
	printf("5.Three Common letters are : %c,%c,%c\n",alpha[0],alpha[1],alpha[2]);
	sort();
	if(wc>=3)
	{
		printf("6.Top three Common words : ");
		p=head;
		for(i=0;i<3;i++)
		{
			printf("%s, ",p->str);
			p=p->next;
		}
		printf("\n");
	}
	printf("7.No.of Words Occured once : %d\n",occured_once());
	p=head;
       fclose(fp);
    return 0;
}
예제 #3
0
int
BldStr(charptr XBfBeg, charptr XBfEnd, charptr* XBfPtr)                /* build a string */
/* charptr XBfBeg;                 beginning of build-string buffer */
/* charptr XBfEnd;                 end of build-string buffer */
/* charptr (*XBfPtr);                 pointer into build-string buffer */
{
    charptr       EndArg;                /* end of input string, plus 1 */
    unsigned char TmpChr;        /* temporary character */

    DBGFEN(2,"BldStr",NULL);

    if (FindES(ESCAPE) == FAILURE)         /* move CBfPtr to end of argument */
    {
        DBGFEX(2,DbgFNm,"FAILURE, FindES(ESCAPE) failed");
        return FAILURE;
    }

    CaseCv = IniSrM;                /* initialize internal search mode */
    BBfPtr = XBfBeg;                /* initialize ptr into build-string buffer */
    EndArg = CBfPtr;                /* save pointer to end of argument */
    CBfPtr = ArgPtr;                /* reset to beginning of argument */

    while (CBfPtr < EndArg)
    {
        if ((*CBfPtr == '^') && ((EdFlag & ED_CARET_OK) == 0))
        {
            if (++CBfPtr == EndArg)
            {
                ErrMsg(ERR_ISS);
                DBGFEX(2,DbgFNm,"FAILURE, no char after ^");
                return FAILURE;
            }
            TmpChr = To_Upper(*CBfPtr);
            if ((TmpChr < '@') || (TmpChr > '_'))
            {
                ErrChr(ERR_IUC, *CBfPtr);
                DBGFEX(2,DbgFNm,"FAILURE, bad char after ^");
                return FAILURE;
            }
            TmpChr &= '\077';
        }
        else
            TmpChr = *CBfPtr;

        switch (TmpChr)
        {
            case CTRL_R:
            case CTRL_Q:
                if (++CBfPtr == EndArg)
                {
                    ErrMsg(ERR_ISS);
                    DBGFEX(2, DbgFNm, "FAILURE");
                    return FAILURE;
                }
                *BBfPtr++ = *CBfPtr;
                break;

            case CTRL_V:
            case CTRL_W:
                if (DoCtVW(EndArg, TmpChr) == FAILURE)
                {
                    DBGFEX(2, DbgFNm, "FAILURE, DoCtVW failed");
                    return FAILURE;
                }
                break;

            case CTRL_E:
                if (DoCtE(EndArg, XBfEnd) == FAILURE)
                {
                    DBGFEX(2, DbgFNm, "FAILURE, DoCtE failed");
                    return FAILURE;
                }
                break;

            default:
                if (CaseCv == LOWER)
                    TmpChr = To_Lower(TmpChr);
                else if (CaseCv == UPPER)
                    TmpChr = To_Upper(TmpChr);
                *BBfPtr++ = TmpChr;
        } /* switch(TmpChr) */

        if (BBfPtr > XBfEnd)
        {
            ErrMsg(ERR_STL);        /* string too long */
            DBGFEX(2, DbgFNm, "FAILURE, string too long");
            return FAILURE;
        }
        ++CBfPtr;
    }
    *XBfPtr = BBfPtr;

#if DEBUGGING
    sprintf(DbgSBf, "string = \"%.*s\"", (int)(BBfPtr-XBfBeg), XBfBeg);
    DbgFEx(2, DbgFNm, DbgSBf);
#endif

    return SUCCESS;
}
예제 #4
0
파일: baksrc.c 프로젝트: blakemcbride/TECOC
/*****************************************************************************
	BakSrc()
	This recursive function does a backward search in the edit buffer,
looking for a string which will match the first match construct in the search
buffer.  Basically,  it is the high-speed part of the search algorithm: it
scans the edit buffer looking for the first character in the search string.
	On entry, SStPtr points to the first match construct in the search
buffer.  On exit,  SStPtr points to the last character of the first match
construct in the search buffer.
	SBfPtr points to the character following the last character in
the search string.  This function does not modify SBfPtr.
	On entry,  EBPtr1 points to the place in the edit buffer where
the search starts.  On exit,  if the search was successful,  EBPtr1 will
point to the found character.  If the search was unsuccessful,  EBPtr1 will
be less than EndSAr.
	On entry,  EBPtr2 is undefined.  On exit,  if the search was
successful,  EBPtr2 points to the last character of the found string.  If
the search was unsuccessful,  EBPtr2 is undefined.
	EndSAr points to the end of the search area (where the search ends).
Note that for backwards searches,  EndSAr is less than EBPtr1.  This function
does not modify EndSAr.
	Match constructs are:
	^X		match any character
	^S		match a separator character (not letter or digit)
	^N		match anything but following match construct
	^EA		match any alphabetic
	^EB		match a separator character (not letter or digit)
	^EC		match symbol constituent
	^ED		match any digit
	^EGq		match any character in q-register q
	^EL		match any line terminator (LF, VT, FF)
	^EM		match non-null string of following match construct
	^ER		match any alphanumeric
	^ES		match non-null string of spaces and/or tabs
	^EV		match lowercase alphabetic
	^EW		match uppercase alphabetic
	^EX		match any character
	^E<nnn>		match character with ASCII code nnn (octal)
	^E[x1,x2,...xn]	match any of the match constructs x1, x2, etc.
	else		match the character itself
*****************************************************************************/
#include "zport.h"		/* define portability identifiers */
#include "tecoc.h"		/* define general identifiers */
#include "defext.h"		/* define external global variables */
#include "dchars.h"		/* define identifiers for characters */
#include "chmacs.h"		/* define character processing macros */
#include "deferr.h"		/* define identifiers for error messages */
DEFAULT BakSrc()		/* forward search for 1st search char */
{
    unsigned char Charac;	/* holds a character */
    charptr	LstBeg;		/* beginning of ^E[x1,x2,...] list */
    char	OtCase;		/* "other" case character */
    charptr	QRPtr;		/* pointer into q-register text */
    BOOLEAN	SamChr;		/* same character indicator */
    charptr	SavEP2;		/* temporary holder of EBPtr2 */
    charptr	SavSSP;		/* temporary holder of SStPtr */
    DEFAULT	Status;		/* FindQR() status for ^EGq */
    charptr	TCBfPt;		/* temporary holder of CBfPtr */
    charptr	TCStEn;		/* temporary holder of CStEnd */
    LONG	TmpLng;		/* holds octal number for ^E<nnn> */
#if DEBUGGING
    static char *DbgFNm = "BakSrc";
    sprintf(DbgSBf,"*SStPtr = '%c', *EBPtr1 = '%c'", *SStPtr, *EBPtr1);
    DbgFEn(3,DbgFNm,DbgSBf);
#endif
    switch (*SStPtr) {
	case CTRL_X:	/* ^X match any char */
    	    break;
	case CTRL_S:	/* ^S match separator char */
	    for (; EBPtr1 >= EndSAr; --EBPtr1) {
	        if (!Is_Alnum(*EBPtr1)) {
		    break;
		}
	    }
	    break;
	case CTRL_N:	/* ^Nx match any BUT next match construct */
	    if (++SStPtr == SBfPtr) {
	        ErrMsg(ERR_ISS);		/* illegal search string */
		DBGFEX(3,DbgFNm,"FAILURE, no ^N arg");
		return FAILURE;
	    }
	    SavSSP = SStPtr;
	    for (;EBPtr1>=EndSAr;--EBPtr1) {
	        EBPtr2 = EBPtr1;
		SStPtr = SavSSP;
		if (CMatch(&SamChr) == FAILURE) {
		    DBGFEX(3,DbgFNm,"FAILURE, CMatch failed");
		    return FAILURE;
		}
		if (!SamChr) {
		    break;
		}
	    }
	    break;
	case CTRL_E:	/* ^E match construct */
	    if (++SStPtr == SBfPtr) {
	        ErrMsg(ERR_ICE);	/* ICE = illegal ^E */
		DBGFEX(3,DbgFNm,"FAILURE, no ^E arg");
		return FAILURE;
	    }
	    switch (To_Upper(*SStPtr)) {
	        case 'A':	/* ^EA match any alphabetic */
		    for (; EBPtr1 >= EndSAr; --EBPtr1) {
		        if (Is_Alpha(*EBPtr1)) {
			    break;
			}
		    }
		    break;
		case 'B':	/* ^EB match any separator (==^S) */
		    for (; EBPtr1 >= EndSAr; --EBPtr1) {
		        if (!Is_Alnum(*EBPtr1)) {
			    break;
			}
		    }
		    break;
		case 'C':	/* ^EC match symbol constitient */
		    for (; EBPtr1 >= EndSAr; --EBPtr1) {
		        if (Is_SyCon(*EBPtr1)) {
			    break;
			}
		    }
		    break;
		case 'D':	/* ^ED match any digit */
		    for (; EBPtr1 >= EndSAr; --EBPtr1) {
		        if (Is_Digit(*EBPtr1)) {
			    break;
			}
		    }
		    break;
		case 'G':	/* ^EGq match any char in Q-reg q */
		    if (++SStPtr == SBfPtr) {
		        ErrMsg(ERR_ICE);
			DBGFEX(3,DbgFNm,"FAILURE, no ^EG arg");
			return FAILURE;
		    }
		    TCBfPt = CBfPtr;	/* save CBfPtr */
		    TCStEn = CStEnd;	/* save CStEnd */
		    CBfPtr = SStPtr;
		    CStEnd = SBfPtr;
		    Status = FindQR();
		    SStPtr = CBfPtr;
		    SBfPtr = CStEnd;
		    CBfPtr = TCBfPt;	/* restore CBfPtr */
		    CStEnd = TCStEn;	/* restore CStEnd */
		    if (Status == FAILURE) {
		        DBGFEX(3,DbgFNm,"FAILURE, ^EG FindQR failed");
			    return FAILURE;
		    }	
		    for (; EBPtr1 >= EndSAr; --EBPtr1) {
		        QRPtr = QR->Start;
			while (QRPtr < QR->End_P1) {
			    if (*QRPtr++ == *EBPtr1) {
			        goto kludge;
			    }
			}
		    }
kludge:		    break;
		case 'L':	/* ^EL match line terminator */
		    for (; EBPtr1 >= EndSAr; --EBPtr1) {
		        if (IsEOL(*EBPtr1)) {
			    break;
			}
		    }
		    break;
		case 'M':	/* ^EM match multiple next constructs */
		    if (++SStPtr == SBfPtr) {
		        ErrMsg(ERR_ICE);
			DBGFEX(3,DbgFNm,"FAILURE, no ^EM arg");
			return FAILURE;
		    }
		    SavSSP = SStPtr;
		    if (BakSrc() == FAILURE) {
		        DBGFEX(3,DbgFNm,"FAILURE");
			return FAILURE;
		    }
		    if (EBPtr1 < EndSAr) {	/* if not found */
		        break;
		    }
		    SavEP2 = EBPtr2;
		    while (EBPtr1 > EndSAr) {
		        EBPtr1--;
			EBPtr2 = EBPtr1;
			SStPtr = SavSSP;
			if (CMatch(&SamChr) == FAILURE) {
			    DBGFEX(3,DbgFNm,"FAILURE");
			    return FAILURE;
			}
			if (!SamChr) {
			    EBPtr1++;
			    EBPtr2 = SavEP2;
			    break;
			}
		    }
		    DBGFEX(3,DbgFNm,"SUCCESS");
		    return SUCCESS;
		case 'R':	/* ^ER match any alphanumeric */
		    for (; EBPtr1 >= EndSAr; --EBPtr1) {
		        if (Is_Alnum(*EBPtr1)) {
			    break;
			}
		    }
		    break;
		case 'S':	/* ^ES match any spaces/tabs */
		    for (; EBPtr1 >= EndSAr; --EBPtr1) {
		        if ((*EBPtr1 == SPACE) || (*EBPtr1 == TABCHR)) {
			    EBPtr2 = EBPtr1;
			    while (EBPtr1 > EndSAr) {
			        EBPtr1--;
				if ((*EBPtr1 != SPACE) &&
				    (*EBPtr1 != TABCHR)) {
				    EBPtr1++;
				    break;
				}
			    }
			    DBGFEX(3,DbgFNm,"SUCCESS");
			    return SUCCESS;
			}
		    }
		    break;
		case 'V':	/* ^EV match any lowercase char */
		    for (; EBPtr1 >= EndSAr; --EBPtr1) {
		        if (Is_Lower(*EBPtr1)) {
			    break;
			}
		    }
		    break;
		case 'W':	/* ^EW match any uppercase character */
		    for (; EBPtr1 >= EndSAr; --EBPtr1) {
		        if (Is_Upper(*EBPtr1)) {
		            break;
			}
		    }
		    break;
		case 'X':	/* ^EX match any char (==^X) */
		    break;
		case '<':	/* ^E<n> match char w/ASCII octal code n */
		    if (++SStPtr == SBfPtr) {
		        ErrMsg(ERR_ICE);
			DBGFEX(3,DbgFNm,"FAILURE, no ^E<> arg");
			return FAILURE;
		    }
		    TmpLng = 0;
		    while (Is_Digit(*SStPtr)) {
		        TmpLng = (TmpLng * 8) + (*SStPtr - '0');
			if (TmpLng > 127) {
			    ErrMsg(ERR_ICE);
			    DBGFEX(3,DbgFNm,"FAILURE");
			    return FAILURE;
			}
			if (++SStPtr == SBfPtr) {
			    ErrMsg(ERR_ICE);
			    DBGFEX(3,DbgFNm,"FAILURE");
			    return FAILURE;
			}
		    }
		    if (*SStPtr != '>') {
		        ErrMsg(ERR_ICE);
			DBGFEX(3,DbgFNm,"FAILURE");
			return FAILURE;
		    }
		    Charac = (unsigned char)TmpLng;
		    for (; EBPtr1 >= EndSAr; --EBPtr1) {
		        if (*EBPtr1 == Charac) {
			    break;
			}
		    }
		    break;
		case '[':	/* ^E[x1,x2,...] match any one of x1,x2,... */
		    if (++SStPtr == SBfPtr) {
		        ErrMsg(ERR_ICE);
			DBGFEX(3,DbgFNm,"FAILURE, no ^E[] arg");
			return FAILURE;
		    }
		    LstBeg = SStPtr;
		    for (; EBPtr1 >= EndSAr; --EBPtr1) {
			while (*SStPtr != ']') {
		            if (*SStPtr == ',') {
			        if (++SStPtr == SBfPtr) {
			            ErrMsg(ERR_ICE);
				    DBGFEX(3,DbgFNm,"FAILURE");
				    return FAILURE;
				}
			    } else {
			        EBPtr2 = EBPtr1;
				if (CMatch(&SamChr) == FAILURE) {
			            DBGFEX(3,DbgFNm,"FAILURE");
				    return FAILURE;
				}
				if (SamChr) {
			            while (*SStPtr != ']') {
				        if (++SStPtr == SBfPtr) {
				            ErrMsg(ERR_ICE);
					    DBGFEX(3,DbgFNm,"FAILURE");
					    return FAILURE;
					}
				    }
				    EBPtr2 = EBPtr1;
				    DBGFEX(3,DbgFNm,"SUCCESS");
				    return SUCCESS;
				}
				if (++SStPtr == SBfPtr) {
			            ErrMsg(ERR_ICE);
				    DBGFEX(3,DbgFNm,"FAILURE");
				    return FAILURE;
				}
			    }
			}
			SStPtr = LstBeg;
		    }
		    break;
		default:
		    ErrMsg(ERR_ICE);
		    DBGFEX(3,DbgFNm,"FAILURE, bad ^E arg");
		    return FAILURE;
	    } /* end of ^E switch */
	    break;
	default:	/* edit buffer char must match search string char */
	    if (SMFlag) {			/* if case dependence */
	        for (; EBPtr1 >= EndSAr; --EBPtr1) {
		    if (*EBPtr1 == *SStPtr) {
		        break;
		    }
		}
	    } else {			/* else case independence */
	        OtCase = Is_Upper(*SStPtr)
		             ? To_Lower(*SStPtr)
			     : To_Upper(*SStPtr);
		for (; EBPtr1 >= EndSAr; --EBPtr1) {
		    if ((*EBPtr1 == *SStPtr) || (*EBPtr1 == OtCase)) {
		        break;
		    }
		}
	    }
    } /* end of switch */
    EBPtr2 = EBPtr1;
    DBGFEX(3,DbgFNm,"SUCCESS");
    return SUCCESS;
}