test code for our MBED board

Dependencies:   mbed lwip

breakup.c

Committer:
lolpcc
Date:
2011-05-04
Revision:
1:6877bb99aa17

File content as of revision 1:6877bb99aa17:

#include "mbed.h"

/*
int breakup(char *, char *[], char);
void breakup_sub(char *, char *,char,char);
*/

void breakup_sub(char *line,char *entery_point,char c,char d)
{
    char *point,*pt2;
     
    point = entery_point;
    
    point++;
    pt2 = point;
    point --;
    while (*pt2!='\0') {
        *point = *pt2;
        point ++;
        pt2 ++;
    }
    *point = *pt2;
}

int breakup(char *string,char *p[],char c)
{
    char *pt,*pt1;
    char cc,ccc;
    int cnt = 0;
    int number = 0;
    int flag = 0;
    int last = 0;
    int just = 0;
    int length = strlen(string);

    pt = string;
    p[number] = pt;
    number++;

    while (cnt != length + 1) {
        cc = *pt;
        if (cc == '\0')
            return(number);
        /* this section of code will need sorting, so we don't have to use a space
           char, we should move the ramainder of the buffer down one charactor
        */
        if (cc=='\\') {
            pt1 = pt;    /* save the current pointer */
            pt++;
            ccc = *pt;
            if (ccc=='"') {
                pt--;
                breakup_sub(string,pt,cc,ccc);
                pt = pt1;
            } else {
                pt--;
                pt = pt1;    /* restore the current pointer */
            }
        }
        if (flag == 0) {
            switch (cc) {
                case '"' :
                    flag = 1;
                case '\n' :
                case '\t' :
                case ' ' :
                    if (just==1) {
                        /* move the current pointer along */
                        pt = pt + 1;
                        p[number] = pt;
                        pt = pt - 1;
                    } else {
                        /* add the current point to the array  */
                        just = 1;
                        *pt = '\0';
                        pt++;
                        p[number] = pt;
                        pt--;
                    }
                    if (flag == 1) {
                        number ++;
                        just = 0;
                    }
                    break;
                default :
                    if (just == 1) {
                        just = 0;
                        number ++;
                    }
                    break;
            }
            if (cc == c) {  /* test for the user defined char  */
                just = 1;
                *pt = '\0';
                pt++;
                p[number] = pt;
                pt--;
            }
        } else {
            if ((last == 0) & (cc =='"')) {     /* close of quoate */
                flag = 0;
                just = 1;
                *pt = '\0';
                pt++;
                p[number] = pt;
                pt--;
            } else if ((flag == 1) & (last == 1) & (cc!='\\'))
                last = 0;
        }
        pt++;
        cnt++;
    }
    return(-1);
}