FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
encode.c
Go to the documentation of this file.
1 /***************************************************************
2  Copyright (C) 2006-2011 Hewlett-Packard Development Company, L.P.
3 
4  This program is free software; you can redistribute it and/or
5  modify it under the terms of the GNU General Public License
6  version 2 as published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 
17  ***************************************************************/
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 
32 #define myBUFSIZ BUFSIZ
33 
34 
35 int main(int argc, char **argv)
36 {
37  char str[myBUFSIZ];
38  char *cp;
39  int i;
40  int len = 0;
41  FILE *fp;
42 
43  if (argc == 1) {
44  fprintf(stderr, "Usage: %s file\n", *argv);
45  exit(1);
46  }
47 
51  if (strcmp(argv[1], "-") == 0) {
52  fp = stdin;
53  }
54  else if ((fp = fopen(argv[1], "r")) == (FILE *) NULL) {
55  perror(argv[1]);
56  exit(1);
57  }
58 
62  if (fgets(str, sizeof(str), fp) == (char *) EOF) {
63  perror(argv[1]);
64  exit(1);
65  }
66  if ((cp = strrchr(str, '\n')) != (char *) NULL) {
67  *cp = '\0';
68  }
69  len = strlen(str);
70 
71  printf("{%d, \"", len);
72  for (i = 0; i < len; i++) {
73  printf("\\%o", str[i] & 0xff);
74  }
75  printf("\\0\"}\n");
76 
77 
78  return 0;
79 }
int main(int argc, char **argv)
Definition: encode.c:35
#define myBUFSIZ
Definition: encode.c:32