Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

emcmotutil.c

Go to the documentation of this file.
00001 /*
00002   emcmotutil.c
00003 
00004   Utility functions shared between motion and other systems
00005 
00006   Modification history:
00007 
00008   14-Aug-2000  FMP added check of errlog ptr for 0
00009   13-Mar-2000 WPS added unused attribute to pid_h to avoid 'defined but
00010   not used' compiler warning.
00011   12-Feb-1998  FMP created
00012   */
00013 
00014 #include "emcmotcfg.h"          /* EMCMOT_ERROR_NUM,LEN */
00015 #include "emcmot.h"             /* these decls */
00016 
00017 /* ident tag */
00018 #ifndef __GNUC__
00019 #ifndef __attribute__
00020 #define __attribute__(x)
00021 #endif
00022 #endif
00023 
00024 static char __attribute__((unused)) ident[] = "$Id: emcmotutil.c,v 1.4 2001/06/11 17:57:22 wshackle Exp $";
00025 
00026 int emcmotErrorInit(EMCMOT_ERROR *errlog)
00027 {
00028   if (errlog == 0) {
00029     return -1;
00030   }
00031 
00032   errlog->head = 0;
00033   errlog->start = 0;
00034   errlog->end = 0;
00035   errlog->num = 0;
00036   errlog->tail = 0;
00037 
00038   return 0;
00039 }
00040 
00041 int emcmotErrorPut(EMCMOT_ERROR *errlog, const char *error)
00042 {
00043   char *p1;
00044   const char *p2;
00045   int i;
00046 
00047   if (errlog == 0 ||
00048       errlog->num == EMCMOT_ERROR_NUM) {
00049     /* full */
00050     return -1;
00051   }
00052 
00053   errlog->head++;
00054 
00055   // strncpy(errlog->error[errlog->end], error, EMCMOT_ERROR_LEN);
00056   // replaced strncpy with manual copy
00057   p1=errlog->error[errlog->end];
00058   p2=error;
00059   i=0;
00060   while(*p2 && i < EMCMOT_ERROR_LEN)
00061     {
00062       *p1 = *p2;
00063       p1++;
00064       p2++;
00065       i++;
00066     }
00067   *p1=0;
00068 
00069   errlog->end = (errlog->end + 1) % EMCMOT_ERROR_NUM;
00070   errlog->num++;
00071 
00072   errlog->tail = errlog->head;
00073 
00074   return 0;
00075 }
00076 
00077 int emcmotErrorGet(EMCMOT_ERROR *errlog, char *error)
00078 {
00079   char *p1;
00080   const char *p2;
00081   int i;
00082   if (errlog == 0 ||
00083       errlog->num == 0) {
00084       /* empty */
00085       return -1;
00086   }
00087 
00088   errlog->head++;
00089 
00090   //  strncpy(error, errlog->error[errlog->start], EMCMOT_ERROR_LEN);  
00091   // replaced strncpy with manual copy
00092   p1=error;
00093   p2=errlog->error[errlog->start];
00094   i=0;
00095   while(*p2 && i < EMCMOT_ERROR_LEN)
00096     {
00097       *p1 = *p2;
00098       p1++;
00099       p2++;
00100       i++;
00101     }
00102   *p1=0;
00103 
00104 
00105   errlog->start = (errlog->start + 1) % EMCMOT_ERROR_NUM;
00106   errlog->num--;
00107 
00108   errlog->tail = errlog->head;
00109 
00110   return 0;
00111 }
00112 
00113 
00114 
00115 

Generated on Sun Dec 2 15:27:39 2001 for EMC by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001