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
/
PrL.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-01-31
|
20KB
|
800 lines
/***************************************************************************
Program: PrLabel
File: PrL.c
Version: V1.1
Date: 28.10.91
Function: Actual label printing and Interface handling routines
Copyright: SciTech Software 1991
Author: Andrew C. R. Martin
Address: SciTech Software
23, Stag Leys,
Ashtead,
Surrey,
KT21 2TD.
Phone: +44 (0372) 275775
EMail: UUCP: cbmuk!cbmuka!scitec!amartin
JANET: andrew@uk.ac.ox.biop
****************************************************************************
This program is Shareware with a suggested donation of £5.00.
It may be freely copied and distributed for no more than a nominal charge
(not more than £4.00 in the U.K.) providing this header is included.
The code may be modified as required, but any modifications must be
documented so that the person responsible can be identified. If someone
else breaks this code, I don't want to be blamed for code that does not
work! The code may not be sold commercially without prior permission from
the author, although it may be given away free with commercial products,
providing it is made clear that this program is free and that the source
code is provided with the program.
****************************************************************************
Description:
============
Actual label printing and interface handling routines for PrLabel.
N.B. The values for spacing in SetSheet27() and SetSheet28() have been
calculated, but never actually tested (I use 3x8 label sheets!).
Similarly Label27() and Label28().
If you find these values are wrong, please let me know...
****************************************************************************
Usage:
======
****************************************************************************
Revision History:
=================
V1.1 17.01.92
Changed interface to use STSLib.
***************************************************************************/
#include "PrLabel.h"
#include <sts/stslib.h>
/**************************************************************************/
/* Macros
*/
#define NEXT(x) (x)=(x)->next
#define ALLOCNEXT(x,y) { if(((x)->next=(y *)malloc(sizeof(y)))==NULL) \
Die("Out of Memory!"); \
NEXT(x); \
(x)->next=NULL; \
}
#define LAST(x) while((x)->next != NULL) NEXT(x)
#define TOGGLE(x) (x) = (!(x))
/**************************************************************************/
SetSheet38(APTR object)
{
int j;
for(j=0;j<8;j++)
{
label[0][j].x = 0;
label[1][j].x = 28;
label[2][j].x = 56;
}
for(j=0;j<3;j++)
{
label[j][0].y = 0;
label[j][1].y = 8;
label[j][2].y = 16;
label[j][3].y = 25;
label[j][4].y = 34;
label[j][5].y = 43;
label[j][6].y = 52;
label[j][7].y = 60;
}
SheetType = THREE_EIGHT;
return(0);
}
/**************************************************************************/
SetSheet28(APTR object)
{
int j;
for(j=0;j<8;j++)
{
label[0][j].x = 0;
label[1][j].x = 43;
label[2][j].x = LINELENGTH+10; /* Make sure this won't be printed */
}
for(j=0;j<3;j++)
{
label[j][0].y = 0;
label[j][1].y = 8;
label[j][2].y = 16;
label[j][3].y = 25;
label[j][4].y = 34;
label[j][5].y = 43;
label[j][6].y = 52;
label[j][7].y = 60;
}
SheetType = TWO_EIGHT;
return(0);
}
/**************************************************************************/
SetSheet27(APTR object)
{
int j;
for(j=0;j<8;j++)
{
label[0][j].x = 0;
label[1][j].x = 42;
label[2][j].x = LINELENGTH+10; /* Make sure this won't be printed */
}
for(j=0;j<3;j++)
{
label[j][0].y = 0;
label[j][1].y = 9;
label[j][2].y = 19;
label[j][3].y = 29;
label[j][4].y = 39;
label[j][5].y = 49;
label[j][6].y = 59;
label[j][7].y = PAGELENGTH+10; /* Make sure this won't be printed */
}
SheetType = TWO_SEVEN;
return(0);
}
/**************************************************************************/
SetPos11(APTR object)
{
TOGGLE(label[0][0].print);
return(0);
}
/**************************************************************************/
SetPos12(APTR object)
{
TOGGLE(label[0][1].print);
return(0);
}
/**************************************************************************/
SetPos13(APTR object)
{
TOGGLE(label[0][2].print);
return(0);
}
/**************************************************************************/
SetPos14(APTR object)
{
TOGGLE(label[0][3].print);
return(0);
}
/**************************************************************************/
SetPos15(APTR object)
{
TOGGLE(label[0][4].print);
return(0);
}
/**************************************************************************/
SetPos16(APTR object)
{
TOGGLE(label[0][5].print);
return(0);
}
/**************************************************************************/
SetPos17(APTR object)
{
TOGGLE(label[0][6].print);
return(0);
}
/**************************************************************************/
SetPos18(APTR object)
{
TOGGLE(label[0][7].print);
return(0);
}
/**************************************************************************/
SetPos21(APTR object)
{
TOGGLE(label[1][0].print);
return(0);
}
/**************************************************************************/
SetPos22(APTR object)
{
TOGGLE(label[1][1].print);
return(0);
}
/**************************************************************************/
SetPos23(APTR object)
{
TOGGLE(label[1][2].print);
return(0);
}
/**************************************************************************/
SetPos24(APTR object)
{
TOGGLE(label[1][3].print);
return(0);
}
/**************************************************************************/
SetPos25(APTR object)
{
TOGGLE(label[1][4].print);
return(0);
}
/**************************************************************************/
SetPos26(APTR object)
{
TOGGLE(label[1][5].print);
return(0);
}
/**************************************************************************/
SetPos27(APTR object)
{
TOGGLE(label[1][6].print);
return(0);
}
/**************************************************************************/
SetPos28(APTR object)
{
TOGGLE(label[1][7].print);
return(0);
}
/**************************************************************************/
SetPos31(APTR object)
{
TOGGLE(label[2][0].print);
return(0);
}
/**************************************************************************/
SetPos32(APTR object)
{
TOGGLE(label[2][1].print);
return(0);
}
/**************************************************************************/
SetPos33(APTR object)
{
TOGGLE(label[2][2].print);
return(0);
}
/**************************************************************************/
SetPos34(APTR object)
{
TOGGLE(label[2][3].print);
return(0);
}
/**************************************************************************/
SetPos35(APTR object)
{
TOGGLE(label[2][4].print);
return(0);
}
/**************************************************************************/
SetPos36(APTR object)
{
TOGGLE(label[2][5].print);
return(0);
}
/**************************************************************************/
SetPos37(APTR object)
{
TOGGLE(label[2][6].print);
return(0);
}
/**************************************************************************/
SetPos38(APTR object)
{
TOGGLE(label[2][7].print);
return(0);
}
/**************************************************************************/
PrintLabels(APTR object)
{
int labelcount,
j,
k;
/* This is only declared as static, to get it off the stack. Once the
stack resizing option is documented for Lattice C, this can be used
instead.
*/
static char PageBuffer[PAGELENGTH][LINELENGTH];
ADDR *p;
/* Move to current address label and copy buffers into linked list */
for(p=address,j=0; p!=NULL && j<CurLabel; NEXT(p), j++);
strcpy(p->line[0], Line1SIBuff);
strcpy(p->line[1], Line2SIBuff);
strcpy(p->line[2], Line3SIBuff);
strcpy(p->line[3], Line4SIBuff);
strcpy(p->line[4], Line5SIBuff);
strcpy(p->line[5], Line6SIBuff);
strcpy(p->line[6], Line7SIBuff);
/* Blank the buffer */
BlankBuffer(PageBuffer);
/* If there's only one label defined, we'll print it at each active
label position
*/
if(NLabel == 1)
{
for(j=0;j<3;j++)
for(k=0;k<8;k++)
if(label[j][k].print) PrintAt(PageBuffer,label[j][k].x,label[j][k].y,0);
}
else
{
labelcount = 0;
for(j=0;j<3;j++)
for(k=0;k<8;k++)
if(label[j][k].print)
{
if(labelcount < NLabel)
PrintAt(PageBuffer, label[j][k].x, label[j][k].y, labelcount++);
}
}
DumpBuffer(PageBuffer);
/* Reactivate line1 gadget */
GoLine1((APTR)1);
return(0);
}
/**************************************************************************/
PrevLabel(APTR object)
{
ADDR *p;
int j;
/* Move to current address label and copy buffers into linked list */
for(p=address,j=0; p!=NULL && j<CurLabel; NEXT(p), j++);
strcpy(p->line[0], Line1SIBuff);
strcpy(p->line[1], Line2SIBuff);
strcpy(p->line[2], Line3SIBuff);
strcpy(p->line[3], Line4SIBuff);
strcpy(p->line[4], Line5SIBuff);
strcpy(p->line[5], Line6SIBuff);
strcpy(p->line[6], Line7SIBuff);
CurLabel--;
if(CurLabel < 0) CurLabel = 0;
/* Put vales for this label in buffers */
for(p=address,j=0; p!=NULL && j<CurLabel; NEXT(p), j++);
strcpy(Line1SIBuff, p->line[0]);
strcpy(Line2SIBuff, p->line[1]);
strcpy(Line3SIBuff, p->line[2]);
strcpy(Line4SIBuff, p->line[3]);
strcpy(Line5SIBuff, p->line[4]);
strcpy(Line6SIBuff, p->line[5]);
strcpy(Line7SIBuff, p->line[6]);
RefreshGList(Line1,Window,NULL,7);
/* Reactivate line1 gadget */
GoLine1((APTR)1);
return(0);
}
/**************************************************************************/
NextLabel(APTR object)
{
ADDR *p;
int j;
/* Move to current address label and copy buffers into linked list */
for(p=address,j=0; p!=NULL && j<CurLabel; NEXT(p), j++);
strcpy(p->line[0], Line1SIBuff);
strcpy(p->line[1], Line2SIBuff);
strcpy(p->line[2], Line3SIBuff);
strcpy(p->line[3], Line4SIBuff);
strcpy(p->line[4], Line5SIBuff);
strcpy(p->line[5], Line6SIBuff);
strcpy(p->line[6], Line7SIBuff);
CurLabel++;
p = address;
/* Allocate space for next address if necessary */
while(NLabel <= CurLabel)
{
LAST(p);
ALLOCNEXT(p,ADDR);
if(!p)
{
ReqMessage(Window,"No memory for next label!",0);
}
else
{
NLabel++;
p->line[0][0] = '\0';
p->line[1][0] = '\0';
p->line[2][0] = '\0';
p->line[3][0] = '\0';
p->line[4][0] = '\0';
p->line[5][0] = '\0';
p->line[6][0] = '\0';
p->next = NULL;
}
}
/* Move to current address label and put values in buffers */
for(p=address,j=0; p!=NULL && j<CurLabel; NEXT(p), j++);
strcpy(Line1SIBuff,p->line[0]);
strcpy(Line2SIBuff,p->line[1]);
strcpy(Line3SIBuff,p->line[2]);
strcpy(Line4SIBuff,p->line[3]);
strcpy(Line5SIBuff,p->line[4]);
strcpy(Line6SIBuff,p->line[5]);
strcpy(Line7SIBuff,p->line[6]);
RefreshGList(Line1,Window,NULL,7);
/* Reactivate line1 gadget */
GoLine1((APTR)1);
return(0);
}
/**************************************************************************/
KillLabel(APTR object)
{
ADDR *p;
int j;
if(NLabel > 1)
{
/* Deal with special case */
if(CurLabel == 0)
{
p = address->next;
free(address);
address = p;
}
else
{
ADDR *q;
/* Move to previous address label in list */
for(p=address,j=0; p!=NULL && j<CurLabel-1; NEXT(p), j++);
/* Save the next pointer from the address label we're going to kill */
q = p->next->next;
/* Kill the address label */
free(p->next);
/* Update the pointer */
p->next = q;
/* Move on if there's another address label */
if(q)
p = q;
else
CurLabel--;
}
/* Decrement number of address labels */
NLabel--;
/* Refresh buffers */
for(p=address,j=0; p!=NULL && j<CurLabel; NEXT(p), j++);
strcpy(Line1SIBuff, p->line[0]);
strcpy(Line2SIBuff, p->line[1]);
strcpy(Line3SIBuff, p->line[2]);
strcpy(Line4SIBuff, p->line[3]);
strcpy(Line5SIBuff, p->line[4]);
strcpy(Line6SIBuff, p->line[5]);
strcpy(Line7SIBuff, p->line[6]);
RefreshGList(Line1,Window,NULL,7);
}
/* Reactivate line1 gadget */
GoLine1((APTR)1);
return(0);
}
/**************************************************************************/
PrintAt(char PageBuffer[PAGELENGTH][LINELENGTH],
int xpos,
int ypos,
int labelnum)
{
int j,
k;
ADDR *p;
/* Set p to point to the address item in which we're interested */
for(p=address,j=0; p!=NULL && j<labelnum; NEXT(p), j++);
/* For each line of an address */
for(j=0;j<NLABLIN; j++)
{
/* Break out if we're off the page */
if(ypos+j >= PAGELENGTH) continue;
/* For each character in the line */
for(k=0;k<strlen(p->line[j]);k++)
{
/* Break out if we're off the page */
if(xpos+k >= LINELENGTH) break;
/* Copy the characters into the page buffer */
PageBuffer[ypos+j][xpos+k] = p->line[j][k];
}
}
return(0);
}
/**************************************************************************/
DumpBuffer(char PageBuffer[PAGELENGTH][LINELENGTH])
{
int j;
struct FileHandle *fh;
if(fh=(struct FileHandle *)Open("PRT:",MODE_OLDFILE))
{
/* For each line */
for(j=0; j<PAGELENGTH; j++)
{
/* Ensure line is correctly terminated */
PageBuffer[j][LINELENGTH-1] = '\0';
/* Dump to the printer */
Write(fh,PageBuffer[j],strlen(PageBuffer[j]));
Write(fh,"\n",1);
}
Close(fh);
}
return(0);
}
/**************************************************************************/
BlankBuffer(char PageBuffer[PAGELENGTH][LINELENGTH])
{
int j,
k;
for(j=0;j<PAGELENGTH;j++)
{
for(k=0;k<LINELENGTH;k++)
PageBuffer[j][k] = ' ';
PageBuffer[j][LINELENGTH-1] = '\0';
}
return(0);
}
/**************************************************************************/
GoLine1(APTR object)
{
ActivateGadget(Line1,Window,NULL);
return(0);
}
/**************************************************************************/
GoLine2(APTR object)
{
ActivateGadget(Line2,Window,NULL);
return(0);
}
/**************************************************************************/
GoLine3(APTR object)
{
ActivateGadget(Line3,Window,NULL);
return(0);
}
/**************************************************************************/
GoLine4(APTR object)
{
ActivateGadget(Line4,Window,NULL);
return(0);
}
/**************************************************************************/
GoLine5(APTR object)
{
ActivateGadget(Line5,Window,NULL);
return(0);
}
/**************************************************************************/
GoLine6(APTR object)
{
ActivateGadget(Line6,Window,NULL);
return(0);
}
/**************************************************************************/
GoLine7(APTR object)
{
ActivateGadget(Line7,Window,NULL);
return(0);
}
/**************************************************************************/
Label38(void)
{
struct IntuiText *itext;
/* Label the Y-axis */
itext = MakeText(NULL,"6",1,97,mb+14,0);
MakeText(itext,"7",1,97,mb+28,0);
MakeText(itext,"7",1,97,mb+42,0);
MakeText(itext,"7",1,97,mb+56,0);
MakeText(itext,"7",1,97,mb+70,0);
MakeText(itext,"7",1,97,mb+84,0);
MakeText(itext,"7",1,97,mb+98,0);
MakeText(itext,"3",1,97,mb+112,0);
/* Label the X-axis */
MakeText(itext,"26",1,15,mb+125,0);
MakeText(itext,"26",1,43,mb+125,0);
MakeText(itext,"20",1,71,mb+125,0);
PrintIText(Window->RPort,itext,0,-8);
FreeIText(itext);
return(0);
}
/**************************************************************************/
Label28(void)
{
struct IntuiText *itext;
/* Label the Y-axis */
itext = MakeText(NULL,"6",1,72,mb+14,0);
MakeText(itext,"7",1,72,mb+28,0);
MakeText(itext,"7",1,72,mb+42,0);
MakeText(itext,"7",1,72,mb+56,0);
MakeText(itext,"7",1,72,mb+70,0);
MakeText(itext,"7",1,72,mb+84,0);
MakeText(itext,"7",1,72,mb+98,0);
MakeText(itext,"3",1,72,mb+112,0);
/* Label the X-axis */
MakeText(itext,"39",1,15,mb+125,0);
MakeText(itext,"34",1,43,mb+125,0);
PrintIText(Window->RPort,itext,0,-8);
FreeIText(itext);
return(0);
}
/**************************************************************************/
Label27(void)
{
struct IntuiText *itext;
/* Label the Y-axis */
itext = MakeText(NULL,"7",1,72,mb+14,0);
MakeText(itext,"7",1,72,mb+28,0);
MakeText(itext,"7",1,72,mb+42,0);
MakeText(itext,"7",1,72,mb+56,0);
MakeText(itext,"7",1,72,mb+70,0);
MakeText(itext,"7",1,72,mb+84,0);
MakeText(itext,"4",1,72,mb+98,0);
/* Label the X-axis */
MakeText(itext,"39",1,15,mb+111,0);
MakeText(itext,"34",1,43,mb+111,0);
PrintIText(Window->RPort,itext,0,-8);
FreeIText(itext);
return(0);
}
/**************************************************************************/
/* Displays an About message
*/
About(APTR object)
{
struct IntuiText *itext1,
*itext2,
*itext3,
*oktext;
oktext = MakeText(NULL,"OK",1,0,0,0);
itext1 = MakeText(NULL,"PrLabel", 1,72, 0,0);
MakeText(itext1,"Label Printing Utility", 1,12,10,0);
MakeText(itext1,"SciTech Software ©1992", 1,12,20,0);
MakeText(itext1," ", 1, 0,30,0);
MakeText(itext1,"This program is shareware",1, 0,40,0);
MakeText(itext1,"and uses the STSLib", 1, 0,50,0);
MakeText(itext1,"gadget and menu library", 1, 0,60,0);
itext2 = MakeText(NULL,"PrLabel", 1,72, 0,0);
MakeText(itext2,"Suggested fee £5.00", 1,24,10,0);
MakeText(itext2," ", 1, 0,20,0);
MakeText(itext2,"STSLib provides 3D-look", 1, 0,30,0);
MakeText(itext2,"gadgets and menu support", 1, 0,40,0);
MakeText(itext2,"under V1.3 and V2.0", 1, 0,50,0);
MakeText(itext2," ", 1, 0,60,0);
MakeText(itext2,"STSLib is £20.00 from:", 1, 0,70,0);
itext3 = MakeText(NULL,"SciTech Software", 1, 0, 0,0);
MakeText(itext3,"23, Stag Leys,", 1, 0,10,0);
MakeText(itext3,"Ashtead,", 1, 0,20,0);
MakeText(itext3,"Surrey", 1, 0,30,0);
MakeText(itext3,"KT21 2TD.", 1, 0,40,0);
MakeText(itext3," ", 1, 0,50,0);
MakeText(itext3,"Tel.: +44(0372)275775", 1, 0,60,0);
STSAutoRequest(NULL,itext1,oktext,oktext,NULL,NULL,0,0);
STSAutoRequest(NULL,itext2,oktext,oktext,NULL,NULL,0,0);
STSAutoRequest(NULL,itext3,oktext,oktext,NULL,NULL,0,0);
FreeIText(itext1);
FreeIText(itext2);
FreeIText(itext3);
return(0);
}
/**************************************************************************/
/* Reads in an address list
*/
ReadList(APTR object)
{
return(0);
}
/**************************************************************************/
/* Writes out an address list
*/
SaveList(APTR object)
{
return(0);
}