UNIXworkcode

1 /******************************************************************************* 2 * * 3 * utils.h -- Nirvana Editor Utilities Header File * 4 * * 5 * Copyright 2002 The NEdit Developers * 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 * July 31, 2001 * 24 * * 25 *******************************************************************************/ 26 27 #ifndef NEDIT_UTILS_H_INCLUDED 28 #define NEDIT_UTILS_H_INCLUDED 29 30 #include <sys/utsname.h> 31 #include <sys/types.h> 32 33 #ifdef VMS 34 #include "vmsparam.h" 35 #else 36 #include <sys/param.h> 37 #endif /*VMS*/ 38 39 const char *GetCurrentDir(void); 40 const char *GetHomeDir(void); 41 char *PrependHome(const char *filename, char *buf, size_t buflen); 42 const char *GetUserName(void); 43 const char *GetNameOfHost(void); 44 int Min(int i1, int i2); 45 const char* GetRCFileName(int type); 46 47 /* 48 ** Simple stack implementation which only keeps void pointers. 49 ** The stack must already be allocated and initialised: 50 ** 51 ** Stack* stack = (Stack*) XtMalloc(sizeof(Stack)); 52 ** stack->top = NULL; 53 ** stack->size = 0; 54 ** 55 ** NULL is not allowed to pass in, as it is used to signal an empty stack. 56 ** 57 ** The user should only ever care about Stack, stackObject is an internal 58 ** object. (So it should really go in utils.c. A forward reference was 59 ** refused by my compiler for some reason though.) 60 */ 61 typedef struct _stackObject { 62 void* value; 63 struct _stackObject* next; 64 } stackObject; 65 66 typedef struct { 67 unsigned size; 68 stackObject* top; 69 } Stack; 70 71 void Push(Stack* stack, const void* value); 72 void* Pop(Stack* stack); 73 74 /* N_FILE_TYPES must be the last entry!! This saves us from counting. */ 75 enum {NEDIT_RC, AUTOLOAD_NM, NEDIT_HISTORY, SEARCH_HISTORY, XNEDIT_HOME, N_FILE_TYPES}; 76 77 /* If anyone knows where to get this from system include files (in a machine 78 independent way), please change this (L_cuserid is apparently not ANSI) */ 79 #define MAXUSERNAMELEN 32 80 81 /* Ditto for the maximum length for a node name. SYS_NMLN is not available 82 on most systems, and I don't know what the portable alternative is. */ 83 #ifdef SYS_NMLN 84 #define MAXNODENAMELEN SYS_NMLN 85 #else 86 #define MAXNODENAMELEN (MAXPATHLEN+2) 87 #endif 88 89 #endif /* NEDIT_UTILS_H_INCLUDED */ 90