xref: /aoo42x/main/sc/addin/rot13/rot13.cl (revision cdf0e10c)
1/*************************************************************************
2 *
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
6 *
7 * OpenOffice.org - a multi-platform office productivity suite
8 *
9 * This file is part of OpenOffice.org.
10 *
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.
14 *
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).
20 *
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.
25 *
26 ************************************************************************/
27
28/* static char rot13_Id[]="@(#) StarCalc Rot13 AddIn (c) 1998-2000 Sun Microsystems, Inc."; */
29
30#include <string.h>
31#include <stdio.h>
32
33#include <xlang.h>
34#include <addin.h>
35#include <rot13.hrc>
36
37/**
38 * the current language the Addin is using
39 */
40static USHORT _nLanguage=LANGUAGE_ENGLISH;
41
42/**
43 * StarCalc calls this function to set a new current Language for the Addin
44 *
45 * @param *nLanguage
46 *
47 */
48void CALLTYPE SetLanguage( USHORT* nLanguage )
49{
50	_nLanguage = GetNeutralLanguage( *nLanguage );
51}
52
53
54/**
55 * Tell StarCalc how many new functions this Addin provides.
56 *
57 * @param *nCount - returns the number of functions which are exported to StarCalc
58 *
59 */
60void CALLTYPE GetFunctionCount( USHORT *nCount )
61{
62    *nCount = 1;
63}
64
65/**
66 * Provides neccessary data for each new function to StarCalc
67 *
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
73 *
74 * @see #GetFunctionCount, #GetParameterDescription
75 *
76 */
77void CALLTYPE GetFunctionData( USHORT *    nNo,
78			       char *      pFuncName,
79			       USHORT *    nParamCount,
80			       ParamType * peType,
81			       char *      pInternalName )
82{
83
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;
98    }
99}
100
101/**
102 * Provides descriptions for each new function to StarCalc
103 * which are shown is the autopilot
104 *
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
109 *
110 * @see #GetFunctionCount, #GetParameterDescription
111 */
112void CALLTYPE GetParameterDescription( USHORT* nNo, USHORT* nParam,
113char* pName, char* pDesc )
114{
115	*pName = 0;
116	*pDesc = 0;
117
118
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));
128		}
129	}
130}
131
132/**
133 * ROT13 Algorithm, each alphabetical character of the text is rotated by 13 in the alphabet
134 *
135 * @param *ret
136 * @param *src
137 *
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 ;-)
141 */
142void CALLTYPE Rot13(char *ret, char *src)
143{
144    if ( ! ret ) return;
145    if ( ! src ) *ret='\0';
146
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;
155	}
156    }
157    *ret=*src;
158}
159