| Index | Manual | Download | Source | Macros | Embedded word Case ins.
Sitemap | Links | Forum | Tests | Projects

# convlinc.htm
Data
Data
Procedures
ConversionPrologue
ConversionEpilogue
MainCon
ReadFile_ini
RecapEncoding
RecapFile
RecapHeaderAndFooter
RecapNumber
WriteFileProxy

This is a CON module of EuroTool program EuroConv for Linux.

It takes arguments from the command line. If both input and output files are specified, it performs the conversion, otherwise GUI module is called.

             EUROASM CPU=X64,Unicode=no
    convlinc PROGRAM Format=COFF,Width=64
             %DROPMACRO *
             INCLUDEHEAD argument.htm
             INCLUDE1 linabi.htm, linf64.htm, lins.htm, status32.htm
             INCLUDE1 stdcal64.htm, string64.htm, cpuext.htm, cpuext64.htm

Data

    [.rodata]    ; Constant data.
    Ext_ini::    DB '.ini',0
    Quote        DB '"',0
    [.bss]       ; Variable data.
    File_ini     DS FILE64
    FileInput::  DS FILE64
    FileOutput:: DS FILE64
    NameUTF8     D MAX_PATH_SIZE * UNICHAR ; Temporary working space for file names in UTF-8.
    Work16::     D MAX_PATH_SIZE * UNICHAR ; Temporary working space for reports in UTF-8.
    [.text]

MainCon
  The MainCon procedure is entry of the program euroconv.x ; it is executed both in console and in pseudographic mode.

    MainCon:: PROC                         ; Entry point of EuroConv for Linux.
        LEA RSI,[CPid::]                   ; Prepare the database of codepages and codepoints.
        LEA RCX,[CPidEnd::]
        SUB RCX,RSI
        SHR ECX,1
        MOV [CodePagesLength::],ECX
        LEA RSI,[CodePoint::]
        LEA RCX,[CodePointEnd::]
        SUB RCX,RSI
        SHR ECX,1
        MOV [CodePointLength::],ECX        ; Specify factory-defaults.
        MOVD [ArgOutputEncoding::],65001   ; Set the default UTF-8.
        LEA RDI,[ArgHtmlEntities::]
        LEA RSI,[=B'Ignore']
        MOV ECX,6
        REP MOVSB                          ; Set the default value.
        LEA RDI,[ArgInvalidCharacter::]
        LEA RSI,[=B'Transliterate']
        MOV CL,13
        REP MOVSB                          ; Set the default value.
        LEA RAX,[FileWriteProxy]
        MOV [WriteProxy::],RAX
        StdOutput EuroConv::, Version::, Eol=yes
        ; Try to load arguments from the configuration file /etc/euroconv.ini.
        FileAssign File_ini, =B'/etc/eurotool/euroconv.ini'
        FileExists? File_ini
        JNC .06:
        FileMkDir File_ini
        JC .04:
        LEA RDI,[Help]                     ; Online help and default configuration.
        GetLength$ RDI
        FileStore File_ini, RDI,RCX
        JNC .06:
    .04:StdOutput =B'Configuration "',File_ini.Name,=B'" could not be saved.',Eol=yes
        JMP .30:
    .06:CALL ReadFile_ini
       ; And finally read arguments from the command-line.
    .30:MOV EAX,[ArgNr::]
        INC EAX
        MOV [ArgNr::],EAX
        GetArg RAX, Frame=RSP              ; Returns in RSI,RCX the line with one argument, e. g. -IF="~/alphabet.txt"
        JC .50:
        CALL ArgParse::                    ; Use ArgParse to translate it to a public symbol Arg***.
        JNC .30:                           ; Go to read the next argument.
        StdOutput ErrorMessage::           ; On error write help and exit.
        JSt [Status::],ArgEnc?|ArgLoc?|ArgFF?,.40:
        StdOutput Help::                   ; On error write help and exit.
    .40:TerminateProgram 8
    .50:
        CMPB [ArgInputFile::],0
        JZ .60:
        CMPB [ArgOutputFile::],0
        JNZ .70:                           ; Stay in the console subsystem when both I/O files are specified.
    .60:CALL MainGui::                     ; One of I/O file is not specified; use GUI.
    .70:CALL ConversionPrologue            ; Both files are specified. Perform conversion in console mode. No GUI.
        JNSt [Status::],ArgCancel,.80:
        FileClose FileInput, FileOutput    ; Close files if they were open.
        StdOutput =B'Conversion aborted.',Eol=yes
        TerminateProgram 8
    .80:CALL ConvFile::                    ; Convert the input file .
        CALL ConversionEpilogue            ; Recapitulate.
        TerminateProgram 0
      ENDP MainCon

ConversionPrologue
  This procedure will check the arguments, open the files, autodetect input encoding if not specified, apply restriction on header and footer, recapitulate arguments.

    ConversionPrologue   PROC
        FileClose FileInput, FileOutput    ; Close files if they were open.
        StdOutput Eol=yes
        FileAssign FileOutput,ArgOutputFile::
        FileStreamCreate FileOutput
        JC .ErrorWrite:
        FileAssign FileInput, ArgInputFile::
        FileLoad FileInput
        JC .ErrorRead:
        MOV [HeaderInMemPtr::],RSI
        MOV [HeaderInMemEnd::],RSI
        ADD RAX,RSI
        MOV [FooterInMemEnd::],RAX
        MOV [FooterInMemPtr::],RAX
        MOV EDX,[ArgInputEncoding::]
        TEST EDX
        JNZ .20:
        CALL AutodetectEncoding::
        MOV [ArgInputEncoding::],EAX
    .20:CALL HeaderAndFooter::             ; Crop the input.
        JC .ErrorRestrictions:
        LEA RSI,[=B'Input']                ; Recapitulation of arguments:
        LEA RAX,[FileInput.Name]
        CALL RecapFile:
        MOV EAX,[ArgHeaderSize::]
        LEA RSI,[=B'Header size: ']
        CALL RecapHeaderAndFooter:
        MOV EAX,[ArgHeaderLength::]
        LEA RSI,[=B'Header length: ']
        CALL RecapHeaderAndFooter:
        MOV EAX,[ArgFooterSize::]
        LEA RSI,[=B'Footer size: ']
        CALL RecapHeaderAndFooter:
        MOV EAX,[ArgFooterLength::]
        LEA RSI,[=B'Footer length: ']
        CALL RecapHeaderAndFooter:
        MOV EAX,[ArgInputEncoding::]
        LEA RSI,[=B'Input']
        CALL RecapEncoding:
        StdOutput =B'HtmlEntities: ',ArgHtmlEntities::, Eol=yes
        LEA RSI,[=B'Output']
        LEA RAX,[FileOutput.Name]
        CALL RecapFile:
        LEA RSI,[=B'Output']
        MOV EAX,[ArgOutputEncoding::]
        CALL RecapEncoding:
        MOV EAX,[ArgOutputEncoding::]
        Dispatch AX,65001,1200,1201,12000,12001
        JMP .40:
    .1200:
    .1201:
    .12000:
    .12001:
    .65001:
        StdOutput =B"Byte Order Mark: "
        LEA RSI,[=B"on"]
        JSt [Status::],ArgBOM,.30:
        LEA RSI,[=B"off"]
    .30:StdOutput RSI,Eol=yes
    .40:StdOutput =B'InvalidCharacters: ',ArgInvalidCharacter::, Eol=yes
        JMP .90:
    .ErrorRestrictions:
        StdOutput =B"Wrong header and footer restrictions.", Eol=yes
        JMP .90:
    .ErrorWrite:
        LEA RDI,[=B'Cannot write the file ']
        StdOutput RDI,Quote,FileOutput.Name,Quote,Eol=yes
        JMP .90:
    .ErrorRead:
        LEA RDI,[=B'Cannot read the file ']
        StdOutput RDI,Quote,FileInput.Name,Quote,Eol=yes
    .90:RET
    ENDP ConversionPrologue

ConversionEpilogue
  This procedure will recapitulate number of converted characters, input and output errors.

    ConversionEpilogue   PROC
        FileClose FileInput, FileOutput
        MOV EAX,[Converted::]
        LEA RSI,[=B'Converted characters: ']
        CALL RecapNumber:
        MOV EAX,[InputErrors::]
        LEA RSI,[=B'Input errors: ']
        CALL RecapNumber:
        MOV EAX,[OutputErrors::]
        LEA RSI,[=B'Output errors: ']
        CALL RecapNumber:
        RET
       ENDP ConversionEpilogue

RecapFile
  Recapitulate input|output file.
Input
  RAX= pointer to file name.
  RSI= prompt.
Called by
  ConversionPrologue.

    RecapFile PROC
        StdOutput RSI,=B' file: "', RAX, =B'"', Eol=yes
        RET
      ENDP RecapFile:

RecapHeaderAndFooter
  Recapitulate header and footer.
Input
  RAX= numeric value of the header or footer in bytes|lines.
  RSI= prompt.
Called by
  ConversionPrologue.

    RecapHeaderAndFooter  PROC
        TEST EAX
        JZ .90:
        LEA RDI,[Work16]         ; Recapitulate only when nonzero.
        StoD RDI
        XOR EAX,EAX
        STOSB
        StdOutput RSI, Work16, Eol=yes
    .90:RET
       ENDP RecapHeaderAndFooter:

RecapEncoding
  Recapitulate encoding.
Input
  RAX= encoding in Microsoft nomenclature (65001 for UTF-8 etc)/
  RSI= prompt.
Called by
  ConversionPrologue.

    RecapEncoding: PROC
        LEA RDI,[CPid::]
        MOV ECX,[CodePagesLength::]
        MOV RDX,RDI
        REPNE SCASW
        SUB RDI,RDX
        MOV EDX,EDI
        SHR EDX,1
        LEA RDI,[Names::]
        LEA RCX,[Tables::]
        SUB RCX,RDI
        XOR EAX,EAX
    .50:DEC EDX
        JZ .70:
        REPNE SCASB
        REPNE SCASB
        JMP .50:
    .70:StdOutput RSI, =B' encoding: ', RDI, =B' '
        XOR EAX,EAX
        REPNE SCASB
        StdOutput RDI, Eol=yes, Unicode=no
        RET
      ENDP RecapEncoding:

RecapNumber
  Recapitulate a number (of errors).
Input
  RAX= binary number.
  RSI= prompt.
Called by
  ConversionEpilogue.

    RecapNumber: PROC
        LEA RDI,[Work16]
        StoD RDI
        XOR EAX,EAX
        STOSB
        StdOutput RSI,Work16, Eol=yes, Unicode=no
        RET
      ENDP RecapNumber:

WriteFileProxy
  Procedure WriteFileProxy writes one byte of data in AL to previously created OutputFile in Linux.
Input
  AL= the data to write.
Called by
  ConvFile.
Clobbers
  -

    FileWriteProxy PROC
        FileStreamWriteByte FileOutput
        JNC .90:
        LEA RSI,[=B'Error writing to the file "']
        LEA RDI,[=B'". Aborting.']
        StdOutput RSI, FileOutput.Name, RDI, Eol=yes
        FileClose FileInput, FileOutput
        TerminateProgram 8
    .90:RET
       ENDP FileWriteProxy

ReadFile_ini
  Procedure ReadFile_ini reads lines from File_ini in UTF-8 and parses its each line into configuration variables Arg*** in UTF-8, too.
  The File_ini.Name is in UTF-16. Procedure writes information about the file name and whether it was found to Work16 in UTF-16.
Called by
  MainCon.
Input
  File_ini is assigned with the name.
Clobbers
  RAX,RCX,RDX,RSI,RDI

    ReadFile_ini:: PROC
        SetSt [Status::],ArgFromFile ; Tell ArgParse that arguments need not begin with / or -.
        StdOutput =B'Configuration "', File_ini.Name
    .10:FileStreamOpen File_ini, BufSize=4K
        JNC .20:
        StdOutput =B'" was not found.', Eol=yes, Unicode=no
        JMP .90:
    .20:FileStreamReadLn File_ini
        JBE .80:
        MOV ECX,EAX              ; Line size. The first line may begin with UTF-8 BOM.
        MOV AX,[RSI]
        CMPW AX,0xBBEF           ; UTF-8 BOM?
        JNE .50:
        ADD RSI,3                ; Skip the BOM.
        SUB ECX,3
        JB .80:
        JMP .50:
    .30:FileStreamReadLn File_ini
        JBE .80:
        MOV ECX,EAX
    .50:CALL ArgParse::          ; RSI,RCX is the UTF-8 string to parse by ArgParse.
        JNC .30:
        LEA RSI,[ErrorMessage::]
        StdOutput RSI, Help, Eol=yes
        TerminateProgram 8
    .80:FileClose File_ini
        StdOutput =B'" was accepted.', Eol=yes, Unicode=no
    .90:RstSt [Status::],ArgFromFile
        RET
      ENDP ReadFile_ini

        ENDPROGRAM convlinc

▲Back to the top▲