📄 smif.c
字号:
break; } else { lbptr ++; if (lgetcount != NULL) (*lgetcount)++; lbptr->curpos = 0; } } else { lbptr->curpos += strlen(curword); free(curword); } curword = SMif_getword(lbptr->line+lbptr->curpos,1, ignotabptr->chartable); lbptr->curpos += SMif_lwastecount (lbptr->line+lbptr->curpos, ignotabptr->chartable); } return curword;}/* Get next word with attention of NPNL from current position */char * GetNextWord_NPNL (FileBuffer* fbptr, SMif_table* ignotabptr, SMif_table* npnltabptr, NPNLTrack *trackheadptr, int* lgetcount){ NPNLTrack tracktemp=NULL, tracktail = NULL; int linerestcount = 0; int npnlcount = 0; LineBuffer* lbptr = &(fbptr->lines[fbptr->curline]); char *result = NULL, *tempstr = NULL; int isnpnl, seeeof; int templen; if (*trackheadptr != NULL) { for (tracktemp = *trackheadptr; tracktemp!=NULL;) { *trackheadptr = tracktemp->next; if (tracktemp->word != NULL) free (tracktemp->word); free (tracktemp); tracktemp = *trackheadptr; } *trackheadptr = tracktemp = NULL; } if (npnltabptr->chartable == NULL && npnltabptr->wordtable == NULL) return (GetNextWord(fbptr,ignotabptr,lgetcount)); if (!fbptr->eof) linerestcount = SMif_wordcount (lbptr->line+lbptr->curpos,ignotabptr->chartable); while (!fbptr->eof && (result == NULL || isinwordtable(result,ignotabptr->wordtable)) ) { if (result != NULL) { free (result); result = NULL; } if (linerestcount >= 1) { result = SMif_getword(lbptr->line+lbptr->curpos,1,ignotabptr->chartable); lbptr->curpos += SMif_lwastecount (lbptr->line+lbptr->curpos, ignotabptr->chartable); if (linerestcount == 2) { if (tempstr != NULL) free (tempstr); tempstr = SMif_getword(lbptr->line + lbptr->curpos, 2, ignotabptr->chartable); if ( isinwordtable (tempstr, ignotabptr->wordtable)) { free (tempstr); tempstr = NULL; } } if (linerestcount == 1 && IsNPNLString(result,npnltabptr) || linerestcount == 2 && tempstr != NULL && ( isinwordtable (tempstr, npnltabptr->wordtable) || strlen(tempstr)==1 && isinchartable (tempstr[0],npnltabptr->chartable) ) ) /* NPNL */ { npnlcount = 1; isnpnl = 1; seeeof = 0; if (*trackheadptr != NULL) { for (tracktemp = *trackheadptr; tracktemp!=NULL;) { *trackheadptr = tracktemp->next; if (tracktemp->word != NULL) free (tracktemp->word); free (tracktemp); tracktemp = *trackheadptr; } *trackheadptr = tracktemp = NULL; } *trackheadptr = (NPNLTrack) malloc (sizeof(struct NPNLTrackItem)); (*trackheadptr)->line = 0; (*trackheadptr)->seeeof = 0; (*trackheadptr)->curlen = strlen(result); (*trackheadptr)->word = result; result = NULL; (*trackheadptr)->next = NULL; (*trackheadptr)->last = NULL; tracktail = *trackheadptr; if (fbptr->curline >= fbptr->linecount -1) { (*trackheadptr)->seeeof = 1; isnpnl = 0; } /* last line: keine Fortsetzung! */ while (isnpnl) { linerestcount = SMif_wordcount ((lbptr+npnlcount)->line, ignotabptr->chartable); tracktemp = (NPNLTrack)malloc(sizeof(struct NPNLTrackItem)); tracktemp->seeeof = 0; tracktemp->line = npnlcount; tracktemp->curlen = (*trackheadptr)->curlen; /* sum */ tracktemp->next = *trackheadptr; tracktemp->last = NULL; tracktemp->word = SMif_getword((lbptr+npnlcount)->line,1, ignotabptr->chartable); (lbptr+npnlcount)->curpos = SMif_lwastecount( (lbptr+npnlcount)->line, ignotabptr->chartable); (*trackheadptr)->last = tracktemp; *trackheadptr = tracktemp; if (linerestcount == 0) break; if (linerestcount == 2) { if (tempstr != NULL) free (tempstr); tempstr = SMif_getword ((lbptr+npnlcount)->line, 2, ignotabptr->chartable); if (isinwordtable (tempstr, ignotabptr->wordtable)) { free (tempstr); tempstr = NULL; } } if (linerestcount == 1 && IsNPNLString ((*trackheadptr)->word,npnltabptr) || linerestcount == 2 && tempstr != NULL && ( isinwordtable (tempstr, npnltabptr->wordtable) || strlen(tempstr)==1 && isinchartable (tempstr[0],npnltabptr->chartable) ) ) { if (fbptr->curline + npnlcount + 1 >= fbptr->linecount) { (*trackheadptr)->seeeof = 1; isnpnl = 0; } else npnlcount ++; } else isnpnl = 0; (*trackheadptr)->curlen += strlen((*trackheadptr)->word); } /* while (isnpnl) */ result = (char*)malloc(sizeof(char)*((*trackheadptr)->curlen+1)); templen = 0; for (tracktemp = tracktail; tracktemp != NULL && tracktemp->word!=NULL; tracktemp = tracktemp->last) { /* word == NULL : empty line */ (void)strcpy( result+templen, tracktemp->word); templen = tracktemp->curlen; } } /* if NPNL */ } /* end of "if (linerestcount >= 1) {...}" */ else { while (linerestcount < 1) { /* linerestcount < = 0 */ fbptr->curline ++; if (fbptr->curline >= fbptr->linecount) { fbptr->eof = 1; fbptr->curline = fbptr->linecount - 1; break; } else { lbptr ++; if (lgetcount != NULL) (*lgetcount)++; linerestcount = SMif_wordcount (lbptr->line, ignotabptr->chartable); } } } } if (tempstr != NULL) free(tempstr); return result;}void SetNewFbptr (FileBuffer * fbptr, NPNLTrack trackhead, int breakp){ NPNLTrack tracktemp = NULL; LineBuffer * lbptr = &(fbptr->lines[fbptr->curline]); if (trackhead != NULL) { for (tracktemp = trackhead; tracktemp->next != NULL && tracktemp->next->curlen >= breakp + 1; tracktemp = tracktemp->next); fbptr->curline += tracktemp->line; lbptr += tracktemp->line; if (tracktemp->next == NULL) lbptr->curpos += breakp; else lbptr->curpos += (breakp - tracktemp->next->curlen); } else lbptr->curpos += breakp;}/* GETItemWord : return 1 : end */int GetItemWord (SMifinfo *smifptr, int *stopget, int flag){ int mm , nn, ll, templen, tempcount, requiredint; int breakget = 0; char *curword = NULL; Tcl_Interp * interp = smifptr->interp; SMif_table *ignotabptr = &(smifptr->envinfo->ignotable); SMif_table *npnltabptr = &(smifptr->envinfo->npnltable); SMif_table *repeattabptr = &(smifptr->envinfo->repeattable); SMif_table *stoptabptr = &(smifptr->envinfo->stoptable); FileBuffer * fbptr = &(smifptr->fbuffer); GetInfo *getinfoptr = &(smifptr->envinfo->getinfo); ItemInfo *iteminfoptr = &(smifptr->envinfo->iteminfo); char **itemword = NULL; char *tempstr1 = NULL, *tempstr2 = NULL; static char tempname[4]; struct SMif_intinwordinfo intinwordinfo; struct SMif_intinfoitem *intinfoptr = NULL; NPNLTrack trackhead = NULL, tracktemp = NULL; itemword = (char**) malloc (sizeof(char*) * iteminfoptr->itemsize); for (nn=0; nn < iteminfoptr->itemsize; nn++) itemword[nn] = NULL; tempname[0] = '$'; intinwordinfo.count = 0; intinwordinfo.intinfo = NULL; mm = 0; while ( mm < iteminfoptr->itemsize) { if ((getinfoptr->type == SMif_GETLIST || getinfoptr->type == SMif_GETPOL) && getinfoptr->subtype == LINENEXT) curword = GetNextWord_NPNL (fbptr, ignotabptr, npnltabptr, &trackhead, &(getinfoptr->getcount)); else curword = GetNextWord_NPNL (fbptr, ignotabptr, npnltabptr, &trackhead, (int*)NULL); if (fbptr->eof || ( getinfoptr->type == SMif_GETLIST || getinfoptr->type == SMif_GETPOL) && getinfoptr->subtype == LINENEXT && getinfoptr->getcount >= getinfoptr->count) /* fbptr->eof <==> curword == NULL */ { if (curword != NULL) { free (curword); curword = NULL; } breakget = 1; break; } /* check: break get command ? */ templen = strlen(curword); /* word */ if (isinwordtable (curword,stoptabptr->wordtable) || isinwordtable (curword,repeattabptr->wordtable) || isinchartable (curword[0],stoptabptr->chartable) || isinchartable (curword[0],repeattabptr->chartable) ) { free (curword); curword = NULL; breakget = 1; break; } for (nn = 0; nn < templen; nn++) /* char */ if (isinchartable (curword[nn],stoptabptr->chartable) || isinchartable (curword[nn],repeattabptr->chartable) ) { curword[nn] = '\0'; breakget = 1; break; } if (flag == DIGITONLY) { SMif_findintinword (curword, &intinwordinfo); requiredint = iteminfoptr->itemsize - mm; for (intinfoptr = intinwordinfo.intinfo; intinfoptr != NULL && mm < iteminfoptr->itemsize; intinfoptr = intinfoptr->next, mm++) { itemword[mm] = (char*)malloc (sizeof(char)*(intinfoptr->length+1)); (void) strncpy (itemword[mm],curword+intinfoptr->pos, intinfoptr->length); itemword[mm][intinfoptr->length] = '\0'; } if (intinfoptr!=NULL && mm == iteminfoptr->itemsize) /* more int than required */ { breakget = 0; if (trackhead!=NULL) trackhead->seeeof = 0; for (intinfoptr = intinwordinfo.intinfo, ll = 1; ll < requiredint; ll++) intinfoptr = intinfoptr->next; SetNewFbptr (fbptr, trackhead, intinfoptr->pos + intinfoptr->length); } else if (breakget) { SetNewFbptr (fbptr, trackhead, nn); break; } else SetNewFbptr (fbptr, trackhead, templen); } else if (flag == ALLCHAR) { itemword[mm] = (char*)malloc (sizeof(char)*(strlen(curword)+1)); (void) strcpy (itemword[mm],curword); mm ++; if (breakget) { SetNewFbptr (fbptr, trackhead, nn); break; } else SetNewFbptr (fbptr, trackhead, templen); } if (trackhead!=NULL && trackhead->seeeof) { fbptr->eof = 1; breakget = 1; break; } if (curword != NULL) { free (curword); curword = NULL; } } /* while ( mm < size ) */ Tcl_ResetResult (interp); if (itemword[0]!=NULL) { if (itemword[iteminfoptr->itemsize-1] == NULL && iteminfoptr->pattern!=NULL) { tempcount = (itemword[mm] == NULL ? mm : mm+1); /* nummer of valid items */ for (mm = tempcount+1; mm <= iteminfoptr->itemsize; mm++) { sprintf (tempname+1, "%d", mm); if (mm >= 10) tempname[3] = '\0'; else tempname[2] = '\0'; if (SMif_at (iteminfoptr->pattern, tempname, 1) != -1) { Tcl_AppendResult (interp, "GET LIST: conflict with ITEM definition", (char*)NULL ); return TCL_ERROR; } } } else tempcount = iteminfoptr->itemsize; if (iteminfoptr->pattern!=NULL) { tempstr1 = (char*) malloc(sizeof(char)*(strlen(iteminfoptr->pattern)+1)); strcpy (tempstr1, iteminfoptr->pattern); for (mm = 10; mm <= tempcount; mm++) { sprintf (tempname+1,"%d",mm); tempname[3] = '\0'; tempstr2 = SMif_strtran (tempstr1,tempname,itemword[mm-1]); free (tempstr1); tempstr1 = tempstr2; tempstr2 = NULL; } for (mm = 1; mm <= (tempcount > 9 ? 9 : tempcount); mm++) { sprintf (tempname+1,"%d",mm); tempname[2] = '\0'; tempstr2 = SMif_strtran (tempstr1,tempname,itemword[mm-1]); free (tempstr1); tempstr1 = tempstr2; tempstr2 = NULL; } if (Tcl_ExprString(interp,tempstr1)==TCL_ERROR) { free (tempstr1); return TCL_ERROR; } } else Tcl_AppendResult (interp,itemword[0],(char*)NULL); if (getinfoptr->type == SMif_GETLIST && getinfoptr->subtype == ITEMNEXT) { getinfoptr->getcount++; if (getinfoptr->getcount == getinfoptr->count) breakget = 1; } } if (stopget != NULL) *stopget = breakget; for (mm = 0; mm < iteminfoptr->itemsize; mm++) if (itemword[mm]!=NULL) free (itemword[mm]); if (tempstr1 != NULL) free (tempstr1); if (tempstr2 != NULL) free (tempstr2); if (curword != NULL) free (curword); if (itemword != NULL) free (itemword); if (trackhead != NULL) for (tracktemp = trackhead; tracktemp!=NULL;) { trackhead = tracktemp->next; if(tracktemp!=NULL) free (tracktemp->word); free (tracktemp); tracktemp = trackhead; } if (intinwordinfo.intinfo != NULL) for (intinfoptr = intinwordinfo.intinfo; intinfoptr!=NULL;) { intinwordinfo.intinfo = intinfoptr->next; free (intinfoptr); intinfoptr = intinwordinfo.intinfo; } return TCL_OK;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -