Exemple #1
0
func scanLoop(scanner *bufio.Scanner, outCh chan string, outTermCh chan bool) {
	first := true
	buf := new(bytes.Buffer)

	for scanner.Scan() {
		text := scanner.Text()
		if DeleteColor(text) == Delimiter {
			if first {
				first = false
			} else {
				text := strings.TrimSpace(buf.String())
				DebugPrint("shell", "out <- [%v]", text)
				outCh <- text
				buf = new(bytes.Buffer)
			}
		} else {
			DebugPrint("shell", "read [%v]", text)
			buf.WriteString(text + "\n")
		}
	}
	text := strings.TrimSpace(buf.String())
	DebugPrint("shell", "out <- [%v]", text)
	if text != "" {
		outCh <- text
	}
	outTermCh <- true
}
Exemple #2
0
func readBoard(scanner *bufio.Scanner) (out board) {
	for scanner.Scan() {
		parts := strings.Split(scanner.Text(), ",")
		out = append(out, parts)
	}
	return out
}
Exemple #3
0
func next(in *bufio.Scanner, shouldScan bool) int {
	if shouldScan {
		in.Scan()
	}
	n, _ := strconv.Atoi(in.Text())
	return n
}
Exemple #4
0
func (this *M3U) media(scanner *bufio.Scanner) {
	line := scanner.Text()
	buf := make(map[string]string)
	scanner.Scan()
	l2 := scanner.Text()
	scanner.Scan()
	toMap(line[strings.Index(line, ":")+1:]+","+l2[strings.Index(l2, ":")+1:], buf)
	rank := 0
	switch buf["VIDEO"] {
	case "chunked":
		rank = 1
	case "high":
		rank = 2
	case "medium":
		rank = 3
	case "low":
		rank = 4
	case "mobile":
		rank = 5
	}
	this.PlayLists = append(this.PlayLists, M3UStream{
		Video:      buf["VIDEO"],
		Name:       buf["NAME"],
		Resolution: buf["RESOLUTION"],
		Location:   scanner.Text(),
		Rank:       rank,
	})
}
Exemple #5
0
// phasesFromLog14 parses the phases for a single Go 1.4 GC cycle.
func phasesFromLog14(scanner *bufio.Scanner) (phases []Phase, haveBegin bool) {
	sub := gc14Log.FindStringSubmatch(scanner.Text())

	n := atoi(sub[1])
	stop, sweepTerm, markTerm, shrink := atoi(sub[2]), atoi(sub[3]), atoi(sub[4]), atoi(sub[5])
	var begin int64
	if sub[6] != "" {
		begin = atoi64(sub[6][1:])
		haveBegin = true
	}

	phases = []Phase{
		// Go 1.5 includes stoptheworld() in sweep termination.
		{0, int64(stop+sweepTerm) * 1000, PhaseSweepTerm, n, 1, 1, true},
		// Go 1.5 includes stack shrink in mark termination.
		{0, int64(markTerm+shrink) * 1000, PhaseMarkTerm, n, 1, 1, true},
		{0, -1, PhaseSweep, n, 1, 0, false},
	}

	if haveBegin {
		for i := range phases {
			phases[i].Begin += begin
			begin += phases[i].Duration
		}
	}

	return
}
Exemple #6
0
// buildBoard builds a "board" (an array) by scanning input, splitting comma-
// separated integers and inserting them into an array.
func buildBoard(input *bufio.Scanner, board *[81]int) {
	l := 0

	for input.Scan() {
		for i, n := range strings.Split(input.Text(), ",") {
			var val int

			// If i is a dash, val is 0
			if n == "-" {
				val = 0
			} else {
				// Convert i to an int
				val2, err := strconv.Atoi(n)
				if err != nil {
					fmt.Println(os.Stderr, err)
					os.Exit(2)
				}
				val = val2
			}

			board[i+9*l] = val
		}

		l++
	}
}
Exemple #7
0
func extractCore(module string, scanner *bufio.Scanner, config *Config) *Dependency {
	dependency := newDependency()
	enable := config.Start == nil
	for scanner.Scan() {
		line := scanner.Text()
		if config.Start != nil && config.Start.MatchString(line) {
			enable = true
		}
		if config.Module != nil {
			if matches := config.Module.FindStringSubmatch(line); matches != nil {
				module = matches[len(matches)-1]
			}
		}
		if enable {
			if matches := config.Pattern.FindStringSubmatch(line); len(matches) >= 1 {
				for _, name := range matches[1:] {
					if name != "" {
						dependency.add(module, name)
					}
				}
			}
		}
		if enable && config.End != nil && config.End.MatchString(line) {
			enable = false
		}
	}
	return dependency
}
Exemple #8
0
func run(ruleset *internal.RuleSet, scanner *bufio.Scanner, apiInstance api.API, unmatched *os.File) Statistics {
	stat := Statistics{
		perMetric: make(map[api.MetricKey]PerMetricStatistics),
	}
	for scanner.Scan() {
		input := scanner.Text()
		converted, matched := ruleset.MatchRule(input)
		if matched {
			stat.matched++
			perMetric := stat.perMetric[converted.MetricKey]
			perMetric.matched++
			reversed, err := ruleset.ToGraphiteName(converted)
			if *insertToDatabase {
				apiInstance.AddMetric(converted)
			}
			if err != nil {
				perMetric.reverseError++
			} else if string(reversed) != input {
				perMetric.reverseIncorrect++
			} else {
				perMetric.reverseSuccess++
			}
			stat.perMetric[converted.MetricKey] = perMetric
		} else {
			stat.unmatched++
			if unmatched != nil {
				unmatched.WriteString(input)
				unmatched.WriteString("\n")
			}
		}
	}
	return stat
}
Exemple #9
0
func adhocTextFix(scanner *bufio.Scanner) string {
	text := scanner.Text()

	r := regexp.MustCompile("(^\\s*Open State.*Alphabetic    ) (The allowable values are:)")
	text = r.ReplaceAllString(text, "$1$2")

	r2 := regexp.MustCompile("^(Number Delta {26})(associated with the new quote)$")
	text = r2.ReplaceAllString(text, "$1                   $2")

	r3 := regexp.MustCompile("^ (Ask|Bid) Reference {41}The (ask|bid) reference number delta$")
	if r3.MatchString(text) {
		scanner.Scan()
		text = superimposeStrings(text, scanner.Text())
	}

	r4 := regexp.MustCompile("^Total Number of")
	if r4.MatchString(text) {
		text = "Total Number of Reference 5 2 Integer                 The number of single side deletes in this"
		scanner.Scan()
		scanner.Scan()
	}

	r5 := regexp.MustCompile("^Reference {45}The order/quote side reference number")
	if r5.MatchString(text) {
		scanner.Scan()
		scanner.Scan()
		text = ""
	}

	return text
}
Exemple #10
0
func importReader(reader io.Reader, gzipped bool) {
	var scanner *bufio.Scanner
	if gzipped {
		gReader, err := gzip.NewReader(reader)
		if err != nil {
			log.Println("[ERR] My bad! I tried to start uncompressing your archive but failed.")
			log.Println("      Try checking the file, or send me the file so I can check it out.")
			return
		}
		defer gReader.Close()
		log.Println("[OK!] GZip detected, unzipping enabled")
		scanner = bufio.NewScanner(gReader)
	} else {
		scanner = bufio.NewScanner(reader)
	}
	log.Println("[OK!] Reading initialized")
	imported := 0
	skipped := 0
	// Now we scan ୧༼ಠ益ಠ༽୨
	for scanner.Scan() {
		status, _ := importLine(scanner.Text())
		if status {
			imported++
		} else {
			skipped++
		}
	}
	log.Println("[OK!] Reading completed")
	log.Println("      " + strconv.Itoa(imported) + " torrents imported")
	log.Println("      " + strconv.Itoa(skipped) + " torrents skipped")
}
Exemple #11
0
func getNextLine(s *bufio.Scanner) string {
	more := s.Scan()
	if !more {
		checkScanError(s)
	}
	return s.Text()
}
Exemple #12
0
func cd(commandSc *bufio.Scanner, conn net.Conn) {
	if commandSc.Scan() {
		path := commandSc.Text()
		fmt.Println(path)
		cdPath(path, conn)
	}
}
Exemple #13
0
// BuildRetentions build cache storage retention matchers
func (cs *CacheStorage) BuildRetentions(retentionScanner *bufio.Scanner) error {
	cs.retentions = make([]retentionMatcher, 0, 100)

	for retentionScanner.Scan() {
		line := retentionScanner.Text()
		if strings.HasPrefix(line, "#") || strings.Count(line, "=") != 1 {
			continue
		}

		pattern, err := regexp.Compile(strings.TrimSpace(strings.Split(line, "=")[1]))
		if err != nil {
			return err
		}

		retentionScanner.Scan()
		line = retentionScanner.Text()
		retentions := strings.TrimSpace(strings.Split(line, "=")[1])
		retention, err := rawRetentionToSeconds(retentions[0:strings.Index(retentions, ":")])
		if err != nil {
			return err
		}

		cs.retentions = append(cs.retentions, retentionMatcher{
			pattern:   pattern,
			retention: retention,
		})
	}
	return retentionScanner.Err()
}
Exemple #14
0
func parseFile(scanner *bufio.Scanner) (map[string]string, error) {
	translations := make(map[string]string)
	definitionRegexp := regexp.MustCompile(`^([\d\w\-_]+)\s*=\s*(".*")\s*(?:\#.*)?$`)
	emptyLineRegexp := regexp.MustCompile(`^(|\s*(\#.*)?)$`)

	for lineNumber := 1; scanner.Scan(); lineNumber++ {
		line := scanner.Text()

		if emptyLineRegexp.MatchString(line) {
			continue
		}

		matches := definitionRegexp.FindStringSubmatch(line)
		if len(matches) != 3 {
			return nil, errors.New(fmt.Sprintf("Malformed line :%d (%q)", lineNumber, line))
		}

		unquoted, err := strconv.Unquote(matches[2])
		if err != nil {
			return nil, errors.New(fmt.Sprintf("Malformed string :%d (%q)", lineNumber, line))
		}
		if _, ok := translations[matches[1]]; ok {
			return nil, errors.New(fmt.Sprintf("Multiple definitions of key %q", matches[1]))
		}

		translations[matches[1]] = unquoted
	}
	return translations, nil
}
Exemple #15
0
// Read reads a line from the scanner, returns true if line was read
func Read(s *bufio.Scanner, args ...interface{}) bool {
	if s.Scan() {
		_, err := fmt.Sscan(s.Text(), args...)
		CheckErr(err)
		return true
	}
	return false
}
func (e *execStreamer) handleStderr(stderrScanner *bufio.Scanner) {
	defer e.recoverPanic("handleStderr")
	defer e.stdOutAndErrWaitGroup.Done()
	for stderrScanner.Scan() {
		fmt.Fprintf(e.StderrWriter, "%s%s\n", e.StderrPrefix, stderrScanner.Text())
		e.flushIfEnabled(e.StderrWriter)
	}
}
Exemple #17
0
func read(scanner *bufio.Scanner) (string, error) {
	err := scanner.Err()
	if err != nil {
		return "", err
	}

	return scanner.Text(), nil
}
Exemple #18
0
func scanUint(scan *bufio.Scanner) int {
	scan.Scan()
	val, err := strconv.ParseUint(scan.Text(), 10, 32)
	if err != nil {
		log.Fatal(err)
	}
	return int(val)
}
Exemple #19
0
func mustAdvanceTo(token string, scanner *bufio.Scanner, die func()) {
	for scanner.Scan() {
		if scanner.Text() == token {
			return
		}
	}
	die()
}
func confirm(serviceName, nameSpace string, scanner *bufio.Scanner) bool {
	fmt.Printf("Generating Microservice template: %s/%s in GOPATH\n", nameSpace, serviceName)
	fmt.Printf("Is this correct? (y|n)\n")
	scanner.Scan()
	line := scanner.Text()

	return line == "y"
}
func includeStatsD(scanner *bufio.Scanner) bool {
	fmt.Printf("Include StatsD? (y|n)\n")
	scanner.Scan()
	line := scanner.Text()
	fmt.Println("")

	return line == "y"
}
Exemple #22
0
func parseTestCase(scanner *bufio.Scanner) (uint64, uint64) {
	scanner.Scan()
	pair := strings.Split(scanner.Text(), " ")

	l, _ := strconv.ParseUint(pair[0], 10, 64)
	u, _ := strconv.ParseUint(pair[1], 10, 64)
	return l, u
}
Exemple #23
0
func read(n int, s *bufio.Scanner) []int {
	ns := make([]int, n)
	for i := range ns {
		s.Scan()
		ns[i], _ = strconv.Atoi(s.Text())
	}
	return ns
}
Exemple #24
0
func parseTestCase(scanner *bufio.Scanner) (int, int) {
	scanner.Scan()
	pair := strings.Split(scanner.Text(), " ")

	v, _ := strconv.Atoi(pair[0])
	d, _ := strconv.Atoi(pair[1])
	return v, d
}
Exemple #25
0
func ReadInt(s *bufio.Scanner) int {
	// call s.Split(bufio.ScanWords) before calling this method

	s.Scan()
	i, _ := strconv.Atoi(s.Text())

	return i
}
Exemple #26
0
func mustAdvanceTo(token string, scanner *bufio.Scanner, die func()) {
	for scanner.Scan() {
		if strings.HasPrefix(scanner.Text(), token) {
			return
		}
	}
	die()
}
Exemple #27
-1
func getContinueInput(scanner *bufio.Scanner) bool {
	ok := scanner.Scan()
	if !ok {
		return false
	}
	return scanner.Text() == "y"
}
Exemple #28
-1
func PushFile(host string, port int, fname string) {
	var scanner *bufio.Scanner

	if len(fname) == 0 {
		scanner = bufio.NewScanner(os.Stdin)
	} else {
		file, err := os.Open(fname)
		defer file.Close()

		if err != nil {
			fmt.Fprintln(os.Stderr, "ERROR", err)
			return
		}

		scanner = bufio.NewScanner(file)
	}

	addr := fmt.Sprintf("%s:%d", host, port)
	conn, err := net.Dial("tcp", addr)

	if err != nil {
		fmt.Fprintln(os.Stderr, "ERROR:", err)
		return
	}

	for scanner.Scan() {
		fmt.Fprintln(conn, scanner.Text())
	}
}
Exemple #29
-21
func GetNextLine(i int, s *bufio.Scanner) string {
	ok := s.Scan()
	if !ok {
		panic(fmt.Sprintf("EOF. expected more lines during problem %v", i))
	}
	return s.Text()
}
Exemple #30
-25
func orderedRemoval(scanner *bufio.Scanner) {
	var entries Entries
	rows := 0
	count := 0
	for scanner.Scan() {
		line := scanner.Text()
		parts := strings.Split(line, " ")
		parts = removeSpaces(parts)
		for col, str := range parts {
			entry := Entry{atoi(str), rows, col}
			entries = append(entries, entry)
			count++
		}
		rows++
	}
	fmt.Printf("Matrix dimensions: rows=%d, cols=%d\n", rows, count/rows)
	sort.Sort(entries)
	best := 0
	for i := 0; i < 1000; i++ {
		sum := run(entries, rows, count/rows)
		if sum > best {
			fmt.Printf("sum=%d, i=%d\n", sum, i)
			best = sum
		}
	}

}