| 1 | /* |
| 2 | * cstring.i |
| 3 | * $Header: /cvsroot/swig/SWIG/Lib/python/cstring.i,v 1.11 2005/09/06 06:22:10 marcelomatus Exp $ |
| 4 | * |
| 5 | * Author(s): David Beazley (beazley@cs.uchicago.edu) |
| 6 | * |
| 7 | * This file provides typemaps and macros for dealing with various forms |
| 8 | * of C character string handling. The primary use of this module |
| 9 | * is in returning character data that has been allocated or changed in |
| 10 | * some way. |
| 11 | */ |
| 12 | |
| 13 | /* |
| 14 | * %cstring_input_binary(TYPEMAP, SIZE) |
| 15 | * |
| 16 | * Macro makes a function accept binary string data along with |
| 17 | * a size. |
| 18 | */ |
| 19 | |
| 20 | /* |
| 21 | * %cstring_bounded_output(TYPEMAP, MAX) |
| 22 | * |
| 23 | * This macro is used to return a NULL-terminated output string of |
| 24 | * some maximum length. For example: |
| 25 | * |
| 26 | * %cstring_bounded_output(Char *outx, 512); |
| 27 | * void foo(Char *outx) { |
| 28 | * sprintf(outx,"blah blah\n"); |
| 29 | * } |
| 30 | * |
| 31 | */ |
| 32 | |
| 33 | /* |
| 34 | * %cstring_chunk_output(TYPEMAP, SIZE) |
| 35 | * |
| 36 | * This macro is used to return a chunk of binary string data. |
| 37 | * Embedded NULLs are okay. For example: |
| 38 | * |
| 39 | * %cstring_chunk_output(Char *outx, 512); |
| 40 | * void foo(Char *outx) { |
| 41 | * memmove(outx, somedata, 512); |
| 42 | * } |
| 43 | * |
| 44 | */ |
| 45 | |
| 46 | /* |
| 47 | * %cstring_bounded_mutable(TYPEMAP, SIZE) |
| 48 | * |
| 49 | * This macro is used to wrap a string that's going to mutate. |
| 50 | * |
| 51 | * %cstring_bounded_mutable(Char *in, 512); |
| 52 | * void foo(in *x) { |
| 53 | * while (*x) { |
| 54 | * *x = toupper(*x); |
| 55 | * x++; |
| 56 | * } |
| 57 | * } |
| 58 | * |
| 59 | */ |
| 60 | |
| 61 | /* |
| 62 | * %cstring_mutable(TYPEMAP [, expansion]) |
| 63 | * |
| 64 | * This macro is used to wrap a string that will mutate in place. |
| 65 | * It may change size up to a user-defined expansion. |
| 66 | * |
| 67 | * %cstring_mutable(Char *in); |
| 68 | * void foo(in *x) { |
| 69 | * while (*x) { |
| 70 | * *x = toupper(*x); |
| 71 | * x++; |
| 72 | * } |
| 73 | * } |
| 74 | * |
| 75 | */ |
| 76 | |
| 77 | /* |
| 78 | * %cstring_output_maxsize(TYPEMAP, SIZE) |
| 79 | * |
| 80 | * This macro returns data in a string of some user-defined size. |
| 81 | * |
| 82 | * %cstring_output_maxsize(Char *outx, int max) { |
| 83 | * void foo(Char *outx, int max) { |
| 84 | * sprintf(outx,"blah blah\n"); |
| 85 | * } |
| 86 | */ |
| 87 | |
| 88 | /* |
| 89 | * %cstring_output_withsize(TYPEMAP, SIZE) |
| 90 | * |
| 91 | * This macro is used to return Character data along with a size |
| 92 | * parameter. |
| 93 | * |
| 94 | * %cstring_output_maxsize(Char *outx, int *max) { |
| 95 | * void foo(Char *outx, int *max) { |
| 96 | * sprintf(outx,"blah blah\n"); |
| 97 | * *max = strlen(outx); |
| 98 | * } |
| 99 | */ |
| 100 | |
| 101 | /* |
| 102 | * %cstring_output_allocate(TYPEMAP, RELEASE) |
| 103 | * |
| 104 | * This macro is used to return Character data that was |
| 105 | * allocated with new or malloc. |
| 106 | * |
| 107 | * %cstring_output_allocated(Char **outx, free($1)); |
| 108 | * void foo(Char **outx) { |
| 109 | * *outx = (Char *) malloc(512); |
| 110 | * sprintf(outx,"blah blah\n"); |
| 111 | * } |
| 112 | */ |
| 113 | |
| 114 | /* |
| 115 | * %cstring_output_allocate_size(TYPEMAP, SIZE, RELEASE) |
| 116 | * |
| 117 | * This macro is used to return Character data that was |
| 118 | * allocated with new or malloc. |
| 119 | * |
| 120 | * %cstring_output_allocated(Char **outx, int *sz, free($1)); |
| 121 | * void foo(Char **outx, int *sz) { |
| 122 | * *outx = (Char *) malloc(512); |
| 123 | * sprintf(outx,"blah blah\n"); |
| 124 | * *sz = strlen(outx); |
| 125 | * } |
| 126 | */ |
| 127 | |
| 128 | %include <pystrings.swg> |
| 129 | %include <cstrbase.swg> |
| 130 | |
| 131 | %typemap_cstrings(%cstring, |
| 132 | char, |
| 133 | SWIG_AsCharPtr, |
| 134 | SWIG_AsCharPtrAndSize, |
| 135 | SWIG_FromCharPtr, |
| 136 | SWIG_FromCharArray); |
| 137 | |