|
|
1.1.1.2 ! root 1: /* Created by Microsoft Corp. 1987 */ ! 2: ! 3: #define INCL_SUB ! 4: ! 5: #include <os2def.h> ! 6: #include <bsesub.h> 1.1 root 7: #include <ctype.h> 8: #include "ssedefs.h" 9: 10: 11: 12: 1.1.1.2 ! root 13: /*** creturn - handles carriage return 1.1 root 14: * 15: * creturn breaks the line reference by linenum at the 16: * current cursor position and inserts the second half of 17: * the 'line' one line below. 18: * 19: * creturn() 20: * 21: * ENTRY - none 22: * 23: * creturn will EXIT the program by calling error25 if 24: * it is unable to add a line to the file or the number 25: * of lines in the file becomes greater than MAXLINES. 26: * 27: * EFFECTS TotalLines - by incrementing it once or twice 28: * EditBuffDirty - by clearing it if set 29: * LinesMarked - by clearing it if set 30: * CharsMarked - by clearing it if set 31: * MarkedChar - by clearing it if set 32: * MarkedLine - by clearing it if set 1.1.1.2 ! root 33: * LineTable - by inserting the second part of the line ! 34: * via 'addline' 1.1 root 35: * CurRow - by incrementing it 36: * TopRow - by incrementing it 37: * CurCol - by setting it to zero 38: * EditBuff - by getting the second part of the line 39: * via 'getline' 40: * SegTable - by using free space for the both parts 41: * of the line via 'allocseg' 42: * by marking the segment containing the original 43: * line as needing compacting via 'deleteline' 44: * by marking the original line in the segment 45: * as being deleted. via 'deleteline' 46: * TotalSegs - via 'alloseg' 47: * memory - by allocating segments via 'allocseg' 48: * the screen - via 'drawscr' 49: */ 50: 51: 52: void creturn() 53: { 1.1.1.2 ! root 54: register USHORT i; ! 55: register USHORT linenum; 1.1 root 56: 57: /* clear flags if set */ 58: if (EditBuffDirty) { /* this call will change */ 59: EditBuffDirty = 0; /* cursor line, so flush */ 60: flushline((TopRow + CurRow), EditBuff); /* edit buffer if dirty */ 61: } 62: /* clear flags if set */ 63: if ( LinesMarked || CharsMarked ) { 64: LinesMarked = 0; /* if there's marked text */ 65: CharsMarked = 0; /* around, clear it and */ 66: for ( i = 0; i < MAXLINES; i++ ) /* redraw the screen */ 67: MarkedLine[i] = 0; 68: for ( i = 0; i < LINESIZE; i++ ) 69: MarkedChar[i] = 0; 70: } 71: 72: /* expand LineTable for second part of line */ 73: linenum = TopRow + CurRow; 74: if ( !(linenum == TotalLines)) { 75: deleteline(linenum); /* mark orginal line as deleted */ 1.1.1.2 ! root 76: for (i = 0; i < TotalLines - (linenum +1); i++) ! 77: LineTable[TotalLines-i] = LineTable[TotalLines-i-1]; 1.1 root 78: ++TotalLines; 79: } 80: else { 81: ++TotalLines; 82: ++TotalLines; 83: } 84: 85: /* find first non blank in first part of line to set new line length to it */ 86: for (i = (CurCol -1); !isgraph(EditBuff[i]) && inline(i, 0); i--); 87: if ( (addline(linenum, (i +1), EditBuff) != 0) || !(TotalLines < MAXLINES)) 88: error25(7); 89: /* call error mesage to save or quit */ 90: 91: ++linenum; 92: /* find first non blank in second part of line to set new line length to it */ 93: for (i = (LINESIZE -1); !(isgraph(EditBuff[i])) && inline(i, CurCol); i--); 94: if (addline(linenum, (i - CurCol +1), &EditBuff[CurCol]) != 0) 95: error25(7); 96: /* call error message to save or quit */ 97: 98: /* move cursor to begining of the second part of the line */ 99: if (CurRow < (PageSize - 1)) 100: ++CurRow; 101: else 102: ++TopRow; 103: CurCol = 0; 1.1.1.2 ! root 104: VioSetCurPos(CurRow, CurCol, 0); 1.1 root 105: drawscr(TopRow); 106: 107: getline(linenum, EditBuff); /* set EditBuff to the current line */ 108: 109: line25(); 110: } 111: 112: 113: 114: 115: /*** ctrl_b - insert line below 116: * 117: * ctrl_b inserts a blank line below the current line 118: * and moves the cursor to the inserted line. 119: * 120: * ctrl_b () 121: * 122: * ctrl_b expands LineTable to insert the new line below 123: * the current line and then inserts the new line via 124: * 'addline' with a length of zero. Also ctrl_b places 125: * the cursor on the insert line in the same column as 126: * the current line. 127: * ctrl_b will EXIT the program by calling error25 if 128: * it is unable to add a line to the file or the number 129: * of lines in the file becomes greater than MAXLINES. 130: * 131: * EFFECTS TotalLines - by incrementing it once or twice 132: * EditBuffDirty - by clearing it if set 133: * LinesMarked - by clearing it if set 134: * CharsMarked - by clearing it if set 135: * MarkedChar - by clearing it if set 136: * MarkedLine - by clearing it if set 137: * LineTable - by insterting the new line and via 'addline' 138: * CurRow - by incrementing it 139: * TopRow - by incrementing it 140: * EditBuff - by setting it to a line of blanks via 'getline' 141: * SegTable - by using free space for the new line 142: * via 'allocseg' 143: * by marking the current line in the segment 144: * as being deleted if it was changed. via 145: * 'fushline' via 'deleteline' 146: * TotalSegs - via 'alloseg' 147: * memory - by allocating segments via 'allocseg' 148: * the screen - via 'drawscr' 149: */ 150: 151: 152: void ctrl_b() 153: { 1.1.1.2 ! root 154: register USHORT i; 1.1 root 155: 156: if (EditBuffDirty) { /* this call will change */ 157: EditBuffDirty = 0; /* cursor line, so flush */ 158: flushline((TopRow + CurRow), EditBuff); /* edit buffer if dirty */ 159: } 160: 161: if ( LinesMarked || CharsMarked ) { 162: LinesMarked = 0; /* if there's marked text */ 163: CharsMarked = 0; /* around, clear it and */ 164: for ( i = 0; i < MAXLINES; i++ ) /* redraw the screen */ 165: MarkedLine[i] = 0; 166: for ( i = 0; i < LINESIZE; i++ ) 167: MarkedChar[i] = 0; 168: } 169: 170: /* expand LineTable to insert the new line below */ 1.1.1.2 ! root 171: for (i = 0; i < TotalLines - (TopRow + CurRow +1); i++) ! 172: LineTable[TotalLines-i] = LineTable[TotalLines-i-1]; 1.1 root 173: if ( (TopRow + CurRow) == TotalLines) { 174: ++TotalLines; 175: if ((addline(TopRow +CurRow, 0, 0) != 0) || !(TotalLines < MAXLINES)) 176: error25(7); 177: /* call error message to save or quit */ 178: 179: } 180: ++TotalLines; 181: if ((addline(TopRow + CurRow +1, 0, 0) != 0) || !(TotalLines < MAXLINES)) 182: error25(7); 183: /* call error message to save or quit */ 184: 185: /* place the cursor on the new line below */ 186: if (CurRow < (PageSize - 1)) 187: ++CurRow; 188: else 189: ++TopRow; 190: 191: /* redraw the screen with the new line below */ 1.1.1.2 ! root 192: VioSetCurPos(CurRow, CurCol, 0); 1.1 root 193: drawscr(TopRow); 194: 195: getline( (TopRow + CurRow), &EditBuff[0] ); 196: 197: line25(); 198: 199: } 200: 201: 202: 203: 204: /*** ctrl_n - insert line above 205: * 206: * ctrl_n inserts a blank line above the current line 207: * and move the cursor to the inserted line. 208: * 209: * ctrl_n () 210: * 211: * ctrl_n expands LineTable to insert the new line above 212: * the current line and then inserts the new line via 213: * 'addline' with a length of zero. Also ctrl_n places 214: * the cursor on the inserted line in the same column as 215: * the current line. 216: * ctrl_n will EXIT the program by calling error25 if 217: * it is unable to add a line to the file or the number 218: * of lines in the file becomes greater than MAXLINES. 219: * 220: * EFFECTS TotalLines - by incrementing it once or twice 221: * EditBuffDirty - by clearing it if set 222: * LinesMarked - by clearing it if set 223: * CharsMarked - by clearing it if set 224: * MarkedChar - by clearing it if set 225: * MarkedLine - by clearing it if set 226: * LineTable - by insterting the new line and via 'addline' 227: * CurRow - by decrementing it 228: * TopRow - by incrementing it 229: * EditBuff - by setting it to a line of blanks via 'getline' 230: * SegTable - by using free space for the new line 231: * via 'allocseg' 232: * by marking the current line in the segment 233: * as being deleted if it was changed. via 234: * 'fushline' via 'deleteline' 235: * TotalSegs - via 'alloseg' 236: * memory - by allocating segments via 'allocseg' 237: * the screen - via 'drawscr' 238: */ 239: 240: 241: void ctrl_n() 242: { 1.1.1.2 ! root 243: register USHORT i; 1.1 root 244: 245: if (EditBuffDirty) { /* this call will change */ 246: EditBuffDirty = 0; /* cursor line, so flush */ 247: flushline((TopRow + CurRow), EditBuff); /* edit buffer if dirty */ 248: } 249: 250: if ( LinesMarked || CharsMarked ) { 251: LinesMarked = 0; /* if there's marked text */ 252: CharsMarked = 0; /* around, clear it and */ 253: for ( i = 0; i < MAXLINES; i++ ) /* redraw the screen */ 254: MarkedLine[i] = 0; 255: for ( i = 0; i < LINESIZE; i++ ) 256: MarkedChar[i] = 0; 257: } 258: 259: /* expand LineTable to insert the new line above */ 1.1.1.2 ! root 260: for (i = 0; i < TotalLines - (TopRow + CurRow); i++) ! 261: LineTable[TotalLines-i] = LineTable[TotalLines-i-1]; 1.1 root 262: /* insert the new line above current line */ 263: if ( (TopRow + CurRow) == TotalLines) { 264: ++TotalLines; 265: if ((addline(TopRow + CurRow + 1, 0, 0) != 0) || !(TotalLines < MAXLINES)) 266: error25(7); 267: /* call error message to save or quit */ 268: } 269: ++TotalLines; 270: if ((addline(TopRow + CurRow, 0, 0) != 0) || !(TotalLines < MAXLINES)) 271: error25(7); 272: /* call error message to save or quit */ 273: 274: /* redraw the screen with the cursor on the insert line above */ 275: if (CurRow > 0) { 276: --CurRow; 277: ++TopRow; 1.1.1.2 ! root 278: VioSetCurPos(CurRow, CurCol, 0); 1.1 root 279: } 280: drawscr(TopRow); 281: getline( (TopRow + CurRow), &EditBuff[0] ); 282: line25(); 283: } 284: 285: 286: 287: 288: /*** ctrl_y - delete current line 289: * 290: * ctrl_y deletes the current line. 291: * 292: * ctrl_y () 293: * 294: * ctrl_y marks the current line as deleted and 295: * compacts the LineTable. 296: * 297: * 298: * EFFECTS TotalLines - by decrementing it 299: * EditBuffDirty - by clearing it if set 300: * LinesMarked - by clearing it if set 301: * CharsMarked - by clearing it if set 302: * MarkedChar - by clearing it if set 303: * MarkedLine - by clearing it if set 304: * LineTable - by marking the current as deleted via 305: * 'deleteline' 306: * EditBuff - by replacing it with the line below the 307: * the current line via 'getline' 308: * SegTable - by marking the current line in the segment 309: * as being deleted via 'deleteline' 310: * by marking the segment containing the 311: * line as needing compacting via 'deleteline' 312: * the screen - via 'drawscr' 313: */ 314: 315: 316: void ctrl_y() 317: { 1.1.1.2 ! root 318: register USHORT i; 1.1 root 319: 320: if (EditBuffDirty) { /* this call will change */ 321: EditBuffDirty = 0; /* cursor line, so flush */ 322: flushline((TopRow + CurRow), EditBuff); /* edit buffer if dirty */ 323: } 324: 325: if ( LinesMarked || CharsMarked ) { 326: LinesMarked = 0; /* if there's marked text */ 327: CharsMarked = 0; /* around, clear it and */ 328: for ( i = 0; i < MAXLINES; i++ ) /* redraw the screen */ 329: MarkedLine[i] = 0; 330: for ( i = 0; i < LINESIZE; i++ ) 331: MarkedChar[i] = 0; 332: } 333: 334: /* compact LineTable */ 335: if( !((TopRow + CurRow) == TotalLines)) { 336: deleteline(TopRow + CurRow); 337: for(i = (TopRow + CurRow); i < TotalLines; i++) 338: LineTable[i] = LineTable[i + 1]; 339: --TotalLines; 340: } 341: 342: /* redraw the screen */ 343: drawscr(TopRow); 344: getline( (TopRow + CurRow), &EditBuff[0] ); 345: line25(); 346: } 347: 348: 349: 350: 351: /*** tab - moves cursor to next tab 352: * 353: * tab insert spaces up to the next tab if it will 354: * not cause the line to grow greater than line size. 355: * 356: * tab() 357: * 358: * ENTRY - none 359: * 360: * EXIT - none 361: * 362: * EFFECTS LinesMarked - by clearing it if set 363: * CharsMarked - by clearing it if set 364: * MarkedChar - by clearing it if set 365: * MarkedLine - by clearing it if set 366: * EditBuffDirty - by setting if the tab is inserted 367: * EditBuff - by inserting the tab 368: * CurCol - by incrementing it by 369: */ 370: 371: 372: void tab() 373: { 1.1.1.2 ! root 374: USHORT ensp = FALSE; /* enough space to add the tab */ ! 375: USHORT tabshift; /* number of spaces to the next tab */ ! 376: USHORT i, j; /* indexes */ 1.1 root 377: 378: 379: if ( LinesMarked || CharsMarked ) { 380: LinesMarked = 0; /* if there's marked text */ 381: CharsMarked = 0; /* around, clear it and */ 382: for ( i = 0; i < MAXLINES; i++ ) /* redraw the screen */ 383: MarkedLine[i] = 0; 384: for ( i = 0; i < LINESIZE; i++ ) 385: MarkedChar[i] = 0; 386: } 387: 388: tabshift = (TABSIZE - (CurCol % TABSIZE)); /* number of spaces to next tab */ 389: 390: /* is there enough space to insert the tab */ 391: if ((CurCol + tabshift) < LINESIZE) { 392: for (i = (LINESIZE - tabshift); 393: (i < LINESIZE) && (ensp = !isgraph(EditBuff[i])); i++); 394: 395: if (ensp) { 396: /* enough space was found for the tab - now insert it */ 397: for (i = (LINESIZE - tabshift -1), j = (LINESIZE - 1); 398: inline(i, CurCol); i--, j--) { 399: EditBuff[j] = EditBuff[i]; 400: EditBuff[i] = ' '; 401: } 402: /* redraw the line with the tab */ 403: drawline(); 404: CurCol += tabshift; 1.1.1.2 ! root 405: VioSetCurPos(CurRow, CurCol, 0); 1.1 root 406: EditBuffDirty = TRUE; 407: } 408: else badkey(); 409: } 410: else badkey(); 411: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.