GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
f_swaplw.c
Go to the documentation of this file.
1 // $Id: f_swaplw.c 478 2009-10-29 12:26:09Z linev $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum für Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "typedefs.h"
15 #define DEBUG 0
16 /*2+F_SWAPLW****+******************************************************/
17 /* */
18 /*+ Module : F_SWAPLW */
19 /* */
20 /* */
21 /*--------------------------------------------------------------------*/
22 /*+ CALLING : sts = f_swaplw(pp_source, */
23 /* l_len, */
24 /* pp_dest) */
25 /* */
26 /*--------------------------------------------------------------------*/
27 /* */
28 /*+ PURPOSE : Long word byte swap. */
29 /* */
30 /*+ ARGUMENTS : */
31 /*+ pp_source : Pointer to source. */
32 /*+ l_dest : length (in long words) */
33 /*+ pp_dest : Pointer to destination or 0 if */
34 /* destination = source. */
35 /* */
36 /*+ FUNCTION : Long word byte swap. Works on the source field if */
37 /* pp_dest points to value 0 or swaps from the source */
38 /* to the destination field. */
39 /* (Should be replaced by a fast assembler routine) */
40 /* */
41 /*+ Return type : int (see s_errnum_def.h) */
42 /*+ Status codes: bit 0: success */
43 /* */
44 /*+ Initialize : - */
45 /*+ Include name: - */
46 /* */
47 /*3+Implementation************+****************************************/
48 /* */
49 /*+ File name : PC_PROC.C */
50 /*+ Version : 1.01 */
51 /*+ Author : R.S. Mayer */
52 /*+ Last Update : 27-Apr-1994 */
53 /*+ Object libr.: ? */
54 /*3+Updates*******+***********+****************************************/
55 /* */
56 /*+ Updates : Date Purpose */
57 /* */
58 /*3+Description***+***********+****************************************/
59 /*1- C Procedure ***********+******************************************/
60 #include <stdio.h>
61 #include <stdlib.h>
62 #include <string.h>
63 #include <errno.h>
64 
65 /* function prototypes */
66 
67 /* defines */
68 
69 int f_swaplw(int *pp_source, int l_len, int *pp_dest)
70 
71 {
72  unsigned char *p_source, *p_dest, *p_s, *p_d;
73  unsigned int lu_save;
74 
75  /* +++ action +++ */
76  p_source = (unsigned char *) pp_source;
77  p_dest = (unsigned char *) pp_dest;
78 
79  if (p_dest == NULL)
80  {
81  /* source == destination */
82  for (p_d = (unsigned char *) p_source,
83  p_s = (unsigned char *) &lu_save;
84  p_d < p_source + (l_len * 4);
85  )
86  {
87  lu_save = *( (int *) p_d);
88  p_s += 4; /* increment source */
89  *(p_d++) = *(--p_s);
90  *(p_d++) = *(--p_s);
91  *(p_d++) = *(--p_s);
92  *(p_d++) = *(--p_s);
93  }
94  }
95  else
96  {
97  for (p_s = (unsigned char *) p_source,
98  p_d = (unsigned char *) p_dest;
99  p_s < p_source + (l_len * 4);
100  p_s += 4)
101  {
102  p_s += 4; /* increment source */
103  *(p_d++) = *(--p_s);
104  *(p_d++) = *(--p_s);
105  *(p_d++) = *(--p_s);
106  *(p_d++) = *(--p_s);
107  }
108 
109  } /* dest == 0 */
110 
111  return(0);
112 }
113 
int f_swaplw(int *pp_source, int l_len, int *pp_dest)
Definition: f_swaplw.c:69