Esempio n. 1
0
// get the header type
static int
read_hb_struct( struct hb_info *HBINFO )
{
  // get the value of beta
  if( setdbl( &( HBINFO -> beta ) , "BETA" ) == GLU_FAILURE ) {
    return GLU_FAILURE ;
  }
  // # of thermalisations
  if( setint( &( HBINFO -> therm ) , "THERM" ) == GLU_FAILURE ) {
    return GLU_FAILURE ;
  }
  // # of iterations
  if( setint( &( HBINFO -> iterations ) , "ITERS" ) == GLU_FAILURE ) {
    return GLU_FAILURE ;
  }
  // # of overrelaxations
  if( setint( &( HBINFO -> Nor ) , "OVER_ITERS" ) == GLU_FAILURE ) {
    return GLU_FAILURE ;
  }
  // file to save
  if( setint( &( HBINFO -> Nsave ) , "SAVE" ) == GLU_FAILURE ) {
    return GLU_FAILURE ;
  }
  // file to save
  if( setint( &( HBINFO -> Nmeasure ) , "MEASURE" ) == GLU_FAILURE ) {
    return GLU_FAILURE ;
  }
  return GLU_SUCCESS ;
}
Esempio n. 2
0
static void
check_sigwinch(void)
{
	if (got_sigwinch) {
		struct winsize ws;

		got_sigwinch = 0;
		if (procpid == kshpid && ioctl(tty_fd, TIOCGWINSZ, &ws) >= 0) {
			struct tbl *vp;

			/* Do NOT export COLUMNS/LINES.  Many applications
			 * check COLUMNS/LINES before checking ws.ws_col/row,
			 * so if the app is started with C/L in the environ
			 * and the window is then resized, the app won't
			 * see the change cause the environ doesn't change.
			 */
			if (ws.ws_col) {
				x_cols = ws.ws_col < MIN_COLS ? MIN_COLS :
				    ws.ws_col;

				if ((vp = typeset("COLUMNS", 0, 0, 0, 0)))
					setint(vp, (long) ws.ws_col);
			}
			if (ws.ws_row && (vp = typeset("LINES", 0, 0, 0, 0)))
				setint(vp, (long) ws.ws_row);
		}
	}
}
int main() {
    char message[] = "Look, this seems like an innocent message!";
    int a;
    static int c;
    int *b;
    a++;
    setint(&a, 10);
    printf("%d\n", a);
    setint(b, 20);
    printf("%ld\n", *b);

    write_message(message);

    return 0;
}
Esempio n. 4
0
NODE *make_intnode(FIXNUM i)
   {
   NODE *nd = newnode(INT);

   setint(nd, i);
   return (nd);
   }
Esempio n. 5
0
/*FUNCTION*/
LVAL c_newnode(tpLspObject pLSP,
               unsigned char type
  ){
/*noverbatim
CUT*/
   LVAL p;

   if( null((p = getnode())) )
      return NIL;

   settype(p,type);
   switch( type )
   {
   case NTYPE_CON:
      return NULL;
   case NTYPE_FLO:
      setfloat(p,0.0);
      break;
   case NTYPE_INT:
      setint(p,0);
      break;
   case NTYPE_STR:
      setstring(p,NULL);
      break;
   case NTYPE_SYM:
      setsymbol(p,NULL);
      break;
   case NTYPE_CHR:
      setchar(p,(char)0);
      break;
   default:
      return NULL;
   }
   return p;
}
Esempio n. 6
0
static void mk_new_int(JRB l, JRB r, JRB p, int il)
{
  JRB newnode;

  newnode = (JRB) calloc(1, sizeof(struct jrb_node));
  setint(newnode);
  setred(newnode);
  setnormal(newnode);
  newnode->flink = l;
  newnode->blink = r;
  newnode->parent = p;
  setlext(newnode, l);
  setrext(newnode, r);
  l->parent = newnode;
  r->parent = newnode;
  setleft(l);
  setright(r);
  if (ishead(p)) {
    p->parent = newnode;
    setroot(newnode);
  } else if (il) {
    setleft(newnode);
    p->flink = newnode;
  } else {
    setright(newnode);
    p->blink = newnode;
  }
  recolor(newnode);
}
Esempio n. 7
0
static void mk_new_int(Rb_node l, Rb_node r, Rb_node p, int il)
{
  Rb_node newnode;
 
  newnode = (Rb_node) malloc(sizeof(struct rb_node));
  setint(newnode);
  setred(newnode);
  setnormal(newnode);
  newnode->c.child.left = l;
  newnode->c.child.right = r;
  newnode->p.parent = p;
  newnode->k.lext = l;
  newnode->v.rext = r;
  l->p.parent = newnode;
  r->p.parent = newnode;
  setleft(l);
  setright(r);
  if (ishead(p)) {
    p->p.root = newnode;
    setroot(newnode);
  } else if (il) {
    setleft(newnode);
    p->c.child.left = newnode;
  } else {
    setright(newnode);
    p->c.child.right = newnode;
  }
  recolor(newnode);
}  
Esempio n. 8
0
PyMODINIT_FUNC
initdski_mod(void)
{
	PyObject *dict, *module;

	module = Py_InitModule("dski_mod", DSKIMethods);
	if (module == NULL)
		return;

	dict = PyModule_GetDict(module);
	if (!dict)
		return;

	setint(dict, "DS_CHAN_TRIG", DS_CHAN_TRIG);
	setint(dict, "DS_CHAN_CONT", DS_CHAN_CONT);
	setint(dict, "DS_CHAN_MMAP", DS_CHAN_MMAP);

}
Esempio n. 9
0
// read from the input file our dimensions
static int
read_random_lattice_info( void )
{
  // lattice dimensions set from input file
  int mu ;
  for( mu = 0 ; mu < ND ; mu++ ) {
    char tmp[ GLU_STR_LENGTH ] ;
    sprintf( tmp , "DIM_%d" , mu ) ;
    Latt.dims[mu] = 8 ; // default to an 8^{ND} lattice
    if( setint( &Latt.dims[ mu ] , tmp ) == GLU_FAILURE ) {
      return GLU_FAILURE ;
    }
  }
  if( setint( &Latt.flow , "CONFNO" ) == GLU_FAILURE ) {
    return GLU_FAILURE ;
  }
  return GLU_SUCCESS ;
}
Esempio n. 10
0
int
sys_waitx(int *wtime, int *rtime)
{
  int a,b;
  int a1,b1;
  argint(0,&a);
  fetchint(a,&a1);
  argint(1,&b);
  fetchint(b,&b1);
  //cprintf("%d %d\n", a1,b1);
  //cprintf("%d %d\n",cpu->proc->rtime,cpu->proc->iotime);
  int totTime=cpu->proc->rtime;
  cprintf("%d MY\n", cpu->proc->pid);
  int totSleepTime=cpu->proc->iotime;
  setint(a,&totTime);
  setint(b,&totSleepTime);
  //cprintf("HI");
  return wait();
}
Esempio n. 11
0
// quickly get the configuration number from the input file
// must be greater than or equal to zero
static size_t
confno( void )
{
  size_t conf = 0 ;
  if( setint( &conf , "CONFNO" ) == GLU_FAILURE ) {
    fprintf( stderr , "[IO] I do not understand CONFNO %zu \n" , conf ) ;
    fprintf( stderr , "[IO] CONFNO should be greater than 0\n" ) ;
    return 0 ;
  }
  return conf ;
}
Esempio n. 12
0
/*FUNCTION*/
LVAL c_char_code(tpLspObject pLSP,
                 LVAL p
  ){
/*noverbatim
CUT*/
  LVAL q;

  if( null(p) || !characterp(p) )return NIL;
  q = newint();
  setint(q,(int)getchr(p));
  return q;
  }
Esempio n. 13
0
int getint(char *ident, int *status) {
	varentry_t *var = lookupvar(ident, integer);
	int out;

	*status = ERROR_NONE;
	if(var == NULL) {
		out = setint(ident, "0", status);
	} else {
		out = var->val.integer;
	}

	return out;
}
Esempio n. 14
0
// read the gauge fixing information
static int
read_gf_struct ( struct gf_info *GFINFO )
{
  // look at what seed type we are going to use
  {
    const int gf_idx = tag_search( "GFTYPE" ) ;
    if( gf_idx == GLU_FAILURE ) { return tag_failure( "GFTYPE" ) ; } 
    if( are_equal( INPUT[gf_idx].VALUE , "LANDAU" ) ) { 
      GFINFO -> type = GLU_LANDAU_FIX ;
    } else if ( are_equal( INPUT[gf_idx].VALUE , "COULOMB" ) ) {
      GFINFO -> type = GLU_COULOMB_FIX ;
    } else {
      fprintf( stderr , "[IO] unknown type [%s] : Defaulting to "
	       "NO GAUGE FIXING \n" , INPUT[gf_idx].VALUE ) ; 
      GFINFO -> type = DEFAULT_NOFIX ; 
    }
  }
  // have a look to see what "improvements" we would like
  {
    const int improve_idx = tag_search( "IMPROVEMENTS" ) ;
    if( improve_idx == GLU_FAILURE ) { return tag_failure( "IMPROVEMENTS" ) ; } 
    GFINFO -> improve = NO_IMPROVE ; // default is no "Improvements" 
    if( are_equal( INPUT[improve_idx].VALUE , "MAG" ) ) {
      GFINFO -> improve = MAG_IMPROVE ; 
    } else if ( are_equal( INPUT[improve_idx].VALUE , "SMEAR" ) ) {
      GFINFO -> improve = SMPREC_IMPROVE ; 
    } else if(  are_equal( INPUT[improve_idx].VALUE , "RESIDUAL" ) ) {
      GFINFO -> improve = RESIDUAL_IMPROVE ; 
    }
  }
  // set the accuracy is 10^{-ACCURACY}
  if( setdbl( &( GFINFO -> accuracy ) , "ACCURACY" ) == GLU_FAILURE ) {
    return GLU_FAILURE ;
  } 
  GFINFO -> accuracy = pow( 10.0 , -GFINFO -> accuracy ) ;
  // set the maximum number of iterations of the routine
  if( setint( &( GFINFO -> max_iters ) , "MAX_ITERS" ) == GLU_FAILURE ) {
    return GLU_FAILURE ;
  }
  // set the alpha goes in Latt.gf_alpha for some reason
  if( setdbl( &Latt.gf_alpha , "GF_TUNE" ) == GLU_FAILURE ) {
    printf( "Failure \n" ) ;
    return GLU_FAILURE ;
  }
  return GLU_SUCCESS ;
}
Esempio n. 15
0
UINT NEAR PASCAL setbase(PUDSTATE np, UINT wNewBase)
{
    UINT wOldBase;

    switch (wNewBase)
    {
        case BASE_DECIMAL:
        case BASE_HEX:
            np->fUnsigned = (wNewBase != BASE_DECIMAL);
            wOldBase = np->nBase;
            np->nBase = wNewBase;
            setint(np);
            return wOldBase;
    }

    return 0;
}
Esempio n. 16
0
NODE *cnv_node_to_numnode(NODE *ndi)
   {
   NODE *val;
   int dr;
   char s2[MAX_NUMBER], *s = s2;

   if (is_number(ndi))
      return (ndi);
   ndi = cnv_node_to_strnode(ndi);
   if (ndi == UNBOUND) return (UNBOUND);
   if (((getstrlen(ndi)) < MAX_NUMBER) && (dr = numberp(ndi)))
      {
      if (backslashed(ndi))
         noparity_strnzcpy(s, getstrptr(ndi), getstrlen(ndi));
      else
         strnzcpy(s, getstrptr(ndi), getstrlen(ndi));
      if (*s == '+') ++s;
      if (s2[getstrlen(ndi) - 1] == '.') s2[getstrlen(ndi) - 1] = 0;
      if (/*TRUE || */ dr - 1 || getstrlen(ndi) > 9)
         {
         val = newnode(FLOAT);
         setfloat(val, atof(s));
         }
      else
         {
         val = newnode(INT);
         setint(val, atol(s));
         }
      gcref(ndi);
      return (val);
      }
   else
      {
      gcref(ndi);
      return (UNBOUND);
      }
   }
Esempio n. 17
0
// pack the sm_info struct
static int
smearing_info( struct sm_info *SMINFO )
{
  // find the smeartype index
  {
    const int type_idx = tag_search( "SMEARTYPE" ) ;
    if( type_idx == GLU_FAILURE ) { return tag_failure( "SMEARTYPE" ) ; }
    if( are_equal( INPUT[type_idx].VALUE , "APE" ) ) { 
      SMINFO -> type = SM_APE ;
    } else if( are_equal( INPUT[type_idx].VALUE , "STOUT" ) ) {
      SMINFO -> type = SM_STOUT ;
    } else if( are_equal( INPUT[type_idx].VALUE , "LOG" ) ) {
      SMINFO -> type = SM_LOG ;
    } else if( are_equal( INPUT[type_idx].VALUE , "HYP" ) ) {
      SMINFO -> type = SM_HYP ;
    } else if( are_equal( INPUT[type_idx].VALUE , "HEX" ) ) {
      SMINFO -> type = SM_HEX ;
    } else if( are_equal( INPUT[type_idx].VALUE , "HYL" ) ) {
      SMINFO -> type = SM_HYL ;
    } else if( are_equal( INPUT[type_idx].VALUE , "WFLOW_LOG" ) ) {
      SMINFO -> type = SM_WFLOW_LOG ;
    } else if( are_equal( INPUT[type_idx].VALUE , "WFLOW_STOUT" ) ) {
      SMINFO -> type = SM_WFLOW_STOUT ;
    } else if( are_equal( INPUT[type_idx].VALUE , "ADAPTWFLOW_LOG" ) ) {
      SMINFO -> type = SM_ADAPTWFLOW_LOG ;
    } else if( are_equal( INPUT[type_idx].VALUE , "ADAPTWFLOW_STOUT" ) ) {
      SMINFO -> type = SM_ADAPTWFLOW_STOUT ;
    } else {
      fprintf( stderr , "[IO] Unrecognised Type [%s] "
	       "Defaulting to No Smearing \n" , INPUT[type_idx].VALUE ) ;
      SMINFO -> type = SM_NOSMEARING ;
    }
  }
  // look for the number of directions
  {
    const int dir_idx = tag_search( "DIRECTION" ) ;
    if( dir_idx == GLU_FAILURE ) { return tag_failure( "DIRECTION" ) ; }
    if( are_equal( INPUT[dir_idx].VALUE , "SPATIAL" ) ) {
      SMINFO -> dir = SPATIAL_LINKS_ONLY ;
    } else {
      SMINFO -> dir = ALL_DIRECTIONS ;
    }
  }
  // set up the number of smearing iterations
  if( setint( &( SMINFO -> smiters ) , "SMITERS" ) == GLU_FAILURE ) {
    return GLU_FAILURE ;
  }
  // poke the smearing alpha's into Latt.smalpha[ND]
  // logically for an ND - dimensional theory there are ND - 1 HYP params.
  {
    size_t mu ;
    for( mu = 0 ; mu < ND - 1 ; mu++ ) {
      char alpha_str[ 64 ] ;
      sprintf( alpha_str , "ALPHA%zu" , mu + 1 ) ;
      if( setdbl( &Latt.sm_alpha[ mu ] , alpha_str ) == GLU_FAILURE ) {
	return GLU_FAILURE ;
      }
    }
  }
  return GLU_SUCCESS ;
}
Esempio n. 18
0
int openusb(struct udev_device* dev, int model){
    // Make sure it's not connected yet
    const char* path = udev_device_get_devnode(dev);
    for(int i = 1; i < DEV_MAX; i++){
        if(keyboard[i].udev && !strcmp(path, udev_device_get_devnode(keyboard[i].udev)))
            return 0;
    }
    // Find a free USB slot
    for(int index = 1; index < DEV_MAX; index++){
        usbdevice* kb = keyboard + index;
        if(!IS_ACTIVE(kb)){
            // Open the sysfs device
            kb->udev = dev;
            kb->handle = open(path, O_RDWR);
            kb->model = model;
            if(kb->handle <= 0){
                printf("Error: Failed to open USB device: %s\n", strerror(errno));
                closehandle(kb);
                connectstatus |= 2;
                return -1;
            }

            // Copy device description and serial
            strncpy(kb->name, udev_device_get_sysattr_value(dev, "product"), NAME_LEN);
            strncpy(kb->setting.serial, udev_device_get_sysattr_value(dev, "serial"), SERIAL_LEN);
            printf("Connecting %s (S/N: %s)\n", kb->name, kb->setting.serial);

            // A USB reset is almost always required in order for it to work correctly
            printf("Resetting device\n");
            if(ioctl(kb->handle, USBDEVFS_RESET, 0)){
                printf("Reset failed (%s). Disconnecting.\n", strerror(errno));
                closehandle(kb);
                connectstatus |= 2;
                return -1;
            }

            // Claim the USB interfaces
            if(usbclaim(kb)){
                printf("Error: Failed to claim interface: %s\n", strerror(errno));
                closehandle(kb);
                connectstatus |= 2;
                return -1;
            }

            // Put the M-keys (K95) as well as the Brightness/Lock keys into software-controlled mode. This packet disables their
            // hardware-based functions.
            unsigned char datapkt[MSG_SIZE] = { 0x07, 0x04, 0x02 };
            struct usbdevfs_ctrltransfer transfer = { 0x21, 0x09, 0x0300, 0x03, MSG_SIZE, 500, datapkt };
            // This packet doesn't always succeed, so reset the device if that happens
            if(ioctl(kb->handle, USBDEVFS_CONTROL, &transfer) != MSG_SIZE){
                printf("Couldn't talk to device (%s), trying to reset again...\n", strerror(errno));
                if(resetusb(kb) || ioctl(kb->handle, USBDEVFS_CONTROL, &transfer) != MSG_SIZE){
                    printf("Reset failed (%s). Disconnecting.\n", strerror(errno));
                    closehandle(kb);
                    connectstatus |= 2;
                    return -1;
                }
            }

            // Set up the device
            if(setupusb(index)){
                closehandle(kb);
                connectstatus |= 2;
                return -1;
            }

            // Set up the interrupt transfers.
            kb->INPUT_TEST = 0;
            setint(kb);

            // We should receive an interrupt transfer shortly after setting them up. If it doesn't happen, the device
            // isn't working correctly and needs to be reset
            int received = 0;
            for(int wait = 0; wait < 10; wait++){
                usleep(50000);
                if(kb->INPUT_TEST){
                    received = 1;
                    break;
                }
            }
            if(!received){
                printf("Didn't get input, trying to reset again...\n");
                if(resetusb(kb)){
                    printf("Reset failed (%s). Disconnecting.\n", strerror(errno));
                    closehandle(kb);
                    connectstatus |= 2;
                    return -1;
                }
            }

            updateconnected();
            printf("Device ready at %s%d\n", devpath, index);
            connectstatus |= 1;
            return 0;
        }
    }
    printf("Error: No free devices\n");
    return -1;
}
Esempio n. 19
0
float raster_contagion ()
{
	int	*adj,*carea;
	int	edgeval;
	int	size;
	float	sum,contagion,prop1,prop2;
	short	i,j,n;
	short	value,neighbor;
	short	xptr,yptr;
	

/*
 *  Get a clean copy of the image.
 */
	read_image(0);

/*
 *  Allocate space for needed variables.
 */
	size = max_class - min_class + 1;

	adj = (int *) calloc ((unsigned)size,sizeof(int));
	if (adj == NULL) {
	   printf ("\nERROR! rascont: Can not allocate space for adj!");
	   exit(-1);
	}
	carea = (int *) calloc ((unsigned)size,sizeof(int));
	if (carea == NULL) {
	   printf ("\nERROR! rascont: Can not allocate space for carea!");
	   exit(-1);
	}

/*
 *  Initialize
 */
	for (i=0; i < size; i++) {
	   carea[i] = 0;
	   adj[i] = 0;
	   for(j=0; j < size; j++) 
	      setint(edge,num_wt,i,j,0);
	}


/*
 *  Step through all cells in the image 
 */

	for (i=0; i < num_rows; i++) {
	   for (j=0; j < num_cols; j++) {
	      value = getshort(image,num_cols,i,j);
	      if (value < 0) continue;

/*
 *  Get the area of each class.
 */
	      carea[value-min_class] ++;

/*
 *  Look at this values 4 neighbors ....
 */
	      for (n=0; n < 4; n++) {
                 xptr = j + xpos[n];
                 if (xptr < 0 || xptr >= num_cols) continue;
                 yptr = i + ypos[n];
                 if (yptr < 0 || yptr >= num_rows) continue;
 
		 neighbor = getshort(image,num_cols,yptr,xptr);

/*
 *  If the neighbor is within the landscape (value >=0), 
 *  increment the count of its patchtype, and increment the
 *  count of the number of this edge type combo.
 */
		 if (neighbor >= 0) {
		    adj[value-min_class] ++;
		    edgeval = getint(edge,num_wt,value-min_class,
			neighbor-min_class);
		    edgeval ++;
		    setint(edge,num_wt,value-min_class,neighbor-min_class,
			edgeval);
		 }
	      }
	   }
	}

/*
 *  Loop over all classes
 */
	sum = 0.0;
	for (i=0; i < size; i++) {
	   if (carea[i] == 0.0) continue;

/* 
 *  Get the proportion of the landscape in this class.
 */
	   prop1 = (float)carea[i] / (float)total_size;

/*
 *  Look for adjacencies with other classes.
 */
	   for (j=0; j < size; j++) {
	      edgeval = getint(edge,num_wt,i,j);
	      if (edgeval > 0) {
	         prop2 = (float)edgeval / (float)adj[i];
		 sum += (prop1 * prop2) * log(prop1 * prop2);
	      }
	   }
	}

/*
 *  Calculate contagion.
 */
	contagion = (sum / (2.0 * log((double)total_num_classes))) + 1.0;

	free (adj);
	free (carea);

	return (contagion);
}
Esempio n. 20
0
// UpDownWndProc:
//
LRESULT CALLBACK UpDownWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    RECT rc;
    int i;
    PUDSTATE np = (PUDSTATE)GetWindowInt(hwnd, 0);

    if (np) {
        if ((uMsg >= WM_MOUSEFIRST) && (uMsg <= WM_MOUSELAST) &&
            (np->ci.style & UDS_HOTTRACK) && !np->fTrackSet) {

            TRACKMOUSEEVENT tme;

            np->fTrackSet = TRUE;

            tme.cbSize = sizeof(tme);
            tme.hwndTrack = np->ci.hwnd;
            tme.dwFlags = TME_LEAVE;

            TrackMouseEvent(&tme);
        }
    }

    switch (uMsg)
    {

    case WM_MOUSEMOVE:
        UD_OnMouseMove(np, lParam);
        break;

    case WM_MOUSELEAVE:
        np->fTrackSet = FALSE;
        UD_Invalidate(np, np->uHot, FALSE);
        np->uHot = UD_HITNOWHERE;
        break;

    case WM_LBUTTONDOWN:
    {
        // Don't set a timer if on the middle border
        BOOL bTimeIt = TRUE;

        if (np->hwndBuddy && !IsWindowEnabled(np->hwndBuddy))
            break;

        SetCapture(hwnd);
        getint(np);

        switch (np->uClass)
        {
        case CLASS_EDIT:
        case CLASS_LISTBOX:
            SetFocus(np->hwndBuddy);
            break;
        }

        switch(UD_HitTest(np, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))) {
        case UD_HITDOWN:
            np->bDown = TRUE;
            squish(np, FALSE, TRUE);
            break;

        case UD_HITUP:
            np->bDown = FALSE;
            squish(np, TRUE, FALSE);
            break;

        case UD_HITNOWHERE:
            bTimeIt = FALSE;
            break;
        }

        if (bTimeIt)
        {
            SetTimer(hwnd, 1, GetProfileInt(TEXT("windows"), TEXT("CursorBlinkRate"), 530), NULL);
            bump(np);
        }
        break;
    }

    case WM_TIMER:
    {
        POINT pt;

        if (GetCapture() != hwnd)
        {
            goto EndScroll;
        }

        SetTimer(hwnd, 1, 100, NULL);

        GetWindowRect(hwnd, &rc);
        if (np->ci.style & UDS_HORZ) {
            i = (rc.left + rc.right) / 2;
            if (np->bDown)
            {
                rc.right = i;
            }
            else
            {
                rc.left = i;
            }
        } else {
            i = (rc.top + rc.bottom) / 2;
            if (np->bDown)
            {
                rc.top = i;
            }
            else
            {
                rc.bottom = i;
            }
        }
        InflateRect(&rc, (g_cxFrame+1)/2, (g_cyFrame+1)/2);
        GetCursorPos(&pt);
        if (PtInRect(&rc, pt))
        {
            squish(np, !np->bDown, np->bDown);
            bump(np);
        }
        else
        {
            squish(np, FALSE, FALSE);
        }
        break;
    }

    case WM_LBUTTONUP:
        if (np->hwndBuddy && !IsWindowEnabled(np->hwndBuddy))
            break;

        if (GetCapture() == hwnd)
        {
EndScroll:
            squish(np, FALSE, FALSE);
            ReleaseCapture();
            KillTimer(hwnd, 1);

            if (np->uClass == CLASS_EDIT)
                Edit_SetSel(np->hwndBuddy, 0, -1);

                        if (np->ci.style & UDS_HORZ)
                            FORWARD_WM_HSCROLL(np->ci.hwndParent, np->ci.hwnd,
                                      SB_ENDSCROLL, np->nPos, SendMessage);
                        else
                            FORWARD_WM_VSCROLL(np->ci.hwndParent, np->ci.hwnd,
                                      SB_ENDSCROLL, np->nPos, SendMessage);
        }
        break;

    case WM_ENABLE:
        InvalidateRect(hwnd, NULL, TRUE);
        break;

    case WM_WININICHANGE:
        if (np && (!wParam ||
            (wParam == SPI_SETNONCLIENTMETRICS) ||
            (wParam == SPI_SETICONTITLELOGFONT))) {
            InitGlobalMetrics(wParam);
            unachor(np);
            anchor(np);
        }
        break;

    case WM_PRINTCLIENT:
    case WM_PAINT:
        PaintUpDownControl(np, (HDC)wParam);
        break;

    case UDM_SETRANGE:
        np->nUpper = GET_X_LPARAM(lParam);
        np->nLower = GET_Y_LPARAM(lParam);
        nudge(np);
        break;

    case UDM_GETRANGE:
        return MAKELONG(np->nUpper, np->nLower);

    case UDM_SETBASE:
        // wParam: new base
        // lParam: not used
        // return: 0 if invalid base is specified,
        //         previous base otherwise
        return (LRESULT)setbase(np, (UINT)wParam);

    case UDM_GETBASE:
        return np->nBase;

    case UDM_SETPOS:
    {
        int iNewPos = GET_X_LPARAM(lParam);
        if (compare(np, np->nLower, np->nUpper, DONTCARE) < 0) {

            if (compare(np, iNewPos, np->nUpper, DONTCARE) > 0) {
                iNewPos = np->nUpper;
            }

            if (compare(np, iNewPos, np->nLower, DONTCARE) < 0) {
                iNewPos = np->nLower;
            }
        } else {
            if (compare(np, iNewPos, np->nUpper, DONTCARE) < 0) {
                iNewPos = np->nUpper;
            }

            if (compare(np, iNewPos, np->nLower, DONTCARE) > 0) {
                iNewPos = np->nLower;
            }
        }

        i = np->nPos;
        np->nPos = iNewPos;
        setint(np);
#ifdef ACTIVE_ACCESSIBILITY
        MyNotifyWinEvent(EVENT_OBJECT_VALUECHANGE, np->ci.hwnd, OBJID_CLIENT, 0);
#endif
        return (LRESULT)i;
    }

    case UDM_GETPOS:
        return getint(np);

    case UDM_SETBUDDY:
        return setbuddy(np, (HWND)wParam);

    case UDM_GETBUDDY:
        return (LRESULT)(int)np->hwndBuddy;

    case UDM_SETACCEL:
            if (wParam == 0)
                return(FALSE);
            if (wParam >= NUM_UDACCELS)
            {
                HANDLE npPrev = (HANDLE)np;
                np = (PUDSTATE)LocalReAlloc((HLOCAL)np, sizeof(UDSTATE)+(wParam-NUM_UDACCELS)*sizeof(UDACCEL),
                    LMEM_MOVEABLE);
                if (!np)
                {
                    return(FALSE);
                }
                else
                {
                    SetWindowInt(hwnd, 0, (int)np);

                    if ((np->ci.style & UDS_ARROWKEYS) && np->hwndBuddy)
                    {
                        SetWindowSubclass(np->hwndBuddy, ArrowKeyProc, 0,
                            (DWORD)np);
                    }
                }
            }

            np->nAccel = wParam;
        for (i=0; i<(int)wParam; ++i)
        {
                np->udAccel[i] = ((LPUDACCEL)lParam)[i];
        }
        return(TRUE);

    case UDM_GETACCEL:
        if (wParam > np->nAccel)
        {
            wParam = np->nAccel;
        }
        for (i=0; i<(int)wParam; ++i)
        {
            ((LPUDACCEL)lParam)[i] = np->udAccel[i];
        }
        return(np->nAccel);

    case WM_NOTIFYFORMAT:
        return CIHandleNotifyFormat(&np->ci, lParam);

    case WM_CREATE:
        // Allocate the instance data space.
        np = (PUDSTATE)LocalAlloc(LPTR, sizeof(UDSTATE));
        if (!np)
            return -1;

        SetWindowInt(hwnd, 0, (int)np);

            #define lpCreate ((CREATESTRUCT FAR *)lParam)

        CIInitialize(&np->ci, hwnd, lpCreate);

        // np->fUp =
        // np->fDown =
            // np->fUnsigned =
            // np->fSharedBorder =
            // np->fSunkenBorder =
        //  FALSE;

        if (lpCreate->dwExStyle & WS_EX_CLIENTEDGE)
            np->fSunkenBorder = TRUE;

        np->nBase = BASE_DECIMAL;
        np->nUpper = 0;
        np->nLower = 100;
        np->nPos = 0;
        np->hwndBuddy = NULL;
        np->uClass = CLASS_UNKNOWN;

            np->nAccel = NUM_UDACCELS;
            np->udAccel[0].nSec = 0;
            np->udAccel[0].nInc = 1;
        np->udAccel[1].nSec = 2;
            np->udAccel[1].nInc = 5;
            np->udAccel[2].nSec = 5;
            np->udAccel[2].nInc = 20;

        /* This does the pickbuddy and anchor
         */
        setbuddy(np, NULL);
        setint(np);
        break;

    case WM_DESTROY:
        if (np) {
            if (np->hwndBuddy)
            {
                // Make sure that our buddy is unsubclassed.
                DebugMsg(DM_ERROR, TEXT("UpDown Destroyed while buddy subclassed"));
                np->fUpDownDestroyed = TRUE;
            }
            else
                LocalFree((HLOCAL)np);
            SetWindowInt(hwnd, 0, 0);
        }
        break;

    default:
        return DefWindowProc(hwnd, uMsg, wParam, lParam);
    }

    return 0L;
}
Esempio n. 21
0
// Use this to click the pos up or down by one.
//
void NEAR PASCAL bump(PUDSTATE np)
{
    BOOL bChanged = FALSE;
    UINT uElapsed, increment;
    int direction, i;

    /* So I'm not really getting seconds here; it's close enough, and
     * dividing by 1024 keeps __aFuldiv from being needed.
     */
    uElapsed = (UINT)((GetTickCount() - np->dwStart) / 1024);

    increment = np->udAccel[0].nInc;
    for (i=np->nAccel-1; i>=0; --i)
    {
        if (np->udAccel[i].nSec <= uElapsed)
        {
            increment = np->udAccel[i].nInc;
            break;
        }
    }

    if (increment == 0)
    {
        DebugMsg(DM_ERROR, TEXT("bad accelerator value"));
        return;
    }

    direction = compare(np,np->nUpper,np->nLower, DONTCARE) < 0 ? -1 : 1;
    if (np->fUp)
    {
        bChanged = TRUE;
    }
    if (np->fDown)
    {
        direction = -direction;
        bChanged = TRUE;
    }

    if (bChanged)
    {
        /* Make sure we have a multiple of the increment
         * Note that we should loop only when the increment changes
         */
        NM_UPDOWN nm;

        nm.iPos = np->nPos;
        nm.iDelta = increment*direction;
        if (SendNotifyEx(np->ci.hwndParent, np->ci.hwnd, UDN_DELTAPOS, &nm.hdr, FALSE))
            return;

        np->nPos += nm.iDelta;
        for ( ; ; )
        {
            if (!((int)np->nPos % (int)increment))
            {
                break;
            }
            np->nPos += direction;
        }

        nudge(np);
        setint(np);
        if (np->ci.style & UDS_HORZ)
            FORWARD_WM_HSCROLL(np->ci.hwndParent, np->ci.hwnd, SB_THUMBPOSITION, np->nPos, SendMessage);
        else
            FORWARD_WM_VSCROLL(np->ci.hwndParent, np->ci.hwnd, SB_THUMBPOSITION, np->nPos, SendMessage);

#ifdef ACTIVE_ACCESSIBILITY
        MyNotifyWinEvent(EVENT_OBJECT_VALUECHANGE, np->ci.hwnd, OBJID_CLIENT, 0);
#endif

    }
}
Esempio n. 22
0
/*
 * local function to read an expression
 */
static LVAL _readexpr(tpLspObject pLSP,FILE *f)
{
   int ch,ch1,ch2,i;
   LVAL p;
   char *s;
   double dval;
   long lval;


   spaceat(ch,f);
   if( ch == EOF )
   {
      return NIL;
   }
   if( ch == pLSP->cClose )
   {
      return NIL;
   }

   if( ch == pLSP->cOpen )/* Read a cons node. */
      return readcons(pLSP,f);

   /**** Note: XLISP allows 1E++10 as a symbol. This is dangerous.
         We do not change XLISP (so far), but here I exclude all symbol
         names starting with numeral. */
   if( const_p1(ch) )/* Read a symbol. */
   {
      for( i = 0 ; const_p(ch) ; i++ ){
        if( storech(pLSP,i,ch) )return NIL;
        ch = getC(pLSP,f);
        }
      UNGETC(ch);
      /* Recognize NIL and nil symbols. */
      if( !strcmp(BUFFER,"NIL") || !strcmp(BUFFER,"nil") )
         return NIL;
      p = newsymbol();
      s = StrDup( BUFFER );
      if( null(p) || s == NULL )return NIL;
      setsymbol(p,s);
      return p;
   }
   if( ch == '\"' ){
     ch = GETC(f);
     storech(pLSP,0,0); /* inititalize the buffer */
     if( ch != '\"' )goto SimpleString;
     ch = GETC(f);
     if( ch != '\"' ){
       UNGETC(ch);
       ch = '\"';/* ch should hold the first character of the string that is " now */
       goto SimpleString;
       }
     ch = GETC(f);     
     /* multi line string */
     for( i = 0 ; ch != EOF ; i++ ){
       if( ch == '\"' ){
         ch1 = GETC(f);
         ch2 = GETC(f);
         if( ch1 == '\"' && ch2 == '\"' )break;
         UNGETC(ch2);
         UNGETC(ch1);
         }
       if( ch == '\\' ){
         ch = GETC(f);
         s = escapers;
         while( *s ){
           if( *s++ == ch ){
             ch = *s;
             break;
             }
           if( *s )s++;
           }
         }
       if( storech(pLSP,i,ch) )return NIL;
       ch = GETC(f);
       }
     p = newstring();
     s = StrDup( BUFFER );
     if( null(p) || s == NULL )return NIL;
     setstring(p,s);
     return p;
     }

   if( ch == '\"' ){/* Read a string. */
     ch = GETC(f);/* Eat the " character. */
SimpleString:
     for( i = 0 ; ch != '\"' && ch != EOF ; i++ ){
       if( ch == '\\' ){
         ch = GETC(f);
         s = escapers;
         while( *s ){
           if( *s++ == ch ){
             ch = *s;
             break;
             }
           if( *s )s++;
           }
         }
       if( ch == '\n' )return NIL;
       if( storech(pLSP,i,ch) )return NIL;
       ch = GETC(f);
       }
      p = newstring();
      s = StrDup( BUFFER );
      if( null(p) || s == NULL )
      {
         return NIL;
      }
      setstring(p,s);
      return p;
   }
   if( numeral1(ch) )
   {
      for( i = 0 ; isinset(ch,"0123456789+-eE.") ; i++ )
      {
         if( storech(pLSP,i,ch) )return NIL;
         ch = getC(pLSP,f);
      }
      UNGETC(ch);
      cnumeric(BUFFER,&i,&dval,&lval);
      switch( i )
      {
      case 0:
         return NIL;
      case 1:
         /* A float number is coming. */
         p = newfloat();
         if( null(p) )
         {
            return NIL;
         }
         setfloat(p,dval);
         return p;
      case 2:
         /* An integer is coming. */
         p = newint();
         if( null(p) )
         {
            return NIL;
         }
         setint(p,lval);
         return p;
      default:
         return NIL;
      }
   }
   return NIL;
}
Esempio n. 23
0
static int domail_maxcli(int argc, char *argv[], void *p)
{
  return setint(&Maxclients, "Max clients", argc, argv);
}
Esempio n. 24
0
// pack the cut_info struct
static int
read_cuts_struct( struct cut_info *CUTINFO )
{
  // set up the cuttype
  {
    const int cuttype_idx = tag_search( "CUTTYPE" ) ;
    if( cuttype_idx == GLU_FAILURE ) { return tag_failure( "CUTTYPE" ) ; }
    if( are_equal( INPUT[cuttype_idx].VALUE , "EXCEPTIONAL" ) ) {
      CUTINFO -> dir = EXCEPTIONAL ;
    } else if( are_equal( INPUT[cuttype_idx].VALUE , "NON_EXCEPTIONAL" ) ) {
      CUTINFO -> dir = NONEXCEPTIONAL ;
    } else if( are_equal( INPUT[cuttype_idx].VALUE , "FIELDS" ) ) {
      CUTINFO -> dir = FIELDS ;
    } else if( are_equal( INPUT[cuttype_idx].VALUE , "SMEARED_GLUONS" ) ) {
      CUTINFO -> dir = SMEARED_GLUONS ;
    } else if( are_equal( INPUT[cuttype_idx].VALUE , "INSTANTANEOUS_GLUONS" ) ) {
      CUTINFO -> dir = INSTANTANEOUS_GLUONS ;
    } else if( are_equal( INPUT[cuttype_idx].VALUE , "CONFIGSPACE_GLUONS" ) ) {
      CUTINFO -> dir = CONFIGSPACE_GLUONS ;
    } else if( are_equal( INPUT[cuttype_idx].VALUE , "GLUON_PROPS" ) ) {
      CUTINFO -> dir = GLUON_PROPS ;
    } else if( are_equal( INPUT[cuttype_idx].VALUE , "STATIC_POTENTIAL" ) ) {
      CUTINFO -> dir = STATIC_POTENTIAL ;
    } else if( are_equal( INPUT[cuttype_idx].VALUE , "TOPOLOGICAL_SUSCEPTIBILITY" ) ) {
      CUTINFO -> dir = TOPOLOGICAL_SUSCEPTIBILITY ;
    } else {
      fprintf( stderr , "[IO] I do not understand your CUTTYPE %s\n" , 
	       INPUT[cuttype_idx].VALUE ) ;
      fprintf( stderr , "[IO] Defaulting to no cutting \n" ) ;
      return GLU_FAILURE ;
    }
  }
  // momentum space cut def
  {
    const int momcut_idx = tag_search( "MOM_CUT" ) ;
    if( momcut_idx == GLU_FAILURE ) { return tag_failure( "MOM_CUT" ) ; }
    if ( are_equal( INPUT[momcut_idx].VALUE , "HYPERCUBIC_CUT" ) ) {
      CUTINFO -> type = HYPERCUBIC_CUT ; 
    } else if ( are_equal( INPUT[momcut_idx].VALUE , "SPHERICAL_CUT" ) ) {
      CUTINFO -> type = PSQ_CUT ; 
    } else if ( are_equal( INPUT[momcut_idx].VALUE , "CYLINDER_CUT" ) ) {
      CUTINFO -> type = CYLINDER_CUT ; 
    } else if ( are_equal( INPUT[momcut_idx].VALUE , "CONICAL_CUT" ) ) {
      CUTINFO -> type = CYLINDER_AND_CONICAL_CUT ; 
    } else {
      fprintf( stderr , "[IO] Unrecognised type [%s] \n" , 
	       INPUT[momcut_idx].VALUE ) ; 
      fprintf( stderr , "[IO] Defaulting to SPHERICAL_CUT \n" ) ; 
    }
  }
  // field definition
  {
    const int field_idx = tag_search( "FIELD_DEFINITION" ) ;
    if( field_idx == GLU_FAILURE ) { return tag_failure( "FIELD_DEFINITION" ) ; }
    CUTINFO -> definition = LINEAR_DEF ;
    if( are_equal( INPUT[field_idx].VALUE , "LOGARITHMIC" ) ) {
      CUTINFO -> definition = LOG_DEF ;
    } 
  }
  // minmom, maxmom angle and cylinder width
  if( setint( &( CUTINFO -> max_t ) , "MAX_T" ) == GLU_FAILURE ) {
    return GLU_FAILURE ;
  }
  if( setint( &( CUTINFO -> max_mom ) , "MAXMOM" ) == GLU_FAILURE ) {
    return GLU_FAILURE ;
  }
  if( setint( &( CUTINFO -> angle ) , "ANGLE" ) == GLU_FAILURE ) {
    return GLU_FAILURE ;
  }
  // set the cylinder width
  if( setdbl( &( CUTINFO -> cyl_width ) , "CYL_WIDTH" ) == GLU_FAILURE ) {
    return GLU_FAILURE ;
  }
  // look for where the output is going
  {
    const int output_idx = tag_search( "OUTPUT" ) ;
    if( output_idx == GLU_FAILURE ) { return tag_failure( "OUTPUT" ) ; }
    sprintf( CUTINFO -> where , "%s" , INPUT[output_idx].VALUE ) ; 
  }
  return GLU_SUCCESS ;
}
Esempio n. 25
0
/**
 * create a new canvas
 * args: width, height, [title]
 */
int Canvas::_new(lua_State *l) {
	const char *title = "Aroma";

	int width = luaL_checkint(l, 2);
	int height = luaL_checkint(l, 3);
	if (lua_gettop(l) > 3) {
		title = luaL_checkstring(l, 4);
	}

	GLContext* context = new GLFWContext(width, height, title);
	if (!context->make_current()) {
		return luaL_error(l, "fatal error: failed to open window");
	}

	_canvas = new Canvas(context);

	Viewport &view = _canvas->view;

	lua_newtable(l);

	// functions

	setfunction("run", Canvas::_run);

	setfunction("rect", Canvas::_rect);
	setfunction("line", Canvas::_line);

	setfunction("viewport", Canvas::_viewport);
	setfunction("view3d", Canvas::_view3d);

	setfunction("look", Canvas::_look);
	setfunction("strip", Canvas::_strip);

	setfunction("rotate", Canvas::_rotate);
	setfunction("scale", Canvas::_scale);
	setfunction("translate", Canvas::_translate);

	setfunction("noise", Canvas::_noise);

	setfunction("save", Canvas::_save);
	setfunction("restore", Canvas::_restore);

	setfunction("getTime", Canvas::_getTime);
	setfunction("clear_color", Canvas::_clearColor);
	setfunction("clear", Canvas::_clear);
	setfunction("flush", Canvas::_flush);

	setfunction("set_mouse", Canvas::_setMouse);
	setfunction("hide_mouse", Canvas::_hideMouse);
	setfunction("show_mouse", Canvas::_showMouse);

	setfunction("key", Canvas::_key);
	setfunction("key_up", Canvas::_key_up);
	setfunction("key_down", Canvas::_key_down);

	// load libraries
	AromaRegister *lib = aroma_libs;
	while (*lib) {
		(*lib++)(l);
	}

	// properties
	setnumber("dt", 0);
	setnumber("time", glfwGetTime());

	setnumber("width", view.getWidth());
	setnumber("height", view.getHeight());


	// mouse input
	lua_newtable(l);
	setint("x", 0);
	setint("y", 0);
	setbool("left", false);
	setbool("right", false);

	lua_setfield(l, -2, "mouse");
	
	// create the input table
	lua_newtable(l);
	setnumber("xaxis", 0);
	setnumber("yaxis", 0);

	setbool("left", false);
	setbool("right", false);
	setbool("up", false);
	setbool("down", false);

	setbool("a", false);
	setbool("b", false);
	setbool("c", false);
	setbool("d", false);

	setbool("start", false);
	setbool("select", false);

	setbool("l", false);
	setbool("r", false);

	lua_setfield(l, -2, "input");

	// the keys
	push_key_table(l);
	lua_setfield(l, -2, "keys");

	// create meta table
	lua_newtable(l);		
	setfunction("__call", _call);
	lua_setmetatable(l, -2);

	return 1;
}