00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "mex.h"
00013
00014 void revord(char *input_buf, mwSize buflen, char *output_buf)
00015 {
00016 mwSize i;
00017
00018 if (buflen == 0) return;
00019
00020
00021 for(i=0;i<buflen-1;i++)
00022 *(output_buf+i) = *(input_buf+buflen-i-2);
00023 }
00024
00025 void mexFunction( int nlhs, mxArray *plhs[],
00026 int nrhs, const mxArray *prhs[])
00027 {
00028 char *input_buf, *output_buf;
00029 mwSize buflen;
00030
00031
00032 if(nrhs!=1)
00033 mexErrMsgTxt("One input required.");
00034 else if(nlhs > 1)
00035 mexErrMsgTxt("Too many output arguments.");
00036
00037
00038 if ( mxIsChar(prhs[0]) != 1)
00039 mexErrMsgTxt("Input must be a string.");
00040
00041
00042 if (mxGetM(prhs[0])!=1)
00043 mexErrMsgTxt("Input must be a row vector.");
00044
00045
00046 buflen = (mxGetM(prhs[0]) * mxGetN(prhs[0])) + 1;
00047
00048
00049 output_buf=mxCalloc(buflen, sizeof(char));
00050
00051
00052 input_buf = mxArrayToString(prhs[0]);
00053
00054 if(input_buf == NULL)
00055 mexErrMsgTxt("Could not convert input to string.");
00056
00057
00058 revord(input_buf, buflen, output_buf);
00059
00060
00061 plhs[0] = mxCreateString(output_buf);
00062 mxFree(input_buf);
00063 return;
00064 }
00065