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

◆ DIR_SEP

#define DIR_SEP   '/'

Definition at line 53 of file emacs.cc.

◆ DIR_SEPP

#define DIR_SEPP   "/"

Definition at line 54 of file emacs.cc.

◆ ESINGULAR

#define ESINGULAR

Definition at line 37 of file emacs.cc.

◆ feReportBug

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

Definition at line 85 of file emacs.cc.

◆ Print

#define Print   error

Definition at line 83 of file emacs.cc.

◆ StringAppend

#define StringAppend   printf

Definition at line 82 of file emacs.cc.

◆ UP_DIR

#define UP_DIR   ".."

Definition at line 55 of file emacs.cc.

◆ Warn

#define Warn   error

Definition at line 80 of file emacs.cc.

◆ WarnS

#define WarnS   error

Definition at line 81 of file emacs.cc.

Function Documentation

◆ error()

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 }

◆ fePrintReportBug()

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 occurred 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:16

◆ feResourceDefault() [1/2]

char* feResourceDefault ( const char  id)

Definition at line 160 of file feResource.cc.

161 {
163 }
static feResourceConfig feGetResourceConfig(const char id)
Definition: feResource.cc:235
static char * feResourceDefault(feResourceConfig config)
Definition: feResource.cc:265

◆ feResourceDefault() [2/2]

char* feResourceDefault ( const char *  key)

Definition at line 165 of file feResource.cc.

166 {
168 }
static feResourceConfig feGetResourceConfig(const char id)
Definition: feResource.cc:235
static char * feResourceDefault(feResourceConfig config)
Definition: feResource.cc:265

◆ main()

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  #ifdef __CYGWIN__
205  error( "Error: Can't find rxvt program. \n Expected it at %s\n Specify alternative with --rxvt=PROGRAM option,\n or set RXVT environment variable to the name of the program to use as rxvt.\n",
206  #else
207  error( "Error: Can't find xterm program. \n Expected it at %s\n Specify alternative with --xterm=PROGRAM option,\n or set XTERM environment variable to the name of the program to use as xterm.\n",
208  #endif
209  feResourceDefault('X'));
210  mainUsage();
211  exit(1);
212  }
213 
214  if (singular == NULL) singular = feResource("SingularXterm", 0);
215  if (singular == NULL)
216  {
217  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",
218  feResourceDefault("SingularXterm"));
219  mainUsage();
220  exit(1);
221  }
222 
223 #ifdef __CYGWIN__
224 #define EXTRA_XTERM_ARGS "+vb -sl 2000 -fb Courier-bold-12 -tn xterm -cr Red3"
225 #else
226 #define EXTRA_XTERM_ARGS ""
227 #endif
228 
229  syscall = (char*) omAlloc(strlen(emacs) +
230  strlen(singular) +
231  length + 300);
232  sprintf(syscall, "%s %s -e %s ", emacs, EXTRA_XTERM_ARGS, singular);
233 
234  for (i=1; i<argc; i++)
235  {
236  if (argv[i] != NULL)
237  {
238  strcat(syscall, " ");
239  strcat(syscall, argv[i]);
240  }
241  }
242 #else
243  // make sure emacs, singular, emacs_dir, emacs_load are set
244  if (emacs == NULL) emacs = feResource("xemacs", 0);
245  if (emacs == NULL) emacs = feResource("emacs", 0);
246  if (emacs == NULL)
247  {
248  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",
249  feResourceDefault("emacs"), feResourceDefault("xemacs"));
250  mainUsage();
251  exit(1);
252  }
253 
254  if (singular == NULL) singular = feResource("SingularEmacs", 0);
255  if (singular == NULL)
256  {
257  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",
258  feResourceDefault("SingularEmacs"));
259  mainUsage();
260  exit(1);
261  }
262 
263  if (emacs_dir == NULL) emacs_dir = feResource("EmacsDir", 0);
264  if (emacs_dir == NULL)
265  {
266  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",
267  feResourceDefault("EmacsDir"));
268  mainUsage();
269  exit(1);
270  }
271 
272  if (emacs_load == NULL)
273  {
274  // look into env variable
275  emacs_load = getenv("ESINGULAR_EMACS_LOAD");
276  if (access(emacs_load, R_OK))
277  {
278  // look in home-dir
279  emacs_load = getenv("HOME");
280 #ifdef __CYGWIN__
281  if ((emacs_load==NULL)||(!access(emacs_load,X_OK)))
282  emacs_load = getenv("SINGHOME");
283 #endif
284  sprintf(cwd, "%s/.emacs-singular", emacs_load);
285  if (! access(cwd, R_OK))
286  {
287  emacs_load = omStrDup(cwd);
288  }
289  else
290  {
291  // try with resources
292  emacs_load = feResource("EmacsLoad", 0);
293  if (emacs_load == NULL)
294  {
295  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",
296  feResourceDefault("EmacsLoad"));
297  mainUsage();
298  exit(1);
299  }
300  }
301  }
302  }
303 
304  syscall = (char*) omAlloc(strlen(emacs) +
305  strlen(singular) +
306  strlen(emacs_dir) +
307  strlen(emacs_load) +
308  length + 300);
309  const char* prefix = "--";
310  if (strstr(emacs, "xemacs") || strstr(emacs, "Xemacs") || strstr(emacs, "XEMACS"))
311  prefix = "-";
312  getcwd(cwd, MAXPATHLEN);
313  // append / at the end of cwd
314  if (cwd[strlen(cwd)-1] != '/') strcat(cwd, "/");
315 
316  // Note: option -no-init-file should be equivalent to -q. Anyhow,
317  // xemacs-20.4 sometimes crashed on startup when using -q. Donīt know why.
318  sprintf(syscall, "%s %sno-init-file %seval '(progn (setq singular-emacs-home-directory \"%s\") (load-file \"%s\") (singular-other \"%s\" \"%s\" (list ",
319  emacs, prefix, prefix, emacs_dir, emacs_load,
320  singular, cwd);
321 
322 
323  for (i=1; i<argc; i++)
324  {
325  if (argv[i] != NULL)
326  {
327  strcat(syscall, "\"");
328  strcat(syscall, argv[i]);
329  strcat(syscall, "\" ");
330  }
331  }
332  strcat(syscall, ") \"singular\"))'");
333 #endif
334 
335  if (no_emacs_call)
336  {
337  printf("%s\n", syscall);
338  }
339  else
340  {
341  if (system(syscall) != 0)
342  {
343  error( "Error: Execution of\n%s\n", syscall);
344  mainUsage();
345  exit(1);
346  }
347  }
348 }
#define MAXPATHLEN
Definition: omRet2Info.c:22
char * fe_optarg
Definition: fegetopt.c:96
static char * feResource(feResourceConfig config, int warn)
Definition: feResource.cc:258
void error(const char *fmt,...)
Definition: emacs.cc:58
char * getenv()
void feInitResources(const char *argv0)
Definition: feResource.cc:170
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:160
void feOptDumpVersionTuple(void)
Definition: feOpt.cc:405
struct fe_option feOptSpec[]
void system(sys)
int i
Definition: cfEzgcd.cc:123
char name(const Variable &v)
Definition: factory.h:178
char * feArgv0
Definition: feResource.cc:19
#define NULL
Definition: omList.c:10
#define LONG_OPTION_RETURN
Definition: feOptTab.h:4
void feOptHelp(const char *name)
Definition: feOpt.cc:354
#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

◆ mainUsage()

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