2017年4月20日 星期四

4gl convert text file to any charset

以下FUNCTION 使用到LINUX 指定 file 與 iconv


function cl_fileconvertto(p_sfile,  p_ofile, p_ocode)
  define p_sfile string,
         p_ofile string,
         p_ocode string,
         ss string
  DEFINE fn CHAR(100)  
  DEFINE ex CHAR(40),
  ch base.Channel 
   DEFINE   li_result     LIKE type_file.num5

    let ss = "file -i ", p_sfile clipped
    LET ch = base.Channel.create()
    CALL ch.setDelimiter("=")
    CALL ch.openPipe(ss,"r")
    while  ch.read([fn,ex])
       display  fn, "   ", ex
    end while
    call ch.close()
   
    if cl_null(ex) then
        let li_result= false
        return li_result
    end if
   
   
    let ss= "iconv -f ", ex clipped, " -t " , p_ocode clipped ," ", p_sfile clipped, " -o " , p_ofile 
    RUN ss
    let ss = "file -i ", p_ofile clipped
    CALL ch.setDelimiter("=")
    CALL ch.openPipe(ss,"r")
    while  ch.read([fn,ex])
       display  fn, "   ", ex
    end while
    call ch.close();
   
    if  ex = p_ocode then
      let li_result = true
    else
      let li_result = false
    end if
   
    return li_result
end function

沒有留言:

張貼留言