home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 613b.lha / PrLabel_v1.1 / src.LZH / src / main.c < prev    next >
C/C++ Source or Header  |  1992-01-31  |  15KB  |  473 lines

  1. /***************************************************************************
  2.  
  3.    Program:    PrLabel
  4.    File:       main.c
  5.    
  6.    Version:    V1.1
  7.    Date:       28.10.91
  8.    Function:   Main routine
  9.    
  10.    Copyright:  SciTech Software 1991
  11.    Author:     Andrew C. R. Martin
  12.    Address:    SciTech Software
  13.                23, Stag Leys,
  14.                Ashtead,
  15.                Surrey,
  16.                KT21 2TD.
  17.    Phone:      +44 (0372) 275775
  18.    EMail:      UUCP: cbmuk!cbmuka!scitec!amartin
  19.                JANET: andrew@uk.ac.ox.biop
  20.                
  21. ****************************************************************************
  22.  
  23.    This program is Shareware with a suggested donation of £5.00.
  24.    It may be freely copied and distributed for no more than a nominal charge 
  25.    (not more than £4.00 in the U.K.) providing this header is included.
  26.    
  27.    The code may be modified as required, but any modifications must be
  28.    documented so that the person responsible can be identified. If someone
  29.    else breaks this code, I don't want to be blamed for code that does not
  30.    work! The code may not be sold commercially without prior permission from
  31.    the author, although it may be given away free with commercial products,
  32.    providing it is made clear that this program is free and that the source
  33.    code is provided with the program.
  34.  
  35. ****************************************************************************
  36.  
  37.    Description:
  38.    ============
  39.    PrLabel is a program to print text for laser labels.
  40.  
  41.    It uses STSLib to create 3D-look gadgets (under AmigaDOS V1.3 and V2.0)
  42.    and menus which will resize with the system default font.
  43.    
  44.    STSLib is available from SciTech Software for £20.00. This includes a 
  45.    full printed manual (>50 A5 pages) and the latest version of STSLib on
  46.    disk with source code.
  47.  
  48. ****************************************************************************
  49.  
  50.    Usage:
  51.    ======
  52.    PrLabel [-27][-28][-38]
  53.  
  54.    From the CLI, PrLabel may be invoked with one of the flags shown to 
  55.    select the label layout. This defaults to 3x8.
  56.  
  57.    From the Workbench, the Tooltype field may be set to one of:
  58.    FORMAT=27
  59.    FORMAT=28
  60.    FORMAT=38
  61.    to get the same result.
  62.  
  63. ****************************************************************************
  64.  
  65.    Revision History:
  66.    =================
  67.    V1.1     17.01.92
  68.    Changed interface to use STSLib.
  69.    
  70.  
  71. ***************************************************************************/
  72. #define MAIN 1
  73.  
  74. #include "PrLabel.h"
  75.  
  76. #include <stdio.h>
  77. #include <sts/stslib.h>
  78.  
  79. extern struct WBStartup *WBenchMsg; /* This is so we can get the program name */
  80.  
  81. /**************************************************************************/
  82. main(int argc,
  83.      char **argv)
  84. {
  85.    /* Dik object structure for parsing tool types */
  86.    struct DiskObject *DiskObj = NULL;
  87.  
  88.    /* Variables for IDCMP handling */
  89.    struct   IntuiMessage *message;
  90.    ULONG    Signals;
  91.    ULONG    MIClass;
  92.    USHORT   MICode;
  93.    APTR     MIAddress;
  94.  
  95.    /* Set default sheet type */
  96.    SetSheet38((APTR)1);
  97.  
  98.    OpenLibraries();
  99.  
  100.    if(argc == 0)  /* Started from Workbench */
  101.    {
  102.       if(DiskObj = (struct DiskObject *)GetDiskObject(WBenchMsg->sm_ArgList->wa_Name))
  103.       {
  104.          if(MatchToolValue(FindToolType(DiskObj->do_ToolTypes,"FORMAT"),"38"))
  105.             SetSheet38((APTR)1);
  106.          if(MatchToolValue(FindToolType(DiskObj->do_ToolTypes,"FORMAT"),"28"))
  107.             SetSheet28((APTR)1);
  108.          if(MatchToolValue(FindToolType(DiskObj->do_ToolTypes,"FORMAT"),"27"))
  109.             SetSheet27((APTR)1);
  110.          FreeDiskObject(DiskObj);
  111.       }
  112.       else
  113.       {
  114.          Die("Unable to get disk object information.");
  115.       }  
  116.    }
  117.    else
  118.    {
  119.       while(--argc)
  120.       {
  121.          argv++;
  122.          if(argv[0][0] == '?')
  123.          {
  124.             Usage();
  125.          }
  126.          else if(argv[0][0] == '-')
  127.          {
  128.             switch(argv[0][1])
  129.             {
  130.             case '3':
  131.                SetSheet38((APTR)1);
  132.                break;
  133.             case '2':
  134.                {
  135.                   switch(argv[0][2])
  136.                   {
  137.                   case '7':
  138.                      SetSheet27((APTR)1);
  139.                      break;
  140.                   case '8':
  141.                      SetSheet28((APTR)1);
  142.                      break;
  143.                   default:
  144.                      Usage();
  145.                   }
  146.                }
  147.                break;
  148.             default:
  149.                Usage();
  150.             }
  151.          }
  152.       }
  153.    }
  154.  
  155.    OpenDisplay();
  156.  
  157.    switch(SheetType)
  158.    {
  159.    case THREE_EIGHT:
  160.       Label38();
  161.       break;
  162.    case TWO_EIGHT:
  163.       Label28();
  164.       break;
  165.    case TWO_SEVEN:
  166.       Label27();
  167.       break;
  168.    default:
  169.       break;
  170.    }
  171.  
  172.    /* Allocate space for first item in address label list */
  173.    address = (ADDR *)malloc(sizeof(ADDR));
  174.    if(!address)
  175.    {
  176.       Die("Unable to allocate memory");
  177.    }
  178.    address->line[0][0] = '\0';
  179.    address->line[1][0] = '\0';
  180.    address->line[2][0] = '\0';
  181.    address->line[3][0] = '\0';
  182.    address->line[4][0] = '\0';
  183.    address->line[5][0] = '\0';
  184.    address->line[6][0] = '\0';
  185.    address->prev       = NULL;
  186.    address->next       = NULL;
  187.  
  188.    /* Initialise so we don't print any labels to start */
  189.    ClearPrint();
  190.  
  191.    /* Activate the first text line gadget */
  192.    GoLine1((APTR)1);
  193.    
  194.    /* Main program loop */
  195.    for(;;)
  196.    {
  197.       /* Wait for messages from window */
  198.       Signals = Wait(1<<Window->UserPort->mp_SigBit);
  199.       /* Handle messages from the window */
  200.       while (message = (struct IntuiMessage *)
  201.          GetMsg(Window->UserPort))
  202.       {
  203.          MIClass   = message->Class;
  204.          MICode    = message->Code;
  205.          MIAddress = message->IAddress;
  206.          
  207.  
  208.          ReplyMsg(message);
  209.  
  210.          switch (MIClass)
  211.          {
  212.             case MENUPICK:
  213.                if ((MICode) != MENUNULL)
  214.                {
  215.                   HandleMenu(MICode);
  216.                }
  217.                break;
  218.  
  219.             case GADGETDOWN:
  220.                break;
  221.  
  222.             case GADGETUP:
  223.                HandleEvent(MIAddress);
  224.                break;
  225.                
  226.             case CLOSEWINDOW:
  227.                QuitProgram((APTR)1);
  228.                break;
  229.  
  230.             default:
  231.                break;
  232.          }
  233.       }
  234.    }
  235.  
  236.    return(0);
  237. }
  238.  
  239.  
  240. /**************************************************************************/
  241. void HandleEvent(object)
  242. APTR object;
  243. {
  244. /* Not yet supported
  245. //  if (object == (APTR)MenuItem1) { ReadList(object); return; }
  246. //  if (object == (APTR)MenuItem2) { SaveList(object); return; }
  247. */
  248.   if (object == (APTR)MenuItem3) { About(object); return; }
  249.   if (object == (APTR)MenuItem4) { QuitProgram(object); return; }
  250.   if (object == (APTR)pos11) { SetPos11(object); return; }
  251.   if (object == (APTR)pos12) { SetPos12(object); return; }
  252.   if (object == (APTR)pos14) { SetPos14(object); return; }
  253.   if (object == (APTR)pos13) { SetPos13(object); return; }
  254.   if (object == (APTR)pos15) { SetPos15(object); return; }
  255.   if (object == (APTR)pos16) { SetPos16(object); return; }
  256.   if (object == (APTR)pos17) { SetPos17(object); return; }
  257.   if (object == (APTR)pos21) { SetPos21(object); return; }
  258.   if (object == (APTR)pos22) { SetPos22(object); return; }
  259.   if (object == (APTR)pos23) { SetPos23(object); return; }
  260.   if (object == (APTR)pos24) { SetPos24(object); return; }
  261.   if (object == (APTR)pos25) { SetPos25(object); return; }
  262.   if (object == (APTR)pos26) { SetPos26(object); return; }
  263.   if (object == (APTR)pos27) { SetPos27(object); return; }
  264.   if (object == (APTR)Line1) { GoLine2(object); return; }
  265.   if (object == (APTR)Line2) { GoLine3(object); return; }
  266.   if (object == (APTR)Line3) { GoLine4(object); return; }
  267.   if (object == (APTR)Line4) { GoLine5(object); return; }
  268.   if (object == (APTR)Line5) { GoLine6(object); return; }
  269.   if (object == (APTR)Line6) { GoLine7(object); return; }
  270.   if (object == (APTR)Line7) { GoLine1(object); return; }
  271.   if (object == (APTR)Print) { PrintLabels(object); return; }
  272.   if (object == (APTR)pos18) { SetPos18(object); return; }
  273.   if (object == (APTR)pos28) { SetPos28(object); return; }
  274.   if (object == (APTR)pos31) { SetPos31(object); return; }
  275.   if (object == (APTR)pos32) { SetPos32(object); return; }
  276.   if (object == (APTR)pos33) { SetPos33(object); return; }
  277.   if (object == (APTR)pos34) { SetPos34(object); return; }
  278.   if (object == (APTR)pos35) { SetPos35(object); return; }
  279.   if (object == (APTR)pos36) { SetPos36(object); return; }
  280.   if (object == (APTR)pos37) { SetPos37(object); return; }
  281.   if (object == (APTR)pos38) { SetPos38(object); return; }
  282.   if (object == (APTR)Prev)  { PrevLabel(object); return; }
  283.   if (object == (APTR)Next)  { NextLabel(object); return; }
  284.   if (object == (APTR)Kill)  { KillLabel(object); return; }
  285. }
  286.  
  287. /**************************************************************************/
  288. HandleMenu(USHORT firstcode)
  289. {
  290.    struct MenuItem *item;
  291.    USHORT nextcode = firstcode;
  292.    while(nextcode != MENUNULL)
  293.    {
  294.       item = (struct MenuItem *)ItemAddress(Menu1, (long)nextcode);
  295.       HandleEvent((APTR)item);
  296.       nextcode = item->NextSelect;
  297.    }
  298.    return(0);
  299. }
  300. /**************************************************************************/
  301. OpenLibraries(void)
  302. {
  303.    if ((IntuitionBase=(struct IntuitionBase *)
  304.                OpenLibrary("intuition.library",INTUITION_REV)) == NULL)
  305.                Die("Unable to open Intuition library");
  306.  
  307.    if ((GfxBase=(struct GfxBase *)
  308.                OpenLibrary("graphics.library",GRAPHICS_REV)) == NULL)
  309.                Die("Unable to open Graphics library");
  310.  
  311.    if ((IconBase=(struct Library *)
  312.                OpenLibrary("icon.library",0)) == NULL)
  313.                Die("Unable to open Icon library");
  314.  
  315.    AslBase=(struct Library *)OpenLibrary("asl.library",ASL_REV);
  316.    /* We don't make any checks as AslBase isn't essential */
  317.  
  318.    return(0);
  319. }
  320.  
  321. /**************************************************************************/
  322. OpenDisplay(void)
  323. {
  324.    struct NewWindow *nw;
  325.    struct Screen    WBscrn;
  326.    
  327.    nw = BuildWindow(NULL,65,0,390,200,"PrLabel V1.1  SciTech Software 1992",
  328.                     0,1);
  329.    /* Modify the IDCMP flags of the basic NewWindow structure */
  330.    nw->IDCMPFlags = IDCMP_GADGETUP | IDCMP_MENUPICK | IDCMP_CLOSEWINDOW;
  331.  
  332.    /* Find the size of the menu bar from the WorkBench */
  333.    GetScreenData(&WBscrn,sizeof(struct Screen), WBENCHSCREEN, NULL);
  334.    mb  = WBscrn.WBorTop + WBscrn.Font->ta_YSize + 1;
  335.  
  336.    /* Create gadgets */
  337.    Line1 = BuildStringGadget(nw,Line1SIBuff,80,125,mb+5,  30,0,0,0,0);
  338.    Line2 = BuildStringGadget(nw,Line2SIBuff,80,125,mb+20, 30,0,0,0,0);
  339.    Line3 = BuildStringGadget(nw,Line3SIBuff,80,125,mb+35, 30,0,0,0,0);
  340.    Line4 = BuildStringGadget(nw,Line4SIBuff,80,125,mb+50, 30,0,0,0,0);
  341.    Line5 = BuildStringGadget(nw,Line5SIBuff,80,125,mb+65, 30,0,0,0,0);
  342.    Line6 = BuildStringGadget(nw,Line6SIBuff,80,125,mb+80, 30,0,0,0,0);
  343.    Line7 = BuildStringGadget(nw,Line7SIBuff,80,125,mb+95, 30,0,0,0,0);
  344.    
  345.    pos11 = BuildBoolGadget(nw," ",10,mb+5  ,1,1,0,0,0,1,0);
  346.    pos12 = BuildBoolGadget(nw," ",10,mb+19 ,1,1,0,0,0,1,0);
  347.    pos13 = BuildBoolGadget(nw," ",10,mb+33 ,1,1,0,0,0,1,0);
  348.    pos14 = BuildBoolGadget(nw," ",10,mb+47 ,1,1,0,0,0,1,0);
  349.    pos15 = BuildBoolGadget(nw," ",10,mb+61 ,1,1,0,0,0,1,0);
  350.    pos16 = BuildBoolGadget(nw," ",10,mb+75 ,1,1,0,0,0,1,0);
  351.    pos17 = BuildBoolGadget(nw," ",10,mb+89 ,1,1,0,0,0,1,0);
  352.    if(SheetType == TWO_EIGHT || SheetType == THREE_EIGHT)
  353.       pos18 = BuildBoolGadget(nw," ",10,mb+103,1,1,0,0,0,1,0);
  354.    
  355.    pos21 = BuildBoolGadget(nw," ",38,mb+5  ,1,1,0,0,0,1,0);
  356.    pos22 = BuildBoolGadget(nw," ",38,mb+19 ,1,1,0,0,0,1,0);
  357.    pos23 = BuildBoolGadget(nw," ",38,mb+33 ,1,1,0,0,0,1,0);
  358.    pos24 = BuildBoolGadget(nw," ",38,mb+47 ,1,1,0,0,0,1,0);
  359.    pos25 = BuildBoolGadget(nw," ",38,mb+61 ,1,1,0,0,0,1,0);
  360.    pos26 = BuildBoolGadget(nw," ",38,mb+75 ,1,1,0,0,0,1,0);
  361.    pos27 = BuildBoolGadget(nw," ",38,mb+89 ,1,1,0,0,0,1,0);
  362.    if(SheetType == TWO_EIGHT || SheetType == THREE_EIGHT)
  363.       pos28 = BuildBoolGadget(nw," ",38,mb+103,1,1,0,0,0,1,0);
  364.    
  365.    if(SheetType == THREE_EIGHT)
  366.    {
  367.       pos31 = BuildBoolGadget(nw," ",66,mb+5  ,1,1,0,0,0,1,0);
  368.       pos32 = BuildBoolGadget(nw," ",66,mb+19 ,1,1,0,0,0,1,0);
  369.       pos33 = BuildBoolGadget(nw," ",66,mb+33 ,1,1,0,0,0,1,0);
  370.       pos34 = BuildBoolGadget(nw," ",66,mb+47 ,1,1,0,0,0,1,0);
  371.       pos35 = BuildBoolGadget(nw," ",66,mb+61 ,1,1,0,0,0,1,0);
  372.       pos36 = BuildBoolGadget(nw," ",66,mb+75 ,1,1,0,0,0,1,0);
  373.       pos37 = BuildBoolGadget(nw," ",66,mb+89 ,1,1,0,0,0,1,0);
  374.       pos38 = BuildBoolGadget(nw," ",66,mb+103,1,1,0,0,0,1,0);
  375.    }
  376.    
  377.    Kill  = BuildBoolGadget(nw,"KILL",  230,mb+141,0,1,0,0,0,0,0);
  378.    Next  = BuildBoolGadget(nw,"NEXT",  255,mb+125,0,1,0,0,0,0,0);
  379.    Prev  = BuildBoolGadget(nw,"PREV",  202,mb+125,0,1,0,0,0,0,0);
  380.    Print = BuildBoolGadget(nw,"PRINT!",11, mb+133,8,3,0,0,0,0,0);
  381.    
  382.    BuildFrame(nw,195,mb+118,120,44,0,0,1);
  383.    
  384.    /* Build Menus */
  385.    Menu1     = BuildMenu(NULL,NULL,"Project");
  386. /* Not yet supported
  387. //   MenuItem1 = BuildMenuItem(NULL,0,(APTR)Menu1,"Open", 'O', 0,0,0,1);
  388. //   MenuItem2 = BuildMenuItem(NULL,0,(APTR)Menu1,"Save", 'S', 0,0,0,1);
  389. */
  390.    MenuItem3 = BuildMenuItem(NULL,0,(APTR)Menu1,"About",'\0',0,0,0,1);
  391.    MenuItem4 = BuildMenuItem(NULL,0,(APTR)Menu1,"Quit", 'Q', 0,0,0,1);
  392.  
  393.    Window = (struct Window *)OpenWindow(nw);
  394.  
  395.    SetMenuStrip(Window, Menu1);
  396.  
  397.    return(0);
  398. }
  399.  
  400. /**************************************************************************/
  401. Cleanup()
  402. {
  403.    QuitProgram((APTR)0);
  404.  
  405.    return(0);
  406. }
  407.  
  408. /**************************************************************************/
  409. QuitProgram(APTR object)
  410. {
  411.    if(Window) CloseWindow(Window);
  412.    exit(0);
  413.    
  414.    return(0);
  415. }
  416.  
  417. /**************************************************************************/
  418. ClearPrint(void)
  419. {
  420.    int j,
  421.        k;
  422.        
  423.    for(j=0;j<3;j++)
  424.       for(k=0;k<8;k++)
  425.          label[j][k].print = 0;
  426.          
  427.    return(0);
  428. }
  429.  
  430. /**************************************************************************/
  431. Usage(void)
  432. {
  433.    OpenIO();
  434.    
  435.    printf("\nUsage: PrLabel [-27][-28][-38]\n");
  436.    printf("PrLabel allows text to be printed for address labels, etc.\n");
  437.    printf("The flags are used to select the label layout and defaults to 3x8\n\n");
  438.  
  439.    exit(0);
  440.    return(0);
  441. }
  442.  
  443. /**************************************************************************/
  444. #include <ios1.h>
  445. #include <fcntl.h>
  446. extern struct UFB _ufbs[];
  447. extern int _fmode,_iomode;
  448.  
  449. OpenIO(void)
  450. {
  451.    register int x;
  452.  
  453.         _ufbs[0].ufbfh = Input();
  454.         _ufbs[1].ufbfh = Output();
  455.         _ufbs[2].ufbfh = Open("*", MODE_OLDFILE);
  456.         x = UFB_NC;                     /* do not close CLI defaults    */
  457.  
  458.    _ufbs[0].ufbflg |= UFB_RA | O_RAW | x;
  459.    _ufbs[1].ufbflg |= UFB_WA | O_RAW | x;
  460.    _ufbs[2].ufbflg |= UFB_RA | UFB_WA | O_RAW;
  461.  
  462.    x = (_fmode) ? 0 : _IOXLAT;
  463.    stdin->_file = 0;
  464.    stdin->_flag = _IOREAD | x;   
  465.    stdout->_file = 1;
  466.    stdout->_flag = _IOWRT | x;
  467.    stderr->_file = 2;
  468.    stderr->_flag = _IORW | x;
  469.  
  470.  
  471.    return(0);
  472. }
  473.