Example #1
0
/* 
 * Handles changing the mode (by returning the char representing the new (future) mode) and printing the current mode.
 */
char handle_mode(char **command, char curr_mode, char future_mode) { 
    if (is_mode(command) == 1) {
        if (curr_mode == 'p') {
            printf("parallel\n");
        }
        else if (curr_mode == 's') {
            printf("sequential\n");
        }
    }
    if (is_mode(command) == 2) {
        future_mode = 's';
    }
    if (is_mode(command) == 3) {
        future_mode = 'p';
    }
    return future_mode;
}
Example #2
0
static void print_cbm_char(mps_t *mps, const BYTE rawchar)
{
    unsigned int y, x;
    int c, err = 0;

    c = (int)rawchar;

    /* in the ROM, graphics charset comes first, then business */
    if (!is_mode(mps, MPS_CRSRUP)) {
        c += 256;
    }

    for (y = 0; y < 7; y++) {
        if (is_mode(mps, MPS_DBLWDTH)) {
            for (x = 0; x < 6; x++) {
                if ((mps->pos + x * 2) >= MAX_COL) {
                    err = 1;
                    break;
                }
                mps->line[mps->pos + x * 2][y] = get_charset_bit(mps, c, x, y);
                if ((mps->pos + x * 2 + 1) >= MAX_COL) {
                    err = 1;
                    break;
                }
                mps->line[mps->pos + x * 2 + 1][y] = get_charset_bit(mps, c, x, y);
            }
        } else {
            for (x = 0; x < 6; x++) {
                if ((mps->pos + x) >= MAX_COL) {
                    err = 1;
                    break;
                }
                mps->line[mps->pos + x][y] = get_charset_bit(mps, c, x, y);
            }
        }
    }

    if (err) {
        log_error(drv803_log, "Printing beyond limit of %d dots.", MAX_COL);
    }

    mps->pos += is_mode(mps, MPS_DBLWDTH) ? 12 : 6;
}
Example #3
0
static int get_charset_bit(mps_t *mps, int nr, unsigned int col,
                           unsigned int row)
{
    int reverse, result;

    reverse = is_mode(mps, MPS_REVERSE);

    result = charset[nr][row] & (1 << (7 - col)) ? !reverse : reverse;

    return result;
}
Example #4
0
int
px_find_cipher(const char *name, PX_Cipher ** res)
{
	char		nbuf[PX_MAX_NAMELEN + 1];
	const char *mode = NULL;
	char	   *p;
	MCRYPT		ctx;

	PX_Cipher  *c;

	strcpy(nbuf, name);

	if ((p = strrchr(nbuf, '-')) != NULL)
	{
		if (is_mode(p + 1))
		{
			mode = p + 1;
			*p = 0;
		}
	}

	name = px_resolve_alias(aliases, nbuf);

	if (!mode)
	{
		mode = "cbc";

		/*
		 * if (mcrypt_module_is_block_algorithm(name, NULL)) mode = "cbc";
		 * else mode = "stream";
		 */
	}
	mode = px_resolve_alias(mode_aliases, mode);

	ctx = mcrypt_module_open((char *) name, NULL, (char *) mode, NULL);
	if (ctx == (void *) MCRYPT_FAILED)
		return -1;

	c = palloc(sizeof *c);
	c->iv_size = cipher_iv_size;
	c->key_size = cipher_key_size;
	c->block_size = cipher_block_size;
	c->init = cipher_init;
	c->encrypt = cipher_encrypt;
	c->decrypt = cipher_decrypt;
	c->free = cipher_free;
	c->ptr = ctx;
	c->pstat = 0;

	*res = c;
	return 0;
}
Example #5
0
/* 
 * Runs commands in sequential mode.
 */
char sequential_mode(char **pointers_to_commands, Node *head) {
    char mode = 's';
    pid_t cpid, w;
    char **command;
    char return_char = 's';
    int i = 0;
    while (pointers_to_commands[i] != NULL) {
        command = tokenify(pointers_to_commands[i], " \n\t");
        if (command[0] == NULL) {
            i++;
            free_tokens(command);
            continue;
        } 
        if (handle_exit(command) != 'n') {
            free_tokens(command);
            return 'e';
        }
        if (return_char != 'e' && is_mode(command)) {
            return_char = handle_mode(command, mode, return_char);
            i++;
            free_tokens(command);
            continue;
        }
        handle_parallel_builtins(command, NULL, NULL, mode);
        cpid = fork();
        if (cpid == 0) {
            char *tempcommand;
            tempcommand = prepend_path(command, head);
            command[0] = tempcommand;   
            if (execv(command[0], command) < 0) {
                fprintf(stderr, "execv failed: %s\n", strerror(errno));
                printf("That's not a valid command! \n");
                free_tokens(command);
                exit(EXIT_FAILURE);
            }
            free(tempcommand);
            }
        else {
            int status = 0;
            w = wait(&status);
            i++;
        }
        free_tokens(command);

    }
    return return_char;
}
Example #6
0
static void write_line(mps_t *mps, unsigned int prnr)
{
    int x, y;

    for (y = 0; y < 7; y++) {
        for (x = 0; x < 480; x++) {
            output_select_putc(prnr, (BYTE)(mps->line[x][y]
                                            ? OUTPUT_PIXEL_BLACK : OUTPUT_PIXEL_WHITE));
        }
        output_select_putc(prnr, (BYTE)(OUTPUT_NEWLINE));
    }

    if (!is_mode(mps, MPS_BITMODE)) {
        /* bitmode:  9 rows/inch (7lines/row * 9rows/inch=63 lines/inch) */
        /* charmode: 6 rows/inch (7lines/row * 6rows/inch=42 lines/inch) */
        /*   --> 63lines/inch - 42lines/inch = 21lines/inch missing */
        /*   --> 21lines/inch / 9row/inch = 3lines/row missing */
        output_select_putc(prnr, OUTPUT_NEWLINE);
        output_select_putc(prnr, OUTPUT_NEWLINE);
        output_select_putc(prnr, OUTPUT_NEWLINE);
    }

    mps->pos = 0;
}
int
main (void)
{
  const char *file = "test-dup2.tmp";
  char buffer[1];
  int fd = open (file, O_CREAT | O_TRUNC | O_RDWR, 0600);

  /* Assume std descriptors were provided by invoker.  */
  ASSERT (STDERR_FILENO < fd);
  ASSERT (is_open (fd));
  /* Ignore any other fd's leaked into this process.  */
  close (fd + 1);
  close (fd + 2);
  ASSERT (!is_open (fd + 1));
  ASSERT (!is_open (fd + 2));

  /* Assigning to self must be a no-op.  */
  ASSERT (dup2 (fd, fd) == fd);
  ASSERT (is_open (fd));

  /* The source must be valid.  */
  errno = 0;
  ASSERT (dup2 (-1, fd) == -1);
  ASSERT (errno == EBADF);
  errno = 0;
  ASSERT (dup2 (99, fd) == -1);
  ASSERT (errno == EBADF);
  errno = 0;
  ASSERT (dup2 (AT_FDCWD, fd) == -1);
  ASSERT (errno == EBADF);
  ASSERT (is_open (fd));

  /* If the source is not open, then the destination is unaffected.  */
  errno = 0;
  ASSERT (dup2 (fd + 1, fd + 1) == -1);
  ASSERT (errno == EBADF);
  ASSERT (!is_open (fd + 1));
  errno = 0;
  ASSERT (dup2 (fd + 1, fd) == -1);
  ASSERT (errno == EBADF);
  ASSERT (is_open (fd));

  /* The destination must be valid.  */
  errno = 0;
  ASSERT (dup2 (fd, -2) == -1);
  ASSERT (errno == EBADF);
  errno = 0;
  ASSERT (dup2 (fd, 10000000) == -1);
  ASSERT (errno == EBADF);

  /* Using dup2 can skip fds.  */
  ASSERT (dup2 (fd, fd + 2) == fd + 2);
  ASSERT (is_open (fd));
  ASSERT (!is_open (fd + 1));
  ASSERT (is_open (fd + 2));

  /* Verify that dup2 closes the previous occupant of a fd.  */
  ASSERT (open ("/dev/null", O_WRONLY, 0600) == fd + 1);
  ASSERT (dup2 (fd + 1, fd) == fd);
  ASSERT (close (fd + 1) == 0);
  ASSERT (write (fd, "1", 1) == 1);
  ASSERT (dup2 (fd + 2, fd) == fd);
  ASSERT (lseek (fd, 0, SEEK_END) == 0);
  ASSERT (write (fd + 2, "2", 1) == 1);
  ASSERT (lseek (fd, 0, SEEK_SET) == 0);
  ASSERT (read (fd, buffer, 1) == 1);
  ASSERT (*buffer == '2');

#if GNULIB_TEST_CLOEXEC
  /* Any new fd created by dup2 must not be cloexec.  */
  ASSERT (close (fd + 2) == 0);
  ASSERT (dup_cloexec (fd) == fd + 1);
  ASSERT (!is_inheritable (fd + 1));
  ASSERT (dup2 (fd + 1, fd + 1) == fd + 1);
  ASSERT (!is_inheritable (fd + 1));
  ASSERT (dup2 (fd + 1, fd + 2) == fd + 2);
  ASSERT (!is_inheritable (fd + 1));
  ASSERT (is_inheritable (fd + 2));
  errno = 0;
  ASSERT (dup2 (fd + 1, -1) == -1);
  ASSERT (errno == EBADF);
  ASSERT (!is_inheritable (fd + 1));
#endif

  /* On systems that distinguish between text and binary mode, dup2
     reuses the mode of the source.  */
  setmode (fd, O_BINARY);
  ASSERT (is_mode (fd, O_BINARY));
  ASSERT (dup2 (fd, fd + 1) == fd + 1);
  ASSERT (is_mode (fd + 1, O_BINARY));
  setmode (fd, O_TEXT);
  ASSERT (is_mode (fd, O_TEXT));
  ASSERT (dup2 (fd, fd + 1) == fd + 1);
  ASSERT (is_mode (fd + 1, O_TEXT));

  /* Clean up.  */
  ASSERT (close (fd + 2) == 0);
  ASSERT (close (fd + 1) == 0);
  ASSERT (close (fd) == 0);
  ASSERT (unlink (file) == 0);

  return 0;
}
Example #8
0
static void print_char(mps_t *mps, unsigned int prnr, const BYTE c)
{
    if (mps->pos >= MAX_COL) {  /* flush buffer*/
        write_line(mps, prnr);
        clear_buffer(mps);
    }
    if (mps->tab) {     /* decode tab-number*/
        mps->tabc[2 - mps->tab] = c;

        if (mps->tab == 1) {
            mps->pos =
                is_mode(mps, MPS_ESC) ?
                mps->tabc[0] << 8 | mps->tabc[1] :
                atoi((char *)mps->tabc) * 6;

            del_mode(mps, MPS_ESC);
        }

        mps->tab--;
        return;
    }

    if (is_mode(mps, MPS_ESC) && (c != 16)) {
        del_mode(mps, MPS_ESC);
    }

    if (is_mode(mps, MPS_REPEAT)) {
        mps->repeatn = c;
        del_mode(mps, MPS_REPEAT);
        return;
    }

    if (is_mode(mps, MPS_BITMODE) && (c & 128)) {
        print_bitmask(mps, c);
        return;
    }

    /* it seems that CR works even in quote mode */
    switch (c) {
        case 13: /* CR*/
            mps->pos = 0;
            if (is_mode(mps, MPS_BUSINESS)) {
                del_mode(mps, MPS_CRSRUP);
            } else {
                set_mode(mps, MPS_CRSRUP);
            }
            /* CR resets Quote mode, revers mode, ... */
            del_mode(mps, MPS_QUOTED);
            del_mode(mps, MPS_REVERSE);
            write_line(mps, prnr);
            clear_buffer(mps);
            return;
    }

    /* in text mode ignore most (?) other control chars when quote mode is active */
    if (!is_mode(mps, MPS_QUOTED) || is_mode(mps, MPS_BITMODE)) {

        switch (c) {
            case 8:
                set_mode(mps, MPS_BITMODE);
                mps->bitcnt = 0;
                return;

            case 10: /* LF*/
                write_line(mps, prnr);
                clear_buffer(mps);
                return;

#ifdef notyet
            /* Not really sure if the MPS803 recognizes this one... */
            case 13 + 128: /* shift CR: CR without LF (from 4023 printer) */
                mps->pos = 0;
                if (is_mode(mps, MPS_BUSINESS)) {
                    del_mode(mps, MPS_CRSRUP);
                } else {
                    set_mode(mps, MPS_CRSRUP);
                }
                /* CR resets Quote mode, revers mode, ... */
                del_mode(mps, MPS_QUOTED);
                del_mode(mps, MPS_REVERSE);
                return;
#endif

            case 14: /* EN on*/
                set_mode(mps, MPS_DBLWDTH);
                if (is_mode(mps, MPS_BITMODE)) {
                    bitmode_off(mps);
                }
                return;

            case 15: /* EN off*/
                del_mode(mps, MPS_DBLWDTH);
                if (is_mode(mps, MPS_BITMODE)) {
                    bitmode_off(mps);
                }
                return;

            case 16: /* POS*/
                mps->tab = 2; /* 2 chars (digits) following, number of first char*/
                return;

            /*
            * By sending the cursor up code [CHR$(145)] to your printer, following
            * characters will be printed in cursor up (graphic) mode until either
            * a carriage return or cursor down code [CHR$(17)] is detected.
            *
            * By sending the cursor down code [CHR$(17)] to your printer,
            * following characters will be printed in business mode until either
            * a carriage return or cursor up code [CHR$(145)] is detected.
            */
            case 17: /* crsr dn, enter businessmode local */
                del_mode(mps, MPS_CRSRUP);
                return;

            case 145: /* CRSR up, enter gfxmode local */
                set_mode(mps, MPS_CRSRUP);
                return;

            case 18:
                set_mode(mps, MPS_REVERSE);
                return;

            case 146: /* 18+128*/
                del_mode(mps, MPS_REVERSE);
                return;

            case 26: /* repeat last chr$(8) c times.*/
                set_mode(mps, MPS_REPEAT);
                mps->repeatn = 0;
                mps->bitcnt = 0;
                return;

            case 27:
                set_mode(mps, MPS_ESC); /* followed by 16, and number MSB, LSB*/
                return;
        }

    }

    if (is_mode(mps, MPS_BITMODE)) {
        return;
    }

   /* 
    * When an odd number of CHR$(34) is detected in a line, the control
    * codes $00-$1F and $80-$9F will be made visible by printing a
    * reverse character for each of these controls. This will continue
    * until an even number of quotes [CHR$(34)] has been received or until
    * end of this line.
    */
    if (c == 34) {
        mps->mode ^= MPS_QUOTED;
    }

    if (is_mode(mps, MPS_QUOTED)) {
        if (c <= 0x1f) {
            set_mode(mps, MPS_REVERSE);
            print_cbm_char(mps, (BYTE)(c + 0x40));
            del_mode(mps, MPS_REVERSE);
            return;
        }
        if ((c >= 0x80) && (c <= 0x9f)) {
            set_mode(mps, MPS_REVERSE);
            print_cbm_char(mps, (BYTE)(c - 0x20));
            del_mode(mps, MPS_REVERSE);
            return;
        }
    }

    print_cbm_char(mps, c);
}
Example #9
0
void down(){
	if(is_mode(1)) downEffect();
	else downBrush();
}
Example #10
0
void up(){
	if(is_mode(1)) upEffect();
	else upBrush();
}
Example #11
0
/* Select from 3 available modes and process accordingly */
void mode_selection(XnPoint3D* handPointList, hand_h* rhand){

	//-------------------sculpting--------------------------
	if(is_mode(1)){
	
		checkRCursor(1, rhand);						//right
		//if(hasTwoHands()) checkLCursor(lhand);	//left
		

		//SELECTION
		if(is_state(1)){	
			float* cursor = getCursor();
			cursorX = cursor[0];
			cursorY = cursor[1];

			drawPickVMModel();
			processPick(cursorX, cursorY);
			set_state(2);	
		}
		//RENDER
		else {
			draw_hand(handPointList);	//draw every hands
			
			//show back buffer?
			if(!BACK_BUFF){
				drawVMModel();
			}
			else{ 
				drawPickVMModel();
			}
			set_state(1);
			glutSwapBuffers();
		}
	}
	
	//-------------------paint----------------------------
	else if(is_mode(2)) {
		checkRCursor(2, rhand); 

		//SELECTION
		if(is_state(1)){
			//update cursor for paint effect
			float* cursor = getCursor();
			cursorX = cursor[0];
			cursorY = cursor[1];

			drawPickVMModel();
			processPick(cursorX, cursorY);
			set_state(2);
		}
		//RENDER
		else {
			//////////////////////////////////////////////////** in gesture////////////////
			draw_hand(handPointList);

			
			if(!BACK_BUFF)
				drawVMModel();
			else drawPickVMModel();

			//back to select other mesh
			set_state(1);
			glutSwapBuffers();
		}
	}

	//------------------ Selection ------------------------
	else if(is_mode(3)) {
		checkRCursor(3, rhand);
		
		 if(is_state(1)){
			drawPickVMModel();

			set_state(2);
		}
		else {
			//////////////////////////////////////////////////** in gesture////////////////
			draw_hand(handPointList);
			if(!BACK_BUFF)
				drawVMModel();
			else drawPickVMModel();
			drawVMModel();
			glutSwapBuffers();
		}
		
	}

}
Example #12
0
static void print_char(mps_t *mps, unsigned int prnr, const BYTE c)
{
    if (mps->pos >= MAX_COL) {  /* flush buffer*/
        write_line(mps, prnr);
        clear_buffer(mps);
    }
    if (mps->tab) {     /* decode tab-number*/
        mps->tabc[2 - mps->tab] = c;

        if (mps->tab == 1) {
            mps->pos =
                is_mode(mps, MPS_ESC) ?
                mps->tabc[0] << 8 | mps->tabc[1] :
                atoi((char *)mps->tabc) * 6;

            del_mode(mps, MPS_ESC);
        }

        mps->tab--;
        return;
    }

    if (is_mode(mps, MPS_ESC) && c != 16) {
        del_mode(mps, MPS_ESC);
    }

    if (is_mode(mps, MPS_REPEAT)) {
        mps->repeatn = c;
        del_mode(mps, MPS_REPEAT);
        return;
    }

    if (is_mode(mps, MPS_BITMODE) && c & 128) {
        print_bitmask(mps, c);
        return;
    }

    switch (c) {
        case 8:
            set_mode(mps, MPS_BITMODE);
            mps->bitcnt = 0;
            return;

        case 10: /* LF*/
            write_line(mps, prnr);
            clear_buffer(mps);
            return;

        case 13: /* CR*/
            mps->pos = 0;
            del_mode(mps, MPS_CRSRUP);
            write_line(mps, prnr);
            clear_buffer(mps);
            return;

        /*
         * By sending the cursor up code [CHR$(145)] to your printer, folowing
         * characters will be printed in cursor up (graphic) mode until either
         * a carriage return or cursor down code [CHR$(17)] is detected.
         *
         * By sending the cursor down code [CHR$(145)] to your printer,
         * following characters will be printed in business mode until either
         * a carriage return or cursor up code [CHR$(145)] is detected.
         *
         * 1. GRAPHIC MODE Code & Front Table, OMITTED
         * When an old number of CHR$(34) is detected in a line, the control
         * codes $00-$1F and $80-$9F will be made visible by printing a
         * reverse character for each of these controls. This will continue
         * until an even number of quotes [CHR$(34)] has been received or until
         * end of this line.
         *
         * 2. BUSINESS MODE Code & Font Table, OMITTED
         * When an old number of CHR$(34) is detected in a line, the control
         * codes $00-$1F and $80-$9F will be made visible by printing a
         * reverse character for each of these controls. This will continue
         * until an even number of quotes [CHR$(34)] has been received or until
         * end of this line.
         */

        case 14: /* EN on*/
            set_mode(mps, MPS_DBLWDTH);
            if (is_mode(mps, MPS_BITMODE)) {
                bitmode_off(mps);
            }
            return;

        case 15: /* EN off*/
            del_mode(mps, MPS_DBLWDTH);
            if (is_mode(mps, MPS_BITMODE)) {
                bitmode_off(mps);
            }
            return;

        case 16: /* POS*/
            mps->tab = 2; /* 2 chars (digits) following, number of first char*/
            return;

        case 17: /* crsr dn*/
            del_mode(mps, MPS_CRSRUP);
            return;

        case 18:
            set_mode(mps, MPS_REVERSE);
            return;

        case 26: /* repeat last chr$(8) c times.*/
            set_mode(mps, MPS_REPEAT);
            mps->repeatn = 0;
            mps->bitcnt = 0;
            return;

        case 27:
            set_mode(mps, MPS_ESC); /* followed by 16, and number MSB, LSB*/
            return;

        case 145: /* CRSR up*/
            set_mode(mps, MPS_CRSRUP);
            return;

        case 146: /* 18+128*/
            del_mode(mps, MPS_REVERSE);
            return;
    }

    if (is_mode(mps, MPS_BITMODE)) {
        return;
    }

    print_cbm_char(mps, c);
}
Example #13
0
/* 
 * Runs commands in parallel mode, with support for background processes.  
 */
char parallel_mode(char **pointers_to_commands, Node *head, Node **paused_list, Node **cpidlist) {

    int count = 0; // counts the no. of times we've been in the loop; 
                    // if more than 1, we need to free
                    // pointers_to_commands, which is different from what we got from main.
    while (1) {
        count++;
        char mode = 'p';
        pid_t cpid;
        char **command;
        char return_char = 'p';
        int i = 0;

        while (pointers_to_commands[i] != NULL) {
            command = tokenify(pointers_to_commands[i], " \n\t");
            if (command[0] == NULL) {
                i++;
                free_tokens(command);
                continue;
            }
            if (handle_exit(command) != 'n') {
                if (*cpidlist == NULL && pointers_to_commands[i+1] == NULL) {
                    return_char = 'e';
                }
                else {
                    printf("There are processes still running. You cannot exit yet. \n");
                }
                free_tokens(command);
                i++;
                continue;
            }
            if (is_mode(command)) {
                return_char = handle_mode(command, mode, return_char);
                if (return_char == 's') {
                    if (*cpidlist != NULL || pointers_to_commands[i+1] != NULL) {
                        printf("There are processes running. You cannot switch modes yet.\n");
                        return_char = 'p';
                    }
                }
                free_tokens(command);
                i++;
                continue;
            }
            if (handle_parallel_builtins(command, paused_list, cpidlist, mode) == 1) {
                i++;
                free_tokens(command);
                continue;
            }
            cpid = fork();
            if (cpid == 0) {
                char *tempcommand;
                tempcommand = prepend_path(command, head);
                command[0]= tempcommand;
                if (execv(command[0], command) < 0) {
                    fprintf(stderr, "execv failed: %s\n", strerror(errno));
                    printf("That's not a valid command! \n");
                    free_tokens(command);
                    exit(EXIT_FAILURE);
                }        
            }
            else {
                char whole_command[128];
                memset(whole_command, '\0', 128);
                strcat(whole_command, command[0]);
                if (command[1] != NULL) {
                    strcat(whole_command, " ");
                    strcat(whole_command, command[1]);
                }
                char cpidstr[128];
                sprintf(cpidstr, "%d", cpid);
                list_append(cpidstr, whole_command, cpidlist);
            }
            i++;
            free_tokens(command);
        }  
        if (count > 1) {
            free_tokens(pointers_to_commands);
        }
        if (return_char != 'p') {
            return return_char;
        }
        
        struct pollfd pfd[1];
        pfd[0].fd = 0;
        pfd[0].events = POLLIN;
        pfd[0].revents = 0;

        display_prompt();     
        int some_process_completed = 0;
        while (1) {
            int status;
            int rv = poll(&pfd[0], 1, 800);
            Node *to_delete_list = NULL;
            Node *tempcpidlist = *cpidlist;
            pid_t w;
            if (rv == 0) {
                some_process_completed = 0;
                while (tempcpidlist != NULL) {
                    w = atoi(tempcpidlist->data);
                    // I know that the ideal way to check for child process death is to use a macro such as WIFEXITED on status, 
                    // but it wasn't working for me.
                    // status always had the value 0. So I'm doing this instead to check for process completion.
                    if (waitpid(w, &status, WUNTRACED|WNOHANG) == -1) { 
                        list_append(tempcpidlist->data, "", &to_delete_list);
                        printf("\nProcess %s (%s) completed.\n", tempcpidlist->data, tempcpidlist->additional_data); 
                        some_process_completed = 1;
                    }
                    tempcpidlist = tempcpidlist->next;                 
                }
                Node *curr = to_delete_list;
                while (curr != NULL) {
                    list_delete(curr->data, cpidlist);
                    curr = curr->next;
                }
                list_clear(to_delete_list);
                if (some_process_completed == 1) {
                    display_prompt();

                }
            }
            else if (rv > 0) {
                char buffer[1024];
                if (fgets(buffer, 1024, stdin) == NULL) {
                    if (*cpidlist != NULL) {
                        printf("There are processes still running. You can't exit now.\n");
                        display_prompt();
                    }
                    else {
                        return_char = 'e';
                        return return_char;
                    }
                }
                else {
                    char *newbuffer = replace_pound(buffer);
                    newbuffer[strlen(newbuffer)-1] = '\0'; 
                    pointers_to_commands = tokenify(newbuffer, ";");
                    free(newbuffer);
                    break;
                }
            }
            else {
                printf("there was some kind of error: %s \n", strerror(errno));
            }
        }
    }
}
Example #14
0
int
main (void)
{
  const char *file = "test-cloexec.tmp";
  int fd = creat (file, 0600);
  int fd2;

  /* Assume std descriptors were provided by invoker.  */
  ASSERT (STDERR_FILENO < fd);
  ASSERT (is_inheritable (fd));

  /* Normal use of set_cloexec_flag.  */
  ASSERT (set_cloexec_flag (fd, true) == 0);
#if !((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
  ASSERT (!is_inheritable (fd));
#endif
  ASSERT (set_cloexec_flag (fd, false) == 0);
  ASSERT (is_inheritable (fd));

  /* Normal use of dup_cloexec.  */
  fd2 = dup_cloexec (fd);
  ASSERT (fd < fd2);
  ASSERT (!is_inheritable (fd2));
  ASSERT (close (fd) == 0);
  ASSERT (dup_cloexec (fd2) == fd);
  ASSERT (!is_inheritable (fd));
  ASSERT (close (fd2) == 0);

  /* On systems that distinguish between text and binary mode,
     dup_cloexec reuses the mode of the source.  */
  setmode (fd, O_BINARY);
  ASSERT (is_mode (fd, O_BINARY));
  fd2 = dup_cloexec (fd);
  ASSERT (fd < fd2);
  ASSERT (is_mode (fd2, O_BINARY));
  ASSERT (close (fd2) == 0);
  setmode (fd, O_TEXT);
  ASSERT (is_mode (fd, O_TEXT));
  fd2 = dup_cloexec (fd);
  ASSERT (fd < fd2);
  ASSERT (is_mode (fd2, O_TEXT));
  ASSERT (close (fd2) == 0);

  /* Test error handling.  */
  errno = 0;
  ASSERT (set_cloexec_flag (-1, false) == -1);
  ASSERT (errno == EBADF);
  errno = 0;
  ASSERT (set_cloexec_flag (10000000, false) == -1);
  ASSERT (errno == EBADF);
  errno = 0;
  ASSERT (set_cloexec_flag (fd2, false) == -1);
  ASSERT (errno == EBADF);
  errno = 0;
  ASSERT (dup_cloexec (-1) == -1);
  ASSERT (errno == EBADF);
  errno = 0;
  ASSERT (dup_cloexec (10000000) == -1);
  ASSERT (errno == EBADF);
  errno = 0;
  ASSERT (dup_cloexec (fd2) == -1);
  ASSERT (errno == EBADF);

  /* Clean up.  */
  ASSERT (close (fd) == 0);
  ASSERT (unlink (file) == 0);

  return 0;
}
Example #15
0
int
main (void)
{
  int i;
  int fd;

  /* We close fd 2 later, so save it in fd 10.  */
  if (dup2 (STDERR_FILENO, BACKUP_STDERR_FILENO) != BACKUP_STDERR_FILENO
      || (myerr = fdopen (BACKUP_STDERR_FILENO, "w")) == NULL)
    return 2;

  /* Create file for later checks.  */
  fd = creat (witness, 0600);
  ASSERT (STDERR_FILENO < fd);

  /* Four iterations, with progressively more standard descriptors
     closed.  */
  for (i = -1; i <= STDERR_FILENO; i++)
    {
      if (0 <= i)
        ASSERT (close (i) == 0);

      /* Detect errors.  */
      errno = 0;
      ASSERT (dup (-1) == -1);
      ASSERT (errno == EBADF);
      errno = 0;
      ASSERT (dup (10000000) == -1);
      ASSERT (errno == EBADF);
      close (fd + 1);
      errno = 0;
      ASSERT (dup (fd + 1) == -1);
      ASSERT (errno == EBADF);

      /* Preserve text vs. binary.  */
      setmode (fd, O_BINARY);
      ASSERT (dup (fd) == fd + 1);
      ASSERT (is_open (fd + 1));
      ASSERT (is_inheritable (fd + 1));
      ASSERT (is_mode (fd + 1, O_BINARY));

      ASSERT (close (fd + 1) == 0);
      setmode (fd, O_TEXT);
      ASSERT (dup (fd) == fd + 1);
      ASSERT (is_open (fd + 1));
      ASSERT (is_inheritable (fd + 1));
      ASSERT (is_mode (fd + 1, O_TEXT));

      /* Create cloexec copy.  */
      ASSERT (close (fd + 1) == 0);
      ASSERT (fd_safer_flag (dup_cloexec (fd), O_CLOEXEC) == fd + 1);
      ASSERT (set_cloexec_flag (fd + 1, true) == 0);
      ASSERT (is_open (fd + 1));
      ASSERT (!is_inheritable (fd + 1));
      ASSERT (close (fd) == 0);

      /* dup always creates inheritable copies.  Also, check that
         earliest slot past std fds is used.  */
      ASSERT (dup (fd + 1) == fd);
      ASSERT (is_open (fd));
      ASSERT (is_inheritable (fd));
      ASSERT (close (fd + 1) == 0);
    }

  /* Cleanup.  */
  ASSERT (close (fd) == 0);
  ASSERT (unlink (witness) == 0);

  return 0;
}