コード例 #1
0
ファイル: CSCRN.C プロジェクト: kytulendu/TW
void dispstrhgc( unsigned char *p_string, int p_xPos, int p_yPos, font_attr p_attr ) {
	while ( ( *p_string != '\0' ) && ( p_xPos < 90 ) ) {
		if ( *p_string < 32 ) {
			togglefont( &p_attr, *p_string );
		} else {
			if ( whatlevel( *p_string ) == MIDDLE ) {
				prchar( *p_string, p_attr, p_xPos, p_yPos );
				if ( ( p_attr & ENLARGEATTR ) == ENLARGEATTR ) {
					p_xPos++;
				}
				p_xPos++;
			} else {
				if ( ( p_attr & ENLARGEATTR ) == ENLARGEATTR ) {
					if ( p_xPos >= 2 ) {
						prchar( *p_string, p_attr, p_xPos - 2, p_yPos );
					}
				} else {
					if ( p_xPos >= 1 ) {
						prchar( *p_string, p_attr, p_xPos - 1, p_yPos );
					}
				}
			}
		}
		p_string++;
	}
}
コード例 #2
0
ファイル: SEARCH.C プロジェクト: kytulendu/TW
int searchfwd( unsigned int *p_xCursorPos, unsigned int *y_CursorPos ) {
	struct line_node *savepage, *templine;
	boolean enlargeflag;
	unsigned int linecount;
	unsigned int savecol;
	unsigned int startpos;
	size_t i;
	font_attr font = NORMALATTR;
	char *foundpoint;
	char *addr;

	savecol = firstcol;
	savepage = curpage;
	storeline( curline );
	templine = curpage;
	linecount = wind.width - 1;

	while ( templine != curline ) {
		linecount--;
		templine = templine->next;
	}

	startpos = linearcolumn( curline->text, *p_xCursorPos + firstcol, &font );
	foundpoint = NULL;

	while ( ( foundpoint == NULL ) && ( curline != sentinel ) ) {
		foundpoint = searchline( curline->text, startpos );

		if ( foundpoint != NULL ) {		/* found */

			while ( ( *y_CursorPos = findrow( ) ) >= wind.width ) {
				curpage = curpage->next;
			}

			*p_xCursorPos = 0;
			firstcol = 0;
			addr = curline->text;
			enlargeflag = NO;

			while ( addr != foundpoint ) {
				if ( ( whatlevel( *addr ) == MIDDLE ) && ( *addr >= 32 ) ) {
					if ( enlargeflag ) {
						( *p_xCursorPos )++;
					}
					( *p_xCursorPos )++;
				} else {
					if ( *addr == ENLARGECODE ) {
						enlargeflag = enlargeflag ^ 1;
					}
				}
				addr++;
			}

			for ( i = 0; source[i] != '\0'; i++ ) {
				if ( whatlevel( source[i] ) == MIDDLE ) {
					if ( enlargeflag ) {
						( *p_xCursorPos )++;
					}
					( *p_xCursorPos )++;
				}
			}

			while ( *p_xCursorPos >= wind.length ) {
				firstcol = firstcol + wind.length;
				*p_xCursorPos = *p_xCursorPos - wind.length;
			}

		} else {
			if ( linecount > 0 ) {
				linecount--;
				curline = curline->next;
				lineno++;
			} else {
				curline = curline->next;
				lineno++;
				curpage = curline;
				linecount = wind.width - 1;
			}
			startpos = 0;
		}
	}

	if ( foundpoint == NULL ) {
		curline = sentinel->previous;
		curpage = curline;
		loadtoline( curline->text );
		endline( p_xCursorPos );
	}

	loadtoline( curline->text );

	if ( savepage != curpage ) {
		showpageall( );
	} else {
		if ( firstcol != savecol ) {
			showpageall( );
		}
	}

	if ( foundpoint != NULL ) {
		return( YES );
	} else {
		return( NO );
	}

}
コード例 #3
0
ファイル: GETSTR.C プロジェクト: kytulendu/CW141
int getstring(char textst[],unsigned x,unsigned y,unsigned maxlen,char attr,strtype mode)
{
 int inkey,key,oldlen,temp;
 char keepchar;
 keepchar = '\0';
 oldlen = strlen(textst);
 dispblank(x,y,maxlen,attr);
 dispstrhgc(textst,x,y,attr);
 waitkbd(x+thaistrlen(textst),y);
 switch(mode) {
 case THAIENG : inkey = readkbd();
                break;
 case NUMBER  :
 case ONEORTWO :
 case ENGLISH : inkey = bioskey(0);
                break;
 case ENGUPCASE : inkey = bioskey(0);
                  key = inkey & 0xff;
                  if ((key >= 'a') && (key <= 'z'))
                    inkey = key - ('a' - 'A');
                  break;
 }
 switch (inkey) {
 case CNTRL_H  :
 case BSKEY    :
 case CNTRL_S  :
 case LEKEY    :
 case CNTRL_M  :
 case RETKEY   : break;
 default       : key = inkey & 0xff;
                 if (mode == NUMBER) {
                   if ((key < '0') || (key > '9')) break;
                 }
                 if (mode == ONEORTWO) {
                   if ((key != '1') && (key != '2')) break;
                 }
                 if ((inkey & 0xff) >= 32) {
                   textst[0] = '\0';
                   dispblank(x,y,maxlen,attr);
                 }
                 break;
 }
 do {
   switch(inkey){
   case CNTRL_M :
   case RETKEY  : return(YES);
   case CNTRL_U : return(NO);              /* Abort */
   case ESCKEY  : return(ESCKEY);
   case UPKEY   : return(UPKEY);
   case DNKEY   : return(DNKEY);
   case CNTRL_H :
   case BSKEY   :
   case LEKEY   :
   case CNTRL_S : temp = strlen(textst);
                   if (temp != 0){
                      if (temp < oldlen)
                         textst[temp] = keepchar;
                      keepchar = textst[temp-1];
                      textst[temp-1] = '\0';
                      dispblank(x,y,maxlen,attr);
                      dispstrhgc(textst,x,y,attr);
                   }
                   break;
   case RIKEY   :
   case CNTRL_D : temp = strlen(textst);
                  if ((temp < oldlen) && (temp < maxlen)){
                     textst[temp] = keepchar;
                     keepchar = textst[temp+1];
                     textst[temp+1] = '\0';
                     dispblank(x,y,maxlen,attr);
                     dispstrhgc(textst,x,y,attr);
                  }
                  break;
   case CNTRL_Y : if (strlen(textst) < oldlen)
                     textst[strlen(textst)] = keepchar;
                  keepchar = textst[0];
                  textst[0] = '\0';
                  dispblank(x,y,maxlen,attr);
                  break;
   case CNTRL_R : if (strlen(textst) < oldlen){
                     textst[strlen(textst)] = keepchar;
                     dispblank(x,y,maxlen,attr);
                     dispstrhgc(textst,x,y,attr);
                  }
                  break;
/*   case F10KEY  : thaimode = !thaimode;
		  writelanguage();
                  break;
*/   default      : inkey = (inkey & 0xff);
                  if (mode == NUMBER) {
                    if ((inkey < '0') || (inkey > '9')) break;
                  }
                  if (mode == ONEORTWO) {
                    if ((inkey != '1') && (inkey != '2')) break;
                  }
                  if (inkey >= 32) {
                    if (strlen(textst) < maxlen) {
                      if (whatlevel(inkey) == MIDDLE) {
                        textst[strlen(textst)+1] = '\0';
                        textst[strlen(textst)] = inkey;
                        oldlen = strlen(textst);
                        dispblank(x,y,maxlen,attr);
                        dispstrhgc(textst,x,y,attr);
                      } else {
                        if ((strlen(textst) != 0) &&
                          (whatlevel(inkey) > whatlevel(textst[strlen(textst)-1])) &&
                          (inkey != HUNAKADMITO)) {
                          textst[strlen(textst)+1] = '\0';
                          textst[strlen(textst)] = inkey;
                          oldlen = strlen(textst);
                          dispblank(x,y,maxlen,attr);
			  dispstrhgc(textst,x,y,attr);
			}
		      }
		  }
		  }
                  break;
   }
   waitkbd(x+thaistrlen(textst),y);
   switch(mode) {
   case THAIENG : inkey = readkbd();
                  break;
   case NUMBER  :
   case ONEORTWO :
   case ENGLISH : inkey = bioskey(0);
                  break;
 case ENGUPCASE : inkey = bioskey(0);
                  key = inkey & 0xff;
                  if ((key >= 'a') && (key <= 'z'))
                    inkey = key - ('a' - 'A');
                  break;
   }
 } while(1);
}
コード例 #4
0
ファイル: EDIT.C プロジェクト: kytulendu/CW141
void displine(struct line_node *line,unsigned y,unsigned linenum)
{
    register unsigned x = 0;
    int count = firstcol;
    font_attr tempfont, curfont = 0;
    char *st;

    st = line->text;
    y += wind.row;
    while ((count > 0) && (*st != '\0')) {
      if (whatlevel(*st) == MIDDLE) {
        if (*st < 32) {
          togglefont(&curfont,*st);
        } else {
          if ((curfont & ENLARGEATTR) == ENLARGEATTR) {
            count--;
          }
          count--;
        }
      }
      st++;
    }
    if ((count < 0) && ((curfont & ENLARGEATTR) == ENLARGEATTR)) {
      x++;
    }
    while ((*st != '\0') && (x < (wind.length - 2))){
      if (*st < 32) {
        togglefont(&curfont,*st);
      } else {
        tempfont = curfont;
        if (haveblock() && inblock(linenum,x + firstcol) && dispblock) {
          curfont = curfont | REVERSEATTR;
        }
        if (whatlevel(*st) != MIDDLE) {
          if (x > 0) {
            if ((curfont & ENLARGEATTR) == ENLARGEATTR) {
              if (x >= 2) {
                prchar(*st,curfont,wind.col+x-2,y);
              }
            } else {
              prchar(*st,curfont,wind.col+x-1,y);
            }
          }
        } else {
          if ((*st != ' ') || (curfont != 0)) {
            if ((curfont & ENLARGEATTR) != ENLARGEATTR) {
              prchar(*st,curfont,wind.col+x,y);
              x++;
            } else {
              prchar(*st,curfont,wind.col+x,y);
              x += 2;
            }
          } else { /* if it's blank and normal attribute,use prblank to speed up */
            prblank(wind.col+x,y);
            x++;
          }
        }
        curfont = tempfont;
      }
      st++;
    }
    clrline(wind.col+x,y,wind.col+wind.length-1);
    if (line->wrap == NO) {
       prchar('<',0,wind.col + wind.length - 1,y);
    }
    if (*st != '\0') {
      prchar('+',0,wind.col + wind.length - 1,y);
    }
    y -= wind.row;
    /*
    if (graphbuff[y] != NULL)
      paintlinegraph(graphbuff[y],y);
    */
}
コード例 #5
0
ファイル: WRAP.C プロジェクト: MegaGod/TW
void reform( void ) {
	struct line_node *templine, *firstline, *freeline;
	unsigned char *temp1, *temp2, *temp3, *cuthere;
	unsigned int i, j;
	font_attr font = 0;
	char fontcode[9];

	storeline( curline );
	firstline = curline;
	templine = firstline;	/* start to concatenate all lines to one line only */
	temp1 = ( char * ) malloc( 1 );
	*temp1 = '\0';
	while ( 1 ) {
		temp2 = ( char * ) malloc( strlen( templine->text ) + 1 );
		i = 0;
		j = 0;
		while ( templine->text[i] != '\0' ) {
			if ( templine->text[i] != WRAPBLANK ) {
				temp2[j] = templine->text[i];
				j++;
			}
			i++;
		}
		temp2[j] = '\0';
		temp3 = ( char * ) malloc( strlen( temp1 ) + strlen( temp2 ) + 1 );
		strcpy( temp3, temp1 );
		strcat( temp3, temp2 );
		free( temp1 );
		free( temp2 );
		if ( templine->wrap == NO ) break;
		temp1 = temp3;
		templine = templine->next;
	}
	/* now paragraph is in the one line only pointed by temp3 */
	/* so we will compress two or more blanks to one blank only */
	compress_blank( temp3 );

	templine->previous = firstline->previous;
	( templine->previous )->next = templine;
	free( templine->text );
	templine->text = temp3;
	if ( curline == curpage ) {
		curpage = templine;
	}
	curline = templine;
	while ( firstline != templine ) {
		freeline = firstline;
		firstline = firstline->next;
		free( freeline->text );
		if ( freeline->graph != NULL ) {
			free( freeline->graph );
		}
		free( freeline );
	}
	while ( thaistrlen( curline->text ) > ( rightmar - leftmar + 1 ) ) {
		i = rightmar - leftmar;   /*   + 1;   */
		temp1 = curline->text;
		while ( ( i != 0 ) && ( *temp1 != '\0' ) ) {
			for ( temp1++; whatlevel( *temp1 ) != MIDDLE; temp1++ );
			i--;
		}
		temp3 = temp1;
		for ( i = 10; ( i != 0 ) && ( *temp3 != '\0' ); i-- ) {
			temp3++;
		}
		cuthere = FINDCUT( curline->text, temp3, temp1 );
		cuthere++;
		font = 0;
		for ( temp1 = curline->text; temp1 != cuthere; temp1++ ) {
			if ( *temp1 < 32 ) {
				togglefont( &font, *temp1 );
			}
		}
		findstrcode( fontcode, font );
		templine = ( struct line_node * ) malloc( sizeof( struct line_node ) );
		templine->text = ( char * ) malloc( strlen( fontcode ) + strlen( cuthere ) + 1 );
		templine->wrap = NO;
		templine->graph = NULL;
		strcpy( templine->text, fontcode );
		strcat( templine->text, cuthere );
		*cuthere = '\0';
		temp3 = ( char * ) malloc( leftmar + strlen( curline->text ) + strlen( fontcode ) );
		i = 0;
		while ( i != ( leftmar - 1 ) ) {
			temp3[i] = WRAPBLANK;
			i++;
		}
		temp3[i] = '\0';
		strcat( temp3, curline->text );
		strcat( temp3, fontcode );
		free( curline->text );
		curline->text = temp3;
		templine->next = curline->next;
		( curline->next )->previous = templine;
		templine->previous = curline;
		curline->next = templine;
		curline->wrap = YES;
		loadtoline( curline->text );
		justify_right( );
		storeline( curline );
		curline = curline->next;
	}
	temp3 = ( char * ) malloc( strlen( curline->text ) + leftmar );
	i = 0;
	while ( i != ( leftmar - 1 ) ) {
		temp3[i] = WRAPBLANK;
		i++;
	}
	temp3[i] = '\0';
	strcat( temp3, curline->text );
	free( curline->text );
	curline->text = temp3;
	if ( curline->next != sentinel ) {
		curline = curline->next;
	}
	lineno = findlineno( curline );
	loadtoline( curline->text );
	while ( findrow( ) > ( wind.width - 1 ) ) {
		curpage = curpage->next;
	}
	changeflag = YES;
	pagecomplete = NO;
	blkbegin.lineno = 1;
	blkend.lineno = 1;
	blkbegin.column = 0;
	blkend.column = 0;
}
コード例 #6
0
ファイル: WRAP.C プロジェクト: MegaGod/TW
void autowrap( unsigned int *x, unsigned int *y ) {
	unsigned int i, j, already = NO, diff;
	char *temp1, *temp3, *cuthere, fontcode[9];
	font_attr font = 0;
	struct line_node *templine;

	storeline( curline );
	diff = strlen( workline.middle ) - ( *x + firstcol + 1 );
	i = 0;
	j = 0;
	while ( curline->text[i] != '\0' ) {
		if ( curline->text[i] != WRAPBLANK ) {
			curline->text[j] = curline->text[i];
			j++;
			already = YES;
		} else {
			if ( already == NO ) {
				curline->text[j] = curline->text[i];
				j++;
			}
		}
		i++;
	}
	curline->text[j] = '\0';
	temp1 = curline->text;
	for ( i = rightmar - 2; ( i > 0 ) && ( *temp1 != '\0' ); i-- ) {
		temp1++;
		while ( whatlevel( *temp1 ) != MIDDLE ) {
			temp1++;
		}
	}
	temp3 = temp1;
	for ( i = 10; ( i != 0 ) && ( *temp3 != '\0' ); i-- ) {
		temp3++;
	}
	cuthere = FINDCUT( curline->text, temp3, temp1 );
	cuthere++;
	for ( temp1 = curline->text; temp1 != cuthere; temp1++ ) {
		if ( *temp1 < 32 ) {
			togglefont( &font, *temp1 );
		}
	}
	findstrcode( fontcode, font );
	templine = ( struct line_node * ) malloc( sizeof( struct line_node ) );
	templine->text = ( char * ) malloc( leftmar + strlen( fontcode ) + strlen( cuthere ) );
	for ( i = 0; i != ( leftmar - 1 ); i++ ) {
		templine->text[i] = WRAPBLANK;
	}
	templine->text[i] = '\0';
	strcat( templine->text, fontcode );
	strcat( templine->text, cuthere );
	templine->graph = NULL;
	templine->wrap = ( curline->next )->wrap;
	*cuthere = '\0';
	temp3 = ( char * ) malloc( strlen( curline->text ) + strlen( fontcode ) + 1 );
	strcpy( temp3, curline->text );
	strcat( temp3, fontcode );
	free( curline->text );
	curline->text = temp3;
	templine->next = curline->next;
	( curline->next )->previous = templine;
	templine->previous = curline;
	curline->next = templine;
	curline->wrap = YES;
	loadtoline( curline->text );
	justify_right( );
	*y = findrow( );
	cursor_down( *y );
	firstcol = 0;
	gocol( strlen( workline.middle ) - 1 - diff, x );
	pagecomplete = NO;
}