Ejemplo n.º 1
0
func StartTiling(w http.ResponseWriter, req *http.Request) {
	if reset != nil {
		select {
		case <-reset:
			reset <- 1
		case reset <- 1:
		}
	}

	tilingType := req.FormValue("type")
	tileSymmetry := req.FormValue("symmetry")

	if tilingType == "skeleton" {
		skeleton := req.FormValue("skeleton")
		showIntermediate, ok := strconv.Atob(req.FormValue("intermediate"))
		if ok != nil || skeleton == "" {
			w.WriteHeader(http.StatusNotFound)
		}
		ZellijTilings, reset = zellij.TileSkeleton(skeleton, tileSymmetry, showIntermediate)
		w.WriteHeader(http.StatusOK)
		return
	} else if tilingType == "plane" {
		maxtiles, okm := strconv.Atoi(req.FormValue("maxtiles"))
		showIntermediate, oks := strconv.Atob(req.FormValue("intermediate"))
		if okm != nil || oks != nil || maxtiles == 0 {
			w.WriteHeader(http.StatusNotFound)
		}
		ZellijTilings, reset = zellij.TilePlane(maxtiles, tileSymmetry, showIntermediate)
		w.WriteHeader(http.StatusOK)
		return
	}

	w.WriteHeader(http.StatusNotFound)
}
Ejemplo n.º 2
0
func load_options() {
	reader, file := take_reader_from_file(os.Getenv("HOME") + "/.tabbyoptions")
	defer file.Close()
	var str string
	for next_string_from_reader(reader, &str) {
		args := strings.Split(compact_space(str), "\t", -1)
		switch args[0] {
		case "space_not_tab":
			opt.space_not_tab, _ = strconv.Atob(args[1])
		case "show_search":
			opt.show_search, _ = strconv.Atob(args[1])
		case "show_error":
			opt.show_error, _ = strconv.Atob(args[1])
		case "ihp_position":
			opt.ihp_position = atoi(args[1])
		case "ohp_position":
			opt.ohp_position = atoi(args[1])
		case "vvp_position":
			opt.vvp_position = atoi(args[1])
		case "alloc_window":
			opt.window_width, opt.window_height, opt.window_x, opt.window_y = atoi(args[1]),
				atoi(args[2]), atoi(args[3]), atoi(args[4])
		case "font":
			opt.font = args[1]
		case "tabsize":
			opt.tabsize = atoi(args[1])
		}
	}
}
Ejemplo n.º 3
0
// Get attribute value as bool
func (this *Node) Ab(namespace, name string) bool {
	if s := this.As(namespace, name); s != "" {
		n, _ := strconv.Atob(s)
		return n
	}
	return false
}
Ejemplo n.º 4
0
// Get node value as bool
func (this *Node) B(namespace, name string) bool {
	if node := rec_SelectNode(this, namespace, name); node != nil && node.Value != "" {
		n, _ := strconv.Atob(node.Value)
		return n
	}
	return false
}
Ejemplo n.º 5
0
// setBoolFlag sets the addressed boolean to the value.
func setBoolFlag(flag *bool, value string) {
	x, err := strconv.Atob(value)
	if err != nil {
		fmt.Fprintf(os.Stderr, "gotest: illegal bool flag value %s\n", value)
		usage()
	}
	*flag = x
}
Ejemplo n.º 6
0
func client_callback(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	itsStatus, _ := strconv.Atob(r.FormValue("Status"))
	msg := MSG{itsStatus, r.FormValue("Nickname"), r.FormValue("Message")}
	for _, value := range map_clients {
		channel.SendJSON(c, value, msg)
	}
}
Ejemplo n.º 7
0
func (this *Section) B(key string, defval bool) bool {
	if v, ok := this.Pairs[key]; ok {
		if b, err := strconv.Atob(v); err == nil {
			return b
		}
	}
	return defval
}
Ejemplo n.º 8
0
func (this ParamList) B(i int, defval bool) bool {
	if -1 < i && i < len(this) {
		if v, err := strconv.Atob(this[i]); err == nil {
			return v
		}
	}
	return defval
}
Ejemplo n.º 9
0
func (p *parser) Bool(v *bool, s string, r bool) {
	if p.err != nil || (!r && p.r.FormValue(s) == "") {
		return
	}
	*v, p.err = strconv.Atob(p.r.FormValue(s))
	if p.err != nil {
		p.err = fmt.Errorf("Parsing %s [bool]: %q", s, p.err)
	}
}
Ejemplo n.º 10
0
func copyValue(dst reflect.Value, src []byte) (err os.Error) {
	// Helper functions for integer and unsigned integer conversions
	var itmp int64
	getInt64 := func() bool {
		itmp, err = strconv.Atoi64(string(src))
		// TODO: should check sizes
		return err == nil
	}
	var utmp uint64
	getUint64 := func() bool {
		utmp, err = strconv.Atoui64(string(src))
		// TODO: check for overflow?
		return err == nil
	}
	var ftmp float64
	getFloat64 := func() bool {
		ftmp, err = strconv.Atof64(string(src))
		// TODO: check for overflow?
		return err == nil
	}

	// Save accumulated data and comments
	switch t := dst; t.Kind() {
	case reflect.Invalid:
		// Probably a comment, handled below
	default:
		return os.NewError("cannot happen: unknown type " + t.Type().String())
	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
		if !getInt64() {
			return err
		}
		t.SetInt(itmp)
	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
		if !getUint64() {
			return err
		}
		t.SetUint(utmp)
	case reflect.Float32, reflect.Float64:
		if !getFloat64() {
			return err
		}
		t.SetFloat(ftmp)
	case reflect.Bool:
		value, err := strconv.Atob(strings.TrimSpace(string(src)))
		if err != nil {
			return err
		}
		t.SetBool(value)
	case reflect.String:
		t.SetString(string(src))
	case reflect.Slice:
		t.Set(reflect.ValueOf(src))
	}
	return nil
}
Ejemplo n.º 11
0
func newVal(lit string) Value {
	x, err := strconv.Atoi(lit)
	if err == nil {
		return Int(x)
	}
	b, err := strconv.Atob(lit)
	if err == nil {
		return Bool(b)
	}
	return Error(fmt.Sprintf("illegal literal '%s'", lit))
}
Ejemplo n.º 12
0
// Set Value From HTMLForm Values
func (t *Tasks) SetValue(Id string, r *http.Request) os.Error {

	var err os.Error

	t.UserId = Id
	t.KeyID, err = strconv.Atoi64(r.FormValue(FORM_KEY))
	if err != nil {
		t.KeyID = 0
	}
	t.Status, err = strconv.Atoi(r.FormValue(FORM_STATUS))
	if err != nil {
		log.Println(err)
		return err
	}

	log.Println("Status")

	t.Context = html.EscapeString(r.FormValue(FORM_CONTEXT))
	t.IsUseLimit, err = strconv.Atob(r.FormValue(FORM_LIMIT))
	if err != nil {
		log.Println(err)
		return err
	}

	log.Println("IsUseLimit")

	t.IsComplete = (t.Status == 2)
	t.IsCanceld = (t.Status == 9)

	log.Println("Set Bool Value")

	if t.IsUseLimit {

		log.Println(r.FormValue(FORM_DATE))
		log.Println(time.RFC3339)
		var limit *time.Time
		limit, err = time.Parse("2006-01-02 15:04:05", r.FormValue(FORM_DATE))
		if err == nil {
			t.PlanDate = datastore.SecondsToTime(limit.Seconds())
		} else {
			log.Println(err)
			return err
		}
	}

	log.Println("PostDate")
	t.PostDate = datastore.SecondsToTime(time.Seconds())
	if t.IsComplete {
		t.CompleteDate = datastore.SecondsToTime(time.Seconds())
	}

	return nil

}
Ejemplo n.º 13
0
func writeTo(data []byte, val reflect.Value) os.Error {
	s := string(data)
	switch v := val.(type) {
	// if we're writing to an interace value, just set the byte data
	// TODO: should we support writing to a pointer?
	case *reflect.InterfaceValue:
		v.Set(reflect.NewValue(data))
	case *reflect.BoolValue:
		b, err := strconv.Atob(s)
		if err != nil {
			return err
		}
		v.Set(b)
	case *reflect.IntValue:
		i, err := strconv.Atoi64(s)
		if err != nil {
			return err
		}
		v.Set(i)
	case *reflect.UintValue:
		ui, err := strconv.Atoui64(s)
		if err != nil {
			return err
		}
		v.Set(ui)
	case *reflect.FloatValue:
		f, err := strconv.Atof64(s)
		if err != nil {
			return err
		}
		v.Set(f)

	case *reflect.StringValue:
		v.Set(s)
	case *reflect.SliceValue:
		typ := v.Type().(*reflect.SliceType)
		if _, ok := typ.Elem().(*reflect.UintType); ok {
			v.Set(reflect.NewValue(data).(*reflect.SliceValue))
		}
	}
	return nil
}
Ejemplo n.º 14
0
func writeTo(data []byte, val reflect.Value) os.Error {
	s := string(data)
	switch v := val; v.Kind() {
	// if we're writing to an interace value, just set the byte data
	// TODO: should we support writing to a pointer?
	case reflect.Interface:
		v.Set(reflect.ValueOf(data))
	case reflect.Bool:
		b, err := strconv.Atob(s)
		if err != nil {
			return err
		}
		v.SetBool(b)
	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
		i, err := strconv.Atoi64(s)
		if err != nil {
			return err
		}
		v.SetInt(i)
	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
		ui, err := strconv.Atoui64(s)
		if err != nil {
			return err
		}
		v.SetUint(ui)
	case reflect.Float32, reflect.Float64:
		f, err := strconv.Atof64(s)
		if err != nil {
			return err
		}
		v.SetFloat(f)

	case reflect.String:
		v.SetString(s)
	case reflect.Slice:
		typ := v.Type()
		if typ.Elem().Kind() == reflect.Uint || typ.Elem().Kind() == reflect.Uint8 || typ.Elem().Kind() == reflect.Uint16 || typ.Elem().Kind() == reflect.Uint32 || typ.Elem().Kind() == reflect.Uint64 || typ.Elem().Kind() == reflect.Uintptr {
			v.Set(reflect.ValueOf(data))
		}
	}
	return nil
}
Ejemplo n.º 15
0
func (o *OAuthClient) GetRequestToken(callback string) *RequestToken {
	nonce := getNonce(40)
	params := map[string]string{
		"oauth_nonce":            nonce,
		"oauth_callback":         URLEscape(callback),
		"oauth_signature_method": "HMAC-SHA1",
		"oauth_timestamp":        strconv.Itoa64(time.Seconds()),
		"oauth_consumer_key":     o.ConsumerKey,
		"oauth_version":          "1.0",
	}

	base := signatureBase("POST", requestTokenUrl.Raw, params)
	signature := signRequest(base, o.ConsumerSecret, "")
	params["oauth_signature"] = URLEscape(signature)

	authBuf := bytes.NewBufferString("OAuth ")
	i := 0
	for k, v := range params {
		authBuf.WriteString(fmt.Sprintf("%s=%q", k, v))
		if i < len(params)-1 {
			authBuf.WriteString(", ")
		}
		i++
	}
	request := httplib.Post(requestTokenUrl.Raw)
	request.Header("Authorization", authBuf.String())
	request.Body("")
	resp, err := request.AsString()
	tokens, err := http.ParseQuery(resp)
	if err != nil {
		println(err.String())
	}

	confirmed, _ := strconv.Atob(tokens["oauth_callback_confirmed"][0])
	rt := RequestToken{
		OAuthTokenSecret:       tokens["oauth_token_secret"][0],
		OAuthToken:             tokens["oauth_token"][0],
		OAuthCallbackConfirmed: confirmed,
	}
	return &rt
}
Ejemplo n.º 16
0
func (query *Query) addFilter(filter map[string][]string) (result *Query, err error) {
	if query.Filter == nil {
		query.Filter = map[string]interface{}{}
	}
	for key, values := range filter {
		if len(values) > 1 {
			query.Filter[key] = bson.M{
				"$in": values,
			}
		} else if len(values) == 1 {
			value, err2 := strconv.Atob(values[0])
			if err2 != nil {
				query.Filter[key] = values[0]
			} else {
				query.Filter[key] = value
			}
		}
	}
	result = query
	return
}
Ejemplo n.º 17
0
// Returns the boolean value represented by the string.
// It accepts "y, Y, yes, YES, Yes, n, N, no, NO, No". And values in
// 'strconv.Atob', and 'ExtraBoolString'. Any other value returns an error.
func atob(str string) (value bool, err os.Error) {
	v, err := strconv.Atob(str)
	if err == nil {
		return v, nil
	}

	switch str {
	case "y", "Y", "yes", "YES", "Yes":
		return true, nil
	case "n", "N", "no", "NO", "No":
		return false, nil
	}

	// Check extra characters, if any.
	boolExtra, ok := ExtraBoolString[str]
	if ok {
		return boolExtra, nil
	}

	return false, err // Return error of 'strconv.Atob'
}
Ejemplo n.º 18
0
func wssServe(ws *websocket.Conn) {
	fmt.Println("Socket connect")
	ws.Write([]byte(strconv.Itoa(int(*state))))
	b := make([]byte, 2)
	var quit bool
	for !quit {
		ws.Read(b)
		t, _ := strconv.Atoi(string(b))
		fmt.Println(t)
		switch t {
		case 0:
			func() {
				fmt.Println("Server Init")
				if *state > 0 {
					ws.Write([]byte(strconv.Itoa(int(*state))))
				} else {
					ws.Write([]byte("0"))
					b = make([]byte, 5)
					ws.Read(b)
					world, _ := strconv.Atob(string(b))
					fmt.Println(world)
					if world {

					} else {

					}
				}
			}()
		default:
			func() {
				fmt.Println(string(b))
				quit = true
			}()
		}
		quit = true
	}
}
Ejemplo n.º 19
0
func (r Row) formatReflectValue(i int, x reflect.Value) (int, os.Error) {
	if i >= len(r.Fields) {
		return 0, ErrorIndex
	}
	if !x.CanSet() {
		return 0, ErrorCantSet
	}
	var (
		assigned int
		errc     os.Error
		kind     = x.Kind()
	)
	switch kind {
	// Format pointers to standard types.
	case reflect.String:
		x.SetString(r.Fields[i])
		assigned++
	case reflect.Int:
		fallthrough
	case reflect.Int8:
		fallthrough
	case reflect.Int16:
		fallthrough
	case reflect.Int32:
		fallthrough
	case reflect.Int64:
		var vint int64
		vint, errc = strconv.Atoi64(r.Fields[i])
		if errc == nil {
			x.SetInt(vint)
			assigned++
		}
	case reflect.Uint:
		fallthrough
	case reflect.Uint8:
		fallthrough
	case reflect.Uint16:
		fallthrough
	case reflect.Uint32:
		fallthrough
	case reflect.Uint64:
		var vuint uint64
		vuint, errc = strconv.Atoui64(r.Fields[i])
		if errc == nil {
			x.SetUint(vuint)
			assigned++
		}
	case reflect.Float32:
		fallthrough
	case reflect.Float64:
		var vfloat float64
		vfloat, errc = strconv.Atof64(r.Fields[i])
		if errc == nil {
			x.SetFloat(vfloat)
			assigned++
		}
	case reflect.Complex64:
		fallthrough
	case reflect.Complex128:
		errc = ErrorUnimplemented
	case reflect.Bool:
		var vbool bool
		vbool, errc = strconv.Atob(r.Fields[i])
		if errc == nil {
			x.SetBool(vbool)
			assigned++
		}
	default:
		errc = ErrorFieldType
	}
	return assigned, errc
}
Ejemplo n.º 20
0
func (b *boolValue) Set(s string) bool {
	v, err := strconv.Atob(s)
	*b = boolValue(v)
	return err == nil
}
Ejemplo n.º 21
0
// t is a struct type.
func buildDefaultMessage(t reflect.Type) (dm defaultMessage) {
	sprop := GetProperties(t)
	for _, prop := range sprop.Prop {
		fi := sprop.tags[prop.Tag]
		ft := t.Field(fi).Type

		// nested messages
		if ft.Kind() == reflect.Ptr && ft.Elem().Kind() == reflect.Struct {
			dm.nested = append(dm.nested, fi)
			continue
		}

		sf := scalarField{
			index: fi,
			kind:  ft.Elem().Kind(),
		}

		// scalar fields without defaults
		if prop.Default == "" {
			dm.scalars = append(dm.scalars, sf)
			continue
		}

		// a scalar field: either *T or []byte
		switch ft.Elem().Kind() {
		case reflect.Bool:
			x, err := strconv.Atob(prop.Default)
			if err != nil {
				log.Printf("proto: bad default bool %q: %v", prop.Default, err)
				continue
			}
			sf.value = x
		case reflect.Float32:
			x, err := strconv.Atof32(prop.Default)
			if err != nil {
				log.Printf("proto: bad default float32 %q: %v", prop.Default, err)
				continue
			}
			sf.value = x
		case reflect.Float64:
			x, err := strconv.Atof64(prop.Default)
			if err != nil {
				log.Printf("proto: bad default float64 %q: %v", prop.Default, err)
				continue
			}
			sf.value = x
		case reflect.Int32:
			x, err := strconv.Atoi64(prop.Default)
			if err != nil {
				log.Printf("proto: bad default int32 %q: %v", prop.Default, err)
				continue
			}
			sf.value = int32(x)
		case reflect.Int64:
			x, err := strconv.Atoi64(prop.Default)
			if err != nil {
				log.Printf("proto: bad default int64 %q: %v", prop.Default, err)
				continue
			}
			sf.value = x
		case reflect.String:
			sf.value = prop.Default
		case reflect.Uint8:
			// []byte (not *uint8)
			sf.value = []byte(prop.Default)
		case reflect.Uint32:
			x, err := strconv.Atoui64(prop.Default)
			if err != nil {
				log.Printf("proto: bad default uint32 %q: %v", prop.Default, err)
				continue
			}
			sf.value = uint32(x)
		case reflect.Uint64:
			x, err := strconv.Atoui64(prop.Default)
			if err != nil {
				log.Printf("proto: bad default uint64 %q: %v", prop.Default, err)
				continue
			}
			sf.value = x
		default:
			log.Printf("proto: unhandled def kind %v", ft.Elem().Kind())
			continue
		}

		dm.scalars = append(dm.scalars, sf)
	}

	return dm
}
Ejemplo n.º 22
0
// Unmarshal a single XML element into val.
func (p *Parser) unmarshal(val reflect.Value, start *StartElement) os.Error {
	// Find start element if we need it.
	if start == nil {
		for {
			tok, err := p.Token()
			if err != nil {
				return err
			}
			if t, ok := tok.(StartElement); ok {
				start = &t
				break
			}
		}
	}

	if pv, ok := val.(*reflect.PtrValue); ok {
		if pv.Get() == 0 {
			zv := reflect.MakeZero(pv.Type().(*reflect.PtrType).Elem())
			pv.PointTo(zv)
			val = zv
		} else {
			val = pv.Elem()
		}
	}

	var (
		data         []byte
		saveData     reflect.Value
		comment      []byte
		saveComment  reflect.Value
		saveXML      reflect.Value
		saveXMLIndex int
		saveXMLData  []byte
		sv           *reflect.StructValue
		styp         *reflect.StructType
	)
	switch v := val.(type) {
	default:
		return os.ErrorString("unknown type " + v.Type().String())

	case *reflect.SliceValue:
		typ := v.Type().(*reflect.SliceType)
		if _, ok := typ.Elem().(*reflect.Uint8Type); ok {
			// []byte
			saveData = v
			break
		}

		// Slice of element values.
		// Grow slice.
		n := v.Len()
		if n >= v.Cap() {
			ncap := 2 * n
			if ncap < 4 {
				ncap = 4
			}
			new := reflect.MakeSlice(typ, n, ncap)
			reflect.ArrayCopy(new, v)
			v.Set(new)
		}
		v.SetLen(n + 1)

		// Recur to read element into slice.
		if err := p.unmarshal(v.Elem(n), start); err != nil {
			v.SetLen(n)
			return err
		}
		return nil

	case *reflect.StringValue,
		*reflect.IntValue, *reflect.UintValue, *reflect.UintptrValue,
		*reflect.Int8Value, *reflect.Int16Value, *reflect.Int32Value, *reflect.Int64Value,
		*reflect.Uint8Value, *reflect.Uint16Value, *reflect.Uint32Value, *reflect.Uint64Value,
		*reflect.FloatValue, *reflect.Float32Value, *reflect.Float64Value, *reflect.BoolValue:
		saveData = v

	case *reflect.StructValue:
		if _, ok := v.Interface().(Name); ok {
			v.Set(reflect.NewValue(start.Name).(*reflect.StructValue))
			break
		}

		sv = v
		typ := sv.Type().(*reflect.StructType)
		styp = typ
		// Assign name.
		if f, ok := typ.FieldByName("XMLName"); ok {
			// Validate element name.
			if f.Tag != "" {
				tag := f.Tag
				ns := ""
				i := strings.LastIndex(tag, " ")
				if i >= 0 {
					ns, tag = tag[0:i], tag[i+1:]
				}
				if tag != start.Name.Local {
					return UnmarshalError("expected element type <" + tag + "> but have <" + start.Name.Local + ">")
				}
				if ns != "" && ns != start.Name.Space {
					e := "expected element <" + tag + "> in name space " + ns + " but have "
					if start.Name.Space == "" {
						e += "no name space"
					} else {
						e += start.Name.Space
					}
					return UnmarshalError(e)
				}
			}

			// Save
			v := sv.FieldByIndex(f.Index)
			if _, ok := v.Interface().(Name); !ok {
				return UnmarshalError(sv.Type().String() + " field XMLName does not have type xml.Name")
			}
			v.(*reflect.StructValue).Set(reflect.NewValue(start.Name).(*reflect.StructValue))
		}

		// Assign attributes.
		// Also, determine whether we need to save character data or comments.
		for i, n := 0, typ.NumField(); i < n; i++ {
			f := typ.Field(i)
			switch f.Tag {
			case "attr":
				strv, ok := sv.FieldByIndex(f.Index).(*reflect.StringValue)
				if !ok {
					return UnmarshalError(sv.Type().String() + " field " + f.Name + " has attr tag but is not type string")
				}
				// Look for attribute.
				val := ""
				k := strings.ToLower(f.Name)
				for _, a := range start.Attr {
					if fieldName(a.Name.Local) == k {
						val = a.Value
						break
					}
				}
				strv.Set(val)

			case "comment":
				if saveComment == nil {
					saveComment = sv.FieldByIndex(f.Index)
				}

			case "chardata":
				if saveData == nil {
					saveData = sv.FieldByIndex(f.Index)
				}

			case "innerxml":
				if saveXML == nil {
					saveXML = sv.FieldByIndex(f.Index)
					if p.saved == nil {
						saveXMLIndex = 0
						p.saved = new(bytes.Buffer)
					} else {
						saveXMLIndex = p.savedOffset()
					}
				}
			}
		}
	}

	// Find end element.
	// Process sub-elements along the way.
Loop:
	for {
		var savedOffset int
		if saveXML != nil {
			savedOffset = p.savedOffset()
		}
		tok, err := p.Token()
		if err != nil {
			return err
		}
		switch t := tok.(type) {
		case StartElement:
			// Sub-element.
			// Look up by tag name.
			if sv != nil {
				k := fieldName(t.Name.Local)
				match := func(s string) bool {
					// check if the name matches ignoring case
					if strings.ToLower(s) != strings.ToLower(k) {
						return false
					}
					// now check that it's public
					c, _ := utf8.DecodeRuneInString(s)
					return unicode.IsUpper(c)
				}

				f, found := styp.FieldByNameFunc(match)
				if !found { // fall back to mop-up field named "Any"
					f, found = styp.FieldByName("Any")
				}
				if found {
					if err := p.unmarshal(sv.FieldByIndex(f.Index), &t); err != nil {
						return err
					}
					continue Loop
				}
			}
			// Not saving sub-element but still have to skip over it.
			if err := p.Skip(); err != nil {
				return err
			}

		case EndElement:
			if saveXML != nil {
				saveXMLData = p.saved.Bytes()[saveXMLIndex:savedOffset]
				if saveXMLIndex == 0 {
					p.saved = nil
				}
			}
			break Loop

		case CharData:
			if saveData != nil {
				data = bytes.Add(data, t)
			}

		case Comment:
			if saveComment != nil {
				comment = bytes.Add(comment, t)
			}
		}
	}

	var err os.Error
	// Helper functions for integer and unsigned integer conversions
	var itmp int64
	getInt64 := func() bool {
		itmp, err = strconv.Atoi64(string(data))
		// TODO: should check sizes
		return err == nil
	}
	var utmp uint64
	getUint64 := func() bool {
		utmp, err = strconv.Atoui64(string(data))
		// TODO: check for overflow?
		return err == nil
	}
	var ftmp float64
	getFloat64 := func() bool {
		ftmp, err = strconv.Atof64(string(data))
		// TODO: check for overflow?
		return err == nil
	}

	// Save accumulated data and comments
	switch t := saveData.(type) {
	case nil:
		// Probably a comment, handled below
	default:
		return os.ErrorString("cannot happen: unknown type " + t.Type().String())
	case *reflect.IntValue:
		if !getInt64() {
			return err
		}
		t.Set(int(itmp))
	case *reflect.Int8Value:
		if !getInt64() {
			return err
		}
		t.Set(int8(itmp))
	case *reflect.Int16Value:
		if !getInt64() {
			return err
		}
		t.Set(int16(itmp))
	case *reflect.Int32Value:
		if !getInt64() {
			return err
		}
		t.Set(int32(itmp))
	case *reflect.Int64Value:
		if !getInt64() {
			return err
		}
		t.Set(itmp)
	case *reflect.UintValue:
		if !getUint64() {
			return err
		}
		t.Set(uint(utmp))
	case *reflect.Uint8Value:
		if !getUint64() {
			return err
		}
		t.Set(uint8(utmp))
	case *reflect.Uint16Value:
		if !getUint64() {
			return err
		}
		t.Set(uint16(utmp))
	case *reflect.Uint32Value:
		if !getUint64() {
			return err
		}
		t.Set(uint32(utmp))
	case *reflect.Uint64Value:
		if !getUint64() {
			return err
		}
		t.Set(utmp)
	case *reflect.UintptrValue:
		if !getUint64() {
			return err
		}
		t.Set(uintptr(utmp))
	case *reflect.FloatValue:
		if !getFloat64() {
			return err
		}
		t.Set(float(ftmp))
	case *reflect.Float32Value:
		if !getFloat64() {
			return err
		}
		t.Set(float32(ftmp))
	case *reflect.Float64Value:
		if !getFloat64() {
			return err
		}
		t.Set(ftmp)
	case *reflect.BoolValue:
		value, err := strconv.Atob(strings.TrimSpace(string(data)))
		if err != nil {
			return err
		}
		t.Set(value)
	case *reflect.StringValue:
		t.Set(string(data))
	case *reflect.SliceValue:
		t.Set(reflect.NewValue(data).(*reflect.SliceValue))
	}

	switch t := saveComment.(type) {
	case *reflect.StringValue:
		t.Set(string(comment))
	case *reflect.SliceValue:
		t.Set(reflect.NewValue(comment).(*reflect.SliceValue))
	}

	switch t := saveXML.(type) {
	case *reflect.StringValue:
		t.Set(string(saveXMLData))
	case *reflect.SliceValue:
		t.Set(reflect.NewValue(saveXMLData).(*reflect.SliceValue))
	}

	return nil
}
Ejemplo n.º 23
0
func main() {
	*buri = os.Getenv("DOOZER_BOOT_URI")

	flag.Usage = Usage
	flag.Parse()

	if *showVersion {
		fmt.Println("doozerd", peer.Version)
		return
	}

	if *laddr == "" {
		fmt.Fprintln(os.Stderr, "require a listen address")
		flag.Usage()
		os.Exit(1)
	}

	log.SetPrefix("DOOZER ")
	log.SetFlags(log.Ldate | log.Lmicroseconds)

	tsock, err := net.Listen("tcp", *laddr)
	if err != nil {
		panic(err)
	}

	if *certFile != "" || *keyFile != "" {
		tsock = tlsWrap(tsock, *certFile, *keyFile)
	}

	uaddr, err := net.ResolveUDPAddr("udp", *laddr)
	if err != nil {
		panic(err)
	}

	usock, err := net.ListenUDP("udp", uaddr)
	if err != nil {
		panic(err)
	}

	var wsock net.Listener
	if *waddr == "" {
		wa, err := net.ResolveTCPAddr("tcp", *laddr)
		if err != nil {
			panic(err)
		}
		wa.Port = defWebPort
		*waddr = wa.String()
	}
	if b, err := strconv.Atob(*waddr); err != nil && !b {
		wsock, err = net.Listen("tcp", *waddr)
		if err != nil {
			panic(err)
		}
	}

	id := randId()
	var cl *doozer.Conn
	switch {
	case len(aaddrs) > 0 && *buri != "":
		cl = attach(*name, aaddrs)
		if cl == nil {
			cl = boot(*name, id, *laddr, *buri)
		}
	case len(aaddrs) > 0:
		cl = attach(*name, aaddrs)
		if cl == nil {
			panic("failed to attach")
		}
	case *buri != "":
		cl = boot(*name, id, *laddr, *buri)
	}

	peer.Main(*name, id, *buri, rwsk, rosk, cl, usock, tsock, wsock, ns(*pi), ns(*fd), ns(*kt), *hi)
	panic("main exit")
}
Ejemplo n.º 24
0
func (this *Option) Bool() bool {
	if b, err := strconv.Atob(this.value); err == nil {
		return b
	}
	return false
}