⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eol.csp

📁 C-smile OOL is a scripting language with C++-like grammar. It has compiler, VM running bytecodes and
💻 CSP
字号:
package eol;

function cvt_file_2unix(node) 
{
  var ins = node.stream("r");
  var outn = new node(node.path);
  outn.extension = "~~~";
  var outs = outn.stream("w");
  while(true) {
    var line = ins.get("\r\n");
    if( is_null(line) ) break;
    outs.printf("%s\n",line);
  }
  ins.close();
  outs.close();
  node.remove();
  outn.rename(node.path);
}

function cvt_file_2dos(node) 
{
  var ins = node.stream("rb");
  var outn = new node(node.path);
  outn.extension = "~~~";
  var outs = outn.stream("wb");
  while(true) {
    var line = ins.get("\n");
    if( is_null(line) ) break;
    outs.printf("%s\r\n",line);
  }
  ins.close();
  outs.close();
  node.remove();
  outn.rename(node.path);
  
}


function cvt_file_repair(node) 
{
  var ins = node.stream("rb");
  var outn = new node(node.path);
  outn.extension = "~~~";
  var outs = outn.stream("wb");
  
  ins.position = 0;
  
  while(true) {
    var line = ins.get("\r\n");
    if( is_null(line) ) break;
    line = line.replace("\r","","\n","");
    outs.printf("%s\r\n",line);
  }
  ins.close();
  outs.close();
  node.remove();
  outn.rename(node.path);
}


var ext_filter = new regexp("^(cpp|cxx|c|hpp|hxx|h|csp)$");

function cvt_file(node,direction) 
{
  var ext = node.extension.to_lower();
  out.printf("%s ", node.path);
  if( ext_filter.test(ext) ) 
    {
      if(direction == "2unix")
        cvt_file_2unix(node);
      else if(direction == "2dos")
        cvt_file_2dos(node);
      else 
        cvt_file_repair(node);
      out.printf("converted\n");
    }
  else
      out.printf("skipped\n");
}

function cvt_folder(nin,direction) 
{
  if( nin.is_folder ) 
  {
    var i, narray = nin.nodes("*.*");
    for(i = 0; i < narray.length; i++) cvt_folder(narray[i],direction); 
  } 
  else if(nin.is_file) cvt_file(nin,direction); 
}

function main(folder_name_in,direction_in) {
  
  if(!folder_name_in && !direction_in) 
  {
    out.printf("unix2dos or dos2unix eol file converter\n"); 
    out.printf("USAGE: eol folder_or_file_name 2unix|2dos\n"); 
  }
  
  var nin = new node(folder_name_in);
  cvt_folder(nin,direction_in); 
  out.printf("done.\n");
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -