Exemple #1
0
int ScanBarcodeSymbol( char* string, int min_length, int max_length, int *nCodeId)
{
	int key;
	struct barcode code = {0};

	(*nCodeId) = 0;
	resetkey();
	code.min = min_length;
	code.max = max_length;
	code.text = string;
	scannerpower( SINGLE, 300 );
#if PX25
	for(;;)
	{
		if ( !scanneroff () )
		{
			if ( readbarcode ( &code ) == OK)
				break;
		}
		else
		{
			if( kbhit() )
			{
				if(( key = getchar() ) != TRIGGER_KEY )
				{
				// put the character back in the input buffer
				// so it can be handled by another function
					ungetc( key, stdin);
					scannerpower( OFF, 0);
					return( ERROR );
				}
			}
		}
	}
#else
	while( readbarcode( &code ) != OK )
	{
		if( kbhit() )
		{
			if(( key = getchar() ) != TRIGGER_KEY )
			{
				// put the character back in the input buffer
				// so it can be handled by another function
				ungetc( key, stdin);
				scannerpower( OFF, 0);
				return( ERROR );
			}
			scannerpower( SINGLE, 300 );
		}
		idle();
	}
#endif
    // Copy the code ID
    (*nCodeId) = code.id;
	goodreadled( GREEN, 10 );
	scannerpower( OFF, 0);
	okbeep();

	return( OK );
}
Exemple #2
0
//
// Wait for one of the specific keys in the list
// If key is found in the list return the key
//
int WaitForKeys( int num, ... )
{
	va_list key_list;
	int key;

	if( num <= 0 )
		return( EOF ); // No keys in the list
	va_start( key_list, num );
	resetkey();
	for(;;)
	{
		key = WaitForKey(); // Wait for keyboard input
		if( check_key_input( key, num, key_list ) == OK )
		{
			va_end( key_list );	// reset the argument ptr
			return( key );
		}
	}
}
Exemple #3
0
/*
 * This function performs the details of file
 * writing. Uses the file management routines in the
 * "fileio.c" package. The number of lines written is
 * displayed. Sadly, it looks inside a struct line; provide
 * a macro for this. Most of the grief is error
 * checking of some sort.
 */
int writeout(char *fn)
{
	int s;
	struct line *lp;
	int nline;

#if	CRYPT
	s = resetkey();
	if (s != TRUE)
		return s;
#endif

	if ((s = ffwopen(fn)) != FIOSUC) {	/* Open writes message. */
		return FALSE;
	}
	mlwrite("(Writing...)");	/* tell us were writing */
	lp = lforw(curbp->b_linep);	/* First line.          */
	nline = 0;		/* Number of lines.     */
	while (lp != curbp->b_linep) {
		if ((s = ffputline(&lp->l_text[0], llength(lp))) != FIOSUC)
			break;
		++nline;
		lp = lforw(lp);
	}
	if (s == FIOSUC) {	/* No write error.      */
		s = ffclose();
		if (s == FIOSUC) {	/* No close error.      */
			if (nline == 1)
				mlwrite("(Wrote 1 line)");
			else
				mlwrite("(Wrote %d lines)", nline);
		}
	} else			/* Ignore close error   */
		ffclose();	/* if a write error.    */
	if (s != FIOSUC)	/* Some sort of error.  */
		return FALSE;
	return TRUE;
}
Exemple #4
0
/*
 * Read file "fname" into the current buffer, blowing away any text
 * found there.  Called by both the read and find commands.  Return
 * the final status of the read.  Also called by the mainline, to
 * read in a file specified on the command line as an argument.
 * The command bound to M-FNR is called after the buffer is set up
 * and before it is read.
 *
 * char fname[];	name of file to read
 * int lockfl;		check for file locks?
 */
int readin(char *fname, int lockfl)
{
	struct line *lp1;
	struct line *lp2;
	int i;
	struct window *wp;
	struct buffer *bp;
	int s;
	int nbytes;
	int nline;
	char mesg[NSTRING];

#if	(FILOCK && BSD) || SVR4
	if (lockfl && lockchk(fname) == ABORT)
#if PKCODE
	{
		s = FIOFNF;
		bp = curbp;
		strcpy(bp->b_fname, "");
		goto out;
	}
#else
		return ABORT;
#endif
#endif
#if	CRYPT
	s = resetkey();
	if (s != TRUE)
		return s;
#endif
	bp = curbp;		/* Cheap.               */
	if ((s = bclear(bp)) != TRUE)	/* Might be old.        */
		return s;
	bp->b_flag &= ~(BFINVS | BFCHG);
	strcpy(bp->b_fname, fname);

	/* let a user macro get hold of things...if he wants */
	execute(META | SPEC | 'R', FALSE, 1);

	if ((s = ffropen(fname)) == FIOERR)	/* Hard file open.      */
		goto out;

	if (s == FIOFNF) {	/* File not found.      */
		mlwrite("(New file)");
		goto out;
	}

	/* read the file in */
	mlwrite("(Reading file)");
	nline = 0;
	while ((s = ffgetline()) == FIOSUC) {
		nbytes = strlen(fline);
		if ((lp1 = lalloc(nbytes)) == NULL) {
			s = FIOMEM;	/* Keep message on the  */
			break;	/* display.             */
		}
#if	PKCODE
		if (nline > MAXNLINE) {
			s = FIOMEM;
			break;
		}
#endif
		lp2 = lback(curbp->b_linep);
		lp2->l_fp = lp1;
		lp1->l_fp = curbp->b_linep;
		lp1->l_bp = lp2;
		curbp->b_linep->l_bp = lp1;
		for (i = 0; i < nbytes; ++i)
			lputc(lp1, i, fline[i]);
		++nline;
	}
	ffclose();		/* Ignore errors.       */
	strcpy(mesg, "(");
	if (s == FIOERR) {
		strcat(mesg, "I/O ERROR, ");
		curbp->b_flag |= BFTRUNC;
	}
	if (s == FIOMEM) {
		strcat(mesg, "OUT OF MEMORY, ");
		curbp->b_flag |= BFTRUNC;
	}
	sprintf(&mesg[strlen(mesg)], "Read %d line", nline);
	if (nline != 1)
		strcat(mesg, "s");
	strcat(mesg, ")");
	mlwrite(mesg);

      out:
	for (wp = wheadp; wp != NULL; wp = wp->w_wndp) {
		if (wp->w_bufp == curbp) {
			wp->w_linep = lforw(curbp->b_linep);
			wp->w_dotp = lforw(curbp->b_linep);
			wp->w_doto = 0;
			wp->w_markp = NULL;
			wp->w_marko = 0;
			wp->w_flag |= WFMODE | WFHARD;
		}
	}
	if (s == FIOERR || s == FIOFNF)	/* False if error.      */
		return FALSE;
	return TRUE;
}
Exemple #5
0
/*
 * Insert file "fname" into the current
 * buffer, Called by insert file command. Return the final
 * status of the read.
 */
int ifile(char *fname)
{
	struct line *lp0;
	struct line *lp1;
	struct line *lp2;
	int i;
	struct buffer *bp;
	int s;
	int nbytes;
	int nline;
	char mesg[NSTRING];

	bp = curbp;		/* Cheap.               */
	bp->b_flag |= BFCHG;	/* we have changed      */
	bp->b_flag &= ~BFINVS;	/* and are not temporary */
	if ((s = ffropen(fname)) == FIOERR)	/* Hard file open.      */
		goto out;
	if (s == FIOFNF) {	/* File not found.      */
		mlwrite("(No such file)");
		return FALSE;
	}
	mlwrite("(Inserting file)");

#if	CRYPT
	s = resetkey();
	if (s != TRUE)
		return s;
#endif
	/* back up a line and save the mark here */
	curwp->w_dotp = lback(curwp->w_dotp);
	curwp->w_doto = 0;
	curwp->w_markp = curwp->w_dotp;
	curwp->w_marko = 0;

	nline = 0;
	while ((s = ffgetline()) == FIOSUC) {
		nbytes = strlen(fline);
		if ((lp1 = lalloc(nbytes)) == NULL) {
			s = FIOMEM;	/* Keep message on the  */
			break;	/* display.             */
		}
		lp0 = curwp->w_dotp;	/* line previous to insert */
		lp2 = lp0->l_fp;	/* line after insert */

		/* re-link new line between lp0 and lp2 */
		lp2->l_bp = lp1;
		lp0->l_fp = lp1;
		lp1->l_bp = lp0;
		lp1->l_fp = lp2;

		/* and advance and write out the current line */
		curwp->w_dotp = lp1;
		for (i = 0; i < nbytes; ++i)
			lputc(lp1, i, fline[i]);
		++nline;
	}
	ffclose();		/* Ignore errors.       */
	curwp->w_markp = lforw(curwp->w_markp);
	strcpy(mesg, "(");
	if (s == FIOERR) {
		strcat(mesg, "I/O ERROR, ");
		curbp->b_flag |= BFTRUNC;
	}
	if (s == FIOMEM) {
		strcat(mesg, "OUT OF MEMORY, ");
		curbp->b_flag |= BFTRUNC;
	}
	sprintf(&mesg[strlen(mesg)], "Inserted %d line", nline);
	if (nline > 1)
		strcat(mesg, "s");
	strcat(mesg, ")");
	mlwrite(mesg);

      out:
	/* advance to the next line and mark the window for changes */
	curwp->w_dotp = lforw(curwp->w_dotp);
	curwp->w_flag |= WFHARD | WFMODE;

	/* copy window parameters back to the buffer structure */
	curbp->b_dotp = curwp->w_dotp;
	curbp->b_doto = curwp->w_doto;
	curbp->b_markp = curwp->w_markp;
	curbp->b_marko = curwp->w_marko;

	if (s == FIOERR)	/* False if error.      */
		return FALSE;
	return TRUE;
}