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