Exemplo n.º 1
0
// init and open sound, video pipes
// fn is filename passed from command line, typically final output file
void I_CapturePrep (const char *fn)
{
  vid_fname = fn;

  if (!parsecommand (soundpipe.command, cap_soundcommand, sizeof(soundpipe.command)))
  {
    lprintf (LO_ERROR, "I_CapturePrep: malformed command %s\n", cap_soundcommand);
    capturing_video = 0;
    return;
  }
  if (!parsecommand (videopipe.command, cap_videocommand, sizeof(videopipe.command)))
  {
    lprintf (LO_ERROR, "I_CapturePrep: malformed command %s\n", cap_videocommand);
    capturing_video = 0;
    return;
  }
  if (!parsecommand (muxpipe.command, cap_muxcommand, sizeof(muxpipe.command)))
  {
    lprintf (LO_ERROR, "I_CapturePrep: malformed command %s\n", cap_muxcommand);
    capturing_video = 0;
    return;
  }

  lprintf (LO_INFO, "I_CapturePrep: opening pipe \"%s\"\n", soundpipe.command);
  if (!my_popen3 (&soundpipe))
  {
    lprintf (LO_ERROR, "I_CapturePrep: sound pipe failed\n");
    capturing_video = 0;
    return;
  }
  lprintf (LO_INFO, "I_CapturePrep: opening pipe \"%s\"\n", videopipe.command);
  if (!my_popen3 (&videopipe))
  {
    lprintf (LO_ERROR, "I_CapturePrep: video pipe failed\n");
    my_pclose3 (&soundpipe);
    capturing_video = 0;
    return;
  }
  I_SetSoundCap ();
  lprintf (LO_INFO, "I_CapturePrep: video capture started\n");
  capturing_video = 1;

  // start reader threads
  soundpipe.stdoutdumpname = "sound_stdout.txt";
  soundpipe.stderrdumpname = "sound_stderr.txt";
  soundpipe.outthread = SDL_CreateThread (threadstdoutproc, "soundpipe.outthread", &soundpipe);
  soundpipe.errthread = SDL_CreateThread (threadstderrproc, "soundpipe.errthread", &soundpipe);
  videopipe.stdoutdumpname = "video_stdout.txt";
  videopipe.stderrdumpname = "video_stderr.txt";
  videopipe.outthread = SDL_CreateThread (threadstdoutproc, "videopipe.outthread", &videopipe);
  videopipe.errthread = SDL_CreateThread (threadstderrproc, "videopipe.errthread", &videopipe);

  atexit (I_CaptureFinish);
}
int main () {
  // variable declaration
  char command[MAXCMD];
  int* heap = malloc(HEAPSIZE);
  char* argv[MAXARGS];

  // memory management
  *heap = HEAPSIZE;
  bID = 0;

  // Loop - fetch command, call functions
  while(1) {
     printf("> ");
     gets(command);
     parsecommand(command, argv);

     if(strcmp(argv[0], "allocate") == 0)
       Allocate(heap, atoi(argv[1]));
     else if(strcmp(argv[0], "free") == 0)
       Free(heap, atoi(argv[1]));
     else if(strcmp(argv[0], "blocklist") == 0)
       blockList(heap);
     else if(strcmp(argv[0], "writeheap") == 0)
       writeHeap(heap, atoi(argv[1]), argv[2][0], atoi(argv[3]));
     else if(strcmp(argv[0], "printheap") == 0)
       printHeap(heap, atoi(argv[1]), atoi(argv[2]));
     else if(strcmp(argv[0], "quit") == 0)
       break;
  }

  free(heap);
  return 0;
}
Exemplo n.º 3
0
Arquivo: bosh.c Projeto: Madx-com/BOSC
/* --- main loop of the simple shell --- */
int main(int argc, char* argv[]) {

  signal(SIGINT, sig_handler);

  /* initialize the shell */
  char *cmdline;
  char *hostname[HOSTNAMEMAX]; /* changed to a pointer */
  int terminate = 0;
  Shellcmd shellcmd;

  if (gethostname(hostname)) {
    /* parse commands until exit or ctrl-c */
    while (!terminate) {
      printf("%s:$", *hostname);
      if (cmdline = readline(" ")) {
	if(*cmdline) {
	  add_history(cmdline);
	  if (parsecommand(cmdline, &shellcmd)) {
	    terminate = executeshellcmd(&shellcmd);
	  }
	}
	free(cmdline);
      } else terminate = 1;
    }
    free(*hostname);
    printf("Exiting bosh.\n");
  }

  return EXIT_SUCCESS;
}
void shell(){
	while(1 && shutdown == 0){
	prompt();
	char s[MAX_SHELL_BUFFER];
	int i=0;
	char c;
		while( ((c=getchar()) != '\n') && i < MAX_SHELL_BUFFER -1 ){
				if(c!=0){
					if(c == '\b' && i >= 1){
						i--;
						putchar(c);
					}
					if(c != '\b' && c!='\n'){
						if(i < MAX_SHELL_BUFFER - 2){
							s[i] = c;
							i++;
							putchar(c);	
						}
						if(i == MAX_SHELL_BUFFER - 1){
							genericBeep();
						}
					}
				}
		}
	putchar(c);
	s[i]='\0';
	parsecommand(s);
	}
}
Exemplo n.º 5
0
/* --- main loop of the simple shell --- */
int main(int argc, char* argv[]) {
  signal(SIGINT, SIG_IGN); // Ignore Ctrl + C - so we don't close the shell
  /* initialize the shell */
  char *cmdline;
  char hostname[HOSTNAMEMAX];
  int terminate = 0;
  Shellcmd shellcmd;
  
  if (gethostnamefromproc(hostname)) {

    /* parse commands until exit or ctrl-c */
    while (!terminate) {
      printf("%s", hostname);
      if (strcmp(cmdline = readline(":# "), "exit") != 0) {
	if(*cmdline) {
          add_history(cmdline);
          if (parsecommand(cmdline, &shellcmd)) {
            terminate = executeshellcmd(&shellcmd);
          }
	}
	free(cmdline);
      } else terminate = 1;
    }
    printf("Exiting BOSH.\n");
  }

  return EXIT_SUCCESS;
}
Exemplo n.º 6
0
void shell_enter(){
	if(shellbuff.buffer[0]!=0){
		putchar('\n');
		parsecommand(shellbuff.buffer);
		restart_shell_buffer();
		prompt();
	}
	return;
}
Exemplo n.º 7
0
void test_parsecommand(void) {
	char command_basic[MAXCMD]      = "./test this that";
	char command_tabbed_mid[MAXCMD] = "./test 		this 		that";
	char command_tabbed_all[MAXCMD] = "		./test 		this 		that		";
	char* argv[MAXARGS];
	CU_ASSERT(parsecommand(command_basic, argv) == 2); // right argc
	CU_ASSERT(strcmp(argv[0], "./test") == 0);
	CU_ASSERT(strcmp(argv[1], "this") == 0);
	CU_ASSERT(strcmp(argv[2], "that") == 0);
	CU_ASSERT(parsecommand(command_tabbed_mid, argv) == 2);
	CU_ASSERT(strcmp(argv[0], "./test") == 0);
	CU_ASSERT(strcmp(argv[1], "this") == 0);
	CU_ASSERT(strcmp(argv[2], "that") == 0);
	CU_ASSERT(parsecommand(command_tabbed_all, argv) == 2);
	CU_ASSERT(strcmp(argv[0], "./test") == 0);
	CU_ASSERT(strcmp(argv[1], "this") == 0);
	CU_ASSERT(strcmp(argv[2], "that") == 0);
}
Exemplo n.º 8
0
Arquivo: bosh.c Projeto: swungify/BOSC
/* --- main loop of the simple shell --- */
int main(int argc, char* argv[]) {

  /* Set the SIGINT (Ctrl-C) signal handler to sigintHandler 
    Refer http://en.cppreference.com/w/c/program/signal */
  signal(SIGINT, sigintHandler);

  /* initialize the shell */
  char *cmdline;
  char hostname[HOSTNAMEMAX];
  int terminate = 0;
  Shellcmd shellcmd;
  
  if (gethostname(hostname)) {

    /* parse commands until exit or ctrl-c */
    while (!terminate) {
      printf("%s", hostname);
      if (cmdline = readline(":# ")) {
      	if(*cmdline) {
          if(strcmp(cmdline, "exit") == 0) {
             break;
          } 
      	  add_history(cmdline);
      	  if (parsecommand(cmdline, &shellcmd)) {
            pid_t pid = fork(); //Make a child process that calls the commands
            if(pid == 0)
            {
              currentPId = getpid();
              terminate = executeshellcmd(&shellcmd);
              return;
            }
            else {
            int status;
            waitpid(pid, &status, 0);
            }
      	  }
      	}
    	 free(cmdline);
      } else terminate = 1;
    }
    printf("Exiting bosh.\n");
  }    
    
  return EXIT_SUCCESS;
}
Exemplo n.º 9
0
int main(int argc, char **argv) {
	
	int waittime = -1;
	char inputbuffer[1024];
	char *newenviron[] = {NULL};
	char *newargv[MAX_ARGS];
	char *newcmd = NULL;
	if(argc > 1) {
		waittime = atoi(argv[1]); 
	}
	signal(SIGALRM,handler);
	writeprompt();
	while(1) {
		int numread = read(STDIN_FILENO,inputbuffer,1024);
		//test for reading in return
		//check for empty array/set null
		if(numread >= MAX_ARG_LENGTH) {
			perror("Length of arguments exceeed the limitation");
		}
		inputbuffer[numread] = '\0';
		parsecommand(inputbuffer,&newcmd,newargv);
		pid = fork();
		if(!pid) {
			execve(newcmd,newargv,newenviron); 
			perror("execve failed");
			_exit(0);
		}else if(pid <0) {
			perror("fork() failed");
			_exit(0);
		}else{
			if(waittime > 0) {
				alarm(waittime);
			}
			wait(pid);
			writeprompt();
		}
		free( newcmd);
	}
	
}
Exemplo n.º 10
0
Arquivo: bosh.c Projeto: Jelb/BOSC
/* --- main loop of the simple shell --- */
int main(int argc, char* argv[]) {

  /* initialize the shell */
  char *cmdline;
  char hostname[HOSTNAMEMAX];
  int terminate = 0;
  Shellcmd shellcmd;
  
  //char cmd[100];
  //sprintf(cmd, "/bin/ls");
  //system(cmd);
  


  if (gethostname(hostname)) {

    /* parse commands until exit or ctrl-c */
    while (!terminate) {
      printf("%s", hostname);
      if (cmdline = readline(":# ")) {
	      if(*cmdline) {
	        add_history(cmdline);
	        if (parsecommand(cmdline, &shellcmd)) {
	          terminate = executeshellcmd(&shellcmd);
	        }
	      }
	      free(cmdline);
      } else {
        terminate = 1;
      }
    }

    printf("Exiting bosh.\n");
  }  
  return EXIT_SUCCESS;
}