REM ******************* CBASEDIT.BAS ********************
REM *		AL BRENDEL 3/15/81
REM *		WRITTEN AS C-BASIC2 MULTILINE FUNCTIONS
REM * A DATA ENTRY AND EDITOR FOR STRINGS OF GIVEN FIELD
REM * LENGTHS. ALLOWS EDITING USING TERMINALS WITH OR WITHOUT
REM * CURSOR CONTROL. ESPECIALLY USEFUL FOR DATA ENTRY FOR
REM * FORMS OR FOR RANDON ACCESS FILES

	REM ******** CBASIC-2 FUNCTION LIBRARY ************\
			AL BRENDEL 3/15/81

	REM ********* SET CONSOLE WIDTH *********
		POKE 272,0
		CONSOLE

	REM ********* STRING FUNCTION ************
	REM *TYPICAL USE:\
		PRINT FN.STRING$(12,10) REM..PRINT 12 LINE FEEDS

	DEF FN.STRING$ (LENGTH,ASCVAL)
		STRING$=""
		FOR NUMB = 1 TO LENGTH
			STRING$ = STRING$ + CHR$(ASCVAL)
		NEXT NUMB
		FN.STRING$=STRING$
		RETURN
	FEND

	REM ********** GET DATA AND EDIT FUNCTION *************
	REM *TYPICAL APPLICATION:
	REM	NAME$=FN.GET.DATA$("MSG",INITNAME$,FIELD.LGTH)
	REM		'PRINTS MSG AND THEN ALLOWS
	REM		'ENTRY OR MODIFICATION OF NAME$ AND
	REM		'SHOWS LENGTH OF FIELD
	REM		'EDITING COMMANDS INCLUDE:
	REM			'MOVE CURSER RIGHT..	>
	REM			'MOVE CURSER LEFT...	< OR BS(^H)
	REM			'DELETE CHARACTER...	DEL
	REM			'INSERT CHARACTER...	^
	REM			'RETURN TO PROGRAM...	CR

	DEF FN.GET.DATA$ (MSG$,NAME$,LENGTH)
		NAME$=NAME$+FN.STRING$(LENGTH-LEN(NAME$),42)
		PRINT MSG$;": ";NAME$+FN.STRING$(LENGTH,8);
		FOR NUM = 1 TO LENGTH
		ANS%=CONCHAR%
		IF ANS%=13 THEN GOTO 1.03
		IF ANS%=8 AND NUM=1 THEN PRINT\
			CHR$(32)+MID$(NAME$,NUM,1)+CHR$(8);\
			:NUM=NUM-1:GOTO 1.02
		IF ANS%=8 THEN NUM=NUM-2\
			:GOTO 1.02
		IF ANS%=62 AND NUM=LENGTH THEN\
			PRINT CHR$(8)+MID$(NAME$,NUM,1)\
			+CHR$(8)+CHR$(7);\
			:NUM=NUM-1:GOTO 1.02
		IF ANS%=62 THEN PRINT CHR$(8)+\
			MID$(NAME$,NUM,1);:GOTO 1.02
		IF ANS%=60 AND NUM>1 THEN PRINT CHR$(8)+\
			MID$(NAME$,NUM,1)+CHR$(8)+CHR$(8);\
			:NUM=NUM-2:GOTO 1.02
		IF ANS%=60 AND NUM=1 THEN PRINT\
			CHR$(8)+MID$(NAME$,NUM,1)+CHR$(8);\
			:NUM=NUM-1:GOTO 1.02
		IF ANS%=94 THEN NAME$=LEFT$(NAME$,NUM-1)\
			+" "+MID$(NAME$,NUM,LENGTH-NUM)\
			:PRINT CHR$(8)+RIGHT$(NAME$,LENGTH-NUM+1)\
			+FN.STRING$(LENGTH-NUM+1,8);\
			:NUM=NUM-1:GOTO 1.02
		IF ANS%=127 THEN NAME$=LEFT$(NAME$,NUM-1)\
			+RIGHT$(NAME$,LENGTH-NUM)+"*"\
			:PRINT RIGHT$(NAME$,LENGTH-NUM+1)\
			+FN.STRING$(LENGTH-NUM+1,8);\
			:NUM=NUM-1:GOTO 1.02
		NAME$=LEFT$(NAME$,NUM-1)\
			+CHR$(ANS%)+RIGHT$(NAME$,LENGTH-NUM)
		IF NUM=LENGTH THEN PRINT CHR$(7)+CHR$(8);\
		:NUM=NUM-1
	1.02	NEXT NUM
		PRINT CHR$(13);
	1.03	FOR NUM=1 TO LENGTH
			IF MID$(NAME$,NUM,1)="*" THEN NAME$= \
			LEFT$(NAME$,NUM-1)+" "+RIGHT$(NAME$,LENGTH-NUM)
		NEXT NUM
		PRINT MSG$;": ";NAME$
		FN.GET.DATA$=NAME$
		RETURN
	FEND

REM ******TEST OF FUNCTIONS

	2.01	INPUT " STARTING WORD";LINE NAME$
		PRINT
		NAME$=FN.GET.DATA$("EDIT ACTIVE..",NAME$,20)
		PRINT:PRINT "ENDING WORD..";NAME$
		GOTO 2.01
