Changeset 1168 in MondoRescue for branches/stable/monitas/from-mondo.c


Ignore:
Timestamp:
Feb 15, 2007, 12:27:39 AM (17 years ago)
Author:
Bruno Cornec
Message:

strip_spaces => mr_strip_spaces in mr_str.c and corrected at the same time :-)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/monitas/from-mondo.c

    r353 r1168  
    66
    77#include "structs.h"
     8#include "mr_str.h"
    89
    910
     
    1314bool does_file_exist (char *);
    1415int make_hole_for_file (char *);
    15 void strip_spaces(char*);
    1616
    1717
     
    5353      pclose (fin);
    5454    }
    55   strip_spaces (result);
     55  mr_strip_spaces (result);
    5656  return (result);
    5757}
     
    124124      incoming[i]='\0';
    125125*/
    126       strip_spaces (incoming);
     126      mr_strip_spaces (incoming);
    127127      log_it (debug, incoming);
    128128    }
     
    204204}
    205205
    206 
    207 
    208 
    209 
    210 
    211 
    212 
    213 
    214 /*************************************************************************
    215  * strip_spaces() -- Hugo Rabson                                         *
    216  *                   rewitten Stefan Huebner                             *
    217  *                                                                       *
    218  * Purpose:   remove leading whitespaces and control characters, replace *
    219  *            TABs by SPACES, remove previous char when followed with BS,*
    220  *            skip control chars, terminate string with '\0' when CR or  *
    221  *            NL is detected                                             *
    222  *            afterwards remove trailing whitespace                      *
    223  * Called by:                                                            *
    224  * Returns:                                                              *
    225  *************************************************************************/
    226 void
    227 strip_spaces (char *in_out)
    228 {
    229     char *r, *w;
    230     r = w = in_out;             // initialize read and write pointer
    231 
    232     while ( *r && *r <= ' ' )
    233         ++r;                    // skip leading whitespace and control chars
    234 
    235     for ( ; *r ; ++r )          // until end of existing string do:
    236       {
    237         if (*r == '\t')                 // TAB
    238           { *w++ = ' ';                     // write SPACE instead
    239             continue; }
    240         if (*r == (char) 8)             // BACKSPACE
    241           { if (w > in_out) --w;            // remove previous character (if any ;-)
    242             continue; }
    243         if (*r == '\n' || *r == '\r')   // CR and LF
    244             break;                          // terminate copying
    245         if (*r < ' ')                   // Control chars
    246             continue;                       // are ignored (skipped)
    247         *w++ = *r;                      // all other chars are copied
    248       }
    249     // all characters are copied
    250     *w = '\0';                  // terminate the copied string
    251     for (--w; w>in_out && *w == ' '; --w)
    252         *w = '\0';              // remove trailing whitespaces
    253     return;
    254     /** buffers ******************************************************/
    255 //  char tmp[MAX_STR_LEN+1];
    256 
    257     /** pointers *****************************************************/
    258 //  char *p;
    259 
    260     /** int *********************************************************/
    261 //  int i;
    262 
    263     /** end vars ****************************************************/
    264 /*  for (i = 0; in_out[i] <= ' ' && i < strlen (in_out); i++);
    265   strcpy (tmp, in_out + i);
    266   for (i = strlen (tmp); i>0 && tmp[i - 1] <= 32; i--);
    267   tmp[i] = '\0';
    268   for (i = 0; i < 80; i++)
    269     {
    270       in_out[i] = ' ';
    271     }
    272   in_out[i] = '\0';
    273   i = 0;
    274   p = tmp;
    275   while (*p != '\0')
    276     {
    277       in_out[i] = *(p++);
    278       in_out[i + 1] = '\0';
    279       if (in_out[i] < 32 && i > 0)
    280     {
    281       if (in_out[i] == 8)
    282         {
    283           i--;
    284         }
    285       else if (in_out[i] == 9)
    286         {
    287           in_out[i++] = ' ';
    288         }
    289       else if (in_out[i] == '\t')
    290         {
    291           for (i++; i % 5; i++);
    292         }
    293       else if (in_out[i] >= 10 && in_out[i] <= 13)
    294         {
    295           break;
    296         }
    297       else
    298         {
    299           i--;
    300         }
    301     }
    302       else
    303     {
    304       i++;
    305     }
    306     }
    307   in_out[i] = '\0';
    308 */
    309 /*  for(i=strlen(in_out); i>0 && in_out[i-1]<=32; i--) {in_out[i-1]='\0';} */
    310 }
    311 
    312 
    313 
    314 
    315 
    316 
    317 
    318 
    319 
    320 
    321 
Note: See TracChangeset for help on using the changeset viewer.