Main Page   Modules   Data Structures   File List   Data Fields   Globals  

C_libs/io/std_io/decode.c

Go to the documentation of this file.
00001 /* -------------------------------------------------------------------
00002 .COPYRIGHT    (c)  1995 CRAL
00003 .IDENT        decode.c
00004 .LANGUAGE     C
00005 .AUTHOR       RB
00006 .PURPOSE      decode arguments dans une chaine
00007 .COMMENT
00008 .VERSION      1.0  26-06-95 RB : creation
00009               1.1  21-12-95 RB : enleve get_adxycol pour table.c
00010                                  ajoute decode_argval_float
00011 ---------------------------------------------------------------------*/
00012 
00013 #include <gendef.h>
00014 #include <items.h>
00015 
00016 double trunc_double(double var, int k)
00017 {
00018         double frac, ipart, e, res;
00019         
00020         e = pow(10.,k);
00021         frac = modf(var, &ipart)*e;
00022         res = ipart + NINT(frac)/e;
00023         return(res);
00024 }
00025 
00026 int decode_open_tablexy(char *arg, TABLE *tab, int *colx, int *coly)
00027 {
00028         char **car;
00029         car = (char **)malloc(sizeof(char *));
00030         car[0] = (char *)malloc(80*sizeof(char));
00031         car[1] = (char *)malloc(80*sizeof(char));
00032         car[2] = (char *)malloc(80*sizeof(char));
00033 
00034         if (decode_argval_char(arg, car) != 3) {
00035                 printf("\nERROR cannot decode table,xcol,ycol in  %s\n",
00036                         arg);
00037                 exit_session(1);
00038         }
00039         open_table(tab, car[0], "I");
00040         *colx = get_col_ref(tab, car[1]);
00041         *coly = get_col_ref(tab, car[2]);
00042         return(0);
00043 }
00044 
00045 int decode_argval_char(char *arg, char **val) 
00046 {
00047         int i, k, n;
00048         char car[81];
00049 
00050         for (i=0, k=0, n=0; i<strlen(arg); i++, k++) {
00051                 if (arg[i] == ',') {
00052                         car[k] = '\0';
00053                         sscanf(car, "%s", val[n]);
00054                         n++;
00055                         k = -1;
00056                 }
00057                 if (k >= 0)
00058                         car[k] = arg[i];
00059         }
00060         car[k] = '\0';
00061         sscanf(car, "%s", val[n]);
00062         n++;
00063 
00064         return(n);
00065 }
00066 
00067 int decode_argval_double(char *arg, double *val, char *sep) 
00068 {
00069         int i, k, n, j;
00070         char car[81];
00071         char code[5];
00072 
00073         strcpy(code, ",/:");
00074 
00075         for (i=0, k=0, n=0; i<strlen(arg); i++, k++) {
00076                 for (j=0; j<3; j++) {
00077                         if (arg[i] == code[j]) {
00078                                 sep[n] = code[j];
00079                                 car[k] = '\0';
00080                                 sscanf(car, "%lf", &(val[n]));
00081                                 n++;
00082                                 k = -1;
00083                                 break;
00084                         }
00085                 }
00086                 if (k >= 0)
00087                         car[k] = arg[i];
00088         }
00089         car[k] = '\0';
00090         sscanf(car, "%lf", &(val[n]));
00091         n++;
00092 
00093         return(n);
00094 }
00095 
00096 int decode_argval_int(char *arg, int *val, char *sep) 
00097 {
00098         int i, k, n, j;
00099         char car[81];
00100         char code[5];
00101 
00102         strcpy(code, ",/:");
00103 
00104         for (i=0, k=0, n=0; i<strlen(arg); i++, k++) {
00105                 for (j=0; j<3; j++) {
00106                         if (arg[i] == code[j]) {
00107                                 sep[n] = code[j];
00108                                 car[k] = '\0';
00109                                 sscanf(car, "%d", &(val[n]));
00110                                 n++;
00111                                 k = -1;
00112                                 break;
00113                         }
00114                 }
00115                 if (k >= 0)
00116                         car[k] = arg[i];
00117         }
00118         car[k] = '\0';
00119         sscanf(car, "%d", &(val[n]));
00120         n++;
00121 
00122         return(n);
00123 }
00124 
00125 int decode_argval_float(char *arg, float *val, char *sep) 
00126 {
00127         int i, k, n, j;
00128         char car[81];
00129         char code[5];
00130 
00131         strcpy(code, ",/:");
00132 
00133         for (i=0, k=0, n=0; i<strlen(arg); i++, k++) {
00134                 for (j=0; j<3; j++) {
00135                         if (arg[i] == code[j]) {
00136                                 sep[n] = code[j];
00137                                 car[k] = '\0';
00138                                 sscanf(car, "%f", &(val[n]));
00139                                 n++;
00140                                 k = -1;
00141                                 break;
00142                         }
00143                 }
00144                 if (k >= 0)
00145                         car[k] = arg[i];
00146         }
00147         car[k] = '\0';
00148         sscanf(car, "%f", &(val[n]));
00149         n++;
00150 
00151         return(n);
00152 }
00153 
00154 int find_selected_arg(char **argval, char **argname, int *list, int n)
00155 {
00156         int i, nsel, sel;
00157 
00158         for (i=0, nsel=0; i<n; i++) {
00159                 if (strcmp(argval[list[i]], "null") == 0)
00160                         continue;
00161                 sel = list[i];
00162                 nsel++;
00163         }
00164         if (nsel > 1) {
00165                 printf("Fatal Error in line parameters\n");
00166                 printf("You can not set more than one of the following parameters:\n");
00167                 for (i=0; i<n; i++) 
00168                         printf("\t%s\n", argname[list[i]]);
00169                 exit_session(1);
00170         } else if (nsel == 0) {
00171                 printf("Fatal Error in line parameters\n");
00172                 printf("You must set one of the following parameters:\n");
00173                 for (i=0; i<n; i++) 
00174                         printf("\t%s\n", argname[list[i]]);
00175                 exit_session(1);
00176         }
00177         return(sel);
00178 }

Generated on Tue Jul 1 17:35:44 2003 for IFU_C_iolibs by doxygen1.3