summary refs log tree commit diff stats
path: root/doc/pydoc/ranger.ext.human_readable.html
blob: a4d71ea912ae8b63ee772c2fd5c12c3d8326706a (plain) (blame)
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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module ranger.ext.human_readable</title>
</head><body bgcolor="#f0f0f8">

<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong><a href="ranger.html"><font color="#ffffff">ranger</font></a>.<a href="ranger.ext.html"><font color="#ffffff">ext</font></a>.human_readable</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/hut/ranger/ranger/ext/human_readable.py">/home/hut/ranger/ranger/ext/human_readable.py</a></font></td></tr></table>
    <p><tt>#&nbsp;Copyright&nbsp;(C)&nbsp;2009,&nbsp;2010&nbsp;&nbsp;Roman&nbsp;Zimbelmann&nbsp;&lt;romanz@lavabit.com&gt;<br>
#<br>
#&nbsp;This&nbsp;program&nbsp;is&nbsp;free&nbsp;software:&nbsp;you&nbsp;can&nbsp;redistribute&nbsp;it&nbsp;and/or&nbsp;modify<br>
#&nbsp;it&nbsp;under&nbsp;the&nbsp;terms&nbsp;of&nbsp;the&nbsp;GNU&nbsp;General&nbsp;Public&nbsp;License&nbsp;as&nbsp;published&nbsp;by<br>
#&nbsp;the&nbsp;Free&nbsp;Software&nbsp;Foundation,&nbsp;either&nbsp;version&nbsp;3&nbsp;of&nbsp;the&nbsp;License,&nbsp;or<br>
#&nbsp;(at&nbsp;your&nbsp;option)&nbsp;any&nbsp;later&nbsp;version.<br>
#<br>
#&nbsp;This&nbsp;program&nbsp;is&nbsp;distributed&nbsp;in&nbsp;the&nbsp;hope&nbsp;that&nbsp;it&nbsp;will&nbsp;be&nbsp;useful,<br>
#&nbsp;but&nbsp;WITHOUT&nbsp;ANY&nbsp;WARRANTY;&nbsp;without&nbsp;even&nbsp;the&nbsp;implied&nbsp;warranty&nbsp;of<br>
#&nbsp;MERCHANTABILITY&nbsp;or&nbsp;FITNESS&nbsp;FOR&nbsp;A&nbsp;PARTICULAR&nbsp;PURPOSE.&nbsp;&nbsp;See&nbsp;the<br>
#&nbsp;GNU&nbsp;General&nbsp;Public&nbsp;License&nbsp;for&nbsp;more&nbsp;details.<br>
#<br>
#&nbsp;You&nbsp;should&nbsp;have&nbsp;received&nbsp;a&nbsp;copy&nbsp;of&nbsp;the&nbsp;GNU&nbsp;General&nbsp;Public&nbsp;License<br>
#&nbsp;along&nbsp;with&nbsp;this&nbsp;program.&nbsp;&nbsp;If&nbsp;not,&nbsp;see&nbsp;&lt;<a href="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</a>&gt;.</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#eeaa77">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
    
<tr><td bgcolor="#eeaa77"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl><dt><a name="-human_readable"><strong>human_readable</strong></a>(byte, seperator<font color="#909090">=' '</font>)</dt></dl>
</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
    
<tr><td bgcolor="#55aa55"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><strong>MAX_EXPONENT</strong> = 5<br>
<strong>ONE_KB</strong> = 1024<br>
<strong>UNITS</strong> = 'BKMGTP'</td></tr></table>
</body></html>
ass="w"> Type_ordinal["array"] || inst.products.at(j).types.at(2) != Type_ordinal["location"]) { raise << "slot 0 should always have type address:array:location, but is " << inst.products.at(j).to_string() << '\n'; continue; } vector<string> s = property(inst.products.at(j), "names"); if (s.empty()) raise << "slot 0 requires a /names property in recipe " << Recipe[r].name << die(); if (SIZE(s) > 1) raise << "slot 0 should have a single value in /names, got " << inst.products.at(j).to_string() << '\n'; string surrounding_recipe_name = s.at(0); if (Surrounding_space.find(r) != Surrounding_space.end() && Surrounding_space[r] != Recipe_ordinal[surrounding_recipe_name]) { raise << "recipe " << Recipe[r].name << " can have only one 'surrounding' recipe but has " << Recipe[Surrounding_space[r]].name << " and " << surrounding_recipe_name << '\n'; continue; } trace("name") << "recipe " << Recipe[r].name << " is surrounded by " << surrounding_recipe_name; Surrounding_space[r] = Recipe_ordinal[surrounding_recipe_name]; } } } //: Once surrounding spaces are available, transform_names uses them to handle //: /space properties. :(replace{} "long long int lookup_name(const reagent& r, const recipe_ordinal default_recipe)") long long int lookup_name(const reagent& x, const recipe_ordinal default_recipe) { //? cout << "AAA " << default_recipe << " " << Recipe[default_recipe].name << '\n'; //? 2 //? cout << "AAA " << x.to_string() << '\n'; //? 1 if (!has_property(x, "space")) { if (Name[default_recipe].empty()) raise << "name not found: " << x.name << '\n' << die(); return Name[default_recipe][x.name]; } vector<string> p = property(x, "space"); if (SIZE(p) != 1) raise << "/space property should have exactly one (non-negative integer) value\n"; long long int n = to_integer(p.at(0)); assert(n >= 0); recipe_ordinal surrounding_recipe = lookup_surrounding_recipe(default_recipe, n); set<recipe_ordinal> done; vector<recipe_ordinal> path; return lookup_name(x, surrounding_recipe, done, path); } // If the recipe we need to lookup this name in doesn't have names done yet, // recursively call transform_names on it. long long int lookup_name(const reagent& x, const recipe_ordinal r, set<recipe_ordinal>& done, vector<recipe_ordinal>& path) { if (!Name[r].empty()) return Name[r][x.name]; if (done.find(r) != done.end()) { raise << "can't compute address of " << x.to_string() << " because "; for (long long int i = 1; i < SIZE(path); ++i) { raise << path.at(i-1) << " requires computing names of " << path.at(i) << '\n'; } raise << path.at(SIZE(path)-1) << " requires computing names of " << r << "..ad infinitum\n" << die(); return 0; } done.insert(r); path.push_back(r); transform_names(r); // Not passing 'done' through. Might this somehow cause an infinite loop? assert(!Name[r].empty()); return Name[r][x.name]; } recipe_ordinal lookup_surrounding_recipe(const recipe_ordinal r, long long int n) { if (n == 0) return r; if (Surrounding_space.find(r) == Surrounding_space.end()) { raise << "don't know surrounding recipe of " << Recipe[r].name << '\n'; return 0; } assert(Surrounding_space[r]); return lookup_surrounding_recipe(Surrounding_space[r], n-1); } //: weaken use-before-set warnings just a tad :(replace{} "bool already_transformed(const reagent& r, const map<string, long long int>& names)") bool already_transformed(const reagent& r, const map<string, long long int>& names) { if (has_property(r, "space")) { vector<string> p = property(r, "space"); assert(SIZE(p) == 1); if (p.at(0) != "0") return true; } return names.find(r.name) != names.end(); }