Difference between revisions of "Source code: users.pal"

From PROSE Programming Language - Wiki
Jump to: navigation, search
(Created page with '<pre> % % Read users from stdin (/etc/passwd file) and populate one container % in the nexus for each username listed % ._init func/def [main], &[.main] local/rtn .main % % Prep…')
 
(Update for 0.7.0)
Line 12: Line 12:
 
% Preparation
 
% Preparation
 
%
 
%
reg/load P10, ![.prose.io]
+
reg/load P10, ![.prose.sys.io]
 
attr/load P11, [psStreamIn], P13, [description]
 
attr/load P11, [psStreamIn], P13, [description]
 
class/load P12, [psContainer]
 
class/load P12, [psContainer]

Revision as of 14:23, 27 December 2010

%
% Read users from stdin (/etc/passwd file) and populate one container
% in the nexus for each username listed
%
._init
func/def	[main], &[.main]
local/rtn

.main
%
% Preparation
%
reg/load	P10, ![.prose.sys.io]
attr/load	P11, [psStreamIn], P13, [description]
class/load	P12, [psContainer]

%
% Create top-level container for the users
%
obj/def		P8
class/add	P8, P12
obj/commit	![.prose], [users], P8
reg/load	P9, ![.prose.users]

.loop
%
% Load next line from stdin
%
attr/copy	P0, P10, P11
reg/jmpeq	&[.eof], P0, NULL

%
% Extract username (field 1, up to first colon)
%
reg/scan	P1, P0, [:]
reg/copy	P2, (P0, #0, P1)

%
% Extract GCOS description (field 5)
%
reg/load	A, #3

.loop2
op/incr		P1
reg/scan	P1, P0, [:], P1
op/decr
reg/jmpneq	&[.loop2], A, #0

op/incr		P1
reg/scan	A, P0, [:], P1
opa/sub		P1
reg/copy	P3, (P0, P1, A)
reg/clr		P0

%
% Create a container for this user
%
obj/def		P8
class/add	P8, P12
attr/add	P8, P13, P3
obj/commit	P9, P2, P8
reg/clr		P2
local/jmp	&[.loop]

.eof
%
% Read the user objects and display to stdout
%
attr/load	P11, [psStreamOut], P12, [pn]
reg/load	P0, (P9)

.loop3
reg/load	P1, (P0)
reg/jmpeq	&[.exit], P1, NULL
attr/copy	P2, P1, P12
attr/copy	P3, P1, P13
reg/copy	P4, [User '], P2, [' (], P3, [)\n]
attr/mod	P10, P11, P4
reg/clr		P2, P3
local/jmp	&[.loop3]

.exit
func/rtn