Working with Source Code to Insert Copyright Statements as a Header

P

Perlgirl

I was wondering if you could give me a hand.

Where could I go to find some samples of PERL code that do the
following:

1. inserts a particular copyright statement
2. checks the existing copyrights and updates it to include the current
year if it's not included
Or if the copyright has the wrong date, the script gives an error.
3. It has to process particular file types (I have that info); a
listing of files to process (I have that info too), and cannot process
binary files (have that info too)

Any help you can give me would be appreciated. Many thanks.
SRGordon
 
P

Paul Lalli

Perlgirl said:
I was wondering if you could give me a hand.

Where could I go to find some samples of PERL code that do the
following:

What John's rather obnoxious remark meant was that the language is
spelled "Perl" and the interpreter is spelled "perl". There is no
"PERL".
1. inserts a particular copyright statement
2. checks the existing copyrights and updates it to include the current
year if it's not included
Or if the copyright has the wrong date, the script gives an error.
3. It has to process particular file types (I have that info); a
listing of files to process (I have that info too), and cannot process
binary files (have that info too)

Any help you can give me would be appreciated. Many thanks.
SRGordon

This isn't really the proper forum for your request. Generally, this
newsgroup helps people in writing and debugging their own code, not
finding other people's code.

Now, if you want some help actually *writing* the program you've
described, you're going to need to be a lot more clear. What do you
mean by "inserting a copyright statement"? Inserting it where? Into a
string? Into a file that's already opened? Into a file that is lying
on the disk somewhere?

What is meant by an "existing copyright"? Do you have a particular
pattern that represents a copyright notice?

I don't know for certain, but you might find Tie::File helpful. It's a
standard module as of Perl 5.8. If you have that version, you can type
`perldoc Tie::File` at the command line to read its documentation. If
not, you can search for it at http://search.cpan.org

I basically recommend: Opening each file you want to process, reading
it line-by-line and using pattern-matching to determine if the
copyright exists, using Tie::File to insert it where you want if it
doesn't, and using a search-and-replace if an incorrect one is found.

You should read:
perldoc perlre
perldoc -f open
perldoc -f readline

You should also read the Posting Guidelines that are posted to this
newsgroup twice a week. Following them maximizes your chances of
getting good help from this group.

Paul Lalli
 
J

John Bokma

Paul Lalli said:
What John's rather obnoxious remark meant was that the language is
spelled "Perl" and the interpreter is spelled "perl". There is no
"PERL".

Apologies >:->
 
P

Perlgirl

Thank you, Paul. You've been most helpful . I admit to being a newbie
and any help of any kind is appreciated. Perlgirl.
 
P

Perlgirl

Paul said:
What John's rather obnoxious remark meant was that the language is
spelled "Perl" and the interpreter is spelled "perl". There is no
"PERL".


This isn't really the proper forum for your request. Generally, this
newsgroup helps people in writing and debugging their own code, not
finding other people's code.

Now, if you want some help actually *writing* the program you've
described, you're going to need to be a lot more clear. What do you
mean by "inserting a copyright statement"? Inserting it where? Into a
string? Into a file that's already opened? Into a file that is lying
on the disk somewhere?

Answer: Insertion of a copyright statement needs to only search through
all text_files
(*.c, .doc, .java, .xml, .pl, .sh. assembler_source, .txt .vbs .any
ascii english text, etc etc etc) at the top of the file, from a string:
"Copyright %Y CompanyName, Inc. All Rights Reserved." These files are
from the cvsroot vault, when a developer checks in his code. Think of
it as a ClearCase Trigger, but as a PERL wrapper for CVS. This string
also needs to be able to add to a current copyright date IF that date
is out of date, as
" Copyright 1999-2006 CompanyName, Inc All Right Reserved"; as well as
NOT change the existing date if the string already has "2006" in it.
Concurrently this string needs to be able to give an error if the
copyright has the wrong date (ex. 2007).
Any suggestions for this? Thanks so much. Perlgirl
 
D

Dr.Ruud

Perlgirl schreef:
Insertion of a copyright statement needs to only search
through all text_files
(*.c, .doc, .java, .xml, .pl, .sh. assembler_source, .txt .vbs .any
ascii english text, etc etc etc) at the top of the file

This can not be done without breaking many of those files. At the top of
the file there is often specific information about how the file should
be handled. But even if you would insert it at line 2 or below, the file
would often no longer be useful as a .c/java/xml/pl/etc. file. Is that
not a problem?
 
P

Peter J. Holzer

Perlgirl schreef:

This can not be done without breaking many of those files. At the top of
the file there is often specific information about how the file should
be handled.

I don't think "at the top of the file" was meant so literally.
But even if you would insert it at line 2 or below, the file
would often no longer be useful as a .c/java/xml/pl/etc. file. Is that
not a problem?

It just means you have to be more careful. If you have determined that
the file is a C file (and you need to identify the files to process
anyway), you have to insert

/* Copyright ... */

instead of just

Copyright ...

Similarly for the other file types.

hp
 
D

Dr.Ruud

Peter J. Holzer schreef:
Dr.Ruud:

I don't think "at the top of the file" was meant so literally.

I didn't think so too, as you should have read in my sentence that
followed. But because of the increasing vagueness from ".doc" (certainly
not MS-Word too?) to ".sh. assembler source" to ".any ascii english
text" and then "etc"x3, I wouldn't bet any money on it either.

It just means you have to be more careful.

No, the list is just too vague and it's just to easy to create a
(possibly nasty) example for many of those types that would end up
corrupted.
 

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

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top