UNIXworkcode

1 /******************************************************************************* 2 * * 3 * clearcase.c -- Nirvana Editor ClearCase support utilities * 4 * * 5 * Copyright (C) 2001 Mark Edel * 6 * * 7 * This is free software; you can redistribute it and/or modify it under the * 8 * terms of the GNU General Public License as published by the Free Software * 9 * Foundation; either version 2 of the License, or (at your option) any later * 10 * version. In addition, you may distribute versions of this program linked to * 11 * Motif or Open Motif. See README for details. * 12 * * 13 * This software is distributed in the hope that it will be useful, but WITHOUT * 14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * 15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * 16 * more details. * 17 * * 18 * You should have received a copy of the GNU General Public License along with * 19 * software; if not, write to the Free Software Foundation, Inc., 59 Temple * 20 * Place, Suite 330, Boston, MA 02111-1307 USA * 21 * * 22 * Nirvana Text Editor * 23 * March, 2001 * 24 * * 25 * Written by Mark Edel * 26 * * 27 *******************************************************************************/ 28 29 #ifdef HAVE_CONFIG_H 30 #include "../config.h" 31 #endif 32 33 #include "clearcase.h" 34 #include "nedit_malloc.h" 35 36 #include <string.h> 37 #include <stdlib.h> 38 39 #include <X11/Intrinsic.h> 40 41 #ifdef HAVE_DEBUG_H 42 #include "../debug.h" 43 #endif 44 45 static int ClearCaseViewTagFound = 0; 46 static char *ClearCaseViewRoot = NULL; 47 static const char *ClearCaseViewTag = NULL; 48 49 const char* GetClearCaseVersionExtendedPath(const char* fullname) 50 { 51 return(strstr(fullname, "@@/")); 52 } 53 54 55 /* 56 ** Return a string showing the ClearCase view tag. If ClearCase is not in 57 ** use, or a view is not set, NULL is returned. 58 ** 59 ** If user has ClearCase and is in a view, CLEARCASE_ROOT will be set and 60 ** the view tag can be extracted. This check is safe and efficient enough 61 ** that it doesn't impact non-clearcase users, so it is not conditionally 62 ** compiled. (Thanks to Max Vohlken) 63 */ 64 const char *GetClearCaseViewTag(void) 65 { 66 if (!ClearCaseViewTagFound) { 67 /* Extract the view name from the CLEARCASE_ROOT environment variable */ 68 const char *envPtr = getenv("CLEARCASE_ROOT"); 69 if (envPtr != NULL) { 70 const char *tagPtr; 71 ClearCaseViewRoot = NEditStrdup(envPtr); 72 73 tagPtr = strrchr(ClearCaseViewRoot, '/'); 74 if (tagPtr != NULL) { 75 ClearCaseViewTag = ++tagPtr; 76 } 77 } 78 } 79 /* If we don't find it first time, we will never find it, so may just as 80 * well say that we have found it. 81 */ 82 ClearCaseViewTagFound = 1; 83 84 return(ClearCaseViewTag); 85 } 86