Пример #1
0
/**
 * @brief sets up the timer
 * 
 * void
 * @return void 
 * 
 */
void setupclk(void)
{
	/** disable the interrupt before config */
	BITOFF(TIMSK2,OCIE2A); 

	/** set to normal operation */
	BITOFF(TCCR2A,COM2A1);
	BITOFF(TCCR2A,COM2A0);

	/** set the operation mode to CTC */
	BITON(TCCR2A,WGM21);
	BITOFF(TCCR2A,WGM20);

	/** make sure we use the internal clock */
	BITOFF(ASSR,AS2);

	/** setup prescaler to 8*/
	SETPORT(TCCR2B,0x0F,CS21);

	/** set output compare */
	SETPORT(OCR2A,0xFF,100);

	/** set counter */
	SETPORT(TCNT2,0xff,0);

	/** enable interrupt */
	BITON(TIMSK2,OCIE2A);
}
Пример #2
0
	void
plot_full_sets (

bitmap_t *		fset_mask,	/* IN - subset of full-sets to plot */
struct cinfo *		cip,		/* IN - compatibility info */
enum plot_size		plot_size	/* IN - size of plot to produce */
)
{
int			i;
int			n;
struct full_set *	fsp;
int *			vp1;
int *			vp2;
char			title [256];
char			buf1 [32];

	n = cip -> num_edges;

	if ((cip -> pts NE NULL) AND (cip -> full_trees NE NULL)) {
		/* Draw the FSTs with postscript. */
		for (i = 0; i < n; i++) {
			if (NOT BITON (fset_mask, i)) continue;
			fsp = cip -> full_trees [i];
			begin_plot (plot_size);
			(void) printf ("\tPlot_Terminals\n");
			fst_comment (fsp);
			draw_fst (fsp, cip);
			dist_to_string (buf1,
					cip -> cost [i],
					&(cip -> scale));
			(void) sprintf (title, "FST %lu,  Length = %s",
					(int32u) i, buf1);
			end_plot (title);
		}
		page_break ();
	}
	else {
		/* Just print the hyperedges */
		for (i = 0; i < n; i++) {
			if (NOT BITON (fset_mask, i)) continue;
			printf ("Edge %d: ", i);
			vp1 = cip -> edge [i];
			vp2 = cip -> edge [i + 1];
			while (vp1 < vp2) {
				printf ("%d ", *vp1++);
			}
			dist_to_string (buf1,
					cip -> cost [i],
					&(cip -> scale));
			printf ("%s\n", buf1);
		}
	}
}
Пример #3
0
static void
state_clear_bits(long * l, int h, int w, int n_bytes, int height){
  int i;
  for(i = 0 ; i < n_bytes ; i++){ l[i + h * n_bytes] = 0; }
  for(i = 0 ; i < height  ; i++){ BITOFF(l, i, w, n_bytes); }
  BITON(l, h, w, n_bytes);
}
Пример #4
0
/* ETDADL: Check compatibility between ETD and ADL.
*/
VOID etdadl(struct etd *p)    /* Pointer to element type definition. */
{
     parmno = 0;
     /* Minimizable element cannot have required attribute. */
     if (GET(p->etdmin, SMO) && GET(p->adl[0].adflags, ADLREQ)) {
          mderr(40, (UNCH *)0, (UNCH *)0);
          RESET(p->etdmin, SMO);
     }
     /* Empty element cannot have NOTATION attribute.
        Attribute is not removed (too much trouble), but we trap
        attempts to specify it on the start-tag in adlval().
     */
     if (GET(p->etdmod->ttype, MNONE)) {
          if (GET(p->adl[0].adflags, ADLNOTE))
               mderr(83, (UNCH *)0, (UNCH *)0);

          /* Empty element cannot have CONREF attribute.
             Attribute is not removed because it just acts
             like IMPLIED anyway.
          */
          if (GET(p->adl[0].adflags, ADLCONR))
               mderr(85, (UNCH *)0, (UNCH *)0);
     }
     /* "-" should not be specified for the end-tag minimization if
	the element has a content reference attribute. */
     if (GET(p->adl[0].adflags, ADLCONR) && BITON(p->etdmin, EMM))
	  mderr(153, (UNCH *)0, (UNCH *)0);
}
Пример #5
0
VOID fixdatt(struct dcncb *p)
{
     int i;
     for (i = 0; i < ENTHASH; i++) {
	  struct entity *ep;
	  for (ep = etab[i]; ep; ep = ep->enext)
	       if (ep->estore == ESN && ep->etx.n && ep->etx.n->nedcn == p) {
		    int adn;
		    initatt(p->adl);
		    /* Don't use adlval because if there were required
		       attributes the error message wouldn't say what
		       entity was involved. */
		    for (adn = 1; adn <= ADN(al); adn++) {
			 if (GET(ADFLAGS(al,adn), AREQ)) {
			      sgmlerr(218, &pcbstag, ADNAME(al,adn),
				      ep->ename + 1);
			      SET(ADFLAGS(al,adn), AINVALID);
			 }
			 if (BITON(ADFLAGS(al, adn), AGROUP))
			      adn += ADNUM(al, adn);
		    }
		    storedatt(ep->etx.n);
	       }
     }
}
Пример #6
0
/* TOKENOPT: Return 1 if current token is contextually optional;
             otherwise, return 0.
*/
int tokenopt(struct thdr mod[],            /* Model of current open element. */
				 struct mpos pos[])            /* Position in open element's model. */
{
	  TRACEEND("TOKENOPT", mod, pos, 0, 0, Tstart);
     return (BITON(TOCC, TOPT) /* Inherently optional. */
	     || TOKENHIT      /* Was hit (handles "plus" suffix case). */
		  || (!ANYHIT(H) && groupopt(mod, pos)));
			      /* In optional group with no hits. */
}
Пример #7
0
static pascal void BlockMoveData_masktrans(const uint8*	srcPtr,	 uint8 *destPtr,
			Size 	byteCount, int trans, int maskx, const uint8 maskdata[])
{
#define  BITON(x, data) (data[(x)/8]&(0x80>>((x)%8)))
	int i;

	if( srcPtr>destPtr ){
		for( i=0; i<byteCount; i++){
			if(  srcPtr[i]!=trans  && BITON(i%maskx, maskdata)  ){
				PMASK_COPY(srcPtr[i],destPtr[i], gmode_mask);
			}
		}
	}else{
		for( i=byteCount-1; i>=0; i--){
			if( BITON(i%maskx, maskdata)  ){
				PMASK_COPY(srcPtr[i],destPtr[i], gmode_mask);
			}
		}
	}
}
Пример #8
0
static void
state_setup_block(struct State * state)
{
  int i, j;
  for(i = 0 ; i < state->height ; i++){
    for(j = 0 ; j < state->width ; j++){
      if (rb_yield_values(2, INT2FIX(i), INT2FIX(j))){
	BITON(state->mat, i, j, state->n_bytes);
      }
    }
  }
}
Пример #9
0
static void
state_setup(struct State * state, struct Query * query, struct Target * target)
{
  int i, j;
  for(i = 0 ; i < query->len ; i++){
    for(j = 0 ; j < target->n_bits ; j++){
      if (query->type[i] == target->typ[j]){
	BITON(state->mat, i, j, target->n_bytes);
      }
    }
  }
}
Пример #10
0
/* GROUPOPT: Temporarily makes the current group be the current token so that
             TOKENOPT() can be applied to it.  Returns the value returned
             by TOKENOPT.
*/
int groupopt(struct thdr mod[],            /* Model of current open element. */
				 struct mpos pos[])            /* Position in open element's model. */
{
     UNCH saveM;              /* Save M when testing if group is not required.*/
     int rc;                  /* 1=contextually optional; 0=not. */

     if (P==1) return(BITON(GOCC, TOPT) || TOKENHIT);
     saveM = M; M = G; --P;
     rc = tokenopt(mod, pos);
     ++P; G = M; M = saveM;
     return(rc);
}
Пример #11
0
VOID adlfree(struct ad *al, int aln)
{
     for (; aln <= ADN(al); aln++) {
		 frem((UNIV)al[aln].adname);
		 if (ADVAL(al, aln))
	       frem((UNIV)ADVAL(al, aln));
		 if (BITON(ADFLAGS(al, aln), AGROUP)) {
	       int i;
	       for (i = 0; i < ADNUM(al, aln); i++)
		    frem((UNIV)al[aln + i + 1].adname);
	       aln += ADNUM(al, aln);
	    }
     }
}
Пример #12
0
/* ECONTEXT: Determine whether the current element can be ended, or whether
             non-optional tokens remain at the current level or higher.
             Returns 1 if element can be ended, or 0 if tokens remain.
             On entry, STATUS==RCEND if there are no tokens left; if not,
             pos points to the next model token to be tested.
             TO DO: Support a "query" mode (what is required now?) by working
                    with a copy of pos.
*/
int econtext(struct thdr mod[],            /* Model of current open element. */
				 struct mpos pos[],            /* Position in open element's model. */
				 UNCH *statuspt)               /* Token status: RCHIT RCMISS RCEND RCREQ RCNREQ*/
{
     unsigned next;           /* Position in AND group of next testable token.*/

     Tstart = T;
     TRACEEND("ECONT", mod, pos, 0, 0, Tstart);
     if (P<=1) {nextetd = 0; return(TOKENHIT || BITON(TOCC, TOPT));}
     nextetd = TTYPE == TTETD ? TOKEN.tu.thetd : 0;
     while (STATUS!=RCMISS && STATUS!=RCEND) {
          STATUS = (UNCH)testend(mod, pos, 0, 0);
          TRACEEND("ECONTEND", mod, pos, 0, 0, Tstart);
          nextetd = P<=1 || TTYPE != TTETD ? 0 : TOKEN.tu.thetd;
          if (STATUS==RCEND)       return(1);
          if (P<=1)                return(TOKENHIT || BITON(TOCC, TOPT));
          if (STATUS==RCMISS) {
               if (BITON(TOCC, TOPT)) nextetd = 0;
               return(0);
          }
          if (!tokenopt(mod, pos)) return(0);

          STATUS = RCNREQ;
          if (GTYPE!=TTAND) ++T;   /* T!=GNUM or group would have ended. */
          else T = (UNCH)(((next = (UNS)offbit(H, (int)T, GNUM))!=0) ?
               next : offbit(H, 0, GNUM));

          M = G + grpsz(&GHDR, (int)T-1) + 1;
          TRACEEND("ECONTNEW", mod, pos, 0, 0, Tstart);
     }
     if (STATUS==RCMISS) {
          if (BITON(TOCC, TOPT)) nextetd = 0;
          return(0);
     }
     return(1);               /* STATUS==RCEND */
}
Пример #13
0
/* CONTEXT: Determine whether a GI is valid in the present structural context.
            Returns RCHIT if valid, RCEND if element has ended, RCREQ if a
            different element is required, and RCMISS if it is totally invalid.
            On entry, pos points to the model token to be tested against the GI.
            TO DO: Save allowed GIs for an error message on an RCMISS.
                   Support a "query" mode (what is allowed now?) by working
                   with a copy of pos.
*/
int context(struct etd *gi,               /* ETD of new GI. */
				struct thdr mod[],            /* Model of current open element. */
				struct mpos pos[],            /* Position in open element's model. */
				UNCH *statuspt,               /* Token status: RCHIT RCMISS RCEND RCREQ RCNREQ*/
				int mexts)                    /* >0=stack level of minus grp; -1=plus; 0=none.*/
{
     UNCH toccsv, gtypesv;    /* Save token's TOCC and GTYPE in case grp ends.*/

     if (mexts == -1) {
	  if (STATUS == RCEND)
	       return RCPEX;
	  copypos(savedpos, pos);
     }
     Tstart = T;              /* Save starting token for AND group testing. */
     while (STATUS!=RCMISS && STATUS!=RCEND) {
          TRACEGI("CONTEXT", gi, mod, pos, Tstart);
          while (TTYPE==TTOR || TTYPE==TTSEQ || TTYPE==TTAND) {
               pos[P+1].g = M++; pos[++P].t = 1; HITCLEAR(H);
               Tstart = T;    /* Save starting token for AND group testing. */
               TRACEGI("OPENGRP", gi, mod, pos, Tstart);
          }
          STATUS = (UNCH)tokenreq(gi, mod, pos);
          TRACEGI("STATUS", gi, mod, pos, Tstart);
          if (gi==TOKEN.tu.thetd) {     /* Hit in model. */
               STATUS = (UNCH)RCHIT;
               gtypesv = GTYPE; toccsv = TOCC;
               newtoken(mod, pos, statuspt);
               return(mexts<=0 ? RCHIT : (gtypesv==TTOR || BITON(toccsv, TOPT))
                                       ?  RCMEX : RCHITMEX);
          }
          if (STATUS==RCREQ) {
				 if (mexts == -1) break;
				 STATUS = RCHIT;
				 nextetd = TOKEN.tu.thetd;
				 newtoken(mod, pos, statuspt);
				 return(RCREQ);
          }
          /* else if (STATUS==RCNREQ) */
			 if (mexts>0) return(RCMEX);
			 newtoken(mod, pos, statuspt);
     }
     if (mexts == -1) {
		  copypos(pos, savedpos);
		  return STATUS = RCPEX;
     }
     return((int)STATUS);
}
Пример #14
0
/*
*   PROTOTYPE    cs_status app_ipintf_pkt_send(cs_pkt_t* pkt, cs_uint32 len)
*   INPUT            pkt
*   OUTPUT         None.
*   Description
*   Pre-condition
*   Post-condition
*   Note : when app_ipintf_arp_egress_filter return code != 0, it means the whole
*            process is finished or error, we should return from here.
*            If return code == 0, we should not return and continue the following code.
*/
cs_status app_ipintf_packet_tx(cs_pkt_t* pkt)
{
    cs_uint16 i = 0;
    cs_uint32 len = pkt->len;
    cs_uint8 *hdr = NULL;
    app_vlan_double_tag_header_t eth_header;

    hdr = pkt->data + pkt->offset;
    if(BITON(hdr[0],0)) {
        vlan_header_parse(hdr, &eth_header);
        if(eth_header.ethertype == EPON_ETHERTYPE_ARP) {
            if(app_ipintf_arp_tx_filter) {
                if(app_ipintf_arp_tx_filter(pkt) == IPINTF_DROP) {
                    APP_IPINTF_LOG(IROS_LOG_LEVEL_DBG3, "%s drop, arp tx filter\n", __func__);
                    return CS_E_ERROR;
                }
            }
         }
        /* flooding packets to all ports */
        APP_IPINTF_LOG(IROS_LOG_LEVEL_DBG3, "BC flooding, len %d\n", len);
        for(i=0;i<ipintf_info.maxport;i++) {
            app_ipintf_send_pkt(PTABLE[i].port,pkt);
        }
    }
    else
    {
        for(i=0; i<IPINTF_MAC_ENTRY_MAX; i++) {
            if(MACTBL[i].used && app_ipintf_macaddr_equal(hdr, MACTBL[i].mac, 6)) {
                /* For known unicast packet, push vlan and pri */
                if(MACTBL[i].vlanid != 0) {
                    push_vlan_ingress(MACTBL[i].vlanid, 0, pkt);
                }
                APP_IPINTF_LOG(IROS_LOG_LEVEL_DBG3, "UC send to %d, len %d\n", MACTBL[i].dpid, pkt->len);
                return app_ipintf_send_pkt(MACTBL[i].dpid, pkt);
            }
        }
        /* unknown unicast : flooding */
        APP_IPINTF_LOG(IROS_LOG_LEVEL_DBG3, "DLF UC flooding , len %d\n", pkt->len);
        for(i=0;i<ipintf_info.maxport;i++) {
            app_ipintf_send_pkt(PTABLE[i].port,pkt);
        }
    }

    return CS_E_OK;

}
Пример #15
0
int main (void) {
    unsigned int u, bitNumber, start, end;

    printf("Enter an integer: ");
    scanf("%ud", &u);
    printf("%u is %s\n", u, (ODD(u) ? "odd" : "even"));

    printf("Enter an integer and a bit number: ");
    scanf("%u %d", &u, &bitNumber);
    printf("%u has bit %d %s\n", u, bitNumber, (BITON(u, bitNumber) ? "on" : "off"));   

    printf("Enter an integer, start and end bit numbers: ");
    scanf("%u %u %u", &u, &start, &end);
    printf("%u has %s those bits on\n", u, (ALLON(u, start, end) ? "all" : "not all"));

    return 0;
}
Пример #16
0
//-----------------------------------------------------------------------------------
int main(void) {

    unsigned int U1,BitNumber,Start,End;

    printf("Enter an integer : ");
    scanf("%ud",&U1);
    printf("%u is %s\n",U1,ODD(U1)?"odd":"even");

    printf("Enter an integer and a bit number : ");
    scanf("%u %d",&U1,&BitNumber);
    printf("%u has bit %d %s\n",U1,BitNumber,BITON(U1,BitNumber)?"on":"off");

    printf("Enter an integer, start and end bit numbers : ");
    scanf("%u %u %u",&U1,&Start,&End);
    printf("%u has %s those bits on\n",U1,ALLON(U1,Start,End)?"all":"not all");

    return(EXIT_SUCCESS);
}
Пример #17
0
// return TRUE if the key is accepted
int hime_im_client_forward_key_press(HIME_client_handle *handle,
                                          KeySym key, u_int state,
                                          char **rstr)
{
  int flag;
  if (!handle)
    return 0;
  // in case client didn't send focus in event
  if (!BITON(handle->flag, FLAG_HIME_client_handle_has_focus)) {
    hime_im_client_focus_in(handle);
    handle->flag |= FLAG_HIME_client_handle_has_focus;
    hime_im_client_set_cursor_location(handle, handle->spot_location.x,
       handle->spot_location.y);
  }

//  dbg("hime_im_client_forward_key_press\n");
  flag = hime_im_client_forward_key_event(
             handle, HIME_req_key_press, key, state, rstr);

  return ((flag & HIME_reply_key_processed) !=0);
}
Пример #18
0
void hime_im_client_set_cursor_location(HIME_client_handle *handle, int x, int y)
{
  if (!handle)
    return;
  if (is_special_user)
    return;

//  dbg("hime_im_client_set_cursor_location %d   %d,%d\n", handle->flag, x, y);

  HIME_req req;
  handle->spot_location.x = x;
  handle->spot_location.y = y;

  if (!BITON(handle->flag, FLAG_HIME_client_handle_has_focus))
    return;

  if (!gen_req(handle, HIME_req_set_cursor_location, &req))
    return;

  if (handle_write(handle, &req, sizeof(req)) <=0) {
    error_proc(handle,"hime_im_client_set_cursor_location error");
  }
}
Пример #19
0
	static
	void
compute_grid_graph (

bitmap_t *	tmap,		/* IN - valid set of terminals */
bitmap_t *	fset_mask,	/* IN - valid FSTs */
struct cinfo *	cip		/* IN - compatibility info */
)
{
int		i;
int		j;
int		k;
int		nverts;
int		nverts2;
int		v1;
int		spi;
int32u *	gridp;
coord_t		coord;
dist_t		prev_coord;
int		prev_index;
struct pset *	tmp;
char		buf1 [128];
char		buf2 [128];

	nverts = cip -> num_verts;

	grid.nt		= nverts;
	grid.ns		= 0;
	grid.x_coord	= NEWA (nverts, coord_t);
	grid.y_coord	= NEWA (nverts, coord_t);
	grid.xindex	= NEWA (nverts, int);
	grid.yindex	= NEWA (nverts, int);

	/* Compute map giving index of each terminal in sequence when	*/
	/* sorted by increasing X coordinate.				*/
	tmp = NEW_PSET (nverts);
	tmp -> n = nverts;
	for (i = 0; i < nverts; i++) {
		tmp -> a [i] = cip -> pts -> a [i];
	}
	sort_x_inc (tmp);
	prev_coord = INF_DISTANCE;
	prev_index = -1;
	for (i = 0; i < nverts; i++) {
		coord = tmp -> a [i].x;
		grid.x_coord [i] = coord;
		j = tmp -> a [i].pnum;
		if (coord NE prev_coord) {
			prev_index = i;
		}
		grid.xindex [j] = prev_index;
		prev_coord = coord;
	}

	/* Compute map giving index of each terminal in sequence when	*/
	/* sorted by increasing Y coordinate.				*/
	tmp -> n = nverts;
	for (i = 0; i < nverts; i++) {
		tmp -> a [i] = cip -> pts -> a [i];
	}
	sort_y_inc (tmp);
	prev_coord = INF_DISTANCE;
	prev_index = -1;
	for (i = 0; i < nverts; i++) {
		coord = tmp -> a [i].y;
		grid.y_coord [i] = tmp -> a [i].y;
		j = tmp -> a [i].pnum;
		if (coord NE prev_coord) {
			prev_index = i;
		}
		grid.yindex [j] = prev_index;
		prev_coord = coord;
	}

	free ((char *) tmp);

	/* Allocate and zero matrix to hold the grid... */
	nverts2 = (nverts + 1) * nverts;
	grid.gridp = NEWA (nverts2, int32u);
	for (i = 0; i < nverts2; i++) {
		grid.gridp [i] = 0;
	}
	grid.gridp += nverts;

	/* Set vertex number for each terminal in the grid... */
	for (i = 0; i < nverts; i++) {
		if (NOT BITON (tmap, i)) {
			/* Should not have any duplicate terminals! */
			fatal ("compute_grid_graph: Bug 1.");
		}
		j = grid.xindex [i];
		k = grid.yindex [i];
		grid.gridp [k * nverts + j] = i + 1;
	}

	draw_full_sets_on_grid (fset_mask, cip);

	identify_steiner_points ();

	/* Count every edge... */
	count_edges = TRUE;
	number_of_edges = 0;
	gridp = grid.gridp;
	for (i = 0; i < nverts; i++) {
		for (j = 0; j < nverts; j++, gridp++) {
			v1 = (*gridp & GMASK);
			if (v1 EQ 0) continue;
			if ((*gridp & RIGHT_EDGE) NE 0) {
				edge_right (gridp, v1, i, j, 0, cip);
			}
			if ((*gridp & UP_EDGE) NE 0) {
				edge_up (gridp, v1, i, j, 0, cip);
			}
			if ((j > 0) AND ((gridp [-1] & RIGHT_EDGE) NE 0)) {
				edge_left (gridp, v1, i, j, 0, cip);
			}
			if ((i > 0) AND ((gridp [-nverts] & UP_EDGE) NE 0)) {
				edge_down (gridp, v1, i, j, 0, cip);
			}
		}
	}

	/* Output total number of vertices, plus number of terminals. */
	if (Print_ORLibrary_Format) {
		printf ("%d %d\n", nverts + grid.ns, number_of_edges);
	}

	if (Print_SteinLib_Format) {
		printf ("33d32945 STP File, STP Format Version 1.00\n"
			"Section Comment\n"
			"Name    \"%s\"\n"
			"Creator \"GeoSteiner\"\n"
			"Remark  \"Reduced graph from FST generator\"\n"
			"End\n\n"
			"Section Graph\n"
			"Nodes %d\n"
			"Edges %d\n",
			cip -> description, nverts + grid.ns, number_of_edges);
	}

	/* Output every edge... */
	count_edges = FALSE;
	gridp = grid.gridp;
	for (i = 0; i < nverts; i++) {
		for (j = 0; j < nverts; j++, gridp++) {
			v1 = (*gridp & GMASK);
			if (v1 EQ 0) continue;
			if ((*gridp & RIGHT_EDGE) NE 0) {
				edge_right (gridp, v1, i, j, 0, cip);
			}
			if ((*gridp & UP_EDGE) NE 0) {
				edge_up (gridp, v1, i, j, 0, cip);
			}
			if ((j > 0) AND ((gridp [-1] & RIGHT_EDGE) NE 0)) {
				edge_left (gridp, v1, i, j, 0, cip);
			}
			if ((i > 0) AND ((gridp [-nverts] & UP_EDGE) NE 0)) {
				edge_down (gridp, v1, i, j, 0, cip);
			}
		}
	}

	/* Write terminals (and coordinates in STP-format) */
	if (Print_ORLibrary_Format) {
		printf ("%d\n", nverts);
		for (i = 0; i < nverts; i++) {
			printf ("%d\n", i+1);
		}
	}

	if (Print_SteinLib_Format) {
		printf ("End\n\n"
			"Section Terminals\n"
			"Terminals %d\n",
			nverts);
		for (i = 0; i < nverts; i++) {
			printf ("T %d\n", i+1);
		}
		printf ("End\n\n"
			"Section Coordinates\n");

		/* Output coordinates of each terminal... */
		for (i = 0; i < nverts; i++) {
			coord_to_string (buf1,
					 cip -> pts -> a [i].x,
					 &(cip -> scale));
			coord_to_string (buf2,
					 cip -> pts -> a [i].y,
					 &(cip -> scale));
			printf ("DD %d %s %s\n", i+1, buf1, buf2);
		}

		/* Output coordinates of each steiner point... */
		spi = nverts+1;
		gridp = grid.gridp;
		for (i = 0; i < nverts; i++) {
			for (j = 0; j < nverts; j++, gridp++) {
				if ((*gridp & GMASK) > nverts) {
					coord_to_string (buf1,
							 grid.x_coord [j],
							 &(cip -> scale));
					coord_to_string (buf2,
							 grid.y_coord [i],
							 &(cip -> scale));
					printf ("DD %d %s %s\n",
						spi, buf1, buf2);
					spi++;
				}
			}
		}
		printf ("End\n\n"
			"EOF\n");
	}


	free ((char *) (grid.gridp - nverts));
	free ((char *) grid.yindex);
	free ((char *) grid.xindex);
	free ((char *) grid.y_coord);
	free ((char *) grid.x_coord);
}
Пример #20
0
	static
	void
build_SEC_flow_formulation (

struct comp *		comp,		/* IN - congested component */
int			t,		/* IN - vertex to force */
struct sec_flow_info *	flowp		/* OUT - SEC flow formulation */
)
{
int			i;
int			j;
int			k;
int			nverts;
int			nedges;
int			nmasks;
int			num_arcs;
int			num_nodes;
int			e;
int			arc_num;
int			num_used_edges;
int			first_edge_node;
int *			used_edges;
bitmap_t *		unused_edge_mask;
struct flow_prob *	prob;
int *			ip1;
int *			ip2;
int *			ep1;
int *			ep2;
int *			vp1;
int *			vp2;
int *			outlist;
int *			inlist;
int *			srcp;
int *			dstp;
double *		capp;
int *			counts;
int **			ptrs;
double			sum;

	nverts	= comp -> num_verts;
	nedges	= comp -> num_edges;

	/* Compute a list of all component edges that	*/
	/* DO NOT contain the vertex "t".		*/
	nmasks		 = BMAP_ELTS (nedges);
	unused_edge_mask = NEWA (nmasks, bitmap_t);
	for (i = 0; i < nmasks; i++) {
		unused_edge_mask [i] = 0;
	}
	num_used_edges = nedges;
	ep1 = comp -> vedges [t];
	ep2 = comp -> vedges [t + 1];
	while (ep1 < ep2) {
		e = *ep1++;
		SETBIT (unused_edge_mask, e);
		--num_used_edges;
	}

	used_edges = NEWA (num_used_edges, int);
	ep1 = used_edges;
	for (i = 0; i < nedges; i++) {
		if (BITON (unused_edge_mask, i)) continue;
		*ep1++ = i;
	}
	free ((char *) unused_edge_mask);

	if (ep1 NE (used_edges + num_used_edges)) {
		/* lost count somewhere? */
		fatal ("build_SEC_flow_formulation: Bug 1.");
	}

	/* Tally up the total number of nodes and arcs needed	*/
	/* for the flow graph.  For the sake of	simplicity, we	*/
	/* include a node for t, but there will	be no arcs	*/
	/* associated with it...				*/

	/* One node per vertex.  One source and one sink	*/
	/* node.  One node per USED edge.			*/
	num_nodes	= nverts + 2 + num_used_edges;

	/* One arc per vertex, one arc per USED edge,		*/
	/* plus one arc for each vertex of every USED edge.	*/
	num_arcs	= nverts + num_used_edges;
	for (i = 0; i < num_used_edges; i++) {
		e = used_edges [i];
		num_arcs += (comp -> everts [e + 1] - comp -> everts [e]);
	}

	/* Start filling in the flow problem instance... */
	prob = &(flowp -> prob);
	prob -> num_nodes	= num_nodes;
	prob -> num_arcs	= num_arcs;

	/* Assign node numbers for the source and sink nodes... */
	prob -> source	= nverts;
	prob -> sink	= nverts + 1;
	first_edge_node	= nverts + 2;

	/* Now that we know how big the directed flow graph is,	*/
	/* allocate storage for the various data structures...	*/

	prob -> out		= NEWA (num_nodes + 1, int *);
	prob -> in		= NEWA (num_nodes + 1, int *);
	prob -> arc_src		= NEWA (num_arcs, int);
	prob -> arc_dst		= NEWA (num_arcs, int);
	prob -> capacity	= NEWA (num_arcs, double);

	outlist			= NEWA (num_arcs, int);
	inlist			= NEWA (num_arcs, int);

	/* Generate the arcs from the source node to each USED edge. */

	srcp = prob -> arc_src;
	dstp = prob -> arc_dst;
	capp = prob -> capacity;
	arc_num	= 0;
	for (i = 0; i < num_used_edges; i++) {
		e = used_edges [i];
		j = first_edge_node + i;
		*srcp++		= prob -> source;
		*dstp++		= j;
		*capp++		= comp -> x [e];
		++arc_num;

		/* Generate the arcs from each edge node to the		*/
		/* corresponding vertex nodes.  These all have weight	*/
		/* 2, which is essentially infinite.			*/
		vp1 = comp -> everts [e];
		vp2 = comp -> everts [e + 1];
		while (vp1 < vp2) {
			k = *vp1++;
			*srcp++		= j;
			*dstp++		= k;
			*capp++		= 2.0;
			++arc_num;
		}
	}

	free ((char *) used_edges);

	/* Now generate one arc from each vertex node to the sink	*/
	/* node.  These all have weight (Bi - 1), where Bi is the	*/
	/* congestion level of vertex i.				*/
	for (i = 0; i < nverts; i++) {
		sum = -1.0;
		ep1 = comp -> vedges [i];
		ep2 = comp -> vedges [i + 1];
		while (ep1 < ep2) {
			e = *ep1++;
			sum += comp -> x [e];
		}
		*srcp++		= i;
		*dstp++		= prob -> sink;
		*capp++		= sum;
		++arc_num;
	}

	if (arc_num NE num_arcs) {
		fatal ("build_SEC_flow_formulation: Bug 2.");
	}

	/* We have now specified the directed flow graph as a	*/
	/* list of directed arcs.  Time to construct the	*/
	/* adjacency lists -- for each node we build a list of	*/
	/* outgoing and incoming arc numbers.  Do the outgoing	*/
	/* lists first...					*/

	counts	= NEWA (num_nodes, int);
	ptrs	= NEWA (num_nodes, int *);

	for (i = 0; i < num_nodes; i++) {
		counts [i] = 0;
	}
	for (i = 0; i < num_arcs; i++) {
		++(counts [prob -> arc_src [i]]);
	}
	ip1 = outlist;
	for (i = 0; i < num_nodes; i++) {
		ptrs [i] = ip1;
		prob -> out [i] = ip1;
		ip1 += counts [i];
	}
	prob -> out [i] = ip1;
	for (i = 0; i < num_arcs; i++) {
		j = prob -> arc_src [i];
		ip1 = ptrs [j]++;
		*ip1 = i;
	}

	/* Now do the incoming arc lists... */
	for (i = 0; i < num_nodes; i++) {
		counts [i] = 0;
	}
	for (i = 0; i < num_arcs; i++) {
		++(counts [prob -> arc_dst [i]]);
	}
	ip1 = inlist;
	for (i = 0; i < num_nodes; i++) {
		ptrs [i] = ip1;
		prob -> in [i] = ip1;
		ip1 += counts [i];
	}
	prob -> in [i] = ip1;
	for (i = 0; i < num_arcs; i++) {
		k = prob -> arc_dst [i];
		ip1 = ptrs [k]++;
		*ip1 = i;
	}

	/* Free temporary memory used to build things... */
	free ((char *) counts);
	free ((char *) ptrs);

	/* Initialize the buffers used to hold flow solutions */
	/* and temporary data... */
	create_flow_solution_data (prob, &(flowp -> soln));
	create_flow_temp_data (prob, &(flowp -> temp));
}
Пример #21
0
static HIME_client_handle *hime_im_client_reopen(HIME_client_handle *hime_ch, Display *dpy)
{
//  dbg("hime_im_client_reopen\n");
  int dbg_msg = getenv("HIME_CONNECT_MSG_ON") != NULL;
  int sockfd=0;
  int servlen;
//  char *addr;
  Server_IP_port srv_ip_port;
#if DEBUG
  u_char *pp;
#endif

  int uid = getuid();
  if (uid > 0 && uid < 500) {
    is_special_user = TRUE;
  }

  int tcp = FALSE;
  HIME_client_handle *handle;
  int rstatus;

//  dbg("hime_im_client_reopen\n");
  if (!dpy) {
    dbg("null disp %d\n", hime_ch->fd);
    goto next;
  }

  Atom hime_addr_atom = get_hime_addr_atom(dpy);
  Window hime_win = None;


#define MAX_TRY 3
  int loop;

  if (!is_special_user)
  for(loop=0; loop < MAX_TRY; loop++) {
    if ((hime_win=find_hime_window(dpy))!=None || getenv("HIME_IM_CLIENT_NO_AUTO_EXEC"))
      break;
    static time_t exec_time;

    if (time(NULL) - exec_time > 1 /* && count < 5 */) {
      time(&exec_time);
      dbg("XGetSelectionOwner: old version of hime or hime is not running ??\n");
      static char execbin[]=HIME_BIN_DIR"/hime";
      dbg("... try to start a new hime server %s\n", execbin);

      int pid;

      if ((pid=fork())==0) {
        setenv("HIME_DAEMON", "", TRUE);
        execl(execbin, "hime", NULL);
      } else {
        int status;
        // hime will daemon()
        waitpid(pid, &status, 0);
      }
    }
  }

  if (loop == MAX_TRY || hime_win == None) {
    goto next;
  }

  Atom actual_type;
  int actual_format;
  u_long nitems,bytes_after;
  char *message_sock = NULL;
  Atom hime_sockpath_atom = get_hime_sockpath_atom(dpy);

//  printf("hime_sockpath_atom %d\n", hime_sockpath_atom);

  if (!hime_sockpath_atom || XGetWindowProperty(dpy, hime_win, hime_sockpath_atom, 0, 64,
     False, AnyPropertyType, &actual_type, &actual_format,
     &nitems,&bytes_after,(u_char **)&message_sock) != Success) {
#if DBG || 1
    dbg("XGetWindowProperty 2: old version of hime or hime is not running ??\n");
#endif
    goto next;
  }

  Server_sock_path srv_sock_path;
  srv_sock_path.sock_path[0] = 0;
  if (message_sock) {
    memcpy(&srv_sock_path, message_sock, sizeof(srv_sock_path));
    XFree(message_sock);
  } else
    goto next;

  struct sockaddr_un serv_addr;
  bzero((char *) &serv_addr,sizeof(serv_addr));
  serv_addr.sun_family = AF_UNIX;
  char sock_path[UNIX_PATH_MAX];

  if (srv_sock_path.sock_path[0]) {
    strcpy(sock_path, srv_sock_path.sock_path);
  }
  else {
    get_hime_im_srv_sock_path(sock_path, sizeof(sock_path));
  }

//  addr = sock_path;
  strcpy(serv_addr.sun_path, sock_path);
#ifdef SUN_LEN
  servlen = SUN_LEN(&serv_addr);
#else
  servlen = strlen(serv_addr.sun_path) + sizeof(serv_addr.sun_family);
#endif

  if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
    perror("cannot open socket");
    goto tcp;
  }

  if (connect(sockfd, (struct sockaddr *)&serv_addr, servlen) < 0) {
    close(sockfd);
    sockfd = 0;
    goto tcp;
  }

  if (dbg_msg)
    dbg("connected to unix socket addr %s\n", sock_path);
  goto next;

  char *message;

tcp:
  message = NULL;

  if (!hime_addr_atom || XGetWindowProperty(dpy, hime_win, hime_addr_atom, 0, 64,
     False, AnyPropertyType, &actual_type, &actual_format,
     &nitems,&bytes_after,(u_char **)&message) != Success) {
#if DBG || 1
    dbg("XGetWindowProperty: old version of hime or hime is not running ??\n");
#endif
    goto next;
  }

  if (message) {
    memcpy(&srv_ip_port, message, sizeof(srv_ip_port));
    XFree(message);
  } else
    goto next;


//  dbg("im server tcp port %d\n", ntohs(srv_ip_port.port));

  struct sockaddr_in in_serv_addr;
  bzero((char *) &in_serv_addr, sizeof(in_serv_addr));

  in_serv_addr.sin_family = AF_INET;
  in_serv_addr.sin_addr.s_addr = srv_ip_port.ip;
  in_serv_addr.sin_port = srv_ip_port.port;
  servlen = sizeof(in_serv_addr);


  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
      perror("cannot open socket");
      goto next;
  }

  dbg("sock %d\n", sockfd);

  if (connect(sockfd, (struct sockaddr *)&in_serv_addr, servlen) < 0) {
    dbg("hime_im_client_open cannot open: ") ;
    perror("");
    close(sockfd);
    sockfd = 0;
    goto next;
  }

#if DEBUG
  pp = (u_char *)&srv_ip_port.ip;
  if (dbg_msg)
    dbg("hime client connected to server %d.%d.%d.%d:%d\n",
        pp[0], pp[1], pp[2], pp[3], ntohs(srv_ip_port.port));
#endif

  tcp = TRUE;

next:
  if (!hime_ch)
    handle = tzmalloc(HIME_client_handle, 1);
  else {
    handle = hime_ch;
  }

  if (sockfd < 0)
    sockfd = 0;

  if (sockfd > 0) {
    handle->fd = sockfd;
    if (tcp) {
      if (!handle->passwd)
        handle->passwd = malloc(sizeof(HIME_PASSWD));
      memcpy(handle->passwd, &srv_ip_port.passwd, sizeof(srv_ip_port.passwd));
    } else {
      if (handle->passwd) {
        free(handle->passwd); handle->passwd = NULL;
      }
    }
  }

  if (handle->fd)  {
    if (BITON(handle->flag, FLAG_HIME_client_handle_has_focus))
      hime_im_client_focus_in(handle);

    hime_im_client_set_flags(handle, flags_backup, &rstatus);
  }

  return handle;
}
Пример #22
0
	void
plot_subtour (

char *		title,		/* IN - title for plot. */
double *	weights,	/* IN - weight of each full set. */
struct cinfo *	cip,		/* IN - compatibility info. */
bitmap_t *	S,		/* IN - subtour to plot. */
enum plot_size	plot_size	/* IN - size of plot to produce. */
)
{
int			i;
int			j;
int			k;
int			n;
struct full_set *	fsp;
int *			vp1;
int *			vp2;

	n = cip -> num_edges;

	if ((cip -> pts NE NULL) AND (cip -> full_trees NE NULL)) {
		/* Draw the FSTs with postscript. */
		begin_plot (plot_size);

		for (i = 0; i < n; i++) {
			if (weights [i] <= 0.000001) continue;
			k = 0;
			vp1 = cip -> edge [i];
			vp2 = cip -> edge [i + 1];
			while (vp1 < vp2) {
				j = *vp1++;
				if (BITON (S, j)) {
					++k;
				}
			}
			if (k < 2) continue;
			fsp = cip -> full_trees [i];
			draw_fractional_fst (fsp, weights [i], cip);
		}

		(void) printf ("\t0.75 setgray\n");
		(void) printf ("\tPlot_Terminals\n");
		(void) printf ("\t0 setgray\n");

		for (j = 0; j < cip -> num_verts; j++) {
			if (NOT BITON (S, j)) continue;
			printf ("\t%d\tPT\n", j);
		}

		end_plot (title);
	}
	else {
		/* Just output the weighted hyperedges. */
		printf ("\n");
		for (i = 0; i < n; i++) {
			if (weights [i] <= 0.000001) continue;
			printf ("x^%d = %10.8g\t", i, weights [i]);
			vp1 = cip -> edge [i];
			vp2 = cip -> edge [i + 1];
			while (vp1 < vp2) {
				printf (" %d", *vp1++);
			}
			printf ("\n");
		}
	}
}
Пример #23
0
	void
plot_full_sets_grouped (

bitmap_t *		fset_mask,	/* IN - subset of full-sets to plot */
struct cinfo *		cip,		/* IN - compatibility info */
enum plot_size		plot_size	/* IN - size of plot to produce */
)
{
int			i;
int			j;
int			n;
int			nleft;
int			kmasks;
int			nmasks;
int			nplot;
bitmap_t *		left;
bitmap_t *		tmask;
int *			plist;
struct full_set *	fsp;
struct pset *		pts;
char *			cp1;
char *			cp2;
char			fsnums [110];
char			fsnum [8];
char			title [120];

	n = cip -> num_edges;
	nmasks = cip -> num_edge_masks;
	kmasks = cip -> num_vert_masks;

	left = NEWA (nmasks, bitmap_t);
	tmask = NEWA (kmasks, bitmap_t);
	plist = NEWA (n, int);

	/* Make a local copy of all full sets left to plot. */
	for (i = 0; i < nmasks; i++) {
		left [i] = fset_mask [i];
	}
	nleft = n;

	while (nleft > 0) {
		begin_plot (plot_size);

		for (i = 0; i < kmasks; i++) {
			tmask [i] = 0;
		}

		nplot = 0;
		cp1 = &fsnums [sizeof (fsnums)];
		*--cp1 = '\0';

		for (i = n - 1; i >= 0; i--) {
			if (NOT BITON (left, i)) continue;

			/* Skip full set "i" if not disjoint	*/
			/* with all others in this plot...	*/
			fsp = cip -> full_trees [i];
			pts = fsp -> terminals;
			for (j = 0; j < pts -> n; j++) {
				if (BITON (tmask, pts -> a [j].pnum)) break;
			}
			if (j < pts -> n) continue;

			(void) sprintf (fsnum, "%lu", (int32u) i);
			for (cp2 = fsnum; *cp2 NE '\0'; cp2++) {
			}

			/* Stop if label does not fit! */
			if ((cp2 - fsnum) + 2 > (cp1 - fsnums)) break;

			while (cp2 > fsnum) {
				*--cp1 = *--cp2;
			}
			*--cp1 = ' ';
			*--cp1 = ',';

			plist [nplot++] = i;
			CLRBIT (left, i);
			--nleft;

			fsp = cip -> full_trees [i];
			fst_comment (fsp);
			draw_fst (fsp, cip);

			pts = fsp -> terminals;
			for (j = 0; j < pts -> n; j++) {
				SETBIT (tmask, pts -> a [j].pnum);
			}
		}

		(void) printf ("\tPlot_Terminals\n");
		(void) sprintf (title,
				"FST%s %s.",
				(nplot > 1) ? "s" : "",
				cp1 + 2);
		end_plot (title);
	}

	page_break ();

	free ((char *) plist);
	free ((char *) tmask);
	free ((char *) left);
}
Пример #24
0
	struct constraint *
sec_flow_separator (

struct comp **		comp_hookp,	/* IN/OUT - congested component(s) */
double *		x,		/* IN - the LP solution to separate */
bitmap_t *		edge_mask,	/* IN - subset of valid edges */
struct bbinfo *		bbip,		/* IN - branch-and-bound info */
struct constraint *	cp		/* IN - existing constraints */
)
{
int			i;
int			j;
int			t;
int			kmasks;
struct comp *		comp;
struct cinfo *		cip;
int *			ip1;
int *			ip2;
double			z;
bitmap_t *		S;
bitmap_t *		RS;

	cip = bbip -> cip;

#if 0
	plot_lp_solution ("LP solution to separate", x, cip, BIG_PLOT);
#endif

	S = NEWA (2 * cip -> num_vert_masks, bitmap_t);
	RS = S + cip -> num_vert_masks;

	for (;;) {
		comp = *comp_hookp;
		if (comp EQ NULL) break;
		if (comp -> num_verts <= 0) {
			/* Free up this component... */
			*comp_hookp = comp -> next;
			comp -> next = NULL;
			free_congested_component (comp);
			continue;
		}
		if (comp -> num_verts EQ 1) {
			/* Because of the total-degree constraint, this	 */
			/* cannot happen unless something is very wrong! */
			fatal ("sec_flow_separator: Bug 1.");
		}

		if (comp -> num_verts <= SEC_ENUM_LIMIT) {
			/* We have whittled this component down to	*/
			/* something small.  Use brute force on the	*/
			/* rest...					*/
			cp = enumerate_all_subtours (comp, cp, bbip);

			/* Free up this component... */
			*comp_hookp = comp -> next;
			comp -> next = NULL;
			free_congested_component (comp);
			continue;
		}

		/* Find the LEAST congested vertex.  this is the one	*/
		/* we are going to try to force into the solution,	*/
		/* since that is the one we would like to delete from	*/
		/* the set afterward...					*/
		t = find_least_congested_vertex (NULL, comp);

#if 0
		tracef (" %% -------------------------"
			    "-------------------------\n"
			" %% separating comp with %d verts, %d edges,"
			    " forcing vertex %d\n"
			" %% -------------------------"
			    "-------------------------\n",
			comp -> num_verts, comp -> num_edges,
			comp -> rverts [t] [0]);
#endif

		/* Find worst SEC violation involving vertex t. */
		z = do_flow_problem (comp, t, S);

#if 0
#if 0
		kmasks = cip -> num_vert_masks;
		for (i = 0; i < kmasks; i++) {
			RS [i] = 0;
		}
		for (i = 0; i < comp -> num_verts; i++) {
			if (NOT BITON (S, i)) continue;
			ip1 = comp -> rverts [i];
			ip2 = comp -> rverts [i + 1];
			while (ip1 < ip2) {
				j = *ip1++;
				SETBIT (RS, j);
			}
		}
		print_mask (" %% S =", RS, cip -> num_verts);
#else
		print_mask (" %% S =", S, comp -> num_verts);
#endif
		tracef (" %%	f(S) = %-24.15g\n", z);
#endif

		if (z < (1.0 - FUZZ)) {
			/* Add new violated constraint to the list... */
			cp = check_component_subtour (S,
						      comp,
						      cp,
						      x,
						      edge_mask,
						      bbip);
		}

		/* We have found the worst violation (if any) involving	*/
		/* vertex t.  We can now eliminate t from further	*/
		/* consideration...					*/

		*comp_hookp = delete_vertex_from_component (t, comp);
	}

	free ((char *) S);

	return (cp);
}
Пример #25
0
void process_client_req(int fd)
{
  HIME_req req;
#if DBG
  dbg("svr--> process_client_req %d\n", fd);
#endif
  int rn = myread(fd, &req, sizeof(req));

  if (rn <= 0) {
    shutdown_client(fd);
    return;
  }
  if (hime_clients[fd].type == Connection_type_tcp) {
    __hime_enc_mem((u_char *)&req, sizeof(req), &srv_ip_port.passwd, &hime_clients[fd].seed);
  }
  to_hime_endian_4(&req.req_no);
  to_hime_endian_4(&req.client_win);
  to_hime_endian_4(&req.flag);
  to_hime_endian_2(&req.spot_location.x);
  to_hime_endian_2(&req.spot_location.y);

//  dbg("spot %d %d\n", req.spot_location.x, req.spot_location.y);

  ClientState *cs = NULL;

  if (current_CS && req.client_win == current_CS->client_win) {
    cs = current_CS;
  } else {
    int idx = fd;
    cs = hime_clients[fd].cs;

    int new_cli = 0;
    if (!cs) {
      cs = hime_clients[idx].cs = tzmalloc(ClientState, 1);
      new_cli = 1;
    }

    cs->client_win = req.client_win;
    cs->b_hime_protocol = TRUE;
    cs->input_style = InputStyleOverSpot;

    if (hime_init_im_enabled && ((hime_single_state && !is_init_im_enabled) || (!hime_single_state && new_cli))) {
      dbg("new_cli default_input_method:%d\n", default_input_method);
      is_init_im_enabled = TRUE;
      current_CS = cs;
      save_CS_temp_to_current();
      init_state_chinese(cs);
    }
  }

  if (!cs)
    p_err("bad cs\n");

  if (req.req_no != HIME_req_message) {
    cs->spot_location.x = req.spot_location.x;
    cs->spot_location.y = req.spot_location.y;
  }

  gboolean status;
  HIME_reply reply;
  bzero(&reply, sizeof(reply));

  switch (req.req_no) {
    case HIME_req_key_press:
    case HIME_req_key_release:
      current_CS = cs;
      save_CS_temp_to_current();

#if DBG && 0
      {
        char tt[128];

        if (req.keyeve.key < 127) {
          sprintf(tt,"'%c'", req.keyeve.key);
        } else {
          strcpy(tt, XKeysymToString(req.keyeve.key));
        }

        dbg_time("HIME_key_press  %x %s\n", cs, tt);
      }
#endif
      to_hime_endian_4(&req.keyeve.key);
      to_hime_endian_4(&req.keyeve.state);

//	  dbg("serv key eve %x %x predit:%d\n",req.keyeve.key, req.keyeve.state, cs->use_preedit);

#if DBG
	  char *typ;
      typ="press";
#endif
#if 0
      if (req.req_no==HIME_req_key_press)
        status = Process2KeyPress(req.keyeve.key, req.keyeve.state);
      else {
        status = Process2KeyRelease(req.keyeve.key, req.keyeve.state);
#else
      if (req.req_no==HIME_req_key_press)
        status = ProcessKeyPress(req.keyeve.key, req.keyeve.state);
      else {
        status = ProcessKeyRelease(req.keyeve.key, req.keyeve.state);
#endif

#if DBG
        typ="rele";
#endif
      }

      if (status)
        reply.flag |= HIME_reply_key_processed;
#if DBG
      dbg("%s srv flag:%x status:%d len:%d %x %c\n",typ, reply.flag, status, output_bufferN, req.keyeve.key,req.keyeve.key & 0x7f);
#endif
      int datalen;
      datalen = reply.datalen =
        output_bufferN ? output_bufferN + 1 : 0; // include '\0'
      to_hime_endian_4(&reply.flag);
      to_hime_endian_4(&reply.datalen);
      write_enc(fd, &reply, sizeof(reply));

//      dbg("server reply.flag %x\n", reply.flag);

      if (output_bufferN) {
        write_enc(fd, output_buffer, datalen);
        clear_output_buffer();
      }

      break;
    case HIME_req_focus_in:
#if DBG
      dbg_time("HIME_req_focus_in  %x %d %d\n",cs, cs->spot_location.x, cs->spot_location.y);
#endif
//      current_CS = cs;
      hime_FocusIn(cs);
      break;
    case HIME_req_focus_out:
#if DBG
      dbg_time("HIME_req_focus_out  %x\n", cs);
#endif
      hime_FocusOut(cs);
      break;
    case HIME_req_focus_out2:
      {
#if DBG
      dbg_time("HIME_req_focus_out2  %x\n", cs);
#endif
      if (hime_FocusOut(cs))
        flush_edit_buffer();

      HIME_reply reply;
      bzero(&reply, sizeof(reply));

      int datalen = reply.datalen =
        output_bufferN ? output_bufferN + 1 : 0; // include '\0'
      to_hime_endian_4(&reply.flag);
      to_hime_endian_4(&reply.datalen);
      write_enc(fd, &reply, sizeof(reply));

//      dbg("server reply.flag %x\n", reply.flag);

      if (output_bufferN) {
        write_enc(fd, output_buffer, datalen);
        clear_output_buffer();
      }
      }
      break;
    case HIME_req_set_cursor_location:
#if DBG
      dbg_time("set_cursor_location %x %d %d\n", cs,
         cs->spot_location.x, cs->spot_location.y);
#endif
      update_in_win_pos();
      break;
    case HIME_req_set_flags:
//      dbg("HIME_req_set_flags\n");
      if (BITON(req.flag, FLAG_HIME_client_handle_raise_window)) {
#if DBG
        dbg("********* raise * window\n");
#endif
        if (!hime_pop_up_win)
          cs->b_raise_window = TRUE;
      }

	  if (req.flag & FLAG_HIME_client_handle_use_preedit)
        cs->use_preedit = TRUE;

      int rflags;
      rflags = 0;
      if (hime_pop_up_win)
        rflags = FLAG_HIME_srv_ret_status_use_pop_up;

      write_enc(fd, &rflags, sizeof(rflags));
      break;
    case HIME_req_get_preedit:
      {
#if DBG
      dbg("svr HIME_req_get_preedit %x\n", cs);
#endif
      char str[HIME_PREEDIT_MAX_STR];
      HIME_PREEDIT_ATTR attr[HIME_PREEDIT_ATTR_MAX_N];
      int cursor, sub_comp_len;
      int attrN = hime_get_preedit(cs, str, attr, &cursor, &sub_comp_len);
      if (hime_edit_display&(HIME_EDIT_DISPLAY_BOTH|HIME_EDIT_DISPLAY_OVER_THE_SPOT))
        cursor=0;
      if (hime_edit_display&HIME_EDIT_DISPLAY_OVER_THE_SPOT) {
        attrN=0;
        str[0]=0;
      }
      int len = strlen(str)+1; // including \0
      write_enc(fd, &len, sizeof(len));
      write_enc(fd, str, len);
//      dbg("attrN:%d\n", attrN);
      write_enc(fd, &attrN, sizeof(attrN));
      if (attrN > 0)
        write_enc(fd, attr, sizeof(HIME_PREEDIT_ATTR)*attrN);
        write_enc(fd, &cursor, sizeof(cursor));
        write_enc(fd, &sub_comp_len, sizeof(sub_comp_len));
//      dbg("uuuuuuuuuuuuuuuuu len:%d %d cursor:%d\n", len, attrN, cursor);
      }
      break;
    case HIME_req_reset:
      hime_reset();
      break;
    case HIME_req_message:
      {
//        dbg("HIME_req_message\n");
        short len=0;
        int rn = myread(fd, &len, sizeof(len));
        if (rn <= 0) {
cli_down:
          shutdown_client(fd);
          return;
        }

        // only unix socket, no decrypt
        char buf[512];
        // message should include '\0'
        if (len > 0 && len < sizeof(buf)) {
          if (myread(fd, buf, len)<=0)
            goto cli_down;
          message_cb(buf);
        }
      }
      break;
    default:
      dbg_time("Invalid request %x from:", req.req_no);
      struct sockaddr_in addr;
      socklen_t len=sizeof(addr);
      bzero(&addr, sizeof(addr));

      if (!getpeername(fd, (struct sockaddr *)&addr, &len)) {
        dbg("%s\n", inet_ntoa(addr.sin_addr));
      } else {
        perror("getpeername\n");
      }
      shutdown_client(fd);
      break;
  }
}
Пример #26
0
/* MDELEM: Process ELEMENT declaration.
*/
VOID mdelem(UNCH *tbuf)       /* Work area for tokenization (tbuf). */
{
     UNCH *ranksuff = lbuf;   /* Rank suffix. */
     UNS dctype = 0;          /* Declared content type (from dctab). */
     UNCH fmin = 0;           /* Minimization bit flags. */
     int i;                   /* Loop counter. */
     UNS u;                   /* Temporary variable. */
     struct etd **mexgrp, **pexgrp; /* Ptr to model exceptions array. */
     struct thdr *cmod, *cmodsv;    /* Ptr to content model. */
     UNCH *etdgi;             /* GI of current etd (when going through group).*/
     int minomitted = 0;      /*  Tag minimization parameters omitted. */

     mdname = key[KELEMENT];  /* Identify declaration for messages. */
     subdcl = NULL;           /* No subject as yet. */
     parmno = 0;              /* No parameters as yet. */
     mdessv = es;             /* Save es level for entity nesting check. */
     ranksuff[0] = 0;
     mexgrp = pexgrp = 0;

     /* PARAMETER 1: Element name or a group of them.
     */
     parsemd(tbuf, NAMECASE, &pcblitp, NAMELEN);
     TRACEMD("1: element name or grp");
     switch (pcbmd.action) {
     case NAS:
          nmgrp[0] = etddef(tbuf);
          nmgrp[1] = 0;
          break;
     case GRPS:
          parsegrp(nmgrp, &pcbgrnm, tbuf);
          break;
     default:
          mderr(121, (UNCH *)0, (UNCH *)0);
          return;
     }
     /* Save first GI for trace and error messages. */
     if (nmgrp[0])
	  subdcl = nmgrp[0]->etdgi+1;

     /* PARAMETER 1A: Rank suffix (optional).
     */
     parsemd(tbuf, NAMECASE, &pcblitp, NAMELEN);
     TRACEMD("1A: rank suffix");
     switch (pcbmd.action) {
     case NUM:
          ustrcpy(ranksuff, tbuf);
          parsemd(tbuf, NAMECASE, &pcblitp, NAMELEN);
     default:
          break;
     }
     /* PARAMETER 2A: Start-tag minimization.
     */
     TRACEMD("2A: start min");
     switch (pcbmd.action) {
     case CDR:
          break;
     case NAS:
	  if (!ustrcmp(tbuf+1, key[KO])) {
	       if (OMITTAG==YES) SET(fmin, SMO);
	       break;
	  }
	  /* fall through */
     default:
	  if (OMITTAG==NO) {minomitted=1; break;}
          mderr(129, tbuf+1, (UNCH *)0);
          return;
     }
     /* Must omit omitted end-tag minimization, if omitted 
	start-tag minimization was omitted (because OMITTAG == NO). */
     if (!minomitted) {
	  /* PARAMETER 2B: End-tag minimization.
	   */
	  parsemd(tbuf, NAMECASE, &pcblitp, NAMELEN);
	  TRACEMD("2B: end min");
	  switch (pcbmd.action) {
	  case NAS:
	       if (ustrcmp(tbuf+1, key[KO])) {mderr(129, tbuf+1, (UNCH *)0); return;}
	       if (OMITTAG==YES) SET(fmin, EMO);
	       break;
	  case CDR:
	       SET(fmin, EMM);
	       break;
	  default:
	       mderr(129, tbuf+1, (UNCH *)0);
	       return;
	  }
	  /* PARAMETER 3: Declared content.
	   */
	  parsemd(tbuf, NAMECASE, &pcblitp, NAMELEN);
     }
     TRACEMD("3: declared content");
     switch (pcbmd.action) {
     case NAS:
          dctype = mapsrch(dctab, tbuf+1);
          if (!dctype) {mderr(24, tbuf+1, (UNCH *)0); return;}
          /* Eliminate incompatibilities among parameters. */
          if (GET(fmin, SMO) && GET(dctype, MNONE+MCDATA+MRCDATA)) {
               mderr(58, (UNCH *)0, (UNCH *)0);
               RESET(fmin, SMO);
          }
          if (GET(dctype, MNONE) && BITON(fmin, EMM)) {
	       mderr(87, (UNCH *)0, (UNCH *)0);
               SET(fmin, EMO);
          }
          /* If valid, process like a content model. */
     case GRPS:
          cmodsv = parsemod((int)(pcbmd.action==GRPS ? 0 : dctype));
          if (cmodsv==0) return;
	  u = (dctype ? 1 : cmodsv->tu.tnum+2) * THSZ;
          cmod = (struct thdr *)rmalloc(u);
          memcpy((UNIV)cmod  , (UNIV)cmodsv, u );
	  ds.modcnt += cmod->tu.tnum;
          TRACEMOD(cmod);
          break;
     default:
          mderr(130, (UNCH *)0, (UNCH *)0);
          return;
     }
     /* PARAMETERS 3A, 3B: Exceptions or end.
     */
     parsemd(tbuf, NAMECASE, &pcblitp, NAMELEN);
     if (BITOFF(cmod->ttype, MCDATA+MRCDATA+MNONE)) {
          /* PARAMETER 3A: Minus exceptions.
          */
          TRACEMD("3A: -grp");
          switch (pcbmd.action) {
          case MGRP:
	       /* We cheat and use nnmgrp for this. */
               mexgrp = copygrp((PETD *)nnmgrp,
				u = parsegrp((PETD *)nnmgrp, &pcbgrnm, tbuf));
               ++ds.pmexgcnt; ds.pmexcnt += u-1;
               TRACEGRP(mexgrp);
               parsemd(tbuf, NAMECASE, &pcblitp, NAMELEN);
          default:
               break;
          }
          /* PARAMETER 3B: Plus exceptions.
          */
          TRACEMD("3B: +grp");
          switch (pcbmd.action) {
          case PGRP:
               pexgrp = copygrp((PETD *)nnmgrp,
				u = parsegrp((PETD *)nnmgrp, &pcbgrnm, tbuf));
               ++ds.pmexgcnt; ds.pmexcnt += u-1;
               TRACEGRP(pexgrp);
               parsemd(tbuf, NAMECASE, &pcblitp, NAMELEN);
          default:
               break;
          }
     }
     /* PARAMETER 4: End of declaration.
     */
     TRACEMD(emd);
     if (pcbmd.action!=EMD) mderr(126, (UNCH *)0, (UNCH *)0);
     if (es!=mdessv) synerr(37, &pcbmd);

     /* EXECUTE: Store the definition for each element name specified.
     */
     TRACEGRP(nmgrp);
     for (i = -1; nmgrp[++i];) {
          etdgi = nmgrp[i]->etdgi;
          if (*ranksuff) {
               if ((tbuf[0] = *etdgi + ustrlen(ranksuff)) - 2 > NAMELEN) {
                    mderr(131, etdgi+1, ranksuff);
                    continue;
               }
               memcpy(tbuf+1, etdgi+1, *etdgi-1);
               ustrcpy(tbuf+*etdgi-1, ranksuff);
               etdcan(etdgi);
               nmgrp[i] = etddef(tbuf);
          }
          if (nmgrp[i]->etdmod) {mderr(56, etdgi+1, (UNCH *)0); continue;}
          etdset(nmgrp[i], fmin+ETDDCL, cmod, mexgrp, pexgrp, nmgrp[i]->etdsrm);
          ++ds.etdcnt;
          if (nmgrp[i]->adl) etdadl(nmgrp[i]); /* Check ETD conflicts. */
          TRACEETD(nmgrp[i]);
     }
}
Пример #27
0
/* MDATTDEF: Process an individual attribute definition.
             The attribute name is parsed by the caller.
             Duplicate attributes are parsed, but removed from list.
             Returns 0 if successful, otherwise returns 1.
*/
int mdattdef(int adlim,       /* Remaining capacity of al (in tokens).*/
				 int datt)        /* Non-zero if a data attribute. */
{
     int deftype;             /* Default value type: 0=not keyword. */
     int errsw = 0;           /* 1=semantic error; ignore att. */
     int novalsw = 0;         /* 1=semantic error; treat as IMPLIED. */
     int attadn = (int)ADN(al);   /* Save ad number of this attribute. */
     struct parse *grppcb = NULL; /* PCB for name/token grp parse. */
     int errcode;             /* Error type returned by PARSEVAL, ANMTGRP. */
     UNCH *advalsv;           /* Save area for permanent value ptr. */

     /* PARAMETER 1: Attribute name (parsed by caller).
     */
     TRACEMD("1: attribute name");
     if (anmget((int)ADN(al)-1, al[attadn].adname)) {
          errsw = 1;
          mderr(99, ADNAME(al,attadn), (UNCH *)0);
     }
     ADNUM(al,attadn) = ADFLAGS(al,attadn) = ADLEN(al,attadn) = 0;
     ADVAL(al,attadn) = 0; ADDATA(al,attadn).x = 0; ADTYPE(al,attadn) = ANMTGRP;
     /* PARAMETER 2: Declared value.
     */
     parsemd(lbuf, NAMECASE, &pcblitp, NAMELEN);
     TRACEMD("2: declared value");
     switch (pcbmd.action) {
     case NAS:                /* Keyword for value type. */
          switch (ADTYPE(al,attadn) = (UNCH)mapsrch(dvtab, lbuf+1)) {
          case 0:
               mderr(100, ADNAME(al,attadn), lbuf+1);
               return 1;
          case ANOTEGRP:
	       if (datt) {
		    errsw = 1;
		    mderr(156, (UNCH *)0, (UNCH *)0);
	       }
               else if (!noteadn) noteadn = ADN(al);
               else {
                    errsw = 1;
                    mderr(101, ADNAME(al,attadn), (UNCH *)0);
               }
               grppcb = &pcbgrnm;         /* NOTATION requires name grp. */
               parsemd(lbuf, NAMECASE, &pcblitp, NAMELEN);/* Get GRPO*/
               break;
          case AID:
	       if (datt) {
		    errsw = 1;
		    mderr(144, (UNCH *)0, (UNCH *)0);
	       }
               else if (!idadn)
		    idadn = attadn;
               else {
                    errsw = 1;
                    mderr(102, ADNAME(al,attadn), (UNCH *)0);
               }
               break;
	  case AIDREF:
	  case AIDREFS:
	       if (datt) {
		    errsw = 1;
		    mderr(155, (UNCH *)0, (UNCH *)0);
	       }
	       break;
	  case AENTITY:
	  case AENTITYS:
	       if (datt) {
		    errsw = 1;
		    mderr(154, (UNCH *)0, (UNCH *)0);
	       }
	       break;
          }
          break;
     case GRPS:
          grppcb = &pcbgrnt;           /* Normal grp is name token grp. */
          break;
     case EMD:
          mderr(103, ADNAME(al,attadn), (UNCH *)0);
          return 1;
     default:
          mderr(104, ADNAME(al,attadn), (UNCH *)0);
          return 1;
     }
     /* PARAMETER 2A: Name token group.
     */
     if (grppcb != NULL) {
	  TRACEMD("2A: name group");
          switch (pcbmd.action) {
          case GRPS:               /* Name token list. */
               SET(ADFLAGS(al,attadn), AGROUP);
               /* Call routine to parse group, create ad entries in adl. */
               errcode = anmtgrp(grppcb, al+attadn,
				 (GRPCNT<adlim ? GRPCNT+1 : adlim+1),
				 &al[attadn].adnum, ADN(al));
               if (errcode<=0) {
		    if (adlim < GRPCNT)
			 mderr(111, (UNCH *)0, (UNCH *)0);
		    else
			 mderr(105, ADNAME(al,attadn), (UNCH *)0);
                    return 1;
               }
               ADN(al) += ADNUM(al,attadn);    /* Add grp size to total ad cnt.*/
               break;
          default:
               mderr(106, ADNAME(al,attadn), (UNCH *)0);
               return 1;
          }
     }
     /* PARAMETER 3: Default value keyword.
     */
     parsemd(lbuf, AVALCASE,
	     (ADTYPE(al,attadn)==ACHARS) ? &pcblitr : &pcblitt, LITLEN);
     TRACEMD("3: default keyword");
     switch (pcbmd.action) {
     case RNS:                /* Keyword. */
          deftype = mapsrch(deftab, lbuf+1);
          switch (deftype) {
          case DFIXED:        /* FIXED */
               SET(ADFLAGS(al,attadn), AFIXED);
               parsemd(lbuf, AVALCASE,
		       (ADTYPE(al,attadn)==ACHARS) ? &pcblitr : &pcblitt,
		       LITLEN);  /* Real default. */
               goto parm3x;   /* Go process specified value. */
          case DCURR:         /* CURRENT: If ID, treat as IMPLIED. */
               if (ADTYPE(al,attadn)==AID) {
                    mderr(80, ADNAME(al,attadn), (UNCH *)0);
                    break;
               }
	       if (datt) {
		    mderr(157, (UNCH *)0, (UNCH *)0);
		    break;
	       }
               SET(ADFLAGS(al,attadn), ACURRENT);
               break;
          case DREQ:          /* REQUIRED */
               SET(ADFLAGS(al,attadn), AREQ); ++reqadn;
               break;
          case DCONR:         /* CONREF */
               if (ADTYPE(al,attadn)==AID) {
                    mderr(107, ADNAME(al,attadn), (UNCH *)0);
                    break;
               }
	       if (datt) {
		    mderr(158, (UNCH *)0, (UNCH *)0);
		    break;
	       }
               SET(ADFLAGS(al,attadn), ACONREF); conradn = 1;
          case DNULL:         /* IMPLIED */
               break;
          default:            /* Unknown keyword is an error. */
               mderr(108, ADNAME(al,attadn), lbuf+1);
               errsw = 1;
          }
          if (errsw) {
	       /* Ignore erroneous att. */
	       adlfree(al, attadn);
	       --AN(al);
	       ADN(al) = (UNCH)attadn-1;
	  }
          return(0);
     default:
          break;
     }
     /* PARAMETER 3x: Default value (non-keyword).
     */
     parm3x:
     TRACEMD("3x: default (non-keyword)");
     if (ADTYPE(al,attadn)==AID) { /* If ID, treat as IMPLIED. */
          mderr(81, ADNAME(al,attadn), (UNCH *)0);
          novalsw = 1;	      /* Keep parsing to keep things straight. */
     }
     switch (pcbmd.action) {
     case LIT:                /* Literal. */
     case LITE:               /* Literal. */
          /* Null string (except CDATA) is error: msg and treat as IMPLIED. */
          if (*lbuf == '\0' && ADTYPE(al,attadn)!=ACHARS) {
               mderr(82, ADNAME(al,attadn), (UNCH *)0);
               novalsw = 1;
          }
	  break;
     case NAS:                /* Name character string. */
     case NMT:                /* Name character string. */
     case NUM:                /* Number or number token string. */
	  /* The name won't have a length byte because AVALCASE was specified. */
          break;
     case CDR:
	  parsetkn(lbuf, NMC, LITLEN);
	  break;
     case EMD:
          mderr(109, ADNAME(al,attadn), (UNCH *)0);
          return 1;
     default:
          mderr(110, ADNAME(al,attadn), (UNCH *)0);
          return 1;
     }
     if (errsw) {
	  /* Ignore erroneous att. */
	  adlfree(al, attadn);
	  --AN(al);
	  ADN(al) = (UNCH)attadn-1;
	  return(0);
     }
     if (novalsw) return(0);

     /* PARAMETER 3y: Validate and store default value.
     */
     if (ADTYPE(al,attadn)==ACHARS) {
	  UNS len = vallen(ACHARS, 0, lbuf);
	  if (len > LITLEN) {
	       /* Treat as implied. */
	       sgmlerr(224, &pcbmd, ADNAME(al,attadn), (UNCH *)0);
	       return 0;
	  }
          /* No more checking for CDATA value. */
          ADNUM(al,attadn) = 0;             /* CDATA is 0 tokens. */
          ADVAL(al,attadn) = savestr(lbuf);/* Store default; save ptr. */
          ADLEN(al,attadn) = len;
          ds.attdef += len;
          return 0;
     }
     /* Parse value and save token count (GROUP implies 1 token). */
     advalsv = (UNCH *)rmalloc(ustrlen(lbuf)+2); /* Storage for tokenized value. */
     errcode = parseval(lbuf, (UNS)ADTYPE(al,attadn), advalsv);
     if (BITOFF(ADFLAGS(al,attadn), AGROUP)) ADNUM(al,attadn) = (UNCH)tokencnt;

     /* If value was invalid, or was a group member that was not in the group,
        issue an appropriate message and set the error switch. */
     if (errcode)
          {sgmlerr((UNS)errcode, &pcbmd, ADNAME(al,attadn), lbuf); errsw = 1;}
     else if ( BITON(ADFLAGS(al,attadn), AGROUP)
          && !amemget(&al[attadn], (int)ADNUM(al,attadn), advalsv) ) {
               sgmlerr(79, &pcbmd, ADNAME(al,attadn), advalsv+1);
               errsw = 1;
     }
     ADLEN(al,attadn) = vallen(ADTYPE(al,attadn), ADNUM(al,attadn), advalsv);
     if (ADLEN(al,attadn) > LITLEN) {
	  sgmlerr(224, &pcbmd, ADNAME(al,attadn), (UNCH *)0);
	  ADLEN(al,attadn) = 0;
	  errsw = 1;
     }
     /* For valid tokenized value, save it and update statistics. */
     if (!errsw) {
	  ADVAL(al,attadn) = advalsv;
          ds.attdef += ADLEN(al,attadn);
          return 0;
     }
     /* If value was bad, free the value's storage and treat as
        IMPLIED or REQUIRED. */
     frem((UNIV)advalsv);          /* Release storage for value. */
     ADVAL(al,attadn) = NULL;         /* And make value NULL. */
     return 0;
}
Пример #28
0
	struct constraint *
add_cutset_to_list (

bitmap_t *		cutset,		/* IN - new cutset to add */
struct constraint *	cutlist,	/* IN - list to add to */
double *		x,		/* IN - current LP solution */
bitmap_t *		vert_mask,	/* IN - set of valid terminals */
bitmap_t *		edge_mask,	/* IN - set of valid hyperedges */
struct cinfo *		cip		/* IN - compatibility info */
)
{
int			i;
int			j;
int			nedges;
int			nmasks;
int			num_in_cut;
int			count;
int *			vp1;
int *			vp2;
struct constraint *	p;
struct constraint **	hookp;
bitmap_t *		cut_edges;
double			z;

	nedges	= cip -> num_edges;
	nmasks	= cip -> num_edge_masks;

	cut_edges = NEWA (nmasks, bitmap_t);
	memset (cut_edges, 0, nmasks * sizeof (*cut_edges));

	count = 0;
	z = 0.0;
	for (i = 0; i < cip -> num_edges; i++) {
		if (NOT BITON (edge_mask, i)) continue;
		num_in_cut = 0;
		vp1 = cip -> edge [i];
		vp2 = cip -> edge [i + 1];
		while (vp1 < vp2) {
			j = *vp1++;
			if (BITON (cutset, j)) {
				++num_in_cut;
			}
		}
		if (num_in_cut <= 0) {
			/* this hyperedge resides entirely	*/
			/* outside of the cut...  doesn't span!	*/
			continue;
		}
		if (num_in_cut >= cip -> edge_size [i]) {
			/* this hyperedge resides entirely	*/
			/* within the cut...  doesn't span!	*/
			continue;
		}
		SETBIT (cut_edges, i);
		++count;
		z += x [i];
	}

	/* Check for an all-zero cutset.  These occasionally	*/
	/* happen because of numeric issues...			*/

	if (count <= 0) {
		/* Empty cutset!  OOOPS! */
#if 1
		tracef (" %% WARNING!  empty cutset!\n");
#endif
		free ((char *) cut_edges);
		return (cutlist);
	}

	if (z >= 1.0 - FUZZ) {
#if 1
		tracef (" %% WARNING!  bogus cutset!\n");
#endif
		free ((char *) cut_edges);
		return (cutlist);
	}

	/* If this new cutset is a superset of an existing one,	*/
	/* then there is nothing to add, and nothing to delete.	*/
	for (p = cutlist; p NE NULL; p = p -> next) {
		if (is_subset (p -> mask, cut_edges, nmasks)) {
			free (cut_edges);
			return (cutlist);
		}
	}

	/* Delete all current cutsets which have this new one	*/
	/* as a subset.						*/
	hookp = &cutlist;
	while ((p = *hookp) NE NULL) {
		if (p -> type NE CT_CUTSET) {
			hookp = &(p -> next);
		}
		else if (is_subset (cut_edges, p -> mask, nmasks)) {
			*hookp = p -> next;
			free ((char *) (p -> mask));
			free ((char *) p);
		}
		else {
			hookp = &(p -> next);
		}
	}

	p = NEW (struct constraint);
	p -> next	= NULL;
	p -> iteration	= 0;
	p -> type	= CT_CUTSET;
	p -> mask	= cut_edges;
	*hookp = p;

	return (cutlist);
}
Пример #29
0
	static
	void
draw_full_sets_on_grid (

bitmap_t *	fset_mask,	/* IN - mask of valid FSTs */
struct cinfo *	cip		/* IN - compatibility info */
)
{
int			i;
int			j;
int			u, v, ux, uy, vx, vy;
int			nt;
int			ns;
struct full_set *	fsp;
struct pset *		terms;
struct pset *		steins;
struct edge *		ep;
int *			xi;
int *			yi;

	xi = grid.xindex;
	yi = grid.yindex;
	for (i = 0; i < cip -> num_edges; i++) {
		if (NOT BITON (fset_mask, i)) continue;
		fsp = cip -> full_trees [i];

		ep = fsp -> edges;
		terms = fsp -> terminals;
		steins = fsp -> steiners;
		nt = terms -> n;
		ns = steins -> n;
		for (j = 0; j < fsp -> nedges; j++, ep++) {
			u = ep -> p1;
			if (u < 0) {
				fatal ("draw_full_sets_on_grid: Bug 1.");
			}
			if (u < nt) {
				u = terms -> a [u].pnum;
				ux = xi [u];
				uy = yi [u];
			}
			else {
				u -= nt;
				if (u >= ns) {
					fatal ("draw_full_sets_on_grid: Bug 2.");
				}
				ux = map_x (steins -> a [u].x);
				uy = map_y (steins -> a [u].y);
			}

			v = ep -> p2;
			if (v < 0) {
				fatal ("draw_full_sets_on_grid: Bug 3.");
			}
			if (v < nt) {
				v = terms -> a [v].pnum;
				vx = xi [v];
				vy = yi [v];
			}
			else {
				v -= nt;
				if (v >= ns) {
					fatal ("draw_full_sets_on_grid: Bug 4.");
				}
				vx = map_x (steins -> a [v].x);
				vy = map_y (steins -> a [v].y);
			}

			draw_bb_grid (ux, uy, vx, vy);
		}
	}
}
Пример #30
0
	static
	void
compute_edge_graph (

bitmap_t *	tmap,		/* IN - valid set of terminals */
bitmap_t *	fset_mask,	/* IN - valid FSTs */
struct cinfo *	cip		/* IN - compatibility info */
)
{
int			i, j, i1, i2;
int			sp_index;
int			sp_total;
int			n2edges;
int			nedges;
struct full_set *	fsp;
struct pset *		terms;
struct point *		p1;
struct point *		p2;
dist_t			d = 0.0;
char			buf1 [128];
char			buf2 [128];

	/* Total number of Steiner points and ordinary edges */
	nedges = cip -> num_edges;
	sp_total = 0;
	n2edges	 = 0;
	for (i = 0; i < nedges; i++) {
		if (NOT BITON (fset_mask, i)) continue;
		sp_total += cip -> full_trees [i] -> steiners -> n;
		n2edges	 += cip -> full_trees [i] -> nedges;
	}

	/* Write header */
	if (Print_ORLibrary_Format) {
		printf ("%d %d\n", cip -> num_verts + sp_total, n2edges);
	}

	if (Print_SteinLib_Format) {
		printf ("33d32945 STP File, STP Format Version 1.00\n"
			"Section Comment\n"
			"Name    \"%s\"\n"
			"Creator \"GeoSteiner\"\n"
			"Remark  \"Reduced graph from FST generator\"\n"
			"End\n\n"
			"Section Graph\n"
			"Nodes %d\n"
			"Edges %d\n",
			cip -> description, cip -> num_verts + sp_total, n2edges);
	}

	/* Write (ordinary) graph edges */
	sp_index = cip -> num_verts;
	for (i = 0; i < nedges; i++) {
		if (NOT BITON (fset_mask, i)) continue;
		fsp = cip -> full_trees [i];
		terms = fsp -> terminals;
		for (j = 0; j < fsp -> nedges; j++) {

			/* Compute length of this edge */
			p1 = (fsp -> edges[j].p1 < terms -> n)
				? &(terms -> a[ fsp -> edges[j].p1 ])
				: &(fsp -> steiners -> a [fsp -> edges[j].p1 - terms -> n]);
			p2 = (fsp -> edges[j].p2 < terms -> n)
				? &(terms -> a[ fsp -> edges[j].p2 ])
				: &(fsp -> steiners -> a [fsp -> edges[j].p2 - terms -> n]);

			i1 = (fsp -> edges[j].p1 < terms -> n)
				? terms -> a[ fsp -> edges[j].p1 ].pnum + 1
				: fsp -> edges[j].p1 - terms -> n + sp_index + 1;
			i2 = (fsp -> edges[j].p2 < terms -> n)
				? terms -> a[ fsp -> edges[j].p2 ].pnum + 1
				: fsp -> edges[j].p2 - terms -> n + sp_index + 1;

			if (Print_SteinLib_Format) {
				printf ("E ");
			}

			if (cip -> metric EQ EUCLIDEAN) {
				d = EDIST(p1, p2);
			}
			else {
				d = RDIST(p1, p2);
			}
			dist_to_string (buf1, d, &(cip -> scale));
			printf ("%d %d %s\n", i1, i2, buf1);
		}
		if (fsp -> steiners NE NULL) {
			sp_index += fsp -> steiners -> n;
		}
	}

	/* Write terminals (and coordinates in STP-format) */
	if (Print_ORLibrary_Format) {
		printf ("%d\n", cip -> num_verts);
		for (i = 0; i < cip -> num_verts; i++) {
			printf ("%d\n", i+1);
		}
	}

	if (Print_SteinLib_Format) {
		printf ("End\n\n"
			"Section Terminals\n"
			"Terminals %d\n",
			cip -> num_verts);
		for (i = 0; i < cip -> num_verts; i++) {
			printf ("T %d\n", i+1);
		}
		printf ("End\n\n"
			"Section Coordinates\n");
		for (i = 0; i < cip -> num_verts; i++) { /* terminals */
			dist_to_string (buf1,
					cip -> pts -> a[i].x,
					&(cip -> scale));
			dist_to_string (buf2,
					cip -> pts -> a[i].y,
					&(cip -> scale));
			printf ("DD %d %s %s\n", i+1, buf1, buf2);
		}
		sp_index = cip -> num_verts + 1;
		for (i = 0; i < nedges; i++) { /* Steiner points */
			fsp = cip -> full_trees [i];
			for (j = 0; j < fsp -> steiners -> n; j++) {
				dist_to_string (buf1,
						fsp -> steiners -> a[j].x,
						&(cip -> scale));
				dist_to_string (buf2,
						fsp -> steiners -> a[j].y,
						&(cip -> scale));
				printf ("DD %d %s %s\n", sp_index++, buf1, buf2);
			}
		}
		printf ("End\n\n"
			"EOF\n");
	}
}