add a convenience function for mering attrs with default attrs, checking, and None...
[PyX.git] / pykpathsea.c
blob60a48d097ae805ae8b73200e60497109ce4fe962
1 /* pykpathsea.c: Copyright 2003-2011 Jörg Lehmann, André Wobst
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 of the License, or
6 * (at your option) any later version.
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.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
19 #include <string.h>
20 #include <Python.h>
21 #include <kpathsea/tex-file.h>
22 #include <kpathsea/progname.h>
24 static PyObject *py_kpse_find_file(PyObject *self, PyObject *args)
26 char *filename;
27 char *format;
28 char *completefilename;
29 PyObject *returnvalue;
30 kpse_file_format_type kpse_file_format;
32 if (PyArg_ParseTuple(args, "ss", &filename, &format)) {
34 /* if (!strcmp(format, "gf")) kpse_file_format = kpse_gf_format; else */
35 /* if (!strcmp(format, "pk")) kpse_file_format = kpse_pk_format; else */
36 /* if (!strcmp(format, "bitmap font")) kpse_file_format = kpse_any_glyph_format; else */
37 if (!strcmp(format, "tfm")) kpse_file_format = kpse_tfm_format; else
38 if (!strcmp(format, "afm")) kpse_file_format = kpse_afm_format; else
39 /* if (!strcmp(format, "base")) kpse_file_format = kpse_base_format; else */
40 /* if (!strcmp(format, "bib")) kpse_file_format = kpse_bib_format; else */
41 /* if (!strcmp(format, "bst")) kpse_file_format = kpse_bst_format; else */
42 /* if (!strcmp(format, "cnf")) kpse_file_format = kpse_cnf_format; else */
43 /* if (!strcmp(format, "ls-R")) kpse_file_format = kpse_db_format; else */
44 /* if (!strcmp(format, "fmt")) kpse_file_format = kpse_fmt_format; else */
45 if (!strcmp(format, "map")) kpse_file_format = kpse_fontmap_format; else
46 /* if (!strcmp(format, "mem")) kpse_file_format = kpse_mem_format; else */
47 /* if (!strcmp(format, "mf")) kpse_file_format = kpse_mf_format; else */
48 /* if (!strcmp(format, "mfpool")) kpse_file_format = kpse_mfpool_format; else */
49 /* if (!strcmp(format, "mft")) kpse_file_format = kpse_mft_format; else */
50 /* if (!strcmp(format, "mp")) kpse_file_format = kpse_mp_format; else */
51 /* if (!strcmp(format, "mppool")) kpse_file_format = kpse_mppool_format; else */
52 /* if (!strcmp(format, "MetaPost support")) kpse_file_format = kpse_mpsupport_format; else */
53 /* if (!strcmp(format, "ocp")) kpse_file_format = kpse_ocp_format; else */
54 /* if (!strcmp(format, "ofm")) kpse_file_format = kpse_ofm_format; else */
55 /* if (!strcmp(format, "opl")) kpse_file_format = kpse_opl_format; else */
56 /* if (!strcmp(format, "otp")) kpse_file_format = kpse_otp_format; else */
57 /* if (!strcmp(format, "ovf")) kpse_file_format = kpse_ovf_format; else */
58 /* if (!strcmp(format, "ovp")) kpse_file_format = kpse_ovp_format; else */
59 if (!strcmp(format, "graphic/figure")) kpse_file_format = kpse_pict_format; else
60 /* if (!strcmp(format, "tex")) kpse_file_format = kpse_tex_format; else */
61 /* if (!strcmp(format, "TeX system documentation")) kpse_file_format = kpse_texdoc_format; else */
62 /* if (!strcmp(format, "texpool")) kpse_file_format = kpse_texpool_format; else */
63 /* if (!strcmp(format, "TeX system sources")) kpse_file_format = kpse_texsource_format; else */
64 if (!strcmp(format, "PostScript header")) kpse_file_format = kpse_tex_ps_header_format; else
65 /* if (!strcmp(format, "Troff fonts")) kpse_file_format = kpse_troff_font_format; else */
66 if (!strcmp(format, "type1 fonts")) kpse_file_format = kpse_type1_format; else
67 if (!strcmp(format, "vf")) kpse_file_format = kpse_vf_format; else
68 if (!strcmp(format, "dvips config")) kpse_file_format = kpse_dvips_config_format; else
69 /* if (!strcmp(format, "ist")) kpse_file_format = kpse_ist_format; else */
70 /* if (!strcmp(format, "truetype fonts")) kpse_file_format = kpse_truetype_format; else */
71 /* if (!strcmp(format, "type42 fonts")) kpse_file_format = kpse_type42_format; else */
72 /* if (!strcmp(format, "web2c files")) kpse_file_format = kpse_web2c_format; else */
73 /* if (!strcmp(format, "other text files")) kpse_file_format = kpse_program_text_format; else */
74 /* if (!strcmp(format, "other binary files")) kpse_file_format = kpse_program_binary_format; else */
75 /* if (!strcmp(format, "misc fonts")) kpse_file_format = kpse_miscfonts_format; else */
76 return NULL;
78 completefilename = kpse_find_file(filename, kpse_file_format, 1);
79 returnvalue = Py_BuildValue("s", completefilename);
80 /* XXX: free(completefilename); */
81 return returnvalue;
84 return NULL;
88 /* exported methods */
90 static PyMethodDef pykpathsea_methods[] = {
91 {"find_file", (PyCFunction) py_kpse_find_file, METH_VARARGS, NULL},
92 {NULL, NULL}
95 static struct PyModuleDef moduledef = {
96 PyModuleDef_HEAD_INIT,
97 "pykpathsea",
98 NULL,
99 -1,
100 pykpathsea_methods,
101 NULL,
102 NULL,
103 NULL,
104 NULL
107 PyMODINIT_FUNC
108 PyInit_pykpathsea(void)
110 PyObject *module = PyModule_Create(&moduledef);
111 if (module == NULL)
112 return NULL;
113 kpse_set_program_name("dvips", "dvips");
114 return module;