uint32_t sftp_v6_link(struct sftpjob *job) { char *oldpath, *newlinkpath; uint8_t symbolic; struct stat sb; /* See also comment in v3.c for SSH_FXP_SYMLINK */ if(readonly) return SSH_FX_PERMISSION_DENIED; pcheck(sftp_parse_path(job, &newlinkpath)); pcheck(sftp_parse_path(job, &oldpath)); /* aka existing-path/target-paths */ pcheck(sftp_parse_uint8(job, &symbolic)); D(("sftp_link %s %s [%s]", oldpath, newlinkpath, symbolic ? "symbolic" : "hard")); if((symbolic ? symlink : link)(oldpath, newlinkpath) < 0) { switch(errno) { case EPERM: if(!symbolic && stat(oldpath, &sb) >= 0 && S_ISDIR(sb.st_mode)) /* Can't hard-link directories */ return SSH_FX_FILE_IS_A_DIRECTORY; else /* e.g. Linux returns EPERM for symlink or link on a FAT32 fs */ return SSH_FX_OP_UNSUPPORTED; break; default: return HANDLER_ERRNO; } } else return SSH_FX_OK; }
void arenaCheck() { /* consistency check */ BlockPrefix_t *p = arenaBegin; size_t amtFree = 0, amtAllocated = 0; int numBlocks = 0; while (p != 0) { /* walk through arena */ fprintf(stderr, " checking from %p, size=%8zd, allocated=%d...\n", p, computeUsableSpace(p), p->allocated); assert(pcheck(p)); /* p must remain within arena */ assert(pcheck(p->suffix)); /* suffix must be within arena */ assert(p->suffix->prefix == p); /* suffix should reference prefix */ if (p->allocated) /* update allocated & free space */ amtAllocated += computeUsableSpace(p); else amtFree += computeUsableSpace(p); numBlocks += 1; p = computeNextPrefixAddr(p); if (p == arenaEnd) { break; } else { assert(pcheck(p)); } } fprintf(stderr, " mcheck: numBlocks=%d, amtAllocated=%zdk, amtFree=%zdk, arenaSize=%zdk\n", numBlocks, (size_t)amtAllocated / 1024LL, (size_t)amtFree/1024LL, ((size_t)arenaEnd - (size_t)arenaBegin) / 1024); }
void test_heapsort (size_t N) { int status; double *orig = (double *) malloc (N * sizeof (double)); double *data = (double *) malloc (N * sizeof (double)); size_t *p = (size_t *) malloc (N * sizeof(size_t)); initialize (orig, N); /* Already sorted */ cpy (data, orig, N); status = gsl_heapsort_index (p, data, N, sizeof (double), (gsl_comparison_fn_t) & cmp_dbl); status |= pcheck (p, data, orig, N); gsl_test (status, "indexing array, n = %u, ordered", N); gsl_heapsort (data, N, sizeof (double), (gsl_comparison_fn_t) & cmp_dbl); status = check (data, orig, N); gsl_test (status, "sorting, array, n = %u, ordered", N); /* Reverse the data */ cpy (data, orig, N); reverse (data, N); status = gsl_heapsort_index (p, data, N, sizeof (double), (gsl_comparison_fn_t) & cmp_dbl); status |= pcheck (p, data, orig, N); gsl_test (status, "indexing array, n = %u, reversed", N); gsl_heapsort (data, N, sizeof (double), (gsl_comparison_fn_t) & cmp_dbl); status = check (data, orig, N); gsl_test (status, "sorting, array, n = %u, reversed", N); /* Perform some shuffling */ cpy (data, orig, N); randomize (data, N); status = gsl_heapsort_index (p, data, N, sizeof (double), (gsl_comparison_fn_t) & cmp_dbl); status |= pcheck (p, data, orig, N); gsl_test (status, "indexing array, n = %u, randomized", N); gsl_heapsort (data, N, sizeof (double), (gsl_comparison_fn_t) & cmp_dbl); status = check (data, orig, N); gsl_test (status, "sorting, array, n = %u, randomized", N); free (orig); free (data); free (p); }
/*----------------------------------------------------------------------------- * dt_in_back *---------------------------------------------------------------------------*/ void dt_in_back(BUFFER_CB *buf, uint32_t src_spu, SPU_ADDRESS src_buf_data, uint32_t num_bytes, uint32_t spu_cmd_id, uint32_t tag) { OUT_DTCB out_dtcb; PPU_DT_PARAMS *cmd; #if CHECK // Validate buffer alignment. pcheck(((src_buf_data & CACHE_MASK) == 0) && (num_bytes != 0)); // Debug tail pointer should be synchronized. assert(buf->otail == buf->tail); // Make sure back of buffer is free. *-in is allowed. check(buf->back_action == BUFFER_ACTION_NONE); buf->back_action = BUFFER_ACTION_IN; #if !DT_ALLOW_UNALIGNED // Make sure data is aligned on qword boundary. pcheck((num_bytes & QWORD_MASK) == 0); check((buf->tail & QWORD_MASK) == 0); #endif // Make sure enough space is available. head and tail must be off by at least // 1 and cannot be non-zero offsets in the same qword. check(((buf->head - (buf->head & QWORD_MASK ? : 1) - buf->tail) & buf->mask) >= num_bytes); #endif // Set up description of region in destination buffer that source SPU will // write to. Data/space in source/destination buffers must have same offset // within cache line (128 bytes) - destination buffer does not automatically // adjust pointers if empty. out_dtcb.head = buf->tail; out_dtcb.tail = (buf->tail + num_bytes) & buf->mask; // Reserve space for data to be transferred. IF_CHECK(buf->otail = out_dtcb.tail); // Set data transfer to wait on the SPU command ID. This must be done before // writing transfer info to SPU. cmd = ppu_dt_wait_spu(src_spu, spu_cmd_id, tag); cmd->type = PPU_CMD_DT_IN_BACK; cmd->buf = buf; cmd->num_bytes = num_bytes; // Write transfer info to source SPU. write64((uint64_t *)buf_get_dt_field_addr(spu_addr(src_spu, src_buf_data), front_in_dtcb), out_dtcb.data); }
/*----------------------------------------------------------------------------- * dt_out_front_ex *---------------------------------------------------------------------------*/ void dt_out_front_ex(BUFFER_CB *buf, uint32_t dest_spu, SPU_ADDRESS dest_buf_data, uint32_t num_bytes) { OUT_DTCB out_dtcb; #if CHECK // Validate alignment. pcheck(((dest_buf_data & CACHE_MASK) == 0) && (num_bytes != 0)); // Debug head pointer should be synchronized. assert(buf->ihead == buf->head); // Make sure front of buffer is free. out-out is disallowed. check((buf->front_action == BUFFER_ACTION_NONE) && (buf->back_action != BUFFER_ACTION_OUT)); // Make sure enough data is available. check(((buf->tail - buf->head) & buf->mask) >= num_bytes); #endif // Set up source buffer's head/tail pointers for region to be transferred. out_dtcb.head = buf->head; out_dtcb.tail = (buf->head + num_bytes) & buf->mask; buf->head = out_dtcb.tail; IF_CHECK(buf->ihead = buf->head); // Write transfer info to destination SPU. write64((uint64_t *)buf_get_dt_field_addr(spu_addr(dest_spu, dest_buf_data), back_in_dtcb), out_dtcb.data); }
uint32_t sftp_v456_stat(struct sftpjob *job) { char *path; struct stat sb; pcheck(sftp_parse_path(job, &path)); D(("sftp_stat %s", path)); return sftp_v456_stat_core(job, stat(path, &sb), &sb, path); }
/*----------------------------------------------------------------------------- * spu_done_command *---------------------------------------------------------------------------*/ static INLINE void spu_done_command(SPU_CMD_GROUP *g, SPU_CMD_HEADER *cmd) { uint32_t cmd_size = spu_cmd_get_size(cmd); g->size += cmd_size; pcheck(g->size <= SPU_CMD_GROUP_MAX_SIZE); g->end += cmd_size; }
uint32_t sftp_v456_fstat(struct sftpjob *job) { int fd; struct handleid id; struct stat sb; uint32_t rc; pcheck(sftp_parse_handle(job, &id)); D(("sftp_fstat %" PRIu32 " %" PRIu32, id.id, id.tag)); if((rc = sftp_handle_get_fd(&id, &fd, 0))) return rc; return sftp_v456_stat_core(job, fstat(fd, &sb), &sb, 0); }
void readcommands(int argc, char **argv) { int i; char *parname = NULL ; phandle *ph ; char str[5000] ; char *tempname ; int n ; while ((i = getopt (argc, argv, "p:vV")) != -1) { switch (i) { case 'p': parname = strdup(optarg) ; break; case 'v': printf("version: %s\n", WVERSION) ; break; case 'V': verbose = YES ; break; case '?': printf ("Usage: bad params.... \n") ; fatalx("bad params\n") ; } } pcheck(parname,'p') ; printf("parameter file: %s\n", parname) ; ph = openpars(parname) ; dostrsub(ph) ; getint(ph, "packmode:", &packmode) ; // controls internals getstring(ph, "genotypename:", &genotypename) ; getstring(ph, "snpname:", &snpname) ; getstring(ph, "indivname:", &indivname) ; getstring(ph, "pcaname:", &pcaname) ; getint(ph, "numpc:", &numpc) ; getint(ph, "qtmode:", &qtmode) ; getint(ph, "hashcheck:", &hashcheck) ; getstring(ph, "outputname:", &outputname); writepars(ph) ; closepars(ph) ; }
/*----------------------------------------------------------------------------- * spu_init_header *---------------------------------------------------------------------------*/ static INLINE void spu_init_header(SPU_CMD_HEADER *cmd, uint32_t type, uint32_t id, uint32_t num_deps, va_list deps) { pcheck((id < SPU_MAX_COMMANDS) && ((num_deps <= SPU_CMD_MAX_DEPS) || ((num_deps <= SPU_CMD_MAX_DEPS_LARGE) && ((SPU_CMD_LARGE_HEADER_TYPES & (1 << type)) != 0)))); cmd->type = type; cmd->id = id; cmd->num_back_deps = num_deps; cmd->num_forward_deps = 0; for (uint32_t i = 0; i < num_deps; i++) { uint32_t dep_id = va_arg(deps, uint32_t); // Duplicate dependencies are not checked for - the SPU side works fine // with them. pcheck(dep_id < SPU_MAX_COMMANDS); cmd->deps[i] = dep_id; } }
/* Command code for the various _*STAT calls. rc is the return value * from *stat() and SB is the buffer. */ static uint32_t sftp_v456_stat_core(struct sftpjob *job, int rc, const struct stat *sb, const char *path) { struct sftpattr attrs; uint32_t flags; if(!rc) { pcheck(sftp_parse_uint32(job, &flags)); sftp_stat_to_attrs(job->a, sb, &attrs, flags, path); sftp_send_begin(job->worker); sftp_send_uint8(job->worker, SSH_FXP_ATTRS); sftp_send_uint32(job->worker, job->id); protocol->sendattrs(job, &attrs); sftp_send_end(job->worker); return HANDLER_RESPONDED; } else return HANDLER_ERRNO; }
uint32_t sftp_v6_version_select(struct sftpjob *job) { char *newversion; /* If we've already created the work queue then this can't be the first * message. */ if(!workqueue) { pcheck(sftp_parse_path(job, &newversion)); /* Handle known versions */ if(!strcmp(newversion, "3")) { protocol = &sftp_v3; return SSH_FX_OK; } if(!strcmp(newversion, "4")) { protocol = &sftp_v4; return SSH_FX_OK; } if(!strcmp(newversion, "5")) { protocol = &sftp_v5; return SSH_FX_OK; } if(!strcmp(newversion, "6")) { protocol = &sftp_v6; return SSH_FX_OK; } sftp_send_status(job, SSH_FX_INVALID_PARAMETER, "unknown version"); } else sftp_send_status(job, SSH_FX_INVALID_PARAMETER, "badly timed version-select"); /* We MUST close the channel. (-13, s5.5). */ exit(-1); }
static LPITEMIDLIST _ILCreateCPanelApplet(LPCSTR name, LPCSTR displayName, LPCSTR comment, int iconIdx) { PIDLCPanelStruct *p; LPITEMIDLIST pidl; PIDLDATA tmp; int size0 = (char*)&tmp.u.cpanel.szName-(char*)&tmp.u.cpanel; int size = size0; int l; tmp.type = PT_CPLAPPLET; tmp.u.cpanel.dummy = 0; tmp.u.cpanel.iconIdx = iconIdx; l = strlen(name); size += l+1; tmp.u.cpanel.offsDispName = l+1; l = strlen(displayName); size += l+1; tmp.u.cpanel.offsComment = tmp.u.cpanel.offsDispName+1+l; l = strlen(comment); size += l+1; pidl = SHAlloc(size+4); if (!pidl) return NULL; pidl->mkid.cb = size+2; memcpy(pidl->mkid.abID, &tmp, 2+size0); p = &((PIDLDATA*)pidl->mkid.abID)->u.cpanel; strcpy(p->szName, name); strcpy(p->szName+tmp.u.cpanel.offsDispName, displayName); strcpy(p->szName+tmp.u.cpanel.offsComment, comment); *(WORD*)((char*)pidl+(size+2)) = 0; pcheck(pidl); return pidl; }
static LPITEMIDLIST _ILCreateCPanelApplet(LPCSTR pszName, LPCSTR pszDisplayName, LPCSTR pszComment, int iIconIdx) { PIDLCPanelStruct *pCP; LPITEMIDLIST pidl; LPPIDLDATA pData; int cchName, cchDisplayName, cchComment, cbData; /* Calculate lengths of given strings */ cchName = strlen(pszName); cchDisplayName = strlen(pszDisplayName); cchComment = strlen(pszComment); /* Allocate PIDL */ cbData = sizeof(pidl->mkid.cb) + sizeof(pData->type) + sizeof(pData->u.cpanel) - sizeof(pData->u.cpanel.szName) + cchName + cchDisplayName + cchComment + 3; pidl = (LPITEMIDLIST)SHAlloc(cbData + sizeof(WORD)); if (!pidl) return NULL; /* Copy data to allocated memory */ pidl->mkid.cb = cbData; pData = (PIDLDATA *)pidl->mkid.abID; pData->type = PT_CPLAPPLET; pCP = &pData->u.cpanel; pCP->dummy = 0; pCP->iconIdx = iIconIdx; strcpy(pCP->szName, pszName); pCP->offsDispName = cchName + 1; strcpy(pCP->szName + pCP->offsDispName, pszDisplayName); pCP->offsComment = pCP->offsDispName + cchDisplayName + 1; strcpy(pCP->szName + pCP->offsComment, pszComment); /* Add PIDL NULL terminator */ *(WORD*)(pCP->szName + pCP->offsComment + cchComment + 1) = 0; pcheck(pidl); return pidl; }
/*----------------------------------------------------------------------------- * dt_out_front *---------------------------------------------------------------------------*/ void dt_out_front(BUFFER_CB *buf, uint32_t dest_spu, SPU_ADDRESS dest_buf_data, uint32_t num_bytes, uint32_t spu_cmd_id, uint32_t tag) { OUT_DTCB out_dtcb; PPU_DT_PARAMS *cmd; #if CHECK // Validate alignment. pcheck(((dest_buf_data & CACHE_MASK) == 0) && (num_bytes != 0)); // Debug head pointer should be synchronized. assert(buf->ihead == buf->head); // Make sure front of buffer is free. out-out is disallowed. check((buf->front_action == BUFFER_ACTION_NONE) && (buf->back_action != BUFFER_ACTION_OUT)); buf->front_action = BUFFER_ACTION_OUT; // Make sure enough data is available. check(((buf->tail - buf->head) & buf->mask) >= num_bytes); #endif // Set up source buffer's head/tail pointers for region to be transferred. out_dtcb.head = buf->head; out_dtcb.tail = (buf->head + num_bytes) & buf->mask; IF_CHECK(buf->ihead = out_dtcb.tail); // Set data transfer to wait on the SPU command ID. This must be done before // writing transfer info to SPU. cmd = ppu_dt_wait_spu(dest_spu, spu_cmd_id, tag); cmd->type = PPU_CMD_DT_OUT_FRONT; cmd->buf = buf; cmd->num_bytes = num_bytes; // Write transfer info to destination SPU. write64((uint64_t *)buf_get_dt_field_addr(spu_addr(dest_spu, dest_buf_data), back_in_dtcb), out_dtcb.data); }
void readcommands(int argc, char **argv) { int i,haploid=0; phandle *ph ; char str[5000] ; char *tempname ; int n, t ; while ((i = getopt (argc, argv, "f:b:p:g:s:o:vVx")) != -1) { switch (i) { case 'p': parname = strdup(optarg) ; break; case 'f': snpdetailsname = strdup(optarg) ; break; case 'g': graphname = strdup(optarg) ; break; case 'o': graphoutname = strdup(optarg) ; break; case 's': seed = atoi(optarg) ; break; case 'b': baseval = atof(optarg) ; break; case 'v': printf("version: %s\n", WVERSION) ; break; case 'x': doanalysis = NO ; break; case 'V': verbose = YES ; break; case '?': printf ("Usage: bad params.... \n") ; fatalx("bad params\n") ; } } if (parname==NULL) { fprintf(stderr, "no parameters\n") ; return ; } pcheck(parname,'p') ; printf("parameter file: %s\n", parname) ; ph = openpars(parname) ; dostrsub(ph) ; getstring(ph, "genotypename:", &genotypename) ; getstring(ph, "snpname:", &snpname) ; getstring(ph, "indivname:", &indivname) ; getstring(ph, "graphname:", &graphname) ; getstring(ph, "graphoutname:", &graphoutname) ; int numeg = 4 ; getstring(ph, "snpdetailsname:", &snpdetailsname) ; getstring(ph, "outpop:", &outpop) ; getstring(ph, "output:", &outputname) ; getstring(ph, "badsnpname:", &badsnpname) ; getstring(ph, "popfilename:", &popfilename) ; getstring(ph, "f3log:", &f3name) ; getstring(ph, "root:", &rootname) ; getdbl(ph, "blgsize:", &blgsize) ; getdbl(ph, "diag:", &diag) ; getdbl(ph, "f2diag:", &f2diag) ; getdbl(ph, "minvar:", &minvar) ; getint(ph, "bigiter:", &bigiter) ; getint(ph, "inbreed:", &inbreed) ; getint(ph, "startiter:", &startiter) ; getint(ph, "fancynorm:", &fancynorm) ; getint(ph, "noxdata:", &noxdata) ; t = -1 ; getint(ph, "xdata:", &t) ; if (t>=0) noxdata = 1-t ; getint(ph, "chrom:", &xchrom) ; getint(ph, "nochrom:", &zchrom) ; getint(ph, "doanalysis:", &doanalysis) ; getint(ph, "quartet:", &quartet) ; getint(ph, "nostatslim:", &nostatslim) ; getint(ph, "popsizelimit:", &popsizelimit) ; getint(ph, "gfromp:", &gfromp) ; // gen dis from phys getint(ph, "seed:", &seed) ; getint(ph, "details:", &details) ; getint(ph, "forcezmode:", &forcezmode) ; getint(ph, "dzeromode:", &dzeromode) ; getdbl(ph, "baseval:", &baseval) ; getdbl(ph, "jackquart:", &jackquart) ; getint(ph, "jackweight:", &jackweight) ; getint(ph, "pubjack:", &pubjack) ; getstring(ph, "dumpname:", &dumpname) ; getstring(ph, "loadname:", &loadname) ; printf("### THE INPUT PARAMETERS\n"); printf("##PARAMETER NAME: VALUE\n"); writepars(ph); }
/*----------------------------------------------------------------------- * convert a DCF77 data buffer into wall clock time + flags * * buffer holds a pointer to a DCF77 data buffer in symbolic * representation * size describes the length of DCF77 information in bits (represented * as chars in symbolic notation * clock points to a wall clock time description of the DCF77 data (result) */ static unsigned long convert_rawdcf( unsigned char *buffer, int size, clocktime_t *clock_time ) { if (size < 57) { PRINTF("%-30s", "*** INCOMPLETE"); return CVT_NONE; } /* * check Start and Parity bits */ if ((ext_bf(buffer, DCF_S) == 1) && pcheck(buffer, DCF_P_P1) && pcheck(buffer, DCF_P_P2) && pcheck(buffer, DCF_P_P3)) { /* * buffer OK - extract all fields and build wall clock time from them */ clock_time->flags = 0; clock_time->usecond= 0; clock_time->second = 0; clock_time->minute = ext_bf(buffer, DCF_M10); clock_time->minute = TIMES10(clock_time->minute) + ext_bf(buffer, DCF_M1); clock_time->hour = ext_bf(buffer, DCF_H10); clock_time->hour = TIMES10(clock_time->hour) + ext_bf(buffer, DCF_H1); clock_time->day = ext_bf(buffer, DCF_D10); clock_time->day = TIMES10(clock_time->day) + ext_bf(buffer, DCF_D1); clock_time->month = ext_bf(buffer, DCF_MO0); clock_time->month = TIMES10(clock_time->month) + ext_bf(buffer, DCF_MO); clock_time->year = ext_bf(buffer, DCF_Y10); clock_time->year = TIMES10(clock_time->year) + ext_bf(buffer, DCF_Y1); clock_time->wday = ext_bf(buffer, DCF_DW); /* * determine offset to UTC by examining the time zone */ switch (ext_bf(buffer, DCF_Z)) { case DCF_Z_MET: clock_time->utcoffset = -60; break; case DCF_Z_MED: clock_time->flags |= DCFB_DST; clock_time->utcoffset = -120; break; default: PRINTF("%-30s", "*** BAD TIME ZONE"); return CVT_FAIL|CVT_BADFMT; } /* * extract various warnings from DCF77 */ if (ext_bf(buffer, DCF_A1)) clock_time->flags |= DCFB_ANNOUNCE; if (ext_bf(buffer, DCF_A2)) clock_time->flags |= DCFB_LEAP; if (ext_bf(buffer, DCF_R)) clock_time->flags |= DCFB_ALTERNATE; return CVT_OK; } else { /* * bad format - not for us */ PRINTF("%-30s", "*** BAD FORMAT (invalid/parity)"); return CVT_FAIL|CVT_BADFMT; } }
void readcommands(int argc, char **argv) { int i,haploid=0; char *parname = NULL ; phandle *ph ; char str[5000] ; char *tempname ; int n ; while ((i = getopt (argc, argv, "p:vVf")) != -1) { switch (i) { case 'p': parname = strdup(optarg) ; break; case 'v': printf("version: %s\n", WVERSION) ; break; case 'V': verbose = YES ; break; case 'f': phasedmode = YES ; break; case '?': printf ("Usage: bad params.... \n") ; fatalx("bad params\n") ; } } pcheck(parname,'p') ; printf("parameter file: %s\n", parname) ; ph = openpars(parname) ; dostrsub(ph) ; getstring(ph, "geno1:", &geno1) ; getstring(ph, "snp1:", &snp1) ; getstring(ph, "ind1:", &ind1) ; getstring(ph, "geno2:", &geno2) ; getstring(ph, "snp2:", &snp2) ; getstring(ph, "ind2:", &ind2) ; getstring(ph, "indoutfilename:", &indoutfilename) ; getstring(ph, "indivoutname:", &indoutfilename) ; getstring(ph, "snpoutfilename:", &snpoutfilename) ; getstring(ph, "snpoutname:", &snpoutfilename) ; getstring(ph, "genooutfilename:", &genooutfilename) ; getstring(ph, "genotypeoutname:", &genooutfilename) ; getstring(ph, "outputformat:", &omode) ; getint(ph, "docheck:", &docheck) ; getint(ph, "hashcheck:", &hashcheck) ; getint(ph, "strandcheck:", &strandcheck) ; getint(ph, "phasedmode:", &phasedmode) ; writepars(ph) ; closepars(ph) ; }
main(int argc,char *argv[]) { long old; int sport= -1; /* Serial port number */ long baud= -1; /* Baud rate */ int vecno= -1; /* Vector number */ int port= -1; /* Printer port number */ unsigned short c; if(argc!=3) { oops: fprintf(stderr,"jterm COMx:[BAUD][,IRQ] LPy:\n"); exit(1); } sscanf(argv[1],"com%d:%ld,%d",&sport,&baud,&vecno); if(sport== -1) sscanf(argv[1],"COM%d:%ld,%d",&sport,&baud,&vecno); sscanf(argv[2],"lp%d:",&port); if(port== -1) sscanf(argv[2],"LP%d:",&port); --sport; if(port<0 || port>2 || sport<0 || sport>3) goto oops; /* Install break interrupt handler */ disable(); old= *(long far *)0x0000006C; *(long far *)0x0000006C=(long)brkint; enable(); if(vecno== -1) vecno=ints[sport]; else vecno+=8; if(baud!= -1) spbaud(ports[sport],baud); /* Open serial port */ spopen(ports[sport],vecno,1<<(vecno-8)); /* Open parallel port */ port=lports[port]; /* Initialize tty */ ttyinit(); loop: /* Print chracters */ if(psize) if(pcheck(port)) { pout(port,pbuf[pold++]); if(pold==pbufsiz) pold=0; psize--; } if(intflg) { intflg=0; spbreak(); } /* Check keyboard */ /* The trick here is to use the DOS interrupt 6 instead of the bios interrupt. * This eliminates untold numbers of problems with ^C and Ctrl-Break for * some microsoft's-programmers-only-know reason. */ _DL=0xFF; _AH=0x6; geninterrupt(0x21); __emit__(0x75,0x2,0x31,0xC0); /* Clear AX if no chars ready */ c=_AX; if(c) { c&=0xFF; if(!c) { _DL=0xFF; _AH=0x6; geninterrupt(0x21); c=_AX; c<<=8; } /* Check for exit key */ if((c&0xff)==']'-64) { spclose(); disable(); *(long far *)0x0000006C=old; enable(); bioscpos(0,height-1); exit(1); } if(c&0xff) spputc(c&0xff); /* ASCII code */ else switch(c) /* Xenix special keys */ { case 0x0300: spputc(0); break; case 0x4800: spputc('\033'); if(mapplication) spputc('O'), spputc('A'); else spputc('['), spputc('A'); break; case 0x5000: spputc('\033'); if(mapplication) spputc('O'), spputc('B'); else spputc('['), spputc('B'); break; case 0x4d00: spputc('\033'); if(mapplication) spputc('O'), spputc('C'); else spputc('['), spputc('C'); break; case 0x4b00: spputc('\033'); if(mapplication) spputc('O'), spputc('D'); else spputc('['), spputc('D'); break; case 0x4700: spputc('\033'), spputc('['), spputc('H'); break; case 0x4f00: spputc('\033'), spputc('['), spputc('F'); break; case 0x4900: spputc('\033'), spputc('['), spputc('I'); break; case 0x5100: spputc('\033'), spputc('['), spputc('G'); break; case 0x5200: spputc('\033'), spputc('['), spputc('L'); break; case 0x5300: spputc(127); break; case 0x0f00: spputc('\033'), spputc('['), spputc('Z'); break; case 0x3b00: spputc('\033'), spputc('['), spputc('M'); break; case 0x3c00: spputc('\033'), spputc('['), spputc('N'); break; case 0x3d00: spputc('\033'), spputc('['), spputc('O'); break; case 0x3e00: spputc('\033'), spputc('['), spputc('P'); break; case 0x3f00: spputc('\033'), spputc('['), spputc('Q'); break; case 0x4000: spputc('\033'), spputc('['), spputc('R'); break; case 0x4100: spputc('\033'), spputc('['), spputc('S'); break; case 0x4200: spputc('\033'), spputc('['), spputc('T'); break; case 0x4300: spputc('\033'), spputc('['), spputc('U'); break; case 0x4400: spputc('\033'), spputc('['), spputc('V'); break; case 0x5400: spputc('\033'), spputc('['), spputc('Y'); break; case 0x5500: spputc('\033'), spputc('['), spputc('Z'); break; case 0x5600: spputc('\033'), spputc('['), spputc('a'); break; case 0x5700: spputc('\033'), spputc('['), spputc('b'); break; case 0x5800: spputc('\033'), spputc('['), spputc('c'); break; case 0x5900: spputc('\033'), spputc('['), spputc('d'); break; case 0x5a00: spputc('\033'), spputc('['), spputc('e'); break; case 0x5b00: spputc('\033'), spputc('['), spputc('f'); break; case 0x5c00: spputc('\033'), spputc('['), spputc('g'); break; case 0x5d00: spputc('\033'), spputc('['), spputc('h'); break; case 0x5e00: spputc('\033'), spputc('['), spputc('k'); break; case 0x5f00: spputc('\033'), spputc('['), spputc('l'); break; case 0x6000: spputc('\033'), spputc('['), spputc('m'); break; case 0x6100: spputc('\033'), spputc('['), spputc('n'); break; case 0x6200: spputc('\033'), spputc('['), spputc('o'); break; case 0x6300: spputc('\033'), spputc('['), spputc('p'); break; case 0x6400: spputc('\033'), spputc('['), spputc('q'); break; case 0x6500: spputc('\033'), spputc('['), spputc('r'); break; case 0x6600: spputc('\033'), spputc('['), spputc('s'); break; case 0x6700: spputc('\033'), spputc('['), spputc('t'); break; case 0x6800: spputc('\033'), spputc('['), spputc('w'); break; case 0x6900: spputc('\033'), spputc('['), spputc('x'); break; case 0x6a00: spputc('\033'), spputc('['), spputc('y'); break; case 0x6b00: spputc('\033'), spputc('['), spputc('z'); break; case 0x6c00: spputc('\033'), spputc('['), spputc('@'); break; case 0x6d00: spputc('\033'), spputc('['), spputc('['); break; case 0x6e00: spputc('\033'), spputc('['), spputc('\\'); break; case 0x6f00: spputc('\033'), spputc('['), spputc(']'); break; case 0x7000: spputc('\033'), spputc('['), spputc('^'); break; case 0x7100: spputc('\033'), spputc('['), spputc('_'); break; } } /* Check serial port */ if(spcangetc()) ttyout(spgetc()); goto loop; }
static unsigned long convert_rawdcf( register unsigned char *buffer, register int size, register clocktime_t *clock_time ) { if (size < 57) { printf("%-30s", "*** INCOMPLETE"); return CVT_NONE; } /* * check Start and Parity bits */ if ((ext_bf(buffer, DCF_S) == 1) && pcheck(buffer, DCF_P_P1) && pcheck(buffer, DCF_P_P2) && pcheck(buffer, DCF_P_P3)) { /* * buffer OK */ clock_time->flags = 0; clock_time->usecond= 0; clock_time->second = 0; clock_time->minute = ext_bf(buffer, DCF_M10); clock_time->minute = TIMES10(clock_time->minute) + ext_bf(buffer, DCF_M1); clock_time->hour = ext_bf(buffer, DCF_H10); clock_time->hour = TIMES10(clock_time->hour) + ext_bf(buffer, DCF_H1); clock_time->day = ext_bf(buffer, DCF_D10); clock_time->day = TIMES10(clock_time->day) + ext_bf(buffer, DCF_D1); clock_time->month = ext_bf(buffer, DCF_MO0); clock_time->month = TIMES10(clock_time->month) + ext_bf(buffer, DCF_MO); clock_time->year = ext_bf(buffer, DCF_Y10); clock_time->year = TIMES10(clock_time->year) + ext_bf(buffer, DCF_Y1); clock_time->wday = ext_bf(buffer, DCF_DW); switch (ext_bf(buffer, DCF_Z)) { case DCF_Z_MET: clock_time->utcoffset = -60; break; case DCF_Z_MED: clock_time->flags |= DCFB_DST; clock_time->utcoffset = -120; break; default: printf("%-30s", "*** BAD TIME ZONE"); return CVT_FAIL|CVT_BADFMT; } if (ext_bf(buffer, DCF_A1)) clock_time->flags |= DCFB_ANNOUNCE; if (ext_bf(buffer, DCF_A2)) clock_time->flags |= DCFB_LEAP; if (ext_bf(buffer, DCF_R)) clock_time->flags |= DCFB_ALTERNATE; return CVT_OK; } else { /* * bad format - not for us */ printf("%-30s", "*** BAD FORMAT (invalid/parity)"); return CVT_FAIL|CVT_BADFMT; } }
/* Main program */ int main(int argc, char *argv[]){ unsigned int g, i; /* Counters. Reps counter, geno counter */ unsigned int reps; /* Length of simulation (no. of introductions of neutral site) */ double Bcheck = 0; /* Frequency of B after each reproduction */ double Acheck = 0; /* Frequency of polymorphism */ double Hsum = 0; /* Summed heterozygosity over transit time of neutral allele */ /* GSL random number definitions */ const gsl_rng_type * T; gsl_rng * r; /* This reads in data from command line. */ if(argc != 8){ fprintf(stderr,"Invalid number of input values.\n"); exit(1); } N = strtod(argv[1],NULL); s = strtod(argv[2],NULL); rec = strtod(argv[3],NULL); sex = strtod(argv[4],NULL); self = strtod(argv[5],NULL); gc = strtod(argv[6],NULL); reps = strtod(argv[7],NULL); /* Arrays definition and memory assignment */ double *genotype = calloc(10,sizeof(double)); /* Genotype frequencies */ unsigned int *gensamp = calloc(10,sizeof(unsigned int)); /* New population samples */ /* create a generator chosen by the environment variable GSL_RNG_TYPE */ gsl_rng_env_setup(); if (!getenv("GSL_RNG_SEED")) gsl_rng_default_seed = time(0); T = gsl_rng_default; r = gsl_rng_alloc(T); /* Initialising genotypes */ geninit(genotype); /* Run simulation for 2000 generations to create a burn in */ for(g = 0; g < 2000; g++){ /* Selection routine */ selection(genotype); /* Reproduction routine */ reproduction(genotype); /* Gene conversion routine */ gconv(genotype); /* Sampling based on new frequencies */ gsl_ran_multinomial(r,10,N,genotype,gensamp); for(i = 0; i < 10; i++){ *(genotype + i) = (*(gensamp + i))/(1.0*N); } /* Printing out results (for testing) */ /* for(i = 0; i < 10; i++){ printf("%.10lf ", *(genotype + i)); } printf("\n"); */ } /* Reintroducing neutral genotype, resetting hap sum */ neutinit(genotype,r); Bcheck = ncheck(genotype); Hsum = Bcheck*(1-Bcheck); /* printf("%.10lf %.10lf\n",Bcheck,Hsum); */ /* Introduce and track neutral mutations 'reps' times */ g = 0; while(g < reps){ /* Selection routine */ selection(genotype); /* Reproduction routine */ reproduction(genotype); /* Gene conversion routine */ gconv(genotype); /* Sampling based on new frequencies */ gsl_ran_multinomial(r,10,N,genotype,gensamp); for(i = 0; i < 10; i++){ *(genotype + i) = (*(gensamp + i))/(1.0*N); } /* Checking state of haplotypes: if B fixed reset so can start fresh next time */ Bcheck = ncheck(genotype); Hsum += Bcheck*(1-Bcheck); /* printf("%.10lf %.10lf\n",Bcheck,Hsum); */ /* If polymorphism fixed then abandon simulation */ Acheck = pcheck(genotype); if(Acheck == 0){ g = reps; } if(Bcheck == 0 || Bcheck == 1){ printf("%.10lf\n",Hsum); g++; /* printf("Rep Number %d\n",g); */ if(Bcheck == 1){ /* Reset genotypes so B becomes ancestral allele */ *(genotype + 0) = *(genotype + 7); *(genotype + 1) = *(genotype + 8); *(genotype + 4) = *(genotype + 9); *(genotype + 7) = 0; *(genotype + 8) = 0; *(genotype + 9) = 0; } /* Reintroducing neutral genotype, resetting hap sum */ neutinit(genotype,r); Bcheck = ncheck(genotype); Hsum = Bcheck*(1-Bcheck); } } /* End of simulation */ /* Freeing memory and wrapping up */ gsl_rng_free(r); free(gensamp); free(genotype); /* printf("The End!\n"); */ return 0; }
void pdump (LPCITEMIDLIST pidl) { LPCITEMIDLIST pidltemp = pidl; if (!TRACE_ON(pidl)) return; if (! pidltemp) { MESSAGE ("-------- pidl=NULL (Desktop)\n"); } else { MESSAGE ("-------- pidl=%p\n", pidl); if (pidltemp->mkid.cb) { do { if (_ILIsUnicode(pidltemp)) { DWORD dwAttrib = 0; LPPIDLDATA pData = _dbg_ILGetDataPointer(pidltemp); DWORD type = pData ? pData->type : 0; LPWSTR szLongName = _dbg_ILGetTextPointerW(pidltemp); LPWSTR szShortName = _dbg_ILGetSTextPointerW(pidltemp); char szName[MAX_PATH]; _dbg_ILSimpleGetText(pidltemp, szName, MAX_PATH); if ( pData && (PT_FOLDER == type || PT_VALUE == type) ) dwAttrib = pData->u.file.uFileAttribs; MESSAGE ("[%p] size=%04u type=%x attr=0x%08x name=%s (%s,%s)\n", pidltemp, pidltemp->mkid.cb, type, dwAttrib, debugstr_a(szName), debugstr_w(szLongName), debugstr_w(szShortName)); } else { DWORD dwAttrib = 0; LPPIDLDATA pData = _dbg_ILGetDataPointer(pidltemp); DWORD type = pData ? pData->type : 0; LPSTR szLongName = _dbg_ILGetTextPointer(pidltemp); LPSTR szShortName = _dbg_ILGetSTextPointer(pidltemp); char szName[MAX_PATH]; _dbg_ILSimpleGetText(pidltemp, szName, MAX_PATH); if ( pData && (PT_FOLDER == type || PT_VALUE == type) ) dwAttrib = pData->u.file.uFileAttribs; MESSAGE ("[%p] size=%04u type=%x attr=0x%08x name=%s (%s,%s)\n", pidltemp, pidltemp->mkid.cb, type, dwAttrib, debugstr_a(szName), debugstr_a(szLongName), debugstr_a(szShortName)); } pidltemp = _dbg_ILGetNext(pidltemp); } while (pidltemp && pidltemp->mkid.cb); } else { MESSAGE ("empty pidl (Desktop)\n"); } pcheck(pidl); } }
void readcommands(int argc, char **argv) { int i,haploid=0; char *parname = NULL ; phandle *ph ; char str[5000] ; char *tempname ; int n ; while ((i = getopt (argc, argv, "p:vV")) != -1) { switch (i) { case 'p': parname = strdup(optarg) ; break; case 'v': printf("version: %s\n", WVERSION) ; break; case 'V': verbose = YES ; break; case '?': printf ("Usage: bad params.... \n") ; fatalx("bad params\n") ; } } pcheck(parname,'p') ; printf("parameter file: %s\n", parname) ; ph = openpars(parname) ; dostrsub(ph) ; /** DIR2: /fg/nfiles/admixdata/ms2 SSSS: DIR2/outfiles genotypename: DIR2/autos_ccshad_fakes eglistname: DIR2/eurlist output: eurout */ getstring(ph, "genotypename:", &genotypename) ; getstring(ph, "genotypelist:", &genotypelist) ; getstring(ph, "snpname:", &snpname) ; getstring(ph, "indivname:", &indivname) ; getstring(ph, "badsnpname:", &badsnpname) ; getstring(ph, "flipsnpname:", &flipsnpname) ; getstring(ph, "flipstrandname:", &flipstrandname) ; getstring(ph, "indoutfilename:", &indoutfilename) ; getstring(ph, "indivoutname:", &indoutfilename) ; /* changed 11/02/06 */ getstring(ph, "snpoutfilename:", &snpoutfilename) ; getstring(ph, "snpoutname:", &snpoutfilename) ; /* changed 11/02/06 */ getstring(ph, "genooutfilename:", &genooutfilename) ; getstring(ph, "genotypeoutname:", &genooutfilename) ; /* changed 11/02/06 */ getstring(ph, "outputformat:", &omode) ; getstring(ph, "outputmode:", &omode) ; getstring(ph, "polarize:", &polarid) ; getint(ph, "zerodistance:", &zerodistance) ; getint(ph, "checksizemode:", &checksizemode) ; getint(ph, "badpedignore:", &badpedignore) ; getint(ph, "numchrom:", &numchrom) ; getstring(ph, "xregionname:", &xregionname) ; getdbl(ph, "hwfilter:", &nhwfilter) ; getstring(ph, "deletesnpoutname:", &deletesnpoutname); getint(ph, "outputgroup:", &ogmode) ; getint(ph, "malexhet:", &malexhet) ; getint(ph, "nomalexhet:", &malexhet) ; /* changed 11/02/06 */ getint(ph, "tersemode:", &tersem) ; getint(ph, "familynames:", &familynames) ; getint(ph, "packout:", &packout) ; /* now obsolete 11/02/06 */ getint(ph, "decimate:", &decim) ; getint(ph, "dmindis:", &dmindis) ; getint(ph, "dmaxdis:", &dmaxdis) ; getint(ph, "fastdup:", &fastdup) ; getint(ph, "flipreference:", &flipreference) ; getint(ph, "fastdupnum:", &fastdupnum) ; getdbl(ph, "fastdupthresh:", &fastdupthresh) ; getdbl(ph, "fastdupkill:", &fastdupkill) ; getint(ph, "killr2:", &killr2) ; getint(ph, "hashcheck:", &hashcheck) ; getint(ph, "outputall:", &outputall) ; getint(ph, "sevencolumnped:", &sevencolumnped) ; getint(ph, "phasedmode:", &phasedmode) ; getdbl(ph, "r2thresh:", &r2thresh) ; getdbl(ph, "r2genlim:", &r2genlim) ; getdbl(ph, "r2physlim:", &r2physlim) ; getint(ph, "chrom:", &xchrom) ; getint(ph, "lopos:", &lopos) ; getint(ph, "hipos:", &hipos) ; getint(ph, "minchrom:", &minchrom) ; getint(ph, "maxchrom:", &maxchrom) ; getdbl(ph, "maxmissfrac:", &maxmissfrac) ; getint(ph, "maxmissing:", &maxmiss) ; getstring(ph, "poplistname:", &poplistname) ; getstring(ph, "newsnpname:", &newsnpname) ; getstring(ph, "newindivname:", &newindivname) ; getint(ph, "deletedup:", &deletedup) ; getint(ph, "mkdiploid:", &mkdiploid) ; writepars(ph) ; closepars(ph) ; }
void readcommands(int argc, char **argv) { int i ; phandle *ph ; int t ; while ((i = getopt (argc, argv, "p:vV")) != -1) { switch (i) { case 'p': parname = strdup(optarg) ; break; case 'v': printf("version: %s\n", WVERSION) ; break; case 'V': verbose = YES ; break; case '?': printf ("Usage: bad params.... \n") ; fatalx("bad params\n") ; } } if (parname==NULL) { fprintf(stderr, "no parameters\n") ; return ; } pcheck(parname,'p') ; printf("parameter file: %s\n", parname) ; ph = openpars(parname) ; dostrsub(ph) ; getstring(ph, "genotypename:", &genotypename) ; getstring(ph, "snpname:", &snpname) ; getstring(ph, "indivname:", &indivname) ; getstring(ph, "poplistname:", &poplistname) ; getstring(ph, "snpeigname:", &snpeigname) ; getstring(ph, "snpweightoutname:", &snpeigname) ; /* changed 09/18/07 */ getstring(ph, "output:", &outputname) ; getstring(ph, "outputvecs:", &outputname) ; getstring(ph, "evecoutname:", &outputname) ; /* changed 11/02/06 */ getstring(ph, "outputvals:", &outputvname) ; getstring(ph, "evaloutname:", &outputvname) ; /* changed 11/02/06 */ getstring(ph, "badsnpname:", &badsnpname) ; getstring(ph, "outliername:", &outliername) ; getstring(ph, "outlieroutname:", &outliername) ; /* changed 11/02/06 */ getstring(ph, "phylipname:", &phylipname) ; getstring(ph, "phylipoutname:", &phylipname) ; /* changed 11/02/06 */ getstring(ph, "weightname:", &weightname) ; getstring(ph, "fstdetailsname:", &fstdetailsname) ; getdbl(ph, "relthresh:", &relthresh) ; getint(ph, "numeigs:", &numeigs) ; getint(ph, "numoutevec:", &numeigs) ; /* changed 11/02/06 */ getint(ph, "markerscore:", &markerscore) ; getint(ph, "chisqmode:", &chisqmode) ; getint(ph, "missingmode:", &missingmode) ; getint(ph, "fancynorm:", &fancynorm) ; getint(ph, "usenorm:", &fancynorm) ; /* changed 11/02/06 */ getint(ph, "dotpopsmode:", &dotpopsmode) ; getint(ph, "pcorrmode:", &pcorrmode) ; /* print correlations */ getint(ph, "pcpopsonly:", &pcpopsonly) ; /* but only within population */ getint(ph, "altnormstyle:", &altnormstyle) ; getint(ph, "hashcheck:", &hashcheck) ; getint(ph, "popgenmode:", &altnormstyle) ; getint(ph, "noxdata:", &noxdata) ; t = -1 ; getint(ph, "xdata:", &t) ; if (t>=0) noxdata = 1-t ; getint(ph, "nostatslim:", &nostatslim) ; getint(ph, "popsizelimit:", &popsizelimit) ; getint(ph, "minallelecnt:", &minallelecnt) ; getint(ph, "chrom:", &xchrom) ; getint(ph, "lopos:", &lopos) ; getint(ph, "hipos:", &hipos) ; getint(ph, "checksizemode:", &checksizemode) ; getint(ph, "pubmean:", &pubmean) ; getint(ph, "fstonly:", &fstonly) ; getint(ph, "fsthiprecision:", &fsthiprec) ; getint(ph, "ldregress:", &ldregress) ; getint(ph, "nsnpldregress:", &ldregress) ; /* changed 11/02/06 */ getdbl(ph, "ldlimit:", &ldlimit) ; /* in morgans */ getdbl(ph, "maxdistldregress:", &ldlimit) ; /* in morgans */ /* changed 11/02/06 */ getint(ph, "minleneig:", &nostatslim) ; getint(ph, "malexhet:", &malexhet) ; getint(ph, "nomalexhet:", &malexhet) ; /* changed 11/02/06 */ getint(ph, "familynames:", &familynames) ; getint(ph, "numoutliter:", &numoutliter) ; getint(ph, "numoutlieriter:", &numoutliter) ; /* changed 11/02/06 */ getint(ph, "numoutleigs", &numoutleigs) ; getint(ph, "numoutlierevec:", &numoutleigs) ; /* changed 11/02/06 */ getdbl(ph, "outlthresh:", &outlthresh) ; getdbl(ph, "outliersigmathresh:", &outlthresh) ; /* changed 11/02/06 */ getdbl(ph, "blgsize:", &blgsize) ; getstring(ph, "indoutfilename:", &indoutfilename) ; getstring(ph, "indivoutname:", &indoutfilename) ; /* changed 11/02/06 */ getstring(ph, "snpoutfilename:", &snpoutfilename) ; getstring(ph, "snpoutname:", &snpoutfilename) ; /* changed 11/02/06 */ getstring(ph, "genooutfilename:", &genooutfilename) ; getstring(ph, "genotypeoutname:", &genooutfilename) ; /* changed 11/02/06 */ getstring(ph, "outputformat:", &omode) ; getstring(ph, "outputmode:", &omode) ; getint(ph, "outputgroup:", &ogmode) ; getint(ph, "packout:", &packout) ; /* now obsolete 11/02/06 */ getstring(ph, "twxtabname:", &twxtabname) ; getdbl(ph, "r2thresh:", &r2thresh) ; getdbl(ph, "r2genlim:", &r2genlim) ; getdbl(ph, "r2physlim:", &r2physlim) ; getint(ph, "killr2:", &killr2) ; getint(ph, "numchrom:", &numchrom) ; printf("### THE INPUT PARAMETERS\n"); printf("##PARAMETER NAME: VALUE\n"); writepars(ph); }
static u_long convert_rawdcf( unsigned char *buffer, int size, struct dcfparam *dcfprm, clocktime_t *clock_time ) { unsigned char *s = buffer; const unsigned char *b = dcfprm->onebits; const unsigned char *c = dcfprm->zerobits; int i; parseprintf(DD_RAWDCF,("parse: convert_rawdcf: \"%s\"\n", buffer)); if (size < 57) { #ifndef PARSEKERNEL msyslog(LOG_ERR, "parse: convert_rawdcf: INCOMPLETE DATA - time code only has %d bits", size); #endif return CVT_NONE; } for (i = 0; i < size; i++) { if ((*s != *b) && (*s != *c)) { /* * we only have two types of bytes (ones and zeros) */ #ifndef PARSEKERNEL msyslog(LOG_ERR, "parse: convert_rawdcf: BAD DATA - no conversion"); #endif return CVT_NONE; } if (*b) b++; if (*c) c++; s++; } /* * check Start and Parity bits */ if ((ext_bf(buffer, DCF_S, dcfprm->zerobits) == 1) && pcheck(buffer, DCF_P_P1, dcfprm->zerobits) && pcheck(buffer, DCF_P_P2, dcfprm->zerobits) && pcheck(buffer, DCF_P_P3, dcfprm->zerobits)) { /* * buffer OK */ parseprintf(DD_RAWDCF,("parse: convert_rawdcf: parity check passed\n")); clock_time->flags = PARSEB_S_ANTENNA|PARSEB_S_LEAP; clock_time->utctime= 0; clock_time->usecond= 0; clock_time->second = 0; clock_time->minute = ext_bf(buffer, DCF_M10, dcfprm->zerobits); clock_time->minute = TIMES10(clock_time->minute) + ext_bf(buffer, DCF_M1, dcfprm->zerobits); clock_time->hour = ext_bf(buffer, DCF_H10, dcfprm->zerobits); clock_time->hour = TIMES10(clock_time->hour) + ext_bf(buffer, DCF_H1, dcfprm->zerobits); clock_time->day = ext_bf(buffer, DCF_D10, dcfprm->zerobits); clock_time->day = TIMES10(clock_time->day) + ext_bf(buffer, DCF_D1, dcfprm->zerobits); clock_time->month = ext_bf(buffer, DCF_MO0, dcfprm->zerobits); clock_time->month = TIMES10(clock_time->month) + ext_bf(buffer, DCF_MO, dcfprm->zerobits); clock_time->year = ext_bf(buffer, DCF_Y10, dcfprm->zerobits); clock_time->year = TIMES10(clock_time->year) + ext_bf(buffer, DCF_Y1, dcfprm->zerobits); switch (ext_bf(buffer, DCF_Z, dcfprm->zerobits)) { case DCF_Z_MET: clock_time->utcoffset = -1*60*60; break; case DCF_Z_MED: clock_time->flags |= PARSEB_DST; clock_time->utcoffset = -2*60*60; break; default: parseprintf(DD_RAWDCF,("parse: convert_rawdcf: BAD TIME ZONE\n")); return CVT_FAIL|CVT_BADFMT; } if (ext_bf(buffer, DCF_A1, dcfprm->zerobits)) clock_time->flags |= PARSEB_ANNOUNCE; if (ext_bf(buffer, DCF_A2, dcfprm->zerobits)) clock_time->flags |= PARSEB_LEAPADD; /* default: DCF77 data format deficiency */ if (ext_bf(buffer, DCF_R, dcfprm->zerobits)) clock_time->flags |= PARSEB_CALLBIT; parseprintf(DD_RAWDCF,("parse: convert_rawdcf: TIME CODE OK: %d:%d, %d.%d.%d, flags 0x%lx\n", (int)clock_time->hour, (int)clock_time->minute, (int)clock_time->day, (int)clock_time->month,(int) clock_time->year, (u_long)clock_time->flags)); return CVT_OK; } else { /* * bad format - not for us */ #ifndef PARSEKERNEL msyslog(LOG_ERR, "parse: convert_rawdcf: parity check FAILED for \"%s\"", buffer); #endif return CVT_FAIL|CVT_BADFMT; } }
uint32_t sftp_v6_realpath(struct sftpjob *job) { char *path, *compose, *resolvedpath; uint8_t control_byte = SSH_FXP_REALPATH_NO_CHECK; unsigned rpflags = 0; struct stat sb; struct sftpattr attrs; pcheck(sftp_parse_path(job, &path)); if(job->left) { pcheck(sftp_parse_uint8(job, &control_byte)); while(job->left) { pcheck(sftp_parse_path(job, &compose)); if(compose[0] == '/') path = compose; else { char *newpath = sftp_alloc(job->a, strlen(path) + strlen(compose) + 2); strcpy(newpath, path); strcat(newpath, "/"); strcat(newpath, compose); path = newpath; } } } D(("sftp_v6_realpath %s %#x", path, control_byte)); switch(control_byte) { case SSH_FXP_REALPATH_NO_CHECK: /* Don't follow links and don't fail if the path doesn't exist */ rpflags = 0; break; case SSH_FXP_REALPATH_STAT_IF: /* Follow links but don't fail if the path doesn't exist */ rpflags = RP_READLINK; break; case SSH_FXP_REALPATH_STAT_ALWAYS: /* Follow links and fail if the path doesn't exist */ rpflags = RP_READLINK|RP_MUST_EXIST; break; default: return SSH_FX_BAD_MESSAGE; } if(!(resolvedpath = sftp_find_realpath(job->a, path, rpflags))) return HANDLER_ERRNO; D(("...real path is %s", resolvedpath)); switch(control_byte) { case SSH_FXP_REALPATH_NO_CHECK: /* Don't stat, send dummy attributes */ memset(&attrs, 0, sizeof attrs); attrs.name = resolvedpath; break; case SSH_FXP_REALPATH_STAT_IF: /* stat as hard as we can but accept failure if it's just not there */ if(stat(resolvedpath, &sb) >= 0 || lstat(resolvedpath, &sb) >= 0) sftp_stat_to_attrs(job->a, &sb, &attrs, 0xFFFFFFFF, resolvedpath); else { memset(&attrs, 0, sizeof attrs); attrs.name = resolvedpath; } break; case SSH_FXP_REALPATH_STAT_ALWAYS: /* stat and error on failure */ if(stat(resolvedpath, &sb) >= 0 || lstat(resolvedpath, &sb) >= 0) sftp_stat_to_attrs(job->a, &sb, &attrs, 0xFFFFFFFF, resolvedpath); else /* Can only happen if path is deleted between realpath call and stat */ return HANDLER_ERRNO; break; } sftp_send_begin(job->worker); sftp_send_uint8(job->worker, SSH_FXP_NAME); sftp_send_uint32(job->worker, job->id); protocol->sendnames(job, 1, &attrs); sftp_send_end(job->worker); return HANDLER_RESPONDED; }