Skip to content

Commit

Permalink
Merge pull request #63 from donald/work
Browse files Browse the repository at this point in the history
Work
  • Loading branch information
donald authored Jul 6, 2017
2 parents 6f76562 + f15abe0 commit b5fe300
Show file tree
Hide file tree
Showing 8 changed files with 304 additions and 200 deletions.
27 changes: 27 additions & 0 deletions mx_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1304,3 +1304,30 @@ int mx_daemon(int nochdir, int noclose)
{
return daemon(nochdir, noclose);
}

void _mx_sort_linked_list (void **list, int (*cmp)(void *o1,void *o2), void ** getnextptr(void *o)) {

void *unsorted=*list;
void *sorted=NULL;

while (unsorted) {
void *o;
void **s_ptr;
void *s;

o=unsorted;
unsorted=*(getnextptr(o));

s_ptr=&sorted;
while(1) {
s=*s_ptr;
if (s==NULL || cmp(o,s)<0) {
break;
}
s_ptr=getnextptr(s);
}
*(getnextptr(o))=s;
*s_ptr=o;
}
*list=sorted;
}
4 changes: 4 additions & 0 deletions mx_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,8 @@ int mx_mkdir_p(char *path, mode_t mode);

int mx_daemon(int nochdir, int noclose);

void _mx_sort_linked_list(void **list, int (*cmp)(void *o1,void *o2), void ** (*getnextptr)(void *o));
#define mx_sort_linked_list(list,cmp,getnextptr) _mx_sort_linked_list((void **)(list),(int (*)(void *,void *))(cmp),(void ** (*)(void *))(getnextptr))


#endif
29 changes: 1 addition & 28 deletions mxq_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,45 +46,18 @@ int mx_log_print(char *msg, size_t len)
{
char timebuf[1024];

static char *lastmsg = NULL;
static size_t lastlen = 0;
static int cnt = 0;

if (!msg) {
mx_free_null(lastmsg);
return 0;
}

if (!len)
return 0;

if (!*msg)
return -(errno=EINVAL);

if (lastmsg && lastlen == len) {
if (mx_streq(msg, lastmsg)) {
cnt++;
mx_free_null(msg);
return 2;
}
}

timetag(timebuf, sizeof(timebuf));

if (cnt > 1)
fprintf(stderr, "%s %s[%d]: last message repeated %d times\n", timebuf, program_invocation_short_name, getpid(), cnt);
else if (cnt == 1)
fprintf(stderr, "%s %s[%d]: %s\n", timebuf, program_invocation_short_name, getpid(), lastmsg);

if (lastmsg)
mx_free_null(lastmsg);

lastmsg = msg;
lastlen = len;
cnt = 0;

fprintf(stderr, "%s %s[%d]: %s\n", timebuf, program_invocation_short_name, getpid(), msg);
fflush(stderr);
mx_free_null(msg);

return 1;
}
Loading

0 comments on commit b5fe300

Please sign in to comment.