Difference between revisions of "Source code: users.pal"
From PROSE Programming Language - Wiki
(Update for 0.7.0) |
(Update for 0.11.0) |
||
(One intermediate revision by the same user not shown) | |||
Line 5: | Line 5: | ||
% | % | ||
._init | ._init | ||
− | func/def [main], &[.main] | + | func/def [main], &[.main] |
local/rtn | local/rtn | ||
Line 12: | Line 12: | ||
% Preparation | % Preparation | ||
% | % | ||
− | reg/load P10, ![.prose.sys.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] |
% | % | ||
% Create top-level container for the users | % Create top-level container for the users | ||
% | % | ||
− | obj/def | + | obj/def P8 |
− | class/add P8, P12 | + | class/add P8, P12 |
− | obj/commit ![.prose], [users], P8 | + | obj/commit ![.prose], [users], P8 |
− | reg/load P9, ![.prose.users] | + | reg/load P9, ![.prose.users] |
.loop | .loop | ||
Line 28: | Line 28: | ||
% Load next line from stdin | % Load next line from stdin | ||
% | % | ||
− | attr/copy P0, P10, P11 | + | attr/copy P0, P10, P11 |
− | reg/jmpeq &[.eof], P0, NULL | + | reg/jmpeq &[.eof], P0, NULL |
% | % | ||
% Extract username (field 1, up to first colon) | % Extract username (field 1, up to first colon) | ||
% | % | ||
− | reg/ | + | reg/xscan P1, P0, [:] |
− | reg/copy P2, (P0, #0, P1) | + | reg/copy P2, (P0, #0, P1) |
% | % | ||
− | % Extract | + | % Extract GECOS description (field 5) |
% | % | ||
− | reg/load A, #3 | + | reg/load A, #3 |
.loop2 | .loop2 | ||
− | op/incr | + | op/incr P1 |
− | reg/ | + | reg/xscan P1, P0, [:], P1 |
op/decr | op/decr | ||
− | reg/jmpneq &[.loop2], A, #0 | + | reg/jmpneq &[.loop2], A, #0 |
− | op/incr | + | op/incr P1 |
− | reg/ | + | reg/xscan P4, P0, [:], P1 |
− | + | opx/sub P4, P4, P1 | |
− | reg/copy P3, (P0, P1, | + | reg/copy P3, (P0, P1, P4) |
− | reg/clr | + | reg/clr P0 |
% | % | ||
% Create a container for this user | % Create a container for this user | ||
% | % | ||
− | obj/def | + | obj/def P8 |
− | class/add P8, P12 | + | class/add P8, P12 |
− | attr/add P8, P13, P3 | + | attr/add P8, P13, P3 |
− | obj/commit P9, P2, P8 | + | obj/commit P9, P2, P8 |
− | reg/clr | + | reg/clr P2 |
− | local/jmp &[.loop] | + | local/jmp &[.loop] |
.eof | .eof | ||
Line 68: | Line 68: | ||
% Read the user objects and display to stdout | % Read the user objects and display to stdout | ||
% | % | ||
− | attr/load P11, [psStreamOut], P12, [pn] | + | attr/load P11, [psStreamOut], P12, [pn] |
− | reg/load P0, (P9) | + | reg/load P0, (P9) |
.loop3 | .loop3 | ||
− | reg/load P1, (P0) | + | reg/load P1, (P0) |
− | reg/jmpeq &[.exit], P1, NULL | + | reg/jmpeq &[.exit], P1, NULL |
− | attr/copy P2, P1, P12 | + | attr/copy P2, P1, P12 |
− | attr/copy P3, P1, P13 | + | attr/copy P3, P1, P13 |
− | reg/copy P4, [User '], P2, [' (], P3, [)\n] | + | reg/copy P4, [User '], P2, [' (], P3, [)\n] |
− | attr/mod P10, P11, P4 | + | attr/mod P10, P11, P4 |
− | reg/clr | + | reg/clr P2, P3 |
− | local/jmp &[.loop3] | + | local/jmp &[.loop3] |
.exit | .exit | ||
func/rtn | func/rtn | ||
</pre> | </pre> |
Latest revision as of 06:15, 2 October 2017
% % 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/xscan P1, P0, [:] reg/copy P2, (P0, #0, P1) % % Extract GECOS description (field 5) % reg/load A, #3 .loop2 op/incr P1 reg/xscan P1, P0, [:], P1 op/decr reg/jmpneq &[.loop2], A, #0 op/incr P1 reg/xscan P4, P0, [:], P1 opx/sub P4, P4, P1 reg/copy P3, (P0, P1, P4) 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