FOSSology  4.4.0
Open Source License Compliance by Open Source Software
encode.c
Go to the documentation of this file.
1 /*
2  SPDX-FileCopyrightText: © 2006-2011 Hewlett-Packard Development Company, L.P.
3 
4  SPDX-License-Identifier: GPL-2.0-only
5 */
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
18 
20 #define myBUFSIZ BUFSIZ
21 
22 
23 int main(int argc, char **argv)
24 {
25  char str[myBUFSIZ];
26  char *cp;
27  int i;
28  int len = 0;
29  FILE *fp;
30 
31  if (argc == 1) {
32  fprintf(stderr, "Usage: %s file\n", *argv);
33  exit(1);
34  }
35 
39  if (strcmp(argv[1], "-") == 0) {
40  fp = stdin;
41  }
42  else if ((fp = fopen(argv[1], "r")) == (FILE *) NULL) {
43  perror(argv[1]);
44  exit(1);
45  }
46 
50  if (fgets(str, sizeof(str), fp) == (char *) EOF) {
51  perror(argv[1]);
52  exit(1);
53  }
54  if ((cp = strrchr(str, '\n')) != (char *) NULL) {
55  *cp = '\0';
56  }
57  len = strlen(str);
58 
59  printf("{%d, \"", len);
60  for (i = 0; i < len; i++) {
61  printf("\\%o", str[i] & 0xff);
62  }
63  printf("\\0\"}\n");
64 
65 
66  return 0;
67 }
#define myBUFSIZ
Definition: encode.c:20
int main(int argc, char **argv)
Definition: encode.c:23