static void remove_group( char *group ) { char buff[_MAX_PATH]; get_group_name( buff, group ); delete_dir( buff ); }
/* Generate an HTML table row for process PID. The return * value is a pointer to a buffer that the caller must * deallocate with free, or NULL if an error occurs. */ static char* format_process_info(pid_t pid) { int rval; uid_t uid; gid_t gid; char* user_name; char* group_name; int rss; char* program_name; size_t result_length; char* result; /* Obtain the process's user and group IDs. */ rval = get_uid_gid(pid, &uid, &gid); if (rval != 0) { return NULL; } /* Obtain the process's RSS. */ rss = get_rss(pid); if (rss == -1) { return NULL; } /* Obtain the process's program name. */ program_name = get_program_name(pid); if (program_name == NULL) { return NULL; } /* Convert user and group IDs to corresponding names. */ user_name = get_user_name(uid); group_name = get_group_name(gid); /* Comput the length of the string we'll need to hold the * result, and allocate memory to hold it. */ result_length = strlen(program_name) + strlen(user_name) + strlen(group_name) + 128; result = (char*) xmalloc(result_length); /* Format the result. */ snprintf(result, result_length, " <tr><td align=\"right\">%d</td>" "<td><tt>%s</tt></td><td>%s</td>" "<td>%s</td><td align=\"right\">%d</td></tr>\n", (int)pid, program_name, user_name, group_name, rss); /* Clean up. */ free(program_name); free(user_name); free(group_name); /* All done. */ return result; }
static BOOL create_group( char *group ) { char buff[_MAX_PATH]; int rc; get_group_name( buff, group ); rc = mkdir( buff ); if( rc == -1 && errno != EEXIST ) { return( FALSE ); } else { return( TRUE ); } }
static bool create_group( char *group ) { char buff[_MAX_PATH]; int rc; get_group_name( buff, group ); rc = mkdir( buff ); if( rc == -1 && errno != EEXIST ) { return( false ); } else { return( true ); } }
static BOOL create_icon( char *group, char *pgm, char *desc, char *arg, char *work, char *icon, int icon_num ) { HRESULT hres; IShellLink *m_link; IPersistFile *p_file; WORD w_link[_MAX_PATH]; char link[_MAX_PATH]; // Determine names of link files get_group_name( link, group ); strcat( link, "\\" ); strcat( link, desc ); strcat( link, ".lnk" ); munge_fname( link ); MultiByteToWideChar( CP_ACP, 0, link, -1, w_link, _MAX_PATH ); // Create an IShellLink object and get a pointer to the IShellLink interface m_link = NULL; hres = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLink, (void **)&m_link ); if( SUCCEEDED( hres ) ) { // Query IShellLink for the IPersistFile interface for // saving the shortcut in persistent storage. p_file = NULL; hres = m_link->lpVtbl->QueryInterface( m_link, &IID_IPersistFile, (void **)&p_file ); if( SUCCEEDED( hres ) ) { // Set the properties of the shortcut hres = m_link->lpVtbl->SetPath( m_link, pgm ); hres = m_link->lpVtbl->SetDescription( m_link, desc ); hres = m_link->lpVtbl->SetWorkingDirectory( m_link, work ); hres = m_link->lpVtbl->SetArguments( m_link, arg ); hres = m_link->lpVtbl->SetIconLocation( m_link, icon, icon_num ); // Save the shortcut via the IPersistFile::Save member function. hres = p_file->lpVtbl->Save( p_file, w_link, TRUE ); // Release the pointer to IPersistFile. p_file->lpVtbl->Release( p_file ); } // Release the pointer to IShellLink. m_link->lpVtbl->Release( m_link ); } return( SUCCEEDED( hres ) ); }
void print_universal_indent_cfg(FILE *pfile) { const group_map_value *p_grp; const char *p_name; /* Dump the header and the categories */ fprintf(pfile, "[header]\n"); /* Add all the categories */ char ch = '='; int idx; fprintf(pfile, "categories"); for (idx = 0; idx < UG_group_count; idx++) { p_grp = get_group_name(idx); if (p_grp != NULL) { fprintf(pfile, "%c%s", ch, p_grp->short_desc); ch = '|'; } } fprintf(pfile, "\n"); fprintf(pfile, "cfgFileParameterEnding=cr\n" "configFilename=TechPlayers.cfg\n"); /* Add all the recognized file extensions */ ch = '='; idx = 0; fprintf(pfile, "fileTypes"); while ((p_name = get_file_extension(idx)) != NULL) { fprintf(pfile, "%c*%s", ch, p_name); ch = '|'; } fprintf(pfile, "\n"); /* Add the rest of the constant file header */ fprintf(pfile, "indenterFileName=TechPlayers\n" "indenterName=TechPlayers (C, C++, C#, ObjectiveC, D, Java, Pawn, VALA)\n" "inputFileName=indentinput\n" "inputFileParameter=\"-f \"\n" "manual=http://TechPlayers.sourceforge.net/config.txt\n" "outputFileName=indentoutput\n" "outputFileParameter=\"-o \"\n" "stringparaminquotes=false\n" "parameterOrder=ipo\n" "showHelpParameter=-h\n" "stringparaminquotes=false\n" "useCfgFileParameter=\"-c \"\n" "version=%s\n", TechPlayers_VERSION); /* Now add each option */ for (idx = 0; idx < UG_group_count; idx++) { p_grp = get_group_name(idx); if (p_grp == NULL) { continue; } for (option_list_cit it = p_grp->options.begin(); it != p_grp->options.end(); it++) { const option_map_value *option = get_option_name(*it); // Create a better readable name from the options name // by replacing '_' by a space and use some upper case characters. char *optionNameReadable = new char[strlen(option->name) + 1]; strcpy(optionNameReadable, option->name); bool was_space = true; for (char *character = optionNameReadable; *character != 0; character++) { if (*character == '_') { *character = ' '; was_space = true; } else if (was_space) { *character = unc_toupper(*character); was_space = false; } } fprintf(pfile, "\n[%s]\n", optionNameReadable); fprintf(pfile, "Category=%d\n", idx); fprintf(pfile, "Description=\"<html>"); const char *tmp = option->short_desc; ch = 0; /* Output the decription which may contain forbidden chars */ while (*tmp != 0) { switch (*tmp) { case '<': fprintf(pfile, "<"); break; case '>': fprintf(pfile, ">"); break; case '&': fprintf(pfile, "&"); break; case '\n': fprintf(pfile, "<BR>"); break; default: fputc(*tmp, pfile); } tmp++; } fprintf(pfile, "</html>\"\n"); // Handle some options independent of their type and most by their type. switch (option->id) { // Indenting with tabs selector becomes a multiple selector and not only a number. Also its default enabled. case UO_indent_with_tabs: fprintf(pfile, "Enabled=true\n"); fprintf(pfile, "EditorType=multiple\n"); fprintf(pfile, "Choices=\"%s=0|%s=1|%s=2\"\n", option->name, option->name, option->name); fprintf(pfile, "ChoicesReadable=\"Spaces only|Indent with tabs, align with spaces|Indent and align with tabs\"\n"); fprintf(pfile, "ValueDefault=%d\n", cpd.settings[option->id].n); break; // All not specially handled options are created only dependent by their type. default: fprintf(pfile, "Enabled=false\n"); switch (option->type) { case AT_BOOL: // [align_keep_tabs] // Category=3 // Description=<html>Whether to keep non-indenting tabs</html> // Value=0 // ValueDefault=0 // EditorType=boolean // TrueFalse="align_keep_tabs=true|align_keep_tabs=false" fprintf(pfile, "EditorType=boolean\n"); fprintf(pfile, "TrueFalse=%s=true|%s=false\n", option->name, option->name); fprintf(pfile, "ValueDefault=%d\n", cpd.settings[option->id].n); break; case AT_IARF: fprintf(pfile, "EditorType=multiple\n"); fprintf(pfile, "Choices=\"%s=ignore|%s=add|%s=remove|%s=force\"\n", option->name, option->name, option->name, option->name); fprintf(pfile, "ChoicesReadable=\"Ignore %s|Add %s|Remove %s|Force %s\"\n", optionNameReadable, optionNameReadable, optionNameReadable, optionNameReadable); fprintf(pfile, "ValueDefault=%d\n", cpd.settings[option->id].n); // [nl_after_switch] // Category=4 // Description=<html>Add or remove newline after 'switch'</html> // Value=3 // ValueDefault=-1 // Enabled=true // EditorType=multiple // Choices="nl_after_switch=ignore|nl_after_switch=add|nl_after_switch=remove|nl_after_switch=force" break; case AT_NUM: // [align_assign_span] // CallName="align_assign_span=" // Category=3 // Description="<html>The span for aligning on '=' in assignments (0=don't align)</html>" // EditorType=numeric // Enabled=false // MaxVal=300 // MinVal=0 // Value=0 // ValueDefault=0 fprintf(pfile, "EditorType=numeric\n"); fprintf(pfile, "CallName=\"%s=\"\n", option->name); fprintf(pfile, "MinVal=%d\n", option->min_val); fprintf(pfile, "MaxVal=%d\n", option->max_val); fprintf(pfile, "ValueDefault=%d\n", cpd.settings[option->id].n); break; case AT_LINE: // [newlines] // Category=0 // Description=<html>The type of line endings</html> // Value=0 // ValueDefault=-1 // Enabled=true // EditorType=multiple // Choices="newlines=auto|newlines=lf|newlines=crlf|newlines=cr" fprintf(pfile, "EditorType=multiple\n"); fprintf(pfile, "Choices=\"%s=lf|%s=crlf|%s=cr|%s=auto\"\n", option->name, option->name, option->name, option->name); fprintf(pfile, "ChoicesReadable=\"Newlines Unix|Newlines Win|Newlines Mac|Newlines Auto\"\n"); fprintf(pfile, "ValueDefault=%d\n", cpd.settings[option->id].n); break; case AT_POS: // [pos_bool] // Category=5 // Description=<html>The position of boolean operators in wrapped expressions</html> // Enabled=false // Value=0 // ValueDefault=-1 // EditorType=multiple // Choices="pos_bool=ignore|pos_bool=lead|pos_bool=trail" fprintf(pfile, "EditorType=multiple\n"); fprintf(pfile, "Choices=\"%s=ignore|%s=lead|%s=lead_break|%s=lead_force|%s=trail|%s=trail_break|%s=trail_force\"\n", option->name, option->name, option->name, option->name, option->name, option->name, option->name); fprintf(pfile, "ChoicesReadable=\"Ignore %s|Lead %s|Lead Break %s|Lead Force %s|Trail %s|Trail Break %s|Trail Force %s\"\n", optionNameReadable, optionNameReadable, optionNameReadable, optionNameReadable, optionNameReadable, optionNameReadable, optionNameReadable); fprintf(pfile, "ValueDefault=%d\n", cpd.settings[option->id].n); break; case AT_STRING: { fprintf(pfile, "CallName=%s=\n", option->name); fprintf(pfile, "EditorType=string\n"); string val_string; const char *val_str; val_string = op_val_to_string(option->type, cpd.settings[option->id]); val_str = val_string.c_str(); fprintf(pfile, "ValueDefault=%s\n", val_str); } break; default: break; } } delete [] optionNameReadable; } } }
static int check_for_node_usability(const char *pathname) { struct stat st; if(!access(pathname, F_OK)) { ticables_info(_(" node %s: exists"), pathname); } else { ticables_info(_(" node %s: does not exist"), pathname); ticables_info(_(" => you will have to create the node.")); return -1; } if(!stat(pathname, &st)) { ticables_info(_(" permissions/user/group:%s%s %s"), get_attributes(st.st_mode), get_user_name(st.st_uid), get_group_name(st.st_gid)); } else { ticables_warning("can't stat '%s'.", pathname); return -1; } if(getuid() == st.st_uid) { ticables_info(_(" user can r/w on device: yes")); return 0; } else { ticables_info(_(" user can r/w on device: no")); } if((st.st_mode & S_IROTH) && (st.st_mode & S_IWOTH)) { ticables_info(_(" others can r/w on device: yes")); } else { char *user, *group; ticables_info(_(" others can r/w on device: no")); user = strdup(get_user_name(getuid())); group = strdup(get_group_name(st.st_gid)); if(!search_for_user_in_group(user, group)) { ticables_info(_(" is the user '%s' in the group '%s': yes"), user, group); } else { ticables_info(_(" is the user '%s' in the group '%s': no"), user, group); ticables_info(_(" => you should add your username at the group '%s' in '/etc/group'"), group); ticables_info(_(" => you will have to restart your session, too"), group); free(user); free(group); return -1; } free(user); free(group); } return 0; }