Peter Cooper / Mbed 2 deprecated Dome

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers breakup.c Source File

breakup.c

00001 #include "mbed.h"
00002 
00003 /*
00004 int breakup(char *, char *[], char);
00005 void breakup_sub(char *, char *,char,char);
00006 */
00007 
00008 void breakup_sub(char *line,char *entery_point,char c,char d)
00009 {
00010     char *point,*pt2;
00011      
00012     point = entery_point;
00013     
00014     point++;
00015     pt2 = point;
00016     point --;
00017     while (*pt2!='\0') {
00018         *point = *pt2;
00019         point ++;
00020         pt2 ++;
00021     }
00022     *point = *pt2;
00023 }
00024 
00025 int breakup(char *string,char *p[],char c)
00026 {
00027     char *pt,*pt1;
00028     char cc,ccc;
00029     int cnt = 0;
00030     int number = 0;
00031     int flag = 0;
00032     int last = 0;
00033     int just = 0;
00034     int length = strlen(string);
00035 
00036     pt = string;
00037     p[number] = pt;
00038     number++;
00039 
00040     while (cnt != length + 1) {
00041         cc = *pt;
00042         if (cc == '\0')
00043             return(number);
00044         /* this section of code will need sorting, so we don't have to use a space
00045            char, we should move the ramainder of the buffer down one charactor
00046         */
00047         if (cc=='\\') {
00048             pt1 = pt;    /* save the current pointer */
00049             pt++;
00050             ccc = *pt;
00051             if (ccc=='"') {
00052                 pt--;
00053                 breakup_sub(string,pt,cc,ccc);
00054                 pt = pt1;
00055             } else {
00056                 pt--;
00057                 pt = pt1;    /* restore the current pointer */
00058             }
00059         }
00060         if (flag == 0) {
00061             switch (cc) {
00062                 case '"' :
00063                     flag = 1;
00064                 case '\n' :
00065                 case '\t' :
00066                 case ' ' :
00067                     if (just==1) {
00068                         /* move the current pointer along */
00069                         pt = pt + 1;
00070                         p[number] = pt;
00071                         pt = pt - 1;
00072                     } else {
00073                         /* add the current point to the array  */
00074                         just = 1;
00075                         *pt = '\0';
00076                         pt++;
00077                         p[number] = pt;
00078                         pt--;
00079                     }
00080                     if (flag == 1) {
00081                         number ++;
00082                         just = 0;
00083                     }
00084                     break;
00085                 default :
00086                     if (just == 1) {
00087                         just = 0;
00088                         number ++;
00089                     }
00090                     break;
00091             }
00092             if (cc == c) {  /* test for the user defined char  */
00093                 just = 1;
00094                 *pt = '\0';
00095                 pt++;
00096                 p[number] = pt;
00097                 pt--;
00098             }
00099         } else {
00100             if ((last == 0) & (cc =='"')) {     /* close of quoate */
00101                 flag = 0;
00102                 just = 1;
00103                 *pt = '\0';
00104                 pt++;
00105                 p[number] = pt;
00106                 pt--;
00107             } else if ((flag == 1) & (last == 1) & (cc!='\\'))
00108                 last = 0;
00109         }
00110         pt++;
00111         cnt++;
00112     }
00113     return(-1);
00114 }