From eaeb955212eb3b133fd98d98457f17bfea8891d1 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 6 Aug 2015 19:15:57 -0700 Subject: 1949 --- html/082persist.cc.html | 57 +++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 28 deletions(-) (limited to 'html/082persist.cc.html') diff --git a/html/082persist.cc.html b/html/082persist.cc.html index 0984d488..b5770552 100644 --- a/html/082persist.cc.html +++ b/html/082persist.cc.html @@ -15,11 +15,12 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } .Constant { color: #00a0a0; } .cSpecial { color: #008000; } +.PreProc { color: #c000c0; } +.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } -.Identifier { color: #804000; } -.PreProc { color: #c000c0; } .CommentedCode { color: #6c6c6c; } +.Identifier { color: #804000; } --> @@ -40,42 +41,42 @@ RESTORE, :(before "End Primitive Recipe Numbers") Recipe_ordinal["restore"] = RESTORE; :(before "End Primitive Recipe Implementations") -case RESTORE: { - if (SIZE(ingredients) != 1) { +case RESTORE: { + if (SIZE(ingredients) != 1) { raise << current_recipe_name() << ": 'restore' requires exactly one ingredient, but got " << current_instruction().to_string() << '\n' << end(); break; } string filename; - if (is_literal_string(current_instruction().ingredients.at(0))) { + if (is_literal_string(current_instruction().ingredients.at(0))) { filename = current_instruction().ingredients.at(0).name; } - else if (is_mu_string(current_instruction().ingredients.at(0))) { + else if (is_mu_string(current_instruction().ingredients.at(0))) { filename = read_mu_string(ingredients.at(0).at(0)); } - else { + else { raise << current_recipe_name() << ": first ingredient of 'restore' should be a string, but got " << current_instruction().ingredients.at(0).to_string() << '\n' << end(); break; } - if (Current_scenario) break; // do nothing in tests + if (Current_scenario) break; // do nothing in tests string contents = slurp("lesson/"+filename); products.resize(1); - if (contents.empty()) + if (contents.empty()) products.at(0).push_back(0); - else + else products.at(0).push_back(new_mu_string(contents)); break; } :(code) -string slurp(const string& filename) { +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()) { + 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; @@ -90,24 +91,24 @@ SAVE, :(before "End Primitive Recipe Numbers") Recipe_ordinal["save"] = SAVE; :(before "End Primitive Recipe Implementations") -case SAVE: { - if (SIZE(ingredients) != 2) { +case SAVE: { + if (SIZE(ingredients) != 2) { raise << current_recipe_name() << ": 'save' requires exactly two ingredients, but got " << current_instruction().to_string() << '\n' << end(); break; } - if (Current_scenario) break; // do nothing in tests + if (Current_scenario) break; // do nothing in tests string filename; - if (is_literal_string(current_instruction().ingredients.at(0))) { + if (is_literal_string(current_instruction().ingredients.at(0))) { filename = current_instruction().ingredients.at(0).name; } - else if (is_mu_string(current_instruction().ingredients.at(0))) { + else if (is_mu_string(current_instruction().ingredients.at(0))) { filename = read_mu_string(ingredients.at(0).at(0)); } - else { + else { raise << current_recipe_name() << ": first ingredient of 'save' should be a string, but got " << current_instruction().ingredients.at(0).to_string() << '\n' << end(); break; } - if (!scalar(ingredients.at(1))) { + if (!scalar(ingredients.at(1))) { raise << current_recipe_name() << ": second ingredient of 'save' should be an address:array:character, but got " << current_instruction().ingredients.at(1).to_string() << '\n' << end(); break; } @@ -115,22 +116,22 @@ case SAVE: { string contents = read_mu_string(ingredients.at(1).at(0)); fout << contents; fout.close(); - if (!exists("lesson/.git")) break; + if (!exists("lesson/.git")) break; // bug in git: git diff -q messes up --exit-code // explicitly say '--all' for git 1.9 - int status = system("cd lesson; git add --all .; git diff HEAD --exit-code >/dev/null || git commit -a -m . >/dev/null"); - if (status != 0) + int status = system("cd lesson; git add --all .; 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; +bool exists(const string& filename) { + struct stat dummy; return 0 == stat(filename.c_str(), &dummy); } -string to_string(long long int x) { +string to_string(long long int x) { ostringstream tmp; tmp << x; return tmp.str(); -- cgit 1.4.1-2-gfad0