Water Sunlight

軽量プログラミングの文法 - JavaScript/Python

ユーザ用ツール

サイト用ツール


sakura-macro

差分

このページの2つのバージョン間の差分を表示します。

この比較画面にリンクする

両方とも前のリビジョン 前のリビジョン
次のリビジョン
前のリビジョン
sakura-macro [2022/01/12 11:36]
tanaka [cb_pic.js]
sakura-macro [2022/02/01 10:31] (現在)
tanaka [visible_pack.js]
行 38: 行 38:
 // ----------------------------------------------- // -----------------------------------------------
 // 1行の最大文字数を指定して改行を入れる // 1行の最大文字数を指定して改行を入れる
-// 0x0Dが含まれる時は0x0Fに変換する(確認メッセージ有)+// ファイル名に.chopを付けて保存する(改行コードは入力する) 
 +// 0x0Dが含まれる時は確認メッセージ表示 
 +// [はい]:0x0D を 0x0F に変換する 
 +// [いいえ]: 何もしない 
 +// ※ 0x0D:'-'  0x0C:'+'  0x0F:' '
 // ----------------------------------------------- // -----------------------------------------------
 main(); main();
行 78: 行 82:
  // ペースト  // ペースト
  Editor.Paste(0);  Editor.Paste(0);
 +
 + // 改行コード
 + var code = parseInt(Editor.InputBox('[0]変換なし | [1]CRLF | [2]LF | [3]CR を入力して下さい。', 0));
 + if(isNaN(code)){
 + Editor.WarnMsg('改行コードの入力が無いので、ファイルを保存しません。');
 + return;
 + }
  
  // 名前を指定して保存  // 名前を指定して保存
  var fileName = Editor.GetFilename() + '.chop';  var fileName = Editor.GetFilename() + '.chop';
- Editor.FileSaveAs(fileName);+ Editor.FileSaveAs(fileName, 0, code);
 } }
 </sxh> </sxh>
行 186: 行 197:
 ===== xsort.js ===== ===== xsort.js =====
 <sxh javascript;title:xsort.js> <sxh javascript;title:xsort.js>
-TODO+// ----------------------------------------------- 
 +// 複数キーのソート 
 +// [入力方法]{開始位置}:{文字長},{開始位置}:{文字長},asc desc 
 +// ----------------------------------------------- 
 + 
 +main(); 
 + 
 +function main() { 
 + 
 + // キー 
 + var input = Editor.InputBox('{開始位置}:{文字長},{開始位置}:{文字長},asc desc'); 
 + if(!input) return; 
 + 
 + var keys = []; 
 + var inputWords = input.split(','); 
 + var orderWords = inputWords[inputWords.length-1].split(' '); 
 + if(inputWords.length - 1 == orderWords.length) { 
 + for(var i=0; i<inputWords.length-1; i++){ 
 + 
 + var words = inputWords[i].split(':'); 
 + if(words.length == 2){ 
 + var pos = 0; 
 + var len = 0; 
 + var order = ''; 
 +  
 + pos = parseInt(words[0]); 
 + len = parseInt(words[1]); 
 + order = orderWords[i]; 
 + 
 + var obj = new Key(pos, len, order); 
 + keys.push(obj); 
 +
 +
 + } else { 
 + Editor.ErrorMsg('キーの数とソート順の数があっていません。'); 
 + return; 
 +
 + 
 + // 行 
 + var items = []; 
 + for(var i=1; i<=Editor.GetLineCount(0); i++){ 
 + var line = GetLineStr(i); 
 + 
 + var itemKeys = []; 
 + for(var j=0; j<keys.length; j++){ 
 + itemKeys[j] = line.substr(keys[j].pos-1, keys[j].len); 
 +
 + 
 + var objItem = new Item(i, itemKeys); 
 + items.push(objItem); 
 +
 + 
 + // ソート 
 + items.sort(function(a, b) { 
 + 
 + for(var i=0; i<a.key.length; i++){ 
 +  
 + if(a.key[i] !== b.key[i]) { 
 + if (a.key[i] < b.key[i]) { 
 + return (keys[i].order.toUpperCase() == 'DESC') ? 1 : -1; 
 +
 + if (a.key[i] > b.key[i]) { 
 + return (keys[i].order.toUpperCase() == 'DESC') ? -1 : 1; 
 +
 +
 +
 +  
 + return 0; 
 + }); 
 + 
 + var sortTxt = ''; 
 + for(var i=0; i<items.length; i++){ 
 + sortTxt += GetLineStr(items[i].lineNo); 
 +
 +  
 + // 上書き 
 + Editor.SelectAll(); 
 + Editor.InsText(sortTxt); 
 +
 + 
 +function Key(pos, len, order) { 
 + this.pos = pos; 
 + this.len = len; 
 + this.order = order; 
 +
 + 
 +function Item(lineNo, key) { 
 + this.lineNo = lineNo; 
 + this.key = key; 
 +}
 </sxh> </sxh>
  
行 483: 行 583:
 // pic句のバイト数を集計 // pic句のバイト数を集計
 // PICTURE文字列がN, CR, DBはサポートしていません。 // PICTURE文字列がN, CR, DBはサポートしていません。
 +// REDEFINES と OCCURS は未サポートです。
 +//  ・出現した時は警告を出します。
 +//  ・出てきた数を数えて警告に表示します。
 // ----------------------------------------------- // -----------------------------------------------
    
行 511: 行 614:
  
  var picArr = [];  var picArr = [];
 + var note = '';
  for(var i=lineFrom; i<lineTo; i++){  for(var i=lineFrom; i<lineTo; i++){
  
行 516: 行 620:
  var txt = Editor.GetLineStr(i);  var txt = Editor.GetLineStr(i);
  
- // インラインコメント削除 + // コメント 
- var commentIndex = txt.indexOf(';'); + var arr = txt.match(/\d{6}(\*|\/)/); 
- if(commentIndex > 0txt = txt.substring(0, commentIndex); + if(arr)
- + note getNote(txt); 
- commentIndex = txt.indexOf('*>')+ continue
- if(commentIndex > 0) txt = txt.substring(0, commentIndex);+ }
  
  // PicObj取得  // PicObj取得
- var pic = getPic(txt);+ var pic = getPic(txt, note);
  if(!pic) continue;  if(!pic) continue;
  
行 544: 行 648:
  // 配列に入れる  // 配列に入れる
  picArr.push(pic);  picArr.push(pic);
 +
 + note = '';
  }  }
  
行 564: 行 670:
 } }
    
-function Pic(no, name, type, option, byte, position) {+function Pic(no, name, type, option, byte, position, note) {
  this.no = no;  this.no = no;
  this.name = name;  this.name = name;
行 571: 行 677:
  this.byte = byte;  this.byte = byte;
  this.position = position;  this.position = position;
 + this.note = note;
 } }
- + 
 +/** 
 + * コメント行の備考を取得 
 + */ 
 +function getNote(line) { 
 +  
 + var note = ''; 
 + var words = line.split(';'); 
 + if(words.length == 2) { 
 + var wds = words[1].split(/\s/); 
 + if(wds.length == 2) { 
 + note = wds[1]; 
 +
 +
 + 
 + return note; 
 +
 /** /**
  * 1行をPicにいれて返す  * 1行をPicにいれて返す
  */  */
-function getPic(line) {+function getPic(line, note) {
  
  var pic = null;  var pic = null;
  
- // コメント行は何もしない + // インラインコメント削除 
- var arr = line.match(/\d{6}(\*|\/)/); + var commentIndex = line.indexOf(';'); 
- if(arrreturn pic;+ if(commentIndex > 0line = line.substring(0, commentIndex); 
 + 
 + commentIndex = line.indexOf('*>'); 
 + if(commentIndex > 0) line = line.substring(0, commentIndex);
  
  var found = line.match(/\s\d{2}\s.+/);  var found = line.match(/\s\d{2}\s.+/);
行 588: 行 715:
  
  // スペースで区切る  // スペースで区切る
- var words = found[0].split(/\s|\t/);+ var words = found[0].split(/\s/);
  
  // 最後のピリオド削除  // 最後のピリオド削除
行 606: 行 733:
  }  }
  
- // オプション+ // オプション(レベル、変数名以外)
  var option = [];  var option = [];
  var j = 0;  var j = 0;
- for(var i=picPos+2; i<words.length; i++){+ for(var i=2; i<words.length; i++){
  option[j++] = words[i];  option[j++] = words[i];
   
行 622: 行 749:
  
  if(picPos > 1) {  if(picPos > 1) {
- pic = new Pic(words[0], words[1], words[picPos+1], option, 0, 0);+ pic = new Pic(words[0], words[1], words[picPos+1], option, 0, 0, note);
  }  }
  }  }
行 801: 行 928:
  }  }
 } }
- + 
 +/** 
 + * オプション 
 + */ 
 +function getOption(option) { 
 + 
 + for(var index in option) { 
 + if(option[index]=='PACKED-DECIMAL' || option[index]=='COMP-3' || option[index]=='COMPUTATIONAL-3' 
 + || option[index]=='BINARY' || option[index]=='COMP'  || option[index]=='COMPUTATIONAL'){ 
 + return option[index]; 
 +
 +
 + return ''; 
 +
 /** /**
  * Pic配列を文字列に変換  * Pic配列を文字列に変換
行 814: 行 955:
  txt += '\t';  txt += '\t';
  txt += picArr[i].type;  txt += picArr[i].type;
 + var option = getOption(picArr[i].option)
 + if(option){
 + txt += ' ' + getOption(picArr[i].option);
 + }
  txt += '\t';  txt += '\t';
  txt += picArr[i].byte;  txt += picArr[i].byte;
  txt += '\t';  txt += '\t';
  txt += picArr[i].position;  txt += picArr[i].position;
 + txt += '\t';
 + txt += picArr[i].note;
  txt += '\r\n';  txt += '\r\n';
  }  }
行 826: 行 973:
  
 \\ \\
 +
sakura-macro.1641954990.txt.gz · 最終更新: 2022/01/12 11:36 by tanaka