util/datamanager.lua
changeset 13186 c48ae06e24d6
parent 13185 87487056bccb
child 13187 33b114fbb5de
equal deleted inserted replaced
13185:87487056bccb 13186:c48ae06e24d6
   327 	local fh, err, errno = io_open(filename);
   327 	local fh, err, errno = io_open(filename);
   328 	if not fh then
   328 	if not fh then
   329 		return fh, err, errno;
   329 		return fh, err, errno;
   330 	end
   330 	end
   331 	local prev_pos = 0; -- position before reading
   331 	local prev_pos = 0; -- position before reading
   332 	local last_item_start = 0;
   332 	local last_item_start = nil;
   333 
   333 
   334 	if items and items[1] then
   334 	if items and items[1] then
   335 		local last_item = items[#items];
   335 		local last_item = items[#items];
   336 		last_item_start = fh:seek("set", last_item.start + last_item.length);
   336 		last_item_start = fh:seek("set", last_item.start + last_item.length);
   337 	else
   337 	else
   338 		items = {};
   338 		items = {};
   339 	end
   339 	end
   340 
   340 
   341 	for line in fh:lines() do
   341 	for line in fh:lines() do
   342 		if line:sub(1, 4) == "item" then
   342 		if line:sub(1, 4) == "item" then
   343 			if prev_pos ~= 0 then
   343 			if prev_pos ~= 0 and last_item_start then
   344 				t_insert(items, { start = last_item_start; length = prev_pos - last_item_start });
   344 				t_insert(items, { start = last_item_start; length = prev_pos - last_item_start });
   345 			end
   345 			end
   346 			last_item_start = prev_pos
   346 			last_item_start = prev_pos
   347 		end
   347 		end
   348 		-- seek position is at the start of the next line within each loop iteration
   348 		-- seek position is at the start of the next line within each loop iteration