Пример #1
0
std::string libmaus::util::ArgInfo::getAbsProgName() const
{
	if ( progname.size() > 0 && progname[0] == '/' )
		return progname;
	else
		return getCurDir() + "/" + progname;
}
Пример #2
0
void shellPrompt(){

	char* curDir=getCurDir();

	if(!strncmp(curDir, env.HOME, strlen(env.HOME))) {
		printf("%s:~%s$ ",env.PS1, curDir+strlen(env.HOME));
	} else {
		printf("%s:%s$ ", env.PS1, curDir);
	}
	
}
Пример #3
0
int main(int argc, char* argv[])
{
	const std::string directory = getCurDir();
	const std::string fileName = directory + "/modulelist";
	std::ofstream logFile(fileName, std::ios_base::out);
	for (const auto& entry : std::filesystem::directory_iterator(directory))
	{
		if (entry.path().extension().string() == ".ifc")
		{
			writeToLog(logFile, entry.path().filename().string());
		}
	}
	logFile.close();
	return 0;
}
Пример #4
0
void executeCmd(char* input,char* envp[]){
	int pid=0;
	int status=0;
	char* args[MAX_ARGS];

	int n=parseInputToParams(input,args,' ');

	char* cmd=args[0];
	char* param;
	if(n>1){
		param=args[1];
	}else{
		param=NULL;
	}
	
	
	int isBgJob=!strcmp(args[n-1],"&");
	if(isBgJob){
		args[n-1]=NULL;
	}
	//judge cmd type
	if(!strcmp(cmd, "exit")) {
		exit(0);
	}else if(!strcmp(cmd, "sbuls")) {
		lsCmd();
	}else if(!strcmp(cmd, "sbucat")) {
		catCmd(param);
	}else if(!strcmp(cmd, "pwd")) {
		printf("%s\n",getCurDir());
	}else if(!strcmp(cmd, "cd")) {
		cdBuiltin(param);
	}else if(!strcmp(cmd, "export")) {
		exportBuiltin(param);
	}else {//execute bin or executables
		pid = fork();
		if(pid == 0) {
			executeBin(args[0],args,envp);
			exit(0);
		}else{
			if(isBgJob){
				printf("backgroud job pid is:%d\n",pid);
			}else{
				waitpid(pid, &status, 0);
			}
		}			
	}
}
void TChDirDialog::handleEvent( TEvent& event )
{
    TDialog::handleEvent( event );
    switch( event.what )
        {
        case evCommand:
            {
            char curDir[PATH_MAX];
            switch( event.message.command )
                {
                case cmRevert:
                    getCurDir( curDir );
                    break;
                case cmChangeDir:
                    {
                    TDirEntry *p = dirList->list()->at( dirList->focused );
                    strcpy( curDir, p->dir() );
			/* SS: changed */
                        if( curDir[strlen(curDir)-1] != '/' )
                            strcat( curDir, "/" );
                    break;
                    }
#ifndef __UNPATCHED
		//!! Handle directory selection.
                case cmDirSelection:
                    chDirButton->makeDefault( (Boolean) event.message.infoPtr );
                    return;     // NOTE: THIS IS RETURN NOT BREAK!!
#endif
                default:
                    return;
                }
            dirList->newDirectory( curDir );
            int len = strlen( curDir );
	    /* SS: changed */
            if( len > 0 && curDir[len-1] == '/' )
                curDir[len-1] = EOS;
            strcpy( dirInput->data, curDir );
            dirInput->drawView();
            dirList->select();
            clearEvent( event );
            }
        default:
            break;
        }
}
void TChDirDialog::setUpDialog()
{
    if( dirList != 0 )
        {
        char curDir[PATH_MAX];
        getCurDir( curDir );
        dirList->newDirectory( curDir );
        if( dirInput != 0 )
            {
            int len = strlen( curDir );
	    /* SS: changed */
            if( len > 0 && curDir[len-1] == '/' )
                curDir[len-1] = EOS;
            strcpy( dirInput->data, curDir );
            dirInput->drawView();
            }
        }
}
Пример #7
0
void lsCmd(){
	char* dir=getCurDir();
	struct dirent *sd; 
	void *dp=opendir(dir); 

	int BUF_SIZE=1024,nread=0;
	char buf[BUF_SIZE];
	int pos=0;
	
	while(1){
		nread = getdents(*((int *)dp), (struct dirent *)buf, BUF_SIZE);
		if(nread<=0)
			break;
		for(pos=0;pos<nread;){
			sd=(struct dirent *)(buf+pos);
			if(strncmp(sd->d_name,".",1))
			printf("%s  ", sd->d_name);
			pos+=sd->d_reclen;
			
		}
		printf("\n");
	}
	closedir(dp);
}
Пример #8
0
void __cdecl
main(
    unsigned argc,
    char *argv[],
    char *envp[])			    /* environment variables  */
{
    extern unsigned saveBytes;
    extern char **envPtr;
    int status;				    /* returned by doMake */
    extern char *makeStr;
#ifdef OS2_SIGNALS
    PUSHORT prev;
    unsigned long _FAR *pfnsig;
#endif

    InitializeEnv();

#if defined(FLAT)
    fRunningUnderTNT = FIsTNT();
#endif

    initCharmap();

    initMacroTable(macroTable);

#ifdef DEBUG_MEMORY
    //This puts 0xff in all free entries in the heap
    _heapset(0xff);
#endif

    envPtr = envp;
#ifdef DEBUG_COMMANDLINE
    {
	int iArg = argc;
	char **chchArg = argv;
	for (; iArg--; chchArg++)
	    printf("'%s' ", *chchArg);
	printf("\n");
    }
#endif
#ifdef TEST_RUNTIME
    //Tests RunTime error R6001
    {char near *foo = NULL; *foo = '1';}
#endif

#ifdef DOS
    startupDir = getCurDir();
#endif

#ifdef FLAT
    resultbuf_size = sizeof(struct _finddata_t);
    #ifdef NT
	    ext_size  = CCHMAXPATHCOMP;
    	filename_size = CCHMAXPATHCOMP;
	    filenameext_size = CCHMAXPATH;
    #endif
#else
    /* If OS/2 1.2 and beyond then allowed max sizes vary
     */
    if (_osmajor < 10 || _osmode == DOS_MODE)
	resultbuf_size = sizeof(struct find_t);
    else if (_osminor < 20)
	resultbuf_size = sizeof(struct FileFindBuf);
    else {
	ext_size  = CCHMAXPATHCOMP;
	filename_size = CCHMAXPATHCOMP;
	filenameext_size = CCHMAXPATH;
	resultbuf_size = sizeof(struct _FILEFINDBUF);
    }
#endif

    if (!makeStr)				  /* extract file name	*/
	if (!filename(_ftcscpy(fileStr, _pgmptr), &makeStr))
	    makeStr = "NMAKE";

    // Initialize the message file
    SetErrorFile("nmake.err", _pgmptr, 1);	// 1=Search Exe Path

#if defined(SELF_RECURSE)
    initSavPtr = (char *)allocate(saveBytes = (&endOfSave - &startOfSave));
    memmove(initSavPtr, &startOfSave, saveBytes);
#endif

    /* set up handler for .PRECIOUS  the handler tries to remove the
     * current target when control-C'd, unless it is "precious"
     */

#ifdef OS2_SIGNALS
    This commented out part was trial for using OS/2 function calls
    It still has some problems
    DOSSETSIGHANDLER(chkPrecious, pfnsig, prev, SIGA_ACCEPT, SIG_CTRLC);
    if (_osmode == OS2_MODE) {
	DOSSETSIGHANDLER(chkPrecious, NULL, NULL, SIGA_ACCEPT, SIG_CTRLBREAK);
	DOSSETSIGHANDLER(chkPrecious, NULL, NULL, SIGA_ACCEPT, SIG_KILLPROCESS);
    }
#endif

    signal(SIGINT, chkPrecious);
    signal(SIGTERM, chkPrecious);

    makeIdeMessage(0, 0);
    status = doMake(argc, argv, NULL);

#ifndef NO_OPTION_Z
    /* If -Z is specified then NMAKE needs to have errorLevel check in the
     * batch file. So add the goto label for exit and print the Reverse batch
     * file
     */
    if (ON(gFlags, F1_REVERSE_BATCH_FILE)) {
	STRINGLIST *revCmd;
	//Adds ':NMAKEEXIT' to jump to end when error occurs
	revCmd = makeNewStrListElement();
	revCmd->text = nmakeExitLabelCmd;
	prependItem(&revList, revCmd);
	//'=c' means echo at current line
	revCmd = makeNewStrListElement();
	revCmd->text = makeString("=c");
	appendItem(&revList, revCmd);
	//'=d' turns echoing on (unless preceeded by @)
	revCmd = makeNewStrListElement();
	revCmd->text = makeString("=d");
	appendItem(&revList, revCmd);
    }
#endif
    delScriptFiles();
#ifndef NO_OPTION_Z
    if (ON(gFlags, F1_REVERSE_BATCH_FILE))
	printReverseFile();
#endif
#ifdef MEMORY_DEBUG
    mem_status();
#endif

#ifdef HEAP_DIAGNOSTICS
    printHeapDiagnostics();
#endif
#ifdef NMK_DEBUG
    fprintf(stderr, "Exiting...\n");
#endif
    if (!fSlashKStatus)
	//error when slashK specified
	status = 1;
#if !defined(NDEBUG) && !defined(NT_BUILD)
    printStats();
#endif
    exit(status);
}