const wchar * StringBase::loadString( dword nId ) { // look for the string already in the hash StringHash::Iterator it = stringIdHash().find( nId ); if (! it.valid() ) { wchar sBuffer[ MAX_RESOURCE_SIZE ]; stringTableQueue().reset(); while( stringTableQueue().valid() ) { int nSize = StringBase::loadString( *stringTableQueue(), nId, sBuffer, MAX_RESOURCE_SIZE ); if ( nSize > 0 ) { // insert the loaded string into our hash, call unslash() to remove any escapped characters it = stringIdHash().insert( nId, unslash( sBuffer ) ); // string found, stop while break; } else stringTableQueue().next(); // try the next table } // if string not found in any table, create a dummy string then if (! it.valid() ) { StringBase::format( sBuffer, sizeof(sBuffer), L"##%d", nId ); it = stringIdHash().insert( nId, strdup( sBuffer ) ); } } return *it; }
int _tmain( int argc, TCHAR* argv[]) { _tsetlocale( LC_ALL, _T("")); if ( argc != 3 ) { _putts( _T("mirrorup, version 1.5 2008-01-17--2008-02-26 (c) Denis Ryzhkov\n") _T("http://denis.ryzhkov.org/?soft/mirrorup\n") _T("\n") _T("usage: mirrorup C:\\proj U:\\proj\n") _T("\n") _T("means: make a mirror backup of C:\\proj to U:\\proj\n") _T("i.e. copy or delete only files and folders\n") _T("that were changed after previous backup.\n") _T("file size and modification time are only compared.\n") _T("\n") _T("source code and batch script provided.")); return 0; } TCHAR* fromPath = unslash( argv[1]); TCHAR* toPath = unslash( argv[2]); TCHAR dateTimeStr[ BUF_LEN ]; _tprintf( _T("\n%s make a mirror backup of %s to %s\n\n"), timestamp( dateTimeStr ), fromPath, toPath ); #define attrErr 0xFFFFFFFF if ( GetFileAttributes( toPath ) == attrErr ) CreateDirectoryEx( fromPath, toPath, 0 ); if ( GetFileAttributes( toPath ) == attrErr ) { _putts( _T("bad path")); return 1; } mirrorup( fromPath, toPath ); _tprintf( _T("\n%s done ok: %d, errors: %d\n"), timestamp( dateTimeStr ), okCount, errCount ); return 0; }
int main (int argc, char * const argv[]) { PROG = "aa-reset"; const char *path_repo = "/run/services"; intptr_t mode = MODE_NONE; int i; int r; for (;;) { struct option longopts[] = { { "auto", no_argument, NULL, 'A' }, { "started", no_argument, NULL, 'a' }, { "double-output", no_argument, NULL, 'D' }, { "help", no_argument, NULL, 'h' }, { "stopped", no_argument, NULL, 'o' }, { "repodir", required_argument, NULL, 'r' }, { "version", no_argument, NULL, 'V' }, { NULL, 0, 0, 0 } }; int c; c = getopt_long (argc, argv, "AaDhor:V", longopts, NULL); if (c == -1) break; switch (c) { case 'A': mode = MODE_AUTO; break; case 'a': mode = MODE_STARTED; break; case 'D': aa_set_double_output (1); break; case 'h': dieusage (0); case 'o': mode = MODE_STOPPED; break; case 'r': unslash (optarg); path_repo = optarg; break; case 'V': aa_die_version (); default: dieusage (1); } } argc -= optind; argv += optind; if (argc < 1 || mode == MODE_NONE) dieusage (1); r = aa_init_repo (path_repo, AA_REPO_READ); if (r < 0) aa_strerr_diefu2sys (2, "init repository ", path_repo); for (i = 0; i < argc; ++i) if (str_equal (argv[i], "-")) { if (process_names_from_stdin ((names_cb) reset_service, (void *) mode) < 0) aa_strerr_diefu1sys (ERR_IO, "process names from stdin"); } else reset_service (argv[i], mode); return 0; }
int main (int argc, char * const argv[]) { PROG = "aa-start"; const char *path_repo = "/run/services"; const char *path_list = NULL; int i; aa_secs_timeout = DEFAULT_TIMEOUT_SECS; for (;;) { struct option longopts[] = { { "double-output", no_argument, NULL, 'D' }, { "help", no_argument, NULL, 'h' }, { "listdir", required_argument, NULL, 'l' }, { "dry-list", no_argument, NULL, 'n' }, { "repodir", required_argument, NULL, 'r' }, { "timeout", required_argument, NULL, 't' }, { "version", no_argument, NULL, 'V' }, { "verbose", no_argument, NULL, 'v' }, { "no-wants", no_argument, NULL, 'W' }, { NULL, 0, 0, 0 } }; int c; c = getopt_long (argc, argv, "Dhl:nr:t:VvW", longopts, NULL); if (c == -1) break; switch (c) { case 'D': aa_set_double_output (1); break; case 'h': dieusage (0); case 'l': unslash (optarg); path_list = optarg; break; case 'n': if (mode & AA_MODE_IS_DRY) mode |= AA_MODE_IS_DRY_FULL; else mode |= AA_MODE_IS_DRY; break; case 'r': unslash (optarg); path_repo = optarg; break; case 't': if (!uint0_scan (optarg, &aa_secs_timeout)) aa_strerr_diefu2sys (ERR_IO, "set default timeout to ", optarg); break; case 'V': aa_die_version (); case 'v': verbose = 1; break; case 'W': no_wants = 1; break; default: dieusage (1); } } argc -= optind; argv += optind; cols = get_cols (1); is_utf8 = is_locale_utf8 (); if (!path_list && argc < 1) dieusage (1); if (aa_init_repo (path_repo, (mode & AA_MODE_IS_DRY) ? AA_REPO_READ : AA_REPO_WRITE) < 0) aa_strerr_diefu2sys (ERR_IO, "init repository ", path_repo); if (path_list) { stralloc sa = STRALLOC_ZERO; int r; if (*path_list != '/' && *path_list != '.') stralloc_cats (&sa, LISTDIR_PREFIX); stralloc_catb (&sa, path_list, strlen (path_list) + 1); r = aa_scan_dir (&sa, 1, it_start, NULL); stralloc_free (&sa); if (r < 0) aa_strerr_diefu3sys (-r, "read list directory ", (*path_list != '/' && *path_list != '.') ? LISTDIR_PREFIX : path_list, (*path_list != '/' && *path_list != '.') ? path_list : ""); } tain_now_g (); for (i = 0; i < argc; ++i) if (str_equal (argv[i], "-")) { if (process_names_from_stdin ((names_cb) add_service, NULL) < 0) aa_strerr_diefu1sys (ERR_IO, "process names from stdin"); } else add_service (argv[i], NULL); mainloop (mode, scan_cb); if (!(mode & AA_MODE_IS_DRY)) { aa_bs_noflush (AA_OUT, "\n"); put_title (1, PROG, "Completed.", 1); aa_show_stat_nb (nb_already, "Already up", ANSI_HIGHLIGHT_GREEN_ON); aa_show_stat_nb (nb_done, "Started", ANSI_HIGHLIGHT_GREEN_ON); show_stat_service_names (&ga_timedout, "Timed out", ANSI_HIGHLIGHT_RED_ON); show_stat_service_names (&ga_failed, "Failed", ANSI_HIGHLIGHT_RED_ON); show_stat_service_names (&ga_depend, "Dependency failed", ANSI_HIGHLIGHT_RED_ON); aa_show_stat_names (aa_names.s, &ga_io, "I/O error", ANSI_HIGHLIGHT_RED_ON); aa_show_stat_names (aa_names.s, &ga_unknown, "Unknown", ANSI_HIGHLIGHT_RED_ON); aa_show_stat_names (aa_names.s, &ga_skipped, "Skipped", ANSI_HIGHLIGHT_YELLOW_ON); } genalloc_free (int, &ga_timedout); genalloc_free (int, &ga_failed); genalloc_free (int, &ga_depend); genalloc_free (size_t, &ga_io); genalloc_free (size_t, &ga_unknown); genalloc_free (size_t, &ga_skipped); genalloc_free (pid_t, &ga_pid); genalloc_free (int, &aa_tmp_list); genalloc_free (int, &aa_main_list); stralloc_free (&aa_names); genalloc_deepfree (struct progress, &ga_progress, free_progress); aa_free_services (close_fd); genalloc_free (iopause_fd, &ga_iop); return rc; }
static void constructSSHurl(char *source, char *options, char *path, char *url, int len) { char *sep1=NULL, *pathstart=NULL; int pos=0, len1; char user[64]; memset(user, '\0', 64); sep1=strchr(source, '@'); if (sep1) { if (sep1-source<len) { memcpy(user, source, sep1-source); } } if (strlen(user)==0) { /* no user part yet: get it from he mountoptions */ get_value_mountoptions(options, "user_id", user, 64); if (strlen(user)>0) { uid_t uidnr=atoi(user); struct passwd *pwd; memset(user, '\0', 64); pwd=getpwuid(uidnr); if (pwd) strncpy(user, pwd->pw_name, 64); } } if (strlen(user)>0) { pos=snprintf(url, len, "sshfs:%s@", user); } else { pos=snprintf(url, len, "sshfs:"); } sep1=strchr(source, ':'); /* look for the starting path in source */ if (sep1) { int len0=strlen(sep1+1); if (len0>0) { if (pos+len0<len) { memcpy(url+pos, sep1+1, len0); pathstart=url+pos; pos+=len0; } } else { /* no path in source: with ssh the home is used of the user */ if (strlen(user)>0) { /* use a template */ len0=strlen("%HOME%"); if (pos+len0<len) { memcpy(url+pos, "%HOME%", len0); pos+=len0; } } else { /* if no user found .... what to do ?? */ logoutput("construct_url_sshfs: no user and no starting path found...."); } } } len1=strlen(path); if (len1>0) { if (pos+len1<len) { memcpy(url+pos, path, len1); if (! pathstart) pathstart=url+pos; pos+=len1; *(url+pos)='\0'; } } if (pathstart) unslash(pathstart); }