📄 tohex.c
字号:
/* * Copyright 2000-2005 Wind River Systems, Inc. * All rights reserved. Provided under license only. * Distribution or other use of this software is only * permitted pursuant to the terms of a license agreement * from Wind River Systems (and is otherwise prohibited). * Refer to that license agreement for terms of use. *//* * Copyright 1993-1997 Epilogue Technology Corporation. * Copyright 1998 Integrated Systems, Inc. * All rights reserved. *//* * $Log: tohex.c,v $ * Revision 1.1.1.1 2001/11/05 17:47:45 tneale * Tornado shuffle * * Revision 9.1 2000/03/17 00:19:55 meister * Update copyright message * * Revision 9.0 1998/10/16 22:12:59 sar * Update version stamp to match release * * Revision 8.1 1998/02/25 04:53:36 sra * Update copyrights. * * Revision 8.0 1997/11/18 00:57:14 sar * Updated revision to 8.0 * * Revision 7.2 1997/03/20 06:49:44 sra * DFARS-safe copyright text. Zap! * * Revision 7.1 1997/02/25 10:49:26 sra * Update copyright notice, dust under the bed. * * Revision 7.0 1996/03/18 20:24:05 sar * Updated rev to 7.0 and copyright to 96 * * Revision 6.2 1996/02/27 21:30:24 sar * added an int to the main call to keep compilers happy * added a default for leftc to keep compilers happy * * Revision 6.1 1995/11/01 00:38:58 sar * removed definition of then * repaginated * * Revision 6.0 1995/05/31 21:49:30 sra * Release 6.0. * * Revision 5.0 1994/05/16 17:21:18 sar * Updated revision to 5.0 and copyright to include 1994 * * Revision 4.0 1993/06/24 17:53:56 sar * Updated rev to 4.0 and copyright to 93 * *//* [clearcase]modification history-------------------01b,19apr05,job update copyright notices01a,24nov03,job update copyright information*/#include <stdio.h>#if (!defined(NO_STDLIB))#include <stdlib.h>#endif#include <ctype.h>intmain(int argc, char **argv){FILE *infile, *outfile;int oddeven;int linenum;unsigned char c;unsigned char leftc = 0, rightc;if (argc != 3) { printf("Usage: tohex input-file output-file\n"); exit(1); }if ((infile = fopen(argv[1], "rt")) == NULL) { perror("Could not open input file"); exit(1); }if ((outfile = fopen(argv[2], "wb")) == NULL) { perror("Could not open output file"); exit(1); }for(oddeven = 0, linenum = 0;;) { int useme; useme = 0; c = (unsigned char) fgetc(infile); if (feof(infile) || ferror(infile)) break; if (c == '\n') { oddeven = 0; linenum++; continue; } if (isalpha(c) && islower(c)) c = toupper(c); if (isdigit(c)) { useme = 1; c -= '0'; } if ((c >= 'A') && (c <= 'F')) { useme = 1; c = 0x0A + c - 'A'; } if (useme != 0) { if (oddeven == 0) { leftc = c; oddeven = ~oddeven; } else { unsigned char hex; rightc = c; hex = (leftc << 4) | rightc; fputc(hex, outfile); oddeven = 0; } continue; } if (oddeven != 0) { printf("Unpaired hex digit, line %d\n", linenum); oddeven = ~oddeven; } if (c == '#') { do { c = (unsigned char) fgetc(infile); if (feof(infile) || ferror(infile)) goto end_of_input; } while (c != '\n'); oddeven = 0; linenum++; } }end_of_input:fclose(infile);fclose(outfile);exit(0);return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -