/***********************************************
 * released under (E) licensing ...            *
 *        (E) RULES AND REGULATIONS            *
 * permission to use/rewrite/add     : granted *
 * permission to trojan/steal        : denied  *
 * permission to use illegally       : denied  *
 * permission to use on /dev/urandom : denied  *
 ***********************************************/
/* contact el8@press.co.jp for full license    */
/* code copyrighted by ~el8 -- don't infringe! */

#include <stdio.h>
#include <stdlib.h>
int verbose;
char *asort(char arr[])
{
   register int y=0,c=0;
   int arrlen = strlen(arr);
   register char tmp;

   for(;;){
      if ( ((int) (arr[y])) > ((int) (arr[y+1])) && arr[y+1]!=(char)NULL )
	{ c++; tmp=arr[y+1]; arr[y+1]=arr[y]; arr[y]=tmp; }
      if ((y+1)>=arrlen) { y=-1; if (c==0) break; else c=0; }
      if (verbose==1) { printf("%s\n",arr); }
      else if (verbose==2) { (void)putchar('*'); }
      y++;
      }
     if (verbose!=-1)
         printf("%s\n",arr);

     return arr;
}

int main(int argc,char *argv[])
{
  int x=0;
  char buf[1024];
  if (argc<2) {
      (void)fprintf(stderr,"usage: %s - | [string1 string2 ...]\n"
                           "-[v | d | q]\n",argv[0]);
      exit(-1);
  }
  if (!strcmp(argv[argc-1],"-v"))
  {
    verbose = 1;
    argc--;
  }
  else
  if (!strcmp(argv[argc-1],"-d"))
  {
    verbose = 2;
    argc--;
  }
  else
  if (!strcmp(argv[argc-1],"-q"))
  {
    verbose = -1;
    argc--;
  }
  else
    verbose = 0;
  if (!strcmp(argv[argc-1],"-"))
  {
      for(;fgets(buf,1024,stdin);)
           asort(buf);
  } else {
           for(x=1;x<argc;x++)
               asort(argv[x]);
  }
  return;
}


syntax highlighted by Code2HTML, v. 0.9.1