DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download
Index: ┃ T t

⟦e70053dc4⟧ TextFile

    Length: 1711 (0x6af)
    Types: TextFile
    Names: »tabs.c«

Derivation

└─⟦a0efdde77⟧ Bits:30001252 EUUGD11 Tape, 1987 Spring Conference Helsinki
    └─ ⟦this⟧ »EUUGD11/euug-87hel/sec1/tabs/tabs.c« 

TextFile

/* tabs.c by Robert A. Larson
 */

#include <stdio.h>
#define inchar()	getc(stdin)
#define outchar(c)	putc(c, stdout)
#define TRUE	1
#define FALSE	0

static unsigned otab = 8;
static unsigned lpos = 0;
static unsigned nsp  = 0;

outspace() {
  register int i;
  if(otab) {
    while(nsp>1 && nsp >= (i=otab-(lpos%otab))) {
      outchar('\t');
      nsp -= i;
      lpos += i;
    }
  }
  lpos += nsp;
  while(nsp--) outchar(' ');
  nsp = 0;
}

main(argc,argv)
int argc;
register char **argv;
{
  register int c;
  register unsigned itab = 8;
  register int trailsup	 = FALSE;

  while(--argc) {
    switch(**++argv) {
      case '-':
	for(;;) {
	  switch(*++*argv) {
	    case '\0': goto nextarg;
	    case 'i':
	      itab = 0;
	      while((c = *++*argv)>='0' && c<='9') {
		itab *= 10;
		itab += c - '0';
	      }
	      (*argv)--;
	      break;
	    case 'o':
	      otab = 0;
	      while((c = *++*argv)>='0' && c<='9') {
		otab *= 10;
		otab += c - '0';
	      }
	      (*argv)--;
	      break;
	    case 't':
	      trailsup = TRUE;
	      break;
	    default:
	      fprintf(stderr, "Unknown switch: %c\n", **argv);
	      exit(1);
	  }
	}
nextarg: break;
      default:
	fprintf(stderr, "Illegal agument: %s\n", *argv);
	exit(1);
    }
  }
  for(;;){
    switch(c = inchar()){
      case -1:
	if(nsp && !trailsup) outspace();  /* in case the file ends in space */
	exit(0);
      case ' ':
	nsp++;
	break;
      case '\t':
	if(itab) nsp += itab - ((lpos+nsp)%itab);
	else {
	  if(nsp) outspace();
	  outchar(c);
	  lpos++;
	}
	break;
      case '\n':
	if(nsp && !trailsup) outspace();
	outchar(c);
	lpos = nsp = 0;
	break;
      default:
	if(nsp) outspace();
	outchar(c);
	lpos++;
	break;
    }
  }
}