JunkBox_Lib  1.10.2
tlist.c
Go to the documentation of this file.
1 
10 #include "tlist.h"
11 #include "jbxl_state.h"
12 
13 
15 // List Data
16 // 静的に生成される.
17 //
18 
27 {
28  tList_data pp;
29 
30  memset(&pp, 0, sizeof(tList_data));
31  return pp;
32 }
33 
34 
50 tList_data make_tList_data(int id, int lv, Buffer key, Buffer val, void* ptr, int sz)
51 {
52  tList_data pp;
53 
54  memset(&pp, 0, sizeof(tList_data));
55 
56  pp.id = id;
57  pp.lv = lv;
58  pp.sz = sz;
59  pp.key = dup_Buffer(key);
60  pp.val = dup_Buffer(val);
61 
62  if (sz>0) {
63  pp.ptr = (void*)malloc(sz);
64  if (pp.ptr!=NULL) {
65  if (ptr!=NULL) memcpy(pp.ptr, ptr, sz);
66  else memset(pp.ptr, 0, sz);
67  }
68  }
69 
70  return pp;
71 }
72 
73 
89 tList_data make_tList_data_bystr(int id, int lv, const char* key, const char* val, void* ptr, int sz)
90 {
91  tList_data pp;
92 
93  memset(&pp, 0, sizeof(tList_data));
94 
95  pp.id = id;
96  pp.lv = lv;
97  pp.sz = sz;
98  pp.key = make_Buffer_bystr(key); // key==NULLなら init_Buffer()
99  pp.val = make_Buffer_bystr(val);
100 
101  if (sz>0) {
102  pp.ptr = (void*)malloc(sz);
103  if (pp.ptr!=NULL) {
104  if (ptr!=NULL) memcpy(pp.ptr, ptr, sz);
105  else memset(pp.ptr, 0, sz);
106  }
107  }
108 
109  return pp;
110 }
111 
112 
121 {
122  if (ldat==NULL) return;
123 
124  ldat->id = 0;
125  ldat->lv = 0;
126  ldat->sz = 0;
127 
128  free_Buffer(&(ldat->key));
129  free_Buffer(&(ldat->val));
130  if (ldat->ptr!=NULL) free(ldat->ptr);
131  del_all_tList(&(ldat->lst));
132 
133  ldat->key = init_Buffer();
134  ldat->val = init_Buffer();
135  ldat->ptr = NULL;
136  ldat->lst = NULL;
137 
138  return;
139 }
140 
141 
150 {
151  if (ldat==NULL || *ldat==NULL) return;
152 
153  clear_tList_data(*ldat);
154  *ldat = NULL;
155 
156  return;
157 }
158 
159 
170 {
171  tList_data dup;
172 
173  memcpy(&dup, &ldat, sizeof(tList_data));
174  dup.key = dup_Buffer(ldat.key);
175  dup.val = dup_Buffer(ldat.val);
176  if (ldat.ptr!=NULL && ldat.sz>0) {
177  dup.ptr = (void*)malloc(ldat.sz);
178  if (dup.ptr!=NULL) memcpy(dup.ptr, ldat.ptr, ldat.sz);
179  }
180  dup.lst = dup_tList(ldat.lst);
181 
182  return dup;
183 }
184 
185 
186 
188 // Tiny List
189 //
190 
199 {
200  tList* pp;
201 
202  pp = (tList*)malloc(sizeof(tList));
203  if (pp==NULL) return NULL;
204  memset(pp, 0, sizeof(tList));
205  pp->ldat = init_tList_data();
206  pp->state = JBXL_NORMAL;
207 
208  return pp;
209 }
210 
211 
224 {
225  tList pp;
226 
227  memset(&pp, 0, sizeof(tList));
228  pp.ldat = ldat;
229  pp.state = JBXL_NORMAL;
230 
231  return pp;
232 }
233 
234 
244 {
245  if (node==NULL) return NULL;
246 
247  clear_tList_data(&(node->ldat));
248 
249  tList* pp = NULL;
250  if (node->prev!=NULL) node->prev->next = node->next;
251  if (node->next!=NULL) {
252  node->next->prev = node->prev;
253  pp = node->next;
254  }
255 
256  return pp;
257 }
258 
259 
271 {
272  if (node==NULL || *node==NULL) return NULL;
273 
274  tList* pp = free_tList_node(*node);
275  free(*node);
276  *node = NULL;
277 
278  return pp;
279 }
280 
281 
288 {
289  tList* pp;
290  int sz;
291 
292  if (node==NULL) return NULL;
293 
294  sz = sizeof(tList);
295  pp = (tList*)malloc(sz);
296  if (pp==NULL) return NULL;
297 
298  memcpy(pp, node, sz);
299  pp->ldat = dup_tList_data(node->ldat);
300  pp->next = NULL;
301  pp->prev = NULL;
302  pp->altp = NULL;
303  pp->yngr = NULL;
304  pp->esis = NULL;
305  pp->ysis = NULL;
306 
307  return pp;
308 }
309 
310 
322 {
323  if (pp==NULL || node==NULL) return NULL;
324 
325  if (node->prev!=NULL) node->prev->next = node->next;
326  if (node->next!=NULL) node->next->prev = node->prev;
327 
328  node->prev = pp;
329  node->next = pp->next;
330  if (pp->next!=NULL) pp->next->prev = node;
331  pp->next = node;
332 
333  return node;
334 }
335 
336 
343 {
344  if (pp1==NULL || pp2==NULL) return NULL;
345 
346  tList_data swp = pp1->ldat;
347  pp1->ldat = pp2->ldat;
348  pp2->ldat = swp;
349 
350  return pp1;
351 /*
352  if (*pp1==NULL || *pp2==NULL) return NULL;
353 
354  tList* p1 = dup_tList_node(*pp1);
355  tList* p2 = dup_tList_node(*pp2);
356 
357  insert_tList(*pp1, p2);
358  insert_tList(*pp2, p1);
359 
360  del_tList_node(pp1);
361  del_tList_node(pp2);
362 
363  *pp1 = p2;
364  *pp2 = p1;
365 
366  return p2;
367 */
368 }
369 
370 
372 {
373  tList* pp;
374 
375  pp = (tList*)malloc(sizeof(tList));
376  if (pp==NULL) return NULL;
377  memset(pp, 0, sizeof(tList));
378  pp->ldat = init_tList_data();
379  pp->ldat.id = TLIST_ANCHOR_NODE;
380  pp->depth = -1;
381  pp->state = JBXL_STATE_ANCHOR; // TLIST_ANCHOR_NODE と同じ
382 
383  return pp;
384 }
385 
386 
388 {
389  tList* pp = node;
390 
391  if (node!=NULL && node->ldat.id==TLIST_ANCHOR_NODE) {
392  pp = node->next;
393  free_tList_node(node);
394  free(node);
395  }
396 
397  return pp;
398 }
399 
400 
401 
403 
418 {
419  tList* pt;
420 
421  pt = new_tList_node();
422  pt->ldat = ldat;
423 
424  if (pp==NULL) {
425  return pt;
426  }
427  //
428  if (pp->next==NULL) {
429  pt->next = NULL;
430  pt->prev = pp;
431  pp->next = pt;
432  return pt;
433  }
434 
435  pt->next = pp->next;
436  pt->prev = pp;
437  pp->next = pt;
438  pt->next->prev = pt;
439 
440  return pt;
441 }
442 
443 
462 tList* add_tList_node_bystr(tList* pp, int id, int lv, const char* key, const char* val, void* ptr, int sz)
463 {
464  tList* pt;
465  tList_data ldat;
466 
467  ldat = make_tList_data_bystr(id, lv, key, val, ptr, sz);
468  pt = add_tList_node_bydata(pp, ldat);
469 
470  return pt;
471 }
472 
473 
492 tList* add_tList_node_byBuffer(tList* pp, int id, int lv, Buffer key, Buffer val, void* ptr, int sz)
493 {
494  tList* pt;
495  tList_data ldat;
496 
497  ldat = make_tList_data(id, lv, key, val, ptr, sz);
498  pt = add_tList_node_bydata(pp, ldat);
499 
500  return pt;
501 }
502 
503 
514 {
515  if (node==NULL) return;
516 
517  clear_tList_data(&(node->ldat));
518  node->ldat = dat;
519 }
520 
521 
536 void set_tList_node_bystr(tList* pp, int id, int lv, const char* key, const char* val, void* ptr, int sz)
537 {
538  if (pp==NULL) return;
539 
540  pp->ldat.id = id;
541  pp->ldat.lv = lv;
542  pp->ldat.sz = sz;
543 
544  if (key!=NULL) {
545  free_Buffer(&(pp->ldat.key));
546  pp->ldat.key = make_Buffer_bystr(key);
547  }
548  if (val!=NULL) {
549  free_Buffer(&(pp->ldat.val));
550  pp->ldat.val = make_Buffer_bystr(val);
551  }
552 
553  if (sz>0 && ptr!=NULL) {
554  if (pp->ldat.ptr!=NULL) free(pp->ldat.ptr);
555  pp->ldat.ptr = (void*)malloc(sz);
556  if (pp->ldat.ptr!=NULL) memcpy(pp->ldat.ptr, ptr, sz);
557  }
558 }
559 
560 
575 void set_tList_node_byBuffer(tList* pp, int id, int lv, Buffer key, Buffer val, void* ptr, int sz)
576 {
577  if (pp==NULL) return;
578 
579  pp->ldat.id = id;
580  pp->ldat.lv = lv;
581 
582  if (pp->ldat.key.buf!=NULL) {
583  free_Buffer(&(pp->ldat.key));
584  pp->ldat.key = dup_Buffer(key);
585  }
586 
587  if (pp->ldat.val.buf!=NULL) {
588  free_Buffer(&(pp->ldat.val));
589  pp->ldat.val = dup_Buffer(val);
590  }
591 
592  if (sz>0 && ptr!=NULL) {
593  if (pp->ldat.ptr!=NULL) free(pp->ldat.ptr);
594  pp->ldat.ptr = (void*)malloc(sz);
595  if (pp->ldat.ptr!=NULL) memcpy(pp->ldat.ptr, ptr, sz);
596  }
597 }
598 
599 
610 {
611  tList* pm;
612  tList_data ldat;
613 
614  if (pt==NULL) return pp;
615 
616  ldat = pp->ldat;
617  pm = update_tList_node_byBuffer(pp, ldat.id, ldat.lv, ldat.key, ldat.val, ldat.ptr, ldat.sz);
618 
619  return pm;
620 }
621 
622 
636 {
637  tList* pm = NULL;
638 
639  if (pp==NULL || srch==NULL) return NULL;
640 
641  pm = strncmp_tList(pp, srch, 0, 1);
642  if (pm!=NULL) set_tList_node_bydata(pm, ldat);
643  else {
644  pm = find_tList_end(pp);
645  pm = add_tList_node_bydata(pm, ldat);
646  }
647 
648  return pm;
649 }
650 
651 
668 tList* update_tList_node_bystr(tList* pp, int id, int lv, const char* key, const char* val, void* ptr, int sz)
669 {
670  tList* pm = NULL;
671 
672  if (pp==NULL || key==NULL) return NULL;
673 
674  pm = strncmp_tList(pp, key, 0, 1);
675  if (pm!=NULL) {
676  set_tList_node_bystr(pm, id, lv, NULL, val, ptr, sz);
677  }
678  else {
679  pm = find_tList_end(pp);
680  pm = add_tList_node_bystr(pm, id, lv, key, val, ptr, sz);
681  }
682 
683  return pm;
684 }
685 
686 
703 tList* update_tList_node_byBuffer(tList* pp, int id, int lv, Buffer key, Buffer val, void* ptr, int sz)
704 {
705  tList* pm = NULL;
706 
707  if (pp==NULL || key.buf==NULL) return NULL;
708 
709  pm = strncmp_tList(pp, (char*)key.buf, 0, 1);
710  if (pm!=NULL) set_tList_node_byBuffer(pm, id, lv, key, val, ptr, sz);
711  else {
712  pm = find_tList_end(pp);
713  pm = add_tList_node_byBuffer(pm, id, lv, key, val, ptr, sz);
714  }
715 
716  return pm;
717 }
718 
719 
720 
722 // tiny List
723 //
724 
736 {
737  tList* pt;
738  tList* pm;
739  tList* pw;
740 
741  if (pp==NULL || *pp==NULL) return NULL;
742 
743  pt = (*pp)->prev;
744  if (pt!=NULL) pt->next = NULL;
745 
746  pm = *pp;
747  while (pm!=NULL) {
748  pw = pm;
749  pm = pm->next;
750  clear_tList_data(&(pw->ldat));
751  free(pw);
752  }
753  *pp = NULL;
754 
755  return pt;
756 }
757 
758 
770 {
771  tList* pm;
772  tList* pv;
773 
774  if (pp==NULL || *pp==NULL) return;
775 
776  pm = *pp;
777  pv = (*pp)->prev;
778 
779  do {
780  pm = del_tList_node(&pm);
781  } while (pm!=NULL);
782 
783  pm = pv;
784  while (pm!=NULL) {
785  pv = pm->prev;
786  del_tList_node(&pm);
787  pm = pv;
788  }
789 
790  *pp = NULL;
791 }
792 
793 
805 int del_tList_key(tList** pl, const char* key, int no)
806 {
807  int dl = 0;
808  int nn = 0;
809  if (no<0) no = 0;
810 
811  tList* pp = *pl;
812 
813  while (pp!=NULL) {
814  if (ex_strncasecmp((char*)(pp->ldat).key.buf, key, 0)) {
815  nn++;
816  if (no==0 || no==nn) {
817  if (pp->prev==NULL) *pl = pp->next;
818  pp = del_tList_node(&pp);
819  dl++;
820  if (no!=0) break;
821  }
822  else {
823  pp = pp->next;
824  }
825  }
826  else {
827  pp = pp->next;
828  }
829  }
830 
831  return dl;
832 }
833 
834 
844 {
845  tList* pt;
846  tList* pl;
847  tList* tt;
848 
849  if (pp==NULL) return NULL;
850 
851  pt = pl = dup_tList_node(pp);
852  pp = pp->next;
853 
854  while(pp!=NULL) {
855  tt = dup_tList_node(pp);
856  pl = insert_tList(pl, tt);
857  pp = pp->next;
858  }
859 
860  return pt;
861 }
862 
863 
878 {
879  if (pt==NULL) return pp;
880  if (pp==NULL) return pt;
881 
882  tList* pe = find_tList_end(pp);
883  pe->next = pt;
884  pt->prev = pe;
885 
886  return pp;
887 }
888 
889 
904 {
905  tList* pe;
906 
907  if (pt==NULL) return pp;
908  if (pp==NULL) return pt;
909 
910  pe = find_tList_end(pt);
911  if (pp->next!=NULL) pp->next->prev = pe;
912  pe->next = pp->next;
913  pp->next = pt;
914  pt->prev = pp;
915 
916  return pt;
917 }
918 
919 
928 void print_tList(FILE* fp, tList* pp)
929 {
930  if (fp==NULL) fp = stderr;
931 
932  if (pp!=NULL) {
933  while(pp!=NULL) {
934  tList_data ld = pp->ldat;
935  fprintf(fp, "[%d] [%d] [%s] [%s]\n", ld.id, ld.lv, ld.key.buf, ld.val.buf);
936  //if (pp->next!=NULL) print_tList(pp->next);
937  pp = pp->next;
938  }
939  }
940  else {
941  fprintf(fp, "(List is NULL)\n");
942  }
943  return;
944 }
945 
946 
952 void dump_tList(FILE* fp, tList* pp)
953 {
954  if (fp==NULL) fp = stderr;
955 
956  if (pp!=NULL) {
957  while(pp!=NULL) {
958  tList_data ld = pp->ldat;
959  fprintf(fp, "[%d] [%d] [%s] [%d]\n", ld.id, ld.lv, ld.key.buf, ld.val.vldsz);
960  fdump(fp, (unsigned char*)ld.val.buf, ld.val.vldsz);
961  pp = pp->next;
962  }
963  }
964  else {
965  fprintf(fp, "(List is NULL)\n");
966  }
967  return;
968 }
969 
970 
980 {
981  int cnt = 0;
982 
983  while (pp!=NULL) {
984  cnt++;
985  pp = pp->next;
986  }
987  return cnt;
988 }
989 
990 
991 
993 
1003 {
1004  if (pl==NULL) return NULL;
1005 
1006  while (pl->prev!=NULL) pl = pl->prev;
1007  return pl;
1008 }
1009 
1010 
1024 {
1025  if (pl==NULL) return NULL;
1026 
1027  while (pl->next!=NULL) pl = pl->next;
1028  return pl;
1029 }
1030 
1031 
1032 
1034 // String Compare
1035 //
1036 
1056 tList* strncmp_tList(tList* pl, const char* key, int len, int no)
1057 {
1058  int nn = 0;
1059 
1060  if (pl==NULL || key==NULL) return NULL;
1061  if (len<=-3) return NULL;
1062  if (no<=0) no = 1;
1063 
1064  while (pl!=NULL) {
1065  if (ex_strncmp((char*)pl->ldat.key.buf, key, len)) {
1066  nn++;
1067  if (no==nn) return pl;
1068  }
1069  pl = pl->next;
1070  }
1071  return NULL;
1072 }
1073 
1074 
1094 tList* strncasecmp_tList(tList* pl, const char* key, int len, int no)
1095 {
1096  int nn = 0;
1097 
1098  if (pl==NULL || key==NULL) return NULL;
1099  if (len<=-3) return NULL;
1100  if (no<=0) no = 1;
1101 
1102  while (pl!=NULL) {
1103  if (ex_strncasecmp((char*)(pl->ldat).key.buf, key, len)) {
1104  nn++;
1105  if (no==nn) return pl;
1106  }
1107  pl = pl->next;
1108  }
1109  return NULL;
1110 }
1111 
1112 
1132 tList* strnrvscmp_tList(tList* pl, const char* key, int len, int no)
1133 {
1134  int nn = 0;
1135 
1136  if (pl==NULL || key==NULL) return NULL;
1137  if (len<=-3) return NULL;
1138  if (no<=0) no = 1;
1139 
1140  while (pl!=NULL) {
1141  if (ex_strnrvscmp((char*)(pl->ldat).key.buf, key, len)) {
1142  nn++;
1143  if (no==nn) return pl;
1144  }
1145  pl = pl->next;
1146  }
1147  return NULL;
1148 }
1149 
1150 
1170 tList* strncaservscmp_tList(tList* pl, const char* key, int len, int no)
1171 {
1172  int nn = 0;
1173 
1174  if (pl==NULL || key==NULL) return NULL;
1175  if (len<=-3) return NULL;
1176  if (no<=0) no = 1;
1177 
1178  while (pl!=NULL) {
1179  if (ex_strncaservscmp((char*)(pl->ldat).key.buf, key, len)) {
1180  nn++;
1181  if (no==nn) return pl;
1182  }
1183  pl = pl->next;
1184  }
1185  return NULL;
1186 }
1187 
1188 
1206 tList* strstr_tList(tList* pl, const char* key, int len, int no)
1207 {
1208  int nn = 0;
1209 
1210  if (pl==NULL || key==NULL) return NULL;
1211  if (no<=0) no = 1;
1212 
1213  while (pl!=NULL) {
1214  if (len>=0) {
1215  if (strstr((char*)(pl->ldat).key.buf, key)!=NULL) {
1216  nn++;
1217  if (no==nn) return pl;
1218  }
1219  }
1220  else if (len<0) {
1221  if (strstr(key, (char*)(pl->ldat).key.buf)!=NULL) {
1222  nn++;
1223  if (no==nn) return pl;
1224  }
1225  }
1226 
1227  pl = pl->next;
1228  }
1229  return NULL;
1230 }
1231 
1232 
1250 tList* strstrcase_tList(tList* pl, const char* key, int len, int no)
1251 {
1252  int nn = 0;
1253 
1254  if (pl==NULL || key==NULL) return NULL;
1255  if (no<=0) no = 1;
1256 
1257  while (pl!=NULL) {
1258  if (len>=0) {
1259  if (strstrcase((char*)(pl->ldat).key.buf, key)!=NULL) {
1260  nn++;
1261  if (no==nn) return pl;
1262  }
1263  }
1264  else if (len<0) {
1265  if (strstrcase(key, (char*)(pl->ldat).key.buf)!=NULL) {
1266  nn++;
1267  if (no==nn) return pl;
1268  }
1269  }
1270 
1271  pl = pl->next;
1272  }
1273  return NULL;
1274 }
1275 
1276 
1277 
1279 // String Compare Back List
1280 //
1281 
1299 tList* strncmp_back_tList(tList* pl, const char* key, int len, int no)
1300 {
1301  int nn = 0;
1302 
1303  if (pl==NULL || key==NULL) return NULL;
1304  if (len<=-3) return NULL;
1305  if (no<=0) no = 1;
1306 
1307  pl = find_tList_end(pl);
1308 
1309  while (pl!=NULL) {
1310  if (ex_strncmp((char*)(pl->ldat).key.buf, key, len)) {
1311  nn++;
1312  if (no==nn) return pl;
1313  }
1314  pl = pl->prev;
1315  }
1316  return NULL;
1317 }
1318 
1319 
1337 tList* strncasecmp_back_tList(tList* pl, const char* key, int len, int no)
1338 {
1339  int nn = 0;
1340 
1341  if (pl==NULL || key==NULL) return NULL;
1342  if (len<=-3) return NULL;
1343  if (no<=0) no = 1;
1344 
1345  pl = find_tList_end(pl);
1346 
1347  while (pl!=NULL) {
1348  if (ex_strncasecmp((char*)(pl->ldat).key.buf, key, len)) {
1349  nn++;
1350  if (no==nn) return pl;
1351  }
1352  pl = pl->prev;
1353  }
1354  return NULL;
1355 }
1356 
1357 
1375 tList* strnrvscmp_back_tList(tList* pl, const char* key, int len, int no)
1376 {
1377  int nn = 0;
1378 
1379  if (pl==NULL || key==NULL) return NULL;
1380  if (len<=-3) return NULL;
1381  if (no<=0) no = 1;
1382 
1383  pl = find_tList_end(pl);
1384 
1385  while (pl!=NULL) {
1386  if (ex_strnrvscmp((char*)(pl->ldat).key.buf, key, len)) {
1387  nn++;
1388  if (no==nn) return pl;
1389  }
1390  pl = pl->prev;
1391  }
1392  return NULL;
1393 }
1394 
1395 
1413 tList* strncaservscmp_back_tList(tList* pl, const char* key, int len, int no)
1414 {
1415  int nn = 0;
1416 
1417  if (pl==NULL || key==NULL) return NULL;
1418  if (len<=-3) return NULL;
1419  if (no<=0) no = 1;
1420 
1421  pl = find_tList_end(pl);
1422 
1423  while (pl!=NULL) {
1424  if (ex_strncaservscmp((char*)(pl->ldat).key.buf, key, len)) {
1425  nn++;
1426  if (no==nn) return pl;
1427  }
1428  pl = pl->prev;
1429  }
1430  return NULL;
1431 }
1432 
1433 
1451 tList* strstr_back_tList(tList* pl, const char* key, int len, int no)
1452 {
1453  int nn = 0;
1454 
1455  if (pl==NULL || key==NULL) return NULL;
1456  if (no<=0) no = 1;
1457 
1458  pl = find_tList_end(pl);
1459 
1460  while (pl!=NULL) {
1461  if (len>=0) {
1462  if (strstr((char*)(pl->ldat).key.buf, key)!=NULL) {
1463  nn++;
1464  if (no==nn) return pl;
1465  }
1466  }
1467  else if (len<0) {
1468  if (strstr(key, (char*)(pl->ldat).key.buf)!=NULL) {
1469  nn++;
1470  if (no==nn) return pl;
1471  }
1472  }
1473 
1474  pl = pl->prev;
1475  }
1476  return NULL;
1477 }
1478 
1479 
1497 tList* strstrcase_back_tList(tList* pl, const char* key, int len, int no)
1498 {
1499  int nn = 0;
1500 
1501  if (pl==NULL || key==NULL) return NULL;
1502  if (no<=0) no = 1;
1503 
1504  pl = find_tList_end(pl);
1505 
1506  while (pl!=NULL) {
1507  if (len>=0) {
1508  if (strstrcase((char*)(pl->ldat).key.buf, key)!=NULL) {
1509  nn++;
1510  if (no==nn) return pl;
1511  }
1512  }
1513  else if (len<0) {
1514  if (strstrcase(key, (char*)(pl->ldat).key.buf)!=NULL) {
1515  nn++;
1516  if (no==nn) return pl;
1517  }
1518  }
1519 
1520  pl = pl->prev;
1521  }
1522  return NULL;
1523 }
1524 
1525 
1526 
1528 
1541 tList* search_id_tList(tList* pl, int id, int no)
1542 {
1543  int nn = 0;
1544 
1545  if (pl==NULL) return NULL;
1546  if (no<=0) no = 1;
1547 
1548  while (pl!=NULL) {
1549  if (pl->ldat.id == id) {
1550  nn++;
1551  if (no==nn) return pl;
1552  }
1553  pl = pl->next;
1554  }
1555  return NULL;
1556 }
1557 
1558 
1571 tList* search_key_tList(tList* pl, const char* key, int no)
1572 {
1573  tList* pp;
1574  if (pl==NULL || key==NULL) return NULL;
1575  if (no<=0) no = 1;
1576 
1577  pp = strncasecmp_tList(pl, key, 0, no); // 完全一致
1578 
1579  return pp;
1580 }
1581 
1582 
1595 Buffer buffer_key_tList(tList* list, const char* key, int no)
1596 {
1597  tList* pp;
1598  Buffer buf;
1599 
1600  buf = init_Buffer();
1601  if (list==NULL || key==NULL) return buf;
1602  if (no<=0) no = 1;
1603 
1604  pp = strncasecmp_tList(list, key, 0, no); // 完全一致
1605  if (pp!=NULL) {
1606  buf = dup_Buffer(pp->ldat.val);
1607  }
1608 
1609  return buf;
1610 }
1611 
1612 
1626 Buffer buffer_key_value_tList(tList* list, const char* key, char* data, int no)
1627 {
1628  tList* pp;
1629  Buffer buf;
1630  char* str;
1631  int len;
1632 
1633  buf = init_Buffer();
1634  if (list==NULL || key==NULL) return buf;
1635  if (no<=0) no = 1;
1636 
1637  if (data==NULL) {
1638  buf = buffer_key_tList(list, key, no);
1639  return buf;
1640  }
1641 
1642  buf = init_Buffer();
1643  len = (int)strlen(data);
1644 
1645  pp = strncasecmp_tList(list, key, 0, no);
1646  if (pp!=NULL) {
1647  str = (char*)pp->ldat.val.buf;
1648  if (str!=NULL && !strncasecmp(str, data, len)) {
1649  buf = make_Buffer_bystr(str);
1650  return buf;
1651  }
1652  }
1653 
1654  return buf;
1655 }
1656 
1657 
1658 /*
1659 int set_value_tList(tList* list, const char* key, int no, const char* value, int add_mode)
1660 
1661 リスト(lt)中の no番目の keyノードの値に valueを設定する.
1662 
1663 no が 0以下の場合は,全ての keyノードの値に対して設定が行われる.@n
1664 keyノードが存在せず,かつ mode==ON の場合は,リストの最後に追加される.
1665 
1666 @param list 処理対象のリスト
1667 @param key 設定を行うノードのキー部.大文字,小文字を区別しない.
1668 @param value 設定される文字列.
1669 @param no keyが一致する何個目のノードに対して設定を行うか.1から数える.0以下の場合はkeyが一致するすべてのノードに対して設定を行う.
1670 @param add_mod この値がON かつ指定したノードが無い場合,ノードをリストの最後に追加する.
1671 
1672 @retval 設定されたノードの数 指定されたノードが存在しない場合は(追加された場合も)0
1673 @retval 負数 エラー
1674 */
1675 int set_value_tList(tList* list, const char* key, int no, const char* value, int add_mode)
1676 {
1677  int cn = 0;
1678  tList* pm;
1679 
1680  if (list==NULL || key==NULL || value==NULL) return JBXL_ARGS_ERROR;
1681 
1682  if (no>0) {
1683  pm = strncasecmp_tList(list, key, 0, no);
1684  if (pm!=NULL) {
1685  int rep = set_value_tList_node(pm, value);
1686  if (rep) cn = 1;
1687  }
1688  }
1689  else { // no<=0
1690  int nn = 1;
1691  cn = 0;
1692  pm = strncasecmp_tList(list, key, 0, nn);
1693  while (pm!=NULL) {
1694  int rep = set_value_tList_node(pm, value);
1695  if (rep) cn++;
1696  pm = strncasecmp_tList(list, key, 0, ++nn);
1697  }
1698  }
1699 
1700  // Not Found
1701  if (add_mode==ON && cn==0) {
1702  add_tList_node_str(list, key, value);
1703  }
1704 
1705  return cn;
1706 }
1707 
1708 
1714 int set_value_tList_node(tList* lp, const char* value)
1715 {
1716  if (lp==NULL || value==NULL) return FALSE;
1717 
1718  Buffer buf = make_Buffer_bystr(value);
1719  free_Buffer(&lp->ldat.val);
1720  lp->ldat.val = buf;
1721 
1722  return TRUE;
1723 }
1724 
1725 
1742 int replace_value_tList(tList* list, const char* key, int no, const char* srcval, char* value)
1743 {
1744  int cn = 0;
1745  tList* pm;
1746 
1747  if (list==NULL || key==NULL || value==NULL) return JBXL_ARGS_ERROR;
1748  if (srcval==NULL) {
1749  return set_value_tList(list, key, no, value, OFF);
1750  }
1751 
1752  if (no>0) {
1753  pm = strncasecmp_tList(list, key, 0, no);
1754  if (pm!=NULL) {
1755  int rep = replace_value_tList_node(pm, srcval, value);
1756  if (rep) cn = 1;
1757  }
1758  }
1759  else { // no<=0
1760  int nn = 1;
1761  cn = 0;
1762  pm = strncasecmp_tList(list, key, 0, nn);
1763  while (pm!=NULL) {
1764  int rep = replace_value_tList_node(pm, srcval, value);
1765  if (rep) cn++;
1766  pm = strncasecmp_tList(list, key, 0, ++nn);
1767  }
1768  }
1769 
1770  return cn;
1771 }
1772 
1773 
1779 int replace_value_tList_node(tList* lp, const char* srcval, const char* value)
1780 {
1781  if (lp==NULL || value==NULL) return FALSE;
1782  if (srcval==NULL) {
1783  return set_value_tList_node(lp, value);
1784  }
1785 
1786  Buffer buf = replace_sBuffer(lp->ldat.val, srcval, value);
1787  free_Buffer(&lp->ldat.val);
1788  lp->ldat.val = buf;
1789 
1790  return TRUE;
1791 }
1792 
1793 
1805 tList* awk_tList(char* str, char cc)
1806 {
1807  int nn = 1;
1808  char* item;
1809  tList* lp = NULL;
1810 
1811  if (str==NULL) return NULL;
1812 
1813  lp = add_tList_node_bystr(NULL, 1, 0, NULL, NULL, NULL, 0);
1814 
1815  // first item
1816  item = awk(str, cc, nn);
1817  if (item==NULL) return lp;
1818  lp->ldat.key = make_Buffer_bystr(item);
1819 
1820  //
1821  item = awk(str, cc, ++nn);
1822  while (item!=NULL) {
1823  lp = add_tList_node_bystr(lp, nn, 0, item, NULL, NULL, 0);
1824  free(item);
1825  item = awk(str, cc, ++nn);
1826  }
1827 
1828  if (lp!=NULL) lp = find_tList_top(lp);
1829  return lp;
1830 }
1831 
1832 
1844 tList* cawk_tList(char* str, char cc)
1845 {
1846  int nn = 1;
1847  char* item;
1848  tList* lp = NULL;
1849 
1850  if (str==NULL) return NULL;
1851 
1852  lp = add_tList_node_bystr(NULL, 1, 0, NULL, NULL, NULL, 0);
1853 
1854  // first item
1855  item = cawk(str, cc, nn);
1856  if (item==NULL) return lp;
1857  lp->ldat.key = make_Buffer_bystr(item);
1858 
1859  //
1860  item = cawk(str, cc, ++nn);
1861  while (item!=NULL) {
1862  lp = add_tList_node_bystr(lp, nn, 0, item, NULL, NULL, 0);
1863  free(item);
1864  item = cawk(str, cc, ++nn);
1865  }
1866 
1867  if (lp!=NULL) lp = find_tList_top(lp);
1868  return lp;
1869 }
1870 
1871 
1884 {
1885  int nn = 1;
1886  Buffer item;
1887  tList* lp = NULL;
1888 
1889  if (buf.buf==NULL) return NULL;
1890 
1891  item = awk_Buffer(buf, cc, nn);
1892  while (item.buf!=NULL) {
1893  lp = add_tList_node_bystr(lp, nn, 0, (char*)item.buf, NULL, NULL, 0);
1894  free_Buffer(&item);
1895  item = awk_Buffer(buf, cc, ++nn);
1896  }
1897 
1898  if (lp!=NULL) lp = find_tList_top(lp);
1899  return lp;
1900 }
1901 
1902 
1915 {
1916  int nn = 1;
1917  Buffer item;
1918  tList* lp = NULL;
1919 
1920  if (buf.buf==NULL) return NULL;
1921 
1922  item = cawk_Buffer(buf, cc, nn);
1923  while (item.buf!=NULL) {
1924  lp = add_tList_node_bystr(lp, nn, 0, (char*)item.buf, NULL, NULL, 0);
1925  free_Buffer(&item);
1926  item = cawk_Buffer(buf, cc, ++nn);
1927  }
1928 
1929  if (lp!=NULL) lp = find_tList_top(lp);
1930  return lp;
1931 
1932 }
1933 
1934 
1941 char* get_str_join_tList(tList* lp, const char* deli)
1942 {
1943  Buffer buf = get_Buffer_join_tList(lp, deli);
1944  return (char*)buf.buf;
1945 }
1946 
1947 
1953 Buffer get_Buffer_join_tList(tList* lp, const char* deli)
1954 {
1955  Buffer buf;
1956 
1957  buf = init_Buffer();
1958  if (lp==NULL) return buf;
1959 
1960  buf = make_Buffer(LBUF);
1961 
1962  if (lp!=NULL && lp->ldat.key.buf!=NULL) {
1963  cat_s2Buffer((char*)lp->ldat.key.buf, &buf);
1964  lp = lp->next;
1965 
1966  while (lp!=NULL && lp->ldat.key.buf!=NULL) {
1967  if (deli!=NULL) cat_s2Buffer(deli, &buf);
1968  cat_s2Buffer((char*)lp->ldat.key.buf, &buf);
1969  lp = lp->next;
1970  }
1971  }
1972 
1973  return buf;
1974 }
1975 
1976 
1977 
1979 // for Configuration File
1980 //
1981 
1994 char* get_str_param_tList(tList* lt, const char* key, const char* dflt)
1995 {
1996  Buffer buf;
1997 
1998  buf = buffer_key_tList(lt, key, 1);
1999  if (buf.buf==NULL) buf = make_Buffer_bystr(dflt);
2000 
2001  return (char*)buf.buf;
2002 }
2003 
2004 
2016 int get_int_param_tList(tList* lt, const char* key, int dflt)
2017 {
2018  Buffer buf;
2019 
2020  buf = buffer_key_tList(lt, key, 1);
2021  if (buf.buf!=NULL) {
2022  int ret = atoi((char*)buf.buf);
2023  free_Buffer(&buf);
2024  return ret;
2025  }
2026  return dflt;
2027 }
2028 
2029 
2041 double get_double_param_tList(tList* lt, const char* key, double dflt)
2042 {
2043  Buffer buf;
2044 
2045  buf = buffer_key_tList(lt, key, 1);
2046  if (buf.buf!=NULL) {
2047  double ret = atof((char*)buf.buf);
2048  free_Buffer(&buf);
2049  return ret;
2050  }
2051  return dflt;
2052 }
2053 
2054 
2066 float get_float_param_tList(tList* lt, const char* key, float dflt)
2067 {
2068  Buffer buf;
2069 
2070  buf = buffer_key_tList(lt, key, 1);
2071  if (buf.buf!=NULL) {
2072  float ret = (float)atof((char*)buf.buf);
2073  free_Buffer(&buf);
2074  return ret;
2075  }
2076  return dflt;
2077 }
2078 
2079 
2091 int get_bool_param_tList(tList* lt, const char* key, int dflt)
2092 {
2093  int ret = dflt;
2094  char* val = NULL;
2095 
2096  if (dflt) val = get_str_param_tList(lt, key, "true");
2097  else val = get_str_param_tList(lt, key, "false");
2098 
2099  if (val!=NULL) {
2100  if (!strcasecmp("true", val)) ret = 1; // TRUE
2101  else ret = 0; // FALSE
2102  free(val);
2103  }
2104 
2105  return ret;
2106 }
2107 
2108 
2109 
2111 // Tiny List File I/O
2112 //
2113 
2127 tList* read_tList_file(const char* fname, int mode)
2128 {
2129  tList* lp = NULL;
2130  FILE* fp;
2131 
2132  fp = fopen(fname, "rb");
2133  if (fp!=NULL) {
2134  lp = read_tList_fp(fp, mode);
2135  fclose(fp);
2136  }
2137 
2138  return lp;
2139 }
2140 
2141 
2158 tList* read_tList_fp(FILE* fp, int mode)
2159 {
2160  char val[LBUF+1];
2161  char* str;
2162  tList* lp = NULL;
2163  tList* lt = NULL;
2164 
2165  if (fp==NULL) return NULL;
2166 
2167  str = fgets(val, LBUF, fp); // str is unused
2168  while (!feof(fp)) {
2169  if (mode>0) {
2170  if (mode>1) {
2171  int i;
2172  for (i=0; i<(int)strlen(val); i++) {
2173  if (val[i]=='#') {
2174  val[i] = '\0';
2175  break;
2176  }
2177  if (i>=LBUF) break;
2178  }
2179  }
2180  str = pack_char(val, ' ');
2181  }
2182  else {
2183  str = (char*)malloc(LBUF+1);
2184  if (str!=NULL) {
2185  memset(str, 0, LBUF+1);
2186  strncpy(val, str, LBUF);
2187  }
2188  }
2189 
2190  if (str!=NULL) {
2191  if (strlen(str)>0) { // 空行のチェック
2192  if (mode==0 || str[0]!='#') {
2193  lt = add_tList_node_str(lt, str, NULL);
2194  if (lp==NULL) lp = lt;
2195  }
2196  }
2197  free(str);
2198  }
2199  str = fgets(val, LBUF, fp); // str is unused
2200  }
2201 
2202  return lp;
2203 }
2204 
2205 
2219 tList* read_index_tList_file(const char* fname, char deli)
2220 {
2221  tList* lp = NULL;
2222  FILE* fp;
2223 
2224  fp = fopen(fname, "rb");
2225  if (fp!=NULL) {
2226  lp = read_index_tList_fp(fp, deli);
2227  fclose(fp);
2228  }
2229  return lp;
2230 }
2231 
2232 
2246 tList* read_index_tList_fp(FILE* fp, char deli)
2247 {
2248  Buffer key, val;
2249  Buffer fst, snd;
2250  tList* pl;
2251  tList* pp;
2252  tList* lt = NULL;
2253 
2254  pp = pl = read_tList_fp(fp, 1);
2255  while (pp!=NULL) {
2256  fst = awk_Buffer(pp->ldat.key, deli, 1);
2257  //snd = awk_Buffer(pp->ldat.key, deli, 2);
2258  //snd = make_Buffer_bystr((char*)&(pp->ldat.key.buf[fst.vldsz]));
2259  snd = make_Buffer_bystr((char*)&(pp->ldat.key.buf[fst.vldsz]) + 1);
2260  key = pack_Buffer(fst, ' ');
2261  val = pack_Buffer(snd, ' ');
2262  if (lt==NULL) lt = add_tList_node_byBuffer(NULL, 0, 0, key, val, NULL, 0);
2263  else add_tList_node_byBuffer(lt, 0, 0, key, val, NULL, 0);
2264 
2265  free_Buffer(&key);
2266  free_Buffer(&val);
2267  free_Buffer(&fst);
2268  free_Buffer(&snd);
2269 
2270  pp = pp->next;
2271  }
2272  del_all_tList(&pl);
2273 
2274  return lt;
2275 }
2276 
2277 
2286 tList* read_Buffer_tList_file(const char* fname)
2287 {
2288  tList* lp = NULL;
2289  FILE* fp;
2290 
2291  fp = fopen(fname, "rb");
2292  if (fp!=NULL) {
2293  lp = read_Buffer_tList_fp(fp);
2294  fclose(fp);
2295  }
2296  return lp;
2297 }
2298 
2299 
2309 {
2310  int cc;
2311  tList* lp = NULL;
2312  tList* lt = NULL;
2313  Buffer key, val;
2314 
2315  if (fp==NULL) return NULL;
2316 
2317  cc = read_Buffer2_format_fp(&key, &val, fp);
2318  while (!feof(fp) && cc) {
2319  lt = add_tList_node_Buffer(lt, key, val);
2320  if (lp==NULL) lp = lt;
2321  free_Buffer(&key);
2322  free_Buffer(&val);
2323  cc = read_Buffer2_format_fp(&key, &val, fp);
2324  }
2325 
2326  free_Buffer(&key);
2327  free_Buffer(&val);
2328  return lp;
2329 }
2330 
2331 
2344 int save_Buffer_tList_file(const char* fname, tList* lp)
2345 {
2346  int ret=FALSE;
2347  FILE* fp;
2348 
2349  fp = fopen(fname, "ab");
2350  if (fp!=NULL) {
2351  ret = save_Buffer_tList_fp(fp, lp);
2352  fclose(fp);
2353  }
2354  return ret;
2355 }
2356 
2357 
2370 int save_Buffer_tList_fp(FILE* fp, tList* lp)
2371 {
2372  int cc=TRUE;
2373 
2374  if (fp==NULL) return FALSE;
2375 
2376  while (lp!=NULL && cc) {
2377  cc = save_Buffer2_format_fp(lp->ldat.key, lp->ldat.val, fp);
2378  lp = lp->next;
2379  }
2380 
2381  if (!cc) return FALSE;
2382  return TRUE;
2383 }
2384 
Buffer make_Buffer(int sz)
Buffer型変数のバッファ部をつくり出す.
Definition: buffer.c:71
int read_Buffer2_format_fp(Buffer *key, Buffer *buf, FILE *fp)
ファイル fp から 2つのBuffer型変数の keyと bufを読み込む.
Definition: buffer.c:1819
void free_Buffer(Buffer *buf)
Buffer型変数のバッファ部を解放する
Definition: buffer.c:128
Buffer init_Buffer()
初期化したBuffer型変数を返す.
Definition: buffer.c:47
Buffer dup_Buffer(Buffer buf)
Buffer型変数のコピーをつくる.
Definition: buffer.c:211
Buffer pack_Buffer(Buffer buf, char cc)
文字列の先頭のcc(複数),終わりのcc(複数),TAB, CR, LF を削除
Definition: buffer.c:1134
Buffer cawk_Buffer(Buffer str, char cc, int n)
Buffer文字列に対する(変形の)awk.
Definition: buffer.c:1094
int save_Buffer2_format_fp(Buffer key, Buffer buf, FILE *fp)
ファイル fp へ 2つのBuffer型変数 keyと bufを書き込む
Definition: buffer.c:1733
Buffer awk_Buffer(Buffer str, char cc, int n)
Buffer文字列に対する awk.
Definition: buffer.c:1050
#define replace_sBuffer(buf, f, t)
replace_sBuffer()
Definition: buffer.h:175
#define cat_s2Buffer(src, dst)
cat_b2Buffer()
Definition: buffer.h:122
#define make_Buffer_bystr(str)
set_Buffer()
Definition: buffer.h:57
#define OFF
Definition: common.h:231
#define LBUF
Definition: common.h:146
#define TRUE
Definition: common.h:226
#define FALSE
Definition: common.h:223
#define ON
Definition: common.h:230
JunkBox_Lib 状態ヘッダ
#define JBXL_ARGS_ERROR
不正な引数(NULLなど)
Definition: jbxl_state.h:42
#define JBXL_STATE_ANCHOR
アンカーノード
Definition: jbxl_state.h:30
#define JBXL_NORMAL
正常
Definition: jbxl_state.h:32
unsigned char ** buf
Definition: jpeg_tool.h:96
unsigned char unsigned long * len
Definition: jpeg_tool.h:96
Definition: buffer.h:35
int vldsz
データの長さ.バイナリデータの場合も使用可能.文字列の場合は 0x00 を含まない.
Definition: buffer.h:37
unsigned char * buf
バッファの先頭へのポインタ.str[bufsz]は必ず 0x00となる.
Definition: buffer.h:39
int replace_value_tList_node(tList *lp, const char *srcval, const char *value)
lt->ldat.val のsrcval部分を value に置き換える.
Definition: tlist.c:1779
int save_Buffer_tList_file(const char *fname, tList *lp)
リストのキー部とバッファ部の Buffer型変数をファイルへ書き込む.
Definition: tlist.c:2344
tList * read_index_tList_file(const char *fname, char deli)
ファイルから一行ずつ読み込んで,deliを区切り文字にしてリストのキー部とデータ部に格納.
Definition: tlist.c:2219
tList * find_tList_end(tList *pl)
リストの最後のノードを探す.
Definition: tlist.c:1023
tList_data make_tList_data_bystr(int id, int lv, const char *key, const char *val, void *ptr, int sz)
文字列データを指定してノードデータを作成
Definition: tlist.c:89
tList * cawk_Buffer_tList(Buffer buf, char cc)
Buffer 中の文字列を区切り文字で区切って,各項目をリストのキー部に入れて返す.連続文字列対応.
Definition: tlist.c:1914
double get_double_param_tList(tList *lt, const char *key, double dflt)
keyに対応する値を double型実数として読み出す.キーがない場合は,デフォルト値 dflt を返す.
Definition: tlist.c:2041
tList * strncasecmp_tList(tList *pl, const char *key, int len, int no)
char* 型変数によるノードのサーチ.大文字小文字を無視する
Definition: tlist.c:1094
tList * strncasecmp_back_tList(tList *pl, const char *key, int len, int no)
char* 型変数によるリストの後方からのノードのサーチ.大文字小文字を無視.
Definition: tlist.c:1337
tList * update_tList_node_bystr(tList *pp, int id, int lv, const char *key, const char *val, void *ptr, int sz)
keyで検索し,ノードがあればノードをコピーする.無ければ最後に追加する(new)
Definition: tlist.c:668
void print_tList(FILE *fp, tList *pp)
リストの表示.ポインタ pp以降の全てのノードを fpに表示する.
Definition: tlist.c:928
void del_tList_data(tList_data **ldat)
ノードデータを削除する.
Definition: tlist.c:149
tList * new_tList_anchor_node(void)
リスト用の ANCHORノードを動的に生成.
Definition: tlist.c:371
tList * strstrcase_back_tList(tList *pl, const char *key, int len, int no)
char* 型変数による後方からのノードの部分文字列サーチ.大文字小文字を無視.
Definition: tlist.c:1497
tList * search_id_tList(tList *pl, int id, int no)
リストの中から no番目の idノード(ldat.id)を探し出し,tListのポインタを返す.
Definition: tlist.c:1541
tList * update_tList_node_byBuffer(tList *pp, int id, int lv, Buffer key, Buffer val, void *ptr, int sz)
key.bufで検索し,ノードがあれば設定する.無ければ最後に追加する(new).
Definition: tlist.c:703
tList * cawk_tList(char *str, char cc)
文字列を区切り文字で区切って,各項目をリストのキー部に入れて返す.連続文字列対応.
Definition: tlist.c:1844
tList * dup_tList(tList *pp)
リストを複製する.
Definition: tlist.c:843
tList_data make_tList_data(int id, int lv, Buffer key, Buffer val, void *ptr, int sz)
データを指定してノードデータを作成
Definition: tlist.c:50
tList * read_index_tList_fp(FILE *fp, char deli)
ファイルポインタが示すファイルから一行ずつ読み込んで,deliを区切り文字にしてリストのキー部とデータ部に格納.
Definition: tlist.c:2246
char * get_str_join_tList(tList *lp, const char *deli)
リストの一連のキー部を deliを区切りにして結合して,その文字列を返す. 要 free
Definition: tlist.c:1941
int get_bool_param_tList(tList *lt, const char *key, int dflt)
keyに対応する値を 論理値(実際は整数)として読み出す.キーがない場合は,デフォルト値 dflt を返す.
Definition: tlist.c:2091
tList * update_tList_node(tList *pp, tList *pt)
pt->keyで検索し,ノードがあればノードをコピーする.無ければ最後にノードを追加する(new).
Definition: tlist.c:609
tList * new_tList_node(void)
リスト用の空ノードを動的に生成する.
Definition: tlist.c:198
Buffer get_Buffer_join_tList(tList *lp, const char *deli)
リストの一連のキー部を deliを区切りにして結合して返す.
Definition: tlist.c:1953
void del_all_tList(tList **pp)
リストの全ノードの削除.ポインタ ppのノードを含むリスト全体を削除する.
Definition: tlist.c:769
int set_value_tList(tList *list, const char *key, int no, const char *value, int add_mode)
リスト(lt)中の no番目の keyノードの値に valueを設定する.
Definition: tlist.c:1675
tList * add_tList_end(tList *pp, tList *pt)
リストppの最後に リストptを追加する.
Definition: tlist.c:877
tList * dup_tList_node(tList *node)
ノードデータを複製する (new).ノードのポインタは複製しない.
Definition: tlist.c:287
int count_tList(tList *pp)
リストの ppノード以降のノードの数を数える.
Definition: tlist.c:979
tList * read_Buffer_tList_fp(FILE *fp)
ファイルポインタから Buffer型変数を 2つずつ読み込んで,リストのキー部とバッファ部に格納し返す.
Definition: tlist.c:2308
float get_float_param_tList(tList *lt, const char *key, float dflt)
keyに対応する値を float型実数として読み出す.キーがない場合は,デフォルト値 dflt を返す.
Definition: tlist.c:2066
tList * free_tList_node(tList *node)
リスト用ノードのバッファ部(データ)の解放.
Definition: tlist.c:243
tList * strncaservscmp_tList(tList *pl, const char *key, int len, int no)
char* 型変数によるノードのサーチ.文字の後方から比べる.大文字小文字を無視.
Definition: tlist.c:1170
tList * strstr_tList(tList *pl, const char *key, int len, int no)
char* 型変数によるノードの部分文字列サーチ.
Definition: tlist.c:1206
int get_int_param_tList(tList *lt, const char *key, int dflt)
keyに対応する値を 整数として読み出す.キーがない場合は,デフォルト値 dflt を返す..
Definition: tlist.c:2016
void clear_tList_data(tList_data *ldat)
ノードデータのバッファ部をクリアする.データ自身は削除しない.
Definition: tlist.c:120
Buffer buffer_key_tList(tList *list, const char *key, int no)
リストの中から no番目の keyノード(ldat.key)を探し出し,ldat.valのコピーを返す.
Definition: tlist.c:1595
tList * awk_tList(char *str, char cc)
文字列を区切り文字で区切って,各項目をリストのキー部に入れて返す.
Definition: tlist.c:1805
void set_tList_node_bydata(tList *node, tList_data dat)
リストのノードに値を設定する.
Definition: tlist.c:513
tList * del_tList_node(tList **node)
リスト用のノードを削除.
Definition: tlist.c:270
tList * move_tList_node(tList *pp, tList *node)
nodeを現在のリストから切り離し,ppへ移動する.
Definition: tlist.c:321
tList * insert_tList(tList *pp, tList *pt)
ノードppの直ぐ後ろに ptを挿入する.
Definition: tlist.c:903
tList make_tList_node(tList_data ldat)
リスト用ノードを静的に作成する.
Definition: tlist.c:223
int set_value_tList_node(tList *lp, const char *value)
lt->ldat.val に文字列を設定する(置き換える).
Definition: tlist.c:1714
tList * add_tList_node_bystr(tList *pp, int id, int lv, const char *key, const char *val, void *ptr, int sz)
文字列データからリスト用ノードを生成し(new),それをリストに追加.
Definition: tlist.c:462
tList * del_tList_anchor_node(tList *node)
ANCHORノードを削除して,TOPのポインターを返す.
Definition: tlist.c:387
tList_data dup_tList_data(tList_data ldat)
ノードデータの複製を作成する
Definition: tlist.c:169
tList * strstr_back_tList(tList *pl, const char *key, int len, int no)
char* 型変数によるリストの後方からのノードの部分文字列サーチ.
Definition: tlist.c:1451
tList * strstrcase_tList(tList *pl, const char *key, int len, int no)
char* 型変数によるノードの部分文字列サーチ.大文字小文字を無視.
Definition: tlist.c:1250
tList * search_key_tList(tList *pl, const char *key, int no)
リストの中から no番目の keyノード(ldat.key)を探し出し,tListへのポインタを返す.大文字小文字を無視.
Definition: tlist.c:1571
int save_Buffer_tList_fp(FILE *fp, tList *lp)
リストのキー部とバッファ部の Buffer型変数をファイルポンタが指すファイルへ書き込む.
Definition: tlist.c:2370
tList * swap_tList_node(tList *pp1, tList *pp2)
pp1ノード と pp2ノードを入れ替える.
Definition: tlist.c:342
tList * update_tList_node_bydata(tList *pp, char *srch, tList_data ldat)
keyで検索し,ノードがあればノードをコピーする.無ければ最後にノードを追加する(new).
Definition: tlist.c:635
tList * read_Buffer_tList_file(const char *fname)
ファイルから Buffer型変数を 2つずつ読み込んで,リストのキー部とバッファ部に格納し返す.
Definition: tlist.c:2286
tList * strnrvscmp_tList(tList *pl, const char *key, int len, int no)
char* 型変数によるノードのサーチ.文字の後方から比べる
Definition: tlist.c:1132
tList_data init_tList_data(void)
空のノードデータを静的に作成.データを初期化するのに使用する.
Definition: tlist.c:26
tList * read_tList_file(const char *fname, int mode)
ファイルから一行ずつ読み込んでリストのキー部に格納.空行はリストに加えない.
Definition: tlist.c:2127
tList * awk_Buffer_tList(Buffer buf, char cc)
Buffer 中の文字列を区切り文字で区切って,各項目をリストのキー部に入れて返す.
Definition: tlist.c:1883
tList * strncmp_tList(tList *pl, const char *key, int len, int no)
char* 型変数によるノードのサーチ.
Definition: tlist.c:1056
void set_tList_node_bystr(tList *pp, int id, int lv, const char *key, const char *val, void *ptr, int sz)
文字列データからリストのノードに値を設定する.それぞれのデータは複製されて設定される.
Definition: tlist.c:536
int replace_value_tList(tList *list, const char *key, int no, const char *srcval, char *value)
リスト(lt)中の no番目の keyノードの値の srcvalの部分を value に置き換える.
Definition: tlist.c:1742
tList * strncaservscmp_back_tList(tList *pl, const char *key, int len, int no)
char* 型変数によるリストの後方からのノードのサーチ.文字も後方から比べる.大文字小文字を無視.
Definition: tlist.c:1413
Buffer buffer_key_value_tList(tList *list, const char *key, char *data, int no)
リストの中から no番目の keyノードを探し出し,ノード値が data で始まる場合,そのノード値を返す.
Definition: tlist.c:1626
tList * add_tList_node_byBuffer(tList *pp, int id, int lv, Buffer key, Buffer val, void *ptr, int sz)
Buffer データからリスト用ノードを生成し(new),それをリストに追加.
Definition: tlist.c:492
tList * del_tList(tList **pp)
指定したリストノード以降のリストを削除.
Definition: tlist.c:735
void set_tList_node_byBuffer(tList *pp, int id, int lv, Buffer key, Buffer val, void *ptr, int sz)
リストのノードに値を設定する.それぞれのデータは複製されて設定される.
Definition: tlist.c:575
int del_tList_key(tList **pl, const char *key, int no)
plからサーチして,no番目の keyのノードを削除する.
Definition: tlist.c:805
char * get_str_param_tList(tList *lt, const char *key, const char *dflt)
keyに対応する値を 文字列として読み出す.キーがない場合は,デフォルト値 dflt を返す.要 free().
Definition: tlist.c:1994
tList * strnrvscmp_back_tList(tList *pl, const char *key, int len, int no)
char* 型変数によるリストの後方からのノードのサーチ.文字も後方から比べる.
Definition: tlist.c:1375
tList * find_tList_top(tList *pl)
リストの最初のノードを探す.
Definition: tlist.c:1002
tList * strncmp_back_tList(tList *pl, const char *key, int len, int no)
char* 型変数によるリストの後方からのノードのサーチ.
Definition: tlist.c:1299
tList * add_tList_node_bydata(tList *pp, tList_data ldat)
データ(ldat)からリスト用ノードを生成し(new),それを指定したリストの後ろに追加.
Definition: tlist.c:417
tList * read_tList_fp(FILE *fp, int mode)
ファイルポインタが示すファイルから一行ずつ読み込んでリストのキー部に格納.
Definition: tlist.c:2158
void dump_tList(FILE *fp, tList *pp)
val.buf を 16進ダンプする.他のデータは通常通り表示する.
Definition: tlist.c:952
Tiny List 構造ライブラリヘッダ
#define add_tList_node_Buffer(p, k, v)
add_tList_node_byBuffer()
Definition: tlist.h:144
#define add_tList_node_str(p, k, v)
add_tList_node_bystr()
Definition: tlist.h:142
#define TLIST_ANCHOR_NODE
アンカーノード
Definition: tlist.h:92
char * awk(char *buf, char cc, int n)
ccを区切り記号として, strのバッファ内の n番目の項目を返す.要 free()
Definition: tools.c:567
char * strstrcase(const char *buf, const char *nd)
文字列 bufの中に文字列 ndがあるかどうかをチェックする.大文字小文字は区別しない.
Definition: tools.c:736
int ex_strncmp(const char *dat, const char *key, int len)
文字列 s1とs2を拡張比較する.一致するなら TRUE
Definition: tools.c:784
int ex_strnrvscmp(const char *dat, const char *key, int len)
文字列 s1とs2を後ろから拡張比較する.一致するなら TRUE
Definition: tools.c:856
int ex_strncasecmp(const char *dat, const char *key, int len)
文字列 s1とs2を拡張比較する.大文字小文字を区別しない.一致するなら TRUE
Definition: tools.c:820
int ex_strncaservscmp(const char *dat, const char *key, int len)
文字列 s1とs2を後ろから拡張比較する.一致するなら TRUE
Definition: tools.c:892
void fdump(FILE *fp, unsigned char *mesg, int n)
16進ダンプを吐き出す
Definition: tools.c:4177
char * cawk(char *buf, char cc, int n)
連続するccを区切り記号として, strのバッファ内の n番目の項目を返す.要 free()
Definition: tools.c:609
#define pack_char(s, c)
pack_char_len()
Definition: tools.h:236