pageup/pagedwn implementation

S

ssubbarayan

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 implementing this feature in embedded devices using C
language only.


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


void pageup();
void pagedown();
static int pagecounter=0;
int bytesperpage=161;
int numpages=0;
int contentremaining=0;
char* customstringcopy=NULL;
char arr[161]={0};
int main(int argc, char *argv[])
{
int totlen=0;
int pagenum=0;


char* customstring=NULL;

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="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 Collection) as it's compiler. Dev-
C++ can also be used in combination with Cygwin or any other GCC based
compiler.";
char* stringdata1="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";
char* stringdata2="You 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(stringdata)+strlen(stringdata)+strlen(stringdata2);
printf("total length is %d\n",totlen);
printf("length of data is %d\n",strlen(data) );
customstring=(char*)(malloc)(totlen+4);
customstringcopy=customstring;
memset(customstring,0,totlen+4);

memcpy(customstring,stringdata,strlen(stringdata));
customstring=customstring+strlen(stringdata);
customstring[0]='\n';
customstring++;
/*printf("%s\n",stringdata);
printf("%s\n",customstringcopy);*/

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

memcpy(customstring,stringdata1,strlen(stringdata1));
customstring=customstring+strlen(stringdata1);
customstring[0]='\n';
customstring++;
/*printf("%s\n",stringdata1);
printf("%s\n",customstringcopy);*/

memcpy(customstring,stringdata2,strlen(stringdata2));
customstring=customstring+strlen(stringdata2);
customstring[0]='\n';
customstring++;
/* printf("%s\n",stringdata2);*/
printf("%s\n",customstringcopy);

numpages=totlen/bytesperpage;
printf("total number of pages is %d\n",numpages);
contentremaining=(totlen)%(bytesperpage);
if(contentremaining > 0)
{
numpages=numpages+1;

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

void pageup()
{


if(pagecounter<numpages)
{
pagecounter++;
printf("pagecounter value is %d\n",pagecounter);
memcpy(arr,customstringcopy,161);
printf("%s\n\n",arr);
customstringcopy=customstringcopy
+bytesperpage;
}


}

void pagedown()
{

if(pagecounter==numpages)
{
pagecounter--;
printf("pagecounter value is %d
\n",pagecounter);
customstringcopy=customstringcopy-2*(bytesperpage);
memcpy(arr,customstringcopy,161);
printf("%s\n\n",arr);
}
else
{
if(pagecounter>1)
{
pagecounter--;
printf("pagecounter value is %d
\n",pagecounter);
customstringcopy=customstringcopy-(bytesperpage);
memcpy(arr,customstringcopy,161);
printf("%s\n\n",arr);
}


}
/* if(pagecounter>0)
{

customstringcopy=customstringcopy-
bytesperpage;
memcpy(arr,customstringcopy,161);
printf("%s\n\n",arr);

} */

}

Looking farward for your replies and advanced thanks for the same,
Regards,
s.subbarayan
 
D

David Brown

ssubbarayan said:
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 implementing this feature in embedded devices using C
language only.
<snip>

I don't think you'll get much help here. First off, no one is going to
wade through that code finding bugs for you - that's *your* job, and the
job of your colleagues. Secondly, it doesn't look like a hard task - if
you can't get this right, you're in the wrong job.

However, I'll give you some free general advice. The compiler doesn't
care what your code looks like, but other people (including yourself)
*do* - write legible code!

The biggest step here is to find the "space" bar - it's the great big
key at the bottom of your keyboard. When writing text (such as these
posts), there should always be two spaces at the end of a sentence, and
one after other punctuation (such as a comma).

In C, put spaces around operators (except "*", "&", "++" and "--"),
after commas, and after keywords (but not after an open bracket, or
after a function name). There are a few variations in style rules, but
these examples show a reasonable set:

memset(customstring, 0, totlen + 4);
customstring = customstring + strlen(stringdata1);
for (pagenum = 0; pagenum <= numpages; pagenum++) {
pageup();
}

Avoid names like "customstringcopy" - they are horrible to read. Where
practical, avoid global names in preference for local names, which can
be shorter (and clearer) without conflicts. If you *do* have to use a
long name, write it as "customStringCopy" or "custom_string_copy" - it's
much easier to read.
 
R

Richard Bos

David Brown said:
I don't think you'll get much help here. First off, no one is going to
wade through that code finding bugs for you - that's *your* job, and the
job of your colleagues. Secondly, it doesn't look like a hard task - if
you can't get this right, you're in the wrong job.

However, I'll give you some free general advice. The compiler doesn't
care what your code looks like, but other people (including yourself)
*do* - write legible code!

And do note that if you think you can read you code, because after all
you've written it yourself - consider what will happen when you come
back to that program half a year from now, to add another option.
The biggest step here is to find the "space" bar - it's the great big
key at the bottom of your keyboard. When writing text (such as these
posts), there should always be two spaces at the end of a sentence, and
one after other punctuation (such as a comma).

Wrong. Two spaces after a full stop is a habit in the USA, where people
didn't learn to write until the typewriter was invented and haven't got
any more culture since we started using word processors. In the
civilised world, it's one full stop, one space.

Richard
 
J

jameskuyper

Richard said:
Wrong. Two spaces after a full stop is a habit in the USA, where people
didn't learn to write until the typewriter was invented and haven't got
any more culture since we started using word processors. In the
civilised world, it's one full stop, one space.

<http://en.wikipedia.org/wiki/French_spacing> suggests a much more
complicated history, one that is incompatible with yours (and
completely lacking in ridiculously stupid gratuitous insults). If you
know that the Wikipedia history is inaccurate, I'd recommend making
some edits.
 
C

CBFalconer

William said:
.... snip ...

try using:

memset( customstring, 0, totlen + 4 );
customstring = customstring + strlen( stringdata1 );
for( pagenum = 0; pagenum <= numpages; pagenum++ ) {
pageup();
}

Actually, IMO you should put the space after the 'for'. for is NOT
a function name, and this practice distinguishes functions from
reserved words or functional macros. It also avoids any need for a
space AFTER the '('.

This makes the above appear as:

for (pagenum = 0; pagenum <= numpages; pagenum++) {
pageup();
}
 
C

CBFalconer

Richard said:
.... snip ...


Wrong. Two spaces after a full stop is a habit in the USA, where
people didn't learn to write until the typewriter was invented and
haven't got any more culture since we started using word processors.
In the civilised world, it's one full stop, one space.

I mildly disagree. However, I do abhor people who can't insert at
least one space after a punctuation mark.

Incidentally, anything done to clarify typewritten verbiage
certainly applies to Usenet. Why do rabid classicists want to
reduce the accuracy of reading? :)
 
J

jellybean stonerfish

I'm not sure about rabid classicists, but I think some Usenet posters
(particularly various net.kooks) try subconsciously to reduce the
accuracy of reading as a means to mask the low quality of the content:
the more nonsensical the ideas being presented, the worse the formatting
seems to get. Perhaps it's not causal, but there seems to be a
correlation...

People that have a hard time communicating in written form will have
content problems, as well as syntax and form problems. It is because of
lack of ability, not attempts to cover up lack of content.

stonerfish
 
A

Andrew Smallshaw

Actually, IMO you should put the space after the 'for'. for is NOT
a function name, and this practice distinguishes functions from
reserved words or functional macros. It also avoids any need for a
space AFTER the '('.

This makes the above appear as:

for (pagenum = 0; pagenum <= numpages; pagenum++) {
pageup();
}

I tend to adopt the same convention, that is a space after an if,
while etc but not after a function name. However I long since
learned that it isn't worth arguing such points because you never
get anywhere. If you were to be pedantic you could easily argue
that I'm inconsistent because I don't use a space after sizeof -
this reflects my view of sizeof as a pseudofunction rather than a
proper language construct like the other keywords.

The only really important things are that usage is at least reasonably
consistent, there is enough whitespace in there somewhere that you
can see the structure of the code, and in particular that indentation
is not actively misleading.
 
R

Richard Bos

jameskuyper said:
<http://en.wikipedia.org/wiki/French_spacing> suggests a much more
complicated history, one that is incompatible with yours (and
completely lacking in ridiculously stupid gratuitous insults).

A page that starts by pointing out that its own title is actually wrong?
Why should I assume that anything else on it is correct?

Meanwhile, I do actually own books in at least six languages, and some
time ago I made the effort of actually _checking this_. Gosh, wow, facts
intruding in a discussion. How gauche... but nevertheless, I did. Only
three books did have two spaces after a full stop, and those were
"typeset" in either troff or TeX - and the rest of the typography was
just as dire. (Yes, K&R2 was one. If only they'd gone to the effort of
making the design of their book read good as the text.)
All other books I own - from six different countries at least, from
dates throughout last century and even before - do not have these double
spaces. In some cases, it may look as if they did, but if you take the
trouble of measuring it (remember that famous programming adagium? Don't
rely on guesswork, _measure_!) it becomes clear that this is a visual
deception, most likely due to the capital which starts the next sentence
not being kerned.
Do the test: open a random book with real (_not_ troff) typography, and
check the difference between ". R" and ". A" or ". T". You'll notice a
_visually_ larger gap between the latter than between the former. If you
put a ruler next to them, though, you'll see that the space is the same,
and it's only the extra internal white in the A and T which makes it
look larger.
If you know that the Wikipedia history is inaccurate, I'd recommend
making some edits.

Why engage in such a futile exercise? Let the facts speak for
themselves, and let the Pikiwediasts argue amongst themselves.

Richard
 
R

Richard Bos

David Brown said:
No, two spaces after a full stop is a habit for good typewriting style
in all Latin alphabet languages (including American as well as English).

Then do please explain why I've hardly ever seen anyone but a USAlien
advocate double spacing full stops, and _never_ anyone in any other
language but English.
Using just one space after a full stop is a habit from when amateurs

Simply wrong. Professionals (and yes, I work for a publisher, so I know
a handful of those) never use two spaces - at least, not outside the
USA.

Richard
 
R

Ross A. Finlayson

Richard said:
Then do please explain why I've hardly ever seen anyone but a USAlien
advocate double spacing full stops, and _never_ anyone in any other
language but English.


Simply wrong. Professionals (and yes, I work for a publisher, so I know
a handful of those) never use two spaces - at least, not outside the
USA.

Richard

No, every sentence ends with two stops.

That's just the way it is.

Thanks,

Ross F.
 
J

James Kuyper

Richard said:
A page that starts by pointing out that its own title is actually wrong?

The title is "Double spaced sentences". That title makes no assertions,
and correctly describes what the page is about. What are you talking
referring to?

The URL for that page ends in French_spacing. One of the first things
the page discusses is the fact that the term "french spacing" has become
a popular term for double spacing, despite being historically
inaccurate. Is that what you're referring to? But French_spacing isn't
the title - it's the URL.
Why should I assume that anything else on it is correct?

As a general rule, I find that texts which contain such disclaimers tend
to be more accurate than those which do not. Such disclaimers usually
indicate someone paying more than the usual amount of attention to detail.

However, I wouldn't recommend assuming that anything that article says
is correct; any more than you should make that same assumption about any
other source of information. If you have any interest in the subject,
and doubts about the accuracy of that article, I'd recommend following
the traditional approach to verifying the accuracy of that article, by
tracking down the citations in the bibliography. There's 67 of them,
plenty to choose from.
Meanwhile, I do actually own books in at least six languages, and some
time ago I made the effort of actually _checking this_.

The main conflict between your brief statement and the wikipedia article
is that you claim double spacing as an American habit; presumably one we
still practice, though you're not entirely clear on that point. The
wikipedia article identifies double spacing as a British invention that
has since gone out of style, even in Britain. Since "habit" and
"invention" are two very different things, even that conflict is less
than perfectly clear.

The wikipedia article identifies the invention of the typewriter as a
key event in the adoption of this practice; you mention the typewriter,
but it's not entirely clear whether you're implying a causal connection,
or merely mentioning it as part of your tirade about how stupid
Americans are.

Relevant evidence for distinguishing between your assertions and the
ones made in the Wikipedia article would have to distinguish between
British and American texts, would have to include both typeset and
typewritten texts, and would have to include typeset texts from before
the typewriter was invented. I couldn't check this out using my book
collection; while it includes about 2000 books, almost all of them were
typeset in the US, and all of them were typeset after the invention of
the typewriter. Books typeset before that invention are mostly
collector's items, and I'm not that type of a collector. The sample I've
looked at this morning didn't include any with double spacing after
sentences, which provides no support for your assertion that this is an
American habit.

The evidence you describe involves only typeset books, does not
distinguish American and British sources, does not distinguish between
texts written before and after the invention of the typewriter. It's not
a very useful study for resolving this issue.
 
B

Ben Bacarisse

jameskuyper <[email protected]> wrote:

A page that starts by pointing out that its own title is actually wrong?
Why should I assume that anything else on it is correct?

Meanwhile, I do actually own books in at least six languages, and some
time ago I made the effort of actually _checking this_. Gosh, wow, facts
intruding in a discussion. How gauche... but nevertheless, I did. Only
three books did have two spaces after a full stop, and those were
"typeset" in either troff or TeX - and the rest of the typography was
just as dire.

That will tell you about the books you happen to have, not about the
history of this notion. To verify that it is not a fiction, you need
to have a book in English, published in the UK or the USA, sometime
between roughly the middle of the 19th and 20th centuries. The only
two I have to hand are an OED (1955 reprint of the 1933 edition) and a
Shakespeare (1903 but reset in 1943). Both show the fashion for wider
space after a full stop, though not the "full quad" suggested by
typographers of the late 19th century.

The habit got incorporated into typing simply because it was in
fashion when typing started. I can't say anything about French habits
at that time since I don't have books published in France at the right
date.
 
C

CBFalconer

Grant said:
Nobody claimed that the "two spaces after a full stop" applied
to typeset material. It was a rule meant for typewritten
material where there was only a single, fixed-width, space.

However, let me point out that Usenet messages, written according
to the appropriate protocols, are using fixed width fonts with
fixed width spaces. The critical thing is not the 'typewriter',
but the physical appearance of the end product.
 
D

Dik T. Winter

> (e-mail address removed) (Richard Bos) writes: ....
>
> That will tell you about the books you happen to have, not about the
> history of this notion. To verify that it is not a fiction, you need
> to have a book in English, published in the UK or the USA, sometime
> between roughly the middle of the 19th and 20th centuries.

I have been checking and found two reports from the National Physical
Laboratory, dated 1980 en 1982. The major advantage is that these are
written using a monospace font and not all text is right justified. They
both contain only a single space after the full stop. I can not get
my hands currently on older reports because this institute is in the
middle of a renovation/new building, and so the library works only in
part.

Other features: no space before punctuation, punctuation after a closing
quotation mark if the punctuation is not part of the quote, etc..
 
C

Charlton Wilbur

CBF> However, let me point out that Usenet messages, written
CBF> according to the appropriate protocols, are using fixed width
CBF> fonts with fixed width spaces.

Cite an RFC that tells me it is incorrect to display my messages in
Times New Roman, please.

Charlton
 
B

Bartc

The title is "Double spaced sentences". That title makes no assertions,
and correctly describes what the page is about. What are you talking
referring to?
the typewriter was invented. I couldn't check this out using my book
collection; while it includes about 2000 books, almost all of them were
typeset in the US, and all of them were typeset after the invention of the
typewriter. Books typeset before that invention are mostly collector's
items, and I'm not that type of a collector.

If it's any help, I have a book typeset and printed in England around 1720.

The gap between sentences (between a full-stop and the first word of the
next sentence) seems two or three times as wide as a normal space.
 
C

CBFalconer

Charlton said:
Cite an RFC that tells me it is incorrect to display my messages
in Times New Roman, please.

I can't pick one out, but believe it exists. You may wish to read,
with care, rfc2822.txt, rfc2821.txt, rfc1036s.txt, rfc822.txt. I
believe that 'ASCII' is also specified. MIME is a different
matter, but does not apply to Usenet.
 
D

Didi

    CBF> However, let me point out that Usenet messages, written
    CBF> according to the appropriate protocols, are using fixed width
    CBF> fonts with fixed width spaces.

Cite an RFC that tells me it is incorrect to display my messages in
Times New Roman, please.

This is one of the few "usenet is/is not that" messages of Chuck with
real practical value.
I am sure you know using fixed (same for all characters) character
width
allows one to draw simple graphics which will be lost with
proportional
fonts. Legacy from the times when terminals had character generators,
each cell say 12x8 pixels (I still emulate that at more places than I
care to remember :) ).

Didi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top