示例#1
0
文件: lines.c 项目: CivilPol/sdcboot
// draw a box directly to display memory
int _near Drawbox_Cmd( LPTSTR pszCmdLine )
{
	register TCHAR *pszArg, *pszLine;
	int nTop, nLeft, nBottom, nRight, nStyle, nAttribute = -1, nFill = -1, n, nFlags = 0, nShade;

	if (( pszCmdLine == NULL ) || ( *pszCmdLine == _TEXT('\0') ))
		return ( Usage( DRAWBOX_USAGE ));

	// get the arguments & colors
	if ( sscanf( pszCmdLine, _TEXT("%d%d%d%d%d%n"), &nTop, &nLeft, &nBottom, &nRight, &nStyle, &n ) == 6 ) {

		pszLine = pszCmdLine + n;
		nAttribute = GetColors( pszLine, 0 );

		// check for a FILL color
		if (( *pszLine ) && ( _strnicmp( first_arg( pszLine ), BOX_FILL, 3 ) == 0 ) && (( pszArg = first_arg( next_arg( pszLine, 1 ))) != NULL )) {

			if ( _strnicmp( pszArg, BRIGHT, 3 ) == 0 ) {
				// set intensity bit
				nFill = 0x80;
				if (( pszArg = first_arg( next_arg( pszLine, 1 ))) == NULL )
					return ( Usage( DRAWBOX_USAGE ));
			} else
				nFill = 0;

			if (( nShade = color_shade( pszArg )) <= 15 ) {
				nFill |= ( nShade << 4 );
				next_arg( pszLine, 1 );
			}
		}

		// check for a SHADOW or ZOOM
		while ( *pszLine ) {
			if ( _strnicmp( pszLine, BOX_SHADOW, 3 ) == 0 )
				nFlags |= BOX_SHADOWED;
			else if ( _strnicmp( pszLine, BOX_ZOOM, 3 ) == 0 )
				nFlags |= BOX_ZOOMED;
			next_arg( pszLine, 1 );
		}
	}

	if (( nAttribute == -1 ) || ( verify_row_col( nTop, nLeft )) || ( verify_row_col( nBottom, nRight )))
		return ( Usage( DRAWBOX_USAGE ));

	if ( nLeft == 999 ) {
		if (( nLeft = (( GetScrCols() - nRight ) / 2 )) < 0 )
			nLeft = 0;
		nRight += nLeft;
	}

	if ( nTop == 999 ) {
		if (( nTop = (( GetScrRows() - nBottom ) / 2 )) < 0 )
			nTop = 0;
		nBottom += nTop;
	}

	_box( nTop, nLeft, nBottom, nRight, nStyle, nAttribute, nFill, nFlags, 1 );

	return 0;
}
示例#2
0
v8::Handle<v8::Value> Rename(const v8::Arguments& args) {
  v8::HandleScope scope;
  if (args.Length() != 2) {
    ThrowException(v8::Exception::TypeError(v8::String::New("Wrong number of arguments")));
    return scope.Close(v8::Undefined());
  }
  if (!args[0]->IsString() ) {
    ThrowException(v8::Exception::TypeError(v8::String::New("switcher create: Wrong first arg type")));
    return scope.Close(v8::Undefined());
  }
  v8::String::AsciiValue first_arg(args[0]->ToString());

  if (!args[1]->IsString()) {
    ThrowException(v8::Exception::TypeError(v8::String::New("switcher create: Wrong second arg type")));
    return scope.Close(v8::Undefined());
  }
  v8::String::AsciiValue second_arg(args[1]->ToString());

  v8::Local<v8::String> name;
  
  v8::Handle<v8::Boolean> res = 
    v8::Boolean::New(switcher_container[0]->rename(std::string(*first_arg), 
						   std::string(*second_arg)));

  return scope.Close(res);
}
示例#3
0
// draw a box directly to display memory
int drawbox_cmd(int argc, char **argv)
{
	char *arg, *pszLine;
	int top, left, bottom, right, style, attribute = -1, fill = -1;
	int box_flags = 0;

	// get the arguments & colors
	if ((argc >= 7) && (sscanf(argv[1],"%d%d%d%d%d",&top,&left,&bottom,&right,&style) == 5)) {

		pszLine = argv[6];
		attribute = GetColors(pszLine,0);

		// check for a FILL color
		if ((*pszLine) && (_strnicmp(first_arg(pszLine),BOX_FILL,3) == 0) && ((arg = first_arg(next_arg(pszLine,1))) != NULL)) {

			if (_strnicmp(arg,BRIGHT,3) == 0) {
				// set intensity bit
				fill = 0x80;
				if ((arg = first_arg(next_arg(pszLine,1))) == NULL)
					return (usage(DRAWBOX_USAGE));
			} else
				fill = 0;

			if ((argc = color_shade(arg)) <= 15) {
				fill |= (argc << 4);
				(void)next_arg(pszLine,1);
			}
		}

		// check for a SHADOW or ZOOM
		while (*pszLine) {
			if (_strnicmp(pszLine,BOX_SHADOW,3) == 0)
				box_flags |= BOX_SHADOWED;
			else if (_strnicmp(pszLine,BOX_ZOOM,3) == 0)
				box_flags |= BOX_ZOOMED;
			(void)next_arg(pszLine,1);
		}
	}

	if ((attribute == -1) || (verify_row_col(top,left)) || (verify_row_col(bottom,right)))
		return (usage(DRAWBOX_USAGE));

	_box(top,left,bottom,right,style,attribute,fill,box_flags,1);

	return 0;
}
示例#4
0
文件: env.c 项目: ErisBlastar/osfree
// remove environment variable(s) or aliases
int unset_cmd( int argc, char **argv )
{
    char *arg;
    int i, rval = 0;
    long fUnset;
    PCH pchList;

    // set the pointer to either the environment or the alias list
    if ( _stricmp( gpInternalName, UNSET_COMMAND ) == 0 )  {

        pchList = 0L;

    } else
        pchList = glpAliasList;

    // strip leading switches
    if (( GetSwitches( argv[1], "MQR", &fUnset, 1 ) != 0 ) || ( first_arg( argv[1] ) == NULL ))
        return ( usage(( pchList == glpAliasList ) ? UNALIAS_USAGE : UNSET_USAGE ));

    // check for master environment set
    if (( pchList == 0L ) && ( fUnset & UNSET_MASTER ))
        pchList = glpMasterEnvironment;

    // read environment or alias file(s)
    if ( fUnset & UNSET_READ )
        return ( SetFromFile( argv[1], pchList, 1 ));

    for ( i = 0; (( arg = ntharg( argv[1], i )) != NULL ); i++ ) {

        if ( _stricmp( arg, "*" ) == 0 ) {

            // wildcard kill - null the environment or alias list
            if ( pchList == 0L )
                pchList = glpEnvironment;
            pchList[0] = '\0';
            pchList[1] = '\0';
            break;
        }

        // kill the variable or alias
        if ( get_list( arg, pchList ) == 0L ) {

            // check for "quiet" switch
            if ( fUnset & UNSET_QUIET )
                rval = ERROR_EXIT;
            else
                rval = error((( pchList == glpAliasList ) ? ERROR_4DOS_NOT_ALIAS : ERROR_4DOS_NOT_IN_ENVIRONMENT ), arg );

        } else if ( add_list( arg, pchList ) != 0)
            rval = ERROR_EXIT;
    }

    return rval;
}
示例#5
0
文件: env.c 项目: ErisBlastar/osfree
// edit an existing environment variable or alias
int eset_cmd( int argc, char **argv )
{
    char *arg;
    int nLength;
    int i, rval = 0;
    long fEset;
    PCH vname, feptr, pchList;
    unsigned char buffer[CMDBUFSIZ];

    // check for alias or master environment switches
    if (( GetSwitches( argv[1], "AM", &fEset, 1 ) != 0 ) || ( first_arg( argv[1] ) == NULL ))
        return ( usage( ESET_USAGE ));

    for ( i = 0; (( arg = ntharg( argv[1], i )) != NULL ); i++ ) {

        pchList = (( fEset & ESET_MASTER ) ? glpMasterEnvironment : glpEnvironment );

        // try environment variables first, then aliases
        if (( fEset & ESET_ALIAS ) || (( feptr = get_list( arg, pchList )) == 0L)) {

            // check for alias editing
            if (( feptr = get_list( arg, glpAliasList )) == 0L ) {
                rval = error((( fEset & ESET_ALIAS ) ? ERROR_4DOS_NOT_ALIAS : ERROR_4DOS_NOT_IN_ENVIRONMENT ), arg );
                continue;
            }

            pchList = glpAliasList;
        }

        // get the start of the alias or variable name
        for ( vname = feptr; (( vname > pchList ) && ( vname[-1] != '\0' )); vname-- )
            ;

        // length of alias/variable name
        nLength = (int)( feptr - vname );

        sprintf( buffer, "%.*Fs%.*Fs", nLength, vname, (( CMDBUFSIZ - 1 ) - nLength), feptr );

        // echo & edit the argument
        printf( FMT_FAR_PREC_STR, nLength, vname );
        (void)egets( buffer + nLength, (( CMDBUFSIZ - 1 ) - nLength ), EDIT_ECHO );

        if ( add_list( buffer, pchList ) != 0 )
            rval = ERROR_EXIT;
    }

    return rval;
}
示例#6
0
// ----------- life management
v8::Handle<v8::Value> Remove(const v8::Arguments& args) {
  v8::HandleScope scope;
  if (args.Length() != 1) {
    ThrowException(v8::Exception::TypeError(v8::String::New("Wrong number of arguments")));
    return scope.Close(v8::Undefined());
  }
  if (!args[0]->IsString() ) {
    ThrowException(v8::Exception::TypeError(v8::String::New("switcher remove: Wrong first arguments type")));
    return scope.Close(v8::Undefined());
  }
  v8::String::AsciiValue first_arg(args[0]->ToString());
  if (switcher_container[0]->remove(std::string(*first_arg)))
    return v8::Boolean::New(true);
  else
    return v8::Boolean::New(false);
}
示例#7
0
文件: fun.cpp 项目: 1Hyena/multiplay
static void do_provide(USER *u, const char *arg) {
    char pass[32];
    char comment[256];
    MANAGER *m = u->manager;

    int user_id = u->get_id();
    VARSET user_vs;
    u->manager->get_vs(user_id,  &user_vs);

    if (u->manager->instance_exists(user_vs.geti("shell_id"))) {
        u->send("You cannot provide a shell while being switched into another shell.\n\r");
        return;
    }

    arg = first_arg(arg, pass, sizeof(pass));
    std::snprintf(comment, sizeof(comment), "%s", arg);

    std::string host = u->get_host();
    std::string port = u->get_port();

    int shell = m->instance_create("shell");
    m->set(shell, "host",       host.c_str());
    m->set(shell, "port",       port.c_str());
    m->set(shell, "password",   pass);
    m->set(shell, "comment",    comment);
    m->set(shell, "user_id",    user_id);
    if (!m->instance_activate(shell)) {
        u->send("Failed to create a new shell.\n\r");
        return;
    }

    INSTANCE *ins = m->instance_find(user_id);
    if (ins && ins->user) {
        if (ins->user->has_prompt()) ins->user->toggle_prompt();
        if (!ins->user->is_server()) ins->user->toggle_server();
    }

    m->set(user_id, "shell_id", shell);
    log("User %d becomes a shell %d (%s:%s).", user_id, shell, host.c_str(), port.c_str());
}
示例#8
0
void process_resolve( DESC_DATA *d )
{
    char buffer[INPUT];
    char address[INPUT];
    char *user;
    int status;

    buffer[0] = '\0';

    if (!read_from_resolve(d->ifd, buffer) || IS_NULL(buffer))
	return;

    user = first_arg(buffer, address, FALSE);

    if (!IS_NULL(user))
    {
	if (d->ident) free_string(d->ident);
	d->ident = str_dup(user);
    }

    if (!IS_NULL(address))
    {
	if (d->host) free_string(d->host);
	d->host = str_dup(address);
	if (USR(d) && USR(d)->host_name)
	    free_string(USR(d)->host_name);
	USR(d)->host_name = str_dup(address);
	get_small_host(USR(d));
    }

    close(d->ifd);
    d->ifd = -1;
    waitpid(d->ipid, &status, WNOHANG);
    d->ipid = -1;

/*    resolve_kill(d); */
    return;
}
示例#9
0
文件: fun.cpp 项目: 1Hyena/multiplay
static void do_alarm(USER *u, const char *arg) {
    char pulse[8];
    int pulse_int = 0;
    int shift_int = 0;
    
    if (strlen(arg) > 0) {
        arg = first_arg(arg, pulse, sizeof(pulse));

        if (!str2int(pulse, &pulse_int, 10) || pulse_int < 0) {
            u->sendf("Alarm length '%s' is neither a positive integer nor zero.\n\r", pulse);
            return;
        }

        if (strlen(arg) > 0) {
            if (!str2int(arg, &shift_int, 10)) {
                u->sendf("Alarm shift '%s' is not an integer.\n\r", arg);
                return;
            }
        }
        else if (pulse_int > 0) {
            // Adjust the shift so that the alarm would go off immediately.
            shift_int = u->manager->get_pulse() % pulse_int + 1;
        }
    }

    u->manager->set(u->get_id(), "alarm_pulse", pulse_int);
    u->manager->set(u->get_id(), "alarm_shift", shift_int);

    if (pulse_int == 0) {
        u->send("Alarm disabled.\n\r");
        return;
    }

    if (shift_int != 0) u->sendf("Alarm set for every %d. pulse (correction %d).\n\r", pulse_int, shift_int);
    else                u->sendf("Alarm set for every %d. pulse.\n\r", pulse_int);
}
示例#10
0
文件: env.c 项目: ErisBlastar/osfree
// create or display environment variables or aliases
int set_cmd( int argc, char **argv )
{
    char *arg;
    long fSet;
    PCH feptr, pchList;
    char szBuffer[CMDBUFSIZ];

    init_page_size();

    // set the pointer to either the environment or the alias list
    if ( _stricmp( gpInternalName, SET_COMMAND ) == 0 )  {

        pchList = 0L;

    } else
        pchList = glpAliasList;

    // strip leading switches
    if (( GetSwitches( argv[1], "AMPR", &fSet, 1 ) != 0) || (( fSet & SET_READ ) && ( first_arg( argv[1] ) == NULL )))
        return ( usage(( pchList == glpAliasList ) ? ALIAS_USAGE : SET_USAGE ));

    // check for master environment set
    if (( pchList == 0L ) && ( fSet & SET_MASTER ))
        pchList = glpMasterEnvironment;

    // read environment or alias file(s)
    if ( fSet & SET_READ )
        return ( SetFromFile( argv[1], pchList, 0 ));

    // pause after each page
    if ( fSet & SET_PAUSE ) {
        gnPageLength = GetScrRows();
    }

    if ( first_arg( argv[1] ) == NULL ) {

        if ( pchList == 0L )
            pchList = glpEnvironment;

        // print all the variables or aliases
        for ( feptr = pchList; ( *feptr != '\0' ); feptr = next_env( feptr ) ) {
            more_page( feptr, 0 );
        }

        if ( pchList == glpEnvironment ) {

            if (( arg = get_list( BEGINLIBPATH, pchList )) != 0L ) {
                sprintf( szBuffer, FMT_TWO_EQUAL_STR, BEGINLIBPATH, arg );
                more_page( szBuffer, 0 );
            }

            if (( arg = get_list( ENDLIBPATH, pchList )) != 0L ) {
                sprintf( szBuffer, FMT_TWO_EQUAL_STR, ENDLIBPATH, arg );
                more_page( szBuffer, 0 );
            }
        }

        // return an error message if no aliases exist
        // just return if no environment variables exist
        return (( feptr == glpAliasList ) ? error( ERROR_4DOS_NO_ALIASES, NULL ) : 0 );
    }

    if ( fSet & SET_EXPRESSION ) {

        if (( arg = strchr( argv[1], '=' )) != NULL )
            arg = skipspace( ++arg );
        else
            arg = argv[1];

        evaluate( arg );
        if ( cv.bn < 0 )
            qputs( arg );

        // create/modify/delete a variable
        return (( arg == argv[1] ) ? 0 : add_list( argv[1], pchList ));
    }

    // display the current variable or alias argument?
    // (setting environment vars requires a '='; it's optional with aliases)
    if ((( arg = strchr( argv[1], '=' )) == NULL ) && (( pchList == 0L ) || ( ntharg( argv[1], 1 ) == NULL ))) {

        if (( feptr = get_list( argv[1], pchList )) == 0L ) {
            return ( error((( pchList == glpAliasList ) ? ERROR_4DOS_NOT_ALIAS : ERROR_4DOS_NOT_IN_ENVIRONMENT),argv[1]));
        }

        printf( FMT_FAR_STR_CRLF, feptr );
        return 0;
    }

    // create/modify/delete a variable or alias
    return ( add_list( argv[1], pchList ));
}
示例#11
0
文件: fun.cpp 项目: 1Hyena/multiplay
static void do_connect(USER *u, const char *arg) {
    char host[256];
    char port[8];
    char pass[32];
    char comment[256];
    arg = first_arg(arg, host, sizeof(host));
    arg = first_arg(arg, port, sizeof(port));
    arg = first_arg(arg, pass, sizeof(pass));
    std::snprintf(comment, sizeof(comment), "%s", arg);

    int port_int;
    if (!str2int(port, &port_int, 10) || port_int <= 0) {
        u->sendf("Port number '%s' is not a positive integer.\n\r", port);
        return;
    }

    if (port_int > 65535) {
        u->sendf("Port number '%s' exceeds 65535.\n\r", port);
        return;
    }

    std::snprintf(port, sizeof(port), "%d", port_int);
    MANAGER *m = u->manager;

    int d = sockets.connect(host, port);
    if (d <= 0) {
        u->sendf("Failed to connect to %s:%s.\n\r", host, port);
        return;
    }

    log("New connection %d to %s:%s.", d, host, port);

    int new_user_id = m->instance_create("user");
    if (new_user_id) {
        m->set(new_user_id, "host", host);
        m->set(new_user_id, "port", port);
        m->set(new_user_id, "descriptor", d);
        m->instance_activate(new_user_id);
        INSTANCE *ins = m->instance_find(new_user_id);
        if (ins && ins->user) {
            ins->user->disable_greet();
            if (ins->user->has_prompt()) ins->user->toggle_prompt();
            if (!ins->user->is_server()) ins->user->toggle_server();
        }
        log("Created user %d (descriptor %d).", new_user_id, d);
    }
    else {
        log("Unable to create a user (descriptor %d).", d);
        sockets.disconnect(d);
        return;
    }

    int shell = m->instance_create("shell");
    m->set(shell, "host",       host);
    m->set(shell, "port",       port);
    m->set(shell, "password",   pass);
    m->set(shell, "comment",    comment);
    m->set(shell, "user_id",    new_user_id);
    m->set(shell, "persistent", true);

    if (!m->instance_activate(shell)) {
        u->send("Failed to create a new shell.\n\r");
        sockets.disconnect(d);
        return;
    }

    m->set(new_user_id, "shell_id", shell);
    log("Created shell %d (%s:%s).", shell, host, port);
    u->sendf("Established a new %s connection to %s:%s as shell %d.\n\r", pass[0] ? "private" : "public", host, port, shell);
    if (pass[0]) u->sendf("You can only switch into this private shell by typing 'switch %s'.\n\r", pass);
}
示例#12
0
文件: listc.c 项目: CivilPol/sdcboot
// edit or display a file with vertical & horizontal scrolling & text searching
int _near List_Cmd( LPTSTR pszCmdLine )
{
	int nFVal, nReturn = 0, argc;
	TCHAR szSource[MAXFILENAME+1], szFileName[MAXFILENAME+1], *pszArg;
	FILESEARCH dir;

	memset( &dir, '\0', sizeof(FILESEARCH) );
	
	// check for and remove switches
	if ( GetRange( pszCmdLine, &(dir.aRanges), 0 ) != 0 )
		return ERROR_EXIT;
	
	// check for /T"search string"
	GetMultiCharSwitch( pszCmdLine, _TEXT("T"), szSource, 255 );
	if ( szSource[0] == _TEXT('"') )
		sscanf( szSource+1, _TEXT("%79[^\"]"), szListFindWhat );
	else if ( szSource[0] )
		sprintf( szListFindWhat, FMT_PREC_STR, 79, szSource );
	
	if ( GetSwitches( pszCmdLine, _TEXT("*HIRSWX"), &lListFlags, 0 ) != 0 )
		return ( Usage( LIST_USAGE ));
	
	if ( szSource[0] )
		lListFlags |= LIST_SEARCH;
	
	// check for pipe to LIST w/o explicit /S switch
	if ( first_arg( pszCmdLine ) == NULL ) {

		if ( _isatty( STDIN ) == 0 )

				lListFlags |= LIST_STDIN;
			else if (( lListFlags & LIST_STDIN ) == 0 )
				return ( Usage( LIST_USAGE ));
	}
	
	// initialize buffers & globals
	
	if ( ListInit() )
		return ERROR_EXIT;
	nCurrent = nStart = 0;
	
	// ^C handling
	if ( setjmp( cv.env ) == -1 ) {
list_abort:
		FindClose( dir.hdir );
		Cls_Cmd( NULL );
		nReturn = CTRLC;
		goto list_bye;
	}
	
RestartFileSearch:
	for ( argc = 0; ; argc++ ) {
		
		// break if at end of arg list, & not listing STDIN
		if (( pszArg = ntharg( pszCmdLine, argc )) == NULL ) {
			if (( lListFlags & LIST_STDIN ) == 0 )
				break;
		} else
			strcpy( szSource, pszArg );
		
		for ( nFVal = FIND_FIRST; ; ) {
			
			szClip[0] = _TEXT('\0');
			
			// if not reading from STDIN, get the next matching file
			if (( lListFlags & LIST_STDIN ) == 0 ) {
				
				// qualify filename
				if ( nFVal == FIND_FIRST ) {
					mkfname( szSource, 0 );
					if ( is_dir( szSource ))
						mkdirname( szSource, WILD_FILE );
				}

				if ( stricmp( szSource, CLIP ) == 0 ) {
					
					RedirToClip( szClip, 99 );
					if ( CopyFromClipboard( szClip ) != 0 )
						break;
					strcpy( szFileName, szClip );
					
				} else if ( QueryIsPipeName( szSource )) {
					
					// only look for pipe once
					if ( nFVal == FIND_NEXT )
						break;
					copy_filename( szFileName, szSource );
					
				} else if ( find_file( nFVal, szSource, ( FIND_BYATTS | FIND_RANGE | FIND_EXCLUDE | 0x07), &dir, szFileName ) == NULL ) {
					nReturn = (( nFVal == FIND_FIRST ) ? ERROR_EXIT : 0 );
					break;
					
				} else if ( nStart < nCurrent ) {
					nStart++;
					nFVal = FIND_NEXT;
					continue;
					
				} else if ( dir.ulSize > 0L )
					LFile.lSize = dir.ulSize;
			}
			
			// clear the screen (scrolling the buffer first to save the current screen)

			Cls_Cmd( NULL );
			
			if (( nReturn = _list( szFileName )) == CTRLC )
				goto list_abort;
			
			if ( szClip[0] )
				remove( szClip );
			
			if ( nReturn != 0 )
				break;
			
			SetCurPos( nScreenRows, 0 );
			
			if (( szClip[0] ) || ( lListFlags & LIST_STDIN ))
				break;

			if ( LFile.hHandle > 0 )
				_close( LFile.hHandle );
			LFile.hHandle = -1;
			
			// increment index to current file
			if ( nCurrent < nStart ) {
				FindClose( dir.hdir );
				nStart = 0;
				goto RestartFileSearch;
			} else {
				nFVal = FIND_NEXT;
				nCurrent++;
				nStart++;
			}
		}
		
		// we can only read STDIN once!
		lListFlags &= ~LIST_STDIN;
	}
	
	crlf();
list_bye:
	FreeMem( LFile.lpBufferStart );
	if ( LFile.hHandle > 0 )
		_close( LFile.hHandle );
	LFile.hHandle = -1;
	
	return nReturn;
}
示例#13
0
文件: env.c 项目: CivilPol/sdcboot
// edit an existing environment variable or alias
int _near Eset_Cmd( LPTSTR pszCmdLine )
{
	LPTSTR pszArg;
	register int nLength;
	int i, nReturn = 0;
	long fEset;
	TCHAR _far *lpszVarName, _far *lpszVars, _far *pchList;
	TCHAR szBuffer[CMDBUFSIZ];

	// check for alias or master environment switches
	if (( GetSwitches( pszCmdLine, _TEXT("AFM"), &fEset, 1 ) != 0 ) || ( first_arg( pszCmdLine ) == NULL ))
		return ( Usage( ESET_USAGE ));

	for ( i = 0; (( pszArg = ntharg( pszCmdLine, i )) != NULL ); i++ ) {

		pchList = (( fEset & ESET_MASTER ) ? glpMasterEnvironment : glpEnvironment );

		// function edit request?
		if ( fEset & ESET_FUNCTION ) {

			pchList = glpFunctionList;
			if (( lpszVars = get_list( pszArg, pchList )) == 0L ) {
				nReturn = error( ERROR_4DOS_NOT_FUNCTION, pszArg );
				continue;
			}

		} else {

			// try environment variables first, then aliases
			if (( fEset & ESET_ALIAS ) || (( lpszVars = get_list( pszArg, pchList )) == 0L )) {

				// check for alias editing
				if (( lpszVars = get_list( pszArg, glpAliasList )) == 0L ) {
					nReturn = error((( fEset & ESET_ALIAS ) ? ERROR_4DOS_NOT_ALIAS : ERROR_4DOS_NOT_IN_ENVIRONMENT ), pszArg );
					continue;
				}

				pchList = glpAliasList;
			}

		}

		// get the start of the alias / function / variable name
		for ( lpszVarName = lpszVars; (( lpszVarName > pchList ) && ( lpszVarName[-1] != _TEXT('\0') )); lpszVarName-- )
			;

		// length of alias/function/variable name
		nLength = (int)( lpszVars - lpszVarName );

		sprintf( szBuffer, _TEXT("%.*Fs%.*Fs"), nLength, lpszVarName, (( CMDBUFSIZ - 1 ) - nLength), lpszVars );

		// echo & edit the argument
		printf( FMT_FAR_PREC_STR, nLength, lpszVarName );
		egets( szBuffer + nLength, (( CMDBUFSIZ - 1 ) - nLength ), EDIT_ECHO | EDIT_SCROLL_CONSOLE );

		if ( add_list( szBuffer, pchList ) != 0 )
			nReturn = ERROR_EXIT;
	}

	return nReturn;
}
示例#14
0
文件: env.c 项目: CivilPol/sdcboot
// remove environment variable(s) or aliases
int _fastcall __Unset( LPTSTR pszCmdLine, char _far *pchList )
{
	register LPTSTR pszArg;
	register int i, nReturn = 0;
	long fUnset;
	TCHAR _far *lpszVars;

	// strip leading switches
	if (( GetSwitches( pszCmdLine, "MQR", &fUnset, 1 ) != 0 ) || ( first_arg( pszCmdLine ) == NULL ))
		return USAGE_ERR;

	// check for master environment set
	if (( pchList == glpEnvironment ) && ( fUnset & UNSET_MASTER ))
		pchList = glpMasterEnvironment;

	// read environment or alias file(s)
	if ( fUnset & UNSET_READ )
		return ( SetFromFile( pszCmdLine, pchList, ( fUnset & ( UNSET_DEFAULT | UNSET_SYSTEM | UNSET_USER | UNSET_VOLATILE )) | 1 ));

	for ( i = 0; (( pszArg = ntharg( pszCmdLine, i )) != NULL ); i++ ) {


		if ( _stricmp( pszArg, _TEXT("*") ) == 0 ) {

			// wildcard kill - null the environment or alias list
			pchList[0] = _TEXT('\0');
			pchList[1] = _TEXT('\0');
			break;

		} else if ( strpbrk( pszArg, _TEXT("*?[") ) != NULL ) {

			// wildcard delete!
			lpszVars = pchList;

			while ( *lpszVars ) {

				TCHAR szVarName[128];

				sscanf_far( lpszVars, _TEXT("%127[^=]"), szVarName );

				// treat it like a "unset varname*"
				if (( szVarName[0] ) && ( wild_cmp( pszArg, szVarName, FALSE, TRUE ) == 0 )) {

					// got a match -- remove it
					if ( add_list( szVarName, pchList ) != 0 ) {
						// check for "quiet" switch
						nReturn = (( fUnset & UNSET_QUIET ) ? ERROR_EXIT : ERROR_NOT_IN_LIST );
					}

				} else
					lpszVars = next_env( lpszVars );
			}

		} else {

			// kill the variable or alias
			if ( get_list( pszArg, pchList ) == 0L ) {

				// check for "quiet" switch
				if ( fUnset & UNSET_QUIET )
					nReturn = ERROR_EXIT;
				else
					nReturn = ERROR_NOT_IN_LIST;

			} else if ( add_list( pszArg, pchList ) != 0 )
				nReturn = ERROR_EXIT;
		}

		// remove argument so it won't appear in error list
		if ( nReturn == 0 ) {
			strcpy( gpNthptr, skipspace( gpNthptr + strlen( pszArg )));
			i--;
		}
	}

	return nReturn;
}