示例#1
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;
}
示例#2
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;
}
示例#3
0
文件: env.c 项目: ErisBlastar/osfree
static int SetFromFile( char *szLine, char *pchList, int fRemove )
{
    char *arg;
    char szBuffer[CMDBUFSIZ];
    int i, n, rval = 0;

    for ( i = 0; (( rval == 0 ) && (( arg = ntharg( szLine, i )) != NULL )); i++ ) {

        mkfname( arg, 0 );

        if (( gnGFH = _sopen( arg, (O_RDONLY | O_BINARY), SH_DENYWR )) < 0 )
            return ( error( _doserrno, arg ));

        for ( arg = szBuffer; (( rval == 0 ) && ( getline( gnGFH, arg, CMDBUFSIZ-((arg-szBuffer)+1), EDIT_DATA ) > 0 )); ) {

            // remove leading white space
            strip_leading( arg, WHITESPACE );

            // if last char is escape character, append
            //   the next line
            n = strlen( arg ) - 1;
            if (( arg[0] ) && ( arg[n] == gpIniptr->EscChr )) {
                arg += n;
                continue;
            }

            // skip blank lines & comments
            arg = szBuffer;
            if (( *arg ) && ( *arg != ':' )) {

                if ( fRemove ) {
                    // delete variable
                    for ( n = 0; (( szBuffer[n] ) && ( szBuffer[n++] != '=' )); )
                        ;
                    szBuffer[n] = '\0';
                }

                // create/modify a variable or alias
                rval = add_list( arg, pchList );
            }
        }

        gnGFH = _close( gnGFH );
    }

    return rval;
}
示例#4
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 ));
}
示例#5
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;
}
示例#6
0
文件: env.c 项目: CivilPol/sdcboot
static int SetFromFile( LPTSTR pszLine, TCHAR _far *pchList, long fFlags )
{
	static TCHAR szDelimiters[] = _TEXT("%[^= \t]");
	register LPTSTR pszArg;
	TCHAR szBuffer[CMDBUFSIZ];
	int i, n, nError = 0, nEditFlags = EDIT_DATA, nFH = -1;


	if (( *pszLine == _TEXT('\0') ) && ( QueryIsConsole( STDIN ) == 0 )) {
		pszLine = CONSOLE;
		nFH = STDIN;
	}

	for ( i = 0; (( nError == 0 ) && (( pszArg = ntharg( pszLine, i )) != NULL )); i++ ) {

		if ( nFH != STDIN ) {
			mkfname( pszArg, 0 );
			if (( nFH = _sopen( pszArg, _O_RDONLY | _O_BINARY, _SH_DENYWR )) < 0 )
				return ( error( _doserrno, pszArg ));
		}

		if ( setjmp( cv.env ) == -1 ) {
			if ( nFH > 0 ) {
				_close( nFH );
				nFH = -1;
			}
            return CTRLC;
		}

		for ( pszArg = szBuffer; (( nError == 0 ) && ( getline( nFH, pszArg, CMDBUFSIZ - (UINT)(( pszArg - szBuffer ) + 1 ), nEditFlags ) > 0 )); ) {

			// remove leading white space
			strip_leading( pszArg, WHITESPACE );

			// if last char is escape character, append the next line
			n = strlen( pszArg ) - 1;
			if (( pszArg[0] ) && ( pszArg[n] == gpIniptr->EscChr )) {
				pszArg += n;
				continue;
			}

			// skip blank lines & comments
			pszArg = szBuffer;
			if (( *pszArg ) && ( *pszArg != _TEXT(':') )) {

				// delete variable
				if ( fFlags & 1 ) {
					// an UNSET requires a '=' delimiter; it's optional elsewhere
					szDelimiters[4] = (( pchList == glpEnvironment ) ? _TEXT('\0') : _TEXT(' '));
					sscanf( szBuffer, szDelimiters, szBuffer );
				}

				// create/modify a variable or alias
				nError = add_list( pszArg, pchList );
			}
		}

		if ( nFH != STDIN ) {
			 _close( nFH );
			 nFH = -1;
		}
	}

	return nError;
}
示例#7
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;
}
示例#8
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;
}
示例#9
0
文件: env.c 项目: CivilPol/sdcboot
// create or display environment variables or aliases
static int _fastcall __Set( LPTSTR pszCmdLine, TCHAR _far * pchList )
{
	LPTSTR pszArg;
	long fSet = 0L;
	TCHAR _far *lpszVars;

	init_page_size();

	// set the pointer to the environment, alias, or function list

	// strip leading switches
	if (( pszCmdLine != NULL ) && ( *pszCmdLine == gpIniptr->SwChr )) {
		if ( GetSwitches( pszCmdLine, "AMPR", &fSet, 1 ) != 0 )
			return USAGE_ERR;
	}

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

	// read environment or alias file(s)
	if ( fSet & SET_READ )
		return ( SetFromFile( pszCmdLine, pchList, fSet & ( SET_DEFAULT | SET_SYSTEM | SET_USER | SET_VOLATILE )));

	if ( setjmp( cv.env ) == -1 )
		return CTRLC;

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

	if (( pszCmdLine == NULL ) || ( *(pszCmdLine = skipspace( pszCmdLine )) == _TEXT('\0'))) {

		// print all the variables or aliases
		for ( lpszVars = pchList; ( *lpszVars != _TEXT('\0') ); lpszVars = next_env( lpszVars ) ) {

			more_page( lpszVars, 0 );
		}

		// return an error if no entries exist
		return (( lpszVars == pchList ) ? ERROR_LIST_EMPTY : 0 );
	}

	if ( fSet & SET_EXPRESSION ) {

		if (( pszArg = strchr( pszCmdLine, _TEXT('=') )) != NULL ) {

			if (( pszArg > pszCmdLine ) && ( strchr( _TEXT("+-*/%&^|><"), pszArg[-1] ) != NULL )) {

				TCHAR szBuf[256];

				// it's an assignment operator ("set /a test+=2")
				sscanf( pszCmdLine, _TEXT(" %[^ +-*/%&^|><=]"), szBuf );
				strcpy( pszArg, pszArg+1 );

				strins( pszCmdLine, _TEXT("=") );
				strins( pszCmdLine, szBuf );
				pszArg = pszCmdLine + strlen( szBuf ) + 1;

			} else
				pszArg = skipspace( pszArg+1 );

		} else
			pszArg = pszCmdLine;
		StripQuotes( pszArg );

		evaluate( pszArg );
		if ( cv.bn < 0 ) {
			qputs( pszArg );
			crlf();
		}

		// create/modify/delete a variable
		return (( pszArg == pszCmdLine ) ? 0 : add_list( pszCmdLine, pchList ));
	}

	// display the current variable or alias argument?
	// (setting environment vars requires a '='; it's optional with aliases)
	if ((( pszArg = strchr( pszCmdLine, _TEXT('=') )) == NULL ) && (( pchList == 0L ) || ( ntharg( pszCmdLine, 0x8001 ) == NULL ))) {

		if (( lpszVars = get_list( pszCmdLine, pchList )) == 0L ) {

			return ERROR_NOT_IN_LIST;
		}

		printf( FMT_FAR_STR_CRLF, lpszVars );
		return 0;
	}

	// create/modify/delete a variable or alias
	return ( add_list( pszCmdLine, pchList ));
}