LINUX.ORG.RU

История изменений

Исправление LINUX-ORG-RU, (текущая версия) :

Доделай сам =) (это просто пример)

Перевод файла по предложению, до ближайшей точки берётся блок и до победного.

lua autotrans.lua input.txt output.txt
local help =
[[
Usage:  autotrans input.txt output.txt
]]

local input  = arg[1]
local output = arg[2]

if not input or not output then
   print(help)
   os.exit(1)
end

input  = io.open(input, 'r')
output = io.open(output,'w')

if not input then
   print('Failed open for read',arg[1])
   os.exit(2)
end

if not input then
   print('Failed open for write',arg[2])
   os.exit(3)
end

input = input:read('*a')

function shell_escape(text)
    return "' " .. text:gsub("'", "'\\''") .. " '"
end

for block in input:gmatch('[^%.]+') do
    exec = io.popen("trans   en:ru  -b "..shell_escape(block))
    local result = exec:read('*a')
    output:write(result)
    print(block)
    print('-------------------------------------------------')
    print(result)
    print('-------------------------------------------------')
end

Пример ввода

 Literal strings can be delimited by matching single or double quotes, and can contain the following C-like escape sequences: '\a' (bell), '\b' (backspace), '\f' (form feed), '\n' (newline), '\r' (carriage return), '\t' (horizontal tab), '\v' (vertical tab), '\\' (backslash), '\"' (quotation mark [double quote]), and '\'' (apostrophe [single quote]). Moreover, a backslash followed by a real newline results in a newline in the string. A character in a string can also be specified by its numerical value using the escape sequence \ddd, where ddd is a sequence of up to three decimal digits. (Note that if a numerical escape is to be followed by a digit, it must be expressed using exactly three digits.) Strings in Lua can contain any 8-bit value, including embedded zeros, which can be specified as '\0'.

Literal strings can also be defined using a long format enclosed by long brackets. We define an opening long bracket of level n as an opening square bracket followed by n equal signs followed by another opening square bracket. So, an opening long bracket of level 0 is written as [[, an opening long bracket of level 1 is written as [=[, and so on. A closing long bracket is defined similarly; for instance, a closing long bracket of level 4 is written as ]====]. A long string starts with an opening long bracket of any level and ends at the first closing long bracket of the same level. Literals in this bracketed form can run for several lines, do not interpret any escape sequences, and ignore long brackets of any other level. They can contain anything except a closing bracket of the proper level.

For convenience, when the opening long bracket is immediately followed by a newline, the newline is not included in the string. As an example, in a system using ASCII (in which 'a' is coded as 97, newline is coded as 10, and '1' is coded as 49), the five literal strings below denote the same string:

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]

A numerical constant can be written with an optional decimal part and an optional decimal exponent. Lua also accepts integer hexadecimal constants, by prefixing them with 0x. Examples of valid numerical constants are

     3   3.0   3.1416   314.16e-2   0.31416E1   0xff   0x56

Вывод

Строки-литералы могут быть разделены сопоставлением одинарных или двойных кавычек и могут содержать следующие escape-последовательности в стиле C: ' ' (колокольчик), ' ' (возврат), ' ' (перевод страницы), '
' (новая строка), '
' (возврат каретки), ' ' (горизонтальная табуляция), ' ' (вертикальная табуляция), '\' (обратная косая черта), '\"' (кавычка [двойная кавычка]) и '\'' (апостроф [одинарная кавычка] ])
Более того, обратная косая черта, за которой следует настоящая новая строка, приводит к появлению новой строки в строке.
Символ в строке также можно указать по его числовому значению с помощью escape-последовательности \ddd, где ddd — это последовательность, содержащая до трех десятичных цифр.
(Обратите внимание, что если за числовым escape-символом должна следовать цифра, она должна быть выражена ровно тремя цифрами.
) Строки в Lua могут содержать любое 8-битное значение, включая встроенные нули, которые можно указать как ' '
Литеральные строки также могут быть определены с использованием длинного формата, заключенного в длинные скобки.
Мы определяем открывающую длинную скобку уровня n как открывающую квадратную скобку, за которой следуют n знаков равенства, за которыми следует еще одна открывающая квадратная скобка.
Итак, открывающая длинная скобка уровня 0 записывается как [[, открывающая длинная скобка уровня 1 записывается как [=[, и так далее.
Закрывающая длинная скобка определяется аналогично; например, закрывающая длинная скобка уровня 4 записывается как ]====]
Длинная строка начинается с открывающей длинной скобки любого уровня и заканчивается на первой закрывающей длинной скобке того же уровня.
Литералы в этой форме в квадратных скобках могут занимать несколько строк, не интерпретировать escape-последовательности и игнорировать длинные скобки любого другого уровня.
Они могут содержать что угодно, кроме закрывающей скобки нужного уровня.
Для удобства, когда за открывающей длинной скобкой сразу следует новая строка, новая строка не включается в строку.
Например, в системе, использующей ASCII (в которой «a» кодируется как 97, новая строка кодируется как 10, а «1» кодируется как 49), пять литеральных строк ниже обозначают одну и ту же строку:

     а = 'ало
123 дюйма
     а = "ало
123""
     а = '\97lo 923"'
     а = [[ало
     123 дюйма]]
     а = [==[
     ало
     123 дюйма]==]

Числовая константа может быть записана с необязательной десятичной частью и необязательным десятичным показателем.
Lua также принимает целочисленные шестнадцатеричные константы, добавляя к ним префикс 0x.
Примеры допустимых числовых констант:

     3 3
0 3
1416 314
16e-2 0
31416E1 0xff 0x56

Огрехи неизбежны, нужно потом лоб в лоб сравнивать и рихтовать. И в целом так себе…

Исправление LINUX-ORG-RU, :

Доделай сам =) (это просто пример)

Перевод файла по предложению, до ближайшей точки берётся блок и до победного.

lua autotrans.lua input.txt output.txt
local help =
[[
Usage:  autotrans input.txt output.txt
]]

local input  = arg[1]
local output = arg[2]

if not input or not output then
   print(help)
   os.exit(1)
end

input  = io.open(input, 'r')
output = io.open(output,'w')

if not input then
   print('Failed open for read',arg[1])
   os.exit(2)
end

if not input then
   print('Failed open for write',arg[2])
   os.exit(3)
end

input = input:read('*a')

for block in input:gmatch('[^%.]+') do
    exec = io.popen("trans   en:ru  -b '"..block.."'");
    output:write(exec:read('*a'))
end

Пример ввода

 Literal strings can be delimited by matching single or double quotes, and can contain the following C-like escape sequences: '\a' (bell), '\b' (backspace), '\f' (form feed), '\n' (newline), '\r' (carriage return), '\t' (horizontal tab), '\v' (vertical tab), '\\' (backslash), '\"' (quotation mark [double quote]), and '\'' (apostrophe [single quote]). Moreover, a backslash followed by a real newline results in a newline in the string. A character in a string can also be specified by its numerical value using the escape sequence \ddd, where ddd is a sequence of up to three decimal digits. (Note that if a numerical escape is to be followed by a digit, it must be expressed using exactly three digits.) Strings in Lua can contain any 8-bit value, including embedded zeros, which can be specified as '\0'.

Literal strings can also be defined using a long format enclosed by long brackets. We define an opening long bracket of level n as an opening square bracket followed by n equal signs followed by another opening square bracket. So, an opening long bracket of level 0 is written as [[, an opening long bracket of level 1 is written as [=[, and so on. A closing long bracket is defined similarly; for instance, a closing long bracket of level 4 is written as ]====]. A long string starts with an opening long bracket of any level and ends at the first closing long bracket of the same level. Literals in this bracketed form can run for several lines, do not interpret any escape sequences, and ignore long brackets of any other level. They can contain anything except a closing bracket of the proper level.

For convenience, when the opening long bracket is immediately followed by a newline, the newline is not included in the string. As an example, in a system using ASCII (in which 'a' is coded as 97, newline is coded as 10, and '1' is coded as 49), the five literal strings below denote the same string:

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]

A numerical constant can be written with an optional decimal part and an optional decimal exponent. Lua also accepts integer hexadecimal constants, by prefixing them with 0x. Examples of valid numerical constants are

     3   3.0   3.1416   314.16e-2   0.31416E1   0xff   0x56

Вывод

Мы определяем открывающую длинную скобку уровня n как открывающую квадратную скобку, за которой следуют n знаков равенства, за которыми следует еще одна открывающая квадратная скобка.
Итак, открывающая длинная скобка уровня 0 записывается как [[, открывающая длинная скобка уровня 1 записывается как [=[, и так далее.
Закрывающая длинная скобка определяется аналогично; например, закрывающая длинная скобка уровня 4 записывается как ]====]
Длинная строка начинается с открывающей длинной скобки любого уровня и заканчивается на первой закрывающей длинной скобке того же уровня.
Литералы в этой форме в квадратных скобках могут занимать несколько строк, не интерпретировать escape-последовательности и игнорировать длинные скобки любого другого уровня.
Они могут содержать что угодно, кроме закрывающей скобки нужного уровня.
Для удобства, когда за открывающей длинной скобкой сразу следует новая строка, новая строка не включается в строку.
Например, в системе, использующей ASCII (в которой a кодируется как 97, новая строка кодируется как 10, а 1 кодируется как 49), пять литеральных строк ниже обозначают одну и ту же строку:

     а = alon123'
     а = алон123"
     а = '\97lo 923
     а = [[ало
     123 дюйма]]
     а = [==[
     ало
     123 дюйма]==]

Числовая константа может быть записана с необязательной десятичной частью и необязательным десятичным показателем.
Lua также принимает целочисленные шестнадцатеричные константы, добавляя к ним префикс 0x.
Примеры допустимых числовых констант:

     3 3
0 3
1416 314
16e-2 0
31416E1 0xff 0x56

Огрехи неизбежны, нужно потом лоб в лоб сравнивать и рихтовать. И в целом так себе…

Исправление LINUX-ORG-RU, :

Доделай сам =)

Перевод файла по предложению, до ближайшей точки берётся блок и до победного.

lua autotrans.lua input.txt output.txt
local help =
[[
Usage:  autotrans input.txt output.txt
]]

local input  = arg[1]
local output = arg[2]

if not input or not output then
   print(help)
   os.exit(1)
end

input  = io.open(input, 'r')
output = io.open(output,'w')

if not input then
   print('Failed open for read',arg[1])
   os.exit(2)
end

if not input then
   print('Failed open for write',arg[2])
   os.exit(3)
end

input = input:read('*a')

for block in input:gmatch('[^%.]+') do
    exec = io.popen("trans   en:ru  -b '"..block.."'");
    output:write(exec:read('*a'))
end

Пример ввода

 Literal strings can be delimited by matching single or double quotes, and can contain the following C-like escape sequences: '\a' (bell), '\b' (backspace), '\f' (form feed), '\n' (newline), '\r' (carriage return), '\t' (horizontal tab), '\v' (vertical tab), '\\' (backslash), '\"' (quotation mark [double quote]), and '\'' (apostrophe [single quote]). Moreover, a backslash followed by a real newline results in a newline in the string. A character in a string can also be specified by its numerical value using the escape sequence \ddd, where ddd is a sequence of up to three decimal digits. (Note that if a numerical escape is to be followed by a digit, it must be expressed using exactly three digits.) Strings in Lua can contain any 8-bit value, including embedded zeros, which can be specified as '\0'.

Literal strings can also be defined using a long format enclosed by long brackets. We define an opening long bracket of level n as an opening square bracket followed by n equal signs followed by another opening square bracket. So, an opening long bracket of level 0 is written as [[, an opening long bracket of level 1 is written as [=[, and so on. A closing long bracket is defined similarly; for instance, a closing long bracket of level 4 is written as ]====]. A long string starts with an opening long bracket of any level and ends at the first closing long bracket of the same level. Literals in this bracketed form can run for several lines, do not interpret any escape sequences, and ignore long brackets of any other level. They can contain anything except a closing bracket of the proper level.

For convenience, when the opening long bracket is immediately followed by a newline, the newline is not included in the string. As an example, in a system using ASCII (in which 'a' is coded as 97, newline is coded as 10, and '1' is coded as 49), the five literal strings below denote the same string:

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]

A numerical constant can be written with an optional decimal part and an optional decimal exponent. Lua also accepts integer hexadecimal constants, by prefixing them with 0x. Examples of valid numerical constants are

     3   3.0   3.1416   314.16e-2   0.31416E1   0xff   0x56

Вывод

Мы определяем открывающую длинную скобку уровня n как открывающую квадратную скобку, за которой следуют n знаков равенства, за которыми следует еще одна открывающая квадратная скобка.
Итак, открывающая длинная скобка уровня 0 записывается как [[, открывающая длинная скобка уровня 1 записывается как [=[, и так далее.
Закрывающая длинная скобка определяется аналогично; например, закрывающая длинная скобка уровня 4 записывается как ]====]
Длинная строка начинается с открывающей длинной скобки любого уровня и заканчивается на первой закрывающей длинной скобке того же уровня.
Литералы в этой форме в квадратных скобках могут занимать несколько строк, не интерпретировать escape-последовательности и игнорировать длинные скобки любого другого уровня.
Они могут содержать что угодно, кроме закрывающей скобки нужного уровня.
Для удобства, когда за открывающей длинной скобкой сразу следует новая строка, новая строка не включается в строку.
Например, в системе, использующей ASCII (в которой a кодируется как 97, новая строка кодируется как 10, а 1 кодируется как 49), пять литеральных строк ниже обозначают одну и ту же строку:

     а = alon123'
     а = алон123"
     а = '\97lo 923
     а = [[ало
     123 дюйма]]
     а = [==[
     ало
     123 дюйма]==]

Числовая константа может быть записана с необязательной десятичной частью и необязательным десятичным показателем.
Lua также принимает целочисленные шестнадцатеричные константы, добавляя к ним префикс 0x.
Примеры допустимых числовых констант:

     3 3
0 3
1416 314
16e-2 0
31416E1 0xff 0x56

Огрехи неизбежны, нужно потом лоб в лоб сравнивать и рихтовать. И в целом так себе…

Исправление LINUX-ORG-RU, :

Доделай сам =)

Перевод файла по предложению, до ближайшей точки берётся блок и до победного.

lua autotrans.lua input.txt output.txt
local help =
[[
Usage:  autotrans input.txt output.txt
]]

local input  = arg[1]
local output = arg[2]

if not input or not output then
   print(help)
   os.exit(1)
end

input  = io.open(input, 'r')
output = io.open(output,'w')

if not input then
   print('Failed open for read',arg[1])
   os.exit(2)
end

if not input then
   print('Failed open for write',arg[2])
   os.exit(3)
end

input = input:read('*a')

for block in input:gmatch('[^%.]+') do
    exec = io.popen("trans   en:ru  -b '"..block.."'");
    output:write(exec:read('*a'))
end

Пример ввода

 Literal strings can be delimited by matching single or double quotes, and can contain the following C-like escape sequences: '\a' (bell), '\b' (backspace), '\f' (form feed), '\n' (newline), '\r' (carriage return), '\t' (horizontal tab), '\v' (vertical tab), '\\' (backslash), '\"' (quotation mark [double quote]), and '\'' (apostrophe [single quote]). Moreover, a backslash followed by a real newline results in a newline in the string. A character in a string can also be specified by its numerical value using the escape sequence \ddd, where ddd is a sequence of up to three decimal digits. (Note that if a numerical escape is to be followed by a digit, it must be expressed using exactly three digits.) Strings in Lua can contain any 8-bit value, including embedded zeros, which can be specified as '\0'.

Literal strings can also be defined using a long format enclosed by long brackets. We define an opening long bracket of level n as an opening square bracket followed by n equal signs followed by another opening square bracket. So, an opening long bracket of level 0 is written as [[, an opening long bracket of level 1 is written as [=[, and so on. A closing long bracket is defined similarly; for instance, a closing long bracket of level 4 is written as ]====]. A long string starts with an opening long bracket of any level and ends at the first closing long bracket of the same level. Literals in this bracketed form can run for several lines, do not interpret any escape sequences, and ignore long brackets of any other level. They can contain anything except a closing bracket of the proper level.

For convenience, when the opening long bracket is immediately followed by a newline, the newline is not included in the string. As an example, in a system using ASCII (in which 'a' is coded as 97, newline is coded as 10, and '1' is coded as 49), the five literal strings below denote the same string:

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]

A numerical constant can be written with an optional decimal part and an optional decimal exponent. Lua also accepts integer hexadecimal constants, by prefixing them with 0x. Examples of valid numerical constants are

     3   3.0   3.1416   314.16e-2   0.31416E1   0xff   0x56

Вывод

Мы определяем открывающую длинную скобку уровня n как открывающую квадратную скобку, за которой следуют n знаков равенства, за которыми следует еще одна открывающая квадратная скобка.
Итак, открывающая длинная скобка уровня 0 записывается как [[, открывающая длинная скобка уровня 1 записывается как [=[, и так далее.
Закрывающая длинная скобка определяется аналогично; например, закрывающая длинная скобка уровня 4 записывается как ]====]
Длинная строка начинается с открывающей длинной скобки любого уровня и заканчивается на первой закрывающей длинной скобке того же уровня.
Литералы в этой форме в квадратных скобках могут занимать несколько строк, не интерпретировать escape-последовательности и игнорировать длинные скобки любого другого уровня.
Они могут содержать что угодно, кроме закрывающей скобки нужного уровня.
Для удобства, когда за открывающей длинной скобкой сразу следует новая строка, новая строка не включается в строку.
Например, в системе, использующей ASCII (в которой a кодируется как 97, новая строка кодируется как 10, а 1 кодируется как 49), пять литеральных строк ниже обозначают одну и ту же строку:

     а = alon123'
     а = алон123"
     а = '\97lo 923
     а = [[ало
     123 дюйма]]
     а = [==[
     ало
     123 дюйма]==]

Числовая константа может быть записана с необязательной десятичной частью и необязательным десятичным показателем.
Lua также принимает целочисленные шестнадцатеричные константы, добавляя к ним префикс 0x.
Примеры допустимых числовых констант:

     3 3
0 3
1416 314
16e-2 0
31416E1 0xff 0x56

Огрехи неизбежны, нужно потом лоб в лоб сравнивать и рихтовать.

Исходная версия LINUX-ORG-RU, :

Доделай сам =)

lua autotrans.lua input.txt output.txt
local help =
[[
Usage:  autotrans input.txt output.txt
]]

local input  = arg[1]
local output = arg[2]

if not input or not output then
   print(help)
   os.exit(1)
end

input  = io.open(input, 'r')
output = io.open(output,'w')

if not input then
   print('Failed open for read',arg[1])
   os.exit(2)
end

if not input then
   print('Failed open for write',arg[2])
   os.exit(3)
end

input = input:read('*a')

for block in input:gmatch('[^%.]+') do
    exec = io.popen("trans   en:ru  -b '"..block.."'");
    output:write(exec:read('*a'))
end

Пример ввода

 Literal strings can be delimited by matching single or double quotes, and can contain the following C-like escape sequences: '\a' (bell), '\b' (backspace), '\f' (form feed), '\n' (newline), '\r' (carriage return), '\t' (horizontal tab), '\v' (vertical tab), '\\' (backslash), '\"' (quotation mark [double quote]), and '\'' (apostrophe [single quote]). Moreover, a backslash followed by a real newline results in a newline in the string. A character in a string can also be specified by its numerical value using the escape sequence \ddd, where ddd is a sequence of up to three decimal digits. (Note that if a numerical escape is to be followed by a digit, it must be expressed using exactly three digits.) Strings in Lua can contain any 8-bit value, including embedded zeros, which can be specified as '\0'.

Literal strings can also be defined using a long format enclosed by long brackets. We define an opening long bracket of level n as an opening square bracket followed by n equal signs followed by another opening square bracket. So, an opening long bracket of level 0 is written as [[, an opening long bracket of level 1 is written as [=[, and so on. A closing long bracket is defined similarly; for instance, a closing long bracket of level 4 is written as ]====]. A long string starts with an opening long bracket of any level and ends at the first closing long bracket of the same level. Literals in this bracketed form can run for several lines, do not interpret any escape sequences, and ignore long brackets of any other level. They can contain anything except a closing bracket of the proper level.

For convenience, when the opening long bracket is immediately followed by a newline, the newline is not included in the string. As an example, in a system using ASCII (in which 'a' is coded as 97, newline is coded as 10, and '1' is coded as 49), the five literal strings below denote the same string:

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]

A numerical constant can be written with an optional decimal part and an optional decimal exponent. Lua also accepts integer hexadecimal constants, by prefixing them with 0x. Examples of valid numerical constants are

     3   3.0   3.1416   314.16e-2   0.31416E1   0xff   0x56

Вывод

Мы определяем открывающую длинную скобку уровня n как открывающую квадратную скобку, за которой следуют n знаков равенства, за которыми следует еще одна открывающая квадратная скобка.
Итак, открывающая длинная скобка уровня 0 записывается как [[, открывающая длинная скобка уровня 1 записывается как [=[, и так далее.
Закрывающая длинная скобка определяется аналогично; например, закрывающая длинная скобка уровня 4 записывается как ]====]
Длинная строка начинается с открывающей длинной скобки любого уровня и заканчивается на первой закрывающей длинной скобке того же уровня.
Литералы в этой форме в квадратных скобках могут занимать несколько строк, не интерпретировать escape-последовательности и игнорировать длинные скобки любого другого уровня.
Они могут содержать что угодно, кроме закрывающей скобки нужного уровня.
Для удобства, когда за открывающей длинной скобкой сразу следует новая строка, новая строка не включается в строку.
Например, в системе, использующей ASCII (в которой a кодируется как 97, новая строка кодируется как 10, а 1 кодируется как 49), пять литеральных строк ниже обозначают одну и ту же строку:

     а = alon123'
     а = алон123"
     а = '\97lo 923
     а = [[ало
     123 дюйма]]
     а = [==[
     ало
     123 дюйма]==]

Числовая константа может быть записана с необязательной десятичной частью и необязательным десятичным показателем.
Lua также принимает целочисленные шестнадцатеричные константы, добавляя к ним префикс 0x.
Примеры допустимых числовых констант:

     3 3
0 3
1416 314
16e-2 0
31416E1 0xff 0x56

Огрехи неизбежны, нужно потом лоб в лоб сравнивать и рихтовать.