home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d6xx / d683 / printfiles.lha / PrintFiles / Source.lha / Source / prf_main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-16  |  9.1 KB  |  344 lines

  1.  
  2. /* prf_main.c */
  3. /* V091 9-3-92 */
  4.  
  5. #include "prf.h"
  6.  
  7. /* ------------------------------------------------------------------- */
  8. /*      for cback.o startup                                            */
  9. /* ------------------------------------------------------------------- */
  10.  
  11. long                      _stack        = 4000;
  12. char                      *_procname    = "*PrintFiles V1.1*";
  13. long                      priority      = 0;
  14. long                      _BackGroundIO = 0;
  15. extern BPTR               _Backstdout;
  16.  
  17. /* ----------------------------------------------------------------- */
  18.  
  19. void __regargs CheckCmdLine(struct prf_info *,int,union wbstart);
  20. void __regargs SetSTFlags(struct prf_info *,UBYTE *);
  21.  
  22.  
  23. struct IntuitionBase *IntuitionBase;
  24. struct Library       *WorkbenchBase;
  25. struct Library       *GadToolsBase;
  26. struct Library       *AslBase;
  27. struct Library       *IconBase;
  28. struct RxsLib        *RexxSysBase;
  29. struct GfxBase       *GfxBase;
  30.  
  31. void  main(int argc ,union wbstart argv)
  32. {
  33.  struct prf_info *info;
  34.  long end = (long)FALSE;
  35.  if(info = (struct prf_info *)calloc(1,sizeof(struct prf_info)))
  36.  {
  37.   if(OpenLibs(info))
  38.   {
  39.    if(OpenApp(info))
  40.    {
  41.     CheckCmdLine(info,argc,argv);
  42.     SetPrfSignals(info);
  43.     if(info->flags.openwindow)
  44.     {
  45.      info->flags.openwindow = 0;
  46.      ChangeApp(info);
  47.     }
  48.     if(info->flags.immediate)
  49.     {
  50.      info->flags.immediate = 0;
  51.      PrintQueue(info);
  52.     }
  53.     while(!end)
  54.     {
  55.      SetPrfSignals(info);
  56.      Wait(info->signals);
  57.      if(DoCommand(info,HandleMsgs(info)) == CMD_QUIT) end = (long)TRUE;
  58.     }
  59.     CloseApp(info);
  60.    }
  61.   }
  62.   CloseLibs(info);
  63.  }
  64.  exit(0);
  65. }
  66.  
  67. long  __regargs OpenLibs(struct prf_info *info)
  68. {
  69.  if(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",SYSTEM_VERSION))
  70.  {
  71.   if(WorkbenchBase = OpenLibrary("workbench.library",SYSTEM_VERSION))
  72.   {
  73.    if(AslBase = OpenLibrary("asl.library",SYSTEM_VERSION))
  74.    {
  75.     if(GadToolsBase = OpenLibrary("gadtools.library",SYSTEM_VERSION))
  76.     {
  77.      if(IconBase = OpenLibrary("icon.library",SYSTEM_VERSION))
  78.      {
  79.       if(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",SYSTEM_VERSION))
  80.       {
  81.        if(info->PubScr = LockPubScreen( "Workbench" ))
  82.        {
  83.         info->BarHeight = (ULONG)((long)(info->PubScr->BarHeight));
  84.         PwdTags[3].ti_Data    += info->BarHeight ;
  85.         SwdTags[3].ti_Data    += info->BarHeight ;
  86.         if(info->VisualInfo = GetVisualInfo(info->PubScr,TAG_DONE ))
  87.         {
  88.          NewList(&info->FileList);
  89.          AttemptOpenRexx(info);
  90.          Prf_Reset(info);
  91.          return ((long)TRUE);
  92.         }
  93.        }
  94.       }
  95.      }
  96.     }
  97.    }
  98.   }
  99.  }
  100.  return ((long)FALSE);
  101.  
  102. }
  103.  
  104. void  __regargs CloseLibs(struct prf_info *info)
  105. {
  106.  struct Node *n;
  107.  if(info)
  108.  {
  109.   CloseRexx(info);
  110.   if(info->Swd)CloseSwd(info);
  111.   if(info->Pwd)ClosePwd(info);
  112.   if(info->VisualInfo) FreeVisualInfo(info->VisualInfo);
  113.   if(info->PubScr)UnlockPubScreen(0L,info->PubScr);
  114.   while(n = (struct Node *)RemHead(&info->FileList))free((struct FileNameNode *)n);
  115.   free(info);
  116.  }
  117.  if (GfxBase)         CloseLibrary((struct Library *)GfxBase);
  118.  if (IconBase)        CloseLibrary(IconBase);
  119.  if (GadToolsBase)    CloseLibrary(GadToolsBase);
  120.  if (AslBase)         CloseLibrary(AslBase);
  121.  if (WorkbenchBase)   CloseLibrary(WorkbenchBase);
  122.  if (IntuitionBase)   CloseLibrary((struct Library *)IntuitionBase);
  123. }
  124.  
  125. void  __regargs Prf_Reset(struct prf_info *info)
  126. {
  127.  struct Node *n;
  128.  while(n = (struct Node *)RemHead(&info->FileList))free((struct FileNameNode *)n);
  129.  info->Lines   = DEFAULT_LINES;
  130.  info->Rmargin = DEFAULT_RMARGIN;
  131.  info->Lmargin = DEFAULT_LMARGIN;
  132.  info->Lines   = DEFAULT_LINES;
  133.    info->flags.draft   = 1;
  134.    info->flags.lq      = 0;
  135.    info->flags.ffpage  = 1;
  136.    info->flags.cpi     = 3;
  137.    info->flags.pitch   = 2;
  138.    info->flags.display = 1;
  139.  info->Columns = DEFAULT_RMARGIN - DEFAULT_LMARGIN;
  140.  strcpy(info->Headline, DEFAULT_HEADLINE);
  141.  strcpy(info->Footline, DEFAULT_FOOTLINE);
  142.  RefreshPwd(info);
  143.  RefreshSwd(info);
  144. }
  145.  
  146. void __regargs SetPrfSignals(struct prf_info *info)
  147. {
  148.  info->signals = 0L;
  149.  if(info->Swd)      info->signals |= (1L << info->Swd->UserPort->mp_SigBit);
  150.  if(info->Pwd)      info->signals |= (1L << info->Pwd->UserPort->mp_SigBit);
  151.  if(info->appPort)  info->signals |= (1L << info->appPort->mp_SigBit);
  152.  if(info->rexxPort) info->signals |= (1L << info->rexxPort->mp_SigBit);
  153.  if(info->prtPort)  info->signals |= (1L << info->prtPort->mp_SigBit);
  154. }
  155.  
  156. long __regargs HandleMsgs(struct prf_info *info)
  157. {
  158.  long rc = CMD_NEUTRAL;
  159.  if(info->Swd)
  160.  {
  161.   while(info->imsg = GT_GetIMsg(info->Swd->UserPort))
  162.   {
  163.    long rc1;
  164.    if((rc1 = HandleImsg(info)) != CMD_NEUTRAL)rc = rc1;
  165.    GT_ReplyIMsg(info->imsg);
  166.   }
  167.  }
  168.  if(info->Pwd)
  169.  {
  170.   while(info->imsg = GT_GetIMsg(info->Pwd->UserPort))
  171.   {
  172.    long rc1;
  173.    if((rc1 = HandleImsg(info)) != CMD_NEUTRAL)rc = rc1;
  174.    GT_ReplyIMsg(info->imsg);
  175.   }
  176.  }
  177.  if(info->appPort)
  178.  {
  179.   while(info->amsg = (struct AppMessage *)GetMsg(info->appPort))
  180.   {
  181.    long rc1;
  182.    if((rc1 = HandleAmsg(info)) != CMD_NEUTRAL)rc = rc1;
  183.    ReplyMsg((struct Message *)info->amsg);
  184.   }
  185.  }
  186.  if(info->rexxPort)
  187.  {
  188.   while(info->rmsg = (struct RexxMsg *)GetMsg(info->rexxPort))
  189.   {
  190.    long rc1;
  191.    if((rc1 = HandleRexxMsg(info)) != CMD_NEUTRAL)rc = rc1;
  192.    ReplyMsg((struct Message *)info->rmsg);
  193.   }
  194.  }
  195.  if(info->prtPort)
  196.  {
  197.   if(GetMsg(info->prtPort)) rc = CMD_CLOSEPRINTER;
  198.  }
  199.  return (rc);
  200. }
  201.  
  202. void __regargs CheckCmdLine(struct prf_info *info,int argc,union wbstart argv)
  203. {
  204.  struct DiskObject *dobj;
  205.  UBYTE *p,buffer[256],**tta;
  206.  ULONG a,b;
  207.  long cmd = CMD_INSERTTAIL;
  208.  int  i;
  209.  if(argc)
  210.  {
  211.   if(argc > 1)
  212.   {
  213.    for(i=1;i<argc;i++)
  214.    {
  215.     switch(argv.args[i][0])
  216.     {
  217.      case  '-': SetSTFlags(info,&argv.args[i][1]);
  218.                 break;
  219.      default  : info->flags.immediate = 1;
  220.                 info->Special1 = (APTR)&argv.args[i][0];
  221.                 info->Special2 = (APTR)&cmd;
  222.                 InsertName(info);
  223.                 info->Special1 = NULL;
  224.                 info->Special2 = NULL;
  225.                 break;
  226.     }
  227.    }
  228.   }
  229.  }
  230.  else
  231.  {
  232.   if(dobj = GetDiskObject(argv.msg->sm_ArgList->wa_Name))
  233.   {
  234.    tta = dobj->do_ToolTypes;
  235.    if(p = (UBYTE *)FindToolType(tta,TOOLTYPE_WD))
  236.    {
  237.     i = sscanf(p,"%ld %ld",&a,&b);
  238.     if(i == 2)
  239.     {
  240.      SwdTags[0].ti_Data = a;
  241.      SwdTags[1].ti_Data = b;
  242.     }
  243.     info->flags.openwindow = 1;
  244.    }
  245.    if(p = (UBYTE *)FindToolType(tta,TOOLTYPE_FLAGS))
  246.    {
  247.     strcpy(buffer,p);
  248.     SetSTFlags(info,buffer);
  249.    }
  250.    if(p = (UBYTE *)FindToolType(tta,TOOLTYPE_HEAD))
  251.    {
  252.     strcpy(info->Headline,p);
  253.    }
  254.    if(p = (UBYTE *)FindToolType(tta,TOOLTYPE_FOOT))
  255.    {
  256.     strcpy(info->Footline,p);
  257.    }
  258.    if(p = (UBYTE *)FindToolType(tta,TOOLTYPE_LMARGIN))
  259.    {
  260.     info->Lmargin = atol(p);
  261.     if(info->Lmargin > info->Rmargin)info->Lmargin = DEFAULT_LMARGIN;
  262.     if((info->Columns = (info->Rmargin - info->Lmargin)) == 0)
  263.      info->Columns = 1;
  264.    }
  265.    if(p = (UBYTE *)FindToolType(tta,TOOLTYPE_RMARGIN))
  266.    {
  267.     info->Rmargin = atol(p);
  268.     if(info->Rmargin < info->Lmargin)info->Rmargin = DEFAULT_RMARGIN;
  269.     if((info->Columns = (info->Rmargin - info->Lmargin)) == 0)
  270.      info->Columns = 1;
  271.    }
  272.    if(p = (UBYTE *)FindToolType(tta,TOOLTYPE_LINES))
  273.    {
  274.     info->Lines = atol(p);
  275.    }
  276.   }
  277.   if(argv.msg->sm_NumArgs > 1)
  278.   {
  279.    info->flags.immediate = 1;
  280.    for(i = 1; i < argv.msg->sm_NumArgs;i++)
  281.    {
  282.     NameFromLock(argv.msg->sm_ArgList[i].wa_Lock,buffer,STR_SIZE);
  283.     AddPart(buffer,argv.msg->sm_ArgList[i].wa_Name,STR_SIZE);
  284.     info->Special1 = (APTR)buffer;
  285.     info->Special2 = (APTR)&cmd;
  286.     InsertName(info);
  287.     info->Special1 = NULL;
  288.     info->Special2 = NULL;
  289.    }
  290.   }
  291.  }
  292. }
  293.  
  294. /* ----------------------------------------------------------------- */
  295. void __regargs SetSTFlags(struct prf_info *info,UBYTE *buffer)
  296. {
  297.  int i;
  298.  for(i=0;i< strlen(buffer);i++)
  299.  {
  300.   switch(*(buffer+i))
  301.   {
  302.    case CLI_TIME   : info->flags.time = 1;
  303.                      break;
  304.    case CLI_FF     : info->flags.ff   = 1;
  305.                      break;
  306.    case CLI_FILE   : info->flags.file = 1;
  307.                      break;
  308.    case CLI_PAGE   : info->flags.page = 1;
  309.                      break;
  310.    case CLI_LINE   : info->flags.line = 1;
  311.                      break;
  312.    case CLI_FFPAGE : info->flags.ffpage = 1;
  313.                      break;
  314.    case CLI_DRAFT  : DoCommand(info,CMD_DRAFT);
  315.                      break;
  316.    case CLI_LQ     : DoCommand(info,CMD_LQ);
  317.                      break;
  318.    case CLI_DATE   : info->flags.date = 1;
  319.                      break;
  320.    case CLI_WD     : info->flags.openwindow = 1;
  321.                      break;
  322.    case CLI_10CPI  : DoCommand(info,CMD_10CPI);
  323.                      break;
  324.    case CLI_12CPI  : DoCommand(info,CMD_12CPI);
  325.                      break;
  326.    case CLI_15CPI  : DoCommand(info,CMD_15CPI);
  327.                      break;
  328.    case CLI_PITCH6 : DoCommand(info,CMD_PITCH6);
  329.                      break;
  330.    case CLI_PITCH8 : DoCommand(info,CMD_PITCH8);
  331.                      break;
  332.    default  : break;
  333.   }
  334.  }
  335. }
  336. /* ----------------------------------------------------------------- */
  337. /* ----------------------------------------------------------------- */
  338. /* ----------------------------------------------------------------- */
  339. /* ----------------------------------------------------------------- */
  340. /* ----------------------------------------------------------------- */
  341.  
  342.  
  343.  
  344.