/*
 * LpStat.c :
 * ----------
 * Auteur         : Xavier Mertens  
 * Version        : 1 
 * Révision       : 00 
 * Langage        : Lattice c v5.0
 * Compatibilité  : 1.3 - 2.x
 * Description    : Commande style Unix : paramètrage de PRT:  
 *
 */

#include <stdio.h>

#define TRUE      1L

#define USAGE     108 /* -? */
#define NORMAL    155 /* -n */
#define VERSION   131 /* -V */
#define ff        147
#define cc        144
#define CC        112
#define gg        148
#define cC        211
#define cf        246
#define cg        247
#define Cf        214
#define Cg        215
#define fg        250
#define cCf       313
#define cCg       314
#define Cfg       317
#define fgc       349
#define cCfg      416

#define RESET     "\033c"
#define NLQ       "\033[2\042z"
#define BOLD      "\033[1m"
#define FRENCH    "\033(B"
#define CONDENSED "\033[4w"

#define PRINTER   "PRT:"

int CheckSum(register char s[]){
  register int i;
  register int cs=0;
  for(i=0;i<strlen(s);i++)
    cs+=s[i];
  return(cs);
}

main(int argc,char *argv[]){
  if(argc!=2){
    puts("Syntaxe incorrecte!\n");
    exit(5);
  }
  switch(CheckSum(argv[1])){
    case USAGE:
      puts("Usage : lpstat [ -?V ]");
      puts("        lpstat [ -cCfg ]\n");
      exit(5);
    case VERSION:
      puts("LpStat version 1.00 écrit par Xavier Mertens,Juin 92.\n");
      exit(5);
    case NORMAL:
      Send2Prt(RESET);
      exit(0);
    case ff:
      Send2Prt(FRENCH);
      exit(0);
    case cc:
      Send2Prt(CONDENSED);
      exit(0);
    case CC:
      Send2Prt(NLQ);
      exit(0);
    case gg:
      Send2Prt(BOLD);
      exit(0);
    case cC:
      Send2Prt(CONDENSED);
      Send2Prt(NLQ);
      exit(0);
    case cf:
      Send2Prt(CONDENSED);
      Send2Prt(FRENCH);
      exit(0);
    case cg:
      Send2Prt(CONDENSED);
      Send2Prt(BOLD);
      exit(0);
    case Cf:
      Send2Prt(NLQ);
      Send2Prt(FRENCH);
      exit(0);
    case Cg:
      Send2Prt(NLQ);
      Send2Prt(FRENCH);
      exit(0);
    case fg:
      Send2Prt(FRENCH);
      Send2Prt(BOLD);
      exit(0);
    case cCf:
      Send2Prt(CONDENSED);
      Send2Prt(NLQ);
      Send2Prt(FRENCH);
      exit(0);
    case cCg:
      Send2Prt(CONDENSED);
      Send2Prt(NLQ);
      Send2Prt(BOLD);
      exit(0);
    case Cfg:
      Send2Prt(NLQ);
      Send2Prt(FRENCH);
      Send2Prt(BOLD);
      exit(0);
    case fgc:
      Send2Prt(FRENCH);
      Send2Prt(BOLD);
      Send2Prt(CONDENSED);
      exit(0);
    case cCfg:
      Send2Prt(CONDENSED);
      Send2Prt(NLQ);
      Send2Prt(FRENCH);
      Send2Prt(BOLD);
      exit(0);
    default:
      puts("Syntaxe incorrecte!\n");
      exit(5);
  }
}

Send2Prt(char *Code){
  FILE *Prt,*fopen();
  if(!(Prt=fopen(PRINTER,"w"))){
    puts("Can't find printer!?!\n");
    exit(5);
  }
  fprintf(Prt,"%s",Code);
  fclose(Prt);
  return(TRUE);
}

/* eof */
