update dev300-m57
[ooovba.git] / sc / addin / rot13 / rot13.cl
blob3454dafa00f532f1ce03bac0dfe3122c67992eed
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rot13.cl,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 /* static char rot13_Id[]="@(#) StarCalc Rot13 AddIn (c) 1998-2000 Sun Microsystems, Inc."; */
33 #include <string.h>
34 #include <stdio.h>
36 #include <xlang.h>
37 #include <addin.h>
38 #include <rot13.hrc>
40 /**
41 * the current language the Addin is using
43 static USHORT _nLanguage=LANGUAGE_ENGLISH;
45 /**
46 * StarCalc calls this function to set a new current Language for the Addin
48 * @param *nLanguage
51 void CALLTYPE SetLanguage( USHORT* nLanguage )
53 _nLanguage = GetNeutralLanguage( *nLanguage );
57 /**
58 * Tell StarCalc how many new functions this Addin provides.
60 * @param *nCount - returns the number of functions which are exported to StarCalc
63 void CALLTYPE GetFunctionCount( USHORT *nCount )
65 *nCount = 1;
68 /**
69 * Provides neccessary data for each new function to StarCalc
71 * @param *nNo Input: Function number between 0 and nCount - 1
72 * @param *pFuncName Output: Functionname which should be called in the AddIn-DLL
73 * @param *nParamCount Output: Number of Parameter. Must be greater than 0, because there's always a return-Value. Maximum is 16.
74 * @param *peType Output: Pointer to arrray with exactly 16 variables of typ Paramtype. nParamCount Entries are set to the type of the corresponding Parameters.
75 * @param *pInternalName Output: Functionname as seen by the Spreadsheet user
77 * @see #GetFunctionCount, #GetParameterDescription
80 void CALLTYPE GetFunctionData( USHORT * nNo,
81 char * pFuncName,
82 USHORT * nParamCount,
83 ParamType * peType,
84 char * pInternalName )
87 switch( *nNo ) {
88 case 0:
89 /* the function name is the same in all languages */
90 SO_StringCopy( pInternalName, "Rot13" );
91 SO_StringCopy( pFuncName, "Rot13" );
92 peType[0] = PTR_STRING;
93 peType[1] = PTR_STRING;
94 *nParamCount=2;
95 break;
96 default:
97 *nParamCount = 0;
98 *pFuncName = 0;
99 *pInternalName = 0;
100 break;
105 * Provides descriptions for each new function to StarCalc
106 * which are shown is the autopilot
108 * @param *nNo Input Parameter, Function number between 0 and nCount - 1
109 * @param *nParam Parameter Number
110 * @param *pName Output: Name of the parameter
111 * @param *pDesc Output: Description of the parameter
113 * @see #GetFunctionCount, #GetParameterDescription
115 void CALLTYPE GetParameterDescription( USHORT* nNo, USHORT* nParam,
116 char* pName, char* pDesc )
118 *pName = 0;
119 *pDesc = 0;
122 switch ( *nNo ) {
123 case 0:
124 switch ( *nParam ) {
125 case 0:
126 SO_StringCopy(pDesc,getText(ROT13_DESC));
127 break;
128 case 1:
129 SO_StringCopy(pName,getText(ROT13_PAR1_NAME));
130 SO_StringCopy(pDesc,getText(ROT13_PAR1_DESC));
136 * ROT13 Algorithm, each alphabetical character of the text is rotated by 13 in the alphabet
138 * @param *ret
139 * @param *src
141 * ER: well, my personal favorite algorithm is
142 * main(_){while(_=~getchar())putchar(~_-1/(~(_|32)/13*2-11)*13);}
143 * but for clarification we do it somehow different here ;-)
145 void CALLTYPE Rot13(char *ret, char *src)
147 if ( ! ret ) return;
148 if ( ! src ) *ret='\0';
150 for(;src && *src; src++ , ret++) {
151 *ret=*src;
152 if (*ret >= 'A' && *ret <= 'Z') {
153 if ( (*ret +=13) > 'Z' ) *ret-=26;
154 } else if (*ret >= 'a' && *ret < 'n') {
155 *ret +=13;
156 } else if (*ret >= 'n' && *ret <= 'z') {
157 *ret -=13;
160 *ret=*src;