|
|
1.1 ! root 1: /*** SSE - Simple Screen Editor ! 2: * ! 3: * ! 4: * ! 5: * ! 6: * ! 7: * ! 8: * ! 9: * ! 10: */ ! 11: ! 12: ! 13: ! 14: #include <ctype.h> ! 15: #include <doscalls.h> ! 16: #include <dos.h> ! 17: #include <stdlib.h> ! 18: #include <stdio.h> ! 19: #include <subcalls.h> ! 20: #include "ssedefs.h" ! 21: ! 22: ! 23: unsigned short TotalLines; /* num of entries in line table */ ! 24: struct Line far *LineTable[MAXLINES]; /* the line table */ ! 25: ! 26: unsigned short TotalSegs; /* num of entries in seg table */ ! 27: struct SegEntry SegTable[MAXSEGS]; ! 28: ! 29: char fbuffer[FBUFFSIZE]; ! 30: unsigned short bytesread; ! 31: ! 32: unsigned char ScrBuff[LONGPAGE][LINESIZE]; ! 33: unsigned char EditBuff[LINESIZE]; ! 34: unsigned short EditBuffDirty; ! 35: ! 36: unsigned short PageSize; ! 37: unsigned short Mode43Set = 0; ! 38: ! 39: unsigned short ForeNorm = 0x07; ! 40: unsigned short BackNorm = 0x10; ! 41: unsigned short ForeHilite = 0x01; ! 42: unsigned short BackHilite = 0x70; ! 43: unsigned short Fore25 = 0x07; ! 44: unsigned short Back25 = 0x40; ! 45: ! 46: unsigned short CurRow, CurCol; ! 47: unsigned short TopRow; ! 48: ! 49: unsigned short LinesMarked, CharsMarked; ! 50: unsigned short MarkedLine[MAXLINES], MarkedChar[LINESIZE]; ! 51: ! 52: char *fname; ! 53: unsigned short fhandle; ! 54: ! 55: /*** main ! 56: * ! 57: * ! 58: * ! 59: */ ! 60: ! 61: main(argc, argv) ! 62: int argc; ! 63: char *argv[]; ! 64: { ! 65: unsigned short i; ! 66: ! 67: unsigned short handtype, flagword; ! 68: ! 69: struct ModeData modedata; /* from subcalls.h */ ! 70: struct CursorData cursordata; ! 71: ! 72: ! 73: /* check if we're in foreground */ ! 74: ! 75: DOSQHANDTYPE( 0, (unsigned far *)&handtype, (unsigned far *)&flagword ); ! 76: if( (handtype == 0) || ( !( flagword & 1 )) || ( !( flagword & 2 )) ) ! 77: quit(1); ! 78: ! 79: ! 80: /* disable signals so user can't exit with Ctrl-C or Ctrl-Break */ ! 81: ! 82: DOSHOLDSIGNAL( TRUE ); ! 83: ! 84: ! 85: /* initialize variables */ ! 86: ! 87: EditBuffDirty = 0; ! 88: LinesMarked = 0; ! 89: CharsMarked = 0; ! 90: for (i = 0; i < MAXLINES; i++) ! 91: MarkedLine[i] = 0; ! 92: for (i = 0; i < LINESIZE; i++) ! 93: MarkedChar[i] = 0; ! 94: ! 95: /* Set PageSize to match the mode we're in, 25 or 43. ! 96: This may be changed later by a switch from the command line. */ ! 97: ! 98: modedata.length = sizeof( modedata ); ! 99: VIOGETMODE( &modedata, 0 ); ! 100: if( modedata.row == 25 ) ! 101: PageSize = SHORTPAGE; ! 102: else PageSize = LONGPAGE; ! 103: ! 104: /* Parse file name */ ! 105: if (argc < 2) { ! 106: error25(8); ! 107: quit(1); ! 108: } ! 109: else if (argc < 4) { ! 110: for( i = 1; i < (argc-1); i++ ) { ! 111: if( (argv[i][0] == '/') && ! 112: ( argv[i][1] == '4' ) && ! 113: ( argv[i][2] == '3' ) ) { ! 114: PageSize = LONGPAGE; ! 115: modedata.row = ( LONGPAGE + 1 ); ! 116: VIOSETMODE( &modedata, 0 ); ! 117: cursordata.cur_start = 6; ! 118: cursordata.cur_end = 7; ! 119: cursordata.cur_width = 1; ! 120: cursordata.cur_attribute = 0; ! 121: VIOSETCURTYPE( &cursordata, 0 ); ! 122: Mode43Set = 1; ! 123: } ! 124: else if( (argv[i][0] == '/') && ! 125: ( (argv[i][1] == 'B') || (argv[i][1] == 'b') ) && ! 126: ( (argv[i][2] == 'W') || (argv[i][2] == 'w') ) ) { ! 127: ForeNorm = 0x07; ! 128: BackNorm = 0; ! 129: ForeHilite = 0; ! 130: BackHilite = 0x70; ! 131: Fore25 = 0; ! 132: Back25 = 0x70; ! 133: } ! 134: else { ! 135: error25(9); ! 136: quit(1); ! 137: } ! 138: ! 139: } ! 140: fname = argv[i]; ! 141: } ! 142: else { ! 143: error25(10); ! 144: quit(1); ! 145: } ! 146: ! 147: /* paint the screen */ ! 148: clearscr(); ! 149: drawscr(0); ! 150: ! 151: /* read file */ ! 152: switch (openfile(fname, &fhandle, FOFLAG)) { ! 153: case 0: ! 154: if (readfile(fhandle)) ! 155: error25(1); ! 156: if (backupfile(fname, fhandle)) ! 157: error25(2); ! 158: break; ! 159: ! 160: case 110: ! 161: /* create the file */ ! 162: error25(3); ! 163: if (openfile(fname, &fhandle, CFFLAG)) ! 164: error25(4); /* error creating file */ ! 165: break; ! 166: ! 167: case 32: ! 168: /* denied write access */ ! 169: error25(5); ! 170: break; ! 171: ! 172: default : ! 173: /* error on opening file */ ! 174: error25(6); ! 175: break; ! 176: } ! 177: ! 178: ! 179: /* if open worked, continue */ ! 180: ! 181: drawscr(0); ! 182: name25(); ! 183: VIOSETCURPOS(0,0,0); ! 184: getline( 0, &EditBuff[0] ); /* initialize */ ! 185: dispatch(); ! 186: freesegs(); ! 187: } ! 188: ! 189: ! 190: ! 191: ! 192: quit(n) /* if we set 43 line mode from command line, */ ! 193: unsigned short n; /* set it back to 25 line mode before exiting */ ! 194: { ! 195: struct ModeData modedata; ! 196: struct CursorData cursordata; ! 197: ! 198: if( Mode43Set ) { ! 199: modedata.length = sizeof( modedata ); ! 200: VIOGETMODE( &modedata, 0 ); ! 201: modedata.row = 25; ! 202: VIOSETMODE( &modedata, 0 ); ! 203: cursordata.cur_start = 12; ! 204: cursordata.cur_end = 13; ! 205: cursordata.cur_width = 1; ! 206: cursordata.cur_attribute = 0; ! 207: VIOSETCURTYPE( &cursordata, 0 ); ! 208: BackNorm = 0; ! 209: ForeNorm = 0; ! 210: clearscr(); ! 211: } ! 212: DOSEXIT(1,n); /* exit with specified completion code */ ! 213: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.