forked from Unidata/netcdf-c
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
89575c6
commit 1c0688b
Showing
5 changed files
with
135 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
|
||
#ifdef HAVE_CONFIG_H | ||
#include <config.h> | ||
#endif | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <assert.h> | ||
|
||
#ifdef _WIN32 | ||
#include <windows.h> | ||
#include <io.h> | ||
#endif | ||
|
||
#ifdef HAVE_GETOPT_H | ||
#include <getopt.h> | ||
#endif | ||
|
||
#if defined(_WIN32) && ! defined(__MINGW32__) | ||
#include "XGetopt.h" | ||
#endif | ||
|
||
int | ||
main(int argc, char** argv) | ||
{ | ||
int i; | ||
int len; | ||
char* result = NULL; | ||
int noeol = 1; /* Default to -n vs -N */ | ||
int escape = 1; /* Ditto */ | ||
char* p = NULL; | ||
char* q = NULL; | ||
char c; | ||
|
||
#ifdef _WIN32 | ||
_setmode(_fileno(stdout),_O_BINARY); | ||
#endif | ||
|
||
opterr = 1; | ||
while ((c = getopt(argc, argv,"enEN")) != EOF) { | ||
switch(c) { | ||
case 'e': escape = 1; break; | ||
case 'n': noeol = 1; break; | ||
case 'E': escape = 0; break; | ||
case 'N': noeol = 0; break; | ||
case '?': default: break; /* ignore */ | ||
} | ||
} | ||
|
||
/* leave non-flag args */ | ||
argc -= optind; | ||
argv += optind; | ||
|
||
/* Compute the max possible length of output */ | ||
for(len=0,i=0;i<argc;i++) len += (int)strlen(argv[i]); | ||
len += (argc - 1); /* inter-arg spacing */ | ||
result = (char*)malloc((size_t)len+1+1); /* +1 for nul term +1 for '\n' */ | ||
assert(result != NULL); | ||
result[0] = '\0'; | ||
/* Concat all the arguments with ' ' between them */ | ||
for(i=0;i<argc;i++) { | ||
if(i > 0) strcat(result," "); | ||
strcat(result,argv[i]); | ||
} | ||
/* Optionally de-escape the result */ | ||
if(escape) { | ||
for(p=result,q=result;*p;) { | ||
switch (*p) { | ||
default: *q++ = *p; break; | ||
case '\\': | ||
p++; | ||
switch(*p) { | ||
case 'a': *q++ = '\a'; break; | ||
case 'b': *q++ = '\b'; break; | ||
case 'f': *q++ = '\f'; break; | ||
case 'r': *q++ = '\r'; break; | ||
case 'n': *q++ = '\n'; break; | ||
case 't': *q++ = '\t'; break; | ||
case 'v': *q++ = '\v'; break; | ||
default: *q++ = *p; break; | ||
} | ||
break; | ||
} | ||
p++; | ||
} | ||
} else | ||
*q++ = *p++; | ||
if(!noeol) *p++ = '\n'; | ||
*p = '\0'; | ||
fputs(result,stdout); | ||
fflush(stdout); | ||
free(result); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters