Sponsored Content
Top Forums UNIX for Advanced & Expert Users Another binary manipulation thread. Post 302855363 by DGPickett on Thursday 19th of September 2013 04:39:34 PM
Old 09-19-2013
Whenever you escape null to \0 you must minimally escape \ to \\. IFS has to have one character in it, so if you put in newline only, \n, a utility that escaped just those three would make data shell friendly.
Code:
 
#include <stdio.h>
void p_putchar( int c ){
  if ( EOF == putchar( c )){
    if ( ferror( stdout )){
      perror( "stdout" );
      exit( 1 );
     }
    exit( 0 );
   }
 }
int main  (){
  int c ;
  while ( EOF != ( c = getchar() )){
    switch ( c ){
    case '\\':
      p_putchar( c );
      break ;
    case '\0':
      p_putchar( '\\' );
      c = '0' ;
      break ;
    case '\n':
      p_putchar( '\\' );
      c = 'n' ;
      break ;
    default:
      break ;
    }
    p_putchar( c );
   }
  if ( ferror( stdin )){
    perror( "stdin" );
    exit( 2 );
   }
 }
 
 
 
 
 
 
$ all256|bin2txt|od -bc
0000000   \   0 001 002 003 004 005 006 007  \b  \t   \   n 013  \f  \r
        134 060 001 002 003 004 005 006 007 010 011 134 156 013 014 015
0000020 016 017 020 021 022 023 024 025 026 027 030 031 032 033 034 035
        016 017 020 021 022 023 024 025 026 027 030 031 032 033 034 035
0000040 036 037       !   "   #   $   %   &   '   (   )   *   +   ,   -
        036 037 040 041 042 043 044 045 046 047 050 051 052 053 054 055
0000060   .   /   0   1   2   3   4   5   6   7   8   9   :   ;   <   =
        056 057 060 061 062 063 064 065 066 067 070 071 072 073 074 075
0000100   >   ?   @   A   B   C   D   E   F   G   H   I   J   K   L   M
        076 077 100 101 102 103 104 105 106 107 110 111 112 113 114 115
0000120   N   O   P   Q   R   S   T   U   V   W   X   Y   Z   [   \   \
        116 117 120 121 122 123 124 125 126 127 130 131 132 133 134 134
0000140   ]   ^   _   `   a   b   c   d   e   f   g   h   i   j   k   l
        135 136 137 140 141 142 143 144 145 146 147 150 151 152 153 154
0000160   m   n   o   p   q   r   s   t   u   v   w   x   y   z   {   |
        155 156 157 160 161 162 163 164 165 166 167 170 171 172 173 174
0000200   }   ~ 177 200 201 202 203 204 205 206 207 210 211 212 213 214
        175 176 177 200 201 202 203 204 205 206 207 210 211 212 213 214
0000220 215 216 217 220 221 222 223 224 225 226 227 230 231 232 233 234
        215 216 217 220 221 222 223 224 225 226 227 230 231 232 233 234
0000240 235 236 237 240 241 242 243 244 245 246 247 250 251 252 253 254
        235 236 237 240 241 242 243 244 245 246 247 250 251 252 253 254
0000260 255 256 257 260 261 262 263 264 265 266 267 270 271 272 273 274
        255 256 257 260 261 262 263 264 265 266 267 270 271 272 273 274
0000300 275 276 277 300 301 302 303 304 305 306 307 310 311 312 313 314
        275 276 277 300 301 302 303 304 305 306 307 310 311 312 313 314
0000320 315 316 317 320 321 322 323 324 325 326 327 330 331 332 333 334
        315 316 317 320 321 322 323 324 325 326 327 330 331 332 333 334
0000340 335 336 337 340 341 342 343 344 345 346 347 350 351 352 353 354
        335 336 337 340 341 342 343 344 345 346 347 350 351 352 353 354
0000360 355 356 357 360 361 362 363 364 365 366 367 370 371 372 373 374
        355 356 357 360 361 362 363 364 365 366 367 370 371 372 373 374
0000400 375 376 377
        375 376 377
0000403
$

Forgot the exit(0) for no error stdout EOF last time!

Last edited by DGPickett; 09-19-2013 at 05:44 PM..
 

4 More Discussions You Might Find Interesting

1. Programming

How to cancel a thread safely from the initial thread?

how about asynchronous canceling? or with signal? if with signal whether it effects the process? my english so badly :( :( (1 Reply)
Discussion started by: alan.zhao
1 Replies

2. Shell Programming and Scripting

Convert binary file to csv and then back to the binary format

Hello *nix specialists, Im working for a non profit organisation in Germany to transport DSL over WLAN to people in areas without no DSL. We are using Linksys WRT 54 router with DD-WRT firmware There are at the moment over 180 router running but we have to change some settings next time. So my... (7 Replies)
Discussion started by: digidax
7 Replies

3. Shell Programming and Scripting

Another Building Block, Binary File Manipulation...

Apologies for any typos, and IF this has been done before... This is yet another building block. The code generates a 256 byte binary file of _characters_ 0x00 to 0xFF for general usage and generates another binary file manipulated in a basic way. I need this facility for a kids project I am... (0 Replies)
Discussion started by: wisecracker
0 Replies

4. Forum Support Area for Unregistered Users & Account Problems

Not able to post thread/reply to thread

Dear Moderator I am not able to post any new thread or post reply to mine old thread. Kindly help as i am stuck on one problem and needed suggestion. Regards Jaydeep (1 Reply)
Discussion started by: jaydeep_sadaria
1 Replies
iconv_8859-5(5)                                         Standards, Environments, and Macros                                        iconv_8859-5(5)

NAME
iconv_8859-5 - code set conversion tables for ISO 8859-5 (Cyrillic) DESCRIPTION
The following code set conversions are supported: +-------------------------------------------------------------------------+ | Code Set Conversions Supported | +--------------+--------+--------------+--------+-------------------------+ | Code |Symbol |Target Code |Symbol | Target Output | +--------------+--------+--------------+--------+-------------------------+ |ISO 8859-5 |iso5 |KOI8-R |koi8 | KOI8-R | +--------------+--------+--------------+--------+-------------------------+ |ISO 8859-5 |iso5 |PC Cyrillic |alt | Alternative PC Cyrillic | +--------------+--------+--------------+--------+-------------------------+ |ISO 8859-5 |iso5 |MS 1251 |win5 | Windows Cyrillic | +--------------+--------+--------------+--------+-------------------------+ |ISO 8859-5 |iso5 |Mac Cyrillic |mac | Macintosh Cyrillic | +--------------+--------+--------------+--------+-------------------------+ CONVERSIONS
The conversions are performed according to the following tables. All values in the tables are given in octal. ISO 8859-5 to KOI8-R For the conversion of ISO 8859-5 to KOI8-R, all characters not in the following table are mapped unchanged. +-----------------------------------------------------------------+ | | Conversions|Performed | | | ISO 8859-5 | KOI8-R | ISO 8859-5 | KOI8-R | |24 | 4 |320 |301 | |241 | 263 |321 |302 | |242 | 261 |322 |327 | |243 | 262 |323 |307 | |244 | 264 |324 |304 | |245 | 265 |325 |305 | |246 | 266 |327 |332 | |247 | 267 |330 |311 | |250 | 270 |331 |312 | |251 | 271 |332 |313 | |252 | 272 |333 |314 | |253 | 273 |334 |315 | |254 | 274 |335 |316 | |256 | 276 |336 |317 | |257 | 277 |337 |320 | |260 | 341 |340 |322 | |261 | 342 |341 |323 | |262 | 367 |342 |324 | |263 | 347 |343 |325 | |264 | 344 |344 |306 | |265 | 345 |345 |310 | |266 | 366 |346 |303 | |267 | 372 |347 |336 | |270 | 351 |350 |333 | |271 | 352 |351 |335 | |272 | 353 |352 |337 | |273 | 354 |353 |331 | |274 | 355 |354 |330 | |275 | 356 |355 |334 | |276 | 357 |356 |300 | |277 | 360 |357 |321 | |300 | 362 |360 |260 | |301 | 363 |361 |243 | |302 | 364 |362 |241 | |303 | 365 |363 |242 | |304 | 346 |364 |244 | |305 | 350 |365 |245 | |306 | 343 |366 |246 | |307 | 376 |367 |247 | |310 | 373 |370 |250 | |311 | 375 |371 |251 | |312 | 377 |372 |252 | |313 | 371 |373 |253 | |314 | 370 |374 |254 | |315 | 374 |375 |255 | |316 | 340 |376 |256 | |317 | 361 | | | +---------------+----------------+----------------+---------------+ ISO 8859-5 to PC Cyrillic For the conversion of ISO 8859-5 to PC Cyrillic, all characters not in the following table are mapped unchanged. +-----------------------------------------------------------------+ | | Conversions|Performed | | | ISO 8859-5 | PC Cyrillic | ISO 8859-5 | PC Cyrillic | |24 | 4 |307 |227 | |200-240 | 40 |310 |230 | |241 | 360 |311 |231 | |242-254 | 40 |312 |232 | |255 | 260 |313 |233 | |256-257 | 40 |314 |234 | |260 | 200 |315 |235 | |261 | 201 |316 |236 | |262 | 202 |317 |237 | |263 | 203 |320 |240 | |264 | 204 |321 |241 | |265 | 205 |322 |242 | |266 | 206 |323 |243 | |267 | 207 |324 |244 | |270 | 210 |325 |245 | |271 | 211 |326 |246 | |272 | 212 |327 |247 | |273 | 213 |330 |250 | |274 | 214 |331 |251 | |275 | 215 |332 |252 | |276 | 216 |333 |253 | |277 | 217 |334 |254 | |300 | 220 |335 |255 | |301 | 221 |336 |256 | |302 | 222 |337 |257 | |303 | 223 |360-374 |40 | |304 | 224 |375 |260 | |305 | 225 |376 |40 | |306 | 226 |365 |40 | +---------------+----------------+----------------+---------------+ ISO 8859-5 to MS 1251 For the conversion of ISO 8859-5 to MS 1251, all characters not in the following table are mapped unchanged. +-----------------------------------------------------------------+ | | Conversions|Performed | | | ISO 8859-5 | MS 1251 | ISO 8859-5 | MS 1251 | |24 | 4 |317 |337 | |200-237 | 40 |320 |340 | |241 | 250 |321 |341 | |242 | 200 |322 |342 | |243 | 201 |323 |343 | |244 | 252 |324 |344 | |245 | 275 |325 |345 | |246 | 262 |326 |346 | |247 | 257 |327 |347 | |250 | 243 |330 |350 | |251 | 212 |331 |351 | |252 | 214 |332 |352 | |253 | 216 |333 |353 | |254 | 215 |334 |354 | |255 | 210 |335 |355 | |256 | 241 |336 |356 | |257 | 217 |337 |357 | |260 | 300 |340 |360 | |261 | 301 |341 |361 | |262 | 302 |342 |362 | |263 | 303 |343 |363 | |264 | 304 |344 |364 | |265 | 305 |345 |365 | |266 | 306 |346 |366 | |267 | 307 |347 |367 | |270 | 310 |350 |370 | |271 | 311 |351 |371 | |272 | 312 |352 |372 | |273 | 313 |353 |373 | |274 | 314 |354 |374 | |275 | 315 |355 |375 | |276 | 316 |356 |376 | |277 | 317 |357 |377 | |300 | 320 |360 |271 | |301 | 321 |361 |270 | |302 | 322 |362 |220 | |303 | 323 |363 |203 | |304 | 324 |364 |272 | |305 | 325 |365 |276 | |306 | 326 |366 |263 | |307 | 327 |367 |277 | |310 | 330 |370 |274 | |311 | 331 |371 |232 | |312 | 332 |372 |234 | |313 | 333 |373 |236 | |314 | 334 |374 |235 | |315 | 335 |375 |210 | |316 | 336 |376 |242 | |376 | 331 | | | +---------------+----------------+----------------+---------------+ ISO 8859-5 to Mac Cyrillic For the conversion of ISO 8859-5 to Mac Cyrillic, all characters not in the following table are mapped unchanged. +-----------------------------------------------------------------+ | | Conversions|Performed | | | ISO 8859-5 | Mac Cyrillic | ISO 8859-5 | Mac Cyrillic | |24 | 4 |317 |237 | |200-237 | 40 |320 |340 | |240 | 312 |321 |341 | |241 | 335 |322 |342 | |242 | 253 |323 |343 | |243 | 256 |324 |344 | |244 | 270 |325 |345 | |245 | 301 |326 |346 | |246 | 247 |327 |347 | |247 | 272 |330 |350 | |250 | 267 |331 |351 | |251 | 274 |332 |352 | |252 | 276 |333 |353 | |253 | 40 |334 |354 | |254 | 315 |335 |355 | |255 | 40 |336 |356 | |256 | 330 |337 |357 | |257 | 332 |340 |360 | |260 | 200 |341 |361 | |261 | 201 |342 |362 | |262 | 202 |343 |363 | |263 | 203 |344 |364 | |264 | 204 |345 |365 | |265 | 205 |346 |366 | |266 | 206 |347 |367 | |267 | 207 |350 |370 | |270 | 210 |351 |371 | |271 | 211 |352 |372 | |272 | 212 |353 |373 | |273 | 213 |354 |374 | |274 | 214 |355 |375 | |275 | 215 |356 |376 | |276 | 216 |357 |337 | |277 | 217 |360 |334 | |300 | 220 |361 |336 | |301 | 221 |362 |254 | |302 | 222 |363 |257 | |303 | 223 |364 |271 | |304 | 224 |365 |317 | |305 | 225 |366 |264 | |306 | 226 |367 |273 | |307 | 227 |370 |300 | |310 | 230 |371 |275 | |311 | 231 |372 |277 | |312 | 232 |373 |40 | |313 | 233 |374 |316 | |314 | 234 |375 |40 | |315 | 235 |376 |331 | |316 | 236 | | | +---------------+----------------+----------------+---------------+ FILES
/usr/lib/iconv/*.so conversion modules /usr/lib/iconv/*.t conversion tables /usr/lib/iconv/iconv_data list of conversions supported by conversion tables SEE ALSO
iconv(1), iconv(3C), iconv(5) SunOS 5.10 18 Apr 1997 iconv_8859-5(5)
All times are GMT -4. The time now is 10:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy