-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsi_print.c
More file actions
91 lines (78 loc) · 2.62 KB
/
si_print.c
File metadata and controls
91 lines (78 loc) · 2.62 KB
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
90
91
/*****************************************************************************
* Sportident C library function
*
*
* Author: Martin Horak
* Version: 1.0
* Date: 7.4.2012
*
* Changes:
****************************************************************************/
/****************************************************************************
* Includes
****************************************************************************/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "si_base.h"
#include "si_print.h"
/****************************************************************************
* Functions
****************************************************************************/
void si_print_card(struct s_sidata *card, FILE *stream){
int i;
char time[16];
fputs("===================================\n", stream);
fprintf(stream, "SI: %d (type %d)\n", card->cardnum, card->cardtype);
fprintf(stream, "Name: %s %s\n", card->fname, card->lname);
fputs("===================================\n", stream);
fprintf(stream, "Clear: %s\n", si_timestr(time, &card->clear));
fprintf(stream, "Check: %s\n", si_timestr(time, &card->check));
fprintf(stream, "Start: %s\n", si_timestr(time, &card->start));
fprintf(stream, "Finish: %s\n", si_timestr(time, &card->finish));
fputs("-----------------------------------\n", stream);
for(i = 0; i < card->npunch; i++){
fprintf(stream, "%3d ... %s\n", card->punches[i].cn, si_timestr(time, &card->punches[i]));
}
fputs("===================================\n", stream);
}
char *si_makepost_card(struct s_sidata *card){
char *outdata;
int size = 1;
char time[16];
/* count buffer size */
/* si_number, si_type */
size += 17 + 10;
/* si_lname */
if(card->lname){
size += 9 + strlen(card->lname);
}
/* si_fname */
if(card->fname){
size += 9 + strlen(card->fname);
}
/* tm_clear, tm_check, tm_start, tm_finish */
size += 9 + 9 + 9 + 10 + 4*8;
if((outdata = (char *) malloc(size)) == NULL) return NULL;
sprintf(outdata, "si_number=%d&si_type=%d", card->cardnum, card->cardtype);
if(card->lname){
strcat(outdata, "&si_lname=");
strcat(outdata, card->lname);
}
if(card->fname){
strcat(outdata, "&si_fname=");
strcat(outdata, card->fname);
}
strcat(outdata, "&tm_clear=");
strcat(outdata, si_timestr(time, &card->clear));
strcat(outdata, "&tm_check=");
strcat(outdata, si_timestr(time, &card->check));
strcat(outdata, "&tm_start=");
strcat(outdata, si_timestr(time, &card->start));
strcat(outdata, "&tm_finish=");
strcat(outdata, si_timestr(time, &card->finish));
return outdata;
}
void si_freepost(char *outdata){
free(outdata);
}