File:  [Power 6/32 Unix Tahoe 4.2BSD] / cci / usr / src / bin / cdb / cmdline.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Sun Jul 28 12:24:19 2019 UTC (7 years ago) by root
Branches: bsd, MAIN
CVS tags: v12b, v121, HEAD
Power 6/32 Unix version 1.2b

static char *sccsid = "@(#)cmdline.c	2.6";

#include <stdio.h>
#include "cdb.h"

extern char *gets();

FILE	*vfpRecord, *vfpPlayback;	/* not every file has <stdio.h> */
export int	vcStepPlayback;
export FLAGT	vfRecord;

#define chEOF 04	/* a ^D */
#define cbSbCmd 200	/* max command length */
#define cbSbQuery 20	/* max query (Yes/No) length */

/* this file contains the routines that read the commnad line from the TTY and
 * maintain the record & playback files.
 * TkNext(), in tk.c, the tokenizer, is what most routines call to actually get
 * something from the current command line.
 */


/* N E X T   C M D */

local void NextCmd(sbCmd, cbCmd, sbPrompt)
char	*sbCmd, *sbPrompt;
int	cbCmd;
{
	FLAGT	fDoit;
	char	*sbT, *sbT2;
	char	sbQuery[cbSbQuery];

	if (sbPrompt != sbNil AND *sbPrompt != chNull)
		printf(sbPrompt);
	while (vfpPlayback != NULL) {
		sbT = fgets(sbCmd, cbCmd, vfpPlayback);
		if ((sbT2 = strrchr(sbCmd, '\n')) != NULL)
			*sbT2 = chNull;	/* step on new-line */
		if ((vcStepPlayback == 0)
		    OR (--vcStepPlayback > 0)) {
			if (sbT != sbNil)
				printf("%s\n", sbCmd);
		} 
		else {	/* we are doing playback stepping */
			if (sbT != sbNil) {
				printf("%s  (<cr>, <#>, C, Q, S or ?): ", sbT);
				fDoit = false;
				while (!fDoit) {
					gets(sbQuery);
					fDoit = true;
					switch (*sbQuery) {
					case 'Q':   
						fclose(vfpPlayback);
						sbT = sbNil;
						if ((sbPrompt != sbNil)
						    AND (*sbPrompt != chNull))
							printf(sbPrompt);
						/* and fall through */
					case 'S':   
						vcStepPlayback = 1;
						goto contMainLoop;
						break;
					case 'C':   
						vcStepPlayback = 0;
						break;
					case chNull:
						vcStepPlayback = 1;
						break;
					case '?':
						printf("<cr> executes THIS command line,\n");
						printf("<#> does that number of command lines,\n");
						printf("S skips this command,\n");
						printf("Q quits playback mode,\n");
						printf("C continues until the end of ALL playback files.\n");
						fDoit = false;
						break;
					case '0': 
					case '1': 
					case '2': 
					case '3':
					case '4': 
					case '5': 
					case '6': 
					case '7':
					case '8': 
					case '9':
						vcStepPlayback = atoi(sbQuery);
						break;
					default:	
						fDoit = false;
					} /* switch */
				} /* while */
			} /* if */
		} /* if */
		if (sbT != sbNil) {
			return;
		} 
		else {
			fclose(vfpPlayback);
			vfpPlayback = NULL;
			/* and fall into `from the TTY code ' */
		} /* if */
		break;
contMainLoop: 
		;
	} /* while */

	/* there is no playback file, read from terminal */
	sbT = gets(sbCmd);
	if (sbT == sbNil) {
		sbCmd[0] = chNull;
	} 
	else if (*sbT == chNull) {
		sbT[0] = '~';
		sbT[1] = chNull;
	} /* if */
} /* NextCmd */


/* R E C O R D	 C M D */

local void RecordCmd(sbCmd)
char	*sbCmd;
{
	if (   vfRecord
	    AND (vfpRecord != NULL)
	    AND (*sbCmd != '!')
	    AND (*sbCmd != '>')
	    AND (*sbCmd != '<') ) {
		fprintf(vfpRecord, "%s\n", sbCmd);	/* make a recording */
	} /* if */
} /* RecordCmd */


/* Y E S   N O */

export int YesNo(sbPrompt)
char	*sbPrompt;
{
	char	sbAnswer[cbSbQuery];

	NextCmd(sbAnswer, cbSbQuery, sbPrompt);
	RecordCmd(sbAnswer);
	return(sbAnswer[0] == 'y' OR sbAnswer[0] == 'Y');
} /* YesNo */


/* S E T   P L A Y B A C K */

local void SetPlayback(sbPlayback, fSinglestep)
char	*sbPlayback;
FLAGT	fSinglestep;
{
	FILE	*fpTemp;

	if (vfpPlayback != NULL)
		fclose(vfpPlayback);
	if ((sbPlayback == sbNil) OR (*sbPlayback == chNull))
		UError("No playback name specified");
	if ((fpTemp = fopen(sbPlayback, "r")) == NULL)
		UError("Can't open %s as playback file", sbPlayback);
	printf("Playing back from %s\n", sbPlayback);
	vfpPlayback = fpTemp;
	vcStepPlayback = (fSinglestep) ? 1 : 0;
} /* SetPlayback */


/* S E T   R E C O R D */

local void SetRecord(sbRecord)
char	*sbRecord;
{
	FILE	*fpTemp;

	if (vfpRecord != NULL) {
		printf("Closing record file\n");
		fclose(vfpRecord);
		vfRecord = false;
		vfpRecord = NULL;
	} /* if */
	if ((sbRecord == sbNil) OR (*sbRecord == chNull))
		return;
	if ((fpTemp = fopen(sbRecord, "w+")) == NULL)
		UError("Can't open %s as record file", sbRecord);
	vfRecord = true;
	vfpRecord = fpTemp;
	printf("Recording is ON, going to %s\n", sbRecord);
} /* SetRecord */


/* S T A T E   R E C O R D */

local void StateRecord(fOn)
FLAGT	fOn;
{
	vfRecord = fOn;
	printf("Recording is %s\n", (vfRecord) ? "ON" : "OFF");
	if ((vfRecord)
	    AND (vfpRecord == NULL))
		UError("WARNING: no record file is open");
} /* StateRecord */


/* S H O W   S T A T E */

local void ShowState()
{
	printf("Debugging %s, %d files %d procedures\n",
	vsbSymfile, vifdMac-3, vipdMac-1);
	if (vfnCore != fnNil)
		printf("Core file is %s\n", vsbCorefile);
	else
		printf("No core file\n");
	if (vpid != pidNil)
		printf("There is an active child process, #%d\n", vpid);
	else
		printf("No active child process\n");
	if (viadMac == 0)
		printf("No assertions.\n");
	else if (vas == asSuspended)
		printf("Assertions are suspended.\n");
	else
		printf("%d assertions are active.\n", viadMac);
	StateRecord(vfRecord);
	printf("Searches are %scase sensitive\n",
	(vcaseMod!=0) ? "NOT " : "");
} /* ShowState */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.