xref: /aoo42x/main/sc/addin/rot13/rot13.cl (revision d4a3fa4b)
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements.  See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership.  The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License.  You may obtain a copy of the License at
10 *
11 *   http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied.  See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22/* static char rot13_Id[]="@(#) StarCalc Rot13 AddIn (c) 1998-2000 Sun Microsystems, Inc."; */
23
24#include <string.h>
25#include <stdio.h>
26
27#include <xlang.h>
28#include <addin.h>
29#include <rot13.hrc>
30
31/**
32 * the current language the Addin is using
33 */
34static USHORT _nLanguage=LANGUAGE_ENGLISH;
35
36/**
37 * StarCalc calls this function to set a new current Language for the Addin
38 *
39 * @param *nLanguage
40 *
41 */
42void CALLTYPE SetLanguage( USHORT* nLanguage )
43{
44	_nLanguage = GetNeutralLanguage( *nLanguage );
45}
46
47
48/**
49 * Tell StarCalc how many new functions this Addin provides.
50 *
51 * @param *nCount - returns the number of functions which are exported to StarCalc
52 *
53 */
54void CALLTYPE GetFunctionCount( USHORT *nCount )
55{
56    *nCount = 1;
57}
58
59/**
60 * Provides neccessary data for each new function to StarCalc
61 *
62 * @param *nNo Input: Function number between 0 and nCount - 1
63 * @param *pFuncName Output: Functionname which should be called in the AddIn-DLL
64 * @param *nParamCount Output: Number of Parameter. Must be greater than 0, because there's always a return-Value. Maximum is 16.
65 * @param *peType Output: Pointer to arrray with exactly 16 variables of typ Paramtype. nParamCount Entries are set to the type of the corresponding Parameters.
66 * @param *pInternalName Output: Functionname as seen by the Spreadsheet user
67 *
68 * @see #GetFunctionCount, #GetParameterDescription
69 *
70 */
71void CALLTYPE GetFunctionData( USHORT *    nNo,
72			       char *      pFuncName,
73			       USHORT *    nParamCount,
74			       ParamType * peType,
75			       char *      pInternalName )
76{
77
78    switch( *nNo ) {
79	case 0:
80	    /* the function name is the same in all languages */
81	    SO_StringCopy( pInternalName, "Rot13" );
82	    SO_StringCopy( pFuncName,     "Rot13" );
83	    peType[0] = PTR_STRING;
84	    peType[1] = PTR_STRING;
85	    *nParamCount=2;
86	    break;
87	 default:
88	    *nParamCount    = 0;
89	    *pFuncName     = 0;
90	    *pInternalName = 0;
91	    break;
92    }
93}
94
95/**
96 * Provides descriptions for each new function to StarCalc
97 * which are shown is the autopilot
98 *
99 * @param *nNo Input Parameter, Function number between 0 and nCount - 1
100 * @param *nParam Parameter Number
101 * @param *pName Output: Name of the parameter
102 * @param *pDesc Output: Description of the parameter
103 *
104 * @see #GetFunctionCount, #GetParameterDescription
105 */
106void CALLTYPE GetParameterDescription( USHORT* nNo, USHORT* nParam,
107char* pName, char* pDesc )
108{
109	*pName = 0;
110	*pDesc = 0;
111
112
113	switch ( *nNo ) {
114	case 0:
115		switch ( *nParam ) {
116		case 0:
117			SO_StringCopy(pDesc,getText(ROT13_DESC));
118			break;
119		case 1:
120			SO_StringCopy(pName,getText(ROT13_PAR1_NAME));
121			SO_StringCopy(pDesc,getText(ROT13_PAR1_DESC));
122		}
123	}
124}
125
126/**
127 * ROT13 Algorithm, each alphabetical character of the text is rotated by 13 in the alphabet
128 *
129 * @param *ret
130 * @param *src
131 *
132 * ER: well, my personal favorite algorithm is
133 * main(_){while(_=~getchar())putchar(~_-1/(~(_|32)/13*2-11)*13);}
134 * but for clarification we do it somehow different here ;-)
135 */
136void CALLTYPE Rot13(char *ret, char *src)
137{
138    if ( ! ret ) return;
139    if ( ! src ) *ret='\0';
140
141    for(;src && *src; src++ , ret++) {
142	*ret=*src;
143	if (*ret >= 'A' && *ret <= 'Z') {
144	    if ( (*ret +=13) > 'Z' ) *ret-=26;
145	} else if (*ret >= 'a' && *ret < 'n') {
146	    *ret +=13;
147	} else if (*ret >= 'n' && *ret <= 'z') {
148	    *ret -=13;
149	}
150    }
151    *ret=*src;
152}
153