473,765 Members | 2,086 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pageup/pagedown implementation using C language

Dear all,
I am in the process of implementing pageup/pagedown feature in our
consumer electronics project.The idea is to provide feature to the
customers to that similar to viewing a single sms message in a mobile
device.With in the given view area if the whole message does not
fit,we need to provide the ability for users to scroll through the
entire message using pageup/pagedown or key up and key down.In our
case we have the whole contents to be displayed stored in a buffer.I
am giving below one implementation I have tried:

Note:We are using only pure C code and dont have active x controls
like tabs or pageup/down buttons as in .NET or VC++.

#include <stdio.h>
#include "string.h"
void pageup();
void pagedown();
static int pagecounter=0;
/*bytes per page calculated by trial and error
considering the viewable area in my device*/
int bytesperpage=16 1;
int numpages=0;
int contentremainin g=0;
char* customstringcop y=NULL;
char arr[161]={0};
int main(int argc, char *argv[])
{
int totlen=0;
int pagenum=0;
char* customstring=NU LL;

char* data="Bloodshed Dev-C++ is a full-featured Integrated
Development Environment (IDE) for the C/C++ programming language. It
uses Mingw port of GCC (GNU Compiler Collec.";
char* stringdata="Blo odshed Dev-C++ is a full-featured Integrated
Development Environment (IDE) for the C/C++ programming language. It
uses Mingw port of GCC (GNU Compiler Collection) as it's compiler.
Dev-
C++ can also be used in combination with Cygwin or any other GCC based
compiler.";
char* stringdata1="th e #bloodshed channel has recently been
created on the Undernet IRC server. I will be please to talk with you
there so feel free to join :) If you want have an IRC client you can
get one for Windows at mirc.com and for Linux at xchat.org";
char* stringdata2="Yo u can subscribe to the Dev-C++ mailing list
(for asking and answering questions on Dev-C++ and C/C++ programming)
by clicking here and filling out the subscribe form there.";

totlen=strlen(s tringdata)+strl en(stringdata)+ strlen(stringda ta2);
printf("total length is %d\n",totlen);
printf("length of data is %d\n",strlen(da ta) );
customstring=(c har*)(malloc)(t otlen+4);
customstringcop y=customstring;
memset(customst ring,0,totlen+4 );

memcpy(customst ring,stringdata ,strlen(stringd ata));
customstring=cu stomstring+strl en(stringdata);
customstring[0]='\n';
customstring++;
/*printf("%s\n", stringdata);
printf("%s\n",c ustomstringcopy );*/

/*customstring[0]='\n';
customstring++; */

memcpy(customst ring,stringdata 1,strlen(string data1));
customstring=cu stomstring+strl en(stringdata1) ;
customstring[0]='\n';
customstring++;
/*printf("%s\n", stringdata1);
printf("%s\n",c ustomstringcopy );*/

memcpy(customst ring,stringdata 2,strlen(string data2));
customstring=cu stomstring+strl en(stringdata2) ;
customstring[0]='\n';
customstring++;
/* printf("%s\n",s tringdata2);*/
printf("%s\n",c ustomstringcopy );

numpages=totlen/bytesperpage;
printf("total number of pages is %d\n",numpages) ;
contentremainin g=(totlen)%(byt esperpage);
if(contentremai ning 0)
{
numpages=numpag es+1;

}
printf("total number of pages is %d\n",numpages) ;
for(pagenum=0;p agenum<=numpage s;pagenum++)
{
pageup();
}
for(pagenum=num pages;pagenum>0 ;pagenum--)
{
pagedown();
}
system("PAUSE") ;
return EXIT_SUCCESS;
}

void pageup()
{
if(pagecounter< numpages)
{
pagecounter++;
printf("pagecou nter value is %d\n",pagecount er);
memcpy(arr,cust omstringcopy,16 1);
printf("%s\n\n" ,arr);
customstringcop y=customstringc opy
+bytesperpage;
}
}

void pagedown()
{

if(pagecounter= =numpages)
{
pagecounter--;
printf("pagecou nter value is %d
\n",pagecounter );
customstringcop y=customstringc opy-2*(bytesperpage );
memcpy(arr,cust omstringcopy,16 1);
printf("%s\n\n" ,arr);
}
else
{
if(pagecounter> 1)
{
pagecounter--;
printf("pagecou nter value is %d
\n",pagecounter );
customstringcop y=customstringc opy-(bytesperpage);
memcpy(arr,cust omstringcopy,16 1);
printf("%s\n\n" ,arr);
}
}
/* if(pagecounter> 0)
{

customstringcop y=customstringc opy-
bytesperpage;
memcpy(arr,cust omstringcopy,16 1);
printf("%s\n\n" ,arr);

} */

}

Incase you find bugs in above code please let me know ways to fix it.

I believe there are much better ways then the one I have tried here.It
would be helpful if some one could provide me some sample code for
similar features you would have come across in your product or some
sample links which shows me sample code on how to implement such a
feature.

Note:I am looking for only C code and not C#,JAVA,.NET,VC ++

Looking farward for all your replies and advanced thanks for the same,
Regards,
s.subbarayan
Oct 28 '08 #1
9 3394
ssubbarayan wrote:
Dear all,
<snip>

Here's another bit of free advice - posting the same long imprecise
question three times with slightly different wording puts you on the
fast-track to the killfiles of many Usenet regulars.
Oct 28 '08 #2

"ssubbaraya n" <ss****@gmail.c omwrote in message
news:1d******** *************** ***********@e38 g2000prn.google groups.com...
Dear all,
I am in the process of implementing pageup/pagedown feature in our
consumer electronics project.The idea is to provide feature to the
customers to that similar to viewing a single sms message in a mobile
device.With in the given view area if the whole message does not
fit,we need to provide the ability for users to scroll through the
entire message using pageup/pagedown or key up and key down.In our
case we have the whole contents to be displayed stored in a buffer.I
am giving below one implementation I have tried:

Note:We are using only pure C code and dont have active x controls
like tabs or pageup/down buttons as in .NET or VC++.
I found your code as unreadable as others have suggested. Perhap
/temporarily/ use a text editor to shorten variable names then the logic
might become clearer.

I've had a go at some pageup/pagedown code. (First time I've used C for this
and was quite a painful experience, especially trying to read a single key
using standard C. If you have a choice of using a rapid development
language, then use it!)

I don't know about your display; the display here is filled up left to
right, top to bottom, without caring about splitting lines in the middle of
words, and assuming a fixed pitch font.

Also, I've split the logic into two: display the text using as input:

* The text
* A single number indicating where to start

And some logic which manipulates that number. (The example displaytext()
function just rewrites everything; probably you will want to use extra logic
to scroll most of the display where possible.)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char *text="The #bloodshed channel has recently been "
"created on the Undernet IRC server. I will be please to talk
with you"
" there so feel free to join :) If you want have an IRC client
you can"
" get one for Windows at mirc.com and for Linux at xchat.org";

#define rowchars 16 /* Chars displayed per row */
#define displayrows 4 /* Rows available on display */

int nlines; /* Lines required by entire message */
int startline; /* Current display starts at this line# (line 1 =
top) */

void displaytext(cha r *text, int nlines, int startline);

int main(void) {
char c;
int quit=0;

nlines=(strlen( text)-1)/rowchars+1;
startline=1;

while (! quit) {
displaytext(tex t,nlines,startl ine);

printf("\nPress U-Up D-Down A-Pageup B-Pagedown H-Home E-End Q-Quit then
Enter:\n");
BODGE1:
c=getc(stdin);

switch (c) {
case 'U': case 'u':
if (startline>1)
--startline;
break;

case 'D': case 'd':
if (startline<nlin es)
++startline;
break;

case 'A': case 'a':
startline-=displayrows;
if (startline<1)
startline=1;
break;

case 'B': case 'b':
startline+=disp layrows;
if (startline>nlin es)
startline=nline s-displayrows+1;
break;

case 'H': case 'h':
startline-=displayrows;
startline=1;
break;

case 'E': case 'e':
startline=nline s-displayrows+1;
break;

case 'Q': case 'q':
quit=1;
break;

default:
goto BODGE1; /* SKIP EXTRANEOUS INPUT */
}
}
}

void displaytext(cha r *text, int nlines, int startline) {
int i,j,n;

text += rowchars*(start line-1);

n = nlines-startline+1; /* Remaining lines to display */
if (n>displayrows) n=displayrows;

/* clear display */
/* ... */
puts("--------------------------");

for (i=1; i<=n; ++i) {
printf("%04d: ",startline ++);
for (j=1; j<=rowchars; ++j) {
if (!*text) {
puts("");
return;
}
printf("%c",*te xt++);
}
puts("");
}
}
--
Bartc

Oct 28 '08 #3
In article <XI************ *******@text.ne ws.virginmedia. com>,
Bartc <bc@freeuk.comw rote:
>
"ssubbarayan " <ss****@gmail.c omwrote in message
news:1d******* *************** ************@e3 8g2000prn.googl egroups.com...
>Dear all,
I am in the process of implementing pageup/pagedown feature in our
consumer electronics project.The idea is to provide feature to the
customers to that similar to viewing a single sms message in a mobile
device.With in the given view area if the whole message does not
fit,we need to provide the ability for users to scroll through the
entire message using pageup/pagedown or key up and key down.In our
case we have the whole contents to be displayed stored in a buffer.I
am giving below one implementation I have tried:

Note:We are using only pure C code and dont have active x controls
like tabs or pageup/down buttons as in .NET or VC++.

I found your code as unreadable as others have suggested. Perhap
/temporarily/ use a text editor to shorten variable names then the logic
might become clearer.
Isn't it perfectly clear that the only clc-acceptable way to do this is:

system("less");

(With, of course,all the usual extra stuff needed to make it compile and
to pass muster in CLC. And, of course, some parsing of argv[]).

Oct 28 '08 #4

"ssubbaraya n" <ss****@gmail.c omwrote in message
news:1d******** *************** ***********@e38 g2000prn.google groups.com...
Dear all,
I am in the process of implementing pageup/pagedown feature in our
consumer electronics project.The idea is to provide feature to the
customers to that similar to viewing a single sms message in a mobile
device.With in the given view area if the whole message does not
fit,we need to provide the ability for users to scroll through the
entire message using pageup/pagedown or key up and key down.In our
case we have the whole contents to be displayed stored in a buffer.I
am giving below one implementation I have tried:

Note:We are using only pure C code and dont have active x controls
like tabs or pageup/down buttons as in .NET or VC++.
You're telling me you don't have a graphical display on this 'device' but
are forced to implment it using a kind of Unix terminal?

I can't imagine a device that doesn't have a graphical color display these
days, and for that you always need libraries, such as MicroWindows or some
other free open-source GUI system. And with those, you don't need to
implement a page-up / down since they are part of the textcontrols.
Oct 28 '08 #5
On October 28, 2008 11:51, in comp.lang.c, Bresco (br****@mixmast er.org)
wrote:
>
"ssubbaraya n" <ss****@gmail.c omwrote in message
news:1d******** *************** ***********@e38 g2000prn.google groups.com...
>Dear all,
I am in the process of implementing pageup/pagedown feature in our
consumer electronics project.The idea is to provide feature to the
customers to that similar to viewing a single sms message in a mobile
device.
[snip]
You're telling me you don't have a graphical display on this 'device' but
are forced to implment it using a kind of Unix terminal?

I can't imagine a device that doesn't have a graphical color display these
days
[snip]

Then I guess that you don't own or use (and have never seen) microwave ovens
or clock-radios or computer printers or watches or mp3 players.

Your lack of imagination doesn't invalidate the OP's requirements. Instead,
it points out how little you know.
--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------
Oct 28 '08 #6
David Brown wrote:
ssubbarayan wrote:
Dear all,
<snip>

Here's another bit of free advice - posting the same long imprecise
question three times with slightly different wording puts you on the
fast-track to the killfiles of many Usenet regulars.
Google Groups went through another one of its fits. Users weren't
getting new posts displayed. Bleah.


Brian
Oct 28 '08 #7
ssubbarayan wrote:
I believe there are much better ways then the one I have tried here.
It would be helpful if some one could provide me some sample code
[...]

Here is my suggestion:

/** @file scrolltest.c */
#define DEBUG
#ifdef DEBUG
#include <stdio.h>
#endif

#define DISPLAY_CHUNK 160

/* + test data */
static char *buffer = "Long data string to be scrolled. Please note"
" there are no (char)0 elements in the string, which would allow "
"use of strcat to combine buffers. "
"If everything is in one buffer anyway, the length of the buffer is"
" known, and the chunk size of output data is fix, then just one "
"pointer to the current start position of the display is "
"sufficient . "
"The C compiler is assumed to combine separate strings into "
"one long string, so for our test we skip any special code for "
"just constructing a demo.";
/* - test data */

static int curpos;
static int minpos;
static int maxpos;
static char arr[DISPLAY_CHUNK + 1]; /* trailing (char)0 */

void update_display( ){
/* force legal start position */
if (curpos < minpos) { curpos = minpos; }
if (curpos maxpos) { curpos = maxpos; }
memcpy(arr, &buffer[curpos], DISPLAY_CHUNK);
arr[DISPLAY_CHUNK]='\0';
#ifdef DEBUG
printf("pos %d display content:\n%s\n" , curpos, arr);
#else
output_to_displ ay(arr);
#endif
}

void page_up(){
curpos -= DISPLAY_CHUNK;
update_display( );
}

void page_down(){
curpos += DISPLAY_CHUNK;
update_display( );
}

int main(int argc, char * argv[]){
/* required initialization */
curpos = 0;
minpos = 0;
maxpos = strlen(buffer) - DISPLAY_CHUNK;
/* initial output */
update_display( );
/* scroll to bottom */
while (curpos < maxpos) page_down();
/* scroll to top */
while (curpos minpos) page_up();
}
/* end of scrolltest.c **/

Have fun! :)

ssubbarayan wrote:
totlen=strlen(s tringdata)+strl en(stringdata)+ strlen(stringda ta2);
BUG: adding lengths of stringdata twice(!) plus of stringdata2
customstringcop y=customstringc opy-bytesperpage;
memcpy(arr,cust omstringcopy,16 1);
BUG: using variable for navigation but number literal for memcpy

WARNING: Variable "data" not used.

Bartc wrote:
I found your code as unreadable as others have suggested. Perhap
/temporarily/ use a text editor to shorten variable names then the
logic might become clearer.
Recommendation: GNU indent v2.2.9 (with line length set to 68 chars)
plus short variable names.
Oct 29 '08 #8
On Oct 28, 9:45*pm, "Default User" <defaultuse...@ yahoo.comwrote:
David Brown wrote:
ssubbarayan wrote:
Dear all,
<snip>
Here's another bit of free advice - posting the same long imprecise
question three times with slightly different wording puts you on the
fast-track to the killfiles of many Usenet regulars.

Google Groups went through another one of its fits. Users weren't
getting new posts displayed. Bleah.

Brian
Hi,
Yes that was the reason that thinking my question did not appear I
posted it thrice!Sorry about it.
Regards,
s.subbarayan
Oct 29 '08 #9
On Oct 28, 9:29*am, ssubbarayan <ssu...@gmail.c omwrote:
Dear all,
I am in the process of implementing pageup/pagedown feature in our
consumer electronics project.The idea is to provide feature to the
customers to that similar to viewing a single sms message in a mobile
device.With in the given view area if the whole message does not
fit,we need to provide the ability for users to scroll through the
entire message using pageup/pagedown or key up and key down.In our
case we have the whole contents to be displayed stored in a buffer.I
am giving below one implementation I have tried:

Note:We are using only pure C code and dont have active x controls
like tabs or pageup/down buttons as in .NET or VC++.
[code deleted]
>
I believe there are much better ways then the one I have tried here.It
would be helpful if some one could provide me some sample code for
similar features you would have come across in your product or some
sample links which shows me sample code on how to implement such a
feature.

Note:I am looking for only C code and not C#,JAVA,.NET,VC ++

Looking farward for all your replies and advanced thanks for the same,
Regards,
s.subbarayan
Even in C you would have some graphics libraries. The scrolling you
are looking for would be an easy application in most such libraries.
Given this is an embedded device, you may have to implement your own.
the key is to think of the different levels of abstraction. What does
scrolling mean at the topmost level? What functions would you need?
This is called top down programming.

HTH,
Ed
Oct 30 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5560
by: yihan | last post by:
Hi, I would like to make a pageUp and pageDown button to go up or down in the text ( it is like PgUp/PgDown on the keyboard). But it works on the IE but not on netscape 7.1. Could somebody tell me the problem? Thanks. The code as below: <HTML> <style type="text/css"> <!-- body
1
2005
by: Harald Solvberg | last post by:
I want a datagrid object that will not intercept PageUp or PageDown keystrokes so that instead the tabcontrol it's on can pick it them up and change TabPages. Any idea how to create a new version of the datagrid that will do this?
0
1207
by: nm | last post by:
I'm using the Web Browser control in my app and notice that when I enter a new URL to view via text box, then give focus to the browser control, I can't page up or down within the browser until I click on it with the mouse, then I can page up/down. How can I programmatically accomplish this without having to click the mouse? -nm
2
4174
by: Phil Galey | last post by:
I have a Panel control docked on all sides on a form and the panel control contains a PictureBox. I'm using the KeyDown event of the form to respond to the and keys for resizing the image and the PageUp, PageDn, Home, End, and arrow keys for scrolling the Panel control. Resizing the image using the and keys works fine, deriving a resized thumbnail from the image and reassigning it to the Image property of the PictureBox. However I'm...
0
1224
by: =?Utf-8?B?SGFyYWxk?= | last post by:
I have a datagrid on a tabcontrol and want PageUp and PageDown to change tabs on the tabcontrol but when on the datagrid the keystrokes get captured by the datagrid. I've created my own datagrid object from the base object in order to override ProcessCmdKey and am able to capture the keystroke however my problem is how to pass that onto the tabcontrol or form. I do this in many places (forms) and therefore need a solution that allows the...
2
2859
by: ssubbarayan | last post by:
Dear all, I am in the process of implementing pageup/pagedown feature in our consumer electronics project.The idea is to provide feature to the customers to that similar to viewing a single sms message in a mobile device.With in the given view area if the whole message does not fit,we need to provide the ability for users to scroll through the entire message using pageup/pagedown or key up and key down.In our case we have the whole...
27
2020
by: ssubbarayan | last post by:
Hi all, I am looking for some sample code which shows how to implement pageup/ pagedown feature using C language similar to the ones we encounter in our mobile devices.In mobiles if we dont have enough view space to show entire content of single message,we provide the feature to do key up/key dn or pageup/pagedn.I have tried a similar code here given below,I would appreciate if some one could give me sample code or links regarding...
0
9566
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9393
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10153
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8830
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7371
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6646
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5272
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2800
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.