begin CRLF := ' '; TAB := ' '; org_str := S_GetSelectedString(0); byte := Length(org_str); if (byte=0) then begin S_SelectAll(); org_str := S_GetSelectedString(0); byte := Length(org_str); end ; pt := 1; t_flg := 0; f_flg := 0; s_flg := 0;
target := ''; w_str := '';
while (pt <= byte) do begin tmp1 := Copy(org_str,pt,1); tmp2 := Copy(org_str,pt,2); if ((tmp1=' ') or (tmp1=TAB) or (tmp1=',') or (tmp2 = CRLF) or (tmp1='(') or (tmp1=')') or (tmp1 = ';') ) then begin
続き w_tmp := LowerCase(Trim(w_str)); if ((w_tmp='select') or (w_tmp='update') or (w_tmp='commit') or (w_tmp='rollback') or (w_tmp='insert') or (w_tmp='delete') or (w_tmp='create') or (w_tmp='drop') or (w_tmp='truncate') or (w_tmp='alter')) then begin s_flg := 0; if (f_flg<>0) then f_flg := 2; i_cnt := 0; while (i_cnt < t_flg) do begin target := target + TAB; i_cnt := i_cnt + 1; end; if ((w_tmp='select') or (w_tmp='update') or (w_tmp='commit') or (w_tmp='rollback')) then begin t_flg := t_flg + 1; target := target + Trim(w_str) + CRLF; end else begin target := target + Trim(w_str) + ' '; end ; end else if ((w_tmp='values') or (w_tmp='set') or (w_tmp='from') or (w_tmp='where') or (w_tmp='having') or (w_tmp='group') or (w_tmp='order')) then begin if (w_tmp='values') then begin s_flg := 2; end else
続き begin s_flg := 0; target := target + CRLF; end ; if (f_flg<>0) then f_flg := 2; t_flg := t_flg - 1; i_cnt := 0; while (i_cnt < t_flg) do begin target := target + TAB; i_cnt := i_cnt + 1; end; if ((w_tmp='group') or (w_tmp='order')) then begin target := target + Trim(w_str) + ' '; end else begin t_flg := t_flg + 1; target := target + Trim(w_str) + CRLF; end ; end else if ((w_tmp='and') or (w_tmp='or') or (w_tmp='table') or (w_tmp='view') or (w_tmp='index') or (w_tmp='by') or (w_tmp='into')) then begin s_flg := 0; if ((w_tmp='table') or (w_tmp='view') or (w_tmp='index')) then begin target :=target + Trim(w_str) + ' '; end else if ((w_tmp='by') or (w_tmp='into')) then begin target := target + Trim(w_str) + CRLF; t_flg := t_flg + 1; end
最後 target := target + Trim(w_str) + ';' + CRLF; end else begin if (Length(w_tmp) <> 0) then begin i_cnt := 0; while (i_cnt < t_flg) do begin target := target + TAB; i_cnt := i_cnt + 1; end; end ; if (tmp2 = CRLF) then begin target := target + Trim(w_str); if (Length(w_tmp) <> 0) then s_flg := 1; end else begin if ((tmp1<>TAB) and (tmp1<>' ')) then begin target := target + Trim(w_str) + tmp1; s_flg := 0; end else begin target := target + Trim(w_str); if (s_flg<>2) then s_flg := 1; end ; end ; end ; w_str := ''; end else begin w_str := w_str + tmp1; end ; pt := pt + 1; end; if (w_str<>'') then target := target + Trim(w_str); target := target + CRLF; S_Delete(); S_InsText(target); end;