1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
/********************************************************************
* Description: emcmotutil.c
* Utility functions shared between motion and other systems
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
********************************************************************/
#include "emcmotcfg.h" /* EMCMOT_ERROR_NUM,LEN */
#include "motion.h" /* these decls */
#include "dbuf.h"
#include "stashf.h"
int emcmotErrorInit(emcmot_error_t * errlog)
{
if (errlog == 0) {
return -1;
}
errlog->head = 0;
errlog->start = 0;
errlog->end = 0;
errlog->num = 0;
errlog->tail = 0;
return 0;
}
int emcmotErrorPutfv(emcmot_error_t * errlog, const char *fmt, va_list ap)
{
struct dbuf errbuf;
struct dbuf_iter it;
if (errlog == 0 || errlog->num == EMCMOT_ERROR_NUM) {
/* full */
return -1;
}
errlog->head++;
dbuf_init(&errbuf, (unsigned char*)errlog->error[errlog->end], EMCMOT_ERROR_LEN);
dbuf_iter_init(&it, &errbuf);
vstashf(&it, fmt, ap);
errlog->end = (errlog->end + 1) % EMCMOT_ERROR_NUM;
errlog->num++;
errlog->tail = errlog->head;
return 0;
}
int emcmotErrorPutf(emcmot_error_t *errlog, const char *fmt, ...)
{
int result;
va_list ap;
va_start(ap, fmt);
result = emcmotErrorPutfv(errlog, fmt, ap);
va_end(ap);
return result;
}
int emcmotErrorPut(emcmot_error_t *errlog, const char *error)
{
return emcmotErrorPutf(errlog, "%s", error);
}
int emcmotErrorGet(emcmot_error_t * errlog, char *error)
{
if (errlog == 0 || errlog->num == 0) {
/* empty */
return -1;
}
errlog->head++;
memcpy(error, errlog->error[errlog->start], EMCMOT_ERROR_LEN);
errlog->start = (errlog->start + 1) % EMCMOT_ERROR_NUM;
errlog->num--;
errlog->tail = errlog->head;
return 0;
}
|