Difference between revisions of "Migration to MIT tool"
From CEGUI Wiki - Crazy Eddie's GUI System (Open Source)
m |
m (Robot: Cosmetic changes) |
||
Line 1: | Line 1: | ||
− | |||
− | |||
− | |||
We use those script / program to update the license of CEGUI sources to MIT. If you need those program to do similar stuff in your project, it's here :) | We use those script / program to update the license of CEGUI sources to MIT. If you need those program to do similar stuff in your project, it's here :) | ||
− | == Driver script == | + | == Driver script == |
'''license_change.sh''' | '''license_change.sh''' | ||
#!/bin/sh | #!/bin/sh | ||
Line 26: | Line 23: | ||
cegui_switch_license $license $convert | cegui_switch_license $license $convert | ||
− | == Converter == | + | == Converter == |
'''cegui_switch_license.c''' | '''cegui_switch_license.c''' | ||
#include <ctype.h> | #include <ctype.h> | ||
Line 215: | Line 212: | ||
* OTHER DEALINGS IN THE SOFTWARE. | * OTHER DEALINGS IN THE SOFTWARE. | ||
***************************************************************************/ | ***************************************************************************/ | ||
+ | |||
+ | [[Category:CEGUI Developer Team]] |
Latest revision as of 16:16, 26 February 2011
We use those script / program to update the license of CEGUI sources to MIT. If you need those program to do similar stuff in your project, it's here :)
Driver script
license_change.sh
#!/bin/sh dir="$1" license="$2" filesHeaders=`find $dir -name "*.h"` filesSources=`find $dir -name "*.cpp"` files="$filesHeaders $filesSources" # find the list of file to be converted for name in $files ; do if grep "GNU Lesser" -q $name ; then convert="$convert $name" fi done #echo "License file: $license" #echo "File to update: $convert" cegui_switch_license $license $convert
Converter
cegui_switch_license.c
#include <ctype.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <dirent.h> int main(int argc, char** argv) { FILE* fdl; size_t licenseSize; char* licenseData; char* licenseDataOrg; int status; int i; if (argc < 3) { fprintf(stderr, "Usage: %s [license] [File1] [File2] ... [FileN]\n", argv[0]); return EXIT_FAILURE; } // Load the license file fdl = fopen(argv[1], "r"); if (fdl == 0) { fprintf(stderr, "Unable to open license file '%s': %s\n", argv[1], strerror(errno)); return EXIT_FAILURE; } fseek(fdl, 0, SEEK_END); // I should check the return code licenseSize = ftell(fdl); // I should check the return code rewind(fdl); // I should check the return code licenseDataOrg = licenseData = malloc(licenseSize + 1); if (licenseData == 0) { fclose(fdl); fprintf(stderr, "Unable to allocate memory\n"); return EXIT_FAILURE; } status = fread(licenseData, 1, licenseSize, fdl); if (status != licenseSize) { free(licenseData); fclose(fdl); fprintf(stderr, "Unable to load in memory license file\n"); return EXIT_FAILURE; } fclose(fdl); licenseData[licenseSize] = '\0'; // Trim the licenseData while(isspace(*licenseData)) { ++licenseData; } while(isspace(licenseData[licenseSize -1])) { licenseData[licenseSize -1] = '\0'; --licenseSize; } printf("License:\n[%s]\n", licenseData); printf("Updating %d files\n", argc - 2); for(i = 2 ; i < argc ; ++i) { // Rename the file char bakFileName[PATH_MAX]; FILE* source; FILE* dest; int state; int data; snprintf(bakFileName, PATH_MAX, "%s.bak", argv[i]); status = rename(argv[i], bakFileName); if (status != 0) { fprintf(stderr, "%s: skipped (rename file '%s' to '%s' failed: %s)\n", argv[i], argv[i], bakFileName, strerror(errno)); continue; } source = fopen(bakFileName, "r"); if (source == 0) { fprintf(stderr, "%s: skipped (opening of '%s' failed: %s)\n", argv[i], bakFileName, strerror(errno)); continue; } dest = fopen(argv[i], "w"); if (dest == 0) { fprintf(stderr, "%s: skipped (opening of '%s' failed: %s\n", argv[i], argv[i], strerror(errno)); fclose(source); continue; } // Start the copy state = 0; while((data = fgetc(source)) != EOF) { switch(state) { case 0: // Before anything if (data == '*') state = 1; else fputc(data, dest); break; // On a lu une etoile, est ce la fin du premier commentaire ? case 1: if (data == '/') { state = 2; // Goto skip license fputc('*', dest); fputc('/', dest); fputc('\n', dest); fwrite(licenseData, 1, licenseSize, dest); } else if (data == '*') { fputc('*', dest); } else { state = 0; fputc(data, dest); } break; // Virer le second commentaire: la license case 2: // skip license if (data == '*') state = 3; break; case 3: if (data == '/') state = 4; // Goto Raw copy else if (data == '*') state = 3; else state = 2; break; // Raw copy case 4: fputc(data, dest); break; } } fclose(dest); fclose(source); if (state != 4) { printf("%s: failed\n", argv[i]); } else { printf("%s: updated\n", argv[i]); } } free(licenseDataOrg); return EXIT_SUCCESS; }
License header
cegui_mit.txt
/*************************************************************************** * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. ***************************************************************************/