示例#1
0
int main() {
	char 	line[BUFSIZ];
	int 	row[BUFSIZ];

	int 	opt = 0;
	FILE*	file= NULL;
	//char*	fn 	= NULL;
	int 	ncol= 0;
	int 	tmp = 0;
	graph*	g 	= NULL;
	int*	ap 	= NULL;	// pointer within g->adjmtx
	router*	r 	= NULL;
	int 	fromto[2] = { 0, 0 };
	for (;;) {
		printf("\n%s\n", menu);
		switch (readNat(&opt)) {
		case 0:
			freegraph(&g);
			goto END;
		case 1:
			printf("%s\n", prompt1);
			//fn = readFilename();
			if ((file = fopen(readFilename(), "r")) == NULL) {
				printf("File not found.\n");
				break;
			}
			// file is opened
			while (getaline(line, BUFSIZ, file)) {//printf("while ...\n");
				tmp = 0;
				if ((tmp = linetoints(line, row)) > 0) {
					if (ncol == 0) {// 1st row
						ncol = tmp;
						if (g != NULL)
							freegraph(&g);	// g == NULL
						g = makegraph(ncol);
						ap = g->adjmtx + intcpy(g->adjmtx, row, ncol);
					} else if (ncol == tmp) {
						ap += intcpy(ap, row, ncol);
					} else {
						printf("File content invalid: different number of elements on different rows.\n");
						break;
					}
				}
			}
			ncol = 0;
			fclose(file);
			//if (isvalidgraph(g)) {// graph is created
				printf("Original routing table is as follows:\n");
				printgraph(g);
			/*} else {
				freegraph(&g);
				printf("File content invalid: elements on upper-left to bottom-right diagonal are not all-zero, ");
				printf("or, the upper-right half of the matrix and the bottom-left half are not symmetric.\n");
			}*/
			
			break;
		case 2:
			if (g == NULL) {
				printf("There is no data currently.\nPlease use option 1 to read a routing table data file first.\n");
				break;
			}
			printf("%s\n", prompt2);
			if (readNat(&tmp) < 0 || tmp > g->size) {
				printf("Not a valid router id.\n");
				break;
			}
			r = makerouter(tmp, g->size);
			buildtable(r, g);
			printf("The routing table for router %d is:\n", r->id);
			printrouter(r);
			freerouter(r);
			break;
		case 3:
			if (g == NULL) {
				printf("There is no data currently.\nPlease use option 1 to read a routing table data file first.\n");
				break;
			}
			printf("%s\n", prompt3);
			if (read2Nats(fromto) < 0 || fromto[0] > g->size || fromto[1] > g->size) {
				printf("Invalid input. Please follow the format:\n\tvalid_src_router_id valid_dest_router_id.\n");
				break;
			}
			// fromto[2] is valid
			r = makerouter(fromto[0], g->size);
			dijkstra(g, r->id, r->varray);
			printpath(r, fromto[1]);
			freerouter(r);
			break;
		default:
			printf("%s\n", prompt0);
			break;
		}
	}
END:
	return 0;
}
示例#2
0
文件: vld.c 项目: muromec/qtopia-ezx
//  InitDecodeTable - Generate decoding tables
extern void InitDecodeTable( void )
{
    int minBits;
    
    minBits = 1;    // Codeword strings need to be non-empty
    buildtable( minBits, dct_next, dectable[TAB_DCT_NEXT]);
    buildtable( minBits, dct_first, dectable[TAB_DCT_FIRST]);
    buildtable( minBits, dct_00100, dectable[TAB_DCT_00100]);
    buildtable( minBits, dct_000000, dectable[TAB_DCT_000000]);
    buildtable( minBits, escape_run, dectable[TAB_ESCAPE_RUN]);
    buildtable( minBits, escape_level, dectable[TAB_ESCAPE_LEVEL]);

    buildtable( minBits, intra_dc, dectable[TAB_INTRA_DC]);
    buildtable( minBits, last_intra_dc, dectable[TAB_LAST_INTRA_DC]);

    buildtable( minBits, mba_startcode, dectable[TAB_MBA_STARTCODE]);
    buildtable( minBits, long_mba, dectable[TAB_LONG_MBA]);
    buildtable( minBits, long_startcode, dectable[TAB_LONG_STARTCODE]);

    buildtable( minBits, mtype, dectable[TAB_MTYPE]);
    buildtable( minBits, long_mtype, dectable[TAB_LONG_MTYPE]);

    buildtable( minBits, mvd, dectable[TAB_MVD]);
    buildtable( minBits, long_mvd, dectable[TAB_LONG_MVD]);

    buildtable( minBits, cbp, dectable[TAB_CBP]);
    buildtable( minBits, long_cbp, dectable[TAB_LONG_CBP]);

    buildtable( minBits, quant_tr, dectable[TAB_QUANT_TR]);  //Don't parse strings

    buildtable( minBits, gei_pei, dectable[TAB_GEI_PEI]);
    buildtable( minBits, long_spare, dectable[TAB_LONG_SPARE]);  //Don't parse strings

    buildtable( minBits, gn, dectable[TAB_GN]);
    buildtable( minBits, ptype, dectable[TAB_PTYPE]);    //Don't parse strings

    buildtable( minBits, illegal_state, dectable[TAB_ILLEGAL_STATE]);
    
    // Generate H.263 decoding tables
    buildtable( minBits, mcbpc263,               dectable[TAB263_MCBPC_INTER] );
    buildtable( minBits, long_mcbpc263,          dectable[TAB263_LONG_MCBPC_INTER] );
    buildtable( minBits, long_startcode263,      dectable[TAB263_LONG_STARTCODE] );
    buildtable( minBits, zeros_and_start263,     dectable[TAB263_ZEROS_AND_START] );
    buildtable( minBits, intra_mcbpc263,         dectable[TAB263_MCBPC_INTRA] );
    buildtable( minBits, long_intra_mcbpc263,    dectable[TAB263_LONG_MCBPC_INTRA] );
    buildtable( minBits, modb263,                dectable[TAB263_MODB] );
    buildtable( minBits, cbpy263,                dectable[TAB263_CBPY] );
    buildtable( minBits, intra_cbpy263,          dectable[TAB263_CBPY_INTRA] );
    buildtable( minBits, dquant263,              dectable[TAB263_DQUANT] );
    buildtable( minBits, mvd263,                 dectable[TAB263_MVD] );
    buildtable( minBits, long_mvd263,            dectable[TAB263_LONG_MVD] );
    buildtable( minBits, tcoef,                  dectable[TAB263_TCOEF] );
    buildtable( minBits, tcoef_0001,             dectable[TAB263_TCOEF_0001] );
    buildtable( minBits, tcoef_0000_1,           dectable[TAB263_TCOEF_0000_1] );
    buildtable( minBits, tcoef_0000_0,           dectable[TAB263_TCOEF_0000_0] );
    buildtable( minBits, esc263_run,             dectable[TAB263_ESC_RUN] );
    buildtable( minBits, esc263_level,           dectable[TAB263_ESCAPE_LEVEL] );
    buildtable( minBits, intra263_dc,            dectable[TAB263_INTRA_DC] );
#ifdef DO_H263_PLUS
    buildtable( minBits, modb263plus,            dectable[TAB263PLUS_MODB] );
    buildtable( minBits, intra_mode263plus,      dectable[TAB263PLUS_INTRA_MODE] );
    buildtable( minBits, tcoef_plus,             dectable[TAB263PLUS_TCOEF] );
    buildtable( minBits, tcoef_0001_plus,        dectable[TAB263PLUS_TCOEF_0001] );
    buildtable( minBits, tcoef_0000_1_plus,      dectable[TAB263PLUS_TCOEF_0000_1] );
    buildtable( minBits, tcoef_0000_0_plus,      dectable[TAB263PLUS_TCOEF_0000_0] );
#endif
    minBits = 0;    // Accept empty codeword string (length 0) to produce SYM_EXIT
    buildtable( minBits, finished_263blk,        dectable[TAB263_FINISHED] );
    
    /*{
        int i, ntab;

        printf("\nDiagnostic print of table #: ");
        scanf("%d", &ntab);
        while (ntab >= 0) {
            printf( "Entry    Type  Value  Length  Statechange\n");
            for (i = 0; i < 256; i++) {
                printf( " %3d     %3d    %3d    %3d        %3d\n", i,
                dectable[ntab][i].sym.type, dectable[ntab][i].sym.value,
                dectable[ntab][i].bits, dectable[ntab][i].statechange);
            }
            printf("\nDiagnostic print of table #: ");
            scanf("%d", &ntab);
        }
        
        printf("\nselectdectab:\n");
        for (i = 0; i < NUMSTATES; ++i)
        {
            if (i % 10  ==  0)  printf("\n%3d   ", i);
            if (i % 10  ==  5)  printf("  ");
            printf("%3d", selectdectab[i] );
        }
        printf("\n");
    }*/
    return;
}