[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c

variable-length strings

Uno

6/1/2011 9:37:00 AM

Hello from the land of enchantment,

I begin a crosspost herewith that I hope to make relevant to the
newsgroups listed. It will take some time to get to there from here, but
the ambition is to make it relatively lean with the topicality of each
ng addressed and respected. I am OP; if that's a problem for you, I'd
like you to move on graciously.

It begins with perl, which I am currently reading. So that's gonna be
q1). There will be more questions in the same format, and I would like
to make you aware of that as you consider an editorial choice. OP
suggests editorial choices that derive from the questions, that is, are
trimmed with respect to q.

$ pwd
/media/KINGSTON
$ perl marni3.pl
death
$ cat marni3.pl
#!/usr/bin/perl -w
use Net::FTP;
my $domain = 'www.merrillpjensen.com';
my $username = 'u61210220';
my $password = '';
my $file = 'jac1.avi';


$ftp = Net::FTP->new($domain) or die "Can't connect: $@\n";
$ftp->login($username, $password) or die "Couldn't login\n";

$ftp->cwd('/wsb6326330301/resources/') or die "death $@\n";
$ftp->put($file) or die "put failed ", $ftp->message;

$

q1) Why did I die?

I had a very successful day. I could show it, except that I'm unable to
communicate well with the internet. This is usually the case when I try
to extend my ubuntu capability. I have something that hangs that
wouldn't under a more firmly-established identity.

q2) [I imagine that I have a distinct question for each listed ng] In
testing, I've noticed a difference in file sizes between what I upload
with ftp and what I download. The files are 60 megs, conceived by
apple, and I can't show what I'm saying until I get ftp working.

There's no way I can look at these files with a hex editor and my eyes.
Doesn't unix have a built-in way to compare them?

q3)

a) Is there some newsgroup out there that considers web design, and not
the kind where you have to give them money for their opinion. If I paid
$40 for usenet advice, it might be worse than what a hooker on central
might do; it's given by people who want to make $40 on usenet.

alt.web.css.embedded.object.rus ?

q4) and then the good people of c.l.c. It looks like your tone has
come a long way. Down the road I'd like to consider how to pass
information which is perl input to fortran output using the iso c binding.

Cheers,
--
Uno
50 Answers

George Mpouras

6/1/2011 2:02:00 PM

0

try to change the connection line to

$ftp = Net::FTP->new($domain, Debug=>1, Passive=>1)


ccc31807

6/1/2011 2:14:00 PM

0

On Jun 1, 5:36 am, Uno <U...@example.invalid> wrote:
> q1)  Why did I die?

The simplest place to start is with your command line ftp program. If
you can connect and transfer files with your command line ftp, then IN
THEORY you should be able to put the same series of commands in a
batch file (i.e., a Perl script) and run them. If you can do that,
then you have all the functionality you neet./


> q2) [I imagine that I have a distinct question for each listed ng]  In
> There's no way I can look at these files with a hex editor and my eyes.
>   Doesn't unix have a built-in way to compare them?

On Unix/Linux, use diff. If you are comfortable with vi/vim, it also
has a diff capability.

> q3)
>
> a)  Is there some newsgroup out there that considers web design, and not
> the kind where you have to give them money for their opinion.  If I paid
> $40 for usenet advice, it might be worse than what a hooker on central
> might do; it's given by people who want to make $40 on usenet.

Sorry, but you need to rephrase your question, as this does not make
sense to me.

> q4)  and then the good people of c.l.c.  It looks like your tone has
> come a long way.  Down the road I'd like to consider how to pass
> information which is perl input to fortran output using the iso c binding.

Data is data. You can use Perl to manipulate and format data. In fact,
PERL (in the opinion of some, anyway) stands for Practical Extraction
and Reporting Language.

CC.

Peter J. Holzer

6/2/2011 1:34:00 PM

0

["Followup-To:" header set to comp.lang.perl.misc.]
On 2011-06-01 09:36, Uno <Uno@example.invalid> wrote:
> $ perl marni3.pl
> death
> $ cat marni3.pl
> #!/usr/bin/perl -w
> use Net::FTP;
> my $domain = 'www.merrillpjensen.com';
> my $username = 'u61210220';
> my $password = '';
> my $file = 'jac1.avi';
>
>
> $ftp = Net::FTP->new($domain) or die "Can't connect: $@\n";
> $ftp->login($username, $password) or die "Couldn't login\n";
>
> $ftp->cwd('/wsb6326330301/resources/') or die "death $@\n";
> $ftp->put($file) or die "put failed ", $ftp->message;
>
> $
>
> q1) Why did I die?

Simple answer: Because you couldn't change the current working directory
to '/wsb6326330301/resources/'.

As to why that didn't work, the Net::FTP module would tell you if you
asked it. Read the synopsis of perldoc Net::FTP for a few examples on
printing proper error messages.

hp

Peter J. Holzer

6/2/2011 1:45:00 PM

0

["Followup-To:" header set to comp.unix.shell.]
On 2011-06-01 09:36, Uno <Uno@example.invalid> wrote:
> q2) [I imagine that I have a distinct question for each listed ng] In
> testing, I've noticed a difference in file sizes between what I upload
> with ftp and what I download. The files are 60 megs, conceived by
> apple, and I can't show what I'm saying until I get ftp working.
>
> There's no way I can look at these files with a hex editor and my eyes.
> Doesn't unix have a built-in way to compare them?

There's cmp, but it only shows you where the first difference is.

There's diff, but it is intended for text files.

You could convert both files with od or hd and diff those. But that
doesn't work well.

I think Emacs has a binary-diff mode, but I'm from the vi fraction.

So, back in the mid 1990's I wrote bdiff (binary diff):
http://www.hjp.at/progr...

I guess I should dust it off, write a man-page and try to get it added
to some linux distribution. But I very rarely need it myself.

hp

Uno

6/2/2011 4:55:00 PM

0

On 06/01/2011 08:13 AM, ccc31807 wrote:
> On Jun 1, 5:36 am, Uno<U...@example.invalid> wrote:
>> q1) Why did I die?
>
> The simplest place to start is with your command line ftp program. If
> you can connect and transfer files with your command line ftp, then IN
> THEORY you should be able to put the same series of commands in a
> batch file (i.e., a Perl script) and run them. If you can do that,
> then you have all the functionality you neet./

I needed a fresh day and fresh eyes, and t set Debug=> 2 to see that the
wsb "web site builder" number was wrong. That's a separate directory
that my host uses for when they build the website. I want to adios this
thing, so I called them, and they have you change an administrative
setting so that a browser will be directed to the index.html in the root
menu as opposed to in the wsb folder.

So now this /wsb.../ thing is a relic for me to play with and destroy.
Why didn't this work:

[sorry can only paste as quotation:]

> $ perl marni5.pl
> Net::FTP>>> Net::FTP(2.77)
> Net::FTP>>> Exporter(5.63)
> Net::FTP>>> Net::Cmd(2.29)
> Net::FTP>>> IO::Socket::INET(1.31)
> Net::FTP>>> IO::Socket(1.31)
> Net::FTP>>> IO::Handle(1.28)
> Net::FTP=GLOB(0xa07a7d8)<<< 220 FTP Server ready.
> Net::FTP=GLOB(0xa07a7d8)>>> USER u61210220
> Net::FTP=GLOB(0xa07a7d8)<<< 331 Password required for u61210220
> Net::FTP=GLOB(0xa07a7d8)>>> PASS ....
> Net::FTP=GLOB(0xa07a7d8)<<< 230 User u61210220 logged in
> Net::FTP=GLOB(0xa07a7d8)>>> RMD /wsb6121022001/
> Net::FTP=GLOB(0xa07a7d8)<<< 550 /wsb6121022001/: Directory not empty
> Net::FTP=GLOB(0xa07a7d8)>>> PORT 192,168,0,64,142,193
> Net::FTP=GLOB(0xa07a7d8)<<< 200 PORT command successful
> Net::FTP=GLOB(0xa07a7d8)>>> NLST /wsb6121022001/
> Net::FTP=GLOB(0xa07a7d8)<<< 150 Opening ASCII mode data connection for file list
> Net::FTP=GLOB(0xa07a7d8)<<< 226 Transfer complete
> Net::FTP=GLOB(0xa07a7d8)>>> DELE /wsb6121022001/.
> Net::FTP=GLOB(0xa07a7d8)<<< 550 /wsb6121022001/.: Is a directory
> Net::FTP=GLOB(0xa07a7d8)>>> RMD /wsb6121022001/.
> Net::FTP=GLOB(0xa07a7d8)<<< 550 /wsb6121022001/.: Directory not empty
> Net::FTP=GLOB(0xa07a7d8)>>> PORT 192,168,0,64,186,213
> Net::FTP=GLOB(0xa07a7d8)<<< 200 PORT command successful
> Net::FTP=GLOB(0xa07a7d8)>>> NLST /wsb6121022001/.
> Net::FTP=GLOB(0xa07a7d8)<<< 150 Opening ASCII mode data connection for file list
> Net::FTP=GLOB(0xa07a7d8)<<< 226 Transfer complete

....

it just keeps on telling me Directory not empty
> ^C
> $ cat marni5.pl
> #!/usr/bin/perl -w
> use Net::FTP;
> my $domain = 'www.merrillpjensen.com';
> my $username = 'u61210220';
> my $password = '';
>
> $ftp = Net::FTP->new($domain, Debug => 2) or die "Can't connect: $@\n";
> $ftp->login($username, $password) or die "Couldn't login\n";
>
> my $recurse = 1;
> $ftp->rmdir('/wsb6121022001/', $recurse);
> #$ftp->cwd('/wsb6121022001/') or die "death $@\n";
>
> my @file = $ftp->ls();
>
> foreach $file (@file){
> print "$file\n";
> }
> $

Cpan says that RECURSE has to be true, and I thought a good guess for
"true" in a syntax that is a child of C would be one.

>
>> q2) [I imagine that I have a distinct question for each listed ng] In
>> There's no way I can look at these files with a hex editor and my eyes.
>> Doesn't unix have a built-in way to compare them?
>
> On Unix/Linux, use diff. If you are comfortable with vi/vim, it also
> has a diff capability.

Thx, ccc, I'll do that. Here's what's vexing me right now.

http://www.merrillpjensen.com/image...

The only difference between these files, is that the smaller one went on
a round on the internet. It was sent up like this:

> #!/usr/bin/perl -w
> use strict;
> use Net::FTP;
> my $domain = 'www.merrillpjensen.com';
> my $username = 'u61210220';
> my $password = '';
> my $file = 'jac1.bmp';
> my $dir = '/images/';
>
> my $ftp = Net::FTP->new($domain, Debug =>2) or die "Can't connect: $@\n";
> $ftp->login($username, $password) or die "Couldn't login\n";
> $ftp->mkdir($dir) or die "death: $@\n";
> $ftp->cwd($dir) or die "death: $@\n";
> $ftp->put($file) or die "put failed ", $ftp->message;

And downloaded using google chrome. Is this typical, because if my
experience is, then I don't really see how any large file gets
transferred faithfully.

Gotta go pull down some legal tender. Adios.
--
Uno


Uno

6/9/2011 3:59:00 AM

0

On 06/04/2011 02:52 AM, Peter J. Holzer wrote:
> On 2011-06-04 04:58, Uno<Uno@example.invalid> wrote:
>> On 06/02/2011 07:44 AM, Peter J. Holzer wrote:
>>> So, back in the mid 1990's I wrote bdiff (binary diff):
>>> http://www.hjp.at/progr...
>>>
>>> I guess I should dust it off, write a man-page and try to get it added
>>> to some linux distribution. But I very rarely need it myself.
> [...]
>> So I downloaded your software, extracted it on a thumbdrive, compiled
>> it, told ubuntu to run it, and it told me I don't have permission.
>>
>> $ sudo chmod 777 bdiff
>> $ ls -l
>>
>> -rw-r--r-- 1 dan dan 12414 2011-06-02 16:29 bdiff
>>
>> That was my last try with that executable. So I tried it again.
>>
>> $ pwd
>> /media/KINGSTON/bdiff-1.0
> ^^^^^^^^^^^^^^^^
>
> What kind of file system is this and how is it mounted?
>
>> $ cc -Wall -Wextra bdiff.c -o bdiff2
>> bdiff.c: In function â??readfileâ??:
>> bdiff.c:98: warning: comparison between signed and unsigned integer
>> expressions
>
> The warnings are harmless, AFAICS, and partially misleading (comparison
> between size_t and -1 is well-defined as long as sizeof(size_t)>=
> sizeof(int), which is pretty much guaranteed).
>
> hp

I want to pursue this on the C side for a bit. [x-posted to clc]

$ pwd
/home/dan/source/bdiff-1.0
$ cc -Wall -Wextra cmp1.c -o cmp
cmp1.c: In function â??mainâ??:
cmp1.c:12: warning: comparison is always true due to limited range of
data type
cmp1.c:17: warning: implicit declaration of function â??closeâ??
cmp1.c:18: error: expected declaration or statement at end of input
$ cat cmp1.c

#include <stdio.h>

int main(void)
{
unsigned char c;
long counter = 0;
FILE *fp;

fp=fopen("shoulder.wmv", "rb+");

while ((c = fgetc(fp)) != EOF)
{
counter++;
}
printf("Counter reached %ld\n", counter);
close (fp);
return 0;
// cc -Wall -Wextra cmp1.c -o cmp
$

What obvious thing am I missing here?
--
Uno

Ian Collins

6/9/2011 4:08:00 AM

0

On 06/ 9/11 03:59 PM, Uno wrote:
>
> I want to pursue this on the C side for a bit. [x-posted to clc]
>
> $ pwd
> /home/dan/source/bdiff-1.0
> $ cc -Wall -Wextra cmp1.c -o cmp
> cmp1.c: In function â??mainâ??:
> cmp1.c:12: warning: comparison is always true due to limited range of
> data type
> cmp1.c:17: warning: implicit declaration of function â??closeâ??
> cmp1.c:18: error: expected declaration or statement at end of input
> $ cat cmp1.c
>
> #include<stdio.h>
>
> int main(void)
> {
> unsigned char c;
> long counter = 0;
> FILE *fp;
>
> fp=fopen("shoulder.wmv", "rb+");
>
> while ((c = fgetc(fp)) != EOF)

I'm guessing this is line 12. fgetc returns an int. EOF is an integer
constant.

> {
> counter++;
> }
> printf("Counter reached %ld\n", counter);
> close (fp);

You are missing <unistd.h>. If you had included it, your compile would
have failed. close works with a file descriptor, not a FILE*.

> return 0;

Missing } ?

--
Ian Collins

Uno

6/9/2011 4:21:00 AM

0

On 06/08/2011 10:08 PM, Ian Collins wrote:
> On 06/ 9/11 03:59 PM, Uno wrote:
>>
>> I want to pursue this on the C side for a bit. [x-posted to clc]
>>
>> $ pwd
>> /home/dan/source/bdiff-1.0
>> $ cc -Wall -Wextra cmp1.c -o cmp
>> cmp1.c: In function â??mainâ??:
>> cmp1.c:12: warning: comparison is always true due to limited range of
>> data type
>> cmp1.c:17: warning: implicit declaration of function â??closeâ??
>> cmp1.c:18: error: expected declaration or statement at end of input
>> $ cat cmp1.c
>>
>> #include<stdio.h>
>>
>> int main(void)
>> {
>> unsigned char c;
>> long counter = 0;
>> FILE *fp;
>>
>> fp=fopen("shoulder.wmv", "rb+");
>>
>> while ((c = fgetc(fp)) != EOF)
>
> I'm guessing this is line 12. fgetc returns an int. EOF is an integer
> constant.
>
>> {
>> counter++;
>> }
>> printf("Counter reached %ld\n", counter);
>> close (fp);
>
> You are missing <unistd.h>. If you had included it, your compile would
> have failed. close works with a file descriptor, not a FILE*.
>
>> return 0;
>
> Missing } ?
>

Thx, Ian.

$ cc -Wall -Wextra cmp2.c -o cmp
$ ./cmp
Counter reached 19573712
$ ls -l
....
-rw-r--r-- 1 dan dan 19573712 2011-06-05 17:32 shoulder.wmv
$ cat cmp2.c

#include <stdio.h>

int main(void)
{
int c;
long counter = 0;
FILE *fp;

fp=fopen("shoulder.wmv", "rb+");

while ((c = fgetc(fp)) != EOF)
{
counter++;
}
printf("Counter reached %ld\n", counter);
fclose (fp);
return 0;
}
// cc -Wall -Wextra cmp2.c -o cmp
$

I guess I thought with counter starting at zero that the numbers
wouldn't agree exactly, but they do.

It's a weird night here in abq; I'm gonna go out and howl at the orange
moon.
--
Uno

Uno

6/9/2011 8:57:00 AM

0

On 06/08/2011 10:20 PM, Uno wrote:
> On 06/08/2011 10:08 PM, Ian Collins wrote:
>> On 06/ 9/11 03:59 PM, Uno wrote:
>>>
>>> I want to pursue this on the C side for a bit. [x-posted to clc]
>>>
>>> $ pwd
>>> /home/dan/source/bdiff-1.0
>>> $ cc -Wall -Wextra cmp1.c -o cmp
>>> cmp1.c: In function â??mainâ??:
>>> cmp1.c:12: warning: comparison is always true due to limited range of
>>> data type
>>> cmp1.c:17: warning: implicit declaration of function â??closeâ??
>>> cmp1.c:18: error: expected declaration or statement at end of input
>>> $ cat cmp1.c
>>>
>>> #include<stdio.h>
>>>
>>> int main(void)
>>> {
>>> unsigned char c;
>>> long counter = 0;
>>> FILE *fp;
>>>
>>> fp=fopen("shoulder.wmv", "rb+");
>>>
>>> while ((c = fgetc(fp)) != EOF)
>>
>> I'm guessing this is line 12. fgetc returns an int. EOF is an integer
>> constant.
>>
>>> {
>>> counter++;
>>> }
>>> printf("Counter reached %ld\n", counter);
>>> close (fp);
>>
>> You are missing <unistd.h>. If you had included it, your compile would
>> have failed. close works with a file descriptor, not a FILE*.
>>
>>> return 0;
>>
>> Missing } ?
>>
>
> Thx, Ian.
>
> $ cc -Wall -Wextra cmp2.c -o cmp
> $ ./cmp
> Counter reached 19573712
> $ ls -l
> ...
> -rw-r--r-- 1 dan dan 19573712 2011-06-05 17:32 shoulder.wmv
> $ cat cmp2.c
>
> #include <stdio.h>
>
> int main(void)
> {
> int c;
> long counter = 0;
> FILE *fp;
>
> fp=fopen("shoulder.wmv", "rb+");
>
> while ((c = fgetc(fp)) != EOF)
> {
> counter++;
> }
> printf("Counter reached %ld\n", counter);
> fclose (fp);
> return 0;
> }
> // cc -Wall -Wextra cmp2.c -o cmp
> $
>
> I guess I thought with counter starting at zero that the numbers
> wouldn't agree exactly, but they do.
>
> It's a weird night here in abq; I'm gonna go out and howl at the orange
> moon.

I'm stuck again, so that's the night. I don't see why this wouldn't
traverse both files for the length of the shorter one:

$ cc -Wall -Wextra cmp4.c -o cmp
cmp4.c: In function â??mainâ??:
cmp4.c:12: error: expected statement before â??)â?? token
$ cat cmp4.c
#include <stdio.h>

int main(void)
{
int c, d;
long counter = 0;
FILE *fp, *fq;

fp=fopen("shoulder.wmv", "rb+");
fq=fopen("downloaded1.wmv", "rb+");

while (((c = fgetc(fp)) != EOF) || (d = fgetc(fq)) != EOF))
{
counter++;
if (counter == 10000)
{
printf("int is %d\n", c);
}

if ( c != d)
{
printf("Ungleich: %ld\n", counter);
}
}
printf("Counter reached %ld\n", counter);
fclose (fp);
return 0;
}
// cc -Wall -Wextra cmp4.c -o cmp
$

My parens are probably mismatched by now, but I don't make one statement
on that line; I think I make two.
--
Uno

Janis Papanagnou

6/9/2011 9:11:00 AM

0

Am 09.06.2011 10:57, schrieb Uno:
> On 06/08/2011 10:20 PM, Uno wrote:
>> On 06/08/2011 10:08 PM, Ian Collins wrote:
>>> On 06/ 9/11 03:59 PM, Uno wrote:
>>>>
>>>> I want to pursue this on the C side for a bit. [x-posted to clc]
>>>>
>>>> $ pwd
>>>> /home/dan/source/bdiff-1.0
>>>> $ cc -Wall -Wextra cmp1.c -o cmp
>>>> cmp1.c: In function â??mainâ??:
>>>> cmp1.c:12: warning: comparison is always true due to limited range of
>>>> data type
>>>> cmp1.c:17: warning: implicit declaration of function â??closeâ??
>>>> cmp1.c:18: error: expected declaration or statement at end of input
>>>> $ cat cmp1.c
>>>>
>>>> #include<stdio.h>
>>>>
>>>> int main(void)
>>>> {
>>>> unsigned char c;
>>>> long counter = 0;
>>>> FILE *fp;
>>>>
>>>> fp=fopen("shoulder.wmv", "rb+");
>>>>
>>>> while ((c = fgetc(fp)) != EOF)
>>>
>>> I'm guessing this is line 12. fgetc returns an int. EOF is an integer
>>> constant.
>>>
>>>> {
>>>> counter++;
>>>> }
>>>> printf("Counter reached %ld\n", counter);
>>>> close (fp);
>>>
>>> You are missing <unistd.h>. If you had included it, your compile would
>>> have failed. close works with a file descriptor, not a FILE*.
>>>
>>>> return 0;
>>>
>>> Missing } ?
>>>
>>
>> Thx, Ian.
>>
>> $ cc -Wall -Wextra cmp2.c -o cmp
>> $ ./cmp
>> Counter reached 19573712
>> $ ls -l
>> ...
>> -rw-r--r-- 1 dan dan 19573712 2011-06-05 17:32 shoulder.wmv
>> $ cat cmp2.c
>>
>> #include <stdio.h>
>>
>> int main(void)
>> {
>> int c;
>> long counter = 0;
>> FILE *fp;
>>
>> fp=fopen("shoulder.wmv", "rb+");
>>
>> while ((c = fgetc(fp)) != EOF)
>> {
>> counter++;
>> }
>> printf("Counter reached %ld\n", counter);
>> fclose (fp);
>> return 0;
>> }
>> // cc -Wall -Wextra cmp2.c -o cmp
>> $
>>
>> I guess I thought with counter starting at zero that the numbers
>> wouldn't agree exactly, but they do.
>>
>> It's a weird night here in abq; I'm gonna go out and howl at the orange
>> moon.
>
> I'm stuck again, so that's the night. I don't see why this wouldn't
> traverse both files for the length of the shorter one:

Here you seem to be asking why your algorithm doesn't work,
but below you show us an apparent compiler syntax error;
your parenthesis are not balanced in line 12.

>
> $ cc -Wall -Wextra cmp4.c -o cmp
> cmp4.c: In function â??mainâ??:
> cmp4.c:12: error: expected statement before â??)â?? token
> $ cat cmp4.c
> #include <stdio.h>
>
> int main(void)
> {
> int c, d;
> long counter = 0;
> FILE *fp, *fq;
>
> fp=fopen("shoulder.wmv", "rb+");
> fq=fopen("downloaded1.wmv", "rb+");
>
> while (((c = fgetc(fp)) != EOF) || (d = fgetc(fq)) != EOF))

while ( (c = fgetc(fp)) != EOF
|| (d = fgetc(fq)) != EOF )

> {
> counter++;
> if (counter == 10000)
> {
> printf("int is %d\n", c);
> }
>
> if ( c != d)
> {
> printf("Ungleich: %ld\n", counter);
> }
> }
> printf("Counter reached %ld\n", counter);
> fclose (fp);
> return 0;
> }
> // cc -Wall -Wextra cmp4.c -o cmp
> $
>
> My parens are probably mismatched by now, but I don't make one statement
> on that line; I think I make two.

The compiler doesn't know what your intention was; it's irrelevant
how many statements you have. Fix your syntax.

BTW, why are you posting this to comp.unix.shell?

Janis