Macros | Functions
emacs.cc File Reference
#include <kernel/mod2.h>
#include <omalloc/omalloc.h>
#include <resources/feResource.h>
#include <Singular/feOpt.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>

Go to the source code of this file.

Macros

#define ESINGULAR
 
#define DIR_SEP   '/'
 
#define DIR_SEPP   "/"
 
#define UP_DIR   ".."
 
#define Warn   error
 
#define WarnS   error
 
#define StringAppend   printf
 
#define Print   error
 
#define feReportBug(s)   fePrintReportBug(s, __FILE__, __LINE__)
 

Functions

void error (const char *fmt,...)
 
void fePrintReportBug (char *msg, char *file, int line)
 
void mainUsage ()
 
char * feResourceDefault (const char id)
 
char * feResourceDefault (const char *key)
 
int main (int argc, char **argv)
 

Macro Definition Documentation

#define DIR_SEP   '/'

Definition at line 53 of file emacs.cc.

#define DIR_SEPP   "/"

Definition at line 54 of file emacs.cc.

#define ESINGULAR

Definition at line 37 of file emacs.cc.

#define feReportBug (   s)    fePrintReportBug(s, __FILE__, __LINE__)

Definition at line 85 of file emacs.cc.

#define Print   error

Definition at line 83 of file emacs.cc.

#define StringAppend   printf

Definition at line 82 of file emacs.cc.

#define UP_DIR   ".."

Definition at line 55 of file emacs.cc.

#define Warn   error

Definition at line 80 of file emacs.cc.

#define WarnS   error

Definition at line 81 of file emacs.cc.

Function Documentation

void error ( const char *  fmt,
  ... 
)

Definition at line 58 of file emacs.cc.

59 {
60  va_list ap;
61  va_start(ap, fmt);
62  vfprintf(stderr, fmt, ap);
63 }
void fePrintReportBug ( char *  msg,
char *  file,
int  line 
)

Definition at line 86 of file emacs.cc.

87 {
88  error("YOU HAVE FOUND A BUG IN SINGULAR.\n"
89 "Please, email the following output to singular@mathematik.uni-kl.de\n"
90 "Bug occured at %s:%d\n"
91 "Message: %s\n"
92 "Version: " S_UNAME VERSION __DATE__ __TIME__,
93  file, line, msg);
94 
95 }
void error(const char *fmt,...)
Definition: emacs.cc:58
#define VERSION
Definition: mod2.h:21
char* feResourceDefault ( const char  id)

Definition at line 154 of file feResource.cc.

155 {
157 }
static feResourceConfig feGetResourceConfig(const char id)
Definition: feResource.cc:229
static char * feResourceDefault(feResourceConfig config)
Definition: feResource.cc:259
char* feResourceDefault ( const char *  key)

Definition at line 159 of file feResource.cc.

160 {
162 }
static feResourceConfig feGetResourceConfig(const char id)
Definition: feResource.cc:229
static char * feResourceDefault(feResourceConfig config)
Definition: feResource.cc:259
int main ( int  argc,
char **  argv 
)

Definition at line 106 of file emacs.cc.

107 {
108  char* singular = NULL;
109  char* emacs = NULL;
110 #ifndef TSINGULAR
111  char* emacs_dir = NULL;
112  char* emacs_load = NULL;
113  char cwd[MAXPATHLEN];
114 #endif
115  int no_emacs_call = 0;
116 
117  // parse-cmdline options
118 
119  feInitResources(argv[0]);
120  feResource('S');
121  feResource('b');
122  feResource('r');
123 
124  int optc, option_index;
125 
126  while ((optc = fe_getopt_long(argc, argv, SHORT_OPTS_STRING,
127  feOptSpec, &option_index))
128  != EOF)
129  {
130  switch(optc)
131  {
132  case 'h':
133  extern void feOptHelp(const char* name);
134 
136  exit(0);
137  break;
138  case '?':
139  case ':':
140  case '\0':
141  mainUsage();
142  exit(1);
143 
144  case LONG_OPTION_RETURN:
145  {
146  switch(option_index)
147  {
148 #ifdef TSINGULAR
149  case FE_OPT_XTERM:
150  emacs = fe_optarg;
151  break;
152 #else
153  case FE_OPT_EMACS:
154  emacs = fe_optarg;
155  break;
156 
157  case FE_OPT_EMACS_DIR:
158  emacs_dir = fe_optarg;
159  break;
160 
161  case FE_OPT_EMACS_LOAD:
162  emacs_load = fe_optarg;
163  break;
164 #endif
165  case FE_OPT_SINGULAR:
166  singular = fe_optarg;
167  break;
168 
169  case FE_OPT_NO_CALL:
170  no_emacs_call = 1;
171  break;
172 
173  case FE_OPT_DUMP_VERSIONTUPLE:
175  exit(0);
176  break;
177 
178  default:
179  goto NEXT;
180  }
181  // delete options from option-list
182  if (fe_optind > 2 && *argv[fe_optind-1] != '-' &&
183  fe_optarg != NULL && feOptSpec[option_index].has_arg)
184  {
185  argv[fe_optind-2] = NULL;
186  }
187  argv[fe_optind-1] = NULL;
188  }
189  }
190  NEXT:{}
191  }
192 
193  int i, length = 0;
194  char* syscall;
195  for (i=1; i<argc; i++)
196  {
197  if (argv[i] != NULL) length += strlen(argv[i]) + 3;
198  }
199 
200 #ifdef TSINGULAR
201  if (emacs == NULL) emacs = feResource('X', 0);
202  if (emacs == NULL)
203  {
204  error( "Error: Can't find emacs xterm program. \n Expected it at %s or %s\n Specify alternative with --xterm=PROGRAM option,\n or set ESINGULAR_EMACS environment variable to the name of the program to use as xterm.\n",
205  feResourceDefault('X'));
206  mainUsage();
207  exit(1);
208  }
209 
210  if (singular == NULL) singular = feResource("SingularXterm", 0);
211  if (singular == NULL)
212  {
213  error( "Error: Can't find singular executable.\n Expected it at %s\n Specify with --singular option,\n or set TSINGULAR_SINGULAR environment variable.\n",
214  feResourceDefault("SingularXterm"));
215  mainUsage();
216  exit(1);
217  }
218 
219 #ifdef __CYGWIN__
220 #define EXTRA_XTERM_ARGS "+vb -sl 2000 -fb Courier-bold-12 -tn xterm -cr Red3"
221 #else
222 #define EXTRA_XTERM_ARGS ""
223 #endif
224 
225  syscall = (char*) omAlloc(strlen(emacs) +
226  strlen(singular) +
227  length + 300);
228  sprintf(syscall, "%s %s -e %s ", emacs, EXTRA_XTERM_ARGS, singular);
229 
230  for (i=1; i<argc; i++)
231  {
232  if (argv[i] != NULL)
233  {
234  strcat(syscall, " ");
235  strcat(syscall, argv[i]);
236  }
237  }
238 #else
239  // make sure emacs, singular, emacs_dir, emacs_load are set
240  if (emacs == NULL) emacs = feResource("xemacs", 0);
241  if (emacs == NULL) emacs = feResource("emacs", 0);
242  if (emacs == NULL)
243  {
244  error( "Error: Can't find emacs or xemacs executable. \n Expected it at %s or %s\n Specify alternative with --emacs option,\n or set ESINGULAR_EMACS environment variable.\n",
245  feResourceDefault("emacs"), feResourceDefault("xemacs"));
246  mainUsage();
247  exit(1);
248  }
249 
250  if (singular == NULL) singular = feResource("SingularEmacs", 0);
251  if (singular == NULL)
252  {
253  error( "Error: Can't find singular executable.\n Expected it at %s\n Specify with --singular option,\n or set ESINGULAR_SINGULAR environment variable.\n",
254  feResourceDefault("SingularEmacs"));
255  mainUsage();
256  exit(1);
257  }
258 
259  if (emacs_dir == NULL) emacs_dir = feResource("EmacsDir", 0);
260  if (emacs_dir == NULL)
261  {
262  error( "Error: Can't find emacs directory for Singular lisp files. \n Expected it at %s\n Specify with --emacs_dir option,\n or set ESINGULAR_EMACS_DIR environment variable.\n",
263  feResourceDefault("EmacsDir"));
264  mainUsage();
265  exit(1);
266  }
267 
268  if (emacs_load == NULL)
269  {
270  // look into env variable
271  emacs_load = getenv("ESINGULAR_EMACS_LOAD");
272  if (access(emacs_load, R_OK))
273  {
274  // look in home-dir
275  emacs_load = getenv("HOME");
276 #ifdef __CYGWIN__
277  if ((emacs_load==NULL)||(!access(emacs_load,X_OK)))
278  emacs_load = getenv("SINGHOME");
279 #endif
280  sprintf(cwd, "%s/.emacs-singular", emacs_load);
281  if (! access(cwd, R_OK))
282  {
283  emacs_load = omStrDup(cwd);
284  }
285  else
286  {
287  // try with resources
288  emacs_load = feResource("EmacsLoad", 0);
289  if (emacs_load == NULL)
290  {
291  error( "Error: Can't find emacs load file for Singular mode. \n Expected it at %s\n Specify with --emacs_load option,\n or set ESINGULAR_EMACS_LOAD environment variable,\n or put file '.emacs-singular' in your home directory.\n",
292  feResourceDefault("EmacsLoad"));
293  mainUsage();
294  exit(1);
295  }
296  }
297  }
298  }
299 
300  syscall = (char*) omAlloc(strlen(emacs) +
301  strlen(singular) +
302  strlen(emacs_dir) +
303  strlen(emacs_load) +
304  length + 300);
305  const char* prefix = "--";
306  if (strstr(emacs, "xemacs") || strstr(emacs, "Xemacs") || strstr(emacs, "XEMACS"))
307  prefix = "-";
308  getcwd(cwd, MAXPATHLEN);
309  // append / at the end of cwd
310  if (cwd[strlen(cwd)-1] != '/') strcat(cwd, "/");
311 
312  // Note: option -no-init-file should be equivalent to -q. Anyhow,
313  // xemacs-20.4 sometimes crashed on startup when using -q. Donīt know why.
314  sprintf(syscall, "%s %sno-init-file %seval '(progn (setq singular-emacs-home-directory \"%s\") (load-file \"%s\") (singular-other \"%s\" \"%s\" (list ",
315  emacs, prefix, prefix, emacs_dir, emacs_load,
316  singular, cwd);
317 
318 
319  for (i=1; i<argc; i++)
320  {
321  if (argv[i] != NULL)
322  {
323  strcat(syscall, "\"");
324  strcat(syscall, argv[i]);
325  strcat(syscall, "\" ");
326  }
327  }
328  strcat(syscall, ") \"singular\"))'");
329 #endif
330 
331  if (no_emacs_call)
332  {
333  printf("%s\n", syscall);
334  }
335  else
336  {
337  if (system(syscall) != 0)
338  {
339  error( "Error: Execution of\n%s\n", syscall);
340  mainUsage();
341  exit(1);
342  }
343  }
344 }
#define MAXPATHLEN
Definition: omRet2Info.c:22
char * fe_optarg
Definition: fegetopt.c:96
static char * feResource(feResourceConfig config, int warn)
Definition: feResource.cc:252
void error(const char *fmt,...)
Definition: emacs.cc:58
char * getenv()
void feInitResources(const char *argv0)
Definition: feResource.cc:164
void mainUsage()
Definition: emacs.cc:97
#define omAlloc(size)
Definition: omAllocDecl.h:210
int fe_getopt_long(int argc, char *const *argv, const char *options, const struct fe_option *long_options, int *opt_index)
Definition: fegetopt.c:666
char * feResourceDefault(const char id)
Definition: feResource.cc:154
void feOptDumpVersionTuple(void)
Definition: feOpt.cc:407
struct fe_option feOptSpec[]
int i
Definition: cfEzgcd.cc:123
char * feArgv0
Definition: feResource.cc:19
char name(const Variable &v)
Definition: variable.h:95
#define NULL
Definition: omList.c:10
#define LONG_OPTION_RETURN
Definition: feOptTab.h:4
void feOptHelp(const char *name)
Definition: feOpt.cc:356
#define NEXT(list)
Definition: omList.c:15
int fe_optind
Definition: fegetopt.c:111
const char SHORT_OPTS_STRING[]
Definition: feOpt.cc:29
#define omStrDup(s)
Definition: omAllocDecl.h:263
void mainUsage ( )

Definition at line 97 of file emacs.cc.

98 {
99  error( "Use `%s --help' for a complete list of options\n", feArgv0);
100 }
void error(const char *fmt,...)
Definition: emacs.cc:58
char * feArgv0
Definition: feResource.cc:19