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