📄 popup.c
字号:
/*
* POPUP.C - Show a popup message to user.
*
*
* PROGRAMMER: Martti Ylikoski
* CREATED: 13.3.1992
*/
static char *VERSION="Version 1.0. Copyright(c) Martti Ylikoski, 1992. " ;
/*
*
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "list.h"
#include <param.h>
#include <paramstd.h>
ParamEntry pentry[12] = {
"P", &ParamSetPause, 0,
"F", &ParamSetFold, 0,
"V", &ParamSetVerbose, 0,
"R", &ParamSetReport, 0,
"S", &ParamSetSubDirs, 0,
"?", &ParamSetHelp, 1,
"H", &ParamSetHelp, 1,
"NOD", &ParamSetNoDefault, 1,
"TEST", &ParamSetTest, 0,
"Y", &ParamSetYes, 0,
"N", &ParamSetTest, 0,
"\0", NULL, 0
} ;
ParamBlock params = {
"/-", IGNORECASE | NOPRIORITY | NOTRIGGERSALLOWED ,
pentry
} ;
extern unsigned long pflags ; /* needed because of paramstd */
/* from wndbox.h */
#define SNGL_TOPLEFT 0
#define SNGL_TOPRIGHT 1
#define SNGL_LINE 2
#define SNGL_BAR 3
#define SNGL_BOTLEFT 4
#define SNGL_BOTRIGHT 5
char sngl[6] = {
218,
191,
196,
179,
192,
217
} ;
#define INCL_VIO
#define INCL_DOS
#define INCL_KBD
#include <os2.h>
static char *progname ;
static char *deffile = ".\\popup.dat" ;
/* local prototypes */
static void DrawBox(int TopRow, int TopCol, int BotRow, int BotCol) ;
static void DrawData(HNDLIST *lhandle, int TopRow, int TopCol, int BotRow, int BotCol) ;
static void AddToDisplay(HNDLIST *lhandle, char *fbuff, int *DataLineCount, int *MaxLineLen) ;
int main(int argc, char *argv[])
{
int TopRow, TopCol, BotRow, BotCol, MaxCol, MaxRow, MaxLineLen, DataLineCount, c ;
USHORT fWait = VP_WAIT | VP_OPAQUE ;
FILE *fp ;
HNDLIST *lhandle ;
char fbuff[125], *tmp, *tmp2 ;
KBDKEYINFO kbdi ;
progname = argv[0] ;
ParamHandle(¶ms, &argc, argv) ;
if ((lhandle = ListInit()) == NULL)
{
printf("Error in ListInit\nExit\n") ;
return( 1 ) ;
}
VioPopUp(&fWait, 0) ;
DataLineCount = 0 ;
MaxLineLen = 0 ;
if (pflags & PA_HELP)
{
sprintf(fbuff,"%s - Shows a popup message for the user.\n", progname) ;
AddToDisplay(lhandle, fbuff, &DataLineCount, &MaxLineLen) ;
AddToDisplay(lhandle,VERSION, &DataLineCount, &MaxLineLen) ;
AddToDisplay(lhandle,"Usage: popup [message] | [/F messagefile] | [/? | /H] [/NOD]", &DataLineCount, &MaxLineLen) ;
AddToDisplay(lhandle,"Where,", &DataLineCount, &MaxLineLen) ;
AddToDisplay(lhandle," message = Displayed message with \\n between different lines.", &DataLineCount, &MaxLineLen) ;
AddToDisplay(lhandle," /F messagefile = Displayed message in a file", &DataLineCount, &MaxLineLen) ;
AddToDisplay(lhandle," /NOD = No default. Automatically added two last lines are not displayed.", &DataLineCount, &MaxLineLen) ;
AddToDisplay(lhandle," /H,/? = Help", &DataLineCount, &MaxLineLen) ;
deffile = "NUL" ;
}
if (argc == 2)
{
tmp2 = argv[1] ;
while ( 1 )
{
if ( (tmp =strchr(tmp2, (int) '\\')) != NULL && tmp[1] == 'n' )
{
tmp[0] = '\0' ;
tmp[1] = '\0' ;
DataLineCount ++ ;
if (fbuff[strlen(tmp2)-1] == '\n')
fbuff[strlen(tmp2)-1] = '\0' ; /* remove trailing newline */
if (strlen(tmp2) > MaxLineLen)
MaxLineLen = strlen(tmp2) ;
ListAdd(lhandle, tmp2, strlen(tmp2)+1) ; /* +1 because we store also \0 */
tmp2 = tmp+2 ;
if (tmp2[0] == '\0')
break ;
}
else
if (tmp2[0] == '\0')
break ;
else
{
DataLineCount ++ ;
if (strlen(tmp2) > MaxLineLen)
MaxLineLen = strlen(tmp2) ;
ListAdd(lhandle, tmp2, strlen(tmp2)+1) ; /* +1 because we store also \0 */
break ;
}
}
}
else
{
if (argc >2 && ( strcmpi(argv[1], "/f") == 0 || strcmpi(argv[1], "-f")==0))
deffile = argv[2] ;
if ((fp = fopen (deffile, "r")) == NULL)
{
sprintf(fbuff,"%s : error opening messagefile %s.", progname, deffile) ;
AddToDisplay(lhandle, fbuff, &DataLineCount, &MaxLineLen) ;
AddToDisplay(lhandle, " ", &DataLineCount, &MaxLineLen) ;
}
else
{
while (fgets(fbuff, sizeof(fbuff), fp ) != NULL)
{
DataLineCount ++ ;
if (fbuff[strlen(fbuff)-1] == '\n')
fbuff[strlen(fbuff)-1] = '\0' ; /* remove trailing newline */
if (strlen(fbuff) > MaxLineLen)
MaxLineLen = strlen(fbuff) ;
ListAdd(lhandle, fbuff, strlen(fbuff)+1) ; /* +1 because we store also \0 */
}
fclose (fp) ;
}
}
MaxCol = 79 ;
MaxRow = 24 ;
if (MaxLineLen <28)
MaxLineLen = 28 ;
memset(fbuff, sngl[SNGL_LINE], (size_t) MaxLineLen) ;
ListAdd(lhandle, fbuff, strlen(fbuff)+1) ; /* +1 because we store also \0 */
strcpy(fbuff, "Press ESC to cancel message.") ;
ListAdd(lhandle, fbuff, strlen(fbuff)+1) ; /* +1 because we store also \0 */
if (strlen(fbuff) > MaxLineLen)
MaxLineLen = strlen(fbuff) ;
DataLineCount += 2 ;
TopRow = (MaxRow - DataLineCount)/2 -1 ;
if (TopRow <0)
TopRow = 0 ;
TopCol = (MaxCol - MaxLineLen)/2 - 1 ;
if (TopCol <0)
TopCol = 0 ;
BotRow = 24 -(MaxRow - DataLineCount)/2 +1 ;
BotCol = 79 - (MaxCol - MaxLineLen)/2 + 1 ;
DrawBox(TopRow, TopCol, BotRow, BotCol) ;
DrawData(lhandle, TopRow, TopCol, BotRow, BotCol) ;
do
{
KbdCharIn(&kbdi, IO_WAIT, 0) ;
} while (kbdi.chChar != 27) ;
VioEndPopUp( 0 ) ;
return( 0 ) ;
}
static void DrawBox(int TopRow, int TopCol, int BotRow, int BotCol)
{
int i ;
BYTE WndCol = 0x17 ;
VioWrtCharStrAtt(&sngl[SNGL_TOPLEFT],1,TopRow, TopCol, &WndCol, 0) ;
for (i = 1 ; i < BotCol - TopCol ; i++)
VioWrtCharStrAtt(&sngl[SNGL_LINE],1,TopRow, TopCol+i, &WndCol, 0) ;
VioWrtCharStrAtt(&sngl[SNGL_TOPRIGHT],1,TopRow, BotCol, &WndCol, 0) ;
for (i = 1 ; i < BotRow - TopRow; i++)
{
VioWrtCharStrAtt(&sngl[SNGL_BAR],1, TopRow+i, TopCol, &WndCol, 0) ;
VioWrtCharStrAtt(&sngl[SNGL_BAR],1, TopRow+i, BotCol, &WndCol, 0) ;
}
VioWrtCharStrAtt( &sngl[SNGL_BOTLEFT], 1, BotRow, TopCol, &WndCol, 0) ;
for (i = 1 ; i < BotCol - TopCol ; i++)
VioWrtCharStrAtt(&sngl[SNGL_LINE],1,BotRow, TopCol+i, &WndCol, 0) ;
VioWrtCharStrAtt(&sngl[SNGL_BOTRIGHT],1,BotRow, BotCol, &WndCol, 0) ;
}
static void DrawData(HNDLIST *lhandle, int TopRow, int TopCol, int BotRow, int BotCol)
{
unsigned short width, height, drawlen ;
LIST_ENTRY *templist ;
long templ, templ2 ;
int actioncode ;
char *buf ;
unsigned long buflen ;
int i ;
unsigned char attrib ;
unsigned char cell[2] ;
cell[0] = ' ' ;
cell[1] = 0x17; // wnd->WndCol ;
height = BotRow - TopRow ; /* calculate the height of the window */
width = BotCol - TopCol ; /* calculate the width of the window */
attrib = 0x17 ; //WndCol ;
ListFirst(lhandle) ;
/* Note different drawing limits for windows with/without borders */
for (i = 1 ; i <= height - 1 ; i++)
{
ListReturn(lhandle, &buf, &buflen) ;
VioWrtCharStrAtt( buf, buflen , TopRow+i, TopCol+1, &attrib, 0) ;
VioWrtNCell(cell, width-1 - buflen, TopRow+i, TopCol+1+buflen, 0) ;
if ( ListNext(lhandle) != LIST_OK)
break ;
}
/* Note different drawing limits for windows with/without borders */
for ( ++i ; i <= height - 1 ; i++)
{
VioWrtNCell(cell, width-1 , TopRow+i, TopCol+1, 0) ;
}
}
static void AddToDisplay(HNDLIST *lhandle, char *fbuff, int *DataLineCount, int *MaxLineLen)
{
*DataLineCount += 1 ;
if (fbuff[strlen(fbuff)-1] == '\n')
fbuff[strlen(fbuff)-1] = '\0' ; /* remove trailing newline */
if (strlen(fbuff) > *MaxLineLen)
*MaxLineLen = strlen(fbuff) ;
ListAdd(lhandle, fbuff, strlen(fbuff)+1) ; /* +1 because we store also \0 */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -