oyster *builtin_open(machine *m){ ARG(name); FILE *in = fopen(string_of(name), "r"); if (in == NULL) toss_signal(make_signal(make_string("File open failure!"), m), m); return make_file(in); }
static OBJ hc_wait( pid_t pid, int options ) {OBJ r; OBJ cs; OBJ sig; OBJ cp; OBJ pr; int statloc; pid_t tmppid; tmppid=waitpid(pid,&statloc,options|WUNTRACED); if(tmppid==(pid_t)-1) { return_unix_failure(errno); } if(tmppid!=(pid_t)0) { if(WIFEXITED(statloc)) { if(WEXITSTATUS(statloc)==EXIT_SUCCESS) { copy_some(__AProcessCtrl_Asuccess,1); AWait_Aexited(__AProcessCtrl_Asuccess,cs); } else { copy_some(__AProcessCtrl_Afailure,1); AWait_Aexited(__AProcessCtrl_Afailure,cs); } } else { if(WIFSIGNALED(statloc)) { if(make_signal(WTERMSIG(statloc),&sig)) { copy_some(__AWait_AsignalledUnknown,1); cs=__AWait_AsignalledUnknown; } else { AWait_Asignalled(sig,cs); } } else { if(WIFSTOPPED(statloc)) { if(make_signal(WSTOPSIG(statloc),&sig)) { copy_some(__AWait_AstoppedUnknown,1); cs=__AWait_AstoppedUnknown; } else { AWait_Astopped(sig,cs); } } else { HLT("hc_wait\'Wait: Unknown process exit status"); } } } make_process(tmppid,cp); APair_S7(cp,cs,pr); if(options&WNOHANG) { AOption_Aavail(pr,r); } else { r=pr; } } else { if(options&WNOHANG) { copy_some(__AOption_Anil,1); r=__AOption_Anil; } else { HLT("hc_wait\'Wait: waitpid returns (pid_t)0 in blocking mode"); } } return_okay(r); }
DUH *make_duh( long length, int n_tags, const char *const tags[][2], int n_signals, DUH_SIGTYPE_DESC *desc[], sigdata_t *sigdata[] ) { DUH *duh = malloc(sizeof(*duh)); int i; int fail; if (duh) { duh->n_signals = n_signals; duh->signal = malloc(n_signals * sizeof(*duh->signal)); if (!duh->signal) { free(duh); duh = NULL; } } if (!duh) { for (i = 0; i < n_signals; i++) if (desc[i]->unload_sigdata) if (sigdata[i]) (*desc[i]->unload_sigdata)(sigdata[i]); return NULL; } duh->n_tags = 0; duh->tag = NULL; fail = 0; for (i = 0; i < n_signals; i++) { duh->signal[i] = make_signal(desc[i], sigdata[i]); if (!duh->signal[i]) fail = 1; } if (fail) { unload_duh(duh); return NULL; } duh->length = length; { int mem = n_tags * 2; /* account for NUL terminators here */ char *ptr; for (i = 0; i < n_tags; i++) mem += strlen(tags[i][0]) + strlen(tags[i][1]); if (mem <= 0) return duh; duh->tag = malloc(n_tags * sizeof(*duh->tag)); if (!duh->tag) return duh; duh->tag[0][0] = malloc(mem); if (!duh->tag[0][0]) { free(duh->tag); duh->tag = NULL; return duh; } duh->n_tags = n_tags; ptr = duh->tag[0][0]; for (i = 0; i < n_tags; i++) { duh->tag[i][0] = ptr; strcpy(ptr, tags[i][0]); ptr += strlen(tags[i][0]) + 1; duh->tag[i][1] = ptr; strcpy(ptr, tags[i][1]); ptr += strlen(tags[i][1]) + 1; } } return duh; }
int main(void){ int i, j, k; int interval, point; int n_trial; int *x1, *x3; complex *x2; int EbN0; int trial; double snr, sigma; int be; double ber, ber_trial; int flag = 0; FILE *fp1; char name1[100]; // メモリの動的確保 x1 = malloc(sizeof(int) *INFO_LENGTH); x2 = malloc(sizeof(complex) *INFO_LENGTH); x3 = malloc(sizeof(int) *INFO_LENGTH); // random関数の初期化 srandom((unsigned)time(NULL)); // ファイル出力の設定 sprintf(name1,"awgn_bpsk_ber.txt"); fp1 = fopen(name1, "w"); // シミュレーションに関する値の設定 setup_prot(&interval, &point, &n_trial); for(EbN0=EbN0_MIN;EbN0<=EbN0_MAX*point;EbN0+=interval){ snr=pow(10,(EbN0/(double)point/(double)10.0)); sigma=sqrt((double)1.0/(double)(2*snr)); be = 0; flag = 0; for(trial=0;trial<n_trial;trial++){ make_signal(x1, INFO_LENGTH); BPSKmodulation(x1, x2, INFO_LENGTH); gaussiannoise(x2, sigma, INFO_LENGTH); BPSKdemodulation(x2, x3, INFO_LENGTH); calculate_ber(&be, x1, x3, &trial, &flag); if(flag == 1){ break; } ber_trial = be / (INFO_LENGTH * (double) (trial+1)); fprintf(stderr,"EbN0 = %f trial = %d BER = %e\r",EbN0/(double)point, trial, ber_trial); } ber = be / (INFO_LENGTH * (double) trial); printf("EbN0 = %f trial = %d BER = %e\n",EbN0/(double)point, trial, ber); fprintf(fp1,"%lf %lf\n", EbN0/(double)point, ber); fflush(fp1); } fflush(stdout); fflush(stderr); return 0; }