00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "emcmotcfg.h"
00015 #include "emcmot.h"
00016
00017
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
00050 return -1;
00051 }
00052
00053 errlog->head++;
00054
00055
00056
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
00085 return -1;
00086 }
00087
00088 errlog->head++;
00089
00090
00091
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