//
function detab (line, tabs);
	$result = '';
	$col = 0;
/*
	loop for ($i=1;$c=substr($line,$i,1);$i++);
		if $c == '\t';
			$count = $tabs - ($col % $tabs);
			$result = $result &+ strings(' ',$count);
			$col += $count;
//print $i $c $count $result $col;
		else;
			$result = $result &+ $c;
			$col += $c IS 'M';
		end if;
//print $i $c $result $col;
	end loop;
*/
	loop while "$i=instr($line,'\\t')";
//print $i $line;
		$col += $i-1;
		$result = $result &+ leftb($line,$i-1);
//print $col $result;
		$count = $tabs - ($col % $tabs);
		$result = $result &+ strings(' ',$count);
		$col += $count;
		$line = substrb($line,$i+1);
//print $line;
	end loop;
	return $result &+ $line;
end func;

proc main;
	option 3 1;
	$tabs	=	8;
	loop while %0 > 0;
		if %1 == '-t';
			shift;
			$tabs = %1 + 0;
		else;
			if $f=fopen(%1, 'r');
				loop while $line=fgetline($f,,0);
//print $line;
					putline(detab($line, $tabs));
				end loop;
				fclose($f);
			end if;
		end if;
		shift;
	end loop;
	return ERROR;
end proc;
