[Home]QuickSnippets

TheSourcery | RecentChanges | Preferences | Index | RSS

Showing revision 2
Difference (from revision 2 to revision 2) (minor diff)
(The revisions are identical or unavailable.)

Quick Snippets

This page contains small code snippets that may or not be useful to mud programmers. Consider them all to be public domain.


Counting objects in player files on a ROM type mud


$ cat offcount.c
#include <stdio.h>
#include <stdlib.h>

int offline_obj_count(int vnum)
{
  FILE *f;
  char cmd[160];
  int count;

  sprintf(cmd, "egrep -ch \"^Vnum %d\" ../player/* | gawk \'{ s += $1 }; END { print s }\' > sum.txt", vnum);
  system(cmd);
  f = fopen ("sum.txt", "r");
  if (!f) {
    printf("offline_obj_count: Could not read sum.txt file.");
    return 0;
  }
  fscanf(f,"%d\n", &count);
  fclose(f);
  return count;
}

int main(int argc, char** argv) {
  int vnum = atoi(argv[1]);
  int count = offline_obj_count(vnum);
  printf("Vnum:%d Count:%d", vnum, count);
  return 0;
}

$ gcc offcount.c

$ ./a 3382
Vnum:3382 Count:62

$ ./a 23008
Vnum:23008 Count:1

$ ./a 23048
Vnum:23048 Count:2

$ ./a 9999
Vnum:9999 Count:0



TheSourcery | RecentChanges | Preferences | Index | RSS
Edit revision 2 of this page | View other revisions | View current revision
Edited May 13, 2005 2:18 am by JonLambert (diff)
Search:
All material on this Wiki is the property of the contributing authors.
©2004-2006 by the contributing authors.
Ideas, requests, problems regarding this site? Send feedback.