Ejemplo n.º 1
0
Archivo: te.c Proyecto: thigley/THOS
int te(int argc, char *argv[]){ 
	if(argc!=2){ 
		printToConsole("Error: Wrong number of arguments!\n");
		return 1;
	}
	int saveoff = typeOffset;

	// save console
	int i;
	for(i = 0; i<VGA_W*VGA_H*2; i++){
		console_save[i]=vidptr[i];
	}
	
	// find file
	int filenum = getfilenum(argv[1]);

	// allow for editing
	setupte(filenum);
	editfile(argv[1]);

	// replace console
	for(i = 0; i<VGA_W*VGA_H*2; i++){
		vidptr[i]=console_save[i];
	}
	typeOffset = saveoff;
	return 0;
}
Ejemplo n.º 2
0
int main( int argc, char **argv ){
   struct options options;
   list_ref list = NULL;
   bzero( &options, sizeof options );
   set_progname( argv[0] );
   progname = argv[0];
   scanoptions( &options, argc, argv );
   list = new_list();
   readFiles(list, &options);
   editfile( &options, list );
   free_list( list ); list = NULL;
   return get_exitcode();
}
Ejemplo n.º 3
0
int main (int argc, char **argv) {
   Exec_Name = basename (argv[0]);
   if (argc != 2) usage_exit();
   want_echo = ! (isatty (fileno (stdin)) && isatty (fileno (stdout)));
   list_ref list = new_list();
   putfileinlist (list, argv[1]);
   editfile (list, argv[1]);
   set_curr_head(list);
   while (!empty_list(list)){
      delete_list(list, "");
   }
   free_list (list); list = NULL;
   return Exit_Status;
}
Ejemplo n.º 4
0
int main (int argc, char **argv) {
    Exec_Name = basename (argv[0]);
    if (argc != 2) usage_exit();
    want_echo = ! (isatty (fileno (stdin)) && isatty (fileno (stdout)));
    list_ref list = new_list();
    if(argc ==2) {
        for (int argi = 1; argi < argc; ++argi) {
            putfilelist (list, argv[argi], 1);
        }
        editfile (list);
        free_list (list);
        list = NULL;
    }
    return Exit_Status;
}
Ejemplo n.º 5
0
/* local */
void editfnam (register char *name) {
register d;
register char *p;
char buf [80];
struct stat st;

	if (stat (name, &st) >= 0) {
		if ((st.st_mode & S_IFMT) != S_IFREG) {
			error ("Cannot edit special files");
			return;
		}
	} else {
		d = creat (name, 0644);
		if (d < 0) {
			error ("Cannot create %s", name);
			return;
		}
		close (d);
	}
	if (useredit) {
		strcpy (buf, editname);
		strcat (buf, " ");
		strcat (buf, name);
		VRestore ();
		syscmd (buf);
		VReopen ();
		VRedraw ();
		setdir (cur == left ? right : left, NULL);
		setdir (cur, NULL);
		return;
	}
	if ((d = open (name, 2)) < 0) {
		error ("Cannot open %s for writing", name);
		return;
	}
	/* skip directory name */
	for (p=name; *p; ++p);
	for (; p>=name && *p!='/'; --p);
	EDITFILE editfile(d, name, p+1);
	close (d);
}
Ejemplo n.º 6
0
/*
 * Main command processor.
 * Accept and execute commands until a quit command, then return.
 */
void
commands(void)
{
	int c, action;

	last_mca = 0;
	nscroll = (sc_height + 1) / 2;

	for (;;) {
		mca = 0;
		number = 0;

		/*
		 * See if any signals need processing.
		 */
		if (sigs) {
			psignals();
			if (quitting)
				quit();
		}
		/*
		 * Display prompt and accept a character.
		 */
		CMD_RESET;
		if (!prompt()) {
			next_file(1);
			continue;
		}
		noprefix();
		c = getcc();

again:		if (sigs)
			continue;

		/*
		 * If we are in a multicharacter command, call mca_char.
		 * Otherwise we call cmd_decode to determine the
		 * action to be performed.
		 */
		if (mca)
			switch (mca_char(c)) {
			case MCA_MORE:
				/*
				 * Need another character.
				 */
				c = getcc();
				goto again;
			case MCA_DONE:
				/*
				 * Command has been handled by mca_char.
				 * Start clean with a prompt.
				 */
				continue;
			case NO_MCA:
				/*
				 * Not a multi-char command
				 * (at least, not anymore).
				 */
				break;
			}

		/* decode the command character and decide what to do. */
		switch (action = cmd_decode(c)) {
		case A_DIGIT:		/* first digit of a number */
			start_mca(A_DIGIT, ":");
			goto again;
		case A_F_SCREEN:	/* forward one screen */
			CMD_EXEC;
			if (number <= 0 && (number = sc_window) <= 0)
				number = sc_height - 1;
			forward(number, 1);
			break;
		case A_B_SCREEN:	/* backward one screen */
			CMD_EXEC;
			if (number <= 0 && (number = sc_window) <= 0)
				number = sc_height - 1;
			backward(number, 1);
			break;
		case A_F_LINE:		/* forward N (default 1) line */
			CMD_EXEC;
			forward(number <= 0 ? 1 : number, 0);
			break;
		case A_B_LINE:		/* backward N (default 1) line */
			CMD_EXEC;
			backward(number <= 0 ? 1 : number, 0);
			break;
		case A_F_SCROLL:	/* forward N lines */
			CMD_EXEC;
			if (number > 0)
				nscroll = number;
			forward(nscroll, 0);
			break;
		case A_B_SCROLL:	/* backward N lines */
			CMD_EXEC;
			if (number > 0)
				nscroll = number;
			backward(nscroll, 0);
			break;
		case A_FREPAINT:	/* flush buffers and repaint */
			if (!ispipe) {
				ch_init(0, 0);
				clr_linenum();
			}
			/* FALLTHROUGH */
		case A_REPAINT:		/* repaint the screen */
			CMD_EXEC;
			repaint();
			break;
		case A_GOLINE:		/* go to line N, default 1 */
			CMD_EXEC;
			if (number <= 0)
				number = 1;
			jump_back(number);
			break;
		case A_PERCENT:		/* go to percent of file */
			CMD_EXEC;
			if (number < 0)
				number = 0;
			else if (number > 100)
				number = 100;
			jump_percent(number);
			break;
		case A_GOEND:		/* go to line N, default end */
			CMD_EXEC;
			if (number <= 0)
				jump_forw();
			else
				jump_back(number);
			break;
		case A_STAT:		/* print file name, etc. */
			longprompt = 1;
			continue;
		case A_QUIT:		/* exit */
			quit();
		case A_F_SEARCH:	/* search for a pattern */
		case A_B_SEARCH:
			if (number <= 0)
				number = 1;
			start_mca(action, (action==A_F_SEARCH) ? "/" : "?");
			last_mca = mca;
			wsearch = 1;
			c = getcc();
			if (c == '!') {
				/*
				 * Invert the sense of the search; set wsearch
				 * to 0 and get a new character for the start
				 * of the pattern.
				 */
				start_mca(action, 
				    (action == A_F_SEARCH) ? "!/" : "!?");
				wsearch = 0;
				c = getcc();
			}
			goto again;
		case A_AGAIN_SEARCH:		/* repeat previous search */
			if (number <= 0)
				number = 1;
			if (wsearch)
				start_mca(last_mca, 
				    (last_mca == A_F_SEARCH) ? "/" : "?");
			else
				start_mca(last_mca, 
				    (last_mca == A_F_SEARCH) ? "!/" : "!?");
			CMD_EXEC;
			(void)search(mca == A_F_SEARCH, (char *)NULL,
			    number, wsearch);
			break;
		case A_HELP:			/* help */
			lower_left();
			clear_eol();
			fputs("help", stdout);
			CMD_EXEC;
			help();
			break;
		case A_TAGFILE:			/* tag a new file */
			CMD_RESET;
			start_mca(A_TAGFILE, "Tag: ");
			c = getcc();
			goto again;
		case A_FILE_LIST:		/* show list of file names */
			CMD_EXEC;
			showlist();
			repaint();
			break;
		case A_EXAMINE:			/* edit a new file */
			CMD_RESET;
			start_mca(A_EXAMINE, "Examine: ");
			c = getcc();
			goto again;
		case A_VISUAL:			/* invoke the editor */
			if (ispipe) {
				error("Cannot edit standard input");
				break;
			}
			CMD_EXEC;
			editfile();
			ch_init(0, 0);
			clr_linenum();
			break;
		case A_NEXT_FILE:		/* examine next file */
			if (number <= 0)
				number = 1;
			next_file(number);
			break;
		case A_PREV_FILE:		/* examine previous file */
			if (number <= 0)
				number = 1;
			prev_file(number);
			break;
		case A_SETMARK:			/* set a mark */
			lower_left();
			clear_eol();
			start_mca(A_SETMARK, "mark: ");
			c = getcc();
			if (c == erase_char || c == kill_char)
				break;
			setmark(c);
			break;
		case A_GOMARK:			/* go to mark */
			lower_left();
			clear_eol();
			start_mca(A_GOMARK, "goto mark: ");
			c = getcc();
			if (c == erase_char || c == kill_char)
				break;
			gomark(c);
			break;
		case A_PREFIX:
			/*
			 * The command is incomplete (more chars are needed).
			 * Display the current char so the user knows what's
			 * going on and get another character.
			 */
			if (mca != A_PREFIX)
				start_mca(A_PREFIX, "");
			if (CONTROL_CHAR(c)) {
				putchar('^');
				c = CARAT_CHAR(c);
			}
			putchar(c);
			c = getcc();
			goto again;
		default:
			putchar('\7');
			break;
		}
	}
}
Ejemplo n.º 7
0
int sbbs_t::text_sec()
{
	char	str[256],usemenu
			,*file[MAX_TXTFILES],addpath[83],addstr[83],*buf,ch;
	char 	tmp[512];
	long	i,j,usrsec[MAX_TXTSECS],usrsecs,cursec;
    long    l,length;
    FILE    *stream;

	for(i=j=0;i<cfg.total_txtsecs;i++) {
		if(!chk_ar(cfg.txtsec[i]->ar,&useron,&client))
			continue;
		usrsec[j++]=i; 
	}
	usrsecs=j;
	if(!usrsecs) {
		bputs(text[NoTextSections]);
		return(1); 
	}
	action=NODE_RTXT;
	while(online) {
		sprintf(str,"%smenu/text_sec.*",cfg.text_dir);
		if(fexist(str))
			menu("text_sec");
		else {
			bputs(text[TextSectionLstHdr]);
			for(i=0;i<usrsecs && !msgabort();i++) {
				sprintf(str,text[TextSectionLstFmt],i+1,cfg.txtsec[usrsec[i]]->name);
				if(i<9) outchar(' ');
				bputs(str); 
			}
		}
		ASYNC;
		mnemonics(text[WhichTextSection]);
		if((cursec=getnum(usrsecs))<1)
			break;
		cursec--;
		while(online) {
			sprintf(str,"%smenu/text%lu.*",cfg.text_dir,cursec+1);
			if(fexist(str)) {
				sprintf(str,"text%lu",cursec+1);
				menu(str);
				usemenu=1; 
			}
			else {
				bprintf(text[TextFilesLstHdr],cfg.txtsec[usrsec[cursec]]->name);
				usemenu=0; 
			}
			sprintf(str,"%stext/%s.ixt",cfg.data_dir,cfg.txtsec[usrsec[cursec]]->code);
			j=0;
			if(fexist(str)) {
				if((stream=fnopen((int *)&i,str,O_RDONLY))==NULL) {
					errormsg(WHERE,ERR_OPEN,str,O_RDONLY);
					return(0); 
				}
				while(!ferror(stream) && !msgabort()) {  /* file open too long */
					if(!fgets(str,81,stream))
						break;
					str[strlen(str)-2]=0;   /* chop off CRLF */
					if((file[j]=(char *)malloc(strlen(str)+1))==NULL) {
						errormsg(WHERE,ERR_ALLOC,nulstr,strlen(str)+1);
						continue; 
					}
					strcpy(file[j],str);
					fgets(str,81,stream);
					if(!usemenu) bprintf(text[TextFilesLstFmt],j+1,str);
					j++; 
				}
				fclose(stream); 
			}
			ASYNC;
			if(SYSOP) {
				strcpy(str,"QARE?");
				mnemonics(text[WhichTextFileSysop]); 
			}
			else {
				strcpy(str,"Q?");
				mnemonics(text[WhichTextFile]); 
			}
			i=getkeys(str,j);
			if(!(i&0x80000000L)) {		  /* no file number */
				for(l=0;l<j;l++)
					free(file[l]);
				if((i=='E' || i=='R') && !j)
					continue; 
			}
			if(i=='Q' || !i)
				break;
			if(i==-1) {  /* ctrl-c */
				for(i=0;i<j;i++)
					free(file[i]);
				return(0); 
			}
			if(i=='?')  /* ? means re-list */
				continue;
			if(i=='A') {    /* Add text file */
				if(j) {
					bputs(text[AddTextFileBeforeWhich]);
					i=getnum(j+1);
					if(i<1)
						continue;
					i--;    /* number of file entries to skip */ }
				else
					i=0;
				bprintf(text[AddTextFilePath]
					,cfg.data_dir,cfg.txtsec[usrsec[cursec]]->code);
				if(!getstr(addpath,80,0))
					continue;
				strcat(addpath,crlf);
				bputs(text[AddTextFileDesc]);
				if(!getstr(addstr,74,0))
					continue;
				strcat(addstr,crlf);
				sprintf(str,"%stext/%s.ixt"
					,cfg.data_dir,cfg.txtsec[usrsec[cursec]]->code);
				if(i==j) {  /* just add to end */
					if((i=nopen(str,O_WRONLY|O_APPEND|O_CREAT))==-1) {
						errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_APPEND|O_CREAT);
						return(0); 
					}
					write(i,addpath,strlen(addpath));
					write(i,addstr,strlen(addstr));
					close(i);
					continue; 
				}
				j=i; /* inserting in middle of file */
				if((stream=fnopen((int *)&i,str,O_RDWR))==NULL) {
					errormsg(WHERE,ERR_OPEN,str,O_RDWR);
					return(0); 
				}
				length=(long)filelength(i);
				for(i=0;i<j;i++) {  /* skip two lines for each entry */
					fgets(tmp,81,stream);
					fgets(tmp,81,stream); 
				}
				l=(long)ftell(stream);
				if((buf=(char *)malloc(length-l))==NULL) {
					fclose(stream);
					errormsg(WHERE,ERR_ALLOC,str,length-l);
					return(0); 
				}
				fread(buf,1,length-l,stream);
				fseek(stream,l,SEEK_SET); /* go back to where we need to insert */
				fputs(addpath,stream);
				fputs(addstr,stream);
				fwrite(buf,1,length-l,stream);
				fclose(stream);
				free(buf);
				continue; 
			}
			if(i=='R' || i=='E') {   /* Remove or Edit text file */
				ch=(char)i;
				if(ch=='R')
					bputs(text[RemoveWhichTextFile]);
				else
					bputs(text[EditWhichTextFile]);
				i=getnum(j);
				if(i<1)
					continue;
				sprintf(str,"%stext/%s.ixt"
					,cfg.data_dir,cfg.txtsec[usrsec[cursec]]->code);
				j=i-1;
				if((stream=fnopen(NULL,str,O_RDONLY))==NULL) {
					errormsg(WHERE,ERR_OPEN,str,O_RDONLY);
					return(0); 
				}
				for(i=0;i<j;i++) {  /* skip two lines for each entry */
					fgets(tmp,81,stream);
					fgets(tmp,81,stream); 
				}
				fgets(addpath,81,stream);
				truncsp(addpath);
				fclose(stream);
				if(!strchr(addpath,'\\') && !strchr(addpath,'/'))
					sprintf(tmp,"%stext/%s/%s"
						,cfg.data_dir,cfg.txtsec[usrsec[cursec]]->code,addpath);
				else
					strcpy(tmp,addpath);
				if(ch=='R') {               /* Remove */
					if(fexist(tmp)) {
						sprintf(str,text[DeleteTextFileQ],tmp);
						if(!noyes(str))
							if(remove(tmp)) errormsg(WHERE,ERR_REMOVE,tmp,0); 
					}
					sprintf(str,"%stext/%s.ixt"
						,cfg.data_dir,cfg.txtsec[usrsec[cursec]]->code);
					removeline(str,addpath,2,0); 
				}
				else {                      /* Edit */
					strcpy(str,tmp);
					editfile(str); 
				}
				continue; 
			}
			i=(i&~0x80000000L)-1;
			if(!strchr(file[i],'\\') && !strchr(file[i],'/'))
				sprintf(str,"%stext/%s/%s"
					,cfg.data_dir,cfg.txtsec[usrsec[cursec]]->code,file[i]);
			else
				strcpy(str,file[i]);
			fexistcase(str);
			attr(LIGHTGRAY);
			printfile(str,0);
			sprintf(str,"%s read text file: %s"
				,useron.alias,file[i]);
			logline("T-",str);
			pause();
			sys_status&=~SS_ABORT;
			for(i=0;i<j;i++)
				free(file[i]); 
		} 
	}
	return(0);
}
Ejemplo n.º 8
0
int
main(void)
{
	int fd;
	FILE *ft, *fp;
	char *editor;
	int ok = 0;
	time_t o_mtime, n_mtime;
	struct stat osbuf, sbuf, oshdbuf, shdbuf;
	char c;

	(void)signal(SIGINT, SIG_IGN);
	(void)signal(SIGQUIT, SIG_IGN);
	(void)signal(SIGHUP, SIG_IGN);
	setbuf(stderr, (char *)NULL);

	editor = getenv("VISUAL");
	if (editor == 0)
		editor = getenv("EDITOR");
	if (editor == 0)
		editor = DEFAULT_EDITOR;

	(void)umask(0077);
	if (stat(passwd, &osbuf) < 0) {
                (void)fprintf(stderr,"vipw: can't stat passwd file.\n");
                goto bad;
        } 

	if (copyfile(passwd, ptemp))
		goto bad;

	if (stat(ptemp, &sbuf) < 0) {
                (void)fprintf(stderr,
			"vipw: can't stat ptemp file, %s unchanged\n",
			passwd);
		goto bad;
	}

	o_mtime = sbuf.st_mtime;

	if (editfile(editor, ptemp, passwd, &n_mtime)) {
		if (sanity_check(ptemp, &n_mtime, passwd))
			goto bad;
		if (o_mtime >= n_mtime)
			goto bad;
	}

	ok++;
	if (o_mtime < n_mtime) {
		fprintf(stdout, "\nYou have modified the password file.\n");
		fprintf(stdout,
	"Press 'e' to edit the shadow file for consistency,\n 'q' to quit: ");
		if ((c = getchar()) == 'q') {
			if (chmod(ptemp, (osbuf.st_mode & 0644)) < 0) {
				(void) fprintf(stderr, "vipw: %s: ", ptemp);
				perror("chmod");
				goto bad;
			}
			if (rename(ptemp, passwd) < 0) {
				(void) fprintf(stderr, "vipw: %s: ", ptemp);
				perror("rename");
				goto bad;
			}
			if (((osbuf.st_gid != sbuf.st_gid) ||
					(osbuf.st_uid != sbuf.st_uid)) &&
			(chown(passwd, osbuf.st_uid, osbuf.st_gid) < 0)) {
				(void) fprintf(stderr, "vipw: %s ", ptemp);
				perror("chown");
			}
			goto bad;
		} else if (c == 'e') {
			if (stat(shadow, &oshdbuf) < 0) {
				(void) fprintf(stderr,
					"vipw: can't stat shadow file.\n");
				goto bad;
			}

			if (copyfile(shadow, stemp))
				goto bad;
			if (stat(stemp, &shdbuf) < 0) {
				(void) fprintf(stderr,
					"vipw: can't stat stmp file.\n");
				goto bad;
			}

			if (editfile(editor, stemp, shadow, &o_mtime))
				goto bad;
			ok++;
			if (chmod(ptemp, (osbuf.st_mode & 0644)) < 0) {
				(void) fprintf(stderr, "vipw: %s: ", ptemp);
				perror("chmod");
				goto bad;
			}
			if (chmod(stemp, (oshdbuf.st_mode & 0400)) < 0) {
				(void) fprintf(stderr, "vipw: %s: ", stemp);
				perror("chmod");
				goto bad;
			}
			if (rename(ptemp, passwd) < 0) {
				(void) fprintf(stderr, "vipw: %s: ", ptemp);
				perror("rename");
				goto bad;
			}
			if (((osbuf.st_gid != sbuf.st_gid) ||
					(osbuf.st_uid != sbuf.st_uid)) &&
			(chown(passwd, osbuf.st_uid, osbuf.st_gid) < 0)) {
				(void) fprintf(stderr, "vipw: %s ", ptemp);
				perror("chown");
			}
			if (rename(stemp, shadow) < 0) {
				(void) fprintf(stderr, "vipw: %s: ", stemp);
				perror("rename");
				goto bad;
			} else if (((oshdbuf.st_gid != shdbuf.st_gid) ||
					(oshdbuf.st_uid != shdbuf.st_uid)) &&
			(chown(shadow, oshdbuf.st_uid, oshdbuf.st_gid) < 0)) {
				(void) fprintf(stderr, "vipw: %s ", stemp);
				perror("chown");
				}
		}
	}
bad:
	(void) unlink(ptemp);
	(void) unlink(stemp);
	return (ok ? 0 : 1);
	/* NOTREACHED */
}
Ejemplo n.º 9
0
/*
 * mainloop() -
 * основной цикл работы редактора
 */
mainloop()
{
    int i,m,first=1;
    register int j;
    int clsave,ccsave;
    int k;
    /* Хитрости с экономией памяти */
    register int *lre1= &lread1;
#define lread1 (*lre1)
    int thiscol, thisrow;
    char ich[8], *cp;
    /* Для команд с тремя вариантами аргументов */
    int (*lnfun)(),(*spfun)();
    int openlines(), openspaces(), closelines(),closespaces(),picklines(),
    pickspaces();
    /* === */
    extern int templ[4];
    struct viewport *oport;
    /*
     * Обработка одного символа или команды
     * ====================================
     */
    if (cursorline== 0) oldcline = 1;
    if (cursorcol == 0) oldccol  = 1;
#ifndef lint
    goto funcdone;
#endif
    FOREVER
        {
        csrsw = clrsw = 0;
        read1();
        if (errsw)
        {
            errsw = 0;
            clrsw = 1;
            goto errclear;
        }
        /*
         * Редактирование в строке
         */
        if ((! CTRLCHAR) || lread1 == CCCTRLQUOTE || lread1 == CCBACKSPACE || lread1 == CCDELCH)
        {
            /* Отмена в 1 колонке */
            if (lread1 == CCBACKSPACE  &&  cursorcol == 0)
            {
                lread1 = -1;
                goto contin;
            }
            if (openwrite[curfile] == 0) goto nowriterr;
            /* Строки у нас нет? Дай! */
            if (clineno != (i = curwksp->ulhclno+cursorline))
                getlin(i);
            /* исключение символа */
            if (lread1==CCDELCH || (imodesw && lread1==CCBACKSPACE) )
            {
                thiscol = cursorcol + curwksp->ulhccno;
                thisrow = cursorline;
                if (lread1 == CCBACKSPACE) thiscol--;
                if (ncline < thiscol + 2)
                {
                    if (lread1 == CCBACKSPACE) movecursor(LT);
                    lread1 = -1;
                    goto contin;
                }
                for (i=thiscol;i<ncline-2;i++) cline[i] = cline[i+1];
                ncline--;
                thiscol -= curwksp->ulhccno;
                putup(-(1+thiscol),cursorline);
                poscursor(thiscol,thisrow);
                fcline = 1;
                lread1 = -1;
                goto contin;
            }
            /* Проверка на границу окна */
            if (cursorcol > curport->rtext)
            {
                if (fcline) {
                    putline(0);
                    movep(defrport);
                    goto contin;
                }
                else  goto margerr;
            }
            fcline = 1;
            if (j = (lread1 == CCBACKSPACE))
            {
                movecursor(LT);
                lread1 = ' ';
            }
            if ((i = cursorcol + curwksp->ulhccno) >=
                (lcline - 2)) excline(i+2);
            if (i >= ncline-1)
            {
                for (k=ncline-1; k<=i; k++) cline[k] = ' ';
                cline[i+1] = NEWLINE;
                ncline = i+2;
            }
            else if (imodesw)
            {
                thiscol = cursorcol + curwksp->ulhccno;
                thisrow = cursorline;
                if (ncline >= lcline) excline(ncline+1);
                for (i=ncline;i>thiscol;i--) cline[i] = cline[i-1];
                ncline++;
                thiscol -= curwksp->ulhccno;
                putup(-(1+thiscol),cursorline);
                poscursor(thiscol,thisrow);
            }
            /* Выставим границу */
            if (cursorcol >= curport->rtext)
                curport->redit = curport->rtext + 1;
            /* Замена символа */
            if(lread1==CCCTRLQUOTE) lread1 = esc0;
            if (cursorcol == curport->rtext - 10) putcha(COBELL);
            cline[i] = lread1;
            putch(lread1,1);
            /* Если переехали границу */
            curport->redit = curport->rtext;
            if (j) movecursor(LT);
            lread1 = -1;
            goto contin;
        }
        /* Сдвиг вниз, если последняя строка  */
        if (lread1 == CCRETURN )
        {
            putline(0);
            if ( cursorline == curport->btext)
                movew(defplline);
            if((i=curwksp->ulhccno) !=0) movep(-i);
            movecursor(lread1);
            lread1= -1;
            goto errclear;
        }
        /*
         * Если команда перемещения
         */
        if (lread1<=BT) {
            movecursor(lread1);
            if (lread1 <= VMOTCODE ) {
                putline(0);
                if(curspos) goto newnumber;
            }
            lread1 = -1;
            goto contin;
        }
        /* Если граница поля */
        if (cursorcol > curport->rtext) poscursor(curport->rtext,cursorline);
        putline(0);
        if (lread1 == CCQUIT)
        {
            if (endit() == 0) goto funcdone;
            gosw = 0;
            return;
        }
        switch (lread1)
        {
        case CCENTER:
            goto gotarg;
        case CCLPORT:
            movep(- deflport);
            goto funcdone;
        case CCSETFILE:
            switchfile();
            goto funcdone;
        case CCCHPORT:
            chgport(-1);
            goto funcdone;
        case CCOPEN:
            if (openwrite[curfile]==0)  goto nowriterr;
            openlines(curwksp->ulhclno + cursorline,definsert);
            goto funcdone;
        case CCMISRCH:
            search(-1);
            goto funcdone;
        case CCCLOSE:
            if (openwrite[curfile]==0)
                goto nowriterr;
            closelines(curwksp->ulhclno + cursorline, defdelete);
            goto funcdone;
        case CCPUT:
            if (openwrite[curfile]==0)
                goto nowriterr;
            if (pickbuf->nrows == 0) goto nopickerr;
            put(pickbuf,curwksp->ulhclno+cursorline,
            curwksp->ulhccno+cursorcol);
            goto funcdone;
        case CCPICK:
            picklines(curwksp->ulhclno + cursorline, defpick);
            goto funcdone;
        case CCINSMODE:
            imodesw = 1 - imodesw;  /* change it */
            goto funcdone;
        case CCGOTO:
            gtfcn(0);
            goto funcdone;
        case CCMIPAGE:
            movew(- defmipage * (1+curport->btext));
            goto funcdone;
        case CCPLSRCH:
            search(1);
            goto funcdone;
        case CCRPORT:
            movep(defrport);
            goto funcdone;
        case CCPLLINE:
            movew(defplline);
            goto funcdone;
        case CCDELCH:
            goto notimperr;
        case CCSAVEFILE:
            savefile(NULL,curfile);
            goto funcdone;
        case CCMILINE:
            movew(-defmiline);
            goto funcdone;
        case CCDOCMD:
            goto notstrerr;
        case CCPLPAGE:
            movew(defplpage * (1+curport->btext));
            goto funcdone;
        case CCMAKEPORT:
            makeport(deffile);
            goto funcdone;
        case CCTABS:
            settab(curwksp->ulhccno + cursorcol);
            goto funcdone;
            /*    case CCMOVELEFT:        */
            /*    case CCTAB:             */
            /*    case CCMOVEDOWN:        */
            /*    case CCHOME:            */
            /*    case CCRETURN:  */
            /*    case CCMOVEUP:  */
        default:
            goto badkeyerr;
        }
        /* Повтор ввода аргумента */
reparg:
        read1();
        if(CTRLCHAR) goto yesarg;
        else goto noargerr;
        /*
         * Дай аргумент!
         */
gotarg:
        param(0);
yesarg:
        if (lread1 == CCQUIT )
        {
            if (paraml>0 && (dechars(paramv,paraml),*paramv) == 'a')
            {
                gosw = 0;
                if (*(paramv+1) != 'd') return;
                cleanup();
                inputfile = -1; /* to force a dump */
                fatal("ABORTED");
            }
            if (endit() == 0) goto funcdone;
            gosw = 1;
            return;
        }
        switch (lread1)
        {
        case CCENTER:
            goto funcdone;
        case CCLPORT:
            if (paramtype <= 0)  goto notstrerr;
            if (s2i(paramv,&i)) goto notinterr;
            movep(-i);
            goto funcdone;
        case CCSETFILE:
            if (paramtype <=  0)  goto notstrerr;
            if (paramv == 0) goto noargerr;
            if ( use0flg || !inputfile)
                dechars(paramv,paraml);
            use0flg=1;
            editfile(paramv,0,0,1,1);
            goto funcdone;
        case CCCHPORT:
            if (paramtype <= 0)  goto notstrerr;
            if (s2i(paramv,&i)) goto notinterr;
            if (i <= 0) goto notposerr;
            chgport(i-1);
            goto funcdone;
        case CCOPEN:
            if (openwrite[curfile]==0)  goto nowriterr;
            if (paramtype == 0) {
                splitline(curwksp->ulhclno + paramr0,
                paramc0 + curwksp->ulhccno);
                goto funcdone;
            }
            else {
                lnfun = openlines;
                spfun = openspaces;
                goto spdir;
            };
        case CCMISRCH:
        case CCPLSRCH:
            if (paramtype <= 0)  goto notstrerr;
            if (paramv == 0) goto noargerr;
            if (searchkey) free(searchkey);
            searchkey = paramv;
            paraml = 0;
            search(lread1==CCPLSRCH?1:-1);
            goto funcdone;
        case CCCLOSE:
            if (openwrite[curfile]==0)  goto nowriterr;
            if (paramtype == 0) combineline(curwksp->ulhclno + paramr0,
            paramc0 + curwksp->ulhccno);
            else {
                if(paramtype > 0 && paramv && paramv[0]=='>')
                {
                    msrbuf(deletebuf,paramv+1,0);
                    goto funcdone;
                }
                lnfun = closelines;
                spfun = closespaces;
                goto spdir;
            }
            goto funcdone;
        case CCPUT:
            if (paramtype >  0 && paramv && paramv[0]=='$' )
            {
                if (msrbuf(pickbuf,paramv+1,1))goto errclear;
                goto funcdone;
            }
            if (paramtype != 0)  goto notstrerr;
            if (openwrite[curfile]==0)
                goto nowriterr;
            if (deletebuf->nrows == 0) goto nodelerr;
            put(deletebuf,curwksp->ulhclno+cursorline,
            curwksp->ulhccno+cursorcol);
            goto funcdone;
        case CCMOVELEFT:
        case CCTAB:
        case CCMOVEDOWN:
        case CCHOME:
        case CCMOVEUP:
        case CCMOVERIGHT:
        case CCBACKTAB:
            if (s2i(paramv,&i)) goto notinterr;
            if (i <= 0) goto notposerr;
            m = ((lread1<=BT) ? lread1:0);
            while (--i >= 0) movecursor(m);
            goto funcdone;
        case CCRETURN:
            if(paramtype <=0|| !paramv) goto notimperr;
            dechars(paramv,paraml);
            switch (paramv[0])
            {
            case '>':
                msvtag(paramv+1);
                goto funcdone;
            case '$':
                if(mdeftag(paramv+1)){
                    lread1= -1;
                    goto reparg;
                }
                else goto funcdone;
            case 'w':
                if(paramv[1]==' ' && paramv[2]=='+')
                    openwrite[curwksp->wfile]=1;
                else openwrite[curwksp->wfile]=0;
                goto funcdone;
            case 'k':
                defkey();
                goto funcdone;
            case 'r':
                rescreen(-1);
                goto funcdone; /* Восттановить экран */
            case 'd':
                if(paramv[1]==' ') defmac(&paramv[2]);
                goto funcdone;
            case 'q':
                lread1=CCQUIT;
                if(paramv[1]=='a') {
                    gosw=0;
                    return;
                }
                goto contin;
            default:
                goto noargerr;
            }
        case CCPICK:
            if (paramtype == 0) goto notimperr;
            if (paramtype > 0 && paramv && paramv[0]=='>')
            {
                msrbuf(pickbuf,paramv+1,0);
                goto funcdone;
            }
            lnfun = picklines;
            spfun = pickspaces;
            goto spdir;
        case CCINSMODE:
            imodesw = 1 - imodesw;  /* Щелкнем!! */
            goto funcdone;
        case CCGOTO:
            if (paramtype == 0) gtfcn(nlines[curfile]);
            else if (paramtype > 0)
            {
                if(paramv && paramv[0]=='$') {
                    mgotag(paramv+1);
                    goto funcdone;
                }
                if (s2i(paramv,&i)) goto notinterr;
                gtfcn(i-1);
            }
            else goto noargerr;
            goto funcdone;
        case CCMIPAGE:
            if (paramtype <= 0)  goto notstrerr;
            if (s2i(paramv,&i)) goto notinterr;
            movew(- i * (1 + curport->btext));
            goto funcdone;
        case CCRPORT:
            if (paramtype <= 0)  goto notstrerr;
            if (s2i(paramv,&i)) goto notinterr;
            movep(i);
            goto funcdone;
        case CCPLLINE:
            if (paramtype < 0)  goto notstrerr;
            else if (paramtype == 0)  movew(cursorline);
            else if (paramtype > 0)
            {
                if (s2i(paramv,&i)) goto notinterr;
                movew(i);
            }
            goto funcdone;
        case CCDELCH:
            goto notimperr;
        case CCSAVEFILE:
            if (paramtype <=  0)  goto notstrerr;
            if (paramv == 0) goto noargerr;
            dechars(paramv,paraml);
            savefile(paramv,curfile);
            goto funcdone;
        case CCMILINE:
            if (paramtype < 0)  goto notstrerr;
            else if (paramtype == 0)  movew(cursorline - curport->btext);
            else if (paramtype > 0)
            {
                if (s2i(paramv,&i)) goto notinterr;
                movew(-i);
            }
            goto funcdone;
        case CCDOCMD:
            if(paramtype<=0) goto notstrerr;
            dechars(paramv,paraml);
            if (openwrite[curfile] == 0) goto nowriterr;
            callexec();
            goto funcdone;
        case CCPLPAGE:
            if (paramtype <= 0)  goto notstrerr;
            if (s2i(paramv,&i)) goto notinterr;
            movew(i * (1 + curport->btext));
            goto funcdone;
        case CCMAKEPORT:
            if (paramtype == 0)  removeport();
            else if (paramtype <  0)  goto notstrerr;
            else {
                dechars(paramv,paraml);
                makeport(paramv);
            }
            goto funcdone;
        case CCTABS:
            clrtab(curwksp->ulhccno + cursorcol);
            goto funcdone;
        default:
            goto badkeyerr;
        }
spdir:
        if (paramtype > 0)
        {
            if(paramv[0] == '$')
            {
                if(mdeftag(paramv+1)) goto spdir;
                else goto funcdone;
            }
            if (s2i(paramv,&i)) goto notinterr;
            if (i <= 0) goto notposerr;
            (*lnfun)(curwksp->ulhclno + cursorline, i);
        }
        else
        {
            if (paramc1 == paramc0)
            {
                (*lnfun)(curwksp->ulhclno+paramr0,
                (paramr1-paramr0)+1);
            }
            else (*spfun)(curwksp->ulhclno + paramr0,
            curwksp->ulhccno + paramc0,
            (paramc1-paramc0),
            (paramr1-paramr0) + 1);
        }
        goto funcdone;
badkeyerr:
        error(DIAG("Illegal key or unnown macro","Неизвестная клавиша или макро"));
        goto funcdone;
notstrerr:
        error(DIAG("Argument must be a string.","Аргумент должен быть строкой"));
        goto funcdone;
noargerr:
        error(DIAG("Invalid argument.","Плохой аргумент"));
        goto funcdone;
notinterr:
        error(DIAG("Argument must be numerik.","Аргумент должен быть числом"));
        goto funcdone;
notposerr:
        error(DIAG("Argument must be positive.","Аргумент должен быть положительным"));
        goto funcdone;
nopickerr:
        error(DIAG("Nothing in the pick buffer.","Буфер вставок пуст"));
        goto funcdone;
nodelerr:
        error (DIAG("Nothing in the close buffer.","Буфер убранных строк пуст"));
        goto funcdone;
notimperr:
        error(DIAG("Feature not implemented yet.","Еще не определено."));
        goto funcdone;
margerr:
        error("Margin stusk; move cursor to free.");
        goto funcdone;
nowriterr:
        error(DIAG("You cannot modify this file!","Вы не можете изменить этот файл."));
        goto funcdone;
funcdone:
        clrsw = 1;
newnumber:
        lread1 = -1;        /* signify char read was used */
errclear:
        oport = curport;
        k = cursorline;
        j = cursorcol;
        switchport(&paramport);
        paramport.redit = PARAMRINFO;
        if (clrsw)
        {
            if (!errsw && !first)
            {
                poscursor(0,0);
                info(blanks,PARAMRINFO);
            }
            poscursor(PARAMREDIT+2,0);
            if (oport->wksp->wfile)
            {
                info(DIAG("file ","файл "),PARAMRINFO);
                info(openfnames[oport->wksp->wfile],PARAMRINFO);
            }
            info(DIAG(" line "," строка: "),PARAMRINFO);
            clsave = cursorline;
            first=0;
            ccsave = cursorcol;
        }
        poscursor(ccsave,clsave);
        i = oport->wksp->ulhclno + k + 1; /* Рисуем номер строки */
        cp = ich + 8;
        *--cp = '\0';
        do
            (*--cp = '0' + (i % 10));
        while (i = i/10);
        info(cp,PARAMRINFO);
        *cp = '\0';
        while (cp != ich) *--cp = ' ';
        info(ich,PARAMRINFO);
        switchport(oport);
        paramport.redit = PARAMREDIT;
        poscursor(j,k);
        if (csrsw)
        {
            putch(COCURS,1);
            poscursor(j,k);
            dumpcbuf();
            sleep(1);
            putup(k,k);
            poscursor(j,k);
        }
        if (imodesw && clrsw && !errsw)
            telluser(DIAG("     ***** i n s e r t m o d e *****","  * * * * режим вставки * * * * "),0);
contin:
        ;
    }
#undef lread1
}
Ejemplo n.º 10
0
Cmdret
dohelp ()
{
    char *cp, *ncp;
    int len, num;
#ifndef ANSI
    static char helpfile[] = EDIR(help);
#else
    static char helpfile[] = EDIR("help");
#endif
    Short i;
    Short j;

    cp = append (helpfile, ediag ("", "_r"));
    if (editfile (cp, (Ncols) -1, (Nlines) -1, 0, NO, NO) <= 0) {
	sfree (cp);
	mesg (ERRALL + 1, ediag("Help file gone: notify sys admin.",
	   "Отсутствует help-файл: обратитесь к системным программистам."));
	return CROK;
    }
    sfree (cp);

    fileflags[curfile] &= ~CANMODIFY;

    if (Item == (S_help *) NULL) { /* Initilize help structures */
	if ((cp = pkarg (curwksp,
			 (Nlines) 0, (Ncols) 0,
			 &len, PK_UPTOS)) == (char *) NULL) {
	Err:
	    deffn = curfile;
	    (void) eddeffile (YES);
	    mesg (ERRALL + 1, ediag("Bad format of Help file: notify sys admin.",
	       "Неверный формат help-файла: обратитесь к системным программистам."));
	    return CROK;
	}
	if (len == 0 || s2i (cp, &HelpItems) == cp
	     || HelpItems <= 0 || HelpItems >= la_lsize (curlas) - 1) {
	    sfree (cp);
	    goto Err;
	}
	sfree (cp);
	if ((Item = (S_help *) salloc (HelpItems * sizeof (S_help), NO))
		== (S_help *) NULL)
	    goto Err;
	for (i = 0; i < HelpItems; i++) {
	    if ((cp = pkarg (curwksp,
			     (Nlines) i + 1, (Ncols) 0,
			     &len, PK_FIELD)) == (char *) NULL) {
	ErrAll:
		for (j = 0; j < i; j++)
		    sfree (Item[j].item_name);
		sfree ((char *) Item);
		goto Err;
	    }
	    if (len == 0) {
		sfree (cp);
		goto ErrAll;
	    }
	    Item[i].item_name = cp;
	    Item[i].item_len = len;
	    if ((cp = pkarg (curwksp,
			     (Nlines) i + 1, (Ncols) len + 1,
			     &len, PK_FIELD)) == (char *) NULL) {
	    ErrNum:
		sfree (Item[i].item_name);
		goto ErrAll;
	    }
	    if (len == 0
		|| (ncp = s2i (cp, &num)) == cp
		|| num <= HelpItems + 1) {
	    ErrPar:
		sfree (cp);
		goto ErrNum;
	    }
	    Item[i].def_line = num - 1;
	    while (isspace (*ncp))
		ncp++;
	    if (s2i (ncp, &num) == ncp || num < 0)
		goto ErrPar;
	    sfree (cp);
	    Item[i].def_col = num;
	}
    }   /* End of init */

    fileflags[curfile] |= HELP;
    HelpActive = YES;

    movewin ((Nlines) HelpItems + 1, (Ncols) 0, (Scols) 0, (Slines) 0, NO);
    putupwin ();
    HelpGotoMarg (NO);

    return CROK;
}