#-h- detab.r 2908 asc 07-may-80 15:21:50 #-h- main 268 asc 07-may-80 15:21:40 #-------------------------------------------------------------------- #include symbols definitions # include symbols #-------------------------------------------------------------------- ## detab -- main program # call initr4 # call dotab # call endr4 # end #-h- dotab 746 asc 07-may-80 15:21:41 ## dotab - driver for detab tool # subroutine dotab subroutine main character buf(MAXLINE) integer open, getarg, length, alldig integer tabs(MAXLINE), int, i, k, l call settab(tabs) # set initial tab stops int = ERR for (i=1; getarg(i, buf, MAXLINE) != EOF; i=i+1) { if (buf(1) == QMARK) call error ("usage: detab [...] [+] [file...]") if (buf(1) == PLUS | alldig(buf) == YES) #ignore flags next if (buf(1) == MINUS & buf(2) == EOS) #read from standard input int = STDIN else int = open(buf, READ) if (int == ERR) call cant(buf) call detab (tabs, int) if (int != STDIN) call close(int) } if (int == ERR) #no files read call detab(tabs, STDIN) return end #-h- detabs 603 asc 07-may-80 15:21:42 ## detab - convert tabs to equivalent number of blanks subroutine detab (tabs, int) integer int character getch character c integer tabs(ARB) integer tabpos integer col col = 1 while (getch(c, int) != EOF) if (c == TAB) repeat { call putc(BLANK) col = col + 1 if (tabpos(col, tabs) == YES) break } else if (c == NEWLINE) { call putc(NEWLINE) col = 1 } else { call putc(c) col = col + 1 } return end #-h- settab 820 asc 07-may-80 15:21:42 # settab - set initial tab stops subroutine settab(tabs) integer alldig integer tabs(MAXLINE), m, p, k, i, j, l integer getarg, ctoi character n(4) p = 0 for (i=1; i<=MAXLINE; i=i+1) tabs(i) = NO for (j=1; getarg(j,n,4)!=EOF; j=j+1) { k=1 if (n(1) == PLUS) k = k + 1 if (alldig(n(k)) == NO) next l = ctoi(n,k) if (l<=0 | l>MAXLINE) next if (n(1)!=PLUS) { p = l tabs(p) = YES } else { if (p==0) p = l + 1 for (m=p; m<=MAXLINE; m=m+l) tabs(m) = YES } } if (p==0) { for (i=9; i<=MAXLINE; i=i+8) tabs(i) = YES } return end #-h- tabpos 226 asc 07-may-80 15:21:43 # tabpos - return YES if col is a tab stop integer function tabpos(col, tabs) integer col, i, tabs(MAXLINE) if (col > MAXLINE) tabpos = YES else tabpos = tabs(col) return end