⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 command.c

📁 tvapp用于播放tv程序
💻 C
📖 第 1 页 / 共 2 页
字号:
				goto repeat;			default:				(void) myungetch(c);				atfield();				(void) clrtoeol();	/* clear current field */				break;			}		}		return(NO);	case '\\':	/* next character is not a command */		(void) addch('\\');	/* display the quote character */		/* get a character from the terminal */		if ((commandc = mygetch()) == EOF) {			return(NO);	/* quit */		}		(void) addstr("\b \b");	/* erase the quote character */		goto ispat;	case '.':		postmsg("The . command has been replaced by ^Y");		atfield();	/* move back to the input field */		/* FALLTHROUGH */	default:		if (selecting && !mouse)		{			char		*c;			if ((c = strchr(dispchars, commandc)))				editref(c - dispchars);		}		/* if this is the start of a pattern */		else if (isprint(commandc)) {	ispat:		if (getline(newpat, COLS - fldcolumn - 1, commandc,			    caseless) > 0) {					(void) strcpy(pattern, newpat);					resetcmd();	/* reset command history */	repeat:				addcmd(field, pattern);	/* add to command history */				if (field == CHANGE) {										/* prompt for the new text */					(void) move(PRLINE, 0);					(void) addstr(toprompt);					(void) getline(newpat, COLS - sizeof(toprompt), '\0', NO);				}				/* search for the pattern */				if (search() == YES) {					curdispline = 0;					++selecting;					switch (field) {					case DEFINITION:					case FILENAME:						if (totallines > 1) {							break;						}						topline = 1;						editref(0);						break;					case CHANGE:						return(changestring());					}				}				/* try to edit the file anyway */				else if (field == FILENAME && 				    access(newpat, READ) == 0) {					edit(newpat, "1");				}			}			else {	/* no pattern--the input was erased */				return(NO);			}		}		else {	/* control character */			return(NO);		}	}	return(YES);}/* clear the prompt line */static voidclearprompt(void){	(void) move(PRLINE, 0);	(void) clrtoeol();}/* read references from a file */BOOLreadrefs(char *filename){	FILE	*file;	int	c;	if ((file = myfopen(filename, "rb")) == NULL) {		cannotopen(filename);		return(NO);	}	if ((c = getc(file)) == EOF) {	/* if file is empty */		return(NO);	}	totallines = 0;	disprefs = 0;	nextline = 1;	if (writerefsfound() == YES) {		(void) putc(c, refsfound);		while ((c = getc(file)) != EOF) {			(void) putc(c, refsfound);		}		(void) fclose(file);		(void) fclose(refsfound);		if ( (refsfound = myfopen(temp1, "rb")) == NULL) {			cannotopen(temp1);			return(NO);		}		countrefs();	}	return(YES);}/* change one text string to another */static BOOLchangestring(void){	char	newfile[PATHLEN + 1];	/* new file name */	char	oldfile[PATHLEN + 1];	/* old file name */	char	linenum[NUMLEN + 1];	/* file line number */	char	msg[MSGLEN + 1];	/* message */	FILE	*script;		/* shell script file */	BOOL	anymarked = NO;		/* any line marked */	MOUSE *p;			/* mouse data */	int	c, i;	char	*s;	/* open the temporary file */	if ((script = myfopen(temp2, "w")) == NULL) {		cannotopen(temp2);		return(NO);	}	/* create the line change indicators */	change = mycalloc((unsigned) totallines, sizeof(BOOL));	changing = YES;	mousemenu();	/* until the quit command is entered */	for (;;) {		/* display the current page of lines */		display();	same:		atchange();				/* get a character from the terminal */		if ((c = mygetch()) == EOF || c == ctrl('D') || c == ctrl('Z')) {			break;	/* change lines */		}		/* see if the input character is a command */		switch (c) {		case ' ':	/* display next page */		case '+':		case ctrl('V'):#if TERMINFO		case KEY_NPAGE:#endif		case '-':	/* display previous page */#if TERMINFO		case KEY_PPAGE:#endif		case '!':	/* shell escape */		case '?':	/* help */			(void) command(c);			break;		case ctrl('L'):	/* redraw screen */#if TERMINFO		case KEY_CLEAR:#endif			(void) command(c);			goto same;		case ESC:	/* don't change lines */#if UNIXPC			if((p = getmouseaction(DUMMYCHAR)) == NULL) {				goto nochange;	/* unknown escape sequence */			}			break;#endif		case ctrl('G'):			goto nochange;		case '*':	/* mark/unmark all displayed lines */			for (i = 0; topline + i < nextline; ++i) {				mark(i);			}			goto same;		case ctrl('A'):	/* mark/unmark all lines */			for (i = 0; i < totallines; ++i) {				if (change[i] == NO) {					change[i] = YES;				}				else {					change[i] = NO;				}			}			/* show that all have been marked */			seekline(totallines);			break;		case ctrl('X'):	/* mouse selection */			if ((p = getmouseaction(DUMMYCHAR)) == NULL) {				goto same;	/* unknown control sequence */			}			/* if the button number is a scrollbar tag */			if (p->button == '0') {				scrollbar(p);				break;			}			/* find the selected line */			/* note: the selection is forced into range */			for (i = disprefs - 1; i > 0; --i) {				if (p->y1 >= displine[i]) {					break;				}			}			mark(i);			goto same;		default:		{			/* if a line was selected */			char		*cc;			if ((cc = strchr(dispchars, c)))				mark(cc - dispchars);			goto same;		}		}	}	/* for each line containing the old text */	(void) fprintf(script, "ed - <<\\!\n");	*oldfile = '\0';	seekline(1);	for (i = 0; fscanf(refsfound, "%s%*s%s%*[^\n]", newfile, linenum) == 2;	    ++i) {		/* see if the line is to be changed */		if (change[i] == YES) {			anymarked = YES;					/* if this is a new file */			if (strcmp(newfile, oldfile) != 0) {								/* make sure it can be changed */				if (access(newfile, WRITE) != 0) {					(void) sprintf(msg, "Cannot write to file %s", newfile);					postmsg(msg);					anymarked = NO;					break;				}				/* if there was an old file */				if (*oldfile != '\0') {					(void) fprintf(script, "w\n");	/* save it */				}				/* edit the new file */				(void) strcpy(oldfile, newfile);				(void) fprintf(script, "e %s\n", oldfile);			}			/* output substitute command */			(void) fprintf(script, "%ss/", linenum);	/* change */			for (s = pattern; *s != '\0'; ++s) {	/* old text */				if (strchr("/\\[.^*", *s) != NULL) {					(void) putc('\\', script);				}				if (caseless == YES && isalpha((unsigned char)*s)) {					(void) putc('[', script);					if(islower((unsigned char)*s)) {						(void) putc(toupper((unsigned char)*s), script);						(void) putc(*s, script);					}					else {						(void) putc(*s, script);						(void) putc(tolower((unsigned char)*s), script);					}					(void) putc(']', script);				}				else						(void) putc(*s, script);			}			(void) putc('/', script);			/* to */ 			for (s = newpat; *s != '\0'; ++s) {	/* new text */				if (strchr("/\\&", *s) != NULL) {					(void) putc('\\', script);				}				(void) putc(*s, script);			}			(void) fprintf(script, "/gp\n");	/* and print */		}	}	(void) fprintf(script, "w\nq\n!\n");	/* write and quit */	(void) fclose(script);	/* if any line was marked */	if (anymarked == YES) {				/* edit the files */		clearprompt();		(void) refresh();		(void) fprintf(stderr, "Changed lines:\n\r");		(void) execute("sh", "sh", temp2, NULL);		askforreturn();		seekline(1);	}	else {nochange:		clearprompt();	}	changing = NO;	mousemenu();	free(change);	return(anymarked);}/* mark/unmark this displayed line to be changed */static voidmark(int i){	int	j;		j = i + topline - 1;	if (j < totallines) {		(void) move(displine[i], 1);		if (change[j] == NO) {			change[j] = YES;			(void) addch('>');		}		else {			change[j] = NO;			(void) addch(' ');		}	}}/* scrollbar actions */static voidscrollbar(MOUSE *p){	/* reposition list if it makes sense */	if (totallines == 0) {		return;	}	switch (p->percent) {			case 101: /* scroll down one page */		if (nextline + mdisprefs > totallines) {			nextline = totallines - mdisprefs + 1;		}		break;			case 102: /* scroll up one page */		nextline = topline - mdisprefs;		if (nextline < 1) {			nextline = 1;		}		break;	case 103: /* scroll down one line */		nextline = topline + 1;		break;			case 104: /* scroll up one line */		if (topline > 1) {			nextline = topline - 1;		}		break;	default:		nextline = p->percent * totallines / 100;	}	seekline(nextline);}/* count the references found */static voidcountrefs(void){	char	*subsystem;		/* OGS subsystem name */	char 	*book;			/* OGS book name */	char	file[PATHLEN + 1];	/* file name */	char	function[PATLEN + 1];	/* function name */	char	linenum[NUMLEN + 1];	/* line number */	int	i;	/* count the references found and find the length of the file,	   function, and line number display fields */	subsystemlen = 9;	/* strlen("Subsystem") */	booklen = 4;		/* strlen("Book") */	filelen = 4;		/* strlen("File") */	fcnlen = 8;		/* strlen("Function") */	numlen = 0;	while ((i = fscanf(refsfound, "%250s%250s%6s %5000[^\n]", file,	    function, linenum, tempstring)) != EOF) {		if (i != 4 ||		    !isgraph((unsigned char)*file) ||		    !isgraph((unsigned char)*function) ||		    !isdigit((unsigned char)*linenum)) {			postmsg("File does not have expected format");			totallines = 0;			disprefs = 0;			return;		}		if ((i = strlen(pathcomponents(file, dispcomponents))) > filelen) {			filelen = i;		}		if (ogs == YES) {			ogsnames(file, &subsystem, &book);			if ((i = strlen(subsystem)) > subsystemlen) {				subsystemlen = i;			}			if ((i = strlen(book)) > booklen) {				booklen = i;			}		}		if ((i = strlen(function)) > fcnlen) {			fcnlen = i;		}		if ((i = strlen(linenum)) > numlen) {			numlen = i;		}		++totallines;	}	rewind(refsfound);	/* restrict the width of displayed columns */	i = (COLS - 5) / 3;	if (ogs == YES) {		i = (COLS - 7) / 5;	}	if (filelen > i && i > 4) {		filelen = i;	}	if (subsystemlen > i && i > 9) {		subsystemlen = i;	}	if (booklen > i && i > 4) {		booklen = i;	}	if (fcnlen > i && i > 8) {		fcnlen = i;	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -