/* * シリアルI/Oポート割込みハンドラ */ void sio_handler(void) { int port; for(port = 0; port < TNUM_PORT; ++ port) { if(BITTEST(siopcb_table[port].Flag, SIO_STA_OPEN)) { /* 受信完了割込み */ if(BITTEST(siopcb_table[port].Flag, SIO_STA_INTRCV)) { /* 受信した文字を取り出し */ BITCLEAR(siopcb_table[port].Flag, SIO_STA_INTRCV); sio_ierdy_rcv(GET_SIOPCB(ID_PORT(port))->exinf); } /* 送信完了割込み */ if(BITTEST(siopcb_table[port].Flag, SIO_STA_INTSND)) { BITCLEAR(siopcb_table[port].Flag, SIO_STA_INTSND); sio_ierdy_snd(GET_SIOPCB(ID_PORT(port))->exinf); } } } }
/* * gcc-specific pragmas. */ int pragmas_gcc(char *t) { char u; int ign, warn, err, i; extern bittype warnary[], werrary[]; extern char *flagstr[], *pragstore; if (strcmp((t = pragtok(NULL)), "diagnostic") == 0) { ign = warn = err = 0; if (strcmp((t = pragtok(NULL)), "ignored") == 0) ign = 1; else if (strcmp(t, "warning") == 0) warn = 1; else if (strcmp(t, "error") == 0) err = 1; else return 1; if (eat('\"') || eat('-')) return 1; for (t = pragstore; *t && *t != '\"'; t++) ; u = *t; *t = 0; for (i = 0; i < NUMW; i++) { if (strcmp(flagstr[i], pragstore+1) != 0) continue; if (err) { BITSET(warnary, i); BITSET(werrary, i); } else if (warn) { BITSET(warnary, i); BITCLEAR(werrary, i); } else { BITCLEAR(warnary, i); BITCLEAR(werrary, i); } return 0; } *t = u; } else if (strcmp(t, "poison") == 0) { /* currently ignore */; } else if (strcmp(t, "visibility") == 0) { /* currently ignore */; } else if (strcmp(t, "system_header") == 0) { /* currently ignore */; } else werror("gcc pragma unsupported"); return 0; }
/****************************************************************************** * * Shutdown Tooltalk connection. * *****************************************************************************/ void DetachFromTooltalk( unsigned long *nocare1) /* if Xt - XtInputId *id; */ { char *sessid; if (dtSvcProcIdG) { /* * NULL the global to indicate that we no longer want to * chit-chat with Tooltalk. */ dtSvcProcIdG = (char *) NULL; sessid = tt_default_session(); tt_session_quit(sessid); tt_free(sessid); tt_close(); } /* * Unregister the Tooltalk fildes from the select mask. */ if (ttfdG != -1) { BITCLEAR(allactivefdsG, ttfdG); ttfdG = -1; } }
// Get and set functions void skiroc2_slow_control_set(const item_t * item, unsigned int value) { if (item->nbits <= 0) { fprintf(stderr, "Invalid number of bits for register %s.\n", item->name); exit(EXIT_FAILURE); } int i; int offset = item->subaddr; char * bitarray = (char *) control_register; #ifdef REVERSE_BIT_ORDER int value2 = 0; for (i = 0; i < item->nbits; ++i) { value2 <<= 1; value2 |= (value & 1); value >>= 1; } value = value2; #endif for (i = 0; i < item->nbits; ++i) { if (value & (1<<i)) { BITSET(bitarray, offset+i); } else { BITCLEAR(bitarray, offset+i); } } }
static int free_ssdcache_entry(ssd_cache_struct_t *cache_struct, ssd_cache_entry_t entry, log_ctx_t *ctx) { // Validate if (NULL == cache_struct) { sfs_log(ctx, SFS_ERR, "%s: Invalid parameter specified\n", __FUNCTION__); errno = EINVAL; return -1; } pthread_spin_lock(&cache_struct->stats.lock); if (entry > cache_struct->stats.num_cachelines) { pthread_spin_unlock(&cache_struct->stats.lock); sfs_log(ctx, SFS_ERR, "%s: Invalid parameter specified\n", __FUNCTION__); errno = EINVAL; return -1; } pthread_spin_unlock(&cache_struct->stats.lock); pthread_mutex_lock(&cache_struct->ssd_ce_mutex); BITCLEAR(cache_struct->ce_bitmap, entry); pthread_mutex_unlock(&cache_struct->ssd_ce_mutex); return 0; }
/* * "emulate" the gcc warning flags. */ void Wflags(char *str) { int i, isset, iserr; /* handle -Werror specially */ if (strcmp("error", str) == 0) { for (i = 0; i < NUMW; i++) BITSET(werrary, i); return; } isset = 1; if (strncmp("no-", str, 3) == 0) { str += 3; isset = 0; } iserr = 0; if (strncmp("error=", str, 6) == 0) { str += 6; iserr = 1; } for (i = 0; i < NUMW; i++) { if (strcmp(flagstr[i], str) != 0) continue; if (isset) { if (iserr) BITSET(werrary, i); BITSET(warnary, i); } else if (iserr) { BITCLEAR(werrary, i); } else { BITCLEAR(warnary, i); } return; } fprintf(stderr, "unrecognised warning option '%s'\n", str); }
static void _i2c_hd44780_pcf8574_lowlevel_write(int fd, unsigned char r, i2c_hd44780_pcf8574_pins_map_t pcf8574_pins) /** * \brief envoi un octet au hd44780 en respectant son timing bas niveau. * \param fd descripteur de communication avec le pcf8574. * \param r octet à envoyer au hd44780 * \param pcf8574_pins mapping hd44780/PCF8574 */ { unsigned char byte = r; BITCLEAR(byte, pcf8574_pins[_HD44780_ENABLE]); i2c_write_byte(fd, byte); mynanosleep(40); BITSET(byte, pcf8574_pins[_HD44780_ENABLE]); i2c_write_byte(fd, byte); mynanosleep(230); BITCLEAR(byte, pcf8574_pins[_HD44780_ENABLE]); i2c_write_byte(fd, byte); mynanosleep(270); }
main() { char bitarray[BITNSLOTS(47)]; BITSET(bitarray, 23); BITCLEAR(bitarray, 14); if(BITTEST(bitarray, 35)) printf("yep\n"); else printf("nope\n"); sieve(); return 0; }
int i2c_hd44780_pcf8574_write_byte(int fd, unsigned char data, enum i2c_hd44780_pcf8574_RS_e rs, int blight, i2c_hd44780_pcf8574_pins_map_t pcf8574_pins) /** * \brief envoi un octet "applicatif" au hd44780. * \details nous sommes en mode 4bits avec un pcf8574. Nous envoyons donc 2 octets (dont seulement les 4bits de poid fort sont significatif) au hd44780 * \param fd descripteur de communication avec le pcf8574. * \param r octet à envoyer au hd44780 * \param pcf8574_pins mapping hd44780/PCF8574 */ { unsigned char d = 0; if(blight) BITSET(d, pcf8574_pins[_HD44780_BLIGHT]); else BITCLEAR(d, pcf8574_pins[_HD44780_BLIGHT]); if(rs) BITSET(d, pcf8574_pins[_HD44780_RS]); else BITCLEAR(d, pcf8574_pins[_HD44780_RS]); // envoie des 4 bits de poid fort BITCPY(data, 4, d, pcf8574_pins[_HD44780_DATA4]); BITCPY(data, 5, d, pcf8574_pins[_HD44780_DATA5]); BITCPY(data, 6, d, pcf8574_pins[_HD44780_DATA6]); BITCPY(data, 7, d, pcf8574_pins[_HD44780_DATA7]); _i2c_hd44780_pcf8574_lowlevel_write(fd, d, pcf8574_pins); // envoie des 4 bits de poid faible BITCPY(data, 0, d, pcf8574_pins[_HD44780_DATA4]); BITCPY(data, 1, d, pcf8574_pins[_HD44780_DATA5]); BITCPY(data, 2, d, pcf8574_pins[_HD44780_DATA6]); BITCPY(data, 3, d, pcf8574_pins[_HD44780_DATA7]); _i2c_hd44780_pcf8574_lowlevel_write(fd, d, pcf8574_pins); }
void performAnalysis(double*** result, char** ltcs, char** mat, char** reaction, unsigned long ltcs_count, unsigned long efm_count, unsigned int rx_count) { unsigned long li, lj, lk; double** m_result = calloc(rx_count, sizeof(double*)); for (li = 0; li < rx_count; li++) { m_result[li] = calloc(ltcs_count, sizeof(double)); } unsigned long bitarray_size = getBitsize(rx_count * 2); unsigned long* counts = calloc(rx_count, sizeof(unsigned long)); char* n_vect = calloc(1, bitarray_size); for (li = 0; li < ltcs_count; li++) { for (lj = 0; lj < bitarray_size; lj++) { BITCLEAR(counts, lj); } for (lj = 0; lj < rx_count; lj++) { counts[lj] = 0; } double c = (double) getLtcsCardinality(ltcs[li], efm_count); for (lj = 0; lj < efm_count; lj++) { if (BITTEST(ltcs[li], lj)) { for (lk = 0; lk < rx_count; lk++) { if (BITTEST(mat[lj], 2*lk)) { counts[lk]++; } else if (BITTEST(mat[lj], 2*lk+1)) { BITSET(n_vect, lk); counts[lk]++; } } } } for (lj = 0; lj < rx_count; lj++) { double val = (double)counts[lj]*100/c; if (BITTEST(n_vect, lj)) { val *= -1; } m_result[lj][li] = val; } } free(n_vect); free(counts); *result = m_result; }
static void DeleteDetailFromMask( Mask **ppDetailMask, unsigned short detail) { Mask *pDetailMask = *ppDetailMask; if (!pDetailMask) { int i; pDetailMask = (Mask *)__XtMalloc(sizeof(Mask) * MasksPerDetailMask); for (i = MasksPerDetailMask; --i >= 0; ) pDetailMask[i] = ~0; *ppDetailMask = pDetailMask; } BITCLEAR((pDetailMask), detail); }
static Mask * DeleteDetailFromMask(Mask *pDetailMask, unsigned int detail) { Mask *mask; int i; mask = malloc(sizeof(Mask) * MasksPerDetailMask); if (mask) { if (pDetailMask) for (i = 0; i < MasksPerDetailMask; i++) mask[i] = pDetailMask[i]; else for (i = 0; i < MasksPerDetailMask; i++) mask[i] = ~0L; BITCLEAR(mask, detail); } return mask; }
int i2c_hd44780_pcf8574_backlight(int fd, int blight, i2c_hd44780_pcf8574_pins_map_t pcf8574_pins) /** * \brief allume ou éteint le rétro-éclairage. * \param fd descripteur de communication avec le pcf8574. * \param blight etat du rétro-éclairage. * \param pcf8574_pins mapping hd44780/PCF8574. */ { unsigned char cmnd = 0; if(blight) BITSET(cmnd, pcf8574_pins[_HD44780_BLIGHT]); else BITCLEAR(cmnd, pcf8574_pins[_HD44780_BLIGHT]); i2c_write_byte(fd, cmnd); return 0; }
/* * read file containing reversibilty of reactions in form of: * 1 0 0 1 1 * where 1 describes a reversible and 0 a non reversible reaction */ void readReversibleFile(char *filename, char *reversible_reactions, unsigned int rx_count) { char* line = NULL; size_t len = 0; FILE *file = fopen(filename, "r"); if (!file) { quitError("Error in opening file\n", ERROR_FILE); } while ( getline(&line, &len, file) != -1) { char *ptr; ptr = strtok(line, "\n\t "); int i = 0; while(ptr != NULL) { int x = atoi(ptr); if (x == 1) { BITSET(reversible_reactions, i); } else if (x == 0) { BITCLEAR(reversible_reactions, i); } else { quitError("not a correct reversibility file\n", ERROR_FILE); } i++; ptr = strtok(NULL, "\n\t "); } if (i != rx_count) { quitError("not a correct reversibility file\n", ERROR_FILE); } } fclose(file); free(line); }
int i2c_hd44780_pcf8574_init(int fd, i2c_hd44780_pcf8574_pins_map_t pcf8574_pins) /** * \brief initialisation pcf8574 et hd44780. * \details Sequence d'initialisation d'un hd44780 : - Attendre au moins 15ms depuis le passage a 5V de Vcc, - Envoyer l'instruction "Function set" avec la valeur 0011XXXX, - Attendre au moins 4.1ms, - Envoyer à nouveau l'instruction "Function set" avec la valeur 0011XXXX, - Attendre au moins 100 microsecondes, - Envoyer à nouveau l'instruction "Function set" avec la valeur 0011XXXX, - Si on veut activer le mode 4 bits, envoyer les 4 bits de poids fort de l'instruction "Function set" avec la valeur 0010, - Configuration du nombre de lignes et de la matrice, en envoyant l'Instruction "Function set" avec par exemple la valeur 00111000 (8 bits, 2 lignes, 5x8pixels), - Configuration du controle d'affichage, en envoyant l'instruction "Display on/off control" avec par exemple la valeur 00001110 (Affichage visible, curseur visible, curseur fixe), // HD44780_CMD_TURN_ON_DISP - Effacement de l'ecran, en envoyant l'instruction "Clear display", avec pour valeur 00000001, // HD44780_CMD_CLEAR_HOME - Configuration du curseur, en envoyant l'instruction "Entry set mode", avec par exemple pour valeur 00000110 (deplacement du curseur vers la droite, pas de decalage du compteur d'adresse). // HD44780_CMD_SET_CSR - Fin de l'initialisation, l'ecran est prêt à recevoir les autres instructions permettant l'affichage. * \param fd descripteur de communication avec le pcf8574. * \param pcf8574_pins mapping hd44780/PCF8574 */ { unsigned char d; d=0; mynanosleep(15 * 1000000); // 15 ms BITSET(d, pcf8574_pins[_HD44780_DATA5]); BITSET(d, pcf8574_pins[_HD44780_DATA4]); mymicrosleep(15000); // initialisation _i2c_hd44780_pcf8574_lowlevel_write(fd, d, pcf8574_pins); // 1er 0x3 mymicrosleep(5000); _i2c_hd44780_pcf8574_lowlevel_write(fd, d, pcf8574_pins); // 2eme 0x3 mymicrosleep(100); _i2c_hd44780_pcf8574_lowlevel_write(fd, d, pcf8574_pins); // 4eme 0x3 mymicrosleep(150); // passage en mode 4 bits BITCLEAR(d, pcf8574_pins[_HD44780_DATA4]); _i2c_hd44780_pcf8574_lowlevel_write(fd, d, pcf8574_pins); mymicrosleep(1000); // préparation divers i2c_hd44780_pcf8574_write_byte(fd, HD44780_CMD_SET_INTERFACE, CMND, 1, pcf8574_pins); mymicrosleep(50); i2c_hd44780_pcf8574_write_byte(fd, HD44780_CMD_EN_DISP, CMND, 1, pcf8574_pins); mymicrosleep(50); i2c_hd44780_pcf8574_write_byte(fd, HD44780_CMD_CLEAR_HOME, CMND, 1, pcf8574_pins); mymicrosleep(1500); // mymicrosleep(2000); i2c_hd44780_pcf8574_write_byte(fd, HD44780_CMD_SET_CSR, CMND, 1, pcf8574_pins); mymicrosleep(50); i2c_hd44780_pcf8574_write_byte(fd, HD44780_CMD_TURN_ON_DISP, CMND, 1, pcf8574_pins); mymicrosleep(50); return 0; }
inline void output_low(unsigned char bit) { BITCLEAR(dest_register, bit); }
/****************************************************************************** * * main * *****************************************************************************/ int main ( int argc, char **argv ) { char **cmdLine; int success; fd_set readfds, exceptfds; int nfound; struct timeval timeoutShort, timeoutLong; int junki,i; char *tmpBuffer; int errorBytes; int firstPass, tmpi; char *tmpProgName = NULL; setlocale( LC_ALL, "" ); #ifdef _DTEXEC_NLS16 Dt_nlInit(); #endif /* _DTEXEC_NLS16 */ /* * For debugging purposes, a way to pause the process and allow * time for a xdb -P debugger attach. If no args, (e.g. libDtSvc is * test running the executable), cruise on. */ if (getenv("_DTEXEC_DEBUG") && (argc > 1)) { /* * Don't block in a system call, or on libDtSvc's attempts to * just test exec us. */ SPINBLOCK } /* * Note: dtSvcProcIdG is used like a boolean to control whether * we are communicating with libDtSvc using Tooltalk. */ dtSvcProcIdG = (char *) NULL; /* assume not communicating with TT */ ttfdG = -1; cmdLine = ParseCommandLine (argc, argv); /* * If a signal goes off *outside* the upcoming select, we'll need to * rediscover the signal by letting select() timeout. * * We might also set a rediscover flag to fake a signal response. */ rediscoverSigCldG = 0; /* boolean and counter */ rediscoverUrgentSigG = 0; /* boolean and counter */ InitializeSignalHandling (); /* * Create a pipe for logging of errors for actions without * windows. */ errorpipeG[0] = -1; /* by default, no stderr redirection */ errorpipeG[1] = -1; if ( requestTypeG == TRANSIENT ) { /* should be WINDOW_TYPE NO_STDIO */ if ( pipe(errorpipeG) == -1 ) { errorpipeG[0] = -1; errorpipeG[1] = -1; } } if (cmdLine) { success = ExecuteCommand (cmdLine); if (!success) { /* * Act like we were killed - it will result in a * DtACTION_FAILED. */ childPidG = -1; rediscoverUrgentSigG = 1; } } else { /* * Act like we had a child and it went away - it will result * in a DtACTION_DONE. */ childPidG = -1; rediscoverSigCldG = 1; } /* * Note when we started so we can compare times when we finish. */ (void) gettimeofday (&startTimeG, &zoneG); if (dtSvcProcIdG) { if ( !InitializeTooltalk() ) { /* * We have no hope of talking to our caller via Tooltalk. */ dtSvcProcIdG = (char *) NULL; } } /* * Tie in to the default session and start chatting. */ if (dtSvcProcIdG) tt_session_join(tt_default_session()); /* * Finally send caller our current proc id so they can talk back. */ if (dtSvcProcIdG) IdSelfToCallerRequest(); /* * Monitor file descriptors for activity. If errors occur on a fds, * it will be removed from allactivefdsG after handling the error. */ CLEARBITS(allactivefdsG); /* * Add Tooltalk */ if ( ttfdG != -1 ) BITSET(allactivefdsG, ttfdG); /* add Tooltalk */ /* * Add Error Log */ if ( errorpipeG[0] != -1 ) BITSET(allactivefdsG, errorpipeG[0]); /* add read side of error pipe */ /* * Set options for rediscovery and not-rediscovery modes of * operation. */ shutdownPhaseG = SDP_DONE_STARTING; /* triggered with rediscoverSigCldG */ timeoutShort.tv_sec = 0; /* in quick rediscovery mode */ timeoutShort.tv_usec = SHORT_SELECT_TIMEOUT; timeoutLong.tv_sec = 86400; /* don't thrash on rediscovery */ timeoutLong.tv_usec = 0; for (;;) { COPYBITS(allactivefdsG, readfds); COPYBITS(allactivefdsG, exceptfds); if (rediscoverSigCldG || rediscoverUrgentSigG) { nfound =select(MAXSOCKS, FD_SET_CAST(&readfds), FD_SET_CAST(NULL), FD_SET_CAST(&exceptfds), &timeoutShort); } else { nfound =select(MAXSOCKS, FD_SET_CAST(&readfds), FD_SET_CAST(NULL), FD_SET_CAST(&exceptfds), &timeoutLong); } if (nfound == -1) { /* * Handle select() problem. */ if (errno == EINTR) { /* * A signal happened - let rediscover flags redirect flow * via short select timeouts. */ } else if ((errno == EBADF) || (errno == EFAULT)) { /* * A connection probably dropped. */ if (ttfdG != -1) { if ( GETBIT(exceptfds, ttfdG) ) { /* * Tooltalk connection has gone bad. * * Judgement call - when the Tooltalk connection goes * bad, let dtexec continue rather than doing an exit. */ DetachFromTooltalk(NULL); } } if (errorpipeG[0] != -1) { if ( GETBIT(exceptfds, errorpipeG[0]) ) { /* * Error pipe has gone bad. */ close(errorpipeG[0]); BITCLEAR(allactivefdsG, errorpipeG[0]); errorpipeG[0] = -1; } } } else { /* * We have bad paremeters to select() */ } /* * So that select() errors cannot dominate, now behave as * though only a timeout had occured. */ nfound = 0; } if (nfound > 0) { /* * Have some input to process. Figure out who. */ if (ttfdG != -1) { if ( GETBIT(readfds, ttfdG) ) { /* Clear bit first, since calling input_handler() could */ /* have the side-effect of setting ttfdG to -1! */ BITCLEAR(readfds, ttfdG); /* * Tooltalk activity. * * Note that the input_handler parameters match * an XtInputHandler() style callback in case Xt is * ever used. */ input_handler((char *) NULL, (int *) &junki, (unsigned long *) &junki); } } if (errorpipeG[0] != -1) { if ( GETBIT(readfds, errorpipeG[0]) ) { /* * Stderr activity. * * Read the errorpipe until no more seems available. * Call that good enough and write a time-stamped * block to the errorLog file. */ errorBytes = 0; /* what we have so far */ tmpBuffer = NULL; firstPass = 1; while (1) { char buf; nfound =select(MAXSOCKS, FD_SET_CAST(&readfds), FD_SET_CAST(NULL), FD_SET_CAST(NULL), &timeoutShort); if (nfound > 0) { tmpi = read (errorpipeG[0], &buf, 1); } else { tmpi = 0; } if ( tmpi > 0 ) { /* * Grow buffer to hold entire error stream. */ firstPass = 0; if (tmpBuffer == NULL) tmpBuffer = (char *) malloc( tmpi + 1); else tmpBuffer = (char *) realloc( tmpBuffer, errorBytes + tmpi + 1); /* * Drain error pipe. */ tmpBuffer[errorBytes] = buf; errorBytes += tmpi; tmpBuffer[errorBytes] = '\0'; if (errorBytes < 65535) { /* * Pause a bit and wait for a continuation of * the error stream if there is more. */ select(0, FD_SET_CAST(NULL), FD_SET_CAST(NULL), FD_SET_CAST(NULL), &timeoutShort); } else { /* * We have enough to do a dump now. */ break; } } else { /* * No more to read. */ if (firstPass) { /* * On the first pass after select(), if we have 0 bytes, * it really means the pipe has gone down. */ close(errorpipeG[0]); BITCLEAR(allactivefdsG, errorpipeG[0]); BITCLEAR(readfds, errorpipeG[0]); errorpipeG[0] = -1; } break; } } if (tmpBuffer) { if (!tmpProgName) { tmpProgName = (char *) malloc (strlen (argv[0]) + strlen (cmdLine[0]) + 5); if (!tmpProgName) tmpProgName = argv[0]; else { /* * To identify the process for this stderr, * use both argv[0] and the name of the * process that was execvp'd */ (void) strcpy (tmpProgName, "("); (void) strcat (tmpProgName, argv[0]); (void) strcat (tmpProgName, ") "); (void) strcat (tmpProgName, cmdLine[0]); } } DtMsgLogMessage( tmpProgName, DtMsgLogStderr, "%s", tmpBuffer ); free( tmpBuffer ); } if (errorpipeG[0] != -1) BITCLEAR(readfds, errorpipeG[0]); } } /* * So that select() data cannot dominate, now behave as * though only a timeout had occured. */ nfound = 0; } if (nfound == 0) { /* * Timeout. We are probably rediscovering and have entered * a shutdown phase. The following rediscover handlers are * in priority order. * * Note that by way of timeouts and events, we will make * multiple passes through this block of code. */ if (rediscoverUrgentSigG) { /* * Handle urgent signal. * * Tact: wait awhile and see if a SIGCLD will happen. * If it does, then a normal shutdown will suffice. * If a SIGCLD does not happen, then do a raw exit(0). * Exit is required for BBA anyway. */ if (rediscoverSigCldG) /* * Rather than act on the Urgent Signal, defer to the * SIGCLD Signal shutdown process. */ rediscoverUrgentSigG = 0; else /* * Still in a mode where we have an outstanding * Urgent Signal but no SIGCLD. Bump a counter * which moves us closer to doing an exit(). */ rediscoverUrgentSigG++; /* * After 5 seconds (add select timeout too) waiting for * a SIGCLD, give up and exit. */ if (rediscoverUrgentSigG > ((1000/SHORT_SELECT_TIMEOUT)*5) ) { #if defined(__aix) || defined (__osf__) || defined(CSRG_BASED) || defined(linux) PanicSignal(0); #else PanicSignal(); #endif } } if (rediscoverSigCldG) { /* * Handle SIGCLD signal. * * Under SIGCLD, we will make multiple passes through the * following, implementing a phased shutdown. */ if (shutdownPhaseG == SDP_DONE_STARTING) { /* * Send Done(Request) for starters. */ if (dtSvcProcIdG) DoneRequest(_DtActCHILD_DONE); if (dtSvcProcIdG) { /* * Sit and wait for the Done Reply in select() */ shutdownPhaseG = SDP_DONE_REPLY_WAIT; } else { /* * Unable to send Done Reply. Assume we're on * our own from now on. */ shutdownPhaseG = SDP_DONE_PANIC_CLEANUP; } } if (shutdownPhaseG == SDP_DONE_REPLY_WAIT) { /* * After 5 minutes of passing through REPLY_WAIT, * assume the Done(Reply) will never come in and * move on. */ rediscoverSigCldG++; if (rediscoverSigCldG > ((1000/SHORT_SELECT_TIMEOUT)*300)) { if (dtSvcProcIdG) { /* * Try to detatch from Tooltalk anyway. */ DetachFromTooltalk(NULL); } shutdownPhaseG = SDP_DONE_PANIC_CLEANUP; } /* * See if the Tooltalk connection is still alive. If * not, then no reason to wait around. */ else if (!dtSvcProcIdG) { shutdownPhaseG = SDP_DONE_PANIC_CLEANUP; } } if (shutdownPhaseG == SDP_DONE_REPLIED) { /* * We have our Done(Reply), so proceed. */ if (dtSvcProcIdG) shutdownPhaseG = SDP_FINAL_LINGER; else shutdownPhaseG = SDP_DONE_PANIC_CLEANUP; } if (shutdownPhaseG == SDP_DONE_PANIC_CLEANUP) { /* * We cannot talk with caller, so do cleanup * of tmp files. */ for (i = 0; i < tmpFileCntG; i++ ) { chmod( tmpFilesG[i], (S_IRUSR|S_IWUSR) ); unlink( tmpFilesG[i] ); } shutdownPhaseG = SDP_FINAL_LINGER; } if (shutdownPhaseG == SDP_FINAL_LINGER) { /* * All done. */ static int skipFirst = 1; if (skipFirst) { /* * Rather than a quick departure from the select() * loop, make one more pass. If the child has gone * down quickly, the SIGCLD may have caused us to * get here before any errorPipeG information has * had a chance to reach us. */ skipFirst = 0; } else { FinalLinger(); } } } } } }
BloomFilter::BloomFilter(int init_size){ size = BITNSLOTS(init_size) * CHAR_BIT; bitarray = new char[BITNSLOTS(init_size)]; for(int i =0; i < init_size; i++) BITCLEAR(bitarray,i); };
int bitset_clear(bitset *bs, unsigned int bit) { if (bs == NULL || bit >= bs->size) return -BITSET_ERROR; BITCLEAR((bs->bs), bit); return BITSET_SUCCESS; }
int main() { unsigned int input; unsigned int bit_length; unsigned int rng_ceil; unsigned int key_size; unsigned int bits; char generate_keys = 'y'; while(is_power_of_two(rng_ceil = get_rng_ceil()) == 0) { puts("Sorry, I can only use powers of 2!"); } bit_length = get_bit_length(rng_ceil); while (generate_keys == 'y' || generate_keys == 'Y') { bits = 0; key_size = get_key_size(); char key[BITNSLOTS(key_size)]; while (bits < key_size) { input = (get_rng_input(rng_ceil) - 1); for (int i = 0; i < bit_length && bits < key_size; i++) { if (input % 2 == 1) { BITSET(key, bits); } else { BITCLEAR(key, bits); } input = input >> 1; bits += 1; } printf("%d of %d bits generated...\n", bits, key_size); } printf("Your key is:\n0x"); unsigned int chunk = 0; for (int i = 0; i < bits; i++) { if (BITTEST(key, i)) { chunk += 1; } if (i > 0 && ((i+1) % HEXBITS == 0 || i+1 == bits)) { printf("%X", chunk); chunk = 0; } else { chunk = chunk << 1; } } puts("\nBe sure to run this through newBitcoinKey in bitcoin.sh first if you are planning on using this to seed a Bitcoin address!"); puts("Generate another? [y/n]"); generate_keys = getchar(); while (generate_keys != 'y' && generate_keys != 'Y' && generate_keys != 'n' && generate_keys != 'N') { generate_keys = getchar(); } } return 0; }
/* * read EFM file * store EFMs in bit vectors * clean matrix by removing reactions that have a flux in only one direction * store internal loops in EFMs */ void readInitialMatrix(int rx_count, unsigned long* efm_count, char* reversible_reactions, unsigned int* rev_rx_count, char*** initial_mat, char*** full_mat, int keep_full_mat, char* exchange_reaction, char** loops, int checkLoops, double threshold, char *filename) { printf("%s loading EFMs\n", getTime()); char** m_initial_mat = NULL; char* m_loops = NULL; char* line = NULL; size_t len = 0; unsigned long mat_ix = 0; unsigned int m_rev_rx_count = getReversibleReactionCount(reversible_reactions, rx_count); unsigned long rxs_bitarray_size = getBitsize(m_rev_rx_count); char* rxs_fwd = calloc(1, rxs_bitarray_size); char* rxs_rev = calloc(1, rxs_bitarray_size); char* rxs_both = calloc(1, rxs_bitarray_size); // read EFMs FILE *file = fopen(filename, "r"); if (!file) { quitError("Error in opening file\n", ERROR_FILE); } while ( getline(&line, &len, file) != -1) { // allocate memory and load EFM reallocInitialMatrix(&m_initial_mat, &m_loops, mat_ix); allocateEfm(&m_initial_mat[mat_ix], m_rev_rx_count); int loaded = loadEfm(m_initial_mat[mat_ix], line, reversible_reactions, rxs_fwd, rxs_rev, rx_count, exchange_reaction, checkLoops, threshold); // check if EFM is an internal loop if (loaded > 0) { BITCLEAR(m_loops, mat_ix); } else { BITSET(m_loops, mat_ix); } mat_ix++; } free(line); line = NULL; fclose(file); unsigned long bitarray_size = getBitsize(mat_ix); m_loops = (char*) realloc(m_loops, bitarray_size); // define reactions that have a flux in both directions unsigned int i = 0; unsigned int result_rx_count = 0; for (i = 0; i < m_rev_rx_count; i++) { if (BITTEST(rxs_fwd,i) && BITTEST(rxs_rev,i)) { BITSET(rxs_both,i); result_rx_count++; } } free(rxs_fwd); free(rxs_rev); rxs_fwd = NULL; rxs_rev = NULL; // clean matrix by removing reactions that are active in only one direction printf("%s optimizating EFM matrix\n", getTime()); getCleanedMatrix(m_initial_mat, mat_ix, m_rev_rx_count, initial_mat, rxs_both, result_rx_count, m_loops); if (keep_full_mat < 1) { unsigned long ul; for (ul = 0; ul < mat_ix; ul++) { if (!BITTEST(m_loops,ul)) { free(m_initial_mat[ul]); } } free(m_initial_mat); m_initial_mat = NULL; } free(rxs_both); rxs_both = NULL; // set return pointer *efm_count = mat_ix; *rev_rx_count = result_rx_count; *loops = m_loops; *full_mat = m_initial_mat; }