1 /*
2  * Copyright (c) 2017,2019 Daichi GOTO
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #define VERSION "20170902"
29 #define CMDNAME "conv_ssv2transposedssv"
30 #define ALIAS "transpose"
31 
32 #include "ttt.h"
33 
34 #define TGT_CHAR_PROCESS(C) \
35 	if (C == ' ') \
36 		++retu; \
37 	else if ((C == '\n') || \
38 	         (C == EOF && (p != '\n' && p != EOF)) || \
39 		 (C == EOF && p == EOF)) { \
40 		if (C == EOF && p == EOF) \
41 			retu = 0; \
42 		else \
43 			++retu; \
44 		if ((C == EOF && p == EOF && -1 == retumax) || \
45 		    retumax < retu) \
46 			retumax = retu; \
47 		retu = 0; \
48 	} \
49 	p = C;
50 
51 #define TGT_GYO_PROCESS(GYO_BUFFER,NF) \
52 	if (! (FILEPROCESS_GYO_FILESIZE_IS_ZERO)) { \
53 		p_ssvline->next = calloc(1, sizeof(struct ssvline)); \
54 		p_ssvline = p_ssvline->next; \
55 		p_ssvline->outputed = 0; \
56 		p_ssvline->nf = retumax; \
57 		p_ssvline->data = \
58 			calloc(p_ssvline->nf + 1, sizeof(char *)); \
59 		for (int i = 1; i <= retumax; i++) { \
60 			if (i > NF) { \
61 				p_ssvline->data[i] = \
62 			 		calloc(2, sizeof(char)); \
63 				p_ssvline->data[i][0] = '@'; \
64 				p_ssvline->data[i][1] = '\0'; \
65 			} \
66 			else { \
67 				p_ssvline->data[i] = \
68 					calloc(1, sizeof(char) * \
69 					(strlen(GYO_BUFFER[i]) + 1)); \
70 				strcpy(p_ssvline->data[i], \
71 					GYO_BUFFER[i]); \
72 			} \
73 		} \
74 	}
75