Beispiel #1
0
/*****************************************************
  Routine to return a new tag search data structure.
******************************************************/
static TAG_SEARCH *NewTagSearch(char *tagnam_ptr)
{
    static    DESCRIPTOR(top, "TOP");
    static    DESCRIPTOR(colons, "::");
    TAG_SEARCH *ctx = (TAG_SEARCH *) malloc(sizeof(TAG_SEARCH));
    static struct descriptor_d empty = {0, DTYPE_T, CLASS_D, 0};
    struct descriptor tag_dsc = {0, DTYPE_T, CLASS_S, 0};
    unsigned short tree_len;
    char *cptr;
    static unsigned short one = 1;
    tag_dsc.length = strlen(tagnam_ptr);
    tag_dsc.pointer = tagnam_ptr;
    ctx->search_tag = empty;
    ctx->search_tree = empty;
    ctx->next_tag = -1;
    ctx->this_tree_info = 0;
    ctx->remote = 0;
    if (*(char *) tag_dsc.pointer == '\\')
    {
        tag_dsc.length--;
        (char *) tag_dsc.pointer++;
    }
    if ((cptr = strstr(tagnam_ptr,"::")) != 0)
    {
        tree_len = cptr - tagnam_ptr;
        StrCopyR(&ctx->search_tree, &tree_len, tag_dsc.pointer);
        tag_dsc.length -= (tree_len + 2);
        tag_dsc.pointer += (tree_len + 2);
    }
    else
        StrCopyR(&ctx->search_tree, &one, "*");
    if (tag_dsc.length)
        StrCopyDx(&ctx->search_tag, &tag_dsc);
    else
        StrCopyR(&ctx->search_tag, &one, "*");
    StrUpcase(&ctx->search_tree,&ctx->search_tree);
    StrUpcase(&ctx->search_tag,&ctx->search_tag);
    ctx->top_match = StrMatchWild(&top, &ctx->search_tag) & 1;
    return ctx;
}
Beispiel #2
0
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
int ShowModule()
{
	char	db_tmp[64];		// enough space for a logical name and a cstring terminator	[2002.02.20]
	int 	i, numOfEntries, status = SUCCESS;

	static DESCRIPTOR( physical, "PHYSICAL" );
	static DESCRIPTOR( module_p, "MODULE" );
	static DESCRIPTOR( format_p, "FORMAT" );
	static DESCRIPTOR( blank, " " );

	static DESCRIPTOR( heading1, "  #  Logical Name                     Physical   Comment" );	// header
	static DESCRIPTOR( heading2, "==== ================================ ========== ========================================" );

	static DYNAMIC_DESCRIPTOR( wild );
	struct Module_	Mod, *pMod;
	
	struct descriptor pattern;

	int format = cli_present(&format_p) & 1;
	int physical_name = cli_present(&physical) & 1;	// 2002.01.16

	cli_get_value( &module_p, &wild );
	StrUpcase( &wild, &wild );						// convert to upper case

	if( MSGLVL(DETAILS) )
		printf("ShowModule(): in %s order\n", (physical_name) ? "physical" : "logical" );

	// check to see if db file memory mapped
	if( CTSdbFileIsMapped == FALSE ) {				// is not, so try
		if( map_data_file(CTS_DB) != SUCCESS ) {	// we're dead in the water
			if( MSGLVL(IMPORTANT) )
				fprintf( stderr, "error memory mapping database file\n" );

			status = FAILURE;		// MAP_ERROR;		[2001.07.12]
			goto Showmodule_Exit;
		}
	}

	// db file now mapped, continue
	pMod = &Mod;										// point to some actual storage
	if( (numOfEntries = get_file_count(CTS_DB)) > 0 ) {	// something to show
		printf( "%s\n",   heading1.pointer );
		printf( "%s%d\n", heading2.pointer, numOfEntries );
		for( i = 0; i < numOfEntries; i++ ) {
			parse_cts_db( CTSdb+i, pMod );		// extract info from db

			memset(db_tmp, ' ', 32);
			db_tmp[33] = '\0';

			if( physical_name ) 		// duh, physical name
				sprintf( db_tmp, "GK%c%d%02d:N%d", 
					pMod->adapter + 'A', pMod->id, pMod->crate, pMod->slot
					);
			else
				sprintf( db_tmp, "%s", pMod->name );

			pattern.pointer = db_tmp;
			pattern.length  = strlen(db_tmp);

			if( StrMatchWild( &pattern, &wild ) & 1 ) {
//				printf( "%s%3d: %.84s<%s\n", CYAN, i+1, (char *)CTSdb+(i * MODULE_ENTRY), NORMAL );	// fancy, with color
				printf( "%3d: %.84s<\n", i+1, (char *)CTSdb+(i * MODULE_ENTRY) );
			}

		} // end of for() loop

		printf( "%s\n", heading2.pointer );
	}
	else {
		if( MSGLVL(IMPORTANT) )
			fprintf( stderr, "db file is empty, no modules to show\n" );

		status = SUCCESS;		// Not necessarily an ERROR;	[2002.02.19]
		goto Showmodule_Exit;
	}
	
Showmodule_Exit:
	if( MSGLVL(DETAILS) ) {
		printf("ShowModule(): "); ShowStatus(status);
	}

	return status;
}
Beispiel #3
0
//-------------------------------------------------------------------------
// deassign a module
//-------------------------------------------------------------------------
int Deassign()
{
	char			db_tmp[64];
	int 			i, index, modulesToDeassign, modulesDeassigned, numOfEntries, physical_name; 
	int				status = SUCCESS;
	struct Module_	Mod, *pMod;

	static DESCRIPTOR( physical, "PHYSICAL" );

	static DESCRIPTOR( modname_p, "MODULE" );
	static DYNAMIC_DESCRIPTOR( modname );

	static DYNAMIC_DESCRIPTOR( wild );

	struct descriptor pattern;

	// get user data
	cli_get_value( &modname_p, &wild );
	StrUpcase( &wild, &wild );

	physical_name = cli_present(&physical) & 1;

	if( MSGLVL(DETAILS) )
		printf("Deassign(): %s module: <%s>\n", physical_name ? "physical" : "logical", wild.pointer);

	// check to see if db file memory mapped
	if( CTSdbFileIsMapped == FALSE ) {				// is not, so try ...
		if( map_data_file(CTS_DB) != SUCCESS ) {	// we're dead in the water
			status = MAP_ERROR;						// [2002.02.21]
			goto Deassign_Exit;
		}
	}

	// get number of current entries
	if( (numOfEntries = get_file_count(CTS_DB)) == 0 ) {	// no entries in cts db file
		if( MSGLVL(IMPORTANT) )
			fprintf( stderr, "db file empty, no entries to remove\n" );

		status = DEASSIGN_ERROR;					// [2002.02.21]
		goto Deassign_Exit;
	}

	// if we get this far, then there are modules in the database
	modulesToDeassign = modulesDeassigned = 0;	// initialize counts
	pMod = &Mod;				// point to some actual storage

	// first, we need to count the number to deassign ...
	for( i = 0; i < numOfEntries; ++i ) {	// scan entire list
		// look up module name(s). NB! more than one logical name may be
		// assigned to the same, unique physical name.
		parse_cts_db( CTSdb+i, pMod );		// extract info from db

		memset(db_tmp, ' ', 32);	// clear out buffer
		db_tmp[33] = '\0';			// ensure buffer 'ends'

		if( physical_name ) 		// physical name
			sprintf( db_tmp, "GK%c%d%02d:N%d",
				pMod->adapter + 'A', 
				pMod->id, 
				pMod->crate,
				pMod->slot
				);
		else 						// logical name 
			sprintf( db_tmp, "%s", pMod->name );

		// prepare for 'wild' match
		pattern.pointer = db_tmp;
		pattern.length  = strlen(db_tmp);

		if( StrMatchWild( &pattern, &wild ) & 1 ) {
			++modulesToDeassign;	//
		}
	} // end of for() loop, all entries checked

	// now actually remove them
	while( modulesToDeassign ) {
		for( i = 0; i < get_file_count(CTS_DB); ++i ) {
			// look up module name(s). NB! more than one logical name may be
			// assigned to the same, unique physical name.
			parse_cts_db( CTSdb+i, pMod );		// extract info from db

			memset(db_tmp, ' ', 32);	// clear out buffer
			db_tmp[33] = '\0';			// ensure buffer 'ends'

			if( physical_name ) 		// physical name
				sprintf( db_tmp, "GK%c%d%02d:N%d",
					pMod->adapter + 'A', 
					pMod->id, 
					pMod->crate,
					pMod->slot
					);
			else 						// logical name 
				sprintf( db_tmp, "%s", pMod->name );

			// prepare for 'wild' match
			pattern.pointer = db_tmp;
			pattern.length  = strlen(db_tmp);

			if( StrMatchWild( &pattern, &wild ) & 1 ) {
				if( remove_entry(CTS_DB, i) != SUCCESS ) {	// removal failed
					status = DEASSIGN_ERROR;				// [2002.02.21]
					goto Deassign_Exit;
				}
				else 
					++modulesDeassigned;	// keep track of successes :)
			}
		}

		--modulesToDeassign;				// one less to remove ...
	}

Deassign_Exit:
	if( MSGLVL(DETAILS) ) {
		printf("Deassign(%d): ", modulesDeassigned); ShowStatus(status);
	}

	return status;
}