2 * tools.c -- Miscellaneous routines used by both the client and server.
11 char *safestrncpy(char *dest, const char *src, size_t n)
13 if (dest == NULL || src == NULL)
15 fprintf(stderr, "safestrncpy: NULL argument\n");
18 strncpy(dest, src, n);
25 * num_parms() - discover number of parameters...
27 int num_parms(char *source)
32 for (a=0; a<strlen(source); ++a)
33 if (source[a]=='|') ++count;
38 * extract() - extract a parameter from a series of "|" separated...
40 void extract(char *dest, char *source, int parmnum)
46 if (strlen(source)==0) {
51 n = num_parms(source);
58 if ( (parmnum == 0) && (n == 1) ) {
60 for (n=0; n<strlen(dest); ++n)
61 if (dest[n]=='|') dest[n] = 0;
65 while (count++ < parmnum) do {
67 } while( (strlen(buf)>0) && (buf[0]!='|') );
68 if (buf[0]=='|') strcpy(buf,&buf[1]);
69 for (count = 0; count<strlen(buf); ++count)
70 if (buf[count] == '|') buf[count] = 0;
75 * extract_int() - extract an int parm w/o supplying a buffer
77 int extract_int(char *source, int parmnum)
81 extract(buf,source,parmnum);
86 * extract_long() - extract an long parm w/o supplying a buffer
88 long extract_long(char *source, long int parmnum)
92 extract(buf,source,parmnum);