home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / Python 1.3 / source code / Dos / config.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-17  |  5.1 KB  |  213 lines  |  [TEXT/R*ch]

  1. /* -*- C -*- ***********************************************
  2. Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
  3. The Netherlands.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its 
  8. documentation for any purpose and without fee is hereby granted, 
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in 
  11. supporting documentation, and that the names of Stichting Mathematisch
  12. Centrum or CWI not be used in advertising or publicity pertaining to
  13. distribution of the software without specific, written prior permission.
  14.  
  15. STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  16. THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17. FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  18. FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  20. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  21. OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  
  23. ******************************************************************/
  24.  
  25. /* Universal Python configuration file */
  26.  
  27. #ifdef HAVE_CONFIG_H
  28. #include "config.h"
  29. #endif
  30.  
  31. #include <stdio.h>
  32. #include <string.h>
  33.  
  34. #include "myproto.h"
  35. #include "mymalloc.h"
  36. #include "osdefs.h"
  37.  
  38.  
  39. #ifndef NO_MAIN
  40.  
  41. /* Normally, the main program is called from here (so everything else
  42.    can be in libPython.a).  We save a pointer to argv[0] because it
  43.    may be needed for dynamic loading of modules in import.c.  If you
  44.    have your own main program and want to use non-SunOS dynamic
  45.    loading, you will have to provide your own version of
  46.    getprogramname(). */
  47.  
  48. static char *argv0;
  49.  
  50. main(argc, argv)
  51.     int argc;
  52.     char **argv;
  53. {
  54. #ifdef macintosh
  55.     wargs(&argc, &argv);
  56. #endif
  57. #ifdef QUICKWIN
  58.     extern char *getversion PROTO((void));
  59.     extern char *getcopyright PROTO((void));
  60.     char about[256];
  61.     sprintf(about, "Python version %s\n%s", getversion(), getcopyright());
  62.     _wabout(about);
  63. #endif
  64.     argv0 = argv[0];  
  65.     realmain(argc, argv);
  66. }             
  67.  
  68. char *
  69. getprogramname()
  70. {
  71.     return argv0;
  72. }
  73.  
  74. #endif
  75.  
  76.  
  77. /* Return the initial python search path.  This is called once from
  78.    initsys() to initialize sys.path.
  79.    The environment variable PYTHONPATH is fetched and the default path
  80.    appended.  (The Mac has no environment variables, so there the
  81.    default path is always returned.)  The default path may be passed
  82.    to the preprocessor; if not, a system-dependent default is used. */
  83.  
  84. #ifndef PYTHONPATH
  85. #ifdef macintosh
  86. #define PYTHONPATH ": :Lib :Lib:stdwin :Demo"
  87. #endif /* macintosh */
  88. #endif /* !PYTHONPATH */
  89.  
  90. #ifndef PYTHONPATH
  91. #ifdef MSDOS
  92. #define PYTHONPATH ".;..\\lib;\\python\\lib"
  93. #endif /* MSDOS */
  94. #endif /* !PYTHONPATH */
  95.  
  96. #ifndef PYTHONPATH
  97. #define PYTHONPATH ".:/usr/local/lib/python"
  98. #endif /* !PYTHONPATH */
  99.  
  100. extern char *getenv();
  101.  
  102. char *
  103. getpythonpath()
  104. {
  105. #ifdef macintosh
  106.     return PYTHONPATH;
  107. #else /* !macintosh */
  108.     char *path = getenv("PYTHONPATH");
  109.     char *defpath = PYTHONPATH;
  110.     char *buf;
  111.     char *p;
  112.     int n;
  113.  
  114.     if (path == 0 || *path == '\0')
  115.         return defpath;
  116.     n = strlen(path) + strlen(defpath) + 2;
  117.     buf = malloc(n);
  118.     if (buf == NULL)
  119.         return path; /* XXX too bad -- but not likely */
  120.     strcpy(buf, path);
  121.     p = buf + strlen(buf);
  122.     *p++ = DELIM;
  123.     strcpy(p, defpath);
  124.     return buf;
  125. #endif /* !macintosh */
  126. }
  127.  
  128.  
  129. /* Table of built-in modules.
  130.    These are initialized when first imported.
  131.    Note: selection of optional extensions is now generally done by the
  132.    makesetup script. */
  133.  
  134. extern void initarray();
  135. extern void initmath();
  136. extern void initparser();
  137. extern void initdos();
  138. extern void initregex();
  139. extern void initstrop();
  140. extern void initstruct();
  141. extern void inittime();
  142. extern void initdbm();
  143. extern void initfcntl();
  144. extern void initnis();
  145. extern void initpwd();
  146. extern void initgrp();
  147. extern void initselect();
  148. extern void initsocket();
  149. extern void initaudioop();
  150. extern void initimageop();
  151. extern void initrgbimg();
  152. extern void initstdwin();
  153. extern void initmd5();
  154. extern void initmpz();
  155. extern void initrotor();
  156. extern void inital();
  157. extern void initcd();
  158. extern void initcl();
  159. extern void initfm();
  160. extern void initgl();
  161. extern void initimgfile();
  162. extern void initsgi();
  163. extern void initfl();
  164. extern void initthread();
  165. extern void inittiming();
  166.  
  167. /* -- ADDMODULE MARKER 1 -- */
  168.  
  169. extern void initmarshal();
  170.  
  171. struct {
  172.     char *name;
  173.     void (*initfunc)();
  174. } inittab[] = {
  175.  
  176.     {"array", initarray},
  177.     {"math", initmath},
  178.     {"parser", initparser},
  179.     {"dos", initdos},
  180.     {"regex", initregex},
  181.     {"strop", initstrop},
  182.     {"struct", initstruct},
  183.     {"time", inittime},
  184. /*    {"audioop", initaudioop}, */
  185. /*    {"imageop", initimageop}, */
  186.     {"rotor", initrotor},
  187.  
  188. /* -- ADDMODULE MARKER 2 -- */
  189.  
  190.     /* This module "lives in" with marshal.c */
  191.     {"marshal", initmarshal},
  192.  
  193.     /* These entries are here for sys.builtin_module_names */
  194.     {"__main__", NULL},
  195.     {"__builtin__", NULL},
  196.     {"sys", NULL},
  197.  
  198.     /* Sentinel */
  199.     {0, 0}
  200. };
  201.  
  202. #ifdef USE_FROZEN
  203. #include "frozen.c"
  204. #else
  205. struct frozen {
  206.     char *name;
  207.     char *code;
  208.     int size;
  209. } frozen_modules[] = {
  210.     {0, 0, 0}
  211. };
  212. #endif
  213.