Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

22
LINES

< > BotCompany Repo | #522 // tryCopyFromParents

Lua code

1  
function tryCopyFromParents(newLines, annotations)
2  
  local pat = "^ *([^ ]+) +(%d+) +(%d+)"
3  
  pid2ann = {}
4  
  for i=1, #newLines do
5  
    if annotations[i] ~= nil and annotations[i] ~= '' then
6  
      local _, _, user, pid, ppid = newLines[i]:find(pat)
7  
      if pid then
8  
        pid2ann[pid] = annotations[i]
9  
        --print("pid2ann", pid, annotations[i])
10  
      end
11  
    end
12  
  end
13  
14  
  for i=1, #newLines do
15  
    if annotations[i] == nil or annotations[i] == '' then
16  
      local _, _, user, pid, ppid = newLines[i]:find(pat)
17  
      if ppid then
18  
        annotations[i] = pid2ann[ppid]
19  
      end
20  
    end
21  
  end
22  
end

test run  test run with input  download  show line numbers   

Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #522
Snippet name: tryCopyFromParents
Eternal ID of this version: #522/1
Text MD5: 6b270f7213600579904bbe234652b21a
Author: stefan
Category:
Type: Lua code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-03-11 18:51:55
Source code size: 623 bytes / 22 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 672 / 160
Referenced in: [show references]