/* ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/ /* */ /* P†l Hedne 1991 */ /* */ /* ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/ sort (...) { string pattern,text,word; int line,col,line1,col1,linex,colx,mtype,wlength,ind; int buf_key,scratch_key; int i,j,wsum,linesum,linesummin,iline,nline; pause_on_error(0); scratch_key=create_buffer("Kladd ",NULL,1); /* error("scratch_key = %d",scratch_key);*/ buf_key=inq_buffer(); inq_position (line, col); mtype = inq_marked (line1, col1, linex, colx); if (mtype > 0) { pattern=""; text="Sort on word no.: "; if (get_parm (0, pattern, text, NULL,pattern)) { ind=atoi(pattern); sprintf(text,"Sorting on column %d...",ind); message(text); /* error("Sorting marked block on word %d",ind);*/ for (j=line1; j<=linex; ++j) { move_abs(j,col1); text=read(); word=get_word(text,ind); wlength=strlen(word); /* error(" Word returned = %s",word);*/ wsum=0; if (wlength>4) wlength=4; for (i=1; i<=wlength; ++i) { /* error("sub=%s,atoi=%d",substr(word,i,1),atoi(substr(word,i,1),0));*/ wsum=wsum+exp127(atoi(substr(word,i,1),0),5-i); /* error(" Wsum(%d) = %d",i,wsum);*/ } /* error(" Wsum = %d",wsum);*/ set_buffer(scratch_key); end_of_buffer(); sprintf(text,"%d\n",wsum); insert(text); set_buffer(buf_key); } nline=linex-line1+1; set_buffer(scratch_key); for (i=1; i<=nline; ++i) { linesummin=2147483647; iline=i; move_abs(i,1); sprintf(text,"%d/%d done",i,nline); message(text); for (j=i; j<=nline; ++j) { text=read(); linesum=atoi(text); /* error("Line=%d sum=%d min=%d",j,linesum,linesummin);*/ if (linesumi) { swap_lines(i,iline); set_buffer(buf_key); swap_lines(line1+i-1,line1+iline-1); set_buffer(scratch_key); } } set_buffer(buf_key); } } pause_on_error(0); move_abs(line,col); message(" "); } /* ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/ get_word(string text, int wno) { string mword; int ind,wlength; int wcount=0; text=ltrim(text); /* error("Index = %d Text = %s",ind,text);*/ do { ind=search_string("[\t\n, ]",text,0,1,0); /* error("Ind1 = %d text = %s",ind,text);*/ if (ind>0) { ++wcount; if (wcount==wno) { mword=substr(text,1,ind-1); return(mword); } text=substr(text,ind); /* error("Word no. %d = %s",wcount,mword);*/ ind=search_string("[~\t\n, ]",text,0,1,0); /* error("Ind2 = %d text = %s",ind,text);*/ text=substr(text,ind); } } while((wcount0)); return(" "); } /* ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/ exp127(int num, int exp) { int i; int val=1; for (i=1; i