× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: Re: One more example for today !
  • From: "Phil Hall" <hallp@xxxxxxxx>
  • Date: Tue, 18 Jul 2000 16:13:32 -0500


----- Original Message -----
From: "Jevgeni Astanovski" <jevgeni@optiva.ee>
To: <C400-L@midrange.com>
Sent: Friday, July 07, 2000 6:43 AM
Subject: Re: One more example for today !


> This example was of great interest for me.
> Thanks, Phil.
> And not because of ports fiddling, but because of DSM. It's a real
> fun! I really like it, though never used before.

If you like DSM, you might find this one fun too...compile it and run it,
when it finishes, press F3 to exit...

[Note#1 - source is a little messy as it was a prototype - sorry !]
[Note#2 - long lines may wrap across multiple lines - sorry !]

Hope you enjoy it !

--phil

[-----------code starts here-----------]

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <unistd.h>
#include <qsnapi.h>

#define _ROWS_    20
#define _COLS_    76
#define _START_COL_   2
#define _CMD_INPUT_LEN_  1
#define _INPUT_CHAR_COL_ 2
#define _INPUT_CHAR_ROW_ 23

#define TRUE    1
#define FALSE    0

#define _COMP_ROW_   19
#define _COMP_COL_   6

#define _STEP1_    1
#define _STEP2_    2
#define _STEP3_    3
#define _STEP4_    4

#define _STEP1_ATTRIB_ROW_ 5
#define _STEP1_ATTRIB_COL_ 6
#define _STEP2_ATTRIB_ROW_ 7
#define _STEP2_ATTRIB_COL_ 6
#define _STEP3_ATTRIB_ROW_ 9
#define _STEP3_ATTRIB_COL_ 6
#define _STEP4_ATTRIB_ROW_ 11
#define _STEP4_ATTRIB_COL_ 6

static int screenCmdBuffer;
static int screenInpBuffer;
static int cmdInput = 747;
static Qsn_Fld_Inf_T fldInfo;
static cur_step_percent = 0;
static cur_install_percent = 0;

void do_test(void);
void set_up_display(void);
void clearScreen(void);
void display_screen(void);
void build_main_screen(void);
char screen_getchar(void);
void sound_bell(void);

void start_step(int step_number, int step_row, int step_col);
void increment_step(int step_number, int inc_percent );
void end_step(int step_number, int step_row, int step_col);
void highlight_step(int step_number, int step_row, int step_col, int
highlight);

void increment_install(int inc_percent);
void end_intall(char *comp_text);

/*-- test data --*/
char title_text[]   = "Example XXXX Install";
char *steps_text[5] = { " ",
       "  - Install Libraries From Save File",
        "  - Create Default Database",
       "  - Create System Admin Profile",
       "  - Delete Temporary Install Files" };


int main(void)
{
 set_up_display();
 build_main_screen();
 do_test();

 return 0;
}

void do_test(void)
{
 char key_pressed;

 display_screen();
 sleep( 1 );

 /*-- step 1 --*/
 start_step( _STEP1_, _STEP1_ATTRIB_ROW_, _STEP1_ATTRIB_COL_ );
 sleep( 1 );
 increment_step( _STEP1_, 25);
 sleep( 1 );
 increment_step( _STEP1_, 25);
 sleep( 1 );
 increment_step( _STEP1_, 20 );
 increment_step( _STEP1_, 20 );
 sleep( 1 );
 increment_step( _STEP1_, 20 );
 end_step( _STEP1_, _STEP1_ATTRIB_ROW_, _STEP1_ATTRIB_COL_ );

 increment_install( 30 );

 /*-- step 2 --*/
 start_step( _STEP2_, _STEP2_ATTRIB_ROW_, _STEP2_ATTRIB_COL_ );
 sleep( 1 );
 increment_step( _STEP2_, 50);
 sleep( 1 );
 increment_step( _STEP2_, 50);
 sleep( 1 );
 end_step( _STEP2_, _STEP2_ATTRIB_ROW_, _STEP2_ATTRIB_COL_ );

 increment_install( 30 );

 /*-- step 3 --*/
 start_step( _STEP3_, _STEP3_ATTRIB_ROW_, _STEP3_ATTRIB_COL_ );
 increment_step( _STEP3_, 25);
 increment_step( _STEP3_, 25);
 sleep( 1 );
 increment_step( _STEP3_, 50 );
 end_step( _STEP3_, _STEP3_ATTRIB_ROW_, _STEP3_ATTRIB_COL_ );

 increment_install( 30 );

 /*-- step 4 --*/
 start_step( _STEP4_, _STEP4_ATTRIB_ROW_, _STEP4_ATTRIB_COL_ );
 sleep( 1 );
 increment_step( _STEP4_, 25);
 sleep( 1 );
 increment_step( _STEP4_, 25);
 sleep( 1 );
 increment_step( _STEP4_, 25 );
 sleep( 1 );
 increment_step( _STEP4_, 25 );
 end_step( _STEP4_, _STEP4_ATTRIB_ROW_, _STEP4_ATTRIB_COL_ );

 increment_install( 10 );

 end_intall( "Installation completed." );

 while( key_pressed != QSN_F3 )
 {
  key_pressed = screen_getchar();
 }
}

void build_main_screen(void)
{
    int i;

    /*-- create the window, do it manually instead of using DSM API's --*/

QsnWrtDta("+----------------------------------------------------------------
------------+",
              78, 0, 1, 2,
              QSN_SA_HI, QSN_SA_NORM, QSN_SA_BLU, QSN_SA_NORM,
screenCmdBuffer, 0, NULL);

QsnWrtDta("+----------------------------------------------------------------
------------+",
              78, 0, 22, 2,
              QSN_SA_HI, QSN_SA_NORM, QSN_SA_BLU, QSN_SA_NORM,
screenCmdBuffer, 0, NULL);

 for (i = 0; i < _ROWS_; i++)
    {
        QsnWrtDta("|", 1, 0,  i + 2, _START_COL_ , QSN_SA_HI, QSN_SA_NORM,
                   QSN_SA_BLU, QSN_SA_GRN, screenCmdBuffer, 0, NULL);
        QsnWrtDta("|", 1, 0,  i + 2, _COLS_ + 3, QSN_SA_HI, QSN_SA_NORM,
                   QSN_SA_BLU, QSN_SA_GRN, screenCmdBuffer, 0, NULL);
    }

    /*-- create the char input field --*/
    QsnSetFld( cmdInput, _CMD_INPUT_LEN_,
               _INPUT_CHAR_ROW_,
               _INPUT_CHAR_COL_,
               QSN_FFW_ALPHA_SHIFT, NULL, 0,
               QSN_SA_NORM | QSN_SA_UL, QSN_SA_GRN_UL, screenCmdBuffer, 0,
NULL);

 /*-- create title text --*/
    QsnWrtDta(title_text,
              strlen(title_text), 0, 2, 4,
              QSN_SA_HI, QSN_SA_NORM, QSN_SA_HI, QSN_SA_NORM,
screenCmdBuffer, 0, NULL);

 /*-- create step #1 text --*/
    QsnWrtDta(steps_text[1],
              strlen(steps_text[1]), 0, _STEP1_ATTRIB_ROW_,
_STEP1_ATTRIB_COL_,
              QSN_SA_HI, QSN_SA_NORM, QSN_SA_NORM, QSN_SA_NORM,
screenCmdBuffer, 0, NULL);

 /*-- create step #2 text --*/
    QsnWrtDta(steps_text[2],
              strlen(steps_text[2]), 0, _STEP2_ATTRIB_ROW_,
_STEP2_ATTRIB_COL_,
              QSN_SA_NORM, QSN_SA_NORM, QSN_SA_NORM, QSN_SA_NORM,
screenCmdBuffer, 0, NULL);

 /*-- create step #3 text --*/
    QsnWrtDta(steps_text[3],
              strlen(steps_text[3]), 0, _STEP3_ATTRIB_ROW_,
_STEP3_ATTRIB_COL_,
              QSN_SA_NORM, QSN_SA_NORM, QSN_SA_NORM, QSN_SA_NORM,
screenCmdBuffer, 0, NULL);

 /*-- create step #4 text --*/
    QsnWrtDta(steps_text[4],
              strlen(steps_text[4]), 0, _STEP4_ATTRIB_ROW_,
_STEP4_ATTRIB_COL_,
              QSN_SA_NORM, QSN_SA_NORM, QSN_SA_NORM, QSN_SA_NORM,
screenCmdBuffer, 0, NULL);

 /*-- create task progress bar borders --*/
    QsnWrtDta("Task Progress        0% ",
              24, 0, 13, 53,
              QSN_SA_HI, QSN_SA_NORM, QSN_SA_BLU, QSN_SA_NORM,
screenCmdBuffer, 0, NULL);
    QsnWrtDta("+----------------------+",
              24, 0, 14, 53,
              QSN_SA_HI, QSN_SA_NORM, QSN_SA_BLU, QSN_SA_NORM,
screenCmdBuffer, 0, NULL);
    QsnWrtDta("|                      |",
              24, 0, 15, 53,
              QSN_SA_HI, QSN_SA_NORM, QSN_SA_BLU, QSN_SA_NORM,
screenCmdBuffer, 0, NULL);
    QsnWrtDta("+----------------------+",
              24, 0, 16, 53,
              QSN_SA_HI, QSN_SA_NORM, QSN_SA_BLU, QSN_SA_NORM,
screenCmdBuffer, 0, NULL);

 /*-- create install progress bar borders --*/
    QsnWrtDta("Install Progress     0% ",
              24, 0, 17, 53,
              QSN_SA_HI, QSN_SA_NORM, QSN_SA_BLU, QSN_SA_NORM,
screenCmdBuffer, 0, NULL);
    QsnWrtDta("+----------------------+",
              24, 0, 18, 53,
              QSN_SA_HI, QSN_SA_NORM, QSN_SA_BLU, QSN_SA_NORM,
screenCmdBuffer, 0, NULL);
    QsnWrtDta("|                      |",
              24, 0, 19, 53,
              QSN_SA_HI, QSN_SA_NORM, QSN_SA_BLU, QSN_SA_NORM,
screenCmdBuffer, 0, NULL);
    QsnWrtDta("+----------------------+",
              24, 0, 20, 53,
              QSN_SA_HI, QSN_SA_NORM, QSN_SA_BLU, QSN_SA_NORM,
screenCmdBuffer, 0, NULL);
}

void start_step(int step_number, int step_row, int step_col)
{
 highlight_step( step_number, step_row, step_col, TRUE);
}

void increment_step(int step_number, int inc_percent )
{
 int count = cur_step_percent + ( inc_percent / 5 );
 char buffer[20] = "";
 char text[3] = "";
 int i = 0;

 if (count > 20)
 {
  cur_step_percent = 20;
 }
 else
 {
  cur_step_percent = count;
 }

 for ( i = 0; i < cur_step_percent; i++)
 {
  buffer[i] = ' ';
 }

 buffer[i] = '\0';

    QsnWrtDta(buffer,
              strlen( buffer ), 0, 15, 55,
              QSN_SA_HI | QSN_SA_RI , QSN_SA_NORM, QSN_SA_BLU_RI,
QSN_SA_BLU, screenCmdBuffer, 0, NULL);

 sprintf( text, "%d%%", cur_step_percent * 5);
 QsnWrtDta(text,
              strlen(text), 0, 13, 73,
              QSN_SA_HI, QSN_SA_NORM, QSN_SA_BLU, QSN_SA_NORM,
screenCmdBuffer, 0, NULL);

 display_screen();
}

void increment_install(int inc_percent)
{
 int count = cur_install_percent + ( inc_percent / 5 );
 char buffer[20] = "";
 char text[3] = "";
 int i = 0;

 if (count > 20)
 {
  cur_install_percent = 20;
 }
 else
 {
  cur_install_percent = count;
 }

 for ( i = 0; i < cur_install_percent; i++)
 {
  buffer[i] = ' ';
 }

 buffer[i] = '\0';

    QsnWrtDta(buffer,
              strlen( buffer ), 0, 19, 55,
              QSN_SA_HI | QSN_SA_RI , QSN_SA_NORM, QSN_SA_BLU_RI,
QSN_SA_BLU, screenCmdBuffer, 0, NULL);

 sprintf( text, "%d%%", cur_install_percent * 5);
 QsnWrtDta(text,
              strlen(text), 0, 17, 73,
              QSN_SA_HI, QSN_SA_NORM, QSN_SA_BLU, QSN_SA_NORM,
screenCmdBuffer, 0, NULL);

 display_screen();
}

void end_step(int step_number, int step_row, int step_col)
{
 steps_text[step_number][0] = 'Y';
 QsnWrtDta("0% ",
              strlen("0% "), 0, 13, 73,
              QSN_SA_HI, QSN_SA_NORM, QSN_SA_BLU, QSN_SA_NORM,
screenCmdBuffer, 0, NULL);

    QsnWrtDta("|                      |",
              24, 0, 15, 53,
              QSN_SA_HI, QSN_SA_NORM, QSN_SA_BLU, QSN_SA_NORM,
screenCmdBuffer, 0, NULL);

 highlight_step( step_number, step_row, step_col, FALSE);
}

void highlight_step(int step_number, int step_row, int step_col, int
highlight)
{
 if ( highlight == TRUE )
 {
     QsnWrtDta(steps_text[step_number],
            strlen(steps_text[step_number]), 0, step_row, step_col,
         QSN_SA_HI, QSN_SA_NORM, QSN_SA_HI, QSN_SA_NORM, screenCmdBuffer, 0,
NULL);
 }
 else
 {
     QsnWrtDta(steps_text[step_number],
            strlen(steps_text[step_number]), 0, step_row, step_col,
         QSN_SA_NORM, QSN_SA_NORM, QSN_SA_NORM, QSN_SA_NORM,
screenCmdBuffer, 0, NULL);
 }
 display_screen();
}

void end_intall(char *comp_text)
{
     QsnWrtDta(comp_text,
            strlen(comp_text), 0, _COMP_ROW_, _COMP_COL_,
         QSN_SA_HI, QSN_SA_NORM, QSN_SA_HI, QSN_SA_NORM, screenCmdBuffer, 0,
NULL);
}

char screen_getchar(void)
{
    char charInputted;
    long numFldsRtnd = 0;

    QsnClrBuf(screenInpBuffer, NULL);

    QsnSetCsrAdr(0, _INPUT_CHAR_ROW_, _INPUT_CHAR_COL_, screenCmdBuffer, 0,
NULL);
    QsnReadMDT(QSN_CC1_NULL, QSN_CC1_NULL, &numFldsRtnd,
               screenInpBuffer, screenCmdBuffer, 0, NULL);
    /* QsnSetCsrAdr(0, real_cursor_row_pos, real_cursor_col_pos,
screenCmdBuffer, 0, NULL); */

    if (QsnRtvReadAID(screenInpBuffer, NULL, NULL) == QSN_F3)
    {
        exit(0);
    }

    if (numFldsRtnd > 0)
    {
        QsnRtvFldInf(screenInpBuffer, 1, &fldInfo, (sizeof(fldInfo)), 0,
NULL);
        if ( fldInfo.data != NULL)
        {
            memcpy( &charInputted, fldInfo.data, 1);
        }
    }

    return charInputted;
}

void display_screen(void)
{
    QsnPutBuf( screenCmdBuffer, 0, NULL );
    QsnClrBuf( screenCmdBuffer, NULL);
}

void set_up_display(void)
{
    /*-- sets up the screen, rather than getting term info --*/
    screenCmdBuffer = QsnCrtCmdBuf(4500, 1000, 5600, NULL, NULL);
    screenInpBuffer = QsnCrtInpBuf(200, 50, 0, NULL, NULL);
    clearScreen();
}

void clearScreen(void)
{
    QsnClrScr('3', 0, 0, NULL);
}

void sound_bell(void)
{
    QsnBeep( 0, 0, NULL);
}


+---
| This is the C/400 Mailing List!
| To submit a new message, send your mail to C400-L@midrange.com.
| To subscribe to this list send email to C400-L-SUB@midrange.com.
| To unsubscribe from this list send email to C400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: bob@cstoneindy.com
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.