File:  [OS/2 SDKs] / os2sdk / demos / apps / sse / sse.c
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs
Thu Aug 9 12:26:06 2018 UTC (7 years, 9 months ago) by root
Branches: msft, MAIN
CVS tags: os2sdk-1988, HEAD
Microsoft OS/2 SDK 03-01-1988

/***	SSE - Simple Screen Editor
 *
 *  Created by Microsoft Corp. 1987
 */

#define  INCL_SUB
#define  INCL_DOSFILEMGR
#define  INCL_DOSSIGNALS

#include <os2def.h>
#include <bse.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include "ssedefs.h"


USHORT TotalLines;		      /* num of entries in line table */
struct Line far *LineTable[MAXLINES]; /* the line table */

USHORT	 TotalSegs;		      /* num of entries in seg table */
struct	SegEntry SegTable[MAXSEGS];

char	       fbuffer[FBUFFSIZE];
USHORT bytesread;

UCHAR ScrBuff[LONGPAGE][LINESIZE];
UCHAR EditBuff[LINESIZE];
USHORT EditBuffDirty;

USHORT PageSize;
USHORT Mode43Set = 0;

USHORT ForeNorm = 0x07;
USHORT BackNorm = 0x10;
USHORT ForeHilite = 0x01;
USHORT BackHilite = 0x70;
USHORT Fore25 = 0x07;
USHORT Back25 = 0x40;

USHORT CurRow, CurCol;
USHORT TopRow;

USHORT LinesMarked, CharsMarked;
USHORT MarkedLine[MAXLINES], MarkedChar[LINESIZE];

char	       *fname;
USHORT fhandle;

/***	main
 *
 *
 *
 */

main(argc, argv)
int   argc;
char *argv[];
{
    USHORT i;

    USHORT handtype, flagword;

    VIOMODEINFO    modedata;	      /* from bsesub.h */
    VIOCURSORINFO  cursordata;


/* check if we're in foreground */

    DosQHandType( 0, &handtype, &flagword );
    if( (handtype == 0) || ( !( flagword & 1 )) || ( !( flagword & 2 )) )
      quit(1);


/* disable signals so user can't exit with Ctrl-C or Ctrl-Break */

    DosHoldSignal( TRUE );


/* initialize variables */

    EditBuffDirty = 0;
    LinesMarked = 0;
    CharsMarked = 0;
    for (i = 0; i < MAXLINES; i++)
	MarkedLine[i] = 0;
    for (i = 0; i < LINESIZE; i++)
	MarkedChar[i] = 0;

/* Set PageSize to match the mode we're in, 25 or 43.
   This may be changed later by a switch from the command line. */

    modedata.cb = sizeof( modedata );
    VioGetMode( &modedata, 0 );
    if( modedata.row == 25 )
	PageSize = SHORTPAGE;
    else PageSize = LONGPAGE;

/*  Parse file name */
    if (argc < 2) {
      error25(8);
      quit(1);
      }
    else if (argc < 4) {
	   for( i = 1; i < (argc-1); i++ ) {
	       if( (argv[i][0] == '/') &&
		   ( argv[i][1] == '4' ) &&
		   ( argv[i][2] == '3' ) ) {
		   PageSize = LONGPAGE;
		   modedata.row = ( LONGPAGE + 1 );
		   VioSetMode( &modedata, 0 );
		   cursordata.yStart = 6;
		   cursordata.cEnd = 7;
		   cursordata.cx = 1;
		   cursordata.attr = 0;
		   VioSetCurType( &cursordata, 0 );
		   Mode43Set = 1;
		   }
	       else if( (argv[i][0] == '/') &&
			( (argv[i][1] == 'B') || (argv[i][1] == 'b') ) &&
			( (argv[i][2] == 'W') || (argv[i][2] == 'w') ) ) {
			   ForeNorm = 0x07;
			   BackNorm = 0;
			   ForeHilite = 0;
			   BackHilite = 0x70;
			   Fore25 = 0;
			   Back25 = 0x70;
			   }
	       else {
		    error25(9);
		    quit(1);
		    }

	   }
       fname = argv[i];
       }
    else {
       error25(10);
       quit(1);
       }

    /* paint the screen */
    clearscr();
    drawscr(0);

/*  read file */
    switch (openfile(fname, &fhandle, FOFLAG)) {
	case  0:
	    if (readfile(fhandle))
		error25(1);
	    if (backupfile(fname, fhandle))
		error25(2);
	    break;

	case  110:
/*	    create the file */
	    error25(3);
	    if (openfile(fname, &fhandle, CFFLAG))
		error25(4);   /* error creating file */
	    break;

	case  32:
/*	    denied write access */
	    error25(5);
	    break;

	default :
/*	    error on opening file */
	    error25(6);
	    break;
    }


/* if open worked, continue */

    drawscr(0);
    name25();
    VioSetCurPos(0,0,0);
    getline( 0, &EditBuff[0] );    /* initialize */
    dispatch();
    freesegs();
}




 quit(n)		      /* if we set 43 line mode from command line,  */
    USHORT n;	      /* set it back to 25 line mode before exiting */
    {
    VIOMODEINFO   modedata;
    VIOCURSORINFO cursordata;

    if( Mode43Set ) {
	modedata.cb = sizeof( modedata );
	VioGetMode( &modedata, 0 );
	modedata.row = 25;
	VioSetMode( &modedata, 0 );
	cursordata.yStart = 12;
	cursordata.cEnd = 13;
	cursordata.cx = 1;
	cursordata.attr = 0;
	VioSetCurType( &cursordata, 0 );
	BackNorm = 0;
	ForeNorm = 0;
	clearscr();
	}
    DosExit(EXIT_PROCESS,n);	    /* exit with specified completion code */
    }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.