Category : BBS Programs+Doors
Archive   : NOTEPAD.ZIP
Filename : NOTEPAD.C
WWIV NotePad 1.0
By The Captain of The White Star Line (@2370)
This modification will give your users a notepad with which to write short
notes whilst on-line. You may change the ASCII codes to suit your preference
if you do not like the default definitions for routines such as cursor
movement and editing functions. The location of the current definitions is
clearly marked in the code.
*****************************************************************************/
#include
#include
#include
#include
#include
extern configrec syscfg;
extern int usernum;
extern int hangup;
struct
{
char line[10][41];
} _note;
void alocate();
void checkhangup();
int sread(fh,rec,struc,size)
FILE *fh;
int rec;
char far *struc;
int size;
{
long temp;
long lsize;
long lrec;
lsize = size;
lrec = rec;
temp = lsize * lrec;
fseek(fh,temp,SEEK_SET);
fread(struc,1,size,fh);
}
int swrite(fh,rec,struc,size)
FILE *fh;
int rec;
char far *struc;
int size;
{
long temp;
long lsize;
long lrec;
lsize = size;
lrec = rec;
temp = lsize*lrec;
fseek(fh,temp,SEEK_SET);
fwrite(struc,1,size,fh);
}
void draw_window()
{
char temp[80];
int i;
alocate(1,1);
prt(2,"ÖÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ[ NotePad ]ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ·");
nl();
for(i=0;i<10;i++) {
prt(2,"º º");
nl(); }
prt(2,"ÓÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĽ");
nl();
alocate(44,1);
prt(4,"ÖÄÄÄÄÄÄÄÄÄ[ Edit Commands ]ÄÄÄÄÄÄÄÄÄ·");
alocate(44,2);
prt(4,"º [Ctrl-I] - Up º");
alocate(44,3);
prt(4,"º [Ctrl-J] - Left [Ctrl-L] - Right º");
alocate(44,4);
prt(4,"º [Ctrl-M] - Down º");
alocate(44,5);
prt(4,"ÇÄÄÄÄÄÄÄÄÄ[ Other Commands ]ÄÄÄÄÄÄÄĶ");
alocate(44,6);
prt(4,"º [Ctrl-U] - Clear Window º");
alocate(44,7);
prt(4,"º [Ctrl-Y] - Delete Line º");
alocate(44,8);
prt(4,"º [Ctrl-Q] - Home Cursor º");
alocate(44,9);
prt(4,"º [Ctrl-E] - End Cursor º");
alocate(44,10);
prt(4,"º [Ctrl-G] - Delete Character º");
alocate(44,11);
prt(4,"º [Ctrl-H] - Delete & Backspace º");
alocate(44,12);
prt(4,"ÇÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĶ");
alocate(44,13);
prt(4,"º Tap [Escape] to Exit and Save the º");
alocate(44,14);
prt(4,"º current Note Pad! º");
alocate(44,15);
prt(4,"ÓÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĽ");
}
void alocate(x,y)
int x,y;
{
char temp[20];
sprintf(temp,"%c[%d;%dH",27,y,x);
outstr(temp);
}
void saveit()
{
FILE *stream;
char dir[40];
int i,j;
strcpy(dir,syscfg.datadir);
strcat(dir,"NOTEPAD.DAT");
stream = fopen(dir,"r+b");
swrite(stream,usernum,&_note,sizeof(_note));
fclose(stream);
}
void restoreit()
{
FILE *stream;
char dir[41];
int i,j;
strcpy(dir,syscfg.datadir);
strcat(dir,"NOTEPAD.DAT");
stream = fopen(dir,"r+b");
sread(stream,usernum,&_note,sizeof(_note));
fclose(stream);
for(i=0;i<10;i++) {
alocate(2,i+2);
memcpy(dir,_note.line[i],41);
dir[41] = 0;
prt(1,dir);
}
alocate(2,2);
}
void createit()
{
FILE *stream;
int i,j;
char dir[80];
strcpy(dir,syscfg.datadir);
strcat(dir,"NOTEPAD.DAT");
for(i=0;i<10;i++)
for(j=0;j<41;j++)
_note.line[i][j] = 32;
if (access(dir,S_IREAD|S_IWRITE) == -1) {
stream = fopen(dir,"a+b");
for(i=0;i<500;i++)
swrite(stream,usernum,&_note,sizeof(_note));
fclose(stream);
}
}
void notepad()
{
int x,y;
int done;
char ch;
char temp[20];
int i,j;
char dir[50],xl[81], cl[81], atr[81], cc;
sysoplog("* Used the NotePad!");
savel(cl, atr, xl, &cc);
draw_window();
x = 1;
y = 1;
done = 0;
createit();
restoreit();
while (!done) {
checkhangup();
ch = 0;
while (!ch) {
ch = inkey();
if (!ch && kbhit())
ch = getch();
}
if (ch == 8) { /* CTRL-H */
if (x > 1)
x--;
else
if (y > 1) {
x = 41;
y--;
}
alocate(x+1,y+1);
outstr(" ");
alocate(x+1,y+1);
_note.line[y][x] = 32;
}
if (ch == 9 && y > 1) { /* CTRL-I */
y--;
alocate(x+1,y+1);
}
if (ch == 13 && y < 10) { /* CTRL-M */
y++;
alocate(x+1,y+1);
}
if (ch == 10 && x > 1) { /* CTRL-J */
x--;
alocate(x+1,y+1);
}
if (ch == 12 && x < 41) { /* CTRL-L */
x++;
alocate(x+1,y+1);
}
if (ch == 21) { /* CTRL-U */
for(i=0;i<10;i++) {
alocate(2,i+2);
for(j=0;j<41;j++) {
outstr(" ");
_note.line[i][j] = 32;
}
}
x = 1;
y = 1;
alocate(x+1,y+1);
}
if (ch == 7) { /* CTRL-G */
for(i=x-1;i<40;i++)
_note.line[y-1][i] = _note.line[y-1][i+1];
_note.line[y-1][40] = 32;
alocate(2,y+1);
memcpy(dir,_note.line[y-1],41);
dir[41] = 0;
prt(1,dir);
alocate(x+1,y+1);
}
if (ch == 17) { /* CTRL-Q */
x = 1;
y = 1;
alocate(x+1,y+1);
}
if (ch == 5) { /* CTRL-E */
x = 1;
y = 10;
alocate(x+1,y+1);
}
if (ch == 25) { /* CTRL-Y */
for(i=0;i<41;i++) {
alocate(i+2,y+1);
outstr(" ");
_note.line[y-1][i] = 32;
}
alocate(x+1,y+1);
}
if (ch == 27) /* CTRL-[ (ESC) */
done = 1;
if (ch == 13) { /* CTRL-M */
x = 1;
alocate(x+1,y+1);
}
if (ch > 31 && ch < 128) {
if (x == 42) {
x = 1;
y++;
}
if (y < 11) {
alocate(x+1,y+1);
sprintf(temp,"%c",ch);
prt(1,temp);
_note.line[y-1][x-1] = ch;
}
else
y = 10;
x++;
}
}
saveit();
outstr("\x1b[2J");
nl();
prt(7,"Your note has been saved...");
nl();
nl();
restorel(cl, atr, xl, &cc);
}
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/