예제 #1
0
void BindExec() {
	int n;

	char temppath[128];		// passed as *path argument
	char tempname[128];		// passed as *argv[0]
	char tempparm[128];		// -UN name of file
	char tempparm2[128];		// -BN name of file
	char temptype[8];		// action type, either "-R" or "-RS"

	const char *path=temppath;
	const char *arg0=bindname;
	const char *arg1=temptype;
	const char *arg2="/S";
	const char *arg3=tempparm;
	const char *arg4=tempparm2;
	const char *arg5=tempname2;


	if(bindtype==0) 	strcpy(temptype,"/R");
	else if(bindtype==1)	strcpy(temptype,"/RS");
	else if(bindtype==2)	strcpy(temptype,"/RC");

	strcpy(temppath,bindname);
	strcpy(tempname,bindname);

	strcpy(tempparm,"/UN");
	strcat(tempparm,tempname2);
	strcpy(tempparm2,"/BN");
	strcat(tempparm2,newfilename);
	n=spawnle(P_WAIT, path, arg0,arg1,arg2,arg3,arg4,arg5, NULL, NULL);

	if(n==-1)
	{
	  GetDOS32APath();
	  strcpy(temppath,dos32apath);
	  strcat(temppath,bindname);
	  strcpy(tempname,dos32apath);
	  strcat(tempname,bindname);
	  n=spawnle(P_WAIT, path, arg0,arg1,arg2,arg3,arg4,arg5, NULL, NULL);
	  if(n==-1)
	  {
	    strcpy(temppath,bindname);
	    strcpy(tempname,bindname);
	    n=spawnlpe(P_WAIT, path, arg0,arg1,arg2,arg3,arg4,arg5, NULL, NULL);
	    if(n==-1) err_nosb();
	  }
	}
	if(n!=0) {
	  if(n==127) err_support(tempname2);
	  else {
	    DeleteTempFiles();
	    exit(1);
	  }
	}
}
예제 #2
0
void UnbindExec()
{
	int n;

	char temppath[128];		// passed as *path argument
	char tempname[128];		// passed as *argv[0]
	char tempparm[128];		// name of file to be processed

	const char *path=temppath;
	const char *arg0=bindname;
	const char *arg1="/U";
	const char *arg2="/O";
	const char *arg3="/S";
	const char *arg4=tempparm;
	const char *arg5=oldfilename;


	strcpy(temppath,bindname);
	strcpy(tempname,bindname);
	strcpy(tempparm,"/UN");
	strcat(tempparm,tempname1);
	n=spawnle(P_WAIT, path, arg0,arg1,arg2,arg3,arg4,arg5, NULL, NULL);

	if(n==-1)
	{
		GetDOS32APath();
		strcpy(temppath,dos32apath);
		strcat(temppath,bindname);
		strcpy(tempname,dos32apath);
		strcat(tempname,bindname);
		n=spawnle(P_WAIT, path, arg0,arg1,arg2,arg3,arg4,arg5, NULL, NULL);
		if(n==-1)
		{
			strcpy(temppath,bindname);
			strcpy(tempname,bindname);
			n=spawnlpe(P_WAIT, path, arg0,arg1,arg2,arg3,arg4,arg5, NULL, NULL);
			if(n==-1)
				err_nosb();
		}
	}
	if(n!=0)
	{
		if(n==127)
			err_support(oldfilename);
		else
		{
			DeleteTempFiles();
			exit(1);
		}
	}
}
예제 #3
0
파일: SPAWNLXX.C 프로젝트: moyuanming/Train
void main(void)
 {
   char *env[] = { "FILE=SPAWNLXX.C", "LANGUAGE=C",
                   "OS=DOS", NULL};

   spawnle(P_WAIT, "CHILD.EXE", "CHILD.EXE", 
      "Using-spawnle", "BBB", NULL, env);

   spawnlp(P_WAIT, "CHILD.EXE", "CHILD.EXE", "Using-spawnlp", 
      "BBB", NULL);
   spawnlpe(P_WAIT, "CHILD.EXE", "CHILD.EXE", "Using-spawnlpe", 
      "BBB", NULL, env);
 }
예제 #4
0
int main( int argc, char * const argv[] )
{
    char                myfile[ sizeof __FILE__ ];
    int                 child = argc > 1;
    int                 handle;
    int                 status;
    int                 handle_out;
    long                size;


    /*** Initialize ***/
    strcpy( ProgramName, argv[0] );     /* store filename */
    strlwr( ProgramName );              /* and lower case it */
    strcpy( myfile, __FILE__ );
    strlwr( myfile );

    if( child ) {
        char    *env_var;

        if( argc == 4 ) {        
        /* Verify expected command line contents */
            VERIFY( !strcmp( argv[1], ARG1 ) );
            VERIFY( !strcmp( argv[2], ARG2 ) );
            VERIFY( !strcmp( argv[3], ARG3 ) );

        /* Verify expected environment contents */
            env_var = getenv( VAR_NAME );
            VERIFY( env_var );
            VERIFY( !strcmp( env_var, VAR_TEXT ) );

            if( NumErrors != 0 ) {
                return( EXIT_FAILURE );
            } else {
                return( CHILD_RC );
            }
        } else {
            if( argc == 2 ) {
            /* Verify expected command line contents */
                VERIFY( !strcmp( argv[1], ARG_REDIR ) );

            /* Write text to stdout */
                printf( REDIR_TEXT );

                if( NumErrors != 0 ) {
                    return( EXIT_FAILURE );
                } else {
                    return( CHILD_RC );
                }
            }
            else
                return( EXIT_FAILURE );
        }                   
    } else {
        int         rc;
        char        **env;
        const char  *path = "PATH=.";   /* Default PATH if none is found */
        const char  *child_args[] = { ProgramName, ARG1, ARG2, ARG3, NULL };
        const char  *child_envp[] = { NULL, VAR_NAME "=" VAR_TEXT, "DOS4G=QUIET", NULL };

        /* We need to pass PATH down to the child because DOS/4GW style stub
         * programs rely on it to function properly.
         */
        for( env = environ; *env; ++env )
            if( !strncmp( *env, "PATH=", 5 ) ) {
                path = *env;
                break;
            }

        child_envp[0] = path;

        /* Test spawn functions */
        rc = spawnle( P_WAIT, ProgramName, ProgramName, ARG1, ARG2, ARG3, NULL, child_envp );
        VERIFY( rc == CHILD_RC );

        rc = spawnlpe( P_WAIT, ProgramName, ProgramName, ARG1, ARG2, ARG3, NULL, child_envp );
        VERIFY( rc == CHILD_RC );

        rc = spawnve( P_WAIT, ProgramName, child_args, child_envp );
        VERIFY( rc == CHILD_RC );

        rc = spawnvpe( P_WAIT, ProgramName, child_args, child_envp );
        VERIFY( rc == CHILD_RC );

        /* Modify our environment that child will inherit */
        VERIFY( !setenv( VAR_NAME, VAR_TEXT, 1 ) );
        VERIFY( !setenv( "DOS4G", "QUIET", 1 ) );
        
        rc = spawnl( P_WAIT, ProgramName, ProgramName, ARG1, ARG2, ARG3, NULL );
        VERIFY( rc == CHILD_RC );

        rc = spawnlp( P_WAIT, ProgramName, ProgramName, ARG1, ARG2, ARG3, NULL );
        VERIFY( rc == CHILD_RC );

        rc = spawnv( P_WAIT, ProgramName, child_args );
        VERIFY( rc == CHILD_RC );

        rc = spawnvp( P_WAIT, ProgramName, child_args );
        VERIFY( rc == CHILD_RC );

        /* Check inherited output redirection */
        handle_out = dup( STDOUT_FILENO );
        
        handle = creat( "test.fil", S_IREAD|S_IWRITE );
        VERIFY( handle != -1 );

        status = dup2( handle, STDOUT_FILENO );
        VERIFY( status != -1 );

        status = close( handle );
        VERIFY( status == 0 );

        rc = spawnl( P_WAIT, ProgramName, ProgramName, ARG_REDIR, NULL );
        VERIFY( rc == CHILD_RC );

        status = dup2( handle_out, STDOUT_FILENO );
        VERIFY( status != -1 );
        
        handle = open( "test.fil", O_RDWR );
        VERIFY( handle != -1 );

        size = filelength( handle );
        VERIFY( size == strlen( REDIR_TEXT ) );

        status = close( handle );
        VERIFY( status == 0 );

        status = unlink( "test.fil" );
        VERIFY( status == 0 );

        signal_count = 0;
        signal_number = 0;
        /* Install SIGBREAK handler */
        VERIFY( signal( SIGBREAK, break_handler ) == SIG_DFL );

        /* Raise signal and verify results */
        VERIFY( raise( SIGBREAK ) == 0 );
        VERIFY( signal_count == 1 );
        VERIFY( signal_number == SIGBREAK );

        /* Raise again - nothing should have happened */
        VERIFY( raise( SIGBREAK ) == 0 );
        VERIFY( signal_count == 1 );

        /*** Print a pass/fail message and quit ***/
        if( NumErrors != 0 ) {
            printf( "%s: FAILURE (%d errors).\n", ProgramName, NumErrors );
            return( EXIT_FAILURE );
        }
        printf( "Tests completed (%s).\n", ProgramName );
    }

    return( 0 );
}
예제 #5
0
파일: ENVIR8.C 프로젝트: krattai/flosh
void main(void)
{
	int key,
		formon = 0,
		buton = 1,
		f2 = 0,
		busy = 0,
		v,
		h,
		z;
	char test;
	int garb;

	startup();						/* standard startup sequence */

	/* Button */
	defbutton(100,450,"End");
	defbutton(400,450,"Help");
	defplate(0,25,"File");
	defplate(58,25,"Form");
    defplate(150,25,"DOS");
	defplate(350,25,"Display");
	defplate(450,25,"Clear");
	defplate(522,25,"Edit");
	defform("50,50,4,test,50,70,8,test2,50,90,6,test3"); 

	initrat(&rat);
	raton(&rat);

	do {
		key = checkinput();
		h = rat.horiz;
		v = rat.verti;
		if((rat.buttons == LBUTTON && key == PRESS) && (platehit(1,h,v)))
		{
			ratoff(&rat);
			if(formon)
			{
				if(f2) busy = 0;
				removeform();
				formon = 0;
			}
			else
			{
				if(f2) busy = 1;
				displayform();
				formon = 1;
			}
			raton(&rat);
		}
		if((rat.buttons == RBUTTON && key == PRESS) && (platehit(2,h,v)))
		{
			garb = spawnle(P_WAIT,"c:\\command.com",NULL,NULL);
			if(garb == -1)
			{
				shutdown();
				perror("\nError");
				getch();
				exit(1);
			}
		}
		if((rat.buttons == LBUTTON && key == PRESS) && (platehit(3,h,v)))
		{
			if(f2 && !busy)
			{
				ratoff(&rat);
				showdata(0,0,testform.fld1);
				showdata(0,1,testform.fld2);
				showdata(0,2,testform.fld3);
				raton(&rat);
			}
		}
		if((rat.buttons == LBUTTON && key == PRESS) && (platehit(4,h,v)))
		{
			if(f2 && !busy)
			{
				ratoff(&rat);
				cleanform(0,0,testform.fld1);
				cleanform(0,1,testform.fld2);
				cleanform(0,2,testform.fld3);
				raton(&rat);
			}
		}
		if((rat.buttons == LBUTTON && key == PRESS) && (platehit(5,h,v)))
		{
			if(f2 && !busy)
			{
				ratoff(&rat);
				cleanform(0,0,testform.fld1);
				for(z=0;z<=10;z++) testform.fld1[z]=NULL;
				test=get_key();
				z=0;
				while(test != ENTER && z < 4)
				{
					testform.fld1[z]=test;
					showdata(0,0,testform.fld1);
					z++;
					test=get_key();
				}
				cleanform(0,1,testform.fld2);
				for(z=0;z<=10;z++) testform.fld2[z]=NULL;
				test=get_key();
				z=0;
				while(test != ENTER && z < 8)
				{
					testform.fld2[z]=test;
					showdata(0,1,testform.fld2);
					z++;
					test=get_key();
				}
				cleanform(0,2,testform.fld3);
				for(z=0;z<=10;z++) testform.fld3[z]=NULL;
				test=get_key();
				z=0;
				while(test != ENTER && z < 6)
				{
					testform.fld3[z]=test;
					showdata(0,2,testform.fld3);
					test=get_key();
					z++;
				}
				raton(&rat);
			}
		}
		if((rat.buttons == LBUTTON && key == PRESS) && (platehit(0,h,v)))
		{
			ratoff(&rat);
			if(f2)
			{
				eraseform(0,WITHOUT);
				f2 = 0;
			}
			else
			{
				showform(0,WITHOUT);
				f2 = 1;
			}
			raton(&rat);
		}
		if((rat.buttons == RBUTTON && key == HELD) && (checkhit(1,h,v)))
		{
			ratoff(&rat);
			if(buton)
			{
				buttonoff(1);
				buton = 0;
			}
			else
			{
				buttonon(1);
				buton = 1;
			}
			raton(&rat);
		}
		if((rat.buttons == CBUTTON && key == RELEASE) && (checkhit(1,h,v)))
		{
			ratoff(&rat);
			if(buton)
			{
				buttonoff(1);
				buton = 0;
			}
			else
			{
				buttonon(1);
				buton = 1;
			}
			raton(&rat);
		}
	} while(!(((rat.buttons == LBUTTON && key == RELEASE) || (key == ENTER))
			&& checkhit(0,h,v) || key == ESC));

	ratoff(&rat);

	shutdown();
}