Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Friday, October 16, 2026

Diff for ep/src/obsolete/Attic/old_functions.c between version 1.1 and 1.2

version 1.1, 2002/02/19 14:35:38 version 1.2, 2002/02/21 02:22:04
Line 185  proctable_read_old(p_ptbl, p_fds)
Line 185  proctable_read_old(p_ptbl, p_fds)
         return 0;          return 0;
 }  }
   
           int
   process_init_by_array(proc, size, array)
           struct process *proc;
           int size;
           char **array;
   {
   
           int c, option_index = 0;
           static struct option long_options[] = {
                   {"stdin", 1, NULL, 'i'},
                   {"stdout", 1, NULL, 'o'},
                   {"stderr", 1, NULL, 'e'},
                   {NULL, 0, NULL, 0}
           };
   
   #if DEBUG
           msg_debug_print("process_init_by_array(): size = %d\n", size);
   #endif
   
           process_init(proc);
   
           optind = 0;
   
           while (1) {
                   c = getopt_long(size + 1, array - 1, "+i:o:e:",
                                                                   long_options, &option_index);
   
   #if DEBUG
                   msg_debug_print("process_init_by_array(): "
                                                                   "getopt_long() = %d [%c]\n", c, c);
   #endif
   
                   if (c == -1) {
                           return process_argv_init_by_array(
                                                                           proc,
                                                                           size + 1 - optind,
                                                                           array - 1 + optind);
                   }
   
                   switch (c) {
                           case 'i':
                           case 'o':
                           case 'e':
                                   {
                                           register int a_ret;
                                           struct proclink link;
   
                                           do {
                                                   a_ret = analyze_proc_optarg(optarg, &link);
                                                   if (a_ret == -1) {
                                                           msg_error_print("invalid filedescriptor "
                                                                                                           "specification -- %s\n",
                                                                                                           optarg);
                                                           return 0;
                                                   }
   
                                                   if (!fd_add_proclink(&proc->fd[optchar2fd_no(c)],
                                                                                                           &link))
                                                           return 0;
   
                                           } while (a_ret > 0);
                                   }
                                   break;
   
                           case '?':
                                   msg_error_print("internal program error\n", c);
                                   return 0;
   
                           case ':':
                                   msg_error_print("missing parameter for -%c\n", c);
                                   return 0;
   
                           default:
                                   msg_error_print("incorrect option: -%c\n", c);
                                   return 0;
                   }
           }
   
   }
   
   
   /*
    * Analyze process optarg.
    * Return 1, if there are items left, link->proc_id and link->fd are set.
    * If it was last item return 0.
    * On error return -1.
    */
           static int
   analyze_proc_optarg(arg, link)
           char *arg;
           struct proclink *link;
   {
           static char *a_arg = NULL;
           static char *curr_sub_arg;
   
           char *next_sub_arg, *curr_2nd_part;
   
           /* Check if this is first call. */
           if (a_arg != arg) {
                   register int i;
   
                   /* Remove all unimportant characters. */
                   i = -1;
                   while (++i, arg[i] != '\0')
                           if (!isalnum(arg[i]))
                                   strdel(arg + i);
   
                   /* Check the consistency. */
                   if (strlen(arg) < 2)
                           return -1;
                   if ((isdigit(arg[0]) && isalpha(arg[strlen(arg)-1])) ||
                                                                   (isalpha(arg[0]) && isdigit(arg[strlen(arg)-1])))
                           ;
                   else
                           return -1;
   
                   curr_sub_arg = a_arg = arg;
           }
   
           /*
            * Set next_sub_arg to the next subargument.
            * Set curr_2nd_part to the 2nd part of current subargument.
            */
           for (curr_2nd_part = next_sub_arg = curr_sub_arg; ; next_sub_arg++) {
                   if ((curr_2nd_part == curr_sub_arg) &&
                                                                   ((isdigit(curr_sub_arg[0]) && isalpha(next_sub_arg[0])) ||
                                                                    (isalpha(curr_sub_arg[0]) && isdigit(next_sub_arg[0]))))
                           curr_2nd_part = next_sub_arg;
                   if ((next_sub_arg[1] == '\0') ||
                                                                   (isdigit(curr_sub_arg[0]) &&
                                                                    isdigit(next_sub_arg[1]) && isalpha(next_sub_arg[0])) ||
                                                                   (isalpha(curr_sub_arg[0]) &&
                                                                    isalpha(next_sub_arg[1]) && isdigit(next_sub_arg[0])))
                           break;
           }
           next_sub_arg++;
   
           /* Parse link->proc_id and link->fd. */
           {
                   register int i;
                   register char *proc_id_start, *fd_start, *fd_end;
                   if (isdigit(curr_sub_arg[0])) {
                           proc_id_start = curr_sub_arg;
                           fd_start = curr_2nd_part;
                           fd_end = next_sub_arg - 1;
                   }
                   else {
                           proc_id_start = curr_2nd_part;
                           fd_start = curr_sub_arg;
                           fd_end = curr_2nd_part - 1;
                   }
   
                   /* Set link->proc_id. */
                   sscanf(proc_id_start, "%d", &link->proc_id);
   
                   /* Set link->fd. */
                   link->fd_id = INVALID_FD;
                   for (i = 0; i < N_FD_STR * N_FD; i++) {
                           if (strlen(fd_str[i/N_FD][i%N_FD]) ==
                                                                           fd_end - fd_start + 1 &&
                                                                           fd_start ==     (char *)strstr(fd_start,
                                                                                   fd_str[i/N_FD][i%N_FD]))
                                   link->fd_id = i % N_FD;
                   }
           }
   
           if (link->fd_id == INVALID_FD)
                   return -1;
   
           /* Move to the next subargument. */
           curr_sub_arg = next_sub_arg;
   
           return curr_sub_arg[0] == '\0' ? 0 : 1;
   }
   
   #ifndef optchar2fd_no
   #  define optchar2fd_no(c) (c == 'i' ? FD_IN : \
                                                   c == 'o' ? FD_OUT : c == 'e' ? FD_ERR : INVALID_FD)
   #endif
   

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top