void spawnProcess(const char *path, char *arg) { spawnl(P_NOWAIT , path, " ", arg,NULL);; }
/* Use sockets or pipes. */ int _gst_open_pipe (const char *command, const char *mode) { int fd[2]; int our_fd, child_fd; int access; int result; _gst_set_signal_handler (SIGCHLD, sigchld_handler); access = strchr (mode, '+') ? O_RDWR : (mode[0] == 'r' ? O_RDONLY : O_WRONLY); if (access == O_RDWR) { result = socketpair (AF_UNIX, SOCK_STREAM, 0, fd); our_fd = fd[1]; child_fd = fd[0]; } else { result = pipe (fd); our_fd = access == O_RDONLY ? fd[0] : fd[1]; child_fd = access == O_RDONLY ? fd[1] : fd[0]; } if (result == -1) return -1; _gst_set_signal_handler (SIGPIPE, SIG_DFL); _gst_set_signal_handler (SIGFPE, SIG_DFL); #ifdef HAVE_SPAWNL { /* Prepare file descriptors, saving the old ones so that we can keep them. */ int save_stdin = -1, save_stdout = -1, save_stderr = -1; if (access != O_WRONLY) { save_stdout = dup (1); save_stderr = dup (2); dup2 (child_fd, 1); dup2 (child_fd, 2); } if (access != O_RDONLY) { save_stdin = dup (0); dup2 (child_fd, 0); } result = spawnl (P_NOWAIT, "/bin/sh", "/bin/sh", "-c", command, NULL); if (save_stdin != -1) { dup2 (save_stdin, 0); close (save_stdin); } if (save_stdout != -1) { dup2 (save_stdout, 1); close (save_stdout); } if (save_stderr != -1) { dup2 (save_stderr, 2); close (save_stderr); } } #else /* !HAVE_SPAWNL */ /* We suppose it is a system that has fork. */ result = fork (); if (result == 0) { /* Child process */ close (our_fd); if (access != O_WRONLY) dup2 (child_fd, 1); if (access != O_RDONLY) dup2 (child_fd, 0); _exit (system (command) >= 0); /*NOTREACHED*/ } #endif /* !HAVE_SPAWNL */ close (child_fd); _gst_set_signal_handler (SIGPIPE, SIG_IGN); _gst_set_signal_handler (SIGFPE, SIG_IGN); if (result == -1) { int save_errno; save_errno = errno; close (our_fd); errno = save_errno; return (-1); } else return (our_fd); }
main (void) { pid_t pid_gui; pid_t pid_sim; pid_t pid_pport; int simChid; int kill_gui; int kill_sim; int kill_pport; int s_return; //---thread paramters--------------// pthread_attr_t attr; pthread_t timerThreadID; pthread_t keyboardThreadID; pthread_t blockIDThreadID; do { printf("\n=========================================================\n"); printf("Please Selet the Operating Mode:\n"); printf("1: Basic Orientation Mode for Block: 0-10).\n"); printf("2: Rotated Orientation Mode for Block:0-6). (alaph version)\n"); printf("===========================================================\n"); flushall(); scanf ("%c",&programMode); printf("You have selected: Mode %c.\n\n",programMode); flushall(); if((programMode != '1' )&&(programMode !='2')) { printf("Invalid Selection, Please Enter!\n"); flushall(); } } while(programMode != '1'&&programMode !='2'); // ----------------Share Memory---------------------------------------- shMem=shm_open("shared_memory", OFLAGS, 0777); if (shMem == -1) { printf("shared_memory failed to open...\n"); flushall(); } else { if (ftruncate (shMem,SIZE) == -1) { printf ("Failed to set size for -- shmem -- \n"); flushall(); } else { //mapping a shared memory location memLocation = mmap (0, SIZE, PROT, MFLAGS, shMem, 0); if (memLocation == MAP_FAILED) { printf (" Failed to map to shared memory...\n"); flushall(); } } } // ---------------Semorphore------------------------------------- // semorphore for shared memory sem = sem_open ("shared_sem", O_CREAT, S_IRWXG | S_IRWXO | S_IRWXU, 0); if (sem == (sem_t *)(-1)) { printf ("User: Memory Semaphore failed to open....\n"); flushall(); } else { sem_post(sem); } // -----------------------channel creation--------------------------- // Create a channels for the simulator and Gui // The ChannelCreate function returns the channel ID ChannelCreate(0); ChannelCreate(0); //ChannelCreate(0);//for pport simChid = 1; sleep(1); // Spawing a process for the GUI and Simulator pid_gui = spawnl(P_NOWAIT, "/usr/local/bin/gui_g", "gui_g", NULL); pid_sim = spawnl(P_NOWAIT, "/usr/local/bin/newGUIPport_g", "sim", NULL); pid_pport = spawnl(P_NOWAIT, "/usr/local/bin/testPport_g", "pport",NULL); sleep(1); //The Gui process automatically connect to the channel //Thus we only need to attach the simulator process to the created channel coidsim = ConnectAttach(0,pid_sim,simChid,0,0); // Display error message if connection failed if (coidsim == -1) { printf("coidsim error\n"); flushall(); exit(EXIT_FAILURE); } coidpport = ConnectAttach(0,pid_pport,simChid,0,0); // Display error message if connection failed if (coidpport == -1) { printf("coidpport error\n"); flushall(); exit(EXIT_FAILURE); } // --------------------------timer code---------------------------------- // Create a channel for sending a pulse to myself when timer expires timerChid = ChannelCreate(_NTO_CHF_UNBLOCK); if(timerChid == -1) { printf("timer Channel create failed\n"); flushall(); } timerCoid = ConnectAttach ( 0, getpid ( ), timerChid, 0, 0); if(timerCoid == -1 ) { printf ("Channel attach failed!\n"); flushall(); perror ( NULL ); exit ( EXIT_FAILURE); } // Set up pulse event for delivery when the first timer expires; pulse code = 8, pulse value = 0; SIGEV_PULSE_INIT (&timerEvent, timerCoid, SIGEV_PULSE_PRIO_INHERIT, 8, 0); // Create Timer if (timer_create (CLOCK_REALTIME, &timerEvent, &timerid) == -1) { printf ( "Failed to create a timer for pulse delivery\n"); flushall(); perror (NULL); exit ( EXIT_FAILURE); } // Setup one time timer for 2 second timer.it_value.tv_sec = 2; timer.it_value.tv_nsec = 0; timer.it_interval.tv_sec = 0; timer.it_interval.tv_nsec = 0; // --------------------------timer2 code---------------------------------- // Create a channel for sending a pulse to myself when timer expires timerChid2 = ChannelCreate(_NTO_CHF_UNBLOCK); if(timerChid2 == -1) { printf("timer Channel create failed\n"); flushall(); } timerCoid2 = ConnectAttach ( 0, getpid ( ), timerChid2, 0, 0); if(timerCoid2 == -1 ) { printf ("Channel attach failed!\n"); flushall(); perror ( NULL ); exit ( EXIT_FAILURE); } // Set up pulse event for delivery when the first timer expires; pulse code = 8, pulse value = 0; SIGEV_PULSE_INIT (&timerEvent2, timerCoid2, SIGEV_PULSE_PRIO_INHERIT, 8, 0); // Create Timer if (timer_create (CLOCK_REALTIME, &timerEvent2, &timerid2) == -1) { printf ( "Failed to create a timer for pulse delivery\n"); flushall(); perror (NULL); exit ( EXIT_FAILURE); } //-------------------timer monitor thread-------------------- pthread_attr_init(&attr); pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); pthread_create(&timerThreadID,&attr,timer_thread,NULL); if(timerThreadID == -1) { printf("Fail to create timer thread!"); flushall(); } else { printf("The timer thread ID is %i \n",timerThreadID); flushall(); } pthread_create(&timerThreadID,&attr,timer2_thread,NULL); if(timerThreadID == -1) { printf("Fail to create timer thread2!"); flushall(); } else { printf("The timer thread2 ID is %i \n",timerThreadID); flushall(); } // //----start the block Identification thread----------------- // pFile = fopen("Blocks.txt","w+"); pthread_create(&blockIDThreadID,&attr,blockID,NULL); if(blockIDThreadID == -1) { printf("Fail to create block indeptification thread!"); flushall(); } else { printf("The BlockID's thread ID is %i \n",blockIDThreadID); flushall(); } delay(10); //---------------------keyboard thread------------------------ pthread_create(&keyboardThreadID,&attr,keyboard_input,NULL); if(keyboardThreadID == -1) { printf("Fail to create keyboard input!"); flushall(); } else { printf("The keyboard_input ID is %i \n",timerThreadID); flushall(); } delay(10); //----------------GUI Monitor Thread--------------------- pthread_create(NULL,&attr,GUI_thread,NULL); delay(10); // --------------------SIM pulse Handler Loop Thread---------- pthread_create(NULL,&attr,Handlerloop_thread,NULL); delay(10); // --------------------SIM Monitor Thread--------------------- pthread_create(NULL,&attr,SIM_thread,NULL); delay(10); // --------------------Auto mode thread----------------------- pthread_create(NULL,&attr,auto_thread,NULL); delay(10); // --------------------others--------------------------------- // call mainLoop() mainLoop(); // sleep for 10sec printf("Sleep the program for 10 seconds\n"); flushall; sleep(10); // start release system resourse printf("Clean up and release system resourse\n"); flushall; // Kill the existing processes kill_gui = kill(pid_gui, 0); kill_sim = kill(pid_sim, 0); kill_pport = kill(pid_pport, 0); if (kill_gui == -1) { printf("GUI Kill failed\n"); flushall(); } if (kill_sim == -1) { printf("SIM Kill failed\n"); flushall(); } if (kill_pport == -1) { printf("PPort Kill failed\n"); flushall(); } // Close and unlink Semorphore sem_close(sem); s_return = sem_unlink("/dev/sem/home/quad6/workspace/Project_S1/shared_sem"); // Display error messae if semorphonre unlink is failed if (s_return == -1) { printf("a: %s\n", strerror( errno )); flushall(); } // Close, unmap, and unlink shared memory shm_close(shMem); munmap(shmLocation,SIZE); shm_unlink("shared_memory"); // Detach the connections and destroy the channels ConnectDetach(coidGui); ConnectDetach(coidsim); ConnectDetach(coidpport); ChannelDestroy(guiChid); ChannelDestroy(simChid); // fclose(pFile); }
int GAME :: common() { board(); coins(); char s; int i=7,j=0; while(1) { setcolor(RED); rectangle(A[i][j].x,A[i][j].y,A[i][j].x+43,A[i][j].y+43); s=getch(); setcolor(WHITE); rectangle(A[i][j].x,A[i][j].y,A[i][j].x+43,A[i][j].y+43); getpos(i,j,s); redraw(); setcolor(RED); rectangle(A[i][j].x,A[i][j].y,A[i][j].x+43,A[i][j].y+43); setfillstyle(SOLID_FILL,WHITE); bar(0,getmaxy()-15,getmaxx(),getmaxy()); settextstyle(2,0,4); outtextxy(10,getmaxy()-15,"White to play and mate in 1 move ..."); if(s=='5') { if(A[i][j].color==null) { setfillstyle(SOLID_FILL,WHITE); bar(0,getmaxy()-15,getmaxx(),getmaxy()); settextstyle(2,0,4); outtextxy(10,getmaxy()-15,"Select a coin to make a move !!"); } else if(A[i][j].color==black) { setfillstyle(SOLID_FILL,WHITE); bar(0,getmaxy()-15,getmaxx(),getmaxy()); settextstyle(2,0,4); outtextxy(10,getmaxy()-15,"It is white chance to play !!"); } else if(A[i][j].color==white) { stop=0; setcolor(YELLOW); rectangle(A[i][j].x,A[i][j].y,A[i][j].x+43,A[i][j].y+43); int p=i,q=j; while(stop==0) { s=getch(); setcolor(WHITE); rectangle(A[p][q].x,A[p][q].y,A[p][q].x+43,A[p][q].y+43); setcolor(YELLOW); rectangle(A[i][j].x,A[i][j].y,A[i][j].x+43,A[i][j].y+43); getpos(p,q,s); setcolor(RED); rectangle(A[p][q].x,A[p][q].y,A[p][q].x+43,A[p][q].y+43); setfillstyle(SOLID_FILL,WHITE); bar(0,getmaxy()-15,getmaxx(),getmaxy()); settextstyle(2,0,4); outtextxy(10,getmaxy()-15,"White to play and mate in 1 move ..."); if(s=='5') { if(level==1 && i==1 && j==5 && A[i][j].coin=='R' && A[i][j].color==white && p==1&&q==2 ) { change(i,j,p,q); return 0; } else if(level==2 && i==3&&j==7 && A[i][j].coin=='R' && A[i][j].color==white && p==0&&q==7 ) { change(i,j,p,q); return 0; } else if(level==3 && i==6&&j==6 && A[i][j].coin=='B' && A[i][j].color==white && p==3&&q==3 ) { change(i,j,p,q); return 0; } else if(level==4 && i==2&&j==4 && A[i][j].coin=='R' && A[i][j].color==white && p==2&&q==7 ) { change(i,j,p,q); return 0; } else if(level==5 && i==4&&j==4 && A[i][j].coin=='H' && A[i][j].color==white && p==5&&q==6 ) { change(i,j,p,q); return 0; } else if(level==6 && i==0&&j==7 && A[i][j].coin=='Q' && A[i][j].color==white && p==0&&q==4 ) { change(i,j,p,q); return 0; } else if(level==7 && i==1&&j==0 && A[i][j].coin=='Q' && A[i][j].color==white && p==5&&q==0 ) { change(i,j,p,q); return 0; } else if(level==8 && i==6&&j==3 && A[i][j].coin=='B' && A[i][j].color==white && p==3&&q==6 ) { change(i,j,p,q); return 0; } else if(level==9 && i==6&&j==4 && A[i][j].coin=='P' && A[i][j].color==white && p==5&&q==4 ) { change(i,j,p,q); return 0; } else if(level==10 && i==4&&j==4 && A[i][j].coin=='H' && A[i][j].color==white && p==2&&q==3 ) { change(i,j,p,q); return 0; } else if(level==11 && i==2&&j==6 && A[i][j].coin=='Q' && A[i][j].color==white && p==2&&q==5 ) { change(i,j,p,q); return 0; } else if(level==12 && i==3&&j==3 && A[i][j].coin=='H' && A[i][j].color==white && p==1&&q==2 ) { change(i,j,p,q); return 0; } else if(level==13 && i==2&&j==7 && A[i][j].coin=='Q' && A[i][j].color==white && p==1&&q==6 ) { change(i,j,p,q); return 0; } else if(level==14 && i==3&&j==7 && A[i][j].coin=='Q' && A[i][j].color==white && p==1&&q==5 ) { change(i,j,p,q); return 0; } else if(level==15 && i==4&&j==5 && A[i][j].coin=='H' && A[i][j].color==white && p==2&&q==6 ) { change(i,j,p,q); getch(); return 0; } else if(p==i && q==j) { setcolor(RED); rectangle(A[p][q].x,A[p][q].y,A[p][q].x+43,A[p][q].y+43); stop++; } else { setfillstyle(SOLID_FILL,WHITE); bar(0,getmaxy()-15,getmaxx(),getmaxy()); settextstyle(2,0,4); outtextxy(10,getmaxy()-15,"Nope ... Try again ... "); getch(); setcolor(WHITE); rectangle(A[i][j].x,A[i][j].y,A[i][j].x+43,A[i][j].y+43); rectangle(A[p][q].x,A[p][q].y,A[p][q].x+43,A[p][q].y+43); stop++; lives--; drawextra(level,lives); if(lives==0) { setfillstyle(SOLID_FILL,WHITE); bar(0,getmaxy()-15,getmaxx(),getmaxy()); settextstyle(2,0,4); setcolor(RED); outtextxy(10,getmaxy()-15,"GAME OVER !! "); getch(); spawnl(P_WAIT,"gameovrp.exe",NULL); cleardevice(); exit(0); } i=p; j=q; }}}}}}}
void main() { int gdriver = DETECT, gmode; initgraph(&gdriver, &gmode, "\\tc\\bgi"); fstream file; file.open("levels.txt",ios::binary|ios::in); if(!file) cout<<"Couldnt open the file"; file.read((char*)&game.level,sizeof(game.level)); file.close(); cleardevice(); while(game.level<16) { if(game.level==1) { game.level1(); drawextra(game.level,game.lives); } else if(game.level==2) { game.level2(); drawextra(game.level,game.lives); } else if(game.level==3) { game.level3(); drawextra(game.level,game.lives); } else if(game.level==4) { game.level4(); drawextra(game.level,game.lives); } else if(game.level==5) { game.level5(); drawextra(game.level,game.lives); } else if(game.level==6) { game.level6(); drawextra(game.level,game.lives); } else if(game.level==7) { game.level7(); drawextra(game.level,game.lives); } else if(game.level==8) { game.level8(); drawextra(game.level,game.lives); } else if(game.level==9) { game.level9(); drawextra(game.level,game.lives); } else if(game.level==10) { game.level10(); drawextra(game.level,game.lives); } else if(game.level==11) { game.level11(); drawextra(game.level,game.lives); } else if(game.level==12) { game.level12(); drawextra(game.level,game.lives); } else if(game.level==13) { game.level13(); drawextra(game.level,game.lives); } else if(game.level==14) { game.level14(); drawextra(game.level,game.lives); } else if(game.level==15) { game.level15(); drawextra(game.level,game.lives); } game.common(); } if(game.level==16) { spawnl(P_WAIT,"winpuzzl.exe",NULL); cleardevice(); exit(0); } closegraph(); }
_WCRTLINK int spawnve( int mode, const CHAR_TYPE * path, const CHAR_TYPE * const argv[], const CHAR_TYPE * const in_envp[] ) { const CHAR_TYPE * const *envp = (const CHAR_TYPE * const *)in_envp; CHAR_TYPE *envmem; CHAR_TYPE *envstrings; unsigned envseg; int len; CHAR_TYPE SPVE_NEAR *np; CHAR_TYPE SPVE_NEAR *p; CHAR_TYPE SPVE_NEAR *end_of_p; int rc; int retval; int num_of_paras; /* for environment */ size_t cmdline_len; CHAR_TYPE SPVE_NEAR *cmdline_mem; CHAR_TYPE SPVE_NEAR *cmdline; CHAR_TYPE *drive; CHAR_TYPE *dir; CHAR_TYPE *fname; CHAR_TYPE *ext; if( mode == OLD_P_OVERLAY ) { rc = __F_NAME(execve,_wexecve)( path, argv, envp ); return( rc ); } retval = __F_NAME(__cenvarg,__wcenvarg)( argv, envp, &envmem, &envstrings, &envseg, &cmdline_len, FALSE ); if( retval == -1 ) { return( -1 ); } num_of_paras = retval; len = __F_NAME(strlen,wcslen)( path ) + 7 + _MAX_PATH2; np = LIB_ALLOC( len * sizeof( CHAR_TYPE ) ); if( np == NULL ) { p = (CHAR_TYPE SPVE_NEAR *)alloca( len * sizeof( CHAR_TYPE ) ); if( p == NULL ) { lib_free( envmem ); return( -1 ); } } else { p = np; } __F_NAME(_splitpath2,_wsplitpath2)( path, p + ( len - _MAX_PATH2 ), &drive, &dir, &fname, &ext ); /* allocate the cmdline buffer */ cmdline_mem = LIB_ALLOC( cmdline_len * sizeof( CHAR_TYPE ) ); if( cmdline_mem == NULL ) { cmdline = (CHAR_TYPE SPVE_NEAR *)alloca( cmdline_len * sizeof( CHAR_TYPE ) ); if( cmdline == NULL ) { retval = -1; _RWD_errno = E2BIG; } } else { cmdline = cmdline_mem; } if( cmdline != NULL ) { __F_NAME(_makepath,_wmakepath)( p, drive, dir, fname, ext ); _RWD_errno = ENOENT; if( ext[0] != NULLCHAR ) { if( __F_NAME(stricmp,wcscmp)( ext, STRING( ".bat" ) ) == 0 ) { retval = -1; /* assume file doesn't exist */ if( file_exists( p ) ) { /* the environment will have to be reconstructed */ lib_free( envmem ); envmem = NULL; __F_NAME(__ccmdline,__wccmdline)( p, argv, cmdline, 1 ); retval = spawnl( mode, getenv( STRING( "COMSPEC" ) ), STRING( "COMMAND" ), STRING( "/c " ), p, cmdline, NULL ); } } else { _RWD_errno = 0; /* user specified an extension, so try it */ retval = __F_NAME(_dospawn,_wdospawn)( mode, p, cmdline, envmem, argv ); } } else { end_of_p = p + __F_NAME(strlen,wcslen)( p ); __F_NAME(strcpy,wcscpy)( end_of_p, STRING( ".com" ) ); _RWD_errno = 0; retval = __F_NAME(_dospawn,_wdospawn)( mode, p, cmdline, envmem, argv ); if( _RWD_errno == ENOENT || _RWD_errno == EINVAL ) { _RWD_errno = 0; __F_NAME(strcpy,wcscpy)( end_of_p, STRING( ".exe" ) ); retval = __F_NAME(_dospawn,_wdospawn)( mode, p, cmdline, envmem, argv ); if( _RWD_errno == ENOENT || _RWD_errno == EINVAL ) { /* try for a .BAT file */ _RWD_errno = 0; __F_NAME(strcpy,wcscpy)( end_of_p, STRING( ".bat" ) ); if( file_exists( p ) ) { /* the environment will have to be reconstructed */ lib_free( envmem ); envmem = NULL; __F_NAME(__ccmdline,__wccmdline)( p, argv, cmdline, 1 ); retval = spawnl( mode, getenv( STRING( "COMSPEC" ) ), STRING( "COMMAND" ), STRING( "/c " ), p, cmdline, NULL ); } } } } } LIB_FREE( cmdline_mem ); LIB_FREE( np ); lib_free( envmem ); return( retval ); }
void main(void){ void choice(char ); void menu(int ); void colorstring(char s[],int t); void prompt(int ); /* int x1,y1,x2,y2,x3,y3,x4,y4,x5,y5; */ int x6,y6,x7,y7,x8,y8,x9,y9,x10,y10,x11,y11,x12,y12,x13,y13,x14,y14,x15,y15; /* int x16,y16; */ int i; char encode(char ); int written,result; int user; char key; char r[]="DARKNIGHT"; char r2[50]; /* int written2; */ printf("\nPsychotron Cybernetics (c) 11/08/93 by Alexey Zilber\nInstallation.\n"); getdate(&d); game.day=d.da_day; game.bbs_type=0x00; game.registered=0x01; game.pool=0x00; game.wanted=0x00; game.reward=0x00; strcpy(game.bbs_name,"Cyber-Design"); strcpy(game.sys_name,"Alexey Zilber"); strcpy(game.game_dir,"C:\\"); strcpy(game.door_dir,"C:\\"); strcpy(game.proto_dir,"C:\\"); strcpy(r2,"000000000"); if(access("game.dat",0)==0){ if((evenmore=fopen("game.dat","rb"))==NULL){ printf("Error opening game.dat!\n"); exit(2); } written=fread(&game,sizeof(struct gm),1,evenmore); fclose(evenmore); } redraw: ; clrscr(); menu(96); textcolor(LIGHTGRAY); cprintf("INSTALLATION"); menu(97); choice('B'); colorstring("BBS Name: ",1); /* x1=wherex(); y1=wherey(); */ printf("%s\n",game.bbs_name); choice('N'); colorstring("Sysop's Name: ",1); /* x2=wherex(); y2=wherey(); */ printf("%s\n",game.sys_name); choice('D'); colorstring("GAME Directory [use trailing \\]:",1); /* x3=wherex(); y3=wherey(); */ printf("\n"); printf("%s\n",game.game_dir); choice('O'); colorstring("DROP FILE Directory [use trailing \\]:",1); /* x4=wherex(); y4=wherey(); */ printf("\n"); printf("%s\n",game.door_dir); choice('P'); colorstring("Protocols Directory (for Zmodem) [use trialing \\]:",1); /* x5=wherex(); y5=wherey(); */ printf("\n"); printf("%s\n",game.proto_dir); choice('R'); colorstring("Registration Code: ",1); /* x16=wherex(); y16=wherey(); */ printf("%s\n",r2); colorstring("BBS Type:",1); printf("\n"); choice('1'); colorstring("Renegade. [ ]",1); x6=wherex(); y6=wherey(); if(game.bbs_type==0x01){ gotoxy(x6-3,y6); textcolor(LIGHTRED); cprintf("�"); gotoxy(x6,y6); }else{ gotoxy(x6-3,y6); cprintf(" "); gotoxy(x6,y6); } printf("\n"); choice('2'); colorstring("Searchlight. [ ]",1); x7=wherex(); y7=wherey(); if(game.bbs_type==0x02){ gotoxy(x7-3,y7); textcolor(LIGHTRED); cprintf("�"); gotoxy(x7,y7); }else{ gotoxy(x7-3,y7); cprintf(" "); gotoxy(x7,y7); } printf("\n"); choice('3'); colorstring("Celerity. [ ]",1); x8=wherex(); y8=wherey(); if(game.bbs_type==0x03){ gotoxy(x8-3,y8); textcolor(LIGHTRED); cprintf("�"); gotoxy(x8,y8); }else{ gotoxy(x8-3,y8); cprintf(" "); gotoxy(x8,y8); } printf("\n"); choice('4'); colorstring("Pc-board. [ ]",1); x9=wherex(); y9=wherey(); if(game.bbs_type==0x04){ gotoxy(x9-3,y9); textcolor(LIGHTRED); cprintf("�"); gotoxy(x9,y9); }else{ gotoxy(x9-3,y9); cprintf(" "); gotoxy(x9,y9); } printf("\n"); choice('5'); colorstring("Telegard. [ ]",1); x10=wherex(); y10=wherey(); if(game.bbs_type==0x05){ gotoxy(x10-3,y10); textcolor(LIGHTRED); cprintf("�"); gotoxy(x10,y10); }else{ gotoxy(x10-3,y10); cprintf(" "); gotoxy(x10,y10); } printf("\n"); choice('6'); colorstring("Wild-Cat. [ ]",1); x11=wherex(); y11=wherey(); if(game.bbs_type==0x06){ gotoxy(x11-3,y11); textcolor(LIGHTRED); cprintf("�"); gotoxy(x11,y11); }else{ gotoxy(x11-3,y11); cprintf(" "); gotoxy(x11,y11); } printf("\n"); choice('7'); colorstring("WWIV. [ ]",1); x12=wherex(); y12=wherey(); if(game.bbs_type==0x07){ gotoxy(x12-3,y12); textcolor(LIGHTRED); cprintf("�"); gotoxy(x12,y12); }else{ gotoxy(x12-3,y12); cprintf(" "); gotoxy(x12,y12); } printf("\n"); choice('8'); colorstring("Vision\\X. [ ]",1); x13=wherex(); y13=wherey(); if(game.bbs_type==0x08){ gotoxy(x13-3,y13); textcolor(LIGHTRED); cprintf("�"); gotoxy(x13,y13); }else{ gotoxy(x13-3,y13); cprintf(" "); gotoxy(x13,y13); } printf("\n"); choice('9'); colorstring("Oblivion. [ ]",1); x14=wherex(); y14=wherey(); if(game.bbs_type==0x09){ gotoxy(x14-3,y14); textcolor(LIGHTRED); cprintf("�"); gotoxy(x14,y14); }else{ gotoxy(x14-3,y14); cprintf(" "); gotoxy(x14,y14); } printf("\n"); choice('*'); colorstring("Other. [ ]",1); x15=wherex(); y15=wherey(); if(game.bbs_type==0x0A){ gotoxy(x15-3,y15); textcolor(LIGHTRED); cprintf("�"); gotoxy(x15,y15); }else{ gotoxy(x15-3,y15); cprintf(" "); gotoxy(x15,y15); } printf("\n"); choice('X'); colorstring("Exit WITHOUT Save.",3); printf("\n"); choice('Z'); colorstring("Save & Continue.",3); printf("\n"); menu(98); prompt(1); do{ key=getch(); }while(!strchr("bndorpxz123456789*", tolower(key))); switch (key){ case 'b': printf("\n"); prompt(3); gets(game.bbs_name); break; case 'n': printf("\n"); prompt(3); gets(game.sys_name); break; case 'd': printf("\n"); prompt(3); gets(game.game_dir); break; case 'o': printf("\n"); prompt(3); gets(game.door_dir); break; case 'p': printf("\n"); prompt(3); gets(game.proto_dir); break; case 'r': printf("\n"); prompt(3); gets(r2); if(strcmp(r,r2)==0) game.registered=encode(0x03); break; case 'x': clrscr(); colorstring("Game NOT installed!",3); printf("\n"); exit(1); case 'z': if(game.bbs_type==0x00){ colorstring("You must complete ALL fields to exit!",3); printf("\n"); prompt(2); getch(); break; } else{ if((more=fopen("game.dat","wb"))==NULL){ printf("Error opening game.dat!"); exit(2); } written=fwrite(&game, sizeof(struct gm),1,more); fclose(more); clrscr(); printf("Wrote %d units to file game.dat.\n\n",written); result=spawnl(P_WAIT,"egen.exe",NULL); if(result==15) printf("INSTALL SUCCESFULL!\n"); if(result!=15) printf("INSTALL FAILED! Result code=%d",result); exit(0); } case '1': game.bbs_type=0x01; break; case '2': game.bbs_type=0x02; break; case '3': game.bbs_type=0x03; break; case '4': game.bbs_type=0x04; break; case '5': game.bbs_type=0x05; break; case '6': game.bbs_type=0x06; break; case '7': game.bbs_type=0x07; break; case '8': game.bbs_type=0x08; break; case '9': game.bbs_type=0x09; break; case '*': game.bbs_type=0x0A; break; } goto redraw; }
void sys_spawn_shell (void) { spawnl (P_WAIT, getenv ("COMSPEC"), "-", 0); }
void __fastcall TDB_packer::ExtBtn5Click(TObject *Sender) { btnSaveClick((TObject*)0); spawnl(P_WAIT, "compress_dbx.bat", "compress_dbx.bat", m_cfgFileName.c_str()); }
int main (int argc, char *argv[]) { HQUEUE hq_server, hq_client; ULONG rc, len; PID owner_pid; PVOID data; REQUESTDATA request; BYTE priority; char buffer[1024], name[512], *p; long client_pid; if (argc == 1) { if (spawnl (P_NOWAIT, argv[0], argv[0], "-r", NULL) < 0) { perror ("spawn"); return (1); } for (;;) { if (fgets (buffer, sizeof (buffer), stdin) == 0) return (0); p = buffer; while (*p != 0 && !(*p >= '0' && *p <= '9')) ++p; client_pid = strtol (p, NULL, 10); (void)sprintf (name, "/queues/emacs/clients/%ld", client_pid); rc = DosOpenQueue (&owner_pid, &hq_client, name); if (rc == 0) { len = strlen (buffer) + 1; rc = DosAllocSharedMem (&data, 0, len, PAG_COMMIT | OBJ_GIVEABLE | PAG_READ | PAG_WRITE); ERROR ("DosAllocSharedMem"); rc = DosGiveSharedMem (data, client_pid, PAG_READ); ERROR ("DosGiveSharedMem"); (void)memcpy (data, buffer, len); rc = DosWriteQueue (hq_client, 0, len, data, 0); ERROR ("DosWriteQueue"); rc = DosFreeMem (data); ERROR ("DosFreeMem"); rc = DosCloseQueue (hq_client); ERROR ("DosCloseQueue"); } } } else if (argc == 2 && strcmp (argv[1], "-r") == 0) { rc = DosCreateQueue (&hq_server, QUE_FIFO | QUE_CONVERT_ADDRESS, "/queues/emacs/server"); ERROR ("DosCreateQueue"); for (;;) { rc = DosReadQueue (hq_server, &request, &len, &data, 0, DCWW_WAIT, &priority, 0); ERROR ("DosReadQueue"); (void)printf ("Client: %d ", (int)request.pid); (void)fputs (data, stdout); (void)fflush (stdout); rc = DosFreeMem (data); ERROR ("DosFreeMem"); } } else { (void)fprintf (stderr, "Usage: %s\n", argv[0]); return (1); } }
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 = NULL; 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. */ env = environ; while( env ) { if( !strncmp( *env, "PATH=", 5 ) ) { path = *env; break; } ++env; } 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 ) ); 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 ); }
/**************************************************************************** PARAMETERS: URL - New URL for the page to load RETURNS: True if page loaded successfully, false if not REMARKS: Remove an applet from the manager. Called during applet destruction ****************************************************************************/ bool wxHtmlAppletWindow::LoadPage( const wxString& link) { wxString href(link); if (link.GetChar(0) == '?'){ wxString cmd = link.BeforeFirst('='); wxString cmdValue = link.AfterFirst('='); // Launches the default Internet browser for the system. if(!(cmd.CmpNoCase("?EXTERNAL"))) { return wxSpawnBrowser(this, cmdValue.c_str()); } // Launches an external program on the system. if (!(cmd.CmpNoCase("?EXECUTE"))) { int waitflag = P_NOWAIT; bool ret; wxString currentdir; wxString filename, path, ext; // Parse the params sent to the execute command. For now the only // parm is "wait". wait will cause spawn wait, default is nowait. // Since we only need one param for now I am not going to make this // any smater then it needs to be. If we need more params later i'll // fix it. int i = cmdValue.Find('('); if (i != -1) { wxString param = cmdValue.AfterFirst('('); cmdValue.Truncate(i); if (!param.CmpNoCase("wait)")) waitflag = P_WAIT; } currentdir = wxGetCwd(); //we don't want to change the path of the virtual file system so we have to use these //functions rather than the filesystem wxSplitPath(cmdValue, &path, &filename, &ext); if (path.CmpNoCase("") != 0) wxSetWorkingDirectory(path); ret = !spawnl( waitflag, cmdValue , NULL ); //HACK should use wxExecute //ret = wxExecute(filename, bool sync = FALSE, wxProcess *callback = NULL) wxSetWorkingDirectory(currentdir); return ret; } // Looks for a href in a variable stored as a cookie. The href can be // changed on the fly. if (!(cmd.CmpNoCase("?VIRTUAL"))){ wxObject *obj = FindCookie(cmdValue); VirtualData *virtData = wxDynamicCast(obj,VirtualData); if (virtData) { // recurse and loadpage, just in case the link is like another // ? link return LoadPage(virtData->GetHref()); } else { #ifdef CHECKED wxLogError(_T("VIRTUAL LINK ERROR: '%s' does not exist."), cmdValue.c_str()); #endif return true; } } // This launches a qlet - It is like an applet but is more generic in that it // can be of any wxWin type so it then has the freedom to do more stuff. if (!(cmd.CmpNoCase("?WXPLUGIN"))){ if (!cmdValue.IsNull()) { // TODO: We are going to need to add code to parse the command line // parameters string in here in the future... wxString cmdLine = link.AfterFirst('('); cmdLine = cmdLine.BeforeLast(')'); if (!CreatePlugIn(cmdValue,cmdLine)) { #ifdef CHECKED wxLogError(_T("Launch PlugIn ERROR: '%s' does not exist."), cmdValue.c_str()); #endif } } return true; } // This used in a link or href will take you back in the history. if (!(cmd.CmpNoCase("?BACK"))){ HistoryBack(); return true; } // This used in a link or href will take you forward in the history if (!(cmd.CmpNoCase("?FORWARD"))){ HistoryForward(); return true; } } // Inform all the applets that the new page is being loaded for (wxAppletList::Node *node = m_AppletList.GetFirst(); node; node = node->GetNext()) (node->GetData())->OnLinkClicked(wxHtmlLinkInfo(href)); Show(false); m_openedlast = href; bool stat = wxHtmlWindow::LoadPage(href); Show(true); // Enable/Dis the navbar tools if (m_NavBarEnabled) { m_NavBar->EnableTool(m_NavForwardId,HistoryCanForward()); m_NavBar->EnableTool(m_NavBackId,HistoryCanBack()); } return stat; }
int CompressFile(char* infile, char* outfile) { return spawnl(P_WAIT, "huf", "huf", infile, outfile, NULL) & 255; }
int mf_mftalk_initscreen (void) { int app; /* Client application type. */ char *prog, *name; /* Client program name. */ /* Size of METAFONT window. */ char height[MAX_INT_LENGTH], width[MAX_INT_LENGTH]; /* Inherited pipe handles. */ char input[MAX_INT_LENGTH], output[MAX_INT_LENGTH]; char parent[MAX_INT_LENGTH]; /* My own process ID. */ int sc_pipe[2]; /* Server->Client pipe. */ int cs_pipe[2]; /* Client->Server pipe. */ int res, ack; /* Wait until child is ready. */ prog = kpse_var_value ("MFTALK"); if (prog == NULL) prog = "mftalk.exe"; name = app_type (prog, &app); if (!name) return 0; if (pipe (sc_pipe) == -1) return 0; if (pipe (cs_pipe) == -1) { close (sc_pipe[0]); close (sc_pipe[1]); return 0; } #ifdef OS2 fatal (setmode, setmode (sc_pipe[0], O_BINARY) == -1); fatal (setmode, setmode (sc_pipe[1], O_BINARY) == -1); fatal (setmode, setmode (cs_pipe[0], O_BINARY) == -1); fatal (setmode, setmode (cs_pipe[1], O_BINARY) == -1); #endif old = signal (SIGCHLD, child_died); fatal (old, old == SIG_ERR); sprintf (height, "-h%d", screendepth); sprintf (width, "-w%d", screenwidth); sprintf (input, "-i%d", sc_pipe[0]); sprintf (output, "-o%d", cs_pipe[1]); sprintf (parent, "-p%d", getpid ()); #ifdef OS2 pid = spawnl (app, name, prog, height, width, input, output, parent, NULL); #else pid = fork (); if (pid == 0) { fatal (close, close (0) == -1); fatal (dup, dup (sc_pipe[0]) != 0); fatal (close, close (sc_pipe[0]) == -1); fatal (close, close (sc_pipe[1]) == -1); fatal (close, close (1) == -1); fatal (dup, dup (cs_pipe[1]) != 1); fatal (close, close (cs_pipe[0]) == -1); fatal (close, close (cs_pipe[1]) == -1); /* We still pass the file handles as parameters for * backward compatibility. instead of sc_pipe[0] and * cs_pipe[1] we just pass 0 (stdin) and 1 (stdout). */ sprintf (input, "-i0"); sprintf (output, "-o1"); execl (name, prog, height, width, input, output, parent, NULL); } #endif /* not OS2 */ switch (pid) { case -1: failure: fatal (close, close (sc_pipe[0]) == -1); fatal (close, close (sc_pipe[1]) == -1); fatal (close, close (cs_pipe[0]) == -1); fatal (close, close (cs_pipe[1]) == -1); fatal (signal, signal (SIGCHLD, old) == SIG_ERR); break; default: res = read (cs_pipe[0], &ack, sizeof (int)); if (res != sizeof (int) || ack != MF_ACK) goto failure; fatal (close, close (cs_pipe[0]) == -1); win = sc_pipe[1]; break; } return (win == -1) ? 0 : 1; }