| |
| /pliant/language/context/processor2.pli |
| |
| 1 |
# Copyright Hubert Tonneau hubert.tonneau@pliant.cx | |
| 2 |
# | |
| 3 |
# This program is free software; you can redistribute it and/or | |
| 4 |
# modify it under the terms of the GNU General Public License version 2 | |
| 5 |
# as published by the Free Software Foundation. | |
| 6 |
# | |
| 7 |
# This program is distributed in the hope that it will be useful, | |
| 8 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 9 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 10 |
# GNU General Public License for more details. | |
| 11 |
# | |
| 12 |
# You should have received a copy of the GNU General Public License | |
| 13 |
# version 2 along with this program; if not, write to the Free Software | |
| 14 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
| 15 |
| |
| 16 |
scope "/pliant/language/" "/pliant/install/" | |
| 17 |
module "/pliant/install/ring2.pli" | |
| 18 |
| |
| 19 |
| |
| 20 |
function test_processor_count -> count | |
| 21 |
arg Int count | |
| 22 |
var Int handle := file_open "/pliant_security/this_computer.pdb" 1 | |
| 23 |
if handle<>(-1) | |
| 24 |
while (file_readline handle (var Str l)) | |
| 25 |
if (l parse "<pdata path=[dq]/env/hardware/processor/count[dq]>" count "</pdata>") | |
| 26 |
file_close handle | |
| 27 |
return | |
| 28 |
file_close handle | |
| 29 |
if os_api="posix" and count=0 | |
| 30 |
if (os_sysctl:"hw.ncpu" parse count) | |
| 31 |
return | |
| 32 |
count := 0 | |
| 33 |
var Int handle := file_open "/proc/cpuinfo" 1 | |
| 34 |
if handle<>(-1) | |
| 35 |
var Str line := "" ; var Str c := " " | |
| 36 |
while (file_read handle c:characters 1)=1 | |
| 37 |
if c="[lf]" | |
| 38 |
if (line 0 "processor":len)="processor" and ((line "processor":len 1)=" " or (line "processor":len 1)="[tab]") | |
| 39 |
count := count+1 | |
| 40 |
line := "" | |
| 41 |
else | |
| 42 |
line := line+c | |
| 43 |
file_close handle | |
| 44 |
if count=0 | |
| 45 |
count := 1 | |
| 46 |
| |
| 47 |
| |
| 48 |
public | |
| 49 |
constant processor_count test_processor_count | |
| |