Exemple #1
0
/*
 * Test for PARSER: parse "i1+i2" or "i1+i2+..." where "i-n" is an integer.
 */
    FUNCTION main ()

    {
    IMPORT	TEXT vrsion[];
    TEXT	string[STRINGSIZ+1];
    CODE	parse();
    struct	SYNBLK sb;
    CODE	code;
    COUNT	dummy;

/* define indexes for our list of pointers to states			*/
#define	s0pt	0
#define	s1pt	1
#define	s2pt	2
#define	s3pt	3
#define	s4pt	4
#define EV_SUM	PA_ACCEPT + 100
/* reference the action routines					*/
    CODE doneact(), sumact();
/* define the state structures						*/
    static struct SHFENT shift0[] = {
    			   EV_SUM, s1pt,  /* to s1 on EV_SUM		*/
    			   PA_NUM, s4pt,  /* to s4 on a number		*/
    			   PA_TABTERM};
    static struct PSTATE s0 = {0, 0, NULL, NULL, shift0};



    static PA_CODE red1[] = {EOS, PA_TABTERM};  	/* reduce if EOS */
    static struct SHFENT shift1[] = {'+', s2pt, PA_TABTERM};
    static struct PSTATE s1 = {1, PA_ACCEPT, doneact, red1, shift1};


    static struct SHFENT shift2[] = {PA_NUM, s3pt, PA_TABTERM};
    static struct PSTATE s2 = {0, 0, NULL, NULL, shift2};

    static PA_CODE red3[] = {EOS, '+', PA_TABTERM};  
    static struct PSTATE s3 = {3, EV_SUM, sumact, red3, NULL};

    static PA_CODE red4[] = {EOS, '+', PA_TABTERM};
    static struct PSTATE s4 = {1, EV_SUM, NULL, red4, NULL};

/* list of state pointers						*/
    struct PSTATE *statelist[]= {&s0, &s1, &s2, &s3, &s4};


    parser_init (statelist, sizeof(statelist)/sizeof(struct PSTATE *));
    printf(" Parser test, version %s\n", vrsion);
    printf(" Enter a string  ");
    t_init(&dummy, &dummy, &dummy);
    t_read(string, &dummy);
    for (; string[0]!='@';)	/* exit on '@'				*/
    	{
    	initok(&sb, string);
    	code = parser(&sb, statelist, s0pt);	/* call the parser	*/
    	printf("Parse complete. Success/fail: %d\n", code);
        printf(" Enter a string  ");
        t_read(string, &dummy);
    	}
    }
Exemple #2
0
FUNCTION CODE inlevel2 
(
    struct CONTXT	*pctx,		/* in/out: proc context w/ tab to update.*/
    struct SFILE	*hf,		/* in/out: help file control block	*/
    TEXT		type[],		/* in: subcmd/parm			*/
    TEXT		subcmd[]	/* in: subcommand qualifier to search	*/

 )
    {
    IMPORT  struct  VARIABLE *char_gbl;		/* system characteristics 	*/

    TEXT		dirctv[STRINGSIZ+1];
    TEXT		field[STRINGSIZ+1];
    TEXT		scope[STRINGSIZ+1];
    TEXT		prmname[NAMESIZ+1];
    TEXT		proc[FSPECSIZ+1];
    TEXT		subname[SUBCMDSIZ+1];
    struct SYNBLK	sb;
    struct VARIABLE	*v;
    struct SUBCMD	*s;
    struct TUTEXT	*t;
    TEXT		str[STRINGSIZ+1];
    CODE		code;
    struct DIRBLK	db;			/* directive block for d_ pkg	*/
    TEXT		libe[FLIBRSIZ+1];
    struct CONTXT	*ctx;

    if (tutctx.nohelpf || tutctx.srch2cplt)	/* if search complete, no help		*/
	goto nhelp_err;
    for (ctx = pctx; (s_equal((*ctx).pdf.libr,"/LOCAL/"));
		ctx = (*ctx).backlink);
    s_copy ((*ctx).pdf.libr, libe);
    d_init(&db, hf, libe,
	(TEXT **) (*char_gbl).v_cvp, (*char_gbl).v_count);    /* init directive block	*/

    if (!tutctx.h2exist)		/* if lev 2 help existence not yet known*/
	{
	if (tutctx.h1exist)		/* if level1 exists			*/
	    f_setpos(hf, &tutctx.lasth1pos); /* start looking from lev 1 help posit	*/
	else
	    f_setpos(hf, &(*hf).posctx);	/* look from current position	*/
	while ((code = d_dirctv(&db, dirctv, field)) == SUCCESS)
	    {
	    if (s_equal(dirctv, ".LEVEL2"))		/* .level2 help found	*/
		break;
	    else if (s_equal(dirctv, ".HELP"))		/* .HELP  encountered	*/
		{
		f_movpos(&(*hf).posctx, &tutctx.hlppos);/* save .help posctx	*/
		tutctx.hlpexist = TRUE;			/* mark as exists	*/
		}
	    else if (s_equal(dirctv, ".END"))		/* End of file reached	*/
	        {
	        tutctx.srch2cplt = TRUE;
	        goto nhelp_err;
	        }
	    }
	if (code != SUCCESS)
	    goto read_err;
	if (f_read(hf, str) != SUCCESS) goto read_err;
	tutctx.h2exist = TRUE;
	f_movpos(&(*hf).posctx, &tutctx.lasth2pos);
	f_movpos(&(*hf).posctx, &tutctx.lev2start);
	}
    f_setpos(hf, &tutctx.lasth2pos);	/* restore last lev 2 help position	*/
    while (FOREVER)
	{
	if (d_dirctv(&db, dirctv, field) != SUCCESS) goto read_err;	/* input next directive line*/
	f_movpos(&(*hf).posctx, &tutctx.lasth2pos);
	if (!s_lseq(".VAR", dirctv)  &&  !s_equal(".SUBCMD", dirctv))
	    {
	    tutctx.srch2cplt = TRUE;
	    goto nhelp_err;
	    }
	if (s_equal(type, "subcmd") &&  s_equal(".SUBCMD", dirctv))
	    break;
	if (s_equal(type, "parm") &&  s_lseq(".VAR", dirctv))
	    break;
	}
    initok(&sb, field);			/* init sb for syntax pkg		*/
    code = gettok(&sb, prmname);
    if (code != S_ALPHA && (!s_equal(type, "subcmd") || code != '-'))
	goto noparm_err;
    if (s_equal(type, "subcmd"))
	{
	if (code == '-')
	    prmname[0] = EOS;
	else
	    prmname[SUBCMDSIZ] = EOS;
	s = subex((*pctx).subptr, prmname);
	if (s == NULL) goto nparm_ret;
	t = &(*s).ext;
	}
    else
	{
	prmname[NAMESIZ] = EOS;
	proc[0] = EOS;
	subname[0] = EOS;
	s_copy(sb.curchr, scope);
	if (!NULLSTR(scope))
	    cmd_parse(&sb, scope, NULL, proc, subname);
	if (!NULLSTR(proc) && !s_equal((*pctx).pdf.name, proc)) goto nparm_ret;
	if (!s_equal(subcmd, subname)) goto nparm_ret;
	v = lookex(&(*pctx).parmst, prmname);
	if (v == NULL) goto nparm_ret;
	if ((*v).v_tp == NULL)
	    if (((*v).v_tp = (struct TUTEXT *) tae_alloc(1, sizeof(struct TUTEXT)))
		== NULL) goto over_err;
	t = (*v).v_tp;
	}
    if ((*t).l2hexist) goto nparm_ret;
    (*t).l2hexist = TRUE;
    f_movpos(&(*hf).posctx, &(*t).l2hpos);	/* save help posit for this var	*/
    f_read(hf, str);				/* pass this position		*/
    f_movpos(&(*hf).posctx, &tutctx.lasth2pos);
    return(SUCCESS);

nparm_ret:
    f_read(hf, str);
    f_movpos(&(*hf).posctx, &tutctx.lasth2pos);
    return(SUCCESS);

nhelp_err:
    return(TUT_NOL2HELP);				/* no leve2 help 	*/

read_err:
    tutmsg(msg_hrde, key_hrde, (uintptr_t) (*pctx).pdf.name, 0, 0, 0, 0);	/* tutor mode help file read error*/
    return(FAIL);

noparm_err:
    tutmsg("Level 2 .VARIABLE statement missing a parameter name.", "TAE-TNPNAM", 0, 0, 0, 0, 0);
    return(FAIL);

over_err:
    tutmsg(msg_mmov, key_mmov, 0, 0, 0, 0, 0);		/* dyn mem overflow			*/
    return(FAIL);
    }
Exemple #3
0
FUNCTION static CODE inlevel1 
(
    struct CONTXT	*pctx,		/* in/out: proc context w/ tab to update.	*/
    struct SFILE	*hf,		/* in/out: help file control block	*/
    TEXT		subcmd[]	/* in: subcommand qualifier to search	*/

 )
    {
    IMPORT  struct  VARIABLE *char_gbl;		/* system characteristics 	*/

    TEXT		dirctv[STRINGSIZ+1];
    TEXT		field[STRINGSIZ+1];
    TEXT		scope[STRINGSIZ+1];
    TEXT		prmname[SUBCMDSIZ+1];
    TEXT		proc[FSPECSIZ+1];
    TEXT		subname[SUBCMDSIZ+1];
    struct SYNBLK	sb;
    struct VARIABLE	*v;
    struct SUBCMD	*s;
    struct TUTEXT	*t;
    TEXT		str[STRINGSIZ+1];
    CODE		code, code1;
    struct DIRBLK	db;			/* directive block for d_ pkg	*/
    TEXT		libe[FLIBRSIZ+1];
    struct CONTXT	*ctx;

    if (!tutctx.h1exist  ||  tutctx.h1done)
	return(TUT_H1DONE);
    f_setpos(hf, &tutctx.lasth1pos);	/* restore last lev 1 help position	*/
    for (ctx = pctx; (s_equal((*ctx).pdf.libr,"/LOCAL/")); ctx = (*ctx).backlink);
    s_copy ((*ctx).pdf.libr, libe);	/* make sure we have a libe good for internal procs */
    d_init(&db, hf, libe,
	(TEXT **) (*char_gbl).v_cvp, (*char_gbl).v_count);	/* init directive block	*/
    while (FOREVER)
	{
	if ((code = d_dirctv(&db, dirctv, field)) != SUCCESS) goto read_err;	/* input next directive line*/
	f_movpos(&(*hf).posctx, &tutctx.lasth1pos);
	if (!s_lseq(".VAR", dirctv)  &&  !s_equal(".SUBCMD", dirctv))
	    {
	    tutctx.h1done = TRUE;
	    return(TUT_H1DONE);
	    }
	if (tutctx.subtut  &&  s_equal(".SUBCMD", dirctv))
	    break;
	if (!tutctx.subtut  &&  s_lseq(".VAR", dirctv))	
	    break;
	}
    initok(&sb, field);			/* init sb for syntax pkg		*/
    code = gettok(&sb, prmname);
    if (code != S_ALPHA && (!tutctx.subtut || code != '-')) goto name_err;
    if (tutctx.subtut)
	{
	if (code == '-')
	    prmname[0] = EOS;
	else
	    prmname[SUBCMDSIZ] = EOS;	
	if ((s = subex((*pctx).subptr, prmname)) == NULL) goto nsubc_err;
	t = &(*s).ext;
	}
    else
	{
	prmname[NAMESIZ] = EOS;
	proc[0] = EOS;
	subname[0] = EOS;
	s_copy(sb.curchr, scope);
	if (!NULLSTR(scope))
	    cmd_parse(&sb, scope, NULL, proc, subname);
	if (!NULLSTR(proc) && !s_equal((*pctx).pdf.name, proc)) goto nparm_err;
	if (!s_equal(subcmd, subname)) goto nparm_err;
	if ((v = lookex(&(*pctx).parmst, prmname)) == NULL) goto nparm_err;
	if ((*v).v_tp == NULL)
	    if (((*v).v_tp = (struct TUTEXT *) tae_alloc(1, sizeof(struct TUTEXT))) == NULL)
		goto over_err;
	t = (*v).v_tp;
	}
    if ((*t).l1hexist) goto name_err;
    (*t).l1hexist = TRUE;
    code1 = SUCCESS;				/* in case we get out at once */
    while ((code = txtread(&db, str, &tutctx.lasth1pos)) == SUCCESS)
	{
	if ((code1 = addtxt(&(*t).l1help, str)) != SUCCESS) break;
	}
    d_incclose(&db);				/* close .include file, if any	*/
    if (code != D_EOT) goto read_err;
    if (code1 != SUCCESS) goto over_err;
    if (tutctx.screen)
	if ((brktxt(&(*t).l1help, TUTHL1SIZ)) != SUCCESS) goto over_err;	/* break text up for descr field width*/
    return(SUCCESS);

read_err:
    tutmsg(msg_hrde, key_hrde, (uintptr_t) (*pctx).pdf.name, 0, 0, 0, 0);	/* tutor mode help file read error	*/
    tutctx.h1done = TRUE;
    return(TUT_H1DONE);

nsubc_err:
nparm_err:
name_err:
    f_read(hf, str);
    f_movpos(&(*hf).posctx, &tutctx.lasth1pos);
    return(SUCCESS);

over_err:
    tutmsg(msg_mmov, key_mmov, 0, 0, 0, 0, 0);			/* dyn mem overflow		*/
    return(FAIL);
    }
Exemple #4
0
void /*FUNCTION*/ initcommon()
{
	int nerr;

	/*=====================================================================
	 * PURPOSE: Variable initialization of ALL common blocks.
	 *=====================================================================
	 * MODULE/LEVEL:  EXM/4
	 *=====================================================================
	 * GLOBAL INPUT:
	 *    MACH:    KWSNGL, KWMULT, KWCONC
	 *    MEM:     MMEM, MEPSL
	 *    CSF:     KTOKDL, NTOKDL, KMSGDL, NMSGDL
	 *=====================================================================
	 * GLOBAL OUTPUT:
	 *    MEM:     SACMEM
	 *=====================================================================
	 * MODIFICATION HISTORY:
	 *    920414:  Moved block data initialization to initsac as a new
	 *             procedure, initblkdata, while portint to IBM RISC 6000.
	 *    920410:  Added nlevelsgt data initialization after taking it out
	 *             of getvlist and getvlist2, moving common to inc/vars.
	 *
	 *    920309:  Added include dload and initialization of global nfiles.
	 *    920330:  Added block data initialization of common variables.
	 *             Added include gem, dfm, cnv, vars. Added initialization 
	 *             of ndsflcnt - files in data-set storage.
	 *    911107:  Added nerr check and exti on initcomlists.
	 *    900405:  Added call to INITCONTATTR.
	 *    900305:  Added call to INIXYZ.
	 *    880520:  Fixed bug in call to endgraphics.
	 *    870527:  Deleted call to INIWVT.
	 *    870513:  Deleted call to INIOFM.
	 *    870317:  Added call to INIICM.
	 *    870301:  Added call to create global variable store.
	 *    860407:  Added call to INIAM.
	 *    860327:  Added call to INIWVT.
	 *             Moved call to DELIMS from INISAC to here.
	 *    860218:  Added call to WILDCH.
	 *    830309:  Added call to end graphics library.
	 *    810514:  Added call to INISNF
	 *    810414:  Original version.
	 *=====================================================================
	 * DOCUMENTED/REVIEWED:  900305
	 *===================================================================== */
	/* PROCEDURE: */
	/* - Terminate graphics library. */
	endgraphics( &nerr );

	/* - SAC's common blocks. */

	inibom();
	inicom();
	inicpf();
	inidfm();
	inieam();
	iniexm();
	inifks();
	inigem();
	inigam();
	inihdr();
	inilhf();
	inisam();
	iniscm();
	inispe();
	initok();
	inisss();
	iniuom();
	initcomlists( &nerr );
	if( nerr == 901 )
		exit(1);
	initsite();
	inismm();
	inibbs();
	iniicm();
	inivars();
	inixyz();
	initcontattr();

	/* - SACMEM array manager. */

	iniam( &cmmem );

	/* - Blackboard store. */

	createbbs( &nerr );
	reperr(nerr);
	sac_report_files_in_memory(&nerr);

	/* - Initialize wildcard patterns with system values. */

	wildch( KWSNGL, KWMULT, KWCONC );

       
	return;

} /* end of function */
Exemple #5
0
    FUNCTION main ()

    {
    struct SYNBLK	sb;		/* syntax block				*/
    TEXT		s[STRINGSIZ+1];	/* string buffer			*/
    TEXT		verb[TOKESIZ+1];/* verb					*/
    TEXT		key[TOKESIZ+1];	/* keyword				*/
    TEXT		*value[MAXVAL];	/* value pointers			*/
    CODE		code;
    COUNT		count;
    COUNT		tstnum;
    COUNT		i;
    CODE		dum;

    dumrout(&code, &tstnum);		/* dummy - get addrs w/ debugger	*/

    tstnum = 0;

/* TEST 1 */
    printf("\n TEST 1 \n");
    s_copy("menu file=alpha a", s);
    initok(&sb, s);
    tstnum++;

    code = getvrb(&sb, verb);
    printf(" code: %d, verb: %s\n", code, verb);
    tstnum++;

    code = getkey(&sb, key);
    printf(" code: %d, key: %s\n", code, key);
    tstnum++;

    code = getval(&sb, value, MAXVAL, &count);
    printf(" code: %d, count: %d, values:  \n", code, count);
    for (i=0; i<count; i++)
	printf("    %s\n", value[i]);
    tstnum++;

    code = chkend(&sb);
    tstnum++;

/* TEST 2 */
    printf("\n TEST 2 \n");
    s_copy("menu (A, B, CDE) file = alpha", s);
    initok(&sb, s);

    code = getvrb(&sb, verb);
    printf(" code: %d, verb: %s\n", code, verb);

    code = getval(&sb, value, MAXVAL, &count);
    printf(" code: %d, count: %d, values:  \n", code, count);
    for (i=0; i<count; i++)
	printf("    %s\n", value[i]);

    code = getkey(&sb, key);
    printf(" code: %d, key: %s\n", code, key);

    code = getval(&sb, value, MAXVAL, &count);
    printf(" code: %d, count: %d, values:  \n", code, count);
    for (i=0; i<count; i++)
	printf("    %s\n", value[i]);

    code = chkend(&sb);

/* TEST 3 */
    printf("\n TEST 3 \n");
    s_copy("vrb ,(A,,C,) f,", s);
    initok(&sb, s);

    code = getvrb(&sb, verb);
    printf(" code: %d, verb: %s\n", code, verb);

    code = getval(&sb, value, MAXVAL, &count);
    printf(" code: %d, count: %d, values:  \n", code, count);
    for (i=0; i<count; i++)
	printf("    %s\n", value[i]);

    code = getval(&sb, value, MAXVAL, &count);
    printf(" code: %d, count: %d, values:  \n", code, count);
    for (i=0; i<count; i++)
	printf("    %s\n", value[i]);

    code = getval(&sb, value, MAXVAL, &count);
    printf(" code: %d, count: %d, values:  \n", code, count);
    for (i=0; i<count; i++)
	printf("    %s\n", value[i]);

    code = getval(&sb, value, MAXVAL, &count);
    printf(" code: %d, count: %d, values:  \n", code, count);
    for (i=0; i<count; i++)
	printf("    %s\n", value[i]);

/* TEST 4 */
    printf("\n TEST 4 \n");
    s_copy("(\"aaa\", \"bbb\")", s);
    initok(&sb, s);


    code = getval(&sb, value, MAXVAL, &count);
    printf(" code: %d, count: %d, values:  \n", code, count);
    for (i=0; i<count; i++)
	printf("    %s\n", value[i]);


/* TEST 5 */
    printf("\n TEST 5 \n");	/* white space test		*/
    s_copy("menu (A, B, CDE) file = alpha", s);
    initok(&sb, s);

    code = getvrb(&sb, verb);
    printf(" code: %d, verb: %s\n", code, verb);

    code = getval(&sb, value, MAXVAL, &count);
    printf(" code: %d, count: %d, values:  \n", code, count);
    for (i=0; i<count; i++)
	printf("    %s\n", value[i]);

    code = getkey(&sb, key);
    printf(" code: %d, key: %s\n", code, key);

    code = getval(&sb, value, MAXVAL, &count);
    printf(" code: %d, count: %d, values:  \n", code, count);
    for (i=0; i<count; i++)
	printf("    %s\n", value[i]);

    code = chkend(&sb);


/* USER TEST */
    while (FOREVER)
	{

	printf("\n Enter a string of values:\n");
	t_init(&dum, &dum, &dum);
	t_read(s, &dum);
	initok(&sb, s);


	code = getval(&sb, value, MAXVAL, &count);
	while (code !=EOS && code!=S_SYNERR)
	    {
	    printf(" code: %d, count: %d, values:  \n", code, count);
	    for (i=0; i<count; i++)
		printf("    %s\n", value[i]);
	    code = getval(&sb, value, MAXVAL, &count);
	    }	
	}

    sb.errchr = sb.curchr - 1;
    synerr(&sb, "Test complete");

    exit(TRUE);
    }