Revert Marcus's changes; will re-apply when we get papers.
[bpt/guile.git] / libguile / simpos.c
1 /* Copyright (C) 1995,1996 Free Software Foundation, Inc.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2, or (at your option)
6 * any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; see the file COPYING. If not, write to
15 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
16 * Boston, MA 02111-1307 USA
17 *
18 * As a special exception, the Free Software Foundation gives permission
19 * for additional uses of the text contained in its release of GUILE.
20 *
21 * The exception is that, if you link the GUILE library with other files
22 * to produce an executable, this does not by itself cause the
23 * resulting executable to be covered by the GNU General Public License.
24 * Your use of that executable is in no way restricted on account of
25 * linking the GUILE library code into it.
26 *
27 * This exception does not however invalidate any other reasons why
28 * the executable file might be covered by the GNU General Public License.
29 *
30 * This exception applies only to the code released by the
31 * Free Software Foundation under the name GUILE. If you copy
32 * code from other Free Software Foundation releases into a copy of
33 * GUILE, as the General Public License permits, the exception does
34 * not apply to the code that you add in this way. To avoid misleading
35 * anyone as to the status of such modified files, you must delete
36 * this exception notice from them.
37 *
38 * If you write modifications of your own for GUILE, it is your choice
39 * whether to permit this exception to apply to your modifications.
40 * If you do not wish that, delete this exception notice. */
41 \f
42
43 #include <stdio.h>
44 #include "_scm.h"
45
46 #include "scmsigs.h"
47 #include "simpos.h"
48
49 #ifdef HAVE_STRING_H
50 #include <string.h>
51 #endif
52 #ifdef HAVE_UNISTD_H
53 #include <unistd.h>
54 #endif
55
56 \f
57 extern int system();
58 \f
59
60 #ifndef _Windows
61 SCM_PROC(s_system, "system", 1, 0, 0, scm_system);
62
63 SCM
64 scm_system(cmd)
65 SCM cmd;
66 {
67 SCM_ASSERT(SCM_NIMP(cmd) && SCM_ROSTRINGP(cmd), cmd, SCM_ARG1, s_system);
68 if (SCM_ROSTRINGP (cmd))
69 cmd = scm_makfromstr (SCM_ROCHARS (cmd), SCM_ROLENGTH (cmd), 0);
70 # ifdef AZTEC_C
71 cmd = SCM_MAKINUM(Execute(SCM_ROCHARS(cmd), 0, 0));
72 # else
73 cmd = SCM_MAKINUM(0L+system(SCM_ROCHARS(cmd)));
74 # endif
75 return cmd;
76 }
77 #endif
78
79 extern char *getenv();
80 SCM_PROC (s_getenv, "getenv", 1, 0, 0, scm_getenv);
81
82 SCM
83 scm_getenv(nam)
84 SCM nam;
85 {
86 char *val;
87 SCM_ASSERT(SCM_NIMP(nam) && SCM_ROSTRINGP(nam), nam, SCM_ARG1, s_getenv);
88 if (SCM_ROSTRINGP (nam))
89 nam = scm_makfromstr (SCM_ROCHARS (nam), SCM_ROLENGTH (nam), 0);
90 val = getenv(SCM_CHARS(nam));
91 return (val) ? scm_makfromstr(val, (scm_sizet)strlen(val), 0) : SCM_BOOL_F;
92 }
93
94 /* I have a feeling this whole arrangement below is a bad idea. One
95 should always test for the presence or absence of a particular
96 feature, instead of checking the system name. Older versions of a
97 system may lack features posessed by new ones, and a feature
98 appearing on one system will soon appear on others. And autoconf
99 provides the mechanisms for detecting features. -JimB */
100
101 #ifdef _AIX
102 # define SYSTNAME "AIX"
103 #endif
104 #ifdef vms
105 # define SYSTNAME "VMS"
106 #endif
107 #if defined (unix) || defined (__unix)
108 # define SYSTNAME "UNIX"
109 #endif
110 #ifdef MWC
111 # define SYSTNAME "COHERENT"
112 #endif
113 #ifdef _Windows
114 # define SYSTNAME "WINDOWS"
115 #else
116 # ifdef MSDOS
117 # define SYSTNAME "MS-DOS"
118 # endif
119 #endif
120 #ifdef __EMX__
121 # define SYSTNAME "OS/2"
122 #endif
123 #ifdef __IBMC__
124 # define SYSTNAME "OS/2"
125 #endif
126 #ifdef THINK_C
127 # define SYSTNAME "THINKC"
128 #endif
129 #ifdef AMIGA
130 # define SYSTNAME "AMIGA"
131 #endif
132 #ifdef atarist
133 # define SYSTNAME "ATARIST"
134 #endif
135 #ifdef mach
136 # define SYSTNAME "MACH"
137 #endif
138 #ifdef ARM_ULIB
139 # define SYSTNAME "ACORN"
140 #endif
141
142 SCM_PROC(s_software_type, "software-type", 0, 0, 0, scm_software_type);
143
144 SCM
145 scm_software_type()
146 {
147 #ifdef nosve
148 return SCM_CAR(scm_intern("nosve", 5));
149 #else
150 return SCM_CAR(scm_intern(SYSTNAME, sizeof SYSTNAME/sizeof(char) -1));
151 #endif
152 }
153
154
155 void
156 scm_init_simpos ()
157 {
158 #include "simpos.x"
159 }
160