commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r921765 [2/2] - /commons/proper/daemon/trunk/src/native/unix/native/
Date Thu, 11 Mar 2010 10:03:33 GMT
Modified: commons/proper/daemon/trunk/src/native/unix/native/replace.c
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/unix/native/replace.c?rev=921765&r1=921764&r2=921765&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/unix/native/replace.c (original)
+++ commons/proper/daemon/trunk/src/native/unix/native/replace.c Thu Mar 11 10:03:32 2010
@@ -1,24 +1,25 @@
-/*
-   Licensed to the Apache Software Foundation (ASF) under one or more
-   contributor license agreements.  See the NOTICE file distributed with
-   this work for additional information regarding copyright ownership.
-   The ASF licenses this file to You under the Apache License, Version 2.0
-   (the "License"); you may not use this file except in compliance with
-   the License.  You may obtain a copy of the License at
- 
-       http://www.apache.org/licenses/LICENSE-2.0
- 
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-*/
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 /* @version $Id$ */
 #include "jsvc.h"
 
 /* Replace all occurrences of a string in another */
-int replace(char *new, int len, char *old, char *mch, char *rpl) {
+int replace(char *new, int len, char *old, char *mch, char *rpl)
+{
     char *tmp;
     int count;
     int shift;
@@ -29,82 +30,92 @@ int replace(char *new, int len, char *ol
     int x;
 
     /* The new buffer is NULL, fail */
-    if (new==NULL) return(-1);
+    if (new == NULL)
+        return -1;
     /* The length of the buffer is less than zero, fail */
-    if (len<0) return(-2);
+    if (len < 0)
+        return -2;
     /* The old buffer is NULL, fail */
-    if (old==NULL) return(-3);
+    if (old == NULL)
+        return -3;
 
     /* The string to be matched is NULL or empty, simply copy */
-    if ((mch==NULL)||(strlen(mch)==0)) {
-        olen=strlen(old);
-        if (len<=olen) return(olen+1);
-        strcpy(new,old);
-        return(0);
+    if ((mch == NULL) || (strlen(mch) == 0)) {
+        olen = strlen(old);
+        if (len <= olen)
+            return (olen + 1);
+        strcpy(new, old);
+        return 0;
     }
 
     /* The string to be replaced is NULL, assume it's an empty string */
-    if (rpl==NULL) rpl="";
+    if (rpl == NULL)
+        rpl = "";
 
     /* Evaluate some lengths */
-    olen=strlen(old);
-    mlen=strlen(mch);
-    rlen=strlen(rpl);
+    olen = strlen(old);
+    mlen = strlen(mch);
+    rlen = strlen(rpl);
 
     /* Calculate how many times the mch string appears in old */
-    tmp=old;
-    count=0;
-    while((tmp=strstr(tmp,mch))!=NULL) {
+    tmp = old;
+    count = 0;
+    while ((tmp = strstr(tmp, mch)) != NULL) {
         count++;
-        tmp+=mlen;
+        tmp += mlen;
     }
 
     /* We have no matches, simply copy */
-    if (count==0) {
-        olen=strlen(old);
-        if (len<=olen) return(olen+1);
-        strcpy(new,old);
-        return(0);
+    if (count == 0) {
+        olen = strlen(old);
+        if (len <= olen)
+            return (olen + 1);
+        strcpy(new, old);
+        return 0;
     }
 
     /* Calculate how big the buffer must be to hold the translation
-       and of how many bytes we need to shift the data */
-    shift=rlen-mlen;
-    nlen=olen+(shift*count);
+     * and of how many bytes we need to shift the data
+     */
+    shift = rlen - mlen;
+    nlen  = olen + (shift * count);
     /* printf("Count=%d Shift= %d OLen=%d NLen=%d\n",count,shift,olen,nlen); */
 
     /* Check if we have enough size in the buffer */
-    if (nlen>=len) return(nlen+1);
+    if (nlen >= len)
+        return (nlen + 1);
 
     /* Copy over the old buffer in the new one (save memory) */
-    strcpy(new,old);
+    strcpy(new, old);
 
     /* Start replacing */
-    tmp=new;
-    while((tmp=strstr(tmp,mch))!=NULL) {
+    tmp = new;
+    while ((tmp = strstr(tmp, mch)) != NULL) {
         /* If shift is > 0 we need to move data from right to left */
-        if (shift>0) {
-            for (x=(strlen(tmp)+shift);x>shift;x--) {
+        if (shift > 0) {
+            for (x = (strlen(tmp) + shift); x > shift; x--) {
                 /*
-                printf("src %c(%d) dst %c(%d)\n",
-                        tmp[x-shift],tmp[x-shift],tmp[x],tmp[x]);
+                   printf("src %c(%d) dst %c(%d)\n",
+                   tmp[x-shift],tmp[x-shift],tmp[x],tmp[x]);
                  */
-                tmp[x]=tmp[x-shift];
+                tmp[x] = tmp[x - shift];
             }
-        /* If shift is < 0 we need to move data from left to right */
-        } else if (shift<0) {
-            for (x=mlen;x<strlen(tmp)-shift;x++) {
+            /* If shift is < 0 we need to move data from left to right */
+        }
+        else if (shift < 0) {
+            for (x = mlen; x < strlen(tmp) - shift; x++) {
                 /*
                    printf("src %c(%d) dst %c(%d)\n",
-                          tmp[x],tmp[x],tmp[x+shift],tmp[x+shift]);
+                   tmp[x],tmp[x],tmp[x+shift],tmp[x+shift]);
                  */
-                tmp[x+shift]=tmp[x];
+                tmp[x + shift] = tmp[x];
             }
         }
         /* If shift is = 0 we don't have to shift data */
-        strncpy(tmp,rpl,rlen);
-        tmp+=rlen;
+        strncpy(tmp, rpl, rlen);
+        tmp += rlen;
         /* printf("\"%s\"\n",tmp); */
     }
-    return(0);
+    return 0;
 }
+

Modified: commons/proper/daemon/trunk/src/native/unix/native/replace.h
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/unix/native/replace.h?rev=921765&r1=921764&r2=921765&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/unix/native/replace.h (original)
+++ commons/proper/daemon/trunk/src/native/unix/native/replace.h Thu Mar 11 10:03:32 2010
@@ -1,19 +1,19 @@
-/*
-   Licensed to the Apache Software Foundation (ASF) under one or more
-   contributor license agreements.  See the NOTICE file distributed with
-   this work for additional information regarding copyright ownership.
-   The ASF licenses this file to You under the Apache License, Version 2.0
-   (the "License"); you may not use this file except in compliance with
-   the License.  You may obtain a copy of the License at
- 
-       http://www.apache.org/licenses/LICENSE-2.0
- 
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-*/
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 /* @version $Id$ */
 #ifndef __JSVC_REPLACE_H__
 #define __JSVC_REPLACE_H__
@@ -36,3 +36,4 @@
 int replace(char *new, int len, char *old, char *mch, char *rpl);
 
 #endif /* ifndef __JSVC_REPLACE_H__ */
+

Modified: commons/proper/daemon/trunk/src/native/unix/native/signals.c
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/unix/native/signals.c?rev=921765&r1=921764&r2=921765&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/unix/native/signals.c (original)
+++ commons/proper/daemon/trunk/src/native/unix/native/signals.c Thu Mar 11 10:03:32 2010
@@ -1,19 +1,19 @@
-/*
-   Licensed to the Apache Software Foundation (ASF) under one or more
-   contributor license agreements.  See the NOTICE file distributed with
-   this work for additional information regarding copyright ownership.
-   The ASF licenses this file to You under the Apache License, Version 2.0
-   (the "License"); you may not use this file except in compliance with
-   the License.  You may obtain a copy of the License at
- 
-       http://www.apache.org/licenses/LICENSE-2.0
- 
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-*/
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 /* @version $Id$ */
 
 /*
@@ -24,26 +24,27 @@
 #ifdef OS_CYGWIN
 #include <windows.h>
 #include <stdio.h>
-static void (*HandleTerm)(void)=NULL; /* address of the handler routine. */
+static void (*HandleTerm) (void) = NULL;        /* address of the handler routine. */
 
 /*
  * Event handling routine
  */
 void v_difthf(LPVOID par)
 {
-HANDLE hevint; /* make a local copy because the parameter is shared! */
+    HANDLE hevint;              /* make a local copy because the parameter is shared! */
 
-  hevint = (HANDLE) par;
+    hevint = (HANDLE) par;
 
-  for (;;) {
-    if (WaitForSingleObject(hevint,INFINITE) == WAIT_FAILED) {
-      /* something have gone wrong. */
-      return; /* may be something more is needed. */
-      }
-
-    /* call the interrupt handler. */
-    if (HandleTerm==NULL) return;
-    HandleTerm();
+    for (;;) {
+        if (WaitForSingleObject(hevint, INFINITE) == WAIT_FAILED) {
+            /* something have gone wrong. */
+            return;             /* may be something more is needed. */
+        }
+
+        /* call the interrupt handler. */
+        if (HandleTerm == NULL)
+            return;
+        HandleTerm();
     }
 }
 
@@ -51,50 +52,52 @@ HANDLE hevint; /* make a local copy beca
  * set a routine handler for the signal
  * note that it cannot be used to change the signal handler
  */
-int SetTerm(void (*func)(void))
+int SetTerm(void (*func) (void))
 {
-char Name[256];
-HANDLE hevint, hthread;
-DWORD ThreadId; 
-SECURITY_ATTRIBUTES sa;
-SECURITY_DESCRIPTOR sd;
-
-  sprintf(Name,"TERM%ld",GetCurrentProcessId());
-
-  /*
-   * event cannot be inherited.
-   * the event is reseted to nonsignaled after the waiting thread is released.
-   * the start state is resetted.
-   */
-
-  /* Initialize the new security descriptor. */
-  InitializeSecurityDescriptor (&sd, SECURITY_DESCRIPTOR_REVISION);
-
-  /* Add a NULL descriptor ACL to the security descriptor. */
-  SetSecurityDescriptorDacl (&sd, TRUE, (PACL)NULL, FALSE);
-
-  sa.nLength = sizeof(sa);
-  sa.lpSecurityDescriptor = &sd;
-  sa.bInheritHandle = TRUE;
-
-
-  /*  It works also with NULL instead &sa!! */
-  hevint = CreateEvent(&sa,FALSE, FALSE,Name);
-
-  HandleTerm = func;
-
-  if (hevint == NULL) return(-1); /* failed */
-
-  /* create the thread to wait for event */
-  hthread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE) v_difthf,
-                         (LPVOID) hevint, 0, &ThreadId);
-  if (hthread == NULL) {
-    /* failed remove the event */
-    CloseHandle(hevint); /* windows will remove it. */
-    return(-1);
+    char Name[256];
+    HANDLE hevint, hthread;
+    DWORD ThreadId;
+    SECURITY_ATTRIBUTES sa;
+    SECURITY_DESCRIPTOR sd;
+
+    sprintf(Name, "TERM%ld", GetCurrentProcessId());
+
+    /*
+     * event cannot be inherited.
+     * the event is reseted to nonsignaled after the waiting thread is released.
+     * the start state is resetted.
+     */
+
+    /* Initialize the new security descriptor. */
+    InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
+
+    /* Add a NULL descriptor ACL to the security descriptor. */
+    SetSecurityDescriptorDacl(&sd, TRUE, (PACL) NULL, FALSE);
+
+    sa.nLength = sizeof(sa);
+    sa.lpSecurityDescriptor = &sd;
+    sa.bInheritHandle = TRUE;
+
+
+    /*  It works also with NULL instead &sa!! */
+    hevint = CreateEvent(&sa, FALSE, FALSE, Name);
+
+    HandleTerm = func;
+
+    if (hevint == NULL)
+        return -1;            /* failed */
+
+    /* create the thread to wait for event */
+    hthread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) v_difthf,
+                           (LPVOID) hevint, 0, &ThreadId);
+    if (hthread == NULL) {
+        /* failed remove the event */
+        CloseHandle(hevint);    /* windows will remove it. */
+        return -1;
     }
 
-  CloseHandle(hthread); /* not needed */
-  return(0);
+    CloseHandle(hthread);       /* not needed */
+    return 0;
 }
 #endif
+

Modified: commons/proper/daemon/trunk/src/native/unix/native/signals.h
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/unix/native/signals.h?rev=921765&r1=921764&r2=921765&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/unix/native/signals.h (original)
+++ commons/proper/daemon/trunk/src/native/unix/native/signals.h Thu Mar 11 10:03:32 2010
@@ -28,7 +28,7 @@
  * @param func The function to call on termination
  * @return Zero on success, a value less than 0 if an error was encountered
  */
-int SetTerm(void (*func)(void));
+int SetTerm(void (*func) (void));
 
 #endif
 #endif /* ifndef __JSVC_SIGNALS_H__ */

Modified: commons/proper/daemon/trunk/src/native/unix/native/version.h
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/unix/native/version.h?rev=921765&r1=921764&r2=921765&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/unix/native/version.h (original)
+++ commons/proper/daemon/trunk/src/native/unix/native/version.h Thu Mar 11 10:03:32 2010
@@ -1,19 +1,19 @@
-/*
-   Licensed to the Apache Software Foundation (ASF) under one or more
-   contributor license agreements.  See the NOTICE file distributed with
-   this work for additional information regarding copyright ownership.
-   The ASF licenses this file to You under the Apache License, Version 2.0
-   (the "License"); you may not use this file except in compliance with
-   the License.  You may obtain a copy of the License at
- 
-       http://www.apache.org/licenses/LICENSE-2.0
- 
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-*/
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 #ifndef __VERSION_H__
 #define __VERSION_H__
 



Mime
View raw message