File:  [Research Unix] / researchv10dc / cmd / icon / ipl / source / delamc.icn
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:21:34 2018 UTC (8 years, 3 months ago) by root
Branches: belllabs, MAIN
CVS tags: researchv10, HEAD
researchv10 Dan Cross

#	DELAMC
#
#	Delaminate file using tab characters
#
#	Thomas R. Hicks
#
#	Last modified 2/9/86 by Ralph E. Griswold
#

procedure main(a)
   local tabset, fylist, nxtarg
   if match("-t",a[1]) then		# tab char given
      tabset := cset(a[1][3:0])
    if 0 = *(fylist := doutfyls(a)) then Usage()
    /tabset := cset(&ascii[10])			# tab is default separator
    delamrc(tabset,fylist)			# call main routine
end

# Usage - write usage message
#
procedure Usage()
    stop("usage: delamc [-tc] {outputfile | -} ...")
end

# delamrc - do actual division of input file using tab chars
#
procedure delamrc(tabset,fylist)
    local i, flen, line
    while line := read() do
        {
        i := 1
        flen := *fylist
        line ? while (i <= flen) do
            {
            if i = flen then
                write(fylist[i][2],tab(0) | "")
            else
                write(fylist[i][2],tab(upto(tabset)) | tab(0) | "")
            move(1)
            i +:= 1
            }
        }
end

# doutfyls - process output file arguments; return list
#
procedure doutfyls(a)
   local lst, x, i
   lst := []
   i := 2
   while \a[i] do {
      if x := llu(a[i],lst) then		# already in list
         lst |||:= [[a[i],lst[x][2]]]
      else					# not in list
         if a[i] == "-" then			# standard out
            lst |||:= [[a[i],&output]]
         else				# a new file
            if not (x := open(a[i],"w")) then
               stop("Cannot open ",a[i]," for output")
            else lst |||:= [[a[i],x]]
      i +:= 1
      }
   return lst
end

# llu - lookup file name in output file list
#
procedure llu(str,lst)
   local i
   i := 1
   while \lst[i] do {
      if \lst[i][1] == str then return i
      i +:= 1
      }
end

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.