source: libcfa/src/algorithms/range_iterator.cfa @ 9d8124f

ADTast-experimentalenumpthread-emulationqualifiedEnum
Last change on this file since 9d8124f was 8e658241, checked in by Thierry Delisle <tdelisle@…>, 3 years ago

Minor fix and super barebones test.

  • Property mode set to 100644
File size: 1.4 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// range_iterator.cfa --
8//
9// Author           : Thierry Delisle
10// Created On       : Tue Nov 30 13:06:22 2021
11// Last Modified By :
12// Last Modified On :
13// Update Count     :
14//
15
16#include "range_iterator.hfa"
17
18#include <stdio.h>
19
20#include <fstream.hfa>
21
22void main(RangeIter & this) {
23        for() {
24                this._start = -1;
25                this._stop = -1;
26                int start_len = -1, stop_len = -1;
27                int ret = sscanf(this.text, "%u%n-%u%n", &this._start, &start_len, &this._stop, &stop_len);
28                switch(ret) {
29                case 0:
30                        // Not a range, maybe a comma?
31                        if(this.text[0] == ',') {
32                                this.text ++;
33                                continue;
34                        }
35
36                        serr | "Error: unexpected character in next range: '" | this.text |"'";
37                        exit(2);
38                case 1:
39                        this.text += start_len;
40                        // Only one value, push it!
41                        this.com = this._start;
42                        suspend;
43                        break;
44                case 2:
45                        if(this._start > this._stop) {
46                                serr | "Error: next range out of order '" | this.text |"'";
47                                exit(2);
48                        }
49                        this.text += stop_len;
50                        for(this.com = this._start; this.com <= this._stop; this.com++) {
51                                suspend;
52                        }
53                        break;
54                default:
55                        serr | "Error reading next block: '" | this.text |"', returned" | ret;
56                        exit(2);
57                }
58
59                if(this.text[0] == '\0') break;
60        }
61        this.com = -1;
62}
Note: See TracBrowser for help on using the repository browser.