home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mega Top 1
/
os2_top1.zip
/
os2_top1
/
DEMO
/
RIM22
/
MACROS
/
MISC.RM
< prev
next >
Wrap
Text File
|
1993-11-10
|
6KB
|
268 lines
/*
** Macro module: misc.c - Misc. functions
**
** Copyright (C) 1993 Brian L. Smith
** Copyright (C) 1993 RimStar Technology, Inc.
** All rights reserved internationally.
** Unlicensed use is a violation of applicable laws.
**
** This source code is provided to licensed users of RimStar's products
** for the purpose of allowing the user to customize and/or enhance RimStar's
** products. The source code remains the property of the copyright holders
** with all rights reserved internationally.
** Any modifications to the source code are considered derivative works and
** all rights thereto are reserved to the copyright holders except
** that the purchaser may use the derivitive work in the same manner
** as permitted by the license governing the unmodified product.
** Distribution in any manner of any part of the original source code,
** whether in source or object form, is expressly prohibited without the
** express written permission of the copyright holders.
**
*/
#include "macro.h"
void
quote(void) {
PRAWKEY pKey;
/* Wait for a key */
while ( !(pKey = KbdBufferQueryKey()) )
;
if ( pKey->ascii && !(pKey->key & KC_ALT) ) {
pKey = KbdBufferGetKey(); /* remove from keyboard buffer */
BufInsertChar(pKey->ascii);
}
} /* end quote() */
long
__next_word(void) {
return SrchFwd("([^ \t\f\n]+)|([ \t\f\n]*)[ \t\f\n]+\\c[^ \t\f\n]", -1);
} /* end __next_word() */
long
__prev_word(void) {
PosPrevChar();
while ( strchr(" \t\f", BufQueryChar()) )
if ( PosPrevChar() )
return 0;
return SrchBack("^|[ \t\f]\\c[^ \t\f\n]+", -1);
} /* end __prev_word() */
void
next_word(void) {
char *pathname;
char ext[5];
char *func;
/* Determine file extension of current buffer */
pathname = BufQueryFilename();
if ( !pathname ) {
__next_word();
return;
}
/* Build function name from file extension */
splitpath(pathname, NULL, NULL, NULL, ext);
func = malloc(32);
ext[0] = '_';
strcpy(func, ext);
strlwr(func);
strcat(func, "_next_word");
if ( LibQueryFunction(func) ) /* is there an extension specific version */
ExecFunction(func);
else
__next_word();
free(func);
} /* end next_word() */
void
prev_word(void) {
char *pathname;
char ext[5];
char *func;
/* Determine file extension of current buffer */
pathname = BufQueryFilename();
if ( !pathname ) {
__prev_word();
return;
}
/* Build function name from file extension */
splitpath(pathname, NULL, NULL, NULL, ext);
func = malloc(32);
ext[0] = '_';
strcpy(func, ext);
strlwr(func);
strcat(func, "_prev_word");
if ( LibQueryFunction(func) ) /* is there an extension specific version */
ExecFunction(func);
else
__prev_word();
free(func);
} /* end prev_word() */
int
delete_next_word() {
long startPos;
long endPos;
long startLine;
long endLine;
startPos = BufQueryOffset();
startLine = BufQueryLine();
MarkPushPos();
next_word();
endPos = BufQueryOffset();
endLine = BufQueryLine();
if ( endPos != startPos ) {
MarkPopPos();
if ( endLine != startLine )
BufDeleteToEOL();
else
BufDeleteChar(endPos - startPos);
return 1;
}
MarkPopPos();
return 0;
} /* end delete_next_word() */
int
delete_prev_word() {
long startPos;
long size;
startPos = BufQueryOffset();
MarkPushPos();
prev_word();
if ( size = startPos - BufQueryOffset() ) {
BufDeleteChar(size);
MarkPopPos(0); /* discard saved position */
return 1;
}
MarkPopPos();
return 0;
} /* end delete_prev_word() */
/*
** open_line - creates an empty line following the current line
*/
void
open_line(void) {
char *pszFunc;
MovEOL();
pszFunc = KbdQueryFunction(KbdStringToKeys("Enter"), 1);
if ( !strcmp(pszFunc, "SelfInsert") || !strcmp(pszFunc, "open_line") )
BufInsertNewline();
else
ExecFunction(pszFunc);
} /* end open_line() */
void
process_selection(char *(*func)() ) {
SELECTION sel;
int type;
long atLine;
long offset;
long size;
char *s1, *s2;
MarkPushPos();
if ( !MarkQuerySelType() )
MarkLine();
type = MarkQuerySel(&sel, 1);
PosAbs(atLine = sel.s_line, sel.s_column);
while ( atLine <= sel.e_line ) {
MarkPushPos();
offset = BufQueryOffset();
if ( atLine == sel.e_line || type == SELECT_COLUMN )
PosAbs(0, sel.e_column);
else
PosEOL();
size = BufQueryOffset() - offset + 1;
MarkPopPos(1);
s1 = BufRead(size);
s2 = strdup(s1);
s2 = func(s2);
if ( strcmp(s1, s2) ) {
BufDeleteChar(size);
BufInsertString(s2);
}
free(s1);
free(s2);
if ( type == SELECT_COLUMN )
offset = sel.s_column;
else
offset = 1L;
PosAbs(++atLine, offset);
}
MarkPopPos(1);
} /* end process_selection() */
#undef toupper
#undef tolower
void
toupper() {
process_selection(strupr);
MarkRemoveSel();
} /* end toupper() */
void
tolower() {
process_selection(strlwr);
MarkRemoveSel();
} /* end tolower() */
char *
convert_to_space(char *s) {
long i;
for ( i = 0; s[i] && s[i] != '\n'; ++i )
if ( s[i] != ' ' && s[i] != '\t' )
s[i] = ' ';
return s;
} /* end convert_to_space() */
void
tospace() {
SELECTION sel;
if ( !MarkQuerySel(&sel, 1) )
BufInsertChar(' ');
else {
process_selection(convert_to_space);
MarkRemoveSel();
MovAbs(sel.s_line, sel.s_column);
}
} /* end tospace() */
/*
** End macro: misc.rm
*/