int CDispatcherDlg::srcfile() { TCHAR destdir[MAX_PATH]; lstrcpy(destdir, this->m_strDest); if (destdir[lstrlen(destdir) - 1] != _T('\\')) { lstrcat(destdir, _T("\\")); } return findfiles(destdir, -1, ::destproc, (DWORD)this); }
void snr3_run_in_files(Tsnr3run *s3run) { DEBUG_MSG("snr3_run_in_files, started for s3run=%p\n",s3run); g_atomic_int_set(&s3run->cancelled, 0); queue_init_full(&s3run->threadqueue, 4, TRUE, TRUE, (QueueFunc)files_replace_run); g_print("filepattern=%s\n",s3run->filepattern); g_atomic_int_set(&s3run->runcount, 1); /* start with one reference for the findfiles() call */ s3run->findfiles = findfiles(s3run->basedir, (s3run->recursion_level > 0), s3run->recursion_level, TRUE,s3run->filepattern, G_CALLBACK(filematch_cb), G_CALLBACK(finished_finding_files_cb), s3run); }
int conect() { //Connects to a server using "Winsock" // Start up Winsock i=WSAStartup(version, &wsaData); if (i!=0) {return(0);} // Store information about the server LPHOSTENT lpHostEntry; lpHostEntry = gethostbyname(server); if (lpHostEntry == NULL) { WSACleanup(); connected=0; return(0); } else connected=1; //This means we're connected //Get important data if (err==0) { //If we didn't run this allready and got an error findserver(); findfiles(); } // Create the socket theSocket = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); if (theSocket == INVALID_SOCKET) { WSACleanup(); connected=0; return(0); } SOCKADDR_IN saServer; saServer.sin_family = AF_INET; saServer.sin_addr = *((LPIN_ADDR)*lpHostEntry->h_addr_list); saServer.sin_port = htons(25); // Connect to the server nRet = connect(theSocket,(LPSOCKADDR)&saServer,sizeof(struct sockaddr)); if (nRet == SOCKET_ERROR) { WSACleanup(); connected=0; return(0); } nRet = recv(theSocket,Buf,sizeof(Buf),0); if (nRet == SOCKET_ERROR) { WSACleanup(); connected=0; return(0); } if (Buf[0]=='4' || Buf[0]=='5') err=1; if (Buf[0]=='2' && Buf[1]=='2' && Buf[2]=='0') { sendmail(); } //Close the connection closesocket(theSocket); // Shutdown Winsock WSACleanup(); }
/* Search the game file directory and generate an array of gameseries * structures corresponding to the puzzle files found there. */ int getseriesfiles(char *filename, gameseries **list, int *count) { seriesdata s; s.list = NULL; s.count = 0; if (*filename && isfilename(filename)) { if (getseriesfile(filename, &s) <= 0 || !s.count) die("Couldn't access \"%s\"", filename); *datadir = '\0'; *savedir = '\0'; } else { if (!findfiles(datadir, &s, getseriesfile) || !s.count) die("Couldn't find any data files in \"%s\".", datadir); if (s.count > 1) qsort(s.list, s.count, sizeof *s.list, gameseriescmp); } *list = s.list; *count = s.count; return TRUE; }
/*--------------------------------------------------------------------------*/ int sci_findfiles(char *fname, unsigned long fname_len) { static int l1 = 0, n1 = 0, m1 = 0; char *pathextented = NULL; char *path = NULL; char *filespec = NULL; char **FilesList = NULL; int sizeListReturned = 0; Rhs = Max(Rhs, 0); CheckRhs(0, 2); CheckLhs(0, 1); switch (Rhs) { default: case 0: { int ierr = 0; path = scigetcwd(&ierr); if (ierr) { Scierror(999, _("%s: Error while trying to retrieve the name of the current directory.\n"), fname); return 0; } else { filespec = strdup(DEFAULT_FILESPEC); } } break; case 1: { if (GetType(1) == sci_strings) { GetRhsVar(1, STRING_DATATYPE, &m1, &n1, &l1); path = strdup(cstk(l1)); filespec = strdup(DEFAULT_FILESPEC); } else { Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, 1); return 0; } } break; case 2: { if ((GetType(1) == sci_strings) && (GetType(2) == sci_strings)) { GetRhsVar(1, STRING_DATATYPE, &m1, &n1, &l1); path = strdup(cstk(l1)); GetRhsVar(2, STRING_DATATYPE, &m1, &n1, &l1); filespec = strdup(cstk(l1)); } else { Scierror(999, _("%s: Wrong type for input arguments: Strings expected.\n"), fname); return 0; } } break; } pathextented = expandPathVariable(path); if (path) { FREE(path); path = NULL; } FilesList = findfiles(pathextented, filespec, &sizeListReturned, FALSE); if (pathextented) { FREE(pathextented); pathextented = NULL; } if (filespec) { FREE(filespec); filespec = NULL; } if (FilesList) { int ncol = 0, nrow = 0; ncol = 1; nrow = sizeListReturned; CreateVarFromPtr(Rhs + 1, MATRIX_OF_STRING_DATATYPE, &nrow, &ncol, FilesList); LhsVar(1) = Rhs + 1; } else { n1 = 0; m1 = 0; l1 = 0; CreateVarFromPtr(Rhs + 1, MATRIX_OF_DOUBLE_DATATYPE, &n1, &m1, &l1); LhsVar(1) = Rhs + 1; } freeArrayOfString(FilesList, sizeListReturned); PutLhsVar(); return 0; }
/* * routine: * main * * purpose: * argument processing and primary dispatch * * returns: * error codes per filesync.1 (ERR_* in filesync.h) * * notes: * read filesync.1 in order to understand the argument processing * * most of the command line options just set some opt_ global * variable that is later looked at by the code that actually * implements the features. Only file names are really processed * in this routine. */ int main(int argc, char **argv) { int i; int c; errmask_t errs = ERR_OK; int do_prune = 0; char *srcname = 0; char *dstname = 0; struct base *bp; /* keep the error messages simple */ argv[0] = "filesync"; /* gather together all of the options */ while ((c = getopt(argc, argv, "AaehmnqvyD:E:r:s:d:f:o:")) != EOF) switch (c) { case 'a': /* always scan for acls */ opt_acls = TRUE; break; case 'e': /* everything agrees */ opt_everything = TRUE; break; case 'h': /* halt on error */ opt_halt = TRUE; break; case 'm': /* preserve modtimes */ opt_mtime = TRUE; break; case 'n': /* notouch */ opt_notouch = TRUE; break; case 'q': /* quiet */ opt_quiet = TRUE; break; case 'v': /* verbose */ opt_verbose = TRUE; break; case 'y': /* yes */ opt_yes = TRUE; break; case 'D': /* debug options */ if (!isdigit(optarg[0])) { dbg_usage(); exit(ERR_INVAL); } opt_debug |= strtol(optarg, (char **)NULL, 0); break; case 'E': /* error simulation */ if (dbg_set_error(optarg)) { err_usage(); exit(ERR_INVAL); } opt_errors = TRUE; break; case 'f': /* force conflict resolution */ switch (optarg[0]) { case 's': opt_force = OPT_SRC; break; case 'd': opt_force = OPT_DST; break; case 'o': opt_force = OPT_OLD; break; case 'n': opt_force = OPT_NEW; break; default: fprintf(stderr, gettext(ERR_badopt), c, optarg); errs |= ERR_INVAL; break; } break; case 'o': /* one way propagation */ switch (optarg[0]) { case 's': opt_oneway = OPT_SRC; break; case 'd': opt_oneway = OPT_DST; break; default: fprintf(stderr, gettext(ERR_badopt), c, optarg); errs |= ERR_INVAL; break; } break; case 'r': /* restricted reconciliation */ if (num_restrs < MAX_RLIST) rlist[ num_restrs++ ] = optarg; else { fprintf(stderr, gettext(ERR_tomany), MAX_RLIST); errs |= ERR_INVAL; } break; case 's': if ((srcname = qualify(optarg)) == 0) errs |= ERR_MISSING; break; case 'd': if ((dstname = qualify(optarg)) == 0) errs |= ERR_MISSING; break; default: case '?': errs |= ERR_INVAL; break; } if (opt_debug & DBG_MISC) fprintf(stderr, "MISC: DBG=%s\n", showflags(dbgmap, opt_debug)); /* if we have file names, we need a source and destination */ if (optind < argc) { if (srcname == 0) { fprintf(stderr, gettext(ERR_nosrc)); errs |= ERR_INVAL; } if (dstname == 0) { fprintf(stderr, gettext(ERR_nodst)); errs |= ERR_INVAL; } } /* check for simple usage errors */ if (errs & ERR_INVAL) { usage(); exit(errs); } /* locate our baseline and rules files */ if (c = findfiles()) exit(c); /* figure out file creation defaults */ whoami(); /* read in our initial baseline */ if (!new_baseline && (c = read_baseline(file_base))) errs |= c; /* read in the rules file if we need or have rules */ if (optind >= argc && new_rules) { fprintf(stderr, ERR_nonames); errs |= ERR_INVAL; } else if (!new_rules) errs |= read_rules(file_rules); /* if anything has failed with our setup, go no further */ if (errs) { cleanup(errs); exit(errs); } /* * figure out whether or not we are willing to do a one-sided * analysis (where we don't even look at the other side. This * is an "I'm just curious what has changed" query, and we are * only willing to do it if: * we aren't actually going to do anything * we have a baseline we can compare against * otherwise, we are going to insist on being able to access * both the source and destination. */ if (opt_notouch && !new_baseline) opt_onesided = opt_oneway; /* * there are two interested usage scenarios: * file names specified * create new rules for the specified files * evaulate and reconcile only the specified files * no file names specified * use already existing rules * consider restricting them to specified subdirs/files */ if (optind < argc) { /* figure out what base pair we're working on */ bp = add_base(srcname, dstname); /* perverse default rules to avoid trouble */ if (new_rules) { errs |= add_ignore(0, SUFX_RULES); errs |= add_ignore(0, SUFX_BASE); } /* create include rules for each file/dir arg */ while (optind < argc) errs |= add_include(bp, argv[ optind++ ]); /* * evaluate the specified base on each side, * being careful to limit evaulation to new rules */ errs |= evaluate(bp, OPT_SRC, TRUE); errs |= evaluate(bp, OPT_DST, TRUE); } else { /* note any possible evaluation restrictions */ for (i = 0; i < num_restrs; i++) errs |= add_restr(rlist[i]); /* * we can only prune the baseline file if we have done * a complete (unrestricted) analysis. */ if (i == 0) do_prune = 1; /* evaulate each base on each side */ for (bp = bases; bp; bp = bp->b_next) { errs |= evaluate(bp, OPT_SRC, FALSE); errs |= evaluate(bp, OPT_DST, FALSE); } } /* if anything serious happened, skip reconciliation */ if (errs & ERR_FATAL) { cleanup(errs); exit(errs); } /* analyze and deal with the differenecs */ errs |= analyze(); /* see if there is any dead-wood in the baseline */ if (do_prune) { c = prune(); if (c > 0 && opt_verbose) fprintf(stdout, V_prunes, c); } /* print out a final summary */ summary(); /* update the rules and baseline files (if needed) */ (void) umask(my_umask); errs |= write_baseline(file_base); errs |= write_rules(file_rules); if (opt_debug & DBG_MISC) fprintf(stderr, "MISC: EXIT=%s\n", showflags(errmap, errs)); /* just returning ERR_RESOLVABLE upsets some people */ if (errs == ERR_RESOLVABLE && !opt_notouch) errs = 0; /* all done */ cleanup(0); return (errs); }