コード例 #1
0
ファイル: twriteorder.c プロジェクト: FilipeMaia/hdf5
/* Overall Algorithm: 
 * Parse options from user;
 * Generate/pre-created the test file needed and close it;
 * fork: child processes become the reader processes;
 *       while parent process continues as the writer process;
 * both run till ending conditions are met.
 */
int
main(int argc, char *argv[])
{
    /*pid_t childpid[READERS_MAX];
    int child_ret_value[READERS_MAX];*/
    pid_t childpid=0;
    int child_ret_value;
    pid_t mypid, tmppid;
    int	child_status;
    int child_wait_option=0;
    int ret_value = 0;

    /* initialization */
    if (setup_parameters(argc, argv) < 0){
	Hgoto_error(1);
    }

    /* ==============================================================*/
    /* UC_READWRITE: create datafile, launch both reader and writer. */
    /* UC_WRITER:    create datafile, skip reader, launch writer.    */
    /* UC_READER:    skip create, launch reader, exit.               */
    /* ==============================================================*/
    /* ============*/
    /* Create file */
    /* ============*/
    if (launch_g != UC_READER){
	printf("Creating skeleton data file for test...\n");
	if (create_wo_file() < 0){
	    fprintf(stderr, "***encounter error\n");
	    Hgoto_error(1);
	}else
	    printf("File created.\n");
    }
    /* flush output before possible fork */
    HDfflush(stdout);

    if (launch_g==UC_READWRITE){
	/* fork process */
	if((childpid = fork()) < 0) {
	    perror("fork");
	    Hgoto_error(1);
	};
    };
    mypid = getpid();

    /* ============= */
    /* launch reader */
    /* ============= */
    if (launch_g != UC_WRITER){
	/* child process launch the reader */
	if(0 == childpid) {
	    printf("%d: launch reader process\n", mypid);
	    if (read_wo_file() < 0){
		fprintf(stderr, "read_wo_file encountered error\n");
		exit(1);
	    }
	    /* Reader is done. Clean up by removing the data file */
	    HDremove(DATAFILE);
	    exit(0);
	}
    }

    /* ============= */
    /* launch writer */
    /* ============= */
    /* this process continues to launch the writer */
    printf("%d: continue as the writer process\n", mypid);
    if (write_wo_file() < 0){
	fprintf(stderr, "write_wo_file encountered error\n");
	Hgoto_error(1);
    }

    /* ================================================ */
    /* If readwrite, collect exit code of child process */
    /* ================================================ */
    if (launch_g == UC_READWRITE){
	if ((tmppid = waitpid(childpid, &child_status, child_wait_option)) < 0){
	    perror("waitpid");
	    Hgoto_error(1);
	}
	if (WIFEXITED(child_status)){
	    if ((child_ret_value=WEXITSTATUS(child_status)) != 0){
		printf("%d: child process exited with non-zero code (%d)\n",
		    mypid, child_ret_value);
		Hgoto_error(2);
	    }
	} else {
	    printf("%d: child process terminated abnormally\n", mypid);
	    Hgoto_error(2);
	}
    }
    
done:
    /* Print result and exit */
    if (ret_value != 0){
	printf("Error(s) encountered\n");
    }else{
	printf("All passed\n");
    }

    return(ret_value);
}
コード例 #2
0
ファイル: field.c プロジェクト: cooljeanius/open-cobol
static void
setup_parameters (struct cb_field *f)
{
	int	flag_local;
	char	pic[8];

	/* determine the class */
	if (f->children) {
		/* group field */
		flag_local = f->flag_local;
		for (f = f->children; f; f = f->sister) {
			f->flag_local = flag_local;
			setup_parameters (f);
		}
	} else {
		/* regular field */
		switch (f->usage) {
		case CB_USAGE_BINARY:
#ifndef WORDS_BIGENDIAN
			if (cb_binary_byteorder == CB_BYTEORDER_BIG_ENDIAN) {
				f->flag_binary_swap = 1;
			}
#endif
			break;

		case CB_USAGE_INDEX:
			f->pic = CB_PICTURE (cb_build_picture ("S9(9)"));
			break;

		case CB_USAGE_LENGTH:
			f->pic = CB_PICTURE (cb_build_picture ("9(9)"));
			break;

		case CB_USAGE_POINTER:
		case CB_USAGE_PROGRAM_POINTER:
			f->pic = CB_PICTURE (cb_build_picture ("9(10)"));
			break;
		case CB_USAGE_FLOAT:
			f->pic = CB_PICTURE (cb_build_picture ("S9(7)V9(7)"));
			break;
		case CB_USAGE_DOUBLE:
			f->pic = CB_PICTURE (cb_build_picture ("S9(9)V9(9)"));
			break;

		case CB_USAGE_COMP_5:
		case CB_USAGE_COMP_X:
			if (f->pic->category == CB_CATEGORY_ALPHANUMERIC) {
				if (f->pic->size > 8) {
					sprintf (pic, "9(36)");
				} else {
					sprintf (pic, "9(%d)", pic_digits[f->pic->size - 1]);
				}
				f->pic = CB_PICTURE (cb_build_picture (pic));
			}
#ifndef WORDS_BIGENDIAN
			if (f->usage == CB_USAGE_COMP_X) {
				if (cb_binary_byteorder == CB_BYTEORDER_BIG_ENDIAN) {
					f->flag_binary_swap = 1;
				}
			}
#endif
			break;

		default:
			break;
		}
	}
}