Annotation of os2sdk/demos/apps/sse/keyfunc1.c, revision 1.1

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

unix.superglobalmegacorp.com

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