| 1 | /* |
|---|
| 2 | This file is part of the Astrometry.net suite. |
|---|
| 3 | Copyright 2006-2008 Dustin Lang, Keir Mierle and Sam Roweis. |
|---|
| 4 | |
|---|
| 5 | The Astrometry.net suite is free software; you can redistribute |
|---|
| 6 | it and/or modify it under the terms of the GNU General Public License |
|---|
| 7 | as published by the Free Software Foundation, version 2. |
|---|
| 8 | |
|---|
| 9 | The Astrometry.net suite is distributed in the hope that it will be |
|---|
| 10 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 12 | General Public License for more details. |
|---|
| 13 | |
|---|
| 14 | You should have received a copy of the GNU General Public License |
|---|
| 15 | along with the Astrometry.net suite ; if not, write to the Free Software |
|---|
| 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 17 | */ |
|---|
| 18 | |
|---|
| 19 | #include <stdio.h> |
|---|
| 20 | #include <string.h> |
|---|
| 21 | |
|---|
| 22 | #include "svn.h" |
|---|
| 23 | #include "an-thread.h" |
|---|
| 24 | |
|---|
| 25 | /*** |
|---|
| 26 | FIXME - consider using this recipe from the SVN book instead. |
|---|
| 27 | |
|---|
| 28 | ## |
|---|
| 29 | ## on every build, record the working copy revision string |
|---|
| 30 | ## |
|---|
| 31 | svn_version.c: FORCE |
|---|
| 32 | echo -n 'const char* svn_version(void) { const char* SVN_Version = "' \ |
|---|
| 33 | > svn_version.c |
|---|
| 34 | svnversion -n . >> svn_version.c |
|---|
| 35 | echo '"; return SVN_Version; }' >> svn_version.c |
|---|
| 36 | |
|---|
| 37 | ## |
|---|
| 38 | ## Then any executable that links in svn_version.o will be able |
|---|
| 39 | ## to call the function svn_version() to get a string that |
|---|
| 40 | ## describes exactly what revision was built. |
|---|
| 41 | ## |
|---|
| 42 | ***/ |
|---|
| 43 | |
|---|
| 44 | static char date_rtnval[256]; |
|---|
| 45 | static char url_rtnval[256]; |
|---|
| 46 | static int rev_rtnval; |
|---|
| 47 | |
|---|
| 48 | /* Ditto for "headurlstr". */ |
|---|
| 49 | static const char* date = "$Date$"; |
|---|
| 50 | static const char* url = "$HeadURL$"; |
|---|
| 51 | static const char* rev = "$Revision$"; |
|---|
| 52 | |
|---|
| 53 | AN_THREAD_DECLARE_STATIC_ONCE(svn_once); |
|---|
| 54 | |
|---|
| 55 | static void runonce(void) { |
|---|
| 56 | const char* cptr; |
|---|
| 57 | const char* str; |
|---|
| 58 | |
|---|
| 59 | // (trim off the first seven and last two characters.) |
|---|
| 60 | strncpy(date_rtnval, date + 7, strlen(date) - 9); |
|---|
| 61 | |
|---|
| 62 | // rev+1 to avoid having "$" in the format string - otherwise svn seems to |
|---|
| 63 | // consider it close enough to the Revision keyword anchor to do replacement! |
|---|
| 64 | if (sscanf(rev + 1, "Revision: %i $", &rev_rtnval) != 1) |
|---|
| 65 | rev_rtnval = -1; |
|---|
| 66 | |
|---|
| 67 | //str = (char*)url + 10; |
|---|
| 68 | str = url + 10; |
|---|
| 69 | cptr = str + strlen(str) - 1; |
|---|
| 70 | // chomp off the filename... |
|---|
| 71 | while (cptr > str && *cptr != '/') cptr--; |
|---|
| 72 | strncpy(url_rtnval, str, cptr - str + 1); |
|---|
| 73 | |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | const char* svn_date() { |
|---|
| 78 | AN_THREAD_CALL_ONCE(svn_once, runonce); |
|---|
| 79 | return date_rtnval; |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | int svn_revision() { |
|---|
| 83 | AN_THREAD_CALL_ONCE(svn_once, runonce); |
|---|
| 84 | return rev_rtnval; |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | const char* svn_url() { |
|---|
| 88 | AN_THREAD_CALL_ONCE(svn_once, runonce); |
|---|
| 89 | return url_rtnval; |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | // The Makefile automatically appends a blank comment line to the end |
|---|
| 93 | // of this file every time libanutils.a gets built. |
|---|
| 94 | // |
|---|
| 95 | |
|---|
| 96 | // |
|---|
| 97 | // |
|---|
| 98 | // |
|---|
| 99 | // |
|---|
| 100 | // |
|---|
| 101 | // |
|---|
| 102 | // |
|---|
| 103 | // |
|---|
| 104 | // |
|---|
| 105 | // |
|---|
| 106 | // |
|---|
| 107 | // |
|---|
| 108 | // |
|---|
| 109 | // |
|---|
| 110 | // |
|---|
| 111 | // |
|---|
| 112 | // |
|---|
| 113 | // |
|---|
| 114 | // |
|---|
| 115 | // |
|---|
| 116 | // |
|---|
| 117 | // |
|---|
| 118 | // |
|---|
| 119 | // |
|---|
| 120 | // |
|---|
| 121 | // |
|---|
| 122 | // |
|---|
| 123 | // |
|---|
| 124 | // |
|---|
| 125 | // |
|---|
| 126 | // |
|---|
| 127 | // |
|---|
| 128 | // |
|---|
| 129 | // |
|---|
| 130 | // |
|---|
| 131 | // |
|---|
| 132 | // |
|---|
| 133 | // |
|---|
| 134 | // |
|---|
| 135 | // |
|---|
| 136 | // |
|---|
| 137 | // |
|---|
| 138 | // |
|---|
| 139 | // |
|---|
| 140 | // |
|---|
| 141 | // |
|---|
| 142 | // |
|---|
| 143 | // |
|---|
| 144 | // |
|---|
| 145 | // |
|---|
| 146 | // |
|---|
| 147 | // |
|---|
| 148 | // |
|---|
| 149 | // |
|---|
| 150 | // |
|---|
| 151 | // |
|---|
| 152 | // |
|---|
| 153 | // |
|---|
| 154 | // |
|---|
| 155 | // |
|---|
| 156 | // |
|---|
| 157 | // |
|---|
| 158 | // |
|---|
| 159 | // |
|---|
| 160 | // |
|---|
| 161 | // |
|---|
| 162 | // |
|---|
| 163 | // |
|---|
| 164 | // |
|---|
| 165 | // |
|---|
| 166 | // |
|---|
| 167 | // |
|---|
| 168 | // |
|---|
| 169 | // |
|---|
| 170 | // |
|---|
| 171 | // |
|---|
| 172 | // |
|---|
| 173 | // |
|---|
| 174 | // |
|---|
| 175 | // |
|---|
| 176 | // |
|---|
| 177 | // |
|---|
| 178 | // |
|---|
| 179 | // |
|---|
| 180 | // |
|---|
| 181 | // |
|---|
| 182 | // |
|---|
| 183 | // |
|---|
| 184 | // |
|---|
| 185 | // |
|---|
| 186 | // |
|---|
| 187 | // |
|---|
| 188 | // |
|---|
| 189 | // |
|---|