home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Python 1.1 / Mac / config.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-29  |  6.0 KB  |  261 lines  |  [TEXT/KAHL]

  1. /* -*- C -*- ***********************************************
  2. Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
  3. Amsterdam, 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. /* Macintosh Python configuration file */
  26.  
  27. #ifdef HAVE_CONFIG_H
  28. #include "config.h"
  29. #endif
  30.  
  31. #ifdef macintosh
  32. /* The Macintosh main program is in macmain.c */
  33. #define NO_MAIN
  34. #endif
  35.  
  36. #include <stdio.h>
  37. #include <string.h>
  38.  
  39. #include "myproto.h"
  40. #include "mymalloc.h"
  41. #include "osdefs.h"
  42. #include "intrcheck.h"
  43.  
  44.  
  45. #ifndef NO_MAIN
  46.  
  47. /* Normally, the main program is called from here (so everything else
  48.    can be in libPython.a).  We save a pointer to argv[0] because it
  49.    may be needed for dynamic loading of modules in import.c.  If you
  50.    have your own main program and want to use non-SunOS dynamic
  51.    loading, you will have to provide your own version of
  52.    getprogramname(). */
  53.  
  54. static char *argv0;
  55.  
  56. main(argc, argv)
  57.     int argc;
  58.     char **argv;
  59. {
  60.     argv0 = argv[0];
  61.     realmain(argc, argv);
  62. }
  63.  
  64. char *
  65. getprogramname()
  66. {
  67.     return argv0;
  68. }
  69.  
  70. #endif
  71.  
  72.  
  73. /* Python version information */
  74.  
  75. #include "patchlevel.h"
  76.  
  77. /* Return the version string.  This is constructed from the official
  78.    version number (from patchlevel.h), and the current date (if known
  79.    to the compiler, else a manually inserted date). */
  80.  
  81. #define VERSION "%s (%s)"
  82.  
  83. #ifdef __DATE__
  84. #define DATE __DATE__
  85. #else
  86. #define DATE "Aug 17 1994"
  87. #endif
  88.  
  89. char *
  90. getversion()
  91. {
  92.     static char version[80];
  93.     sprintf(version, VERSION, PATCHLEVEL, DATE);
  94.     return version;
  95. }
  96.  
  97.  
  98. /* Return the copyright string.  This is updated manually. */
  99.  
  100. char *
  101. getcopyright()
  102. {
  103.     return "Copyright 1991-1994 Stichting Mathematisch Centrum, Amsterdam";
  104. }
  105.  
  106.  
  107. /* Return the initial python search path.  This is called once from
  108.    initsys() to initialize sys.path.
  109.    The environment variable PYTHONPATH is fetched and the default path
  110.    appended.  (The Mac has no environment variables, so there the
  111.    default path is always returned.)  The default path may be passed
  112.    to the preprocessor; if not, a system-dependent default is used. */
  113.  
  114. #ifndef PYTHONPATH
  115. #ifdef macintosh
  116. #define PYTHONPATH ": :Lib :Lib:stdwin :Lib:test :Lib:mac"
  117. #endif /* macintosh */
  118. #endif /* !PYTHONPATH */
  119.  
  120. #ifndef PYTHONPATH
  121. #if defined(MSDOS) || defined(NT)
  122. #define PYTHONPATH ".;..\\lib;\\python\\lib"
  123. #endif /* MSDOS || NT */
  124. #endif /* !PYTHONPATH */
  125.  
  126. #ifndef PYTHONPATH
  127. #define PYTHONPATH ".:/usr/local/lib/python"
  128. #endif /* !PYTHONPATH */
  129.  
  130. extern char *getenv();
  131.  
  132. char *
  133. getpythonpath()
  134. {
  135. #ifdef macintosh
  136.     return PYTHONPATH;
  137. #else /* !macintosh */
  138.     char *path = getenv("PYTHONPATH");
  139.     char *defpath = PYTHONPATH;
  140.     char *buf;
  141.     char *p;
  142.     int n;
  143.  
  144.     if (path == 0 || *path == '\0')
  145.         return defpath;
  146.     n = strlen(path) + strlen(defpath) + 2;
  147.     buf = malloc(n);
  148.     if (buf == NULL)
  149.         return path; /* XXX too bad -- but not likely */
  150.     strcpy(buf, path);
  151.     p = buf + strlen(buf);
  152.     *p++ = DELIM;
  153.     strcpy(p, defpath);
  154.     return buf;
  155. #endif /* !macintosh */
  156. }
  157.  
  158.  
  159. /* Table of built-in modules.
  160.    These are initialized when first imported.
  161.    Note: selection of optional extensions is now generally done by the
  162.    makesetup script. */
  163.  
  164. extern void initarray();
  165. extern void initmath();
  166. extern void initparser();
  167. extern void initmac();
  168. extern void MacOS_Init();
  169. extern void initregex();
  170. extern void initstrop();
  171. extern void initstruct();
  172. extern void inittime();
  173. extern void initdbm();
  174. extern void initfcntl();
  175. extern void initnis();
  176. extern void initpwd();
  177. extern void initgrp();
  178. extern void initcrypt();
  179. extern void initselect();
  180. extern void initsocket();
  181. extern void initaudioop();
  182. extern void initimageop();
  183. extern void initrgbimg();
  184. extern void initstdwin();
  185. extern void initmd5();
  186. extern void initmpz();
  187. extern void initrotor();
  188. extern void inital();
  189. extern void initcd();
  190. extern void initcl();
  191. extern void initfm();
  192. extern void initgl();
  193. extern void initimgfile();
  194. extern void initimgformat();
  195. extern void initsgi();
  196. extern void initsv();
  197. extern void initfl();
  198. extern void initthread();
  199. extern void inittiming();
  200. extern void initsignal();
  201. extern void initnew();
  202. extern void initdl();
  203. extern void initsyslog();
  204. extern void initgestalt();
  205.  
  206. /* -- ADDMODULE MARKER 1 -- */
  207.  
  208. extern void initmarshal();
  209.  
  210. struct {
  211.     char *name;
  212.     void (*initfunc)();
  213. } inittab[] = {
  214.  
  215.     {"array", initarray},
  216.     {"math", initmath},
  217.     {"parser", initparser},
  218.     {"mac", initmac},
  219.     {"MacOS", MacOS_Init},
  220.     {"regex", initregex},
  221.     {"strop", initstrop},
  222.     {"struct", initstruct},
  223.     {"time", inittime},
  224.     {"audioop", initaudioop},
  225.     {"imageop", initimageop},
  226.     {"rgbimg", initrgbimg},
  227. #ifdef USE_STDWIN
  228.     {"stdwin", initstdwin},
  229. #endif
  230.     {"md5", initmd5},
  231.     {"rotor", initrotor},
  232.     {"new", initnew},
  233.     {"gestalt", initgestalt},
  234.     {"imgformat", initimgformat},
  235.  
  236. /* -- ADDMODULE MARKER 2 -- */
  237.  
  238.     /* This module "lives in" with marshal.c */
  239.     {"marshal", initmarshal},
  240.  
  241.     /* These entries are here for sys.builtin_module_names */
  242.     {"__main__", NULL},
  243.     {"__builtin__", NULL},
  244.     {"sys", NULL},
  245.  
  246.     /* Sentinel */
  247.     {0, 0}
  248. };
  249.  
  250. #ifdef USE_FROZEN
  251. #include "frozen.c"
  252. #else
  253. struct frozen {
  254.     char *name;
  255.     char *code;
  256.     int size;
  257. } frozen_modules[] = {
  258.     {0, 0, 0}
  259. };
  260. #endif
  261.