File: version.c

package info (click to toggle)
vile 9.5-i1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 8,248 kB
  • ctags: 8,023
  • sloc: ansic: 86,640; lex: 8,291; sh: 3,073; perl: 2,926; cpp: 2,891; makefile: 779; awk: 276
file content (225 lines) | stat: -rw-r--r-- 5,815 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/*
 * version & usage-messages for vile
 *
 * $Header: /usr/build/vile/vile/RCS/version.c,v 1.59 2006/01/12 22:37:43 tom Exp $
 *
 */

#include	"estruct.h"	/* global structures and defines */
#include	"edef.h"	/* global definitions */
#include	"patchlev.h"

static char version_string[NSTRING];

void
print_usage(int code)
{
    static const char *const options[] =
    {
	"-h             to get help on startup",
	"-gNNN          or simply +NNN to go to line NNN",
#if SYS_WINNT && DISP_NTWIN
	"-fn fontspec   to change font",
	"-geometry CxR  to set initial size to R rows and C columns",
#endif
#if SYS_WINNT && DISP_NTCONS
	"-console       if stdin is not a tty, start editor in a new console",
#endif
#if SYS_WINNT && defined(VILE_OLE) && DISP_NTWIN
	"-Oa            invoke as an OLE Automation server",
	"-Or            register ole automation interface and exit",
	"-Ou            unregister ole automation interface and exit",
	"-invisible     OLE Automation server does not initially show a window",
	"-multiple      multiple instances of OLE Automation server permitted",
#endif
	"-sstring       or +/string to search for \"string\"",
#if OPT_TAGS
#if DISP_X11			/* because -title is predefined */
	"-Ttagname      to look up a tag",
#else
	"-ttagname      to look up a tag",
#endif
#endif
	"-v             to edit in \"view\" mode -- no changes permitted",
	"-R             to edit files \"read-only\" -- no writes permitted",
#if OPT_ENCRYPT
	"-kcryptkey     for encrypted files (same as -K)",
#endif
#if DISP_X11
	"-name name     to change program name for X resources",
	"-title name    to set name in title bar",
	"-fg color      to change foreground color",
	"-bg color      to change background color",
	"-fn fontname   to change font",
	"-fork          to spawn xvile immediately on startup",
	"+fork          to force xvile to not spawn on startup",
	"-display       displayname to change the default display",
	"-rv            for reverse video",
	"-geometry CxR  to set initial size to R rows and C columns",
	"-xrm Resource  to change an xvile resource",
	"-leftbar       Put scrollbar(s) on left",
	"-rightbar      Put scrollbar(s) on right (default)",
#endif
#if DISP_BORLAND
	"-2             25-line mode",
	"-4             43-line mode",
	"-5             50-line mode",
#if SYS_OS2
	"-6             60-line mode",
#endif
	"(see help file for more screen resolutions)",
#endif
#if SYS_VMS
	"-80            80-column mode",
	"-132           132-column mode",
#endif
#if OPT_EVAL || OPT_DEBUGMACROS
	"-D             trace macros into [Trace] buffer",
#endif
	"-V             for version info",
	"-I             use vileinit.rc to initialize",
	"use @cmdfile to run cmdfile as commands (this will suppress .vilerc)",
	"single-letter options usually are case-independent"
    };

    term.clean(TRUE);
#if DISP_NTWIN
    gui_usage(prog_arg, options, TABLESIZE(options));
#else
    (void) fprintf(stderr, "usage: %s [-flags] [@cmdfile] files...\n",
		   prog_arg);
    {
	unsigned j;
	for (j = 0; j < TABLESIZE(options); j++)
	    (void) fprintf(stderr, "\t%s\n", options[j]);
    }
#endif
    ExitProgram(code);
}

const char *
getversion(void)
{
    if (*version_string)
	return version_string;
#if SYS_UNIX || SYS_VMS
    /*
     * We really would like to have the date at which this program was
     * linked, but a.out doesn't have that in general.  COFF files do.
     * Getting the executable's modification-time is a reasonable
     * compromise.
     */
    (void) lsprintf(version_string, "%s %s%s for %s",
		    prognam, version, VILE_PATCHLEVEL, opersys);
    {
	char *s;
	if ((s = cfg_locate(prog_arg,
			    (FL_EXECDIR | FL_PATH) | FL_EXECABLE)) != NULL) {
	    time_t mtime = file_modified(s);
	    if (mtime != 0) {
		(void) strcat(version_string, ", installed ");
		(void) strcat(version_string, ctime(&mtime));
		/* trim the newline */
		version_string[strlen(version_string) - 1] = EOS;
	    }
	}
    }
#else
# if SYS_MSDOS || SYS_OS2 || SYS_WINNT
#  if defined(__DATE__) && !SMALLER
    (void) lsprintf(version_string, "%s %s%s for %s, built %s %s with %s",
		    prognam, version, VILE_PATCHLEVEL, opersys, __DATE__, __TIME__,
#   if CC_WATCOM
		    "Watcom C/386"
#   endif
#   if CC_DJGPP
#    if __DJGPP__ >= 2
		    "DJGPP v2"
#    else
		    "DJGPP"
#    endif
#   endif
#   if CC_TURBO
#    ifdef __BORLANDC__
		    "Borland C++"
#    else
		    "Turbo C"
#    endif
#   endif
#   if CC_CSETPP
#    if __IBMC__ >= 300
		    "VisualAge C++"
#    else
		    "IBM C Set ++"
#    endif
#   endif
#   if CC_LCC_WIN32
		    "Lcc-win32"
#   endif
#   if CC_MSVC
		    "Visual C++"
#   endif
	);
#  endif
# endif				/* SYS_MSDOS || SYS_OS2 || SYS_WINNT */
#endif /* not SYS_UNIX or SYS_VMS */
    return version_string;
}

/* i'm not even going to try to justify this.  -pgf */
static void
personals(int n)
{
#if !SMALLER
    char **cmdp = NULL;

    static char *pgfcmds[] =
    {
	"bind-key split-current-window ^T",
	"bind-key next-window ^N",
	"bind-key previous-window ^P",
	"set ai atp nobl ul=0 sw=4 csw=4 timeoutlen=50 check-modtime visual-matches=underline",
	NULL
    };

    if (n == 11)
	cmdp = pgfcmds;

    if (n == -11)
	*(int *) (1) = 42;	/* test core dumps */

    if (!cmdp)
	return;

    while (*cmdp) {
	(void) docmd(*cmdp, TRUE, FALSE, 1);
	cmdp++;
    }
#endif

}

/* ARGSUSED */
int
showversion(int f GCC_UNUSED, int n)
{
    personals(n);
    mlforce(getversion());

    return TRUE;
}

/*
 * Returns the special string consisting of program name + version, used to
 * fill in the filename-field for scratch buffers that are not associated with
 * an external file.
 */
const char *
non_filename(void)
{
    static char buf[80];
    if (buf[0] == EOS)
	(void) lsprintf(buf, "       %s   %s%s",
			prognam, version, VILE_PATCHLEVEL);
    return buf;
}