00001 // $Id: f_swaplw.c 478 2009-10-29 12:26:09Z linev $ 00002 //----------------------------------------------------------------------- 00003 // The GSI Online Offline Object Oriented (Go4) Project 00004 // Experiment Data Processing at EE department, GSI 00005 //----------------------------------------------------------------------- 00006 // Copyright (C) 2000- GSI Helmholtzzentrum für Schwerionenforschung GmbH 00007 // Planckstr. 1, 64291 Darmstadt, Germany 00008 // Contact: http://go4.gsi.de 00009 //----------------------------------------------------------------------- 00010 // This software can be used under the license agreements as stated 00011 // in Go4License.txt file which is part of the distribution. 00012 //----------------------------------------------------------------------- 00013 00014 #include "typedefs.h" 00015 #define DEBUG 0 00016 /*2+F_SWAPLW****+******************************************************/ 00017 /* */ 00018 /*+ Module : F_SWAPLW */ 00019 /* */ 00020 /* */ 00021 /*--------------------------------------------------------------------*/ 00022 /*+ CALLING : sts = f_swaplw(pp_source, */ 00023 /* l_len, */ 00024 /* pp_dest) */ 00025 /* */ 00026 /*--------------------------------------------------------------------*/ 00027 /* */ 00028 /*+ PURPOSE : Long word byte swap. */ 00029 /* */ 00030 /*+ ARGUMENTS : */ 00031 /*+ pp_source : Pointer to source. */ 00032 /*+ l_dest : length (in long words) */ 00033 /*+ pp_dest : Pointer to destination or 0 if */ 00034 /* destination = source. */ 00035 /* */ 00036 /*+ FUNCTION : Long word byte swap. Works on the source field if */ 00037 /* pp_dest points to value 0 or swaps from the source */ 00038 /* to the destination field. */ 00039 /* (Should be replaced by a fast assembler routine) */ 00040 /* */ 00041 /*+ Return type : int (see s_errnum_def.h) */ 00042 /*+ Status codes: bit 0: success */ 00043 /* */ 00044 /*+ Initialize : - */ 00045 /*+ Include name: - */ 00046 /* */ 00047 /*3+Implementation************+****************************************/ 00048 /* */ 00049 /*+ File name : PC_PROC.C */ 00050 /*+ Version : 1.01 */ 00051 /*+ Author : R.S. Mayer */ 00052 /*+ Last Update : 27-Apr-1994 */ 00053 /*+ Object libr.: ? */ 00054 /*3+Updates*******+***********+****************************************/ 00055 /* */ 00056 /*+ Updates : Date Purpose */ 00057 /* */ 00058 /*3+Description***+***********+****************************************/ 00059 /*1- C Procedure ***********+******************************************/ 00060 #include <stdio.h> 00061 #include <stdlib.h> 00062 #include <string.h> 00063 #include <errno.h> 00064 00065 /* function prototypes */ 00066 00067 /* defines */ 00068 00069 int f_swaplw(int *pp_source, int l_len, int *pp_dest) 00070 00071 { 00072 unsigned char *p_source, *p_dest, *p_s, *p_d; 00073 unsigned int lu_save; 00074 00075 /* +++ action +++ */ 00076 p_source = (unsigned char *) pp_source; 00077 p_dest = (unsigned char *) pp_dest; 00078 00079 if (p_dest == NULL) 00080 { 00081 /* source == destination */ 00082 for (p_d = (unsigned char *) p_source, 00083 p_s = (unsigned char *) &lu_save; 00084 p_d < p_source + (l_len * 4); 00085 ) 00086 { 00087 lu_save = *( (int *) p_d); 00088 p_s += 4; /* increment source */ 00089 *(p_d++) = *(--p_s); 00090 *(p_d++) = *(--p_s); 00091 *(p_d++) = *(--p_s); 00092 *(p_d++) = *(--p_s); 00093 } 00094 } 00095 else 00096 { 00097 for (p_s = (unsigned char *) p_source, 00098 p_d = (unsigned char *) p_dest; 00099 p_s < p_source + (l_len * 4); 00100 p_s += 4) 00101 { 00102 p_s += 4; /* increment source */ 00103 *(p_d++) = *(--p_s); 00104 *(p_d++) = *(--p_s); 00105 *(p_d++) = *(--p_s); 00106 *(p_d++) = *(--p_s); 00107 } 00108 00109 } /* dest == 0 */ 00110 00111 return(0); 00112 } 00113