Example #1
0
func defined(z *int, s string) bool {
	//
	str.Move(&s, true)
	negative := s[0] == '-'
	var n uint
	if negative {
		n = uint(len(s))
		s = str.Part(s, 1, n-1)
	}
	if str.Empty(s) {
		return false
	}
	if nat.Defined(&n, s) {
		if negative {
			if n < m2 {
				*z = -int(n)
				return true
			} else if n == m2 {
				*z = MinInt
				return true
			}
		} else if n <= MaxInt {
			*z = int(n)
			return true
		}
	}
	return false
}
Example #2
0
func put(n string, x, y, w, h uint) {
	//
	if str.Empty(n) {
		return
	}
	str.RemSpaces(&n)
	filename := n + suffix
	if scr.UnderX() {
		errh.Hint("bitte etwas Geduld ...")
	}
	buf := scr.P6Encode(x, y, w, h)
	if scr.UnderX() {
		errh.DelHint()
	}
	file := pseq.New(buf)
	file.Name(filename)
	file.Clr()
	file.Put(buf)
	file.Terminate()
	if !toPrint {
		exec.Command("pnmtopng", filename+suffix, ">", n, ".png").Run()
		ker.Msleep(100)
		exec.Command("rm", filename)
	}
}
Example #3
0
func (x *Imp) Name(s string) {
	//
	if str.Empty(s) {
		return
	}
	x.name = s
	x.file.Name(x.name + "." + suffix)
	x.tree.Clr()
	x.posPool.Clr()
	if x.file.Empty() {
		return
	}
	x.file.Trav(func(a Any) {
		x.object = a.(Object)
		if x.object.Empty() {
			x.posPool.Ins(x.pos)
		} else {
			x.index.Set(x.f(x.object), x.pos)
			x.tree.Ins(x.index)
		}
		x.pos++
	})
	x.pos = 0
	x.Jump(false)
}
Example #4
0
func Init(e, d bool, n uint, s string) {
	//
	if initialisiert {
		Graph.Terminate()
	} else {
		scr.Switch(scr.WVGApp)
		initialisiert = true
	}
	Ecke = node.New(n)
	Ecke1 = node.New(n)
	tempEcke = node.New(n)
	tempEcke1 = node.New(n)
	Kante = edge.New()
	tempKante = edge.New()
	Graph = gra.New(d, Ecke, Kante)
	edge.WithValues = e
	Dateiname := ""
	str.RemAllSpaces(&s)
	if str.Empty(s) {
		Dateiname = "temp"
	} else {
		Dateiname = s
	}
	//  sel.DateinameEditieren (Dateiname)
	Graph.Name(Dateiname + "." + "gra")
}
Example #5
0
func (x *Imp) Empty() bool {
	//
	if str.Empty(x.name) {
		return true
	}
	return x.file.empty()
}
Example #6
0
func (x *Imp) Defined(t string) bool {
	//
	str.RemSpaces(&t)
	if str.Empty(t) {
		x.Clr()
		return true
	}
	for c := country(keineAngabe); c < noNations; c++ {
		x.cnt = c
		x.att = Folge[c]
		switch x.fmt {
		case Tld:
			if t == x.att.tld {
				return true
			}
		case Long:
			var p uint
			if str.IsPart(t, x.att.name, &p) && p == 0 {
				return true
			}
		default:
			return false
		}
	}
	return false
}
Example #7
0
func (x *Imp) Rename(n string) {
	//
	if str.Empty(n) || n == x.name {
		return
	}
	x.name = n
	x.file.rename(x.name)
}
Example #8
0
func (x *Imp) Rename(s string) {
	//
	if str.Empty(s) || x.name == s {
		return
	}
	x.name = s
	x.file.Rename(x.name + "." + suffix)
}
Example #9
0
func (x *Imp) Terminate() {
	//
	if !str.Empty(x.name) {
		buf := x.Encode()
		f := pseq.New(buf)
		f.Name(x.name)
		f.Clr()
		f.Put(buf)
		f.Terminate()
	}
	//  x.Clr ()
}
Example #10
0
func (x *Imp) Defined(t string) bool {
	//
	x.Clr()
	if str.Empty(t) {
		return true
	}
	n, ss, P, L := nat.DigitSequences(t)
	if n == 0 || n > 3 {
		return false
	}
	if n == 3 {
		if x.fmt == Hh_mm {
			return false
		}
	}
	if L[0] >= textlength[x.fmt] {
		return false
	}
	h, m, s := uint(0), uint(0), uint(0)
	if n == 1 {
		if !nat.Defined(&h, str.Part(t, P[0], 2)) {
			return false
		}
		if L[0] > 2 {
			if !nat.Defined(&m, str.Part(t, P[0]+2, 2)) {
				return false
			}
			if L[0] > 4 {
				if !nat.Defined(&s, str.Part(t, P[0]+4, 2)) {
					return false
				}
			}
		}
	} else {
		if !nat.Defined(&h, ss[0]) {
			return false
		}
		if !nat.Defined(&m, ss[1]) {
			return false
		}
		if n == 2 && x.fmt == Mm_ss {
			s, m, h = m, h, 0
		}
		if n == 3 {
			if !nat.Defined(&s, ss[2]) {
				return false
			}
		}
	}
	return x.defined(h, m, s)
}
Example #11
0
func defined() (string, bool) {
	//
	bx := box.New()
	bx.Wd(6)
	bx.Colours(col.LightCyan, col.Black)
	bx.Write("Welt:", 1, 0)
	const n = 12
	bx.Wd(n)
	name := str.Clr(n)
	name = ""
	errh.Hint("Namen der Welt eingeben                Programmende: leere Eingabe")
	bx.Edit(&name, 1, 6)
	str.RemSpaces(&name)
	errh.DelHint()
	return name, !str.Empty(name)
}
Example #12
0
func get(n string, x, y uint) {
	//
	const tst = true
	if str.Empty(n) {
		return
	}
	str.RemSpaces(&n)
	filename := n + suffix
	l := pseq.Length(filename)
	if l == 0 {
		return
	}
	buf := make([]byte, l)
	file := pseq.New(buf)
	file.Name(filename)
	buf = file.Get().([]byte)
	file.Terminate()
	scr.P6Decode(x, y, buf)
}
Example #13
0
func size_(n string) (uint, uint) {
	//
	w, h := uint(0), uint(0)
	if str.Empty(n) {
		return w, h
	}
	str.RemSpaces(&n)
	filename := n + suffix
	l := pseq.Length(filename)
	if l == 0 {
		return w, h
	}
	buf := make([]byte, l)
	file := pseq.New(buf)
	file.Name(filename)
	buf = file.Get().([]byte)
	file.Terminate()
	w, h = scr.P6Size(buf)
	return w, h
}
Example #14
0
func (x *Imp) Defined(s string) bool {
	//
	if str.Empty(s) {
		x.Clr()
		return true
	}
	i := uint(0)
	str.Move(&s, true)
	l := str.ProperLen(s)
	if str.Contains(s, ' ', &i) && s[0] == '0' {
		n := uint(0)
		if nat.Defined(&n, s[1:i]) { // i <= l
			x.prefix = uint16(n)
			if l == i {
				return false
			}
			s = s[i:l]
		} else {
			return false
		}
	} else {
		x.prefix = 0
	}
	str.Move(&s, true)
	str.RemAllSpaces(&s)
	if s == "" {
		x.number = uint(x.prefix)
		x.prefix = 0
		return true
	}
	if nat.Defined(&x.number, s) {
		return true
	} else {
		x.prefix = 0
		x.number = 0
	}
	return false
}
Example #15
0
func (x *Imp) Defined(s string) bool {
	//
	x.Clr()
	if str.Empty(s) {
		return true
	}
	str.Move(&s, true)
	x.geq0 = s[0] != '-'
	switch s[0] {
	case '+', '-':
		str.Rem(&s, 0, 1)
	}
	n := str.ProperLen(s)
	var p uint
	if str.Contains(s, '/', &p) {
		s1 := str.Part(s, p+1, n-p-1)
		if nat.Defined(&x.denom, s1) {
			if x.denom >= max {
				return false
			}
		} else {
			return false
		}
	} else {
		p = n
		x.denom = 1
	}
	s1 := str.Part(s, 0, p)
	if nat.Defined(&x.num, s1) {
		if x.num >= max {
			return false
		}
	} else {
		return false
	}
	return true
}
Example #16
0
func New0(a Any, h string, p uint16, o bool) *Imp {
	//
	if str.Empty(h) || p >= 1<<16-Port0 {
		return nil
	}
	if a == nil {
		a = false
	}
	x := new(Imp)
	if tst {
		println("nchan.New0 started for host", h, "/ port", p)
	}
	x.object, x.width = Clone(a), Codelen(a)
	str.RemSpaces(&h)
	x.farHost = host.New()
	if !x.farHost.Defined(h) {
		errh.Error("Hostname "+h+" is not resolvable", 0)
		Stop(pack, 1)
	}
	x.isServer = host.Local(h)
	x.server = h
	x.port = Port0 + p
	x.oneOne = o
	if x.oneOne {
		if x.isServer {
			x.isServer = first(x.port)
		} else {
			x.isServer = x.farHost.Sonstewas()
		}
	}
	x.buf = make([]byte, x.width)
	//  x.info = true
	if tst {
		println("nchan.New0 for host", h, "is done")
	}
	return x
}
Example #17
0
func (F *files) name(N string) {
	//
	if str.Empty(N) {
		return
	}
	F.flush()
	var fi FileInfo
	fi, F.err = Stat(N)
	F.isThere = F.err == nil
	if F.isThere { // is there a file with name N (?)
		//    if ! fi.IsRegular() { errh.Error (N + " is no regular file", 0); Terminate(); Exit (1) } // nothing goes
		//    if fi.Permission() != rights { errh.Error (N + " has no rights", 0); Terminate(); Exit (1) } // nothing goes
		F.file, F.err = OpenFile(N, O_RDWR, rights) // ; F.report ("define", "OpenFile", 0)
		if F.err == nil {
			F.endoffset = uint64(fi.Size())
			_ = F.file.Close() // ; F.report ("define", "Close", 0)
		} else {
			F.file = nil
			println(&PathError{"define", N, F.err})
		}
	} else { // there is no file with name N (?)
		if IsPermission(F.err) {
			println("no permission ")
		}
		F.file, F.err = Create(N) // ; F.report ("define", "Create", 0)
		if F.err == nil {
			F.endoffset = 0
			_ = F.file.Close() // ; F.report ("define", "Close", 0)
			F.isThere = true
		} else {
			F.file = nil
		}
	}
	F.offset = 0
	F.isOpen = false
}
Example #18
0
func (x *Imp) Defined(s string) bool {
	//
	if str.Empty(s) {
		x.cent = undefined
		return true
	}
	a, t, P, L := nat.DigitSequences(s)
	var k uint
	hatKomma := str.Contains(s, ',', &k)
	if !hatKomma {
		hatKomma = str.Contains(s, '.', &k)
	}
	var n uint
	if !nat.Defined(&n, t[0]) {
		return false
	}
	switch a {
	case 1:
		if hatKomma && k < P[0] { // Komma vor der Ziffernfolge
			switch L[0] {
			case 1:
				x.cent = 10 * n
			case 2:
				x.cent = n
			default:
				return false
			}
			return true
		}
		if hatKomma && k >= P[0]+L[0] || !hatKomma {
			if L[0] <= nDigits {
				x.cent = hundred * n
				return true
			}
		}
	case 2:
		if !hatKomma {
			return false
		}
		if k < P[0]+L[0] || P[1] <= k {
			return false
		}
		if L[0] > nDigits {
			return false
		} else {
			x.cent = hundred * n
		}
		if !nat.Defined(&n, t[1]) {
			return false
		}
		switch L[1] {
		case 1:
			x.cent += 10 * n
		case 2:
			x.cent += n
		default:
			return false
		}
		return true
	}
	return false
}
Example #19
0
func (x *Imp) Empty() bool {
	//
	return str.Empty(x.name)
}
Example #20
0
func (x *Imp) Defined(s string) bool {
	//
	if str.Empty(s) {
		x.Clr()
		return true
	}
	var d Imp
	d.day, d.month, d.year = x.day, x.month, x.year
	var T string
	var l, p uint
	n, ss, P, L := nat.DigitSequences(s)
	switch x.fmt {
	case Dd, // e.g. " 8"
		Dd_mm_,     // e.g. " 8.10."
		Dd_mm_yy,   // e.g. " 8.10.07"
		Dd_mm_yyyy: // e.g. " 8.10.2007" *):
		switch n {
		case 1:
			l = 2
		case 2, 3:
			l = L[0]
		default:
			return false
		} // see below
	case Dd_M, // e.g. "8. Oktober"
		Dd_M_yyyy: // e.g. "8. Oktober 2007"
		if x.fmt == Dd_M {
			if n != 1 {
				return false
			}
		} else {
			if n != 2 {
				return false
			}
		}
		if !str.Contains(s, '.', &p) {
			return false
		}
		if x.fmt == Dd_M_yyyy {
			//      l = str.ProperLen (s)
			//      T = str.Part (s, p, l - p)
			T = ss[1]
			if !nat.Defined(&d.year, T) {
				return false
			}
		}
		T = ss[0]
		str.Move(&T, true)
		if !nat.Defined(&d.day, T) {
			return false
		}
		T = str.Part(s, p+1, P[1]-p-1)
		str.Move(&T, true)
		if !isMonth(&d.month, T) {
			return false
		}
		return x.defined(d.day, d.month, d.year)
	case Yymmdd: // e.g. "090418"
		if !nat.Defined(&d.year, str.Part(s, 0, 2)) {
			return false
		}
		if !nat.Defined(&d.month, str.Part(s, 2, 2)) {
			return false
		}
		if !nat.Defined(&d.day, str.Part(s, 4, 2)) {
			return false
		}
		return x.defined(d.day, d.month, d.year)
	case Yyyymmdd: // e.g. "20090418"
		if !nat.Defined(&d.year, str.Part(s, 0, 4)) {
			return false
		}
		if !nat.Defined(&d.month, str.Part(s, 4, 2)) {
			return false
		}
		if !nat.Defined(&d.day, str.Part(s, 6, 2)) {
			return false
		}
		return x.defined(d.day, d.month, d.year)
	case Yy, // e.g. "08"
		Yyyy: // e.g. "2007"
		if n != 1 {
			return false
		}
		if nat.Defined(&d.year, ss[0]) {
			return x.defined(d.day, d.month, d.year)
		} else {
			return false
		}
	case Wd, // e.g. "Mo"
		WD: // e.g. "Monday"
		return false // Fall noch nicht erledigt
	case Mmm, // e.g. "Mon"
		M: // e.g. "Oktober"
		if !isMonth(&d.month, s) {
			return false
		}
		return x.defined(d.day, d.month, d.year)
	case Myyyy: // e.g. "Oktober 2007"
		if n != 1 {
			return false
		}
		if !nat.Defined(&d.year, ss[0]) {
			return false
		}
		if !str.Contains(s, ' ', &p) {
			return false
		}
		if !isMonth(&d.month, str.Part(s, 0, p)) {
			return false
		}
		return x.defined(d.day, d.month, d.year)
	case Wn, // e.g. "1" (.Woche)
		WN: // e.g. "1.Woche"
		if n != 1 {
			return false
		}
		if nat.Defined(&n, T) {
			if 0 < n && n <= 3 {
				d.day, d.month, d.year = 1, 1, x.year
				c := internalCode(d)
				w := weekday(d)
				if w > Thursday {
					c += 7
				} // see Weeknumber
				if c < uint16(w) {
					return false
				}
				c -= uint16(w) // so c is a Monday
				d.Decode(Encode(uint(c) + 7*n))
				if d.year == x.year {
					x.day = d.day
					x.month = d.month
					return true
				}
			}
			return false
		}
	case WNyyyy: // e.g. "1.Woche 2007"
		return false // not yet implemented
	case Qu: // e.g. "  I/06"
		if n != 1 {
			return false
		}
		if !str.Contains(s, '/', &p) {
			return false
		}
		if !nat.Defined(&d.year, ss[0]) {
			return false
		}
		T = str.Part(s, 0, p)
		str.Move(&T, true)
		n = str.ProperLen(T)
		if T[0] != 'I' {
			return false
		}
		switch n {
		case 1:
			d.month = 1
		case 2:
			switch T[1] {
			case 'I':
				d.month = 4
			case 'V':
				d.month = 10
			default:
				return false
			}
		case 3:
			if T[1] == 'I' && T[2] == 'I' {
				d.month = 7
			}
		default:
			return false
		}
		return x.defined(d.day, d.month, d.year)
	}
	if !nat.Defined(&d.day, str.Part(s, P[0], l)) {
		return false
	}
	if n == 1 {
		if L[0] > 8 {
			return false
		} // maximal "Dd_mm_yyyy"
		if L[0] > 2 {
			if !nat.Defined(&d.month, str.Part(s, P[0]+2, 2)) {
				return false
			}
		}
		if L[0] > 4 {
			if !nat.Defined(&d.year, str.Part(s, P[0]+4, L[0]-4)) {
				return false
			}
		}
	} else { // n == 2, 3
		if !nat.Defined(&d.month, ss[1]) {
			return false
		}
		if n == 2 && x.Empty() {
			d.year = today.(*Imp).year
		}
		if n == 3 {
			if !nat.Defined(&d.year, ss[2]) {
				return false
			}
		}
	}
	return x.defined(d.day, d.month, d.year)
}
Example #21
0
func (x *Imp) Ok() bool {
	//
	var i uint
	return str.IsEquivPart(actual.text, x.text, &i) &&
		!str.Empty(actual.text)
}
Example #22
0
func main() {
	//
	if !scr.MouseEx() {
		return
	}
	var symbol [Nfigure]byte
	symbol[line] = 'S'      // "Strecke"
	symbol[rectangle] = 'R' // "Rechteck"
	symbol[circle] = 'K'    // "Kreis"
	symbol[ellipse] = 'E'   // "Ellipse"
	X, Y := 0, 0
	X1, Y1 := scr.NX(), scr.NY()
	//  Farbe, Papier:= col.LightWhite, col.Black
	Farbe, Papier := col.Black, col.LightWhite
	col.ScreenF, col.ScreenB = Farbe, Papier
	scr.Cls()
	paintColour := Farbe
	scr.Colour(paintColour)
	//  Staerke = 3
	bx := box.New()
	bx.Wd(20)
	bx.Colours(Papier, Farbe)
	Name := env.Par(1)
	if str.Empty(Name) {
		Name = "temp"
	}
	scr.Save(0, 0, 20, 1)
	for {
		bx.Edit(&Name, 0, 0)
		if !str.Empty(Name) {
			str.RemSpaces(&Name)
			break
		}
	}
	scr.Restore(0, 0, 20, 1)
	img.Get(Name, uint(X), uint(Y))
	scr.MouseCursor(true)
	Figur := figure(rectangle)
	var x, y, x0, y0 int
loop:
	for {
		scr.Colour(paintColour)
		Zeichen, Kommando, T := kbd.Read()
		switch Kommando {
		case kbd.None:
			x, y = scr.MousePosGr()
			scr.SwitchTransparence(true)
			scr.Write1Gr(Zeichen, x, y-int(scr.NY1()))
			//    scr.WarpMouse (x + scr.NX1(), y)
		case kbd.Esc:
			break loop
		case kbd.Back:
			switch T {
			case 0:
				x, y = scr.MousePosGr()
				x -= int(scr.NX1())
				scr.Colour(Papier)
				scr.Write1Gr(' ', x, y-int(scr.NY1()))
				//        scr.RectangleFull (x, y - scr.NY1(), x + scr.NX1(), y)
				//        scr.WarpMouseGr (x, y)
				scr.Colour(paintColour)
			default:
				scr.Cls()
			}
			/*
			   case kbd.Ins:
			     img.Write (X, Y, X1, Y1 - 16, Name)
			     box.Edit (Feld, Name, scr.Zeilenzahl () - 1, 0)
			     img.Get (X, Y, Name)
			*/
		case kbd.Help:
			paintColour = sel.Colour()
			//    case kbd.LookFor:
			//      Staerke = Strichstaerken.Staerke()
		case kbd.Enter:
			if T > 0 {
				x0, y0 = scr.MousePosGr()
				//        scr.Fill1 (x0, y0)
			}
		case kbd.PrintScr:
			img.Print(uint(X), uint(Y), X1, Y1-16)
		case kbd.Tab:
			if T == 0 {
				if Figur+1 < Nfigure {
					Figur++
				} else {
					Figur = figure(0)
				}
			} else {
				if Figur > 0 {
					Figur--
				} else {
					Figur = figure(Nfigure - 1)
				}
			}
			scr.Colours(col.White, Papier)
			scr.Write1(symbol[Figur], scr.NY()-1, 0)
		case kbd.Here:
			x0, y0 = scr.MousePosGr()
			scr.CircleFull(x0, y0, 3/2)
		case kbd.Pull:
			x, y = scr.MousePosGr()
			scr.Line(x0, y0, x, y)
			x0, y0 = x, y
		case kbd.Hither:
			x, y = scr.MousePosGr()
			scr.Line(x0, y0, x, y)
		case kbd.There:
			x0, y0 = scr.MousePosGr()
			x, y = x0, y0
		case kbd.Push:
			paint(Figur, inv, x0, y0, x, y)
			x, y = scr.MousePosGr()
			paint(Figur, inv, x0, y0, x, y)
		case kbd.Thither:
			paint(Figur, inv, x0, y0, x, y)
			//      scr.Colour (paintColour)
			x, y = scr.MousePosGr()
			paint(Figur, border, x0, y0, x, y)
			x0, y0 = x, y
		case kbd.This:
			x0, y0 = scr.MousePosGr()
			x, y = x0, y0
		case kbd.Move:
			scr.LineInv(x0, y0, x, y)
			x, y = scr.MousePosGr()
			scr.LineInv(x0, y0, x, y)
		case kbd.Thus:
			scr.LineInv(x0, y0, x, y)
			x, y = scr.MousePosGr()
			scr.Line(x0, y0, x, y)
			x0, y0 = x, y
		}
	}
	scr.Save(0, 0, 20, 1)
	for {
		bx.Edit(&Name, 0, 0)
		// TODO make sure, that "Name" is x{x|y} where x is letter, y is digit
		if !str.Empty(Name) {
			str.RemSpaces(&Name)
			break
		}
	}
	scr.Restore(0, 0, 20, 1)
	img.Put(Name, uint(X), uint(Y), X1, Y1)
	ker.Terminate()
}
Example #23
0
func (x *Imp) Empty() bool {
	//
	return str.Empty(x.text)
}
Example #24
0
func (x *Imp) Empty() bool {
	//
	return str.Empty(x.content)
}