#include <stdio.h>
#define progname "adhead"

short asize=128 ;    /* pic dimensions */

FILE *fp, *fq = NULL;            /* input,output picture channels */
 
main(argc,argv)
char **argv;
{

  argv++;
  while ((argc>1)&&((*argv)[0] == '-'))
  {

    switch((*argv)[1]) {
    case 'x':
      sscanf(*argv+2,"%hd",&asize);
      if(asize<0||asize>255) error("picture size");
      break;
    default:
      error("unknown flag");
      break;
    }
    --argc;argv++;
  }
 
  if (argc<3)
    error("missing arguments");
  else
  {
    if((fp = fopen(*argv++,"r")) == NULL)
      error("can't access input file");
    --argc;

    if((fq = fopen(*argv,"w")) == NULL)
      error("can't access output file");
  }
  adhead();
  fclose(fp);
  fclose(fq);
}
 
error(s)
char *s;
{
  fprintf(stderr,"%s: %s\n",progname,s);
  exit(1);
}
 
adhead()
{
long i,area;
  area = asize*asize;

  putc(asize,fq);

  for (i=0;i<area;i++) {
       putc((getc(fp)&0377),fq);
   }
}
