about summary refs log tree commit diff stats
ModeNameSize
-rw-r--r--LICENSE1120log stats plain blame
-rw-r--r--Makefile1425log stats plain blame
-rw-r--r--README1011log stats plain blame
-rw-r--r--bar.c811log stats plain blame
-rw-r--r--client.c4024log stats plain blame
-rw-r--r--cmd.c454log stats plain blame
-rw-r--r--config.h303log stats plain blame
-rw-r--r--config.mk534log stats plain blame
-rw-r--r--draw.c3972log stats plain blame
-rw-r--r--draw.h866log stats plain blame
-rw-r--r--event.c4345log stats plain blame
-rw-r--r--font.c1927log stats plain blame
-rw-r--r--gridmenu.11645log stats plain blame
-rw-r--r--gridwm.1280log stats plain blame
-rw-r--r--kb.c1315log stats plain blame
-rw-r--r--menu.c9198log stats plain blame
-rw-r--r--mouse.c2893log stats plain blame
-rw-r--r--util.c2136log stats plain blame
-rw-r--r--util.h763log stats plain blame
-rw-r--r--wm.c7085log stats plain blame
-rw-r--r--wm.h1921log stats plain blame
18 13:48:49 -0700 1814 - save code in editor' href='/akkartik/mu/commit/082persist.cc?h=hlt&id=13ba3defe91b4de6ab3da7e937ee448c49909725'>13ba3def ^
35064671 ^
13ba3def ^

5aa38b52 ^






5c7ed3d6 ^





5aa38b52 ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
                            

                                          

                                             
        
                                        
                                    
                                                
               
                                 
                                                                                                                 
                     







                                                                 




                                      
                                     











                                                                
                                          









                                                
                                                                                                                
                                                                 

                                                           

                                              
                                                                                                                
                                                            

                   
                                    
                                                  
                                                                                                                     
                  
                                                                       

        






                                             





                                   

                        
//: Dead simple persistence.
//:   'restore' - reads string from a file
//:   'save' - writes string to a file

:(before "End Primitive Recipe Declarations")
RESTORE,
:(before "End Primitive Recipe Numbers")
Recipe_ordinal["restore"] = RESTORE;
:(before "End Primitive Recipe Implementations")
case RESTORE: {
  if (!scalar(ingredients.at(0)))
    raise << "restore: illegal operand " << current_instruction().ingredients.at(0).to_string() << '\n' << end();
  products.resize(1);
  string filename = current_instruction().ingredients.at(0).name;
  if (!is_literal(current_instruction().ingredients.at(0)))
    filename = to_string(ingredients.at(0).at(0));
  string contents = slurp("lesson/"+filename);
  if (contents.empty())
    products.at(0).push_back(0);
  else
    products.at(0).push_back(new_mu_string(contents));
  break;
}

:(code)
string slurp(const string& filename) {
//?   cerr << filename << '\n'; //? 1
  ostringstream result;
  ifstream fin(filename.c_str());
  fin.peek();
  if (!fin) return result.str();  // don't bother checking errno
  const int N = 1024;
  char buf[N];
  while (!fin.eof()) {
    bzero(buf, N);
    fin.read(buf, N-1);  // leave at least one null
    result << buf;
  }
  fin.close();
//?   cerr << "=> " << result.str(); //? 1
  return result.str();
}

:(before "End Primitive Recipe Declarations")
SAVE,
:(before "End Primitive Recipe Numbers")
Recipe_ordinal["save"] = SAVE;
:(before "End Primitive Recipe Implementations")
case SAVE: {
  if (!scalar(ingredients.at(0)))
    raise << "save: illegal operand 0 " << current_instruction().ingredients.at(0).to_string() << '\n' << end();
  string filename = current_instruction().ingredients.at(0).name;
  if (!is_literal(current_instruction().ingredients.at(0)))
    filename = to_string(ingredients.at(0).at(0));
  ofstream fout(("lesson/"+filename).c_str());
  if (!scalar(ingredients.at(1)))
    raise << "save: illegal operand 1 " << current_instruction().ingredients.at(1).to_string() << '\n' << end();
  string contents = read_mu_string(ingredients.at(1).at(0));
  fout << contents;
  fout.close();
  if (!exists("lesson/.git")) break;
  // bug in git: git diff -q messes up --exit-code
  int status = system("cd lesson; git add .; git diff HEAD --exit-code >/dev/null || git commit -a -m . >/dev/null");
  if (status != 0)
    raise << "error in commit: contents " << contents << '\n' << end();
  break;
}

:(code)
bool exists(const string& filename) {
  struct stat dummy;
  return 0 == stat(filename.c_str(), &dummy);
}

string to_string(long long int x) {
  ostringstream tmp;
  tmp << x;
  return tmp.str();
}

:(before "End Includes")
#include<sys/stat.h>