[R-gregmisc-users] SF.net SVN: r-gregmisc:[1839] trunk/SASxport/src
Brought to you by:
warnes
From: <wa...@us...> - 2014-07-18 17:04:10
|
Revision: 1839 http://sourceforge.net/p/r-gregmisc/code/1839 Author: warnes Date: 2014-07-18 17:04:07 +0000 (Fri, 18 Jul 2014) Log Message: ----------- minor code formatting changes Modified Paths: -------------- trunk/SASxport/src/SASxport.c trunk/SASxport/src/ibm2ieee.c trunk/SASxport/src/writeSAS.c Modified: trunk/SASxport/src/SASxport.c =================================================================== --- trunk/SASxport/src/SASxport.c 2014-07-18 17:03:46 UTC (rev 1838) +++ trunk/SASxport/src/SASxport.c 2014-07-18 17:04:07 UTC (rev 1839) @@ -62,7 +62,7 @@ static double get_IBM_double(char* c, size_t len) { - /* Conversion from IBM 360 format to double */ +/* Conversion from IBM 360 format to double */ /* * IBM format: * 6 5 0 @@ -77,14 +77,14 @@ * the high order hex fraction digit. */ unsigned int i, upper, lower; - /* exponent is expressed here as - excess 70 (=64+6) to accomodate - integer conversion of c[1] to c[4] */ + /* exponent is expressed here as + excess 70 (=64+6) to accomodate + integer conversion of c[1] to c[4] */ char negative = c[0] & 0x80, exponent = (c[0] & 0x7f) - 70, buf[4]; - double value; + double value; char ibuf[8]; - if (len < 2 || len > 8) + if (len < 2 || len > 8) error(_("invalid field length in numeric variable")); /* this effectively zero-pads c: */ @@ -169,7 +169,7 @@ return 0; return 1; } - + static int get_mem_header(FILE *fp, struct SAS_XPORT_member *member) { @@ -179,7 +179,7 @@ n = GET_RECORD(record, fp, 80); if(n != 80 || strncmp(DSC_HEADER, record, 80) != 0) error(_("file not in SAS transfer format")); - + n = GET_RECORD(record, fp, 80); if(n != 80) return 0; @@ -224,7 +224,7 @@ Free(lib_head); n = GET_RECORD(record, fp, 80); - if(n != 80 || + if(n != 80 || strncmp(MEM_HEADER, record, 75) != 0 || strncmp(" ", record+78, 2) != 0 ) error(_("file not in SAS transfer format")); @@ -290,20 +290,20 @@ } static int -next_xport_info(FILE *fp, int namestr_length, int nvars, +next_xport_info(FILE *fp, int namestr_length, int nvars, int *headpad, - int *tailpad, - int *length, - int *ntype, + int *tailpad, + int *length, + int *ntype, int *nlng, - int *nvar0, - SEXP nname, - SEXP nlabel, - SEXP nform, - int *nfl, - int *nfd, - SEXP niform, - int *nifl, + int *nvar0, + SEXP nname, + SEXP nlabel, + SEXP nform, + int *nfl, + int *nfd, + SEXP niform, + int *nifl, int *nifd, int *npos) { @@ -331,13 +331,13 @@ } (*headpad) += i; } - + n = GET_RECORD(record, fp, 80); if(n != 80 || strncmp(OBS_HEADER, record, 80) != 0) { Free(nam_head); error(_("file not in SAS transfer format")); } - + for(i = 0; i < nvars; i++) { int nname_len = 0, nlabel_len = 0, nform_len = 0, niform_len=0; char tmpname[41]; @@ -455,7 +455,7 @@ sscanf(record+75, "%d", &namestr_length); break; } - + if (fsetpos(fp, ¤tPos)) { error(_("problem accessing SAS XPORT file")); } @@ -663,14 +663,14 @@ SET_STRING_ELT(ansNames , ansLength, mkChar(dsname )); SET_VECTOR_ELT(ans, ansLength, varInfo); ansLength++; - + UNPROTECT(7); PROTECT(ans); PROTECT(ansNames); } - setAttrib(ans, R_NamesSymbol, ansNames); + setAttrib(ans, R_NamesSymbol, ansNames); UNPROTECT(5); fclose(fp); return ans; @@ -736,7 +736,7 @@ for(k = nvar-1; k >= 0; k--) { tmpchar = record + dataPosition[k]; if(dataType[k] == REALSXP) { - REAL(VECTOR_ELT(data, k))[j] = + REAL(VECTOR_ELT(data, k))[j] = get_IBM_double(tmpchar, dataWidth[k]); } else { tmpchar[dataWidth[k]] = '\0'; @@ -753,7 +753,7 @@ } fseek(fp, dataTailPad, SEEK_CUR); - + Free(record); } UNPROTECT(1); Modified: trunk/SASxport/src/ibm2ieee.c =================================================================== --- trunk/SASxport/src/ibm2ieee.c 2014-07-18 17:03:46 UTC (rev 1838) +++ trunk/SASxport/src/ibm2ieee.c 2014-07-18 17:04:07 UTC (rev 1839) @@ -30,7 +30,7 @@ * * Convert an array of IBM/360 format double precision values of at *in * of length 'count' to BIG-ENDIAN IEEE double precision value at *out. - * + * * This code was extracted from the "ntohd" function, original author * Michael John Muuss * @@ -63,7 +63,9 @@ continue; } \ -void ibm2ieee(register unsigned char *out, register const unsigned char *in, int count) +void ibm2ieee(register unsigned char *out, + register const unsigned char *in, + int count) { /* * IBM Format. @@ -75,11 +77,11 @@ register unsigned int left, right, signbit; register int exp; - left = ( (unsigned int) in[0]<<24) | - ( (unsigned int) in[1]<<16) | - ( (unsigned int) in[2]<<8) | + left = ( (unsigned int) in[0]<<24) | + ( (unsigned int) in[1]<<16) | + ( (unsigned int) in[2]<<8) | in[3]; - right = ( (unsigned int) in[4]<<24) | + right = ( (unsigned int) in[4]<<24) | ( (unsigned int) in[5]<<16) | ( (unsigned int) in[6]<<8) | in[7]; Modified: trunk/SASxport/src/writeSAS.c =================================================================== --- trunk/SASxport/src/writeSAS.c 2014-07-18 17:03:46 UTC (rev 1838) +++ trunk/SASxport/src/writeSAS.c 2014-07-18 17:04:07 UTC (rev 1839) @@ -5,7 +5,7 @@ * Author: Gregory R. Warnes <gr...@wa...> * * Copyright (C) 2007-2013 Gregory R. Warnes <gr...@wa...> - * + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -40,7 +40,7 @@ { int i; - for(i=0; i<(len); i++) + for(i=0; i<(len); i++) target[i]=' '; } @@ -64,7 +64,7 @@ { int i; - for(i=0; i<(len); i++) + for(i=0; i<(len); i++) target[i]=0; } @@ -90,7 +90,7 @@ * This function is used to retreive the filled buffer as an R 'raw' * object. This is necessary because the buffer legitimately contains * embedded nulls and R currently does not permit raw buffers to be - * passed via .C . + * passed via .C . */ #define MYBUFSIZE 1024 /* plenty big */ @@ -113,7 +113,7 @@ -void fill_file_header( +void fill_file_header( char **cDate, /* creation date */ char **mdate, /* modification date */ char **sasVer, /* SAS version number */ @@ -127,7 +127,7 @@ /* Line 2*/ blankCopy( file_header.sas_symbol1, 8, "SAS "); - blankCopy( file_header.sas_symbol2, 8, "SAS "); + blankCopy( file_header.sas_symbol2, 8, "SAS "); blankCopy( file_header.saslib, 8, "SASLIB "); blankCopy( file_header.sasver, 8, sasVer[0] ); zeroCopy ( file_header.sas_os, 8, osType[0] ); @@ -148,7 +148,7 @@ } -void fill_member_header( +void fill_member_header( char **dfName, /* Name of data set */ char **sasVer, /* SAS version number */ char **osType, /* Operating System */ @@ -220,19 +220,19 @@ int *nvar0, /* VARNUM */ char **nname, /* NAME OF VARIABLE */ char **nlabel, /* LABEL OF VARIABLE */ - + char **nform, /* NAME OF FORMAT */ int *nfl, /* FORMAT FIELD LENGTH OR 0 */ int *nfd, /* FORMAT NUMBER OF DECIMALS */ int *nfj, /* 0=LEFT JUSTIFICATION, 1=RIGHT JUST */ - + // char nfill[2], /* (UNUSED, FOR ALIGNMENT AND FUTURE) */ - + char **niform, /* NAME OF INPUT FORMAT */ int *nifl, /* INFORMAT LENGTH ATTRIBUTE */ int *nifd, /* INFORMAT NUMBER OF DECIMALS */ int *npos /* POSITION OF VALUE IN OBSERVATION */ - + // char rest[52], /* remaining fields are irrelevant */ ) { @@ -250,19 +250,19 @@ namestr_record.nfd = (short) *nfd; /* FORMAT NUMBER OF DECIMALS */ namestr_record.nfj = (short) *nfj; /* 0=LEFT JUSTIFICATION, 1=RIGHT JUST */ - zeroFill(namestr_record.nfill, 2); /* (UNUSED, FOR ALIGNMENT AND FUTURE) */ + zeroFill(namestr_record.nfill, 2); /* (UNUSED, FOR ALIGNMENT AND FUTURE) */ blankCopy(namestr_record.niform, 8, niform[0]); /* NAME OF INPUT FORMAT */ namestr_record.nifl = (short) *nifl; /* INFORMAT LENGTH ATTRIBUTE */ namestr_record.nifd = (short) *nifd; /* INFORMAT NUMBER OF DECIMALS */ - namestr_record.npos = (int) *npos; /* POSITION OF VALUE IN OBSERVATION */ + namestr_record.npos = (int) *npos; /* POSITION OF VALUE IN OBSERVATION */ zeroFill(namestr_record.rest, 52); /* remaining fields are irrelevant */ /* Flip byte order if necessary */ #define SHORTREV(a) REVERSE( &a, sizeof(short) ) -#define INTREV(a) REVERSE( &a, sizeof(int) ) +#define INTREV(a) REVERSE( &a, sizeof(int) ) SHORTREV( namestr_record.ntype ); SHORTREV( namestr_record.nhfun ); @@ -274,7 +274,7 @@ SHORTREV( namestr_record.nifl ); SHORTREV( namestr_record.nifd ); - INTREV ( namestr_record.npos ); + INTREV ( namestr_record.npos ); /* copy filled struct to return area */ memcpy( raw_buffer, &namestr_record, sizeof(namestr_record) ); @@ -284,13 +284,13 @@ return; } - - + + void fill_obs_header() { struct OBS_HEADER obs_header; - blankCopy( obs_header.l1, 80, + blankCopy( obs_header.l1, 80, "HEADER RECORD*******OBS HEADER RECORD!!!!!!!000000000000000000000000000000 "); /* copy filled struct to return area */ @@ -305,10 +305,10 @@ void fill_numeric_field( double *value /* single numeric value */ - ) + ) { /* convert to IBM floating point */ - + reverse( (unsigned char*) value, sizeof(double) ); ieee2ibm( (unsigned char *) raw_buffer, (unsigned char *) value, 1); @@ -320,11 +320,11 @@ return; } - + void fill_character_field( char **value, /* single character string */ int *width /* field width */ - ) + ) { /* copy to buffer */ blankCopy(raw_buffer, *width, value[0]); @@ -344,7 +344,7 @@ return; } - + void fill_space( int *type, /* 0 --> zero fill, 1 --> space fill */ int *width This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |