7

I've been working on an iOS project for some time now, creating hundreds of source files, and now that's it's good and done, I realize something sad : I edit the copyright file template before getting to work, and all of my files have this lame format :

//
//  MyClass.h
//
//  Created by Redwarp on 3/25/13.
//  Copyright (c) 2013 Redwarp. All rights reserved.
//

And that's not cool ! I would like to replace it with something more like that :

/* This software is licensed under the Apache 2 license, quoted below.

Copyright 2013 Redwarp <redwarp@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
*/

Anyway. I could probably write a script, that searches all my files and replace the first "//" lines with a better comment, but I'm sure there is a tool out there that does that perfectly.

Except : I can't find that tool anywhere.

Would anyone know of such a tool ? (Or might it be that I'm a fool ?)

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Redwarp
  • 3,221
  • 3
  • 31
  • 44
  • I don't know an easy way to fix it, but this might be of interest to you in the future: http://stackoverflow.com/questions/33720/change-templates-in-xcode – woz Mar 25 '13 at 18:41
  • How about XCode's search and replace? It supports multi-line textual search, but not multi-line regex search. So two regex searches and one textual search should cover it. FTR, I would just go with sed. – maroux Mar 25 '13 at 23:36
  • The thing is, not all of my headers are exactly the same. Anyway, I guess I could go with sed, but as I never truly used it (and I'm not exactly sure what it's capable of), it's gonna be a pain :-P – Redwarp Mar 26 '13 at 10:17

1 Answers1

6

I ended up using the script I found here : http://gergap.wordpress.com/2009/06/03/howto-recursively-replace-file-headers-of-source-files/

Does exactly the job I wanted to do, and spared me the burden of doing it myself.

Redwarp
  • 3,221
  • 3
  • 31
  • 44
  • I have faced a similar problem and ended up writing python script. Which work nicely, it is also nice because it handles a situation of changing previous version of the copyright (in case it will change in the future) and omits 3rd part libraries, do not forget about it, do not stamp code you do not own! – Julian Jan 22 '14 at 13:36
  • Don't hesitate to share it ^_^ – Redwarp Jan 22 '14 at 15:50
  • Wordpress link is broken. Anyone looking for same: https://github.com/gergap/bash_scripts/tree/master/rh – Rumin Nov 21 '19 at 22:50