Beispiel #1
0
void    CpData(void) {
//================

// Compile DATA statement.

    label_id    end_data;
    int         data_sets;
    bool        error;

    // so that we can issue ST_DATA_TOO_EARLY later
    SgmtSw |= SG_SEEN_DATA;
    error = false;
    data_sets = 0;
    CITNode->opr = OPR_COM; // prevent call to FinishImpDo first time
    end_data = GDataProlog();
    for(;;) {
        DoData();
        error |= AError;
        ++data_sets;
        if( RecNOpn() ) {
            AdvanceITPtr();
            if( RecTrmOpr() )
                break;
            ReqComma();
        }
        if( RecTrmOpr() || error ) {
            break;
        }
    }
    if( !error ) {
        DumpDataSets( data_sets, ITHead );
    }
    GDataEpilog( end_data );
    CITNode->opr = OPR_TRM;
}
void LoadFile(Btree *bt, char *fname)
{
    FILE *infile;
    char buffer[BUFLEN], *s;
    int i = 0, j = 0, retval = TREE_OK;

    if ((infile = fopen(fname, "r")) == NULL) {
        fputs(" Couldn't open the file.\n", stdout);
        return;
    }

    while (fgets(buffer, BUFLEN, infile)) {
        s = buffer + strlen(buffer);
        while(iscntrl(*s))
            *s-- = 0;

        printf("Loading %s\n", buffer);
        if (buffer[0] == ';') /* a comment */
            ;
        else if (buffer[0] == '-' && buffer[1] != 0) {
            retval = DoData(bt, buffer+1, 0);
            if (retval) {
                printf("  --delete failed\n");
                retval = 0;
            }
            else
                j++;
        }
        else {
            retval = DoData(bt, buffer, 1);
            if (retval)
                break;
            i++;
        }
    }

    if (retval)
        printf("Failed at line %s\n", buffer);

    fclose(infile);
    printf("Loaded %d items and deleted %d from %s.\n",
        i, j, fname);
}
Beispiel #3
0
Bool CAdapterFY::Parser(Msg_t& Msg)
{
	Bool rVal        = false;
	S8*  pParsePoint = NULL;
	S8*  pCurPos     = NULL;
	U32  DataLen     = 0;
	U32  PacketLen   = 0;
	Msg.Type = ADP::ADP_CMD_UNKNOW;

	do {
		pParsePoint = m_RcvBuf.FindKey("FYMT", sizeof("FYMT"));
		if (pParsePoint) 
		{
			pCurPos = pParsePoint;
		    DataLen =  m_RcvBuf.GetDataLen();
			if (DataLen < (sizeof(MsgHead_t)))
			{
				break;
			}
			PacketLen = GetPackLen(pParsePoint);
			if (DataLen < PacketLen) 
			{
				break;
			}
			if (!m_RcvBuf.CheckDataLen(PacketLen)) 
			{
				rVal = true;
				pCurPos++;
				break;
			}
			
			if (MW_SUCC != DoData(pParsePoint, Msg)) 
			{
				pCurPos = pParsePoint + 1;
			} 
			else 
			{
				pCurPos = pParsePoint + PacketLen;
			}
			rVal = true;
		}
	} while(0);
	m_RcvBuf.SetParsePos(pCurPos);

	return rVal;
}
Beispiel #4
0
void    DataInit( itnode *var_node ) {
//====================================

// Process data within a type declaration statement.

    label_id    end_data;

    Free2CIT( var_node );
    var_node->opr = OPR_COM;
    CITNode = var_node;
    end_data = GDataProlog();
    DoData();
    if( !AError ) {
        DumpDataSets( 1, var_node );
    }
    GDataEpilog( end_data );
    if( ReqNOpn() ) {
        AdvanceITPtr();
    }
}
main(int argc, char **argv)
{
    char inbuf[BUFLEN], *s;
    Btree *bt = NULL;
    FILE *logfile = NULL;

    for (;;) {
        fflush(stdout);
        fputs("Action (? for help): ", stdout);
        fflush(stdout);
        fgets(inbuf, BUFLEN, stdin);
        s = inbuf + strlen(inbuf);
        while(iscntrl(*s))
            *s-- = 0;

        if (logfile)
            fprintf(logfile, "%s\n", inbuf);

        if (!bt && strchr("@adfkKmMsSwW", inbuf[0])) {
            fputs(" **no open dataset\n", stdout);
            continue;
        }


        switch (inbuf[0]) {
            case '?':
                fputs(
        "@file      - load strings in file into tree\n"
        "a string   - add name;addr to tree\n"
        "d string   - delete name;addr from tree\n"
        "dup [0|1]  - disallow/allow duplicates\n"
        "f string   - find name;addr in tree\n"
        "k/K [file] - display key counts (K = overwrite file)\n"
        "l file     - log actions to file\n"
        "l          - turn off action logging\n"
        "m/M [file] - display block usage map\n"
        "n file     - make a new dataset\n"
        "o file     - open an existing dataset\n"
        "s/S [file] - display tree (S = overwrite file)\n"
        "w/W [file] - walk tree, (W = overwrite file)\n"
        "q          - quit\n"
        , stdout);
                fflush(stdout);
                break;

            case '@':
                LoadFile(bt, inbuf + 1);
                break;

            case 'a':
                if (inbuf[1] != ' ' ||
                    !inbuf[2]       ||
                    !strchr(inbuf,';'))
                    fputs(" Not a valid command\n", stdout);
                else
                    if (DoData(bt, inbuf + 2, 1) == TREE_FAIL)
                        fputs(" ** Insertion failed\n", stdout);
                break;

            case 'd':
                if (inbuf[1] == 'u' && inbuf[2] == 'p') {
                    if (inbuf[3] == ' ' &&
                        (inbuf[4] == '0' || inbuf[4] == '1'))
                        bt -> duplicatesOK =
                        inbuf[4] == '0' ? 0 : 1;
                    fputs("duplicates are ", stdout);
                    if (bt -> duplicatesOK == 0)
                        fputs("not ", stdout);
                    fputs("allowed.\n", stdout);
                    break;
                }

                if (inbuf[1] != ' ' || inbuf[2] == 0)
                    fputs(" Not a valid command\n", stdout);


                else {
                    if (DoData(bt, inbuf + 2, 0) == TREE_FAIL)
                        fputs(" ** Delete failed\n", stdout);
                }
                break;

            case 'f':
                if (inbuf[1] != ' ' || inbuf[2] == 0)
                    fputs(" Not a valid command\n", stdout);
                else {
                    UR record;
                    inbuf[12] = '\0';
                    if (bt_find(bt, &record, inbuf+2) ==
                                                    TREE_FAIL)
                        fputs(" ** Find failed\n", stdout);
                    else
                        fprintf(stdout, "found %s;%s\n",
                                record.name, record.addr);
                }
                break;

            case 'k': case 'K': {
                    FILE *out;

                    if (inbuf[1] == ' ' && inbuf[2] != 0) {
                        out = fopen(inbuf+2,
                                    inbuf[0] == 'k' ? "w" : "a");
                        if (!out)
                            printf("Can't open %s\n", inbuf + 2);
                        else {
                            show_btree(bt, out, 0);
                            fclose(out);
                        }
                    }
                    else
                        show_btree(bt, stdout, 0);
                }
                break;

            case 'l':
                if (inbuf[1] != ' ' || inbuf[2] == 0) {
                    if (logfile) {
                        fclose(logfile);
                        logfile = NULL;
                    }
                    else
                        fputs(" Logfile not open\n", stdout);
                }
                else {
                    logfile = fopen(inbuf + 2, "w");
                    if (logfile == NULL)
                        printf("Can't open %s\n", inbuf + 2);
                }
                break;

            case 'm': case 'M': {
                    FILE *out;

                    if (inbuf[1] == ' ' && inbuf[2] != 0) {
                        out = fopen(inbuf+2, inbuf[0] ==
                                                'm' ? "w" : "a");
                        if (!out)
                            printf("Can't open %s\n", inbuf + 2);
                        else {
                            show_btree_map(bt, out);
                            fclose(out);
                        }
                    }
                    else
                        show_btree_map(bt, stdout);
                }
                break;

            case 'n':
                if (inbuf[1] != ' ' || inbuf[2] == 0)
                    fputs(" Not a valid command\n", stdout);
                else
                    make_dataset(inbuf+2);
                break;

            case 'o':
				if (inbuf[1] != ' ' || inbuf[2] == 0)
                    fputs(" Not a valid command\n", stdout);
                else {
                    if (bt) {
                        if (bt_close(bt))
                            printf("\nClose failed: %s\n",
                                    ErrorText[bt->error_code]);
                        else
                            printf("\nData files closed.\n");

                        bt = NULL;
                    }
					bt = open_dataset(inbuf+2);
                }
                break;

            case 'q':
                if (logfile)
                    fclose(logfile);

                if (bt) {
                    if (bt_close(bt))
                        printf("\nClose failed: %s\n",
                                ErrorText[bt->error_code]);
                    else
                        printf("\nData files closed.\n");
                }
                return;

            case 's': case 'S': {
                    FILE *out;

                    if (inbuf[1] == ' ' && inbuf[2] != 0) {
                        out = fopen(inbuf+2, inbuf[0] ==
                                             's' ? "w" : "a");
                        if (!out)
                            printf("Can't open %s\n", inbuf + 2);
                        else {
                            show_btree(bt, out, 1);
                            fclose(out);
                        }
                    }
                    else
                        show_btree(bt, stdout, 1);
                }
                break;

            case 'w': case 'W': {
                    if (inbuf[1] == ' ' && inbuf[2] != 0) {
                        outfile = fopen(inbuf+2, inbuf[0] ==
                                             'w' ? "w" : "a");
                        if (!outfile)
                            printf("Can't open %s\n", inbuf + 2);
                        else {
                            DataCount = 0;
                            bt_walk(bt, DisplayFunc);
                            fprintf(outfile, "%d items\n",
                                    DataCount);
                            fclose(outfile);
                            outfile = NULL;
                        }
                    }
                    else {
                        DataCount = 0;
                        outfile = stdout;
                        bt_walk(bt, DisplayFunc);
                        fprintf(outfile, "%d items\n",
                                    DataCount);
                        outfile = NULL;
                    }
                }
                break;

            case ';':
                break;  /* comment */

            default:
                fputs(" Not a valid command\n", stdout);
                break;
        }
        if (bt && bt->error_code) {
            printf("ERROR: %s\n", ErrorText[bt->error_code]);
            bt->error_code = 0;
        }
    }
}
Beispiel #6
0
/*  Translate one element.
 *  Arguments:
 *	Pointer to element under consideration.
 *	FILE pointer to where to write output.
 *	Pointer to translation spec for current element, or null.
 */
void
TransElement(
    Element_t	*e,
    FILE	*fp,
    Trans_t	*t
)
{
    int		i;

    if (!t) t = ((e && e->trans) ? e->trans : &NullTrans);

    /* see if we should quit. */
    if (t->quit) {
	fprintf(stderr, "Quitting at location:\n");
	PrintLocation(e, fp);
	fprintf(stderr, "%s\n", t->quit);
	exit(1);
    }

    /* See if we want to replace subtree (do text, don't descend subtree) */
    if (t->replace) {
	ProcesOutputSpec(t->replace, e, fp, 1);
	if (t->message) ProcesOutputSpec(t->message, e, stderr, 0);
	set_and_increment(t);		/* adjust variables, if appropriate */
	return;
    }

    if (t->starttext) ProcesOutputSpec(t->starttext, e, fp, 1);
    if (t->startcode) CallInterpreter(t->startcode, e);
    if (t->message)   ProcesOutputSpec(t->message, e, stderr, 0);

    /* Process data for this node and descend child elements/nodes. */
    if (t->ignore != IGN_ALL) {
	/* Is there a "generated" node at the front of this one? */
	if (e->gen_trans[0]) {
	    Trans_t *tp;
	    if ((tp = FindTranByID(e->gen_trans[0]))) {
		if (tp->starttext) ProcesOutputSpec(tp->starttext, e, fp, 1);
		if (tp->startcode) CallInterpreter(t->startcode, e);
		if (tp->message)   ProcesOutputSpec(tp->message, e, stderr, 0);
		if (tp->endcode)   CallInterpreter(t->endcode, e);
		if (tp->endtext)   ProcesOutputSpec(tp->endtext, e, fp, 1);
	    }
	}
	/* Loop thruthe "nodes", whether data, child element, or PI. */
	for (i=0; i<e->ncont; i++) {
	    if (IsContElem(e,i)) {
		if (t->ignore != IGN_CHILDREN)	/* skip child nodes? */
		    TransElement(ContElem(e,i), fp, NULL);
	    }
	    else if (IsContData(e,i)) {
		if (t->ignore != IGN_DATA)	/* skip data nodes? */
		    DoData(ContData(e,i), fp);
	    }
	    else if (IsContPI(e,i))
		DoPI(e->cont[i].ch.data, fp);
	}
	/* Is there a "generated" node at the end of this one? */
	if (e->gen_trans[1]) {
	    Trans_t *tp;
	    if ((tp = FindTranByID(e->gen_trans[1]))) {
		if (tp->starttext) ProcesOutputSpec(tp->starttext, e, fp, 1);
		if (tp->startcode) CallInterpreter(t->startcode, e);
		if (tp->message)   ProcesOutputSpec(tp->message, e, stderr, 0);
		if (tp->endcode)   CallInterpreter(t->endcode, e);
		if (tp->endtext)   ProcesOutputSpec(tp->endtext, e, fp, 1);
	    }
	}
    }

    set_and_increment(t);		/* adjust variables, if appropriate */

    if (t->endcode) CallInterpreter(t->endcode, e);
    if (t->endtext) ProcesOutputSpec(t->endtext, e, fp, 1);

    e->processed = 1;
}