+static int removed_mask_pos;
+
+char cflagsbuf[256];
+char cflagsmyinfo[256];
+
+int chmode_flags[256];
+
+extern int h_get_channel_access;
+
+/* OPTIMIZE ME! -- dwr */
+void
+construct_cflags_strings(void)
+{
+ int i;
+ char *ptr = cflagsbuf;
+ char *ptr2 = cflagsmyinfo;
+
+ *ptr = '\0';
+ *ptr2 = '\0';
+
+ for(i = 0; i < 256; i++)
+ {
+ if( !(chmode_table[i].set_func == chm_ban) &&
+ !(chmode_table[i].set_func == chm_forward) &&
+ !(chmode_table[i].set_func == chm_throttle) &&
+ !(chmode_table[i].set_func == chm_key) &&
+ !(chmode_table[i].set_func == chm_limit) &&
+ !(chmode_table[i].set_func == chm_op) &&
+ !(chmode_table[i].set_func == chm_voice))
+ {
+ chmode_flags[i] = chmode_table[i].mode_type;
+ }
+ else
+ {
+ chmode_flags[i] = 0;
+ }
+
+ switch (chmode_flags[i])
+ {
+ case MODE_FREETARGET:
+ case MODE_DISFORWARD:
+ if(ConfigChannel.use_forward)
+ *ptr++ = (char) i;
+ break;
+ default:
+ if(chmode_flags[i] != 0)
+ {
+ *ptr++ = (char) i;
+ }
+ }
+
+ /* Should we leave orphaned check here? -- dwr */
+ if(!(chmode_table[i].set_func == chm_nosuch) && !(chmode_table[i].set_func == chm_orphaned))
+ {
+ *ptr2++ = (char) i;
+ }
+ }
+
+ *ptr++ = '\0';
+ *ptr2++ = '\0';
+}
+
+/*
+ * find_umode_slot
+ *
+ * inputs - NONE
+ * outputs - an available cflag bitmask or
+ * 0 if no cflags are available
+ * side effects - NONE
+ */
+static unsigned int
+find_cflag_slot(void)
+{
+ unsigned int all_cflags = 0, my_cflag = 0, i;
+
+ for (i = 0; i < 256; i++)
+ all_cflags |= chmode_flags[i];
+
+ for (my_cflag = 1; my_cflag && (all_cflags & my_cflag);
+ my_cflag <<= 1);
+
+ return my_cflag;
+}
+
+unsigned int
+cflag_add(char c_, ChannelModeFunc function)
+{
+ int c = (unsigned char)c_;
+
+ if (chmode_table[c].set_func != chm_nosuch &&
+ chmode_table[c].set_func != chm_orphaned)
+ return 0;
+
+ if (chmode_table[c].set_func == chm_nosuch)
+ chmode_table[c].mode_type = find_cflag_slot();
+ if (chmode_table[c].mode_type == 0)
+ return 0;
+ chmode_table[c].set_func = function;
+ construct_cflags_strings();
+ return chmode_table[c].mode_type;
+}
+
+void
+cflag_orphan(char c_)
+{
+ int c = (unsigned char)c_;
+
+ s_assert(chmode_flags[c] != 0);
+ chmode_table[c].set_func = chm_orphaned;
+ construct_cflags_strings();
+}