📄 dumpsfx.c
字号:
/************************************************************************** * * * dumpsfx 1.0 * * Copyright (C) 2001 Fabien Menemenlis (nihilist@dead-inside.org) * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * * as published by the Free Software Foundation; either version 2 * * of the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * * USA * * * **************************************************************************//* * this program dumps a suffix tree file to plain text on the standard * output */#include <stdio.h>#include <stdlib.h>#include "sfxdisk.h"static char *sep;static char d_hexa = 0;void print_hexa(char *data, int size){ int i; for (i = 0; i < size; i++) printf("%02x", (unsigned char)data[i]); printf("\n");}void DumpNode(STFile *stfile, offset_t offset, char *key){ STnode node; int i; char *rep; int sizerep; int pos; char keynode[TELEM + 1]; char buffer[100 + 1]; strcpy(keynode, key); STreadnode(stfile, &node, offset); strcat(keynode, node.elem); if (node.value > 0) { keynode[strlen(keynode) - 1] = '\0'; pos = node.value; rep = NULL; do { pos = STreaddata(stfile, pos, (void *)&rep, &sizerep); if (d_hexa) { print_hexa(keynode, strlen(keynode)); snprintf(buffer, 100, "%d", sizerep); print_hexa(buffer, strlen(buffer)); print_hexa(rep, sizerep); } else printf("%s%s%s\n", keynode, sep, rep); } while (pos != -1); free(rep); return; } for (i = 0; i < MAXLIST; i++) { if (node.list[i]) DumpNode(stfile, node.list[i], keynode); }}int main(int argc, char *argv[]){ STFile *stfile; if (argc < 2 || argc > 4) { fprintf(stderr, "%s <suffix tree file> [-s separator (default is newline)|" "-h]\n-h dumps to hexa (for use with loadsfx)\n" "output on stdout\n", argv[0]); return(1); } if (argc == 4) { if (strcmp(argv[2], "-s")) { fprintf(stderr, "unknown option\n"); return(1); } sep = argv[3]; } else if (argc == 3) { if (strcmp(argv[2], "-h")) { fprintf(stderr, "unknown option\n"); return(1); } d_hexa = 1; } else sep = "\n"; if ((stfile = STopen(argv[1], ST_RDONLY)) == NULL) { perror(argv[1]); return(1); } /* * first read the root of all nodes */ DumpNode(stfile, 0, ""); STclose(stfile); return(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -