home *** CD-ROM | disk | FTP | other *** search
- -h- dodash.tra 818
- { dodash - expand set at src[i] into dest[j], stop at delim }
- procedure dodash (delim : character; var src : string;
- var i : integer; var dest : string;
- var j : integer; maxset : integer);
- var
- k : integer;
- junk : boolean;
- begin
- while (src[i] <> delim) and (src[i] <> ENDSTR) do begin
- if (src[i] = ESCAPE) then
- junk := addstr(esc(src, i), dest, j, maxset)
- else if (src[i] <> DASH) then
- junk := addstr(src[i], dest, j, maxset)
- else if (j <= 1) or (src[i+1] = ENDSTR) then
- junk := addstr(DASH,dest,j,maxset) { literal - }
- else if (isalphanum(src[i-1]))
- and (isalphanum(src[i+1]))
- and (src[i-1] <= src[i+1]) then begin
- for k := src[i-1]+1 to src[i+1] do
- junk := addstr(k, dest, j, maxset);
- i := i + 1
- end
- else
- junk := addstr(DASH, dest, j, maxset);
- i := i + 1
- end
- end;
-
- -h- makeset.tra 306
- { makeset -- make set from inset[k] in outset }
- function makeset (var inset : string; k : integer;
- var outset : string; maxset : integer) : boolean;
- var
- j : integer;
- {$include:'dodash.tra'}
- begin
- j := 1;
- dodash(ENDSTR, inset, k, outset, j, maxset);
- makeset := addstr(ENDSTR, outset, j, maxset)
- end;
-
- -h- translit.tra 1224
- { translit -- map characters }
- procedure translit;
- const
- NEGATE = CARET; { ^ }
- var
- arg, fromset, toset : string;
- c : character;
- i, lastto : 0..MAXSTR;
- allbut, squash : boolean;
- {$include:'makeset.tra'}
- {$include:'xindex.tra' }
- begin
- if (not getarg(1, arg, MAXSTR)) then
- error('usage: translit from to');
- allbut := (arg[1] = NEGATE);
- if (allbut) then
- i := 2
- else
- i := 1;
- if (not makeset(arg, i, fromset, MAXSTR)) then
- error('translit: "from" set too large');
- if (not getarg(2, arg, MAXSTR)) then
- toset[1] := ENDSTR
- else if (not makeset(arg, 1, toset, MAXSTR)) then
- error('translit: "to" set too large')
- else if (length(fromset) < length(toset)) then
- error('translit: "from" shorter than "to"');
-
- lastto := length(toset);
- squash := (length(fromset) > lastto) or (allbut);
- repeat
- i := xindex(fromset, getc(c), allbut, lastto);
- if (squash) and (i>=lastto) and (lastto>0) then begin
- putc(toset[lastto]);
- repeat
- i := xindex(fromset, getc(c), allbut, lastto)
- until (i < lastto)
- end;
- if (c <> ENDFILE) then begin
- if (i > 0) and (lastto > 0) then { translate }
- putc(toset[i])
- else if (i = 0) then { copy }
- putc(c)
- { else delete }
- end
- until (c = ENDFILE)
- end;
-
- -h- xindex.tra 335
- { xindex -- conditionally invert value from index }
- function xindex (var inset : string; c : character;
- allbut : boolean; lastto : integer) : integer;
- begin
- if (c = ENDFILE) then
- xindex := 0
- else if (not allbut) then
- xindex := index(inset, c)
- else if (index(inset, c) > 0) then
- xindex := 0
- else
- xindex := lastto + 1
- end;
- -h- translit.pas 461
- {$debug-}
- program outer (input,output);
-
- {$include:'globcons.inc'}
- {$include:'globtyps.inc'}
-
- {$include:'initio.dcl'}
- {$include:'flush.dcl' }
-
- {$include:'isalphan.dcl'}
- {$include:'error.dcl' }
- {$include:'getc.dcl' }
- {$include:'putc.dcl' }
- {$include:'getarg.dcl' }
- {$include:'length.dcl' }
- {$include:'addstr.dcl' }
- {$include:'index.dcl' }
- {$include:'esc.dcl' }
-
- {$include:'translit.tra' }
- BEGIN
- minitio; initio;
- translit;
- flush(0);
- END.
- -h- translit.mak 98
- translit+initio+getfcb+error+getarg+nargs+length+isalphan+
- getc+putc+addstr+index+esc+flush+putcf