~ubuntu-branches/ubuntu/saucy/ricochet/saucy

« back to all changes in this revision

Viewing changes to ricochet-0.1/svg/bin2cstring.5c

  • Committer: Package Import Robot
  • Author(s): Keith Packard
  • Date: 2012-06-11 13:37:57 UTC
  • Revision ID: package-import@ubuntu.com-20120611133757-zn0ukd22vz56ymto
Tags: 0.3
* Improve appearance of board
* Fix user list when removing/adding same user

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
void
2
 
bin_to_5cstring(file f)
3
 
{
4
 
        bool was_escape = false;
5
 
        putchar ('"');
6
 
        while (!File::end(f)) {
7
 
                int c = File::getc (f);
8
 
 
9
 
                if (Ctype::isprint (c) && c != '"' && (!Ctype::isdigit(c) || !was_escape)) {
10
 
                        printf ("%c", c);
11
 
                        was_escape = false;
12
 
                } else {
13
 
                        was_escape = false;
14
 
                        switch (c) {
15
 
                        case '\n':
16
 
                                printf ("\\n");
17
 
                                break;
18
 
                        case '\t':
19
 
                                printf ("\\t");
20
 
                                break;
21
 
                        case '"':
22
 
                                printf ("\\\042");
23
 
                                break;
24
 
                        default:
25
 
                                printf ("\\%03o", c);
26
 
                                was_escape = true;
27
 
                        }
28
 
                }
29
 
        }
30
 
        putchar('"');
31
 
}
32
 
 
33
 
public string filename(string path) 
34
 
/*
35
 
 * Return the file portion of 'path'
36
 
 */
37
 
{
38
 
        int n = String::rindex(path, "/");
39
 
        if (n == -1)
40
 
                return path;
41
 
        int len = String::length(path);
42
 
        return String::substr(path, n+1, len-(n+1));
43
 
}
44
 
 
45
 
void
46
 
main()
47
 
{
48
 
        printf("extend namespace Client {\n    public namespace SVG {\n");
49
 
        for (int i = 1; i < dim(argv); i++) {
50
 
                twixt (file f = File::open(argv[i], "r"); File::close(f)) {
51
 
                        string base = filename(argv[i]);
52
 
                        string name = String::split(base, ".")[0];
53
 
                        printf ("\tpublic string %s = ", name);
54
 
                        bin_to_5cstring(f);
55
 
                        printf (";\n");
56
 
                }
57
 
        }
58
 
        printf ("   }\n}\n");
59
 
}
60
 
 
61
 
main();
62