Ejemplo n.º 1
0
/*
 *  シリアル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);
			}
		}
	}
}
Ejemplo n.º 2
0
/*
 * print efm matrix for debugging
 */
void printMatrix(char** matrix, unsigned long efm_count, unsigned int rx_count)
{
    unsigned long i;
    unsigned int j;
    unsigned int bits = rx_count * 2;
    for (i = 0; i < efm_count; i++)
    {
        for (j = 0; j < bits; j+=2)
        {
            if (BITTEST(matrix[i],j))
            {
                printf("  1");
                if (BITTEST(matrix[i], j+1))
                {
                    quitError("ERROR: fwd and rev is active in EFM\n", ERROR_EFM);
                }
            }
            else if (BITTEST(matrix[i],j+1))
            {
                printf(" -1");
            }
            else
            {
                printf("  0");
            }
        }
        printf("\n");
    }
}
Ejemplo n.º 3
0
/*
 * read stoichiometric matrix file and searches exchange reactions
 * exchange reactions are defined as those reactions that have only positive
 * or only negative values
 */
void defineExchangeReactions(int *cols, char** exchange_reaction, double
        threshold, char* filename)
{
    double n_thres = -1 * threshold;
    FILE *rx_file = fopen(filename, "r");
    if (!rx_file)
    {
        quitError("Error in opening file\n", ERROR_FILE);
    }
    int rx_count = getRxCount(rx_file);
    fclose(rx_file);
    char* line = NULL;
    size_t len = 0;
    unsigned long bitarray_size = getBitsize(rx_count);
    char* m_exchange_reaction = calloc(1, bitarray_size);
    char* m_pos = calloc(1, bitarray_size);
    char* m_neg = calloc(1, bitarray_size);
    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) 
        {
            double val = atof(ptr);
            // positive value
            if (val > threshold)
            {
                BITSET(m_pos, i);
            }
            // negative value
            else if (val < n_thres)
            {
                BITSET(m_neg,i);
            }
            i++;
            ptr = strtok(NULL, "\n\t ");
        }
    }
    free(line);
    line = NULL;
    fclose(file);
    int i;
    for (i = 0; i < rx_count; i++) {
        // check if reaction have positive and negative values
        if ( (BITTEST(m_pos,i) && !BITTEST(m_neg,i)) || (!BITTEST(m_pos,i) && BITTEST(m_neg,i)) )
        {
            BITSET(m_exchange_reaction, i);
        }
    }
    free(m_pos);
    free(m_neg);
    *cols = rx_count;
    *exchange_reaction = m_exchange_reaction;
}
Ejemplo n.º 4
0
/*
 * stores an EFM into a bitset if it is not an internal loop
 * every reaction is mapped to two bits
 * first bit is if reaction has a positive flux
 * second bit is set if reaction has a negative flux
 * none is set if reaction has no flux
 */
int loadEfm (char* matrix, char* line, char* reversible_reactions, char*
        rxs_fwd, char* rxs_rev, int rx_count, char* exchange_reaction, int
        checkLoops, double threshold)
{
    double n_thres = -1 * threshold;
    char *ptr;
    ptr = strtok(line, "\n\t ");
    int i = 0;
    int j = 0;
    while(ptr != NULL) 
    {
        double x = atof(ptr);
        if (checkLoops > 0 && BITTEST(exchange_reaction, i))
        {
            // check if EFM is an internal loop
            if (x >= threshold || x <= n_thres)
            {
                checkLoops = 0;
            }
        }
        if (BITTEST(reversible_reactions,i))
        {
            // positive flux
            if (x >= threshold)
            {
                BITSET(matrix, 2*j);
                BITSET(rxs_fwd,j);
            }
            // negative flux
            else if (x <= n_thres)
            {
                BITSET(matrix, (2*j)+1);
                BITSET(rxs_rev, j);
            }
            j++;
        }
        i++;
        ptr = strtok(NULL, "\n\t ");
    }
    if (checkLoops > 0)
    {
        // EFM is a loop - free memory
        free(matrix);
        matrix=NULL;
        return(0);
    }
    else
    {
        return(1);
    }
}
Ejemplo n.º 5
0
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;
}
Ejemplo n.º 6
0
unsigned int skiroc2_slow_control_get(const item_t * item) {
    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;

    unsigned int value = 0;
    for (i = 0; i < item->nbits; ++i) {
        if (BITTEST(bitarray, offset+i)) {
            value |= (1<<i);
        }
    }

#ifdef REVERSE_BIT_ORDER
    int value2 = 0;
    for (i = 0; i < item->nbits; ++i) {
        value2 <<= 1;
        value2 |= (value & 1);
        value >>= 1;
    }
    value = value2;
#endif

    return value;
}
Ejemplo n.º 7
0
static BOOL SerialConsole_PutChar(SIOPCB * cb, INT chr, BOOL rasint)
{
	char	buffer[2];
	int		textlength;
	HANDLE	console;

	assert(cb != NULL);
	assert(BITTEST(cb->Flag, SIO_TYP_CONSOLE));
	assert(cb->Handle != NULL);

	console = GetDlgItem(cb->Handle, IDC_CONSOLE);
	buffer[0] = (char) chr;
	buffer[1] = '\x0';

	textlength = GetWindowTextLength(console);
	if(textlength > BUFSZ_UPPERBOUND)
	{
			/* 古い情報を消す */
		SendMessage(console,EM_SETSEL,0,textlength - BUFSZ_LOWERBOUND);
		SendMessage(console,EM_REPLACESEL,(WPARAM)FALSE,(LPARAM)"");
		textlength = GetWindowTextLength(console);
	}
		/* 末尾に文字を置く */
	SendMessage(console,EM_SETSEL,textlength,textlength);
	SendMessage(console,EM_REPLACESEL,(WPARAM)FALSE,(LPARAM)buffer);

	if(rasint == TRUE)
	{
		BITSET(cb->Flag, SIO_STA_INTSND);
		HALInterruptRequest(INHNO_SERIAL);
	}

	return TRUE;
}
Ejemplo n.º 8
0
tri_val_t finish_do_drink(obj_t *otmp, Boolean nothing, Boolean unkn)
{
  Boolean go_on = false;
  if (!otmp) return NO_OP; // bug if that happens
  if (nothing) {
    unkn = true;
    message("You have a peculiar feeling for a moment, then it passes.");
  }
  if ((otmp->bitflags & O_IS_DESCKNOWN) &&
      !BITTEST(oc_name_known, otmp->otype)) {
    if (!unkn) {
      BITSET(oc_name_known, otmp->otype);//objects[otmp->otyp].oc_name_known=1;
      more_experienced(0,10);
    } else if (!oc_has_uname(otmp->otype)) {
      // here's what I'll do instead of do_call/docall(otmp) :
      show_all_messages();
      clone_for_call(otmp); // so we don't have to worry about useup!
      FrmPopupForm(EngraveForm);
      go_on = true;
    }
  }
  useup(otmp);
  if (go_on) return GO_ON;
  else       return DONE;
}
Ejemplo n.º 9
0
/*
 *  コンソールポートへの強制一文字出力 (割込みなし)
 */
void SerialRawPutc(INT chr)
{
	SIOPCB * siopcb = &siopcb_table[CONSOLE_PORTID - 1];

	assert(siopcb != NULL);

	if(!BITTEST(siopcb->Flag, SIO_STA_OPEN))
		return;

	switch(SIO_TYP(siopcb->Flag))
	{
	case SIO_TYP_CONSOLE:
		SerialConsole_PutChar(siopcb, chr, FALSE);
		break;
	case SIO_TYP_TTY:
		WinConsole_PutChar(siopcb, chr, FALSE);
		break;
	case SIO_TYP_SCRBUF:
		ScreenBuffer_PutChar(siopcb, chr, FALSE);
		break;
	case SIO_TYP_RAWSIO:
		RawSerial_PutChar(siopcb, chr, FALSE);
		break;
	}
}
Ejemplo n.º 10
0
void *sieve(void *k)
{
    int ret = 0;
    int tid = (int)k;

    for (long i = 2; i < ceil(sqrt(MAX)); ++i) {
        // Mark all multiples of the number
        if (!BITTEST(bitarray, i)) {
            // Make sure the number we are using is not divisible by
            // any other number currently being processed.
            for (int v = 0; v < NUM_THREADS; ++v) {
                if((i % working[v]) == 0) continue;
            }

            working[tid] = i;

            for(long j = i + i; 0 < j && j < MAX; j += i) {
                ret = pthread_mutex_lock(&mutexes[BITSLOT(j)]);
                if (ret != 0) errExit("pthread_mutex_lock");

                BITSET(bitarray, j);

                ret = pthread_mutex_unlock(&mutexes[BITSLOT(j)]);
                if (ret != 0) errExit("pthread_mutex_lock");
            }
        }
    }

    return NULL;
}
Ejemplo n.º 11
0
Bool	keytests::KeyHeld3d(KeyVal3D keyval)
{
KeyMap3d*
		keymap=(KeyMap3d*) reftable3d.flat;
		if (BITRESET((keymap->bitflags),keyval+1))
			return(TRUE);
		return	(BITTEST((keymap->bitflags),keyval));
}
Ejemplo n.º 12
0
static void WinConsole_ClosePort(SIOPCB * cb)
{
	assert(cb != NULL);
	assert(BITTEST(cb->Flag, SIO_TYP_TTY));

	if(cb->Handle != NULL && cb->Handle != 0)
	{
		FreeConsole();
		cb->Handle = NULL;
	}
}
Ejemplo n.º 13
0
/*
 * print a bit vector for debugging
 */
void printBitset (char* bs, unsigned int len)
{
    unsigned int i;
    for (i = 0; i < len; i++) {
        if (BITTEST(bs, i))
        {
            printf("%d ", i);
        }
    }
    printf("\n");
}
Ejemplo n.º 14
0
static void ScreenBuffer_ClosePort(SIOPCB * cb)
{
	assert(cb != NULL);
	assert(BITTEST(cb->Flag, SIO_TYP_SCRBUF));

	if(cb->Handle != NULL && cb->Handle != 0)
	{
		CloseHandle(cb->Handle);
		cb->Handle = NULL;
	}
}
Ejemplo n.º 15
0
static void RawSerial_ClosePort(SIOPCB * cb)
{
	assert(cb != NULL);
	assert(BITTEST(cb->Flag, SIO_TYP_RAWSIO));

	if(cb->Handle != NULL && cb->Handle != 0)
	{
		CloseHandle(cb->Handle);
		cb->Handle = NULL;
	}
}
Ejemplo n.º 16
0
/*
 * calculate the cardinality of a LTCS
 */
unsigned long getLtcsCardinality(char* ltcs, unsigned long efm_count)
{
    unsigned long res = 0;
    unsigned long li;
    for (li = 0; li < efm_count; li++) {
        if (BITTEST(ltcs, li))
        {
            res++;
        }
    }
    return(res);
}
Ejemplo n.º 17
0
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;
}
Ejemplo n.º 18
0
/*
 * return number of reversible reactions
 */
unsigned int getReversibleReactionCount (char* reversible_reactions, unsigned int rx_count)
{
    unsigned int rev_rx_count = 0;
    unsigned int i;
    for (i = 0; i < rx_count; i++) 
    {
        if (BITTEST(reversible_reactions, i))
        {
            rev_rx_count++;
        }
    }
    return rev_rx_count;
}
Ejemplo n.º 19
0
/*
 * clean matrix
 * keep only those reactions that have a positive and a negative flux in any of
 * the EFMs
 */
void getCleanedMatrix(char **initial_mat, unsigned long efms, unsigned int
        init_rx_count, char ***cleaned_mat, char *rxs_both, unsigned int
        result_rx_count, char* loops) {
    unsigned int i;
    unsigned int j;
    unsigned long ul;
    char **m_cleaned_mat = calloc(efms, sizeof(char*));
    unsigned long bitarray_size = getBitsize(2 * result_rx_count);
    for (ul = 0; ul < efms; ul++) 
    {
        if (!BITTEST(loops, ul))
        {
            m_cleaned_mat[ul] = calloc(1, bitarray_size);
            if (NULL == m_cleaned_mat[ul])
            {
                quitError("Not enough free memory in getCleanedMatrix\n", ERROR_RAM);
            }
            j = 0;
            for (i = 0; i < init_rx_count; i++) 
            {
                if (BITTEST(rxs_both,i))
                {
                    if (BITTEST(initial_mat[ul], 2*i))
                    {
                        BITSET(m_cleaned_mat[ul], j);
                    }
                    j++;
                    if (BITTEST(initial_mat[ul], 2*i+1))
                    {
                        BITSET(m_cleaned_mat[ul], j);
                    }
                    j++;
                }
            }
        }
    }
    *cleaned_mat = m_cleaned_mat;
}
Ejemplo n.º 20
0
int smack_cipso_apply(struct smack_cipso *cipso)
{
    struct cipso_mapping *m = NULL;
    char buf[CIPSO_MAX_SIZE];
    int fd;
    int i;
    int offset;
    int use_long;

    if (init_smackfs_mnt())
        return -1;

    fd = open_smackfs_file("cipso2", "cipso", O_WRONLY, &use_long);
    if (fd < 0)
        return -1;

    if (!use_long && cipso->has_long)
        return -1;

    memset(buf,0,CIPSO_MAX_SIZE);
    for (m = cipso->first; m != NULL; m = m->next) {
        offset = (int)snprintf(buf, SMACK_LABEL_LEN + 1,
                               use_long ? "%s " : "%-23s ", m->label);

        sprintf(&buf[offset], CIPSO_NUM_LEN_STR, m->level);
        offset += NUM_LEN;

        sprintf(&buf[offset], CIPSO_NUM_LEN_STR, m->ncats);
        offset += NUM_LEN;

        for (i = 0; i < CAT_MAX_COUNT; i++) {
            if (BITTEST(m->cats, i)) {
                sprintf(&buf[offset], CIPSO_NUM_LEN_STR, i + 1);
                offset += NUM_LEN;
            }
        }

        if (write(fd, buf, offset) < 0) {
            close(fd);
            return -1;
        }
    }

    close(fd);
    return 0;
}
Ejemplo n.º 21
0
Archivo: node.c Proyecto: the-mrd/culzw
struct node* Node_getchild(struct node* parent, unsigned char l) {

    assert(parent);

    if (!BITTEST(parent -> bitarray, l))		//child not present
        return NULL;

    int x = Bit_count_set_bits_up_to(parent -> bitarray, sizeof(parent -> bitarray), l);
    struct node* target = parent -> child[x];

    if (!target) {
        Node_print(parent);
        printf("Did not find label [%x]\n", l);
        assert(target);				//cause assert(NULL)
    }

    return target;
}
Ejemplo n.º 22
0
// also used for scrolls.
Boolean strange_feeling(obj_t *obj, Char *txt)
{
  Boolean engrave = false;
  if (flags.beginner)
    message("You have a strange feeling for a moment, then it passes.");
  else
    message(txt);
  if (!BITTEST(oc_name_known, obj->otype) &&
      !oc_has_uname(obj->otype)) {
    // here's what I'll do instead of do_call/docall(obj) :
    show_all_messages();
    clone_for_call(obj); // so we don't have to worry about useup!
    FrmPopupForm(EngraveForm);
    engrave = true;
  }
  useup(obj);
  return engrave;
}
Ejemplo n.º 23
0
BOOL wbSysDlgOpen(PWBOBJ pwboParent, LPCTSTR pszTitle, LPCTSTR pszFilter, LPCTSTR pszPath, LPTSTR pszFileName, DWORD dwWBStyle)
{
	OPENFILENAME ofn;
	BOOL bRet;
	TCHAR *pszCopy;

	if(pszPath && *pszPath)
		pszCopy = MakeWinPath(_wcsdup(pszPath));
	else
		pszCopy = NULL;

	ofn.lStructSize = sizeof(OPENFILENAME);
	ofn.hwndOwner = pwboParent ? (HWND)pwboParent->hwnd : NULL;
	ofn.hInstance = NULL;
	ofn.lpstrFilter = pszFilter && *pszFilter ? pszFilter : TEXT("All files (*.*)\0*.*\0\0");
	ofn.lpstrCustomFilter = NULL;
	ofn.nMaxCustFilter = 0;
	ofn.nFilterIndex = 0;
	ofn.lpstrFile = pszFileName;
	ofn.nMaxFile = MAX_PATH;
	ofn.lpstrFileTitle = NULL;
	ofn.nMaxFileTitle = MAX_PATH;
	ofn.lpstrInitialDir = pszCopy;
	ofn.lpstrTitle = (pszTitle && * pszTitle) ? pszTitle : NULL;
	ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;
	ofn.nFileOffset = 0;
	ofn.nFileExtension = 0;
	ofn.lpstrDefExt = NULL;
	ofn.lCustData = 0;
	ofn.lpfnHook = NULL;
	ofn.lpTemplateName = NULL;

	ofn.Flags |= BITTEST(dwWBStyle, WBC_MULTISELECT) ? OFN_ALLOWMULTISELECT | OFN_EXPLORER : 0;

	bRet = GetOpenFileName(&ofn);
	if(!bRet && pszFileName)
		*pszFileName = '\0';

	if(pszCopy)
		free(pszCopy);
	return bRet;
}
Ejemplo n.º 24
0
BOOL wbGetTreeViewItemState(PWBOBJ pwbo, HTREEITEM hItem)
{
	TV_ITEM tvi;

	if(!pwbo || !pwbo->hwnd || !IsWindow(pwbo->hwnd))
		return FALSE;

	if(!hItem)
		return FALSE;

	// Get item data

	tvi.hItem = hItem;
	tvi.mask = TVIF_HANDLE | TVIF_STATE;
//	tvi.state = TVIS_EXPANDED;
	tvi.stateMask = TVIS_EXPANDED;

	TreeView_GetItem(pwbo->hwnd, &tvi);
	return BITTEST(tvi.state, TVIS_EXPANDED);
}
Ejemplo n.º 25
0
/**
 * find subsets of LTCS and set memory of those LTCS free
 */
void filterLtcs(char** ltcs, char** notAnLtcs, unsigned long ltcs_count,
        unsigned long efm_count)
{
    unsigned long bitarray_size = getBitsize(ltcs_count);
    char* m_notAnLtcs = calloc(1, bitarray_size);
    unsigned long li, lj, lk;
    for (li = 0; li < (ltcs_count - 1); li++) {
        if (!BITTEST(m_notAnLtcs, li))
        {
            for (lj = (li+1); lj < ltcs_count; lj++) {
                if (!BITTEST(m_notAnLtcs, lj))
                {
                    int a = 0;
                    int b = 0;
                    for (lk = 0; lk < efm_count; lk++) {
                        if (BITTEST(ltcs[li],lk) && !BITTEST(ltcs[lj],lk))
                        {
                            a = 1;
                        }
                        else if (!BITTEST(ltcs[li],lk) && BITTEST(ltcs[lj],lk))
                        {
                            b = 1;
                        }
                        if (a > 0 && b > 0)
                        {
                            lk = efm_count;
                        }
                    }
                    // ltcs 2 is a subset of ltcs 1
                    if (a > 0 && b == 0)
                    {
                        BITSET(m_notAnLtcs, lj);
                        free(ltcs[lj]);
                    }
                    // ltcs 1 is a subset of ltcs 2
                    else if (a == 0 && b > 0)
                    {
                        BITSET(m_notAnLtcs, li);
                        free(ltcs[li]);
                        lj = ltcs_count;
                    }
                }
            }
        }
    }
    *notAnLtcs = m_notAnLtcs;
}
Ejemplo n.º 26
0
int
main(int argc, char **argv)
{
    char bitarray[BITSLOTS(MAX)];
    int index = 0;

    memset(bitarray, 0, BITSLOTS(MAX));

    for(index = 1; index <= MAX; index += 10) {
        BITSET(bitarray, index);
    }

    for(index = 1; index <= MAX; index++) {
        if(BITTEST(bitarray, index))
            printf("%d", 1);
        else
            printf("%d", 0);

        if(index % 10 == 0)
            printf("\n");
    }
    return 0;
}
Ejemplo n.º 27
0
static BOOL RawSerial_PutChar(SIOPCB * cb, INT chr, BOOL rasint)
{
	BOOL  result;
	DWORD written;
	char  word;

	assert(cb != NULL);
	assert(BITTEST(cb->Flag, SIO_TYP_RAWSIO));
	assert(cb->Handle != NULL && cb->Handle != 0);

		/* 標準出力に一文字送信 */
	word   = (char)chr;
	result = WriteFile(cb->Handle, &word, 1, &written, NULL);

		/* 割込み発生フラグが立っていたら、送信完了割込み要求を起こす */
	if(result != 0 && rasint == TRUE)
	{
		BITSET(cb->Flag, SIO_STA_INTSND);
		HALInterruptRequest(INHNO_SERIAL);
	}

	return result != 0 ? TRUE : FALSE;
}
Ejemplo n.º 28
0
Archivo: apply.c Proyecto: JSefara/foma
int apply_at_last_arc(struct apply_handle *h) {
    int seeksym, nextsym;
    if (h->state_has_index) {
	if (h->iptr->next == NULL || h->iptr->next->fsmptr == -1) {
	    return 1;
	}
    } else {
	if  ((h->binsearch && !(h->has_flags)) || (h->binsearch && !(BITTEST(h->flagstates, (h->gstates+h->ptr)->state_no)))) {
	    if ((h->gstates+h->ptr)->state_no != (h->gstates+h->ptr+1)->state_no) {
		return 1;
	    }
	    seeksym = (h->sigmatch_array+h->ipos)->signumber;
	    nextsym  = (((h->mode) & DOWN) == DOWN) ? (h->gstates+h->ptr)->in  : (h->gstates+h->ptr)->out;
	    if (nextsym == -1 || seeksym < nextsym) {
		return 1;
	    }
	} else {
	    if ((h->gstates+h->ptr)->state_no != (h->gstates+h->ptr+1)->state_no) {
		return 1;
	    }
	}
    }
    return 0;
}
Ejemplo n.º 29
0
void *find_prime(void *arg)
{
    int prime_count = 0;
    uint32_t i, j;
    int s;
    //memset(bitarray, 0, BITNSLOTS(MAX));
    memset(bitarray, 0, sizeof(bitarray));

    for (i = 2; i < MAX; i++){
        if (!BITTEST(bitarray, i)){
            s = pthread_mutex_lock(&mtx);
            if (s != 0)
                perror("pthread_mute_lock");
            prime_count++;
            s = pthread_mutex_unlock(&mtx);
            for (j = i + i; j < MAX; j += i)
                BITSET(bitarray, j);
        }

    }
    printf("%d \n", prime_count);
    return 0;

}
Ejemplo n.º 30
0
BOOL wbDrawText(HANDLE handle, LPCTSTR pszString, int xPos, int yPos, int nWidth, int nHeight, int nFont, DWORD dwFlags)
{
	int nLen;
	BOOL bRet;
	COLORREF clOld;
	HFONT hfOld;
	RECT rc;
	PFONT pfont;
	DWORD dwWinFlags;

	if(!pszString || !*pszString)
		return FALSE;

	pfont = wbGetFont(nFont);
	if(!pfont)
		return FALSE;

	if(!DrawStart(handle))
		return FALSE;

	clOld = SetTextColor(hdcMain, pfont->color);
	SetBkMode(hdcMain, TRANSPARENT);
	hfOld = SelectObject(hdcMain, pfont->hFont);
	nLen = wcslen(pszString);

	if(nWidth > 0 && nHeight > 0) {
		rc.left = xPos;
		rc.right = xPos + nWidth;
		rc.top = yPos;
		rc.bottom = yPos + nHeight;

		// Text flags

		if(dwFlags == 0) {												// No flags: default font

			dwWinFlags = DT_LEFT | DT_SINGLELINE | DT_VCENTER;

		} else if(BITTEST(dwFlags, WBC_MULTILINE)) {					// Multi-line

			dwWinFlags = DT_EDITCONTROL | DT_WORDBREAK;

		} else if(BITTEST(dwFlags, WBC_TOP)) {							// Top

			if(BITTEST(dwFlags, WBC_CENTER))
				dwWinFlags = DT_CENTER | DT_SINGLELINE | DT_TOP;
			else if(BITTEST(dwFlags, WBC_RIGHT))
				dwWinFlags = DT_RIGHT | DT_SINGLELINE | DT_TOP;
			else // WBC_LEFT == 0
				dwWinFlags = DT_LEFT | DT_SINGLELINE | DT_TOP;

		} else if(BITTEST(dwFlags, WBC_BOTTOM)) {						// Bottom

			if(BITTEST(dwFlags, WBC_CENTER))
				dwWinFlags = DT_CENTER | DT_SINGLELINE | DT_BOTTOM;
			else if(BITTEST(dwFlags, WBC_RIGHT))
				dwWinFlags = DT_RIGHT | DT_SINGLELINE | DT_BOTTOM;
			else // WBC_LEFT == 0
				dwWinFlags = DT_LEFT | DT_SINGLELINE | DT_BOTTOM;

		} else {														// Middle (WBC_MIDDLE == 0)

			if(BITTEST(dwFlags, WBC_CENTER))
				dwWinFlags = DT_CENTER | DT_SINGLELINE | DT_VCENTER;
			else if(BITTEST(dwFlags, WBC_RIGHT))
				dwWinFlags = DT_RIGHT | DT_SINGLELINE | DT_VCENTER;
			else // WBC_LEFT == 0
				dwWinFlags = DT_LEFT | DT_SINGLELINE | DT_VCENTER;
		}

		if(BITTEST(dwFlags, WBC_ELLIPSIS))
			dwWinFlags |= DT_END_ELLIPSIS | DT_PATH_ELLIPSIS;

		bRet = DrawTextEx(hdcMain, (LPTSTR)pszString, nLen, &rc, dwWinFlags, NULL);
	} else {
		bRet = TextOut(hdcMain, xPos, yPos, (LPTSTR)pszString, nLen);
	}

	SelectObject(hdcMain, hfOld);
	SetBkMode(hdcMain, OPAQUE);
	SetTextColor(hdcMain, clOld);

	if(!DrawEnd(handle))
		return FALSE;

	return bRet;
}